void test_properties()
{
    icalproperty *prop;
    icalparameter *param;
    icalvalue *value;
    char *str;

    icalproperty *clone;

    /* Create a new property */
    prop = icalproperty_vanew_comment(
        "Another Comment",
        icalparameter_new_cn("A Common Name 1"),
        icalparameter_new_cn("A Common Name 2"),
        icalparameter_new_cn("A Common Name 3"),
        icalparameter_new_cn("A Common Name 4"),
        0);

    /* Iterate through all of the parameters in the property */
    for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER);
        param != 0;
        param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) {

        printf("Prop parameter: %s\n",icalparameter_get_cn(param));
    }

    /* Get a string representation of the property's value */
    printf("Prop value: %s\n",icalproperty_get_comment(prop));

    /* Spit out the property in its RFC 5545 representation */
    str = icalproperty_as_ical_string_r(prop);
    printf("As iCAL string:\n %s\n", str);
    free(str);

    /* Make a copy of the property. Caller owns the memory */
    clone = icalproperty_new_clone(prop);

    /* Get a reference to the value within the clone property */
    value = icalproperty_get_value(clone);

    str = icalvalue_as_ical_string_r(value);
    printf("Value: %s", str);
    free(str);

    /* Free the original and the clone */
    icalproperty_free(clone);
    icalproperty_free(prop);

}
Пример #2
0
RRCAPCmdArgs *
msg_parse(RRCAP *cap, icalcomponent *comp) {

	icalproperty   *prop;
	icalparameter  *param;
	icalvalue      *value;
	RRCAPCmdArgs   *ret = g_new0(RRCAPCmdArgs, 1);
	char *str;

	ret->comp = comp;

	/* Find the command */
	if ((prop = icalcomponent_get_first_property(comp, ICAL_CMD_PROPERTY)) == NULL) {
		rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND,
			"No CMD sent", NULL);
		goto FAILED;
	}
	if ((value = icalproperty_get_value(prop)) == NULL) {
		str = icalproperty_as_ical_string_r(prop);
		rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND,
			"CMD has no value", str);
		free(str);
		goto FAILED;
	}
	ret->cmd = icalvalue_get_cmd(value);

	/* Look for params */

	/* ID */
	if ((param = icalproperty_get_first_parameter(prop,
						ICAL_ID_PARAMETER)) != NULL) {
		if ((ret->id = icalparameter_get_id(param)) == NULL) {
			str = icalproperty_as_ical_string_r(prop);
			rr_cap_send_error(cap, NULL,
				ICAL_9_0_UNRECOGNIZED_COMMAND,
				"ID param is garbled",
				str);
			free(str);
			goto FAILED;
		}
	}

	/* LATENCY */
	if ((param = icalproperty_get_first_parameter(prop,
						ICAL_LATENCY_PARAMETER)) != NULL) {
		const char *tmp;
		if ((tmp = icalparameter_get_latency(param)) == NULL) {
			str = icalproperty_as_ical_string_r(prop);
			rr_cap_send_error(cap, NULL,
				ICAL_9_0_UNRECOGNIZED_COMMAND,
				"LATENCY is garbled",
				str);
			free(str);
			goto FAILED;
		}

		ret->latency = atoi(tmp);
	}

	/* ACTION */
	if ((param = icalproperty_get_first_parameter(prop,
						ICAL_ACTIONPARAM_PARAMETER)) != NULL) {
		if ((ret->action = icalparameter_get_actionparam(param))
		    == NULL) {
			str = icalproperty_as_ical_string_r(prop);
			rr_cap_send_error(cap, NULL,
				ICAL_9_0_UNRECOGNIZED_COMMAND,
				"ACTION is garbled",
				str);
			free(str);
			goto FAILED;
		}
	}

	if ((ret->latency >= 0) ^ (ret->action != ICAL_ACTIONPARAM_NONE)) {
		str = icalproperty_as_ical_string_r(prop);
		rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND,
			"LATENCY and ACTION must be both present",
			str);
		free(str);
		goto FAILED;
	}

	return ret;

FAILED:
	g_free(ret);
	return NULL;
}