From 05cee7b7170c83f19db96e4e49e9aefdca1bd315 Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Wed, 31 Oct 2012 14:58:44 +0000 Subject: Properly extract the Body information of an EWS calendar item Unlike all other calendar modules, res_calendar_ews fails to extract the Body information for a calendar item. This is due, in part, to a quirk in the schema in the XML - not only does a CalendarItem contain a Body element, but the CalendarItem exists as a descendant of a different Body element. The neon parser was erroneously skipping all Body elements. This patch fixes that by bypassing Body elements that are not a child of CalendarItem, and parsing the Body element out if it is a child. Note that the original patch by Terry Wilson only needed slight modifications to make it properly pull the Body information out; as such, while I've linked to the patch that I uploaded for Dmitry, I've attributed the patch to Terry. (closes issue ASTERISK-19738) Reported by: Dmitry Burilov Tested by: Dmitry Burilov patches: calendar_ews_body_2012_10_29.diff uploaded by Terry Wilson (license 6283) ........ Merged revisions 375528 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 375531 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 375532 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@375533 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_calendar_ews.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/res/res_calendar_ews.c b/res/res_calendar_ews.c index 7deca9c97..3cf0d745e 100644 --- a/res/res_calendar_ews.c +++ b/res/res_calendar_ews.c @@ -80,7 +80,9 @@ struct xml_context { /* Important states of XML parsing */ enum { + XML_EVENT_CALENDAR_ITEM = 9, XML_EVENT_NAME = 10, + XML_EVENT_DESCRIPTION, XML_EVENT_START, XML_EVENT_END, XML_EVENT_BUSY, @@ -180,7 +182,7 @@ static int startelm(void *userdata, int parent, const char *nspace, const char * /* Nodes needed for traversing until CalendarItem is found */ if (!strcmp(name, "Envelope") || - !strcmp(name, "Body") || + (!strcmp(name, "Body") && parent != XML_EVENT_CALENDAR_ITEM) || !strcmp(name, "FindItemResponse") || !strcmp(name, "GetItemResponse") || !strcmp(name, "CreateItemResponse") || @@ -228,7 +230,7 @@ static int startelm(void *userdata, int parent, const char *nspace, const char * return NE_XML_ABORT; } - return 1; + return XML_EVENT_CALENDAR_ITEM; } else if (!strcmp(name, "ItemId")) { /* Event UID */ if (ctx->op == XML_OP_FIND) { @@ -255,6 +257,13 @@ static int startelm(void *userdata, int parent, const char *nspace, const char * } ast_str_reset(ctx->cdata); return XML_EVENT_NAME; + } else if (!strcmp(name, "Body") && parent == XML_EVENT_CALENDAR_ITEM) { + /* Event body/description */ + if (!ctx->cdata) { + return NE_XML_ABORT; + } + ast_str_reset(ctx->cdata); + return XML_EVENT_DESCRIPTION; } else if (!strcmp(name, "Start")) { /* Event start time */ return XML_EVENT_START; @@ -387,6 +396,11 @@ static int endelm(void *userdata, int state, const char *nspace, const char *nam ast_string_field_set(ctx->event, summary, ast_str_buffer(ctx->cdata)); ast_debug(3, "EWS: XML: Summary: %s\n", ctx->event->summary); ast_str_reset(ctx->cdata); + } else if (!strcmp(name, "Body") && state == XML_EVENT_DESCRIPTION) { + /* Event body/description end */ + ast_string_field_set(ctx->event, description, ast_str_buffer(ctx->cdata)); + ast_debug(3, "EWS: XML: Description: %s\n", ctx->event->description); + ast_str_reset(ctx->cdata); } else if (!strcmp(name, "Organizer")) { /* Event organizer end */ ast_string_field_set(ctx->event, organizer, ast_str_buffer(ctx->cdata)); -- cgit v1.2.3