Back to index

lightning-sunbird  0.9+nobinonly
Functions
icalparameter.c File Reference
#include "icalparameter.h"
#include "icalproperty.h"
#include "icalerror.h"
#include "icalmemory.h"
#include "icalparameterimpl.h"
#include <stdlib.h>
#include <errno.h>
#include <string.h>

Go to the source code of this file.

Functions

icalparameter * icalparameter_new_from_value_string (icalparameter_kind kind, const char *val)
struct icalparameter_implicalparameter_new_impl (icalparameter_kind kind)
icalparameter * icalparameter_new (icalparameter_kind kind)
icalparameter * icalparameter_new_x_name (const char *name, const char *value)
void icalparameter_free (icalparameter *param)
icalparameter * icalparameter_new_clone (icalparameter *old)
icalparameter * icalparameter_new_from_string (const char *str)
char * icalparameter_as_ical_string (icalparameter *param)
 Return a string representation of the parameter according to RFC2445.
int icalparameter_is_valid (icalparameter *parameter)
icalparameter_kind icalparameter_isa (icalparameter *parameter)
int icalparameter_isa_parameter (void *parameter)
void icalparameter_set_xname (icalparameter *param, const char *v)
const char * icalparameter_get_xname (icalparameter *param)
void icalparameter_set_xvalue (icalparameter *param, const char *v)
const char * icalparameter_get_xvalue (icalparameter *param)
void icalparameter_set_parent (icalparameter *param, icalproperty *property)
icalproperty * icalparameter_get_parent (icalparameter *param)

Function Documentation

char* icalparameter_as_ical_string ( icalparameter *  param)

Return a string representation of the parameter according to RFC2445.

param = param-name "=" param-value param-name = iana-token / x-token param-value = paramtext /quoted-string paramtext = *SAFE-SHARE quoted-string= DQUOTE *QSAFE-CHARE DQUOTE QSAFE-CHAR = any character except CTLs and DQUOTE SAFE-CHAR = any character except CTLs, DQUOTE. ";", ":", ","

Definition at line 224 of file icalparameter.c.

{
    size_t buf_size = 1024;
    char* buf; 
    char* buf_ptr;
    char *out_buf;
    const char *kind_string;

    icalerror_check_arg_rz( (param!=0), "parameter");

    /* Create new buffer that we can append names, parameters and a
       value to, and reallocate as needed. Later, this buffer will be
       copied to a icalmemory_tmp_buffer, which is managed internally
       by libical, so it can be given to the caller without fear of
       the caller forgetting to free it */

    buf = icalmemory_new_buffer(buf_size);
    buf_ptr = buf;

    if(param->kind == ICAL_X_PARAMETER) {

       icalmemory_append_string(&buf, &buf_ptr, &buf_size, 
                             icalparameter_get_xname(param));

    } else {

       kind_string = icalparameter_kind_to_string(param->kind);
       
       if (param->kind == ICAL_NO_PARAMETER || 
           param->kind == ICAL_ANY_PARAMETER || 
           kind_string == 0)
       {
           icalerror_set_errno(ICAL_BADARG_ERROR);
           return 0;
       }
       
       
       /* Put the parameter name into the string */
       icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string);

    }

    icalmemory_append_string(&buf, &buf_ptr, &buf_size, "=");

    if(param->string !=0){
        int qm = 0;

       /* Encapsulate the property in quotes if necessary */
       if (strpbrk(param->string, ";:,") != 0) {
              icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"');
              qm = 1;
       }
        icalmemory_append_string(&buf, &buf_ptr, &buf_size, param->string); 
       if (qm == 1) {
              icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"');
       }
    } else if (param->data != 0){
        const char* str = icalparameter_enum_to_string(param->data);
        icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); 
    } else {
        icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
        return 0;
    }

    /* Now, copy the buffer to a tmp_buffer, which is safe to give to
       the caller without worring about de-allocating it. */
    
    out_buf = icalmemory_tmp_copy(buf);
    icalmemory_free_buffer(buf);

    return out_buf;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void icalparameter_free ( icalparameter *  param)

Definition at line 98 of file icalparameter.c.

{

/*  HACK. This always triggers, even when parameter is non-zero
    icalerror_check_arg_rv((parameter==0),"parameter");*/


#ifdef ICAL_FREE_ON_LIST_IS_ERROR
    icalerror_assert( (param->parent ==0),"Tried to free a parameter that is still attached to a component. ");
    
#else
    if(param->parent !=0){
       return;
    }
#endif

    
    if (param->string != 0){
       free ((void*)param->string);
    }
    
    if (param->x_name != 0){
       free ((void*)param->x_name);
    }
    
    memset(param,0,sizeof(param));

    param->parent = 0;
    param->id[0] = 'X';
    free(param);
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalproperty* icalparameter_get_parent ( icalparameter *  param)

Definition at line 391 of file icalparameter.c.

{
    icalerror_check_arg_rz( (param!=0),"param");

    return param->parent;
}
const char* icalparameter_get_xname ( icalparameter *  param)

Definition at line 350 of file icalparameter.c.

{
    icalerror_check_arg_rz( (param!=0),"param");

    return param->x_name;
}

Here is the caller graph for this function:

const char* icalparameter_get_xvalue ( icalparameter *  param)

Definition at line 376 of file icalparameter.c.

{
    icalerror_check_arg_rz( (param!=0),"param");

    return param->string;
}

Here is the caller graph for this function:

int icalparameter_is_valid ( icalparameter *  parameter)
icalparameter_kind icalparameter_isa ( icalparameter *  parameter)

Definition at line 304 of file icalparameter.c.

{
    if(parameter == 0){
       return ICAL_NO_PARAMETER;
    }

    return parameter->kind;
}

Here is the caller graph for this function:

Definition at line 315 of file icalparameter.c.

{
    struct icalparameter_impl *impl = (struct icalparameter_impl *)parameter;

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

    if (strcmp(impl->id,"para") == 0) {
       return 1;
    } else {
       return 0;
    }
}

Here is the caller graph for this function:

icalparameter* icalparameter_new ( icalparameter_kind  kind)

Definition at line 72 of file icalparameter.c.

{
    struct icalparameter_impl* v = icalparameter_new_impl(kind);

    return (icalparameter*) v;

}

Here is the call graph for this function:

Here is the caller graph for this function:

icalparameter* icalparameter_new_clone ( icalparameter *  old)

Definition at line 133 of file icalparameter.c.

{
    struct icalparameter_impl *new;

    new = icalparameter_new_impl(old->kind);

    icalerror_check_arg_rz((old!=0),"param");

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

    memcpy(new,old,sizeof(struct icalparameter_impl));

    if (old->string != 0){
       new->string = icalmemory_strdup(old->string);
       if (new->string == 0){
           icalparameter_free(new);
           return 0;
       }
    }

    if (old->x_name != 0){
       new->x_name = icalmemory_strdup(old->x_name);
       if (new->x_name == 0){
           icalparameter_free(new);
           return 0;
       }
    }

    return new;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalparameter* icalparameter_new_from_string ( const char *  str)

Definition at line 166 of file icalparameter.c.

{
    char* eq;
    char* cpy;
    icalparameter_kind kind;
    icalparameter *param;

    icalerror_check_arg_rz(str != 0,"str");

    cpy = icalmemory_strdup(str);

    if (cpy == 0){
        icalerror_set_errno(ICAL_NEWFAILED_ERROR);
        return 0;
    }

    eq = strchr(cpy,'=');

    if(eq == 0){
        icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
        return 0;
    }

    *eq = '\0';

    eq++;

    kind = icalparameter_string_to_kind(cpy);

    if(kind == ICAL_NO_PARAMETER){
        icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
        return 0;
    }

    param = icalparameter_new_from_value_string(kind,eq);

    if(kind == ICAL_X_PARAMETER){
        icalparameter_set_xname(param,cpy);
    }

    free(cpy);

    return param;
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalparameter* icalparameter_new_from_value_string ( icalparameter_kind  kind,
const char *  val 
)

Definition at line 1157 of file icalderivedparameter.c.

{

    struct icalparameter_impl* param=0;
    int found_kind = 0;
    int i;

    icalerror_check_arg_rz((val!=0),"val");

    /* Search through the parameter map to find a matching kind */

    param = icalparameter_new_impl(kind);

    for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
        if(kind == icalparameter_map[i].kind) {
            found_kind = 1;
            if(strcmp(val,icalparameter_map[i].str) == 0) {

                param->data = (int)icalparameter_map[i].enumeration;
                return param;
            }
        }
    }
    
    if(found_kind == 1){
        /* The kind was in the parameter map, but the string did not
           match, so assume that it is an alternate value, like an
           X-value.*/
        
        icalparameter_set_xvalue(param, val);

    } else {
 
        /* If the kind was not found, then it must be a string type */
        
        ((struct icalparameter_impl*)param)->string = icalmemory_strdup(val);

    }

   return param;
}

Definition at line 49 of file icalparameter.c.

{
    struct icalparameter_impl* v;

    if ( ( v = (struct icalparameter_impl*)
          malloc(sizeof(struct icalparameter_impl))) == 0) {
       icalerror_set_errno(ICAL_NEWFAILED_ERROR);
       return 0;
    }
    
    strcpy(v->id,"para");

    v->kind = kind;
    v->size = 0;
    v->string = 0;
    v->x_name = 0;
    v->parent = 0;
    v->data = 0;

    return v;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalparameter* icalparameter_new_x_name ( const char *  name,
const char *  value 
)

Definition at line 81 of file icalparameter.c.

                                                              {

       icalparameter  *ret;

       if (name == NULL || value == NULL)
              return NULL;

       ret = icalparameter_new_x(value);
       if (ret == NULL)
              return NULL;

       icalparameter_set_xname(ret, name);

       return ret;   
}

Here is the call graph for this function:

void icalparameter_set_parent ( icalparameter *  param,
icalproperty *  property 
)

Definition at line 383 of file icalparameter.c.

{
    icalerror_check_arg_rv( (param!=0),"param");

    param->parent = property;
}
void icalparameter_set_xname ( icalparameter *  param,
const char *  v 
)

Definition at line 332 of file icalparameter.c.

{
    icalerror_check_arg_rv( (param!=0),"param");
    icalerror_check_arg_rv( (v!=0),"v");

    if (param->x_name != 0){
       free((void*)param->x_name);
    }

    param->x_name = icalmemory_strdup(v);

    if (param->x_name == 0){
       errno = ENOMEM;
    }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void icalparameter_set_xvalue ( icalparameter *  param,
const char *  v 
)

Definition at line 358 of file icalparameter.c.

{
    icalerror_check_arg_rv( (param!=0),"param");
    icalerror_check_arg_rv( (v!=0),"v");

    if (param->string != 0){
       free((void*)param->string);
    }

    param->string = icalmemory_strdup(v);

    if (param->string == 0){
       errno = ENOMEM;
    }

}

Here is the call graph for this function:

Here is the caller graph for this function: