nsresult calIcalComponent::SetPropertyValue(icalproperty_kind kind, icalvalue *val) { ClearAllProperties(kind); if (!val) return NS_OK; icalproperty *prop = icalproperty_new(kind); if (!prop) { icalvalue_free(val); return NS_ERROR_OUT_OF_MEMORY; } icalproperty_set_value(prop, val); icalcomponent_add_property(mComponent, prop); return NS_OK; }
static icalproperty * ical_property_add_x_property_value(icalcomponent *parent, const char *propname, const char *value) { icalproperty *prop; icalvalue *icalText; /* Sanity checks */ if (!parent) return NULL; if (!propname) return NULL; if (!value) return NULL; icalText = icalvalue_new_text(value); prop = icalproperty_new_x(icalvalue_as_ical_string(icalText)); icalvalue_free(icalText); icalproperty_set_x_name(prop, propname); icalcomponent_add_property(parent, prop); return prop; }
int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) { icalcomponent *inner; int local_pass = 0; int last_clause = 1, this_clause = 1; pvl_elem e; icalcomponent_kind kind; icalproperty *rrule; int compare_recur = 0; icalerror_check_arg_rz( (comp!=0), "comp"); icalerror_check_arg_rz( (gauge!=0), "gauge"); if (gauge == 0 || comp == 0) return 0; inner = icalcomponent_get_first_real_component(comp); if(inner == 0){ /* Wally Yau: our component is not always wrapped with * a <VCALENDAR>. It's not an error. * icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); * return 0; */ kind = icalcomponent_isa(comp); if(kind == ICAL_VEVENT_COMPONENT || kind == ICAL_VTODO_COMPONENT || kind == ICAL_VJOURNAL_COMPONENT || kind == ICAL_VQUERY_COMPONENT || kind == ICAL_VAGENDA_COMPONENT){ inner = comp; } else { icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); return 0; } inner = comp; } /* Check that this component is one of the FROM types */ local_pass = 0; for(e = pvl_head(gauge->from);e!=0;e=pvl_next(e)){ icalcomponent_kind k = (icalcomponent_kind)pvl_data(e); if(k == icalcomponent_isa(inner)){ local_pass=1; } } if(local_pass == 0){ return 0; } /**** Check each where clause against the component ****/ for(e = pvl_head(gauge->where);e!=0;e=pvl_next(e)){ struct icalgauge_where *w = pvl_data(e); icalcomponent *sub_comp; icalvalue *v; icalproperty *prop; icalvalue_kind vk; if(w->prop == ICAL_NO_PROPERTY || w->value == 0){ icalerror_set_errno(ICAL_INTERNAL_ERROR); return 0; } /* First, create a value from the gauge */ vk = icalenum_property_kind_to_value_kind(w->prop); if(vk == ICAL_NO_VALUE){ icalerror_set_errno(ICAL_INTERNAL_ERROR); return 0; } if (w->compare == ICALGAUGECOMPARE_ISNULL || w->compare == ICALGAUGECOMPARE_ISNOTNULL) v = icalvalue_new(vk); else v = icalvalue_new_from_string(vk,w->value); if (v == 0){ /* Keep error set by icalvalue_from-string*/ return 0; } /* Now find the corresponding property in the component, descending into a sub-component if necessary */ if(w->comp == ICAL_NO_COMPONENT){ sub_comp = inner; } else { sub_comp = icalcomponent_get_first_component(inner,w->comp); if(sub_comp == 0){ return 0; } } /* check if it is a recurring */ rrule = icalcomponent_get_first_property(sub_comp,ICAL_RRULE_PROPERTY); if (gauge->expand && rrule) { if (w->prop == ICAL_DTSTART_PROPERTY || w->prop == ICAL_DTEND_PROPERTY || w->prop == ICAL_DUE_PROPERTY){ /** needs to use recurrence-id to do comparison */ compare_recur = 1; } } this_clause = 0; local_pass = (w->compare == ICALGAUGECOMPARE_ISNULL) ? 1 : 0; for(prop = icalcomponent_get_first_property(sub_comp,w->prop); prop != 0; prop = icalcomponent_get_next_property(sub_comp,w->prop)){ icalvalue* prop_value; icalgaugecompare relation; if (w->compare == ICALGAUGECOMPARE_ISNULL) { local_pass = 0; break; } if (w->compare == ICALGAUGECOMPARE_ISNOTNULL) { local_pass = 1; break; } if (compare_recur) { icalproperty *p = icalcomponent_get_first_property(sub_comp, ICAL_RECURRENCEID_PROPERTY); prop_value = icalproperty_get_value(p); } else /* prop value from this component */ prop_value = icalproperty_get_value(prop); relation = (icalgaugecompare)icalvalue_compare(prop_value,v); if (relation == w->compare){ local_pass++; } else if (w->compare == ICALGAUGECOMPARE_LESSEQUAL && ( relation == ICALGAUGECOMPARE_LESS || relation == ICALGAUGECOMPARE_EQUAL)) { local_pass++; } else if (w->compare == ICALGAUGECOMPARE_GREATEREQUAL && ( relation == ICALGAUGECOMPARE_GREATER || relation == ICALGAUGECOMPARE_EQUAL)) { local_pass++; } else if (w->compare == ICALGAUGECOMPARE_NOTEQUAL && ( relation == ICALGAUGECOMPARE_GREATER || relation == ICALGAUGECOMPARE_LESS)) { local_pass++; } else { local_pass = 0; } } this_clause = local_pass > 0 ? 1 : 0; /* Now look at the logic operator for this clause to see how the value should be merge with the previous clause */ if(w->logic == ICALGAUGELOGIC_AND){ last_clause = this_clause && last_clause; } else if(w->logic == ICALGAUGELOGIC_OR) { last_clause = this_clause || last_clause; } else { last_clause = this_clause; } icalvalue_free(v); }/**** check next one in where clause ****/ return last_clause; }