icalcomponent *icalparser_clean(icalparser *parser) { icalcomponent *tail; icalerror_check_arg_rz((parser != 0), "parser"); /* We won't get a clean exit if some components did not have an "END" tag. Clear off any component that may be left in the list */ while ((tail = pvl_data(pvl_tail(parser->components))) != 0) { insert_error(tail, " ", "Missing END tag for this component. Closing component at end of input.", ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); parser->root_component = pvl_pop(parser->components); tail = pvl_data(pvl_tail(parser->components)); if (tail != 0 && parser->root_component != NULL) { if (icalcomponent_get_parent(parser->root_component) != 0) { icalerror_warn( "icalparser_clean is trying to attach a component for the second time"); } else { icalcomponent_add_component(tail, parser->root_component); } } } return parser->root_component; }
icalcomponent *icalparser_parse(icalparser *parser, icalparser_line_gen_func line_gen_func) { char *line; icalcomponent *c = 0; icalcomponent *root = 0; icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); int cont; icalerror_check_arg_rz((parser != 0), "parser"); icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL); do { line = icalparser_get_line(parser, line_gen_func); if ((c = icalparser_add_line(parser, line)) != 0) { if (icalcomponent_get_parent(c) != 0) { /* This is bad news... assert? */ } assert(parser->root_component == 0); assert(pvl_count(parser->components) == 0); if (root == 0) { /* Just one component */ root = c; } else if (icalcomponent_isa(root) != ICAL_XROOT_COMPONENT) { /*Got a second component, so move the two components under an XROOT container */ icalcomponent *tempc = icalcomponent_new(ICAL_XROOT_COMPONENT); icalcomponent_add_component(tempc, root); icalcomponent_add_component(tempc, c); root = tempc; } else if (icalcomponent_isa(root) == ICAL_XROOT_COMPONENT) { /* Already have an XROOT container, so add the component to it */ icalcomponent_add_component(root, c); } else { /* Badness */ assert(0); } c = 0; } cont = 0; if (line != 0) { icalmemory_free_buffer(line); cont = 1; } } while (cont); icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, es); return root; }
icalcomponent* icalmime_parse(char* (*get_string)(char *s, size_t size, void *d), void *data) { struct sspm_part *parts; int i, last_level=0; icalcomponent *root=0, *parent=0, *comp=0, *last = 0; if ( (parts = (struct sspm_part *) malloc(NUM_PARTS*sizeof(struct sspm_part)))==0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } memset(parts,0,sizeof(parts)); sspm_parse_mime(parts, NUM_PARTS, /* Max parts */ icalmime_local_action_map, /* Actions */ get_string, data, /* data for get_string*/ 0 /* First header */); for(i = 0; i <NUM_PARTS && parts[i].header.major != SSPM_NO_MAJOR_TYPE ; i++){ #define TMPSZ 1024 char mimetype[TMPSZ]; const char* major = sspm_major_type_string(parts[i].header.major); const char* minor = sspm_minor_type_string(parts[i].header.minor); if(parts[i].header.minor == SSPM_UNKNOWN_MINOR_TYPE ){ assert(parts[i].header.minor_text !=0); minor = parts[i].header.minor_text; } snprintf(mimetype,sizeof(mimetype),"%s/%s",major,minor); comp = icalcomponent_new(ICAL_XLICMIMEPART_COMPONENT); if(comp == 0){ /* HACK Handle Error */ assert(0); } if(parts[i].header.error!=SSPM_NO_ERROR){ const char *str="Unknown error"; char temp[256]; if(parts[i].header.error==SSPM_MALFORMED_HEADER_ERROR){ str = "Malformed header, possibly due to input not in MIME format"; } if(parts[i].header.error==SSPM_UNEXPECTED_BOUNDARY_ERROR){ str = "Got an unexpected boundary, possibly due to a MIME header for a MULTIPART part that is missing the Content-Type line"; } if(parts[i].header.error==SSPM_WRONG_BOUNDARY_ERROR){ str = "Got the wrong boundary for the opening of a MULTIPART part."; } if(parts[i].header.error==SSPM_NO_BOUNDARY_ERROR){ str = "Got a multipart header that did not specify a boundary"; } if(parts[i].header.error==SSPM_NO_HEADER_ERROR){ str = "Did not get a header for the part. Is there a blank\ line between the header and the previous boundary\?"; } if(parts[i].header.error_text != 0){ snprintf(temp,256, "%s: %s",str,parts[i].header.error_text); } else { strcpy(temp,str); } icalcomponent_add_property (comp, icalproperty_vanew_xlicerror( temp, icalparameter_new_xlicerrortype( ICAL_XLICERRORTYPE_MIMEPARSEERROR), 0)); } if(parts[i].header.major != SSPM_NO_MAJOR_TYPE && parts[i].header.major != SSPM_UNKNOWN_MAJOR_TYPE){ icalcomponent_add_property(comp, icalproperty_new_xlicmimecontenttype((char*) icalmemory_strdup(mimetype))); } if (parts[i].header.encoding != SSPM_NO_ENCODING){ icalcomponent_add_property(comp, icalproperty_new_xlicmimeencoding( sspm_encoding_string(parts[i].header.encoding))); } if (parts[i].header.filename != 0){ icalcomponent_add_property(comp, icalproperty_new_xlicmimefilename(parts[i].header.filename)); } if (parts[i].header.content_id != 0){ icalcomponent_add_property(comp, icalproperty_new_xlicmimecid(parts[i].header.content_id)); } if (parts[i].header.charset != 0){ icalcomponent_add_property(comp, icalproperty_new_xlicmimecharset(parts[i].header.charset)); } /* Add iCal components as children of the component */ if(parts[i].header.major == SSPM_TEXT_MAJOR_TYPE && parts[i].header.minor == SSPM_CALENDAR_MINOR_TYPE && parts[i].data != 0){ icalcomponent_add_component(comp, (icalcomponent*)parts[i].data); parts[i].data = 0; } else if(parts[i].header.major == SSPM_TEXT_MAJOR_TYPE && parts[i].header.minor != SSPM_CALENDAR_MINOR_TYPE && parts[i].data != 0){ /* Add other text components as "DESCRIPTION" properties */ icalcomponent_add_property(comp, icalproperty_new_description( (char*)icalmemory_strdup((char*)parts[i].data))); parts[i].data = 0; } if(root!= 0 && parts[i].level == 0){ /* We've already assigned the root, but there is another part at the root level. This is probably a parse error*/ icalcomponent_free(comp); continue; } if(parts[i].level == last_level && last_level != 0){ icalerror_assert(parent!=0,"No parent for adding component"); icalcomponent_add_component(parent,comp); } else if (parts[i].level == last_level && last_level == 0 && root == 0) { root = comp; parent = comp; } else if (parts[i].level > last_level){ parent = last; icalcomponent_add_component(parent,comp); last_level = parts[i].level; } else if (parts[i].level < last_level){ if (parent) parent = icalcomponent_get_parent(parent); icalcomponent_add_component(parent,comp); last_level = parts[i].level; } else { assert(0); } last = comp; last_level = parts[i].level; assert(parts[i].data == 0); } sspm_free_parts(parts,NUM_PARTS); free(parts); return root; }
static icalcomponent * create_user_free_busy (ECalBackendHttp *cbhttp, const gchar *address, const gchar *cn, time_t start, time_t end) { GSList *slist = NULL, *l; icalcomponent *vfb; icaltimezone *utc_zone; ECalBackendSExp *obj_sexp; ECalBackendHttpPrivate *priv; ECalBackendStore *store; gchar *query, *iso_start, *iso_end; priv = cbhttp->priv; store = priv->store; /* create the (unique) VFREEBUSY object that we'll return */ vfb = icalcomponent_new_vfreebusy (); if (address != NULL) { icalproperty *prop; icalparameter *param; prop = icalproperty_new_organizer (address); if (prop != NULL && cn != NULL) { param = icalparameter_new_cn (cn); icalproperty_add_parameter (prop, param); } if (prop != NULL) icalcomponent_add_property (vfb, prop); } utc_zone = icaltimezone_get_utc_timezone (); icalcomponent_set_dtstart (vfb, icaltime_from_timet_with_zone (start, FALSE, utc_zone)); icalcomponent_set_dtend (vfb, icaltime_from_timet_with_zone (end, FALSE, utc_zone)); /* add all objects in the given interval */ iso_start = isodate_from_time_t (start); iso_end = isodate_from_time_t (end); query = g_strdup_printf ( "occur-in-time-range? (make-time \"%s\") (make-time \"%s\")", iso_start, iso_end); obj_sexp = e_cal_backend_sexp_new (query); g_free (query); g_free (iso_start); g_free (iso_end); if (!obj_sexp) return vfb; slist = e_cal_backend_store_get_components (store); for (l = slist; l; l = g_slist_next (l)) { ECalComponent *comp = l->data; icalcomponent *icalcomp, *vcalendar_comp; icalproperty *prop; icalcomp = e_cal_component_get_icalcomponent (comp); if (!icalcomp) continue; /* If the event is TRANSPARENT, skip it. */ prop = icalcomponent_get_first_property ( icalcomp, ICAL_TRANSP_PROPERTY); if (prop) { icalproperty_transp transp_val = icalproperty_get_transp (prop); if (transp_val == ICAL_TRANSP_TRANSPARENT || transp_val == ICAL_TRANSP_TRANSPARENTNOCONFLICT) continue; } if (!e_cal_backend_sexp_match_comp ( obj_sexp, l->data, E_TIMEZONE_CACHE (cbhttp))) continue; vcalendar_comp = icalcomponent_get_parent (icalcomp); if (!vcalendar_comp) vcalendar_comp = icalcomp; e_cal_recur_generate_instances ( comp, start, end, free_busy_instance, vfb, resolve_tzid, vcalendar_comp, icaltimezone_get_utc_timezone ()); } g_object_unref (obj_sexp); return vfb; }