Index: res/res_calendar_ews.c =================================================================== --- res/res_calendar_ews.c (revision 282606) +++ res/res_calendar_ews.c (working copy) @@ -99,6 +99,7 @@ ne_uri uri; ne_session *session; struct ao2_container *events; + unsigned int items; }; static void ewscal_destructor(void *obj) @@ -166,7 +167,7 @@ { struct xml_context *ctx = userdata; - ast_debug(3, "EWS: XML: Start: %s\n", name); + ast_debug(5, "EWS: XML: Start: %s\n", name); if (ctx->op == XML_OP_CREATE) { return NE_XML_DECLINE; } @@ -184,7 +185,7 @@ return 1; } else if (!strcmp(name, "RootFolder")) { /* Get number of events */ - int items; + unsigned int items; ast_debug(3, "EWS: XML: \n"); if (sscanf(ne_xml_get_attr(ctx->parser, atts, NULL, "TotalItemsInView"), "%d", &items) != 1) { @@ -194,6 +195,7 @@ } ast_debug(3, "EWS: %d calendar items to load\n", items); + ctx->pvt->items = items; if (items < 1) { /* Stop processing XML if there are no events */ return NE_XML_DECLINE; @@ -391,8 +393,11 @@ } } else if (!strcmp(name, "Envelope")) { /* Events end */ - ast_debug(3, "EWS: XML: All events has been parsed, merging…\n"); - ast_calendar_merge_events(ctx->pvt->owner, ctx->pvt->events); + ast_debug(3, "EWS: XML: %d of %d event(s) has been parsed…\n", ao2_container_count(ctx->pvt->events), ctx->pvt->items); + if (ao2_container_count(ctx->pvt->events) >= ctx->pvt->items) { + ast_debug(3, "EWS: XML: All events has been parsed, merging…\n"); + ast_calendar_merge_events(ctx->pvt->owner, ctx->pvt->events); + } } return 0;