NS_IMETHODIMP
calIcalProperty::GetNextParameterName(nsACString &name)
{
    icalparameter *icalparam =
        icalproperty_get_next_parameter(mProperty,
                                        ICAL_ANY_PARAMETER);
    return FillParameterName(icalparam, name);
}
/**
 * get parameters from the icalendar property and store them in the internal
 * struct if the parameter describes a hidden or inline attachment.
 */
static void
add_e_attachment_parameters(icalproperty *prop, I_common *i_common, gboolean inln)
{
	gboolean binary = FALSE;
	gchar* mime_type = NULL;
	gchar* label = NULL;

	/* iterate over all parameters of the attachment property */
	int i, pc = icalproperty_count_parameters(prop);
	icalparameter *para;
	for (i = 0; i < pc; i++) {
		icalparameter_kind kind;
		icalparameter_value xvalue;

		para = i == 0 ? icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER) :
			icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER);

		kind = icalparameter_isa(para);
		xvalue = icalparameter_get_value(para);
		if (kind == ICAL_VALUE_PARAMETER && xvalue == ICAL_VALUE_BINARY)
			binary = TRUE; /* not a link attachment */
		else if (kind == ICAL_FMTTYPE_PARAMETER) /* found mime type */
			mime_type = (gchar*) icalparameter_get_xvalue(para);
		else if (xvalue == ICAL_VALUE_X) { /* found attachment name */
			const char* name = icalparameter_get_xname(para);
			const char* value = icalparameter_get_xvalue(para);
			if (name && strcmp(name, ICONTACT_KOLAB_STORE_ATTACHMENT_NAME) == 0)
				label = (gchar*) value;
		}
	}

	if (binary) { /* if not a linked attachment add data to struct */
		Kolab_conv_mail_part *mpart = g_new0(Kolab_conv_mail_part, 1);
		gchar* pname = NULL;

		if (label != NULL) {
			if (inln)
				i_common->inline_attachment_names = g_list_append(
				                                                  i_common->inline_attachment_names,
				                                                  strdup(label));
			mpart->name = strdup(label);
		}
		if (mime_type != NULL)
			mpart->mime_type = strdup(mime_type);
		/* add data and length */
		pname = (gchar*) icalproperty_get_value_as_string(prop);
		if (pname) {
			gsize outlen;
			mpart->data = (gchar*) g_base64_decode (pname, &outlen);
			mpart->length = outlen;
			/* add created mail part to the attachment list */
			i_common->kolab_attachment_store = g_list_append(i_common->kolab_attachment_store, mpart);
		}
	}
}
示例#3
0
icalparameter* icalproperty_get_iana_parameter_by_name(icalproperty *prop,
                                                       const char *name)
{
    icalparameter *param;

    for (param = icalproperty_get_first_parameter(prop, ICAL_IANA_PARAMETER);
         param && strcmp(icalparameter_get_iana_name(param), name);
         param = icalproperty_get_next_parameter(prop, ICAL_IANA_PARAMETER));

    return param;
}
static icalparameter*
FindParameter(icalproperty *prop, const nsACString &param, icalparameter_kind kind)
{
    for (icalparameter *icalparam =
             icalproperty_get_first_parameter(prop, kind);
         icalparam;
         icalparam = icalproperty_get_next_parameter(prop, kind)) {
        if (param.Equals(icalparameter_get_xname(icalparam)))
            return icalparam;
    }
    return nullptr;
}
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);

}
示例#6
0
/*
 * Construct an XML element for an iCalendar property.
 */
static xmlNodePtr icalproperty_as_xml_element(icalproperty *prop)
{
    icalproperty_kind prop_kind;
    const char *x_name, *property_name = NULL;
    icalparameter *param;
    xmlNodePtr xprop, xparams = NULL;

    if (!prop) return NULL;

    prop_kind = icalproperty_isa(prop);
    x_name = icalproperty_get_x_name(prop);

    if (prop_kind == ICAL_X_PROPERTY && x_name)
        property_name = x_name;
    else
        property_name = icalproperty_kind_to_string(prop_kind);

    if (!property_name) {
        icalerror_warn("Got a property of an unknown kind.");
        return NULL;
    }

    /* Create property */
    xprop = xmlNewNode(NULL,
                       BAD_CAST lcase(icalmemory_tmp_copy(property_name)));


    /* Add parameters */
    for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
            param != 0;
            param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {

        if (icalparameter_isa(param) == ICAL_VALUE_PARAMETER) continue;

        if (!xparams)
            xparams = xmlNewChild(xprop, NULL, BAD_CAST "parameters", NULL);

        xmlAddChild(xparams, icalparameter_as_xml_element(param));
    }


    /* Add value */
    icalproperty_add_value_as_xml_element(xprop, prop);

    return xprop;
}
static void
patch_tzids (icalcomponent *subcomp,
             GHashTable *mapping)
{
	gchar *tzid = NULL;

	if (icalcomponent_isa (subcomp) != ICAL_VTIMEZONE_COMPONENT) {
		icalproperty *prop = icalcomponent_get_first_property (
			subcomp, ICAL_ANY_PROPERTY);
		while (prop) {
			icalparameter *param = icalproperty_get_first_parameter (
				prop, ICAL_TZID_PARAMETER);
			while (param) {
				const gchar *oldtzid;
				const gchar *newtzid;

				g_free (tzid);
				tzid = g_strdup (icalparameter_get_tzid (param));

				if (!g_hash_table_lookup_extended (
					mapping, tzid,
					(gpointer *) &oldtzid,
					(gpointer *) &newtzid)) {
					/* Corresponding VTIMEZONE not seen before! */
					newtzid = e_cal_match_tzid (tzid);
				}
				if (newtzid) {
					icalparameter_set_tzid (param, newtzid);
				}
				param = icalproperty_get_next_parameter (
					prop, ICAL_TZID_PARAMETER);
			}
			prop = icalcomponent_get_next_property (
				subcomp, ICAL_ANY_PROPERTY);
		}
	}

	g_free (tzid);
}
示例#8
0
icalparameter *icallangbind_get_next_parameter(icalproperty *prop)
{
    icalparameter_kind kind = ICAL_ANY_PARAMETER;

    return icalproperty_get_next_parameter(prop, kind);
}
示例#9
0
char *icallangbind_property_eval_string_r(icalproperty *prop, char *sep)
{
    char tmp[25];
    size_t buf_size = 1024;
    char *buf;
    char *buf_ptr;
    icalparameter *param;

    icalvalue *value;

    if (prop == 0) {
        return 0;
    }

    buf = icalmemory_new_buffer(buf_size);
    buf_ptr = buf;

    APPENDS("{ ");

    value = icalproperty_get_value(prop);

    APPENDS(" 'name' ");
    APPENDS(sep);
    APPENDC('\'');
    APPENDS(icalproperty_kind_to_string(icalproperty_isa(prop)));
    APPENDC('\'');

    if (value) {
        APPENDS(", 'value_type' ");
        APPENDS(sep);
        APPENDC('\'');
        APPENDS(icalvalue_kind_to_string(icalvalue_isa(value)));
        APPENDC('\'');
    }

    APPENDS(", 'pid' ");
    APPENDS(sep);
    APPENDC('\'');
    snprintf(tmp, 25, "%p", prop);
    APPENDS(tmp);
    APPENDC('\'');

    if (value) {
        switch (icalvalue_isa(value)) {

        case ICAL_ATTACH_VALUE:
        case ICAL_BINARY_VALUE:
        case ICAL_NO_VALUE:{
                icalerror_set_errno(ICAL_INTERNAL_ERROR);
                break;
            }

        default:
            {
                char *str = icalvalue_as_ical_string_r(value);
                char *copy = (char *)malloc(strlen(str) + 1);

                const char *i;
                char *j;

                if (copy == 0) {
                    icalerror_set_errno(ICAL_NEWFAILED_ERROR);
                    break;
                }
                /* Remove any newlines */

                for (j = copy, i = str; *i != 0; j++, i++) {
                    if (*i == '\n') {
                        i++;
                    }
                    *j = *i;
                }

                *j = 0;

                APPENDS(", 'value'");
                APPENDS(sep);
                APPENDC('\'');
                APPENDS(copy);
                APPENDC('\'');

                free(copy);
                free(str);
                break;
            }
        }
    }

    /* Add Parameters */

    for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
         param != 0; param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {

        char *copy = icalparameter_as_ical_string_r(param);
        char *v;

        if (copy == 0) {
            icalerror_set_errno(ICAL_NEWFAILED_ERROR);
            continue;
        }

        v = strchr(copy, '=');

        if (v == 0) {
            free(copy);
            continue;
        }

        *v = 0;

        v++;

        APPENDS(", ");
        APPENDC('\'');
        APPENDS(copy);
        APPENDC('\'');
        APPENDS(sep);
        APPENDC('\'');
        APPENDS(v);
        APPENDC('\'');
        free(copy);
    }

    APPENDC('}');

    return buf;
}
示例#10
0
/*
 * Construct a JSON array for an iCalendar property.
 */
static json_t *icalproperty_as_json_array(icalproperty *prop)
{
    icalproperty_kind prop_kind;
    const char *x_name, *property_name = NULL;
    icalparameter *param;
    const char *type = NULL;
    const icalvalue *value;
    json_t *jprop, *jparams;

    if (!prop) return NULL;

    prop_kind = icalproperty_isa(prop);
    x_name = icalproperty_get_x_name(prop);

    if (prop_kind == ICAL_X_PROPERTY && x_name)
        property_name = x_name;
    else
        property_name = icalproperty_kind_to_string(prop_kind);

    if (!property_name) {
        icalerror_warn("Got a property of an unknown kind.");
        return NULL;
    }

    /* Create property array */
    jprop = json_array();


    /* Add property name */
    json_array_append_new(jprop,
                          json_string(lcase(icalmemory_tmp_copy(property_name))));


    /* Add parameters */
    jparams = json_object();
    for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
         param != 0;
         param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {

        if (icalparameter_isa(param) == ICAL_VALUE_PARAMETER) continue;

        icalparameter_as_json_object_member(param, jparams);
    }
    json_array_append_new(jprop, jparams);


    /* Add type */
    type = icalproperty_value_kind_as_string(prop);
    json_array_append_new(jprop, json_string(lcase(icalmemory_tmp_copy(type))));


    /* Add value */
    value = icalproperty_get_value(prop);
    if (value) {
        switch (icalproperty_isa(prop)) {
        case ICAL_CATEGORIES_PROPERTY:
        case ICAL_RESOURCES_PROPERTY:
        case ICAL_POLLPROPERTIES_PROPERTY:
            if (icalvalue_isa(value) == ICAL_TEXT_VALUE) {
                /* Handle multi-valued properties */
                const char *str = icalvalue_as_ical_string(value);
                tok_t tok;

                tok_init(&tok, str, ",", TOK_TRIMLEFT|TOK_TRIMRIGHT|TOK_EMPTY);
                while ((str = tok_next(&tok))) {
                    if (*str) json_array_append_new(jprop, json_string(str));
                }
                tok_fini(&tok);
                break;
            }

        default:
            json_array_append_new(jprop, icalvalue_as_json_object(value));
            break;
        }
    }

    return jprop;
}