From 3068eed783a8cf2f63f2280ceab9c8871c30153b Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Fri, 16 Jul 2010 20:02:14 +0100 Subject: [PATCH] Parse more fields The output processing is half-arsed; we need to quote things consistently, etc. But that requirement will probably go away once we're part of a larger program and just returning a structure rather than spitting out ical directly. --- ews2ical.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/ews2ical.c b/ews2ical.c index e928d6a..734301f 100644 --- a/ews2ical.c +++ b/ews2ical.c @@ -47,7 +47,7 @@ int main(int argc, char **argv) fprintf(stderr, "Too many args. Want only xml file and ical file\n"); return -1; } - // read(xmlfd, buf, 1); + read(xmlfd, buf, 1); xml_doc = xmlReadFd(xmlfd, "noname.xml", "utf-8", 0); if (!xml_doc) { fprintf(stderr, "Failed to parse XML\n"); @@ -147,7 +147,7 @@ int main(int argc, char **argv) int process_mailbox(xmlNode *xml_node, const char **r_name, const char **r_email) { - const char *type, *name = NULL, *email = NULL; + const char *type = NULL, *name = NULL, *email = NULL; for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) { if (xml_node->type != XML_ELEMENT_NODE) @@ -158,13 +158,13 @@ int process_mailbox(xmlNode *xml_node, const char **r_name, const char **r_email email = (char *)xmlNodeGetContent(xml_node); if (!strcmp((char *)xml_node->name, "RoutingType")) { type = (char *)xmlNodeGetContent(xml_node); - if (strcmp(type, "SMTP")) { - printf("Unknown RoutingType '%s'\n", type); - return -1; - } } } + if (type && strcmp(type, "SMTP")) { + printf("Unknown RoutingType '%s' ('%s' '%s')\n", type, name, email); + return -1; + } *r_name = name; *r_email = email; return 0; @@ -186,11 +186,36 @@ int process_organizer(xmlNode *xml_node) return 0; } +int process_required_attendee(xmlNode *xml_node) +{ + for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) { + if (xml_node->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((char *)xml_node->name, "Mailbox")) { + const char *name = NULL, *email = NULL; + if (process_mailbox(xml_node, &name, &email)) + return -1; + fprintf(calfile, "ATTENDEE;ROLE=REQ-PARTICIPANT;CN=\"%s\":MAILTO:%s\n", + name, email); + } + } + return 0; +} + int process_required_attendees(xmlNode *xml_node) { + for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) { + if (xml_node->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((char *)xml_node->name, "Attendee")) { + if (process_required_attendee(xml_node)) + { } + } + } return 0; } + int process_start(xmlNode *xml_node) { return 0; @@ -203,10 +228,42 @@ int process_end(xmlNode *xml_node) int process_body(xmlNode *xml_node) { + char *body = (char *)xmlNodeGetContent(xml_node); + int col = 12; + + if (!body) + return -1; + + fprintf(calfile, "DESCRIPTION:"); + + while (*body) { + switch (*body) { + case '\n': + col += fprintf(calfile, "\\n"); + break; + case ',': + case '"': + col++; fputc('\\', calfile); + default: + col++; fputc(*body, calfile); + break; + } + body++; + if (col >= 76) { + fprintf(calfile, "\n "); + col = 1; + } + } + fputc('\n', calfile); return 0; } int process_subject(xmlNode *xml_node) { + const char *subject = (char *)xmlNodeGetContent(xml_node); + if (!subject) + return -1; + + fprintf(calfile, "SUMMARY:\"%s\"\n", subject); return 0; } -- 2.49.0