]> www.infradead.org Git - users/dwmw2/ews-sync.git/commitdiff
Parse more fields
authorDavid Woodhouse <dwmw2@infradead.org>
Fri, 16 Jul 2010 19:02:14 +0000 (20:02 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Fri, 16 Jul 2010 19:02:14 +0000 (20:02 +0100)
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

index e928d6a07e4286986af30e65c1f9f264a30c528c..734301f6c9ac05da23cc767bf7c4ed5c361388d8 100644 (file)
@@ -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;
 }