Logo Search packages:      
Sourcecode: libical version File versions  Download package

int icalgauge_compare ( icalgauge *  g,
icalcomponent *  comp 
)

Return true if comp matches the gauge.

The component must be in cannonical form -- a VCALENDAR with one VEVENT, VTODO or VJOURNAL sub component

needs to use recurrence-id to do comparison

Definition at line 276 of file icalgauge.c.

{

    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;

}


Generated by  Doxygen 1.6.0   Back to index