Ejemplo n.º 1
0
/*
 * Add an iCalendar parameter to an existing JSON object.
 */
static void icalparameter_as_json_object_member(icalparameter *param,
                                                json_t *jparams)
{
    icalparameter_kind kind;
    const char *kind_string, *value_string;

    kind = icalparameter_isa(param);

    switch (kind) {
    case ICAL_X_PARAMETER:
        kind_string = icalparameter_get_xname(param);
        break;

#ifdef HAVE_IANA_PARAMS
    case ICAL_IANA_PARAMETER:
        kind_string = icalparameter_get_iana_name(param);
        break;
#endif

    default:
        kind_string = icalparameter_kind_to_string(kind);
        if (kind_string) break;

    case ICAL_NO_PARAMETER:
    case ICAL_ANY_PARAMETER:
            icalerror_set_errno(ICAL_BADARG_ERROR);
            return;
    }

    /* XXX  Need to handle multi-valued parameters */
    value_string = icalparameter_get_xvalue(param);
    if (!value_string) {
        icalparameter_value value = icalparameter_get_value(param);

        if (value) value_string = icalparameter_enum_to_string(value);
    }
    if (!value_string) return;

    json_object_set_new(jparams, lcase(icalmemory_tmp_copy(kind_string)),
                        json_string(value_string));
}
Ejemplo n.º 2
0
/*
 * Construct an XML element for an iCalendar parameter.
 */
static xmlNodePtr icalparameter_as_xml_element(icalparameter *param)
{
    icalparameter_kind kind;
    icalparameter_value value;
    const char *kind_string, *type_string, *value_string;
    xmlNodePtr xparam;

    kind = icalparameter_isa(param);

    switch (kind) {
    case ICAL_X_PARAMETER:
        kind_string = icalparameter_get_xname(param);
        break;

#ifdef HAVE_IANA_PARAMS
    case ICAL_IANA_PARAMETER:
        kind_string = icalparameter_get_iana_name(param);
        break;
#endif

    default:
        kind_string = icalparameter_kind_to_string(kind);
        if (kind_string) break;

    case ICAL_NO_PARAMETER:
    case ICAL_ANY_PARAMETER:
        icalerror_set_errno(ICAL_BADARG_ERROR);
        return NULL;
    }

    /* Get value type */
    switch (kind) {
    case ICAL_ALTREP_PARAMETER:
    case ICAL_DIR_PARAMETER:
        type_string = "uri";
        break;

    case ICAL_DELEGATEDFROM_PARAMETER:
    case ICAL_DELEGATEDTO_PARAMETER:
    case ICAL_MEMBER_PARAMETER:
    case ICAL_SENTBY_PARAMETER:
        type_string = "cal-address";
        break;

    case ICAL_RSVP_PARAMETER:
        type_string = "boolean";
        break;

    default:
        type_string = "text";
        break;
    }

    /* XXX  Need to handle multi-valued parameters */
    value = icalparameter_get_value(param);
    if (value == ICAL_VALUE_X) value_string = icalparameter_get_xvalue(param);
    else value_string = icalparameter_enum_to_string(value);
    if (!value_string) return NULL;

    xparam = xmlNewNode(NULL, BAD_CAST lcase(icalmemory_tmp_copy(kind_string)));
    xmlNewTextChild(xparam, NULL, BAD_CAST type_string, BAD_CAST value_string);

    return xparam;
}