Back to index

lightning-sunbird  0.9+nobinonly
icalderivedvalue.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*- */
00002 /*======================================================================
00003   FILE: icalvalue.c
00004   CREATOR: eric 02 May 1999
00005   
00006   $Id: icalderivedvalue.c,v 1.5 2002/09/01 19:12:31 gray-john Exp $
00007 
00008 
00009  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
00010 
00011  This program is free software; you can redistribute it and/or modify
00012  it under the terms of either: 
00013 
00014     The LGPL as published by the Free Software Foundation, version
00015     2.1, available at: http://www.fsf.org/copyleft/lesser.html
00016 
00017   Or:
00018 
00019     The Mozilla Public License Version 1.0. You may obtain a copy of
00020     the License at http://www.mozilla.org/MPL/
00021 
00022   The original code is icalvalue.c
00023 
00024   Contributions from:
00025      Graham Davison (g.m.davison@computer.org)
00026 
00027 
00028 ======================================================================*/
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "icalerror.h"
00035 #include "icalmemory.h"
00036 #include "icalparser.h"
00037 #include "icalenums.h"
00038 
00039 #include "icalvalueimpl.h"
00040 
00041 #include <stdlib.h> /* for malloc */
00042 #include <stdio.h> /* for sprintf */
00043 #include <string.h> /* For memset, others */
00044 #include <stddef.h> /* For offsetof() macro */
00045 #include <errno.h>
00046 #include <time.h> /* for mktime */
00047 #include <stdlib.h> /* for atoi and atof */
00048 #include <limits.h> /* for SHRT_MAX */         
00049 
00050 struct icalvalue_impl*  icalvalue_new_impl(icalvalue_kind kind);
00051 
00052 /* This map associates each of the value types with its string
00053    representation */
00054 struct icalvalue_kind_map {
00055        icalvalue_kind kind;
00056        char name[20];
00057 };
00058 
00059 static struct icalvalue_kind_map value_map[28]={
00060     {ICAL_BOOLEAN_VALUE,"BOOLEAN"},
00061     {ICAL_UTCOFFSET_VALUE,"UTC-OFFSET"},
00062     {ICAL_XLICCLASS_VALUE,"X-LIC-CLASS"},
00063     {ICAL_RECUR_VALUE,"RECUR"},
00064     {ICAL_METHOD_VALUE,"METHOD"},
00065     {ICAL_CALADDRESS_VALUE,"CAL-ADDRESS"},
00066     {ICAL_PERIOD_VALUE,"PERIOD"},
00067     {ICAL_STATUS_VALUE,"STATUS"},
00068     {ICAL_BINARY_VALUE,"BINARY"},
00069     {ICAL_TEXT_VALUE,"TEXT"},
00070     {ICAL_DURATION_VALUE,"DURATION"},
00071     {ICAL_DATETIMEPERIOD_VALUE,"DATE-TIME-PERIOD"},
00072     {ICAL_INTEGER_VALUE,"INTEGER"},
00073     {ICAL_URI_VALUE,"URI"},
00074     {ICAL_TRIGGER_VALUE,"TRIGGER"},
00075     {ICAL_ATTACH_VALUE,"ATTACH"},
00076     {ICAL_CLASS_VALUE,"CLASS"},
00077     {ICAL_FLOAT_VALUE,"FLOAT"},
00078     {ICAL_QUERY_VALUE,"QUERY"},
00079     {ICAL_STRING_VALUE,"STRING"},
00080     {ICAL_TRANSP_VALUE,"TRANSP"},
00081     {ICAL_X_VALUE,"X"},
00082     {ICAL_DATETIME_VALUE,"DATE-TIME"},
00083     {ICAL_REQUESTSTATUS_VALUE,"REQUEST-STATUS"},
00084     {ICAL_GEO_VALUE,"GEO"},
00085     {ICAL_DATE_VALUE,"DATE"},
00086     {ICAL_ACTION_VALUE,"ACTION"},
00087     {ICAL_NO_VALUE,""}
00088 };
00089 
00090 
00091 icalvalue* icalvalue_new_boolean (int v){
00092    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_BOOLEAN_VALUE);
00093    
00094    icalvalue_set_boolean((icalvalue*)impl,v);
00095    return (icalvalue*)impl;
00096 }
00097 void icalvalue_set_boolean(icalvalue* value, int v) {
00098     struct icalvalue_impl* impl; 
00099     icalerror_check_arg_rv( (value!=0),"value");
00100     
00101     icalerror_check_value_type(value, ICAL_BOOLEAN_VALUE);
00102     impl = (struct icalvalue_impl*)value;
00103 
00104 
00105     impl->data.v_int = v; 
00106 
00107     icalvalue_reset_kind(impl);
00108 }
00109 int icalvalue_get_boolean(const icalvalue* value) {
00110 
00111     icalerror_check_arg( (value!=0),"value");
00112     icalerror_check_value_type(value, ICAL_BOOLEAN_VALUE);
00113     return ((struct icalvalue_impl*)value)->data.v_int;
00114 }
00115 
00116 
00117 
00118 icalvalue* icalvalue_new_utcoffset (int v){
00119    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_UTCOFFSET_VALUE);
00120    
00121    icalvalue_set_utcoffset((icalvalue*)impl,v);
00122    return (icalvalue*)impl;
00123 }
00124 void icalvalue_set_utcoffset(icalvalue* value, int v) {
00125     struct icalvalue_impl* impl; 
00126     icalerror_check_arg_rv( (value!=0),"value");
00127     
00128     icalerror_check_value_type(value, ICAL_UTCOFFSET_VALUE);
00129     impl = (struct icalvalue_impl*)value;
00130 
00131 
00132     impl->data.v_int = v; 
00133 
00134     icalvalue_reset_kind(impl);
00135 }
00136 int icalvalue_get_utcoffset(const icalvalue* value) {
00137 
00138     icalerror_check_arg( (value!=0),"value");
00139     icalerror_check_value_type(value, ICAL_UTCOFFSET_VALUE);
00140     return ((struct icalvalue_impl*)value)->data.v_int;
00141 }
00142 
00143 
00144 
00145 icalvalue* icalvalue_new_xlicclass (enum icalproperty_xlicclass v){
00146    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_XLICCLASS_VALUE);
00147    
00148    icalvalue_set_xlicclass((icalvalue*)impl,v);
00149    return (icalvalue*)impl;
00150 }
00151 void icalvalue_set_xlicclass(icalvalue* value, enum icalproperty_xlicclass v) {
00152     struct icalvalue_impl* impl; 
00153     icalerror_check_arg_rv( (value!=0),"value");
00154     
00155     icalerror_check_value_type(value, ICAL_XLICCLASS_VALUE);
00156     impl = (struct icalvalue_impl*)value;
00157 
00158 
00159     impl->data.v_enum = v; 
00160 
00161     icalvalue_reset_kind(impl);
00162 }
00163 enum icalproperty_xlicclass icalvalue_get_xlicclass(const icalvalue* value) {
00164 
00165     icalerror_check_arg( (value!=0),"value");
00166     icalerror_check_value_type(value, ICAL_XLICCLASS_VALUE);
00167     return ((struct icalvalue_impl*)value)->data.v_enum;
00168 }
00169 
00170 
00171 
00172 icalvalue* icalvalue_new_method (enum icalproperty_method v){
00173    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_METHOD_VALUE);
00174    
00175    icalvalue_set_method((icalvalue*)impl,v);
00176    return (icalvalue*)impl;
00177 }
00178 void icalvalue_set_method(icalvalue* value, enum icalproperty_method v) {
00179     struct icalvalue_impl* impl; 
00180     icalerror_check_arg_rv( (value!=0),"value");
00181     
00182     icalerror_check_value_type(value, ICAL_METHOD_VALUE);
00183     impl = (struct icalvalue_impl*)value;
00184 
00185 
00186     impl->data.v_enum = v; 
00187 
00188     icalvalue_reset_kind(impl);
00189 }
00190 enum icalproperty_method icalvalue_get_method(const icalvalue* value) {
00191 
00192     icalerror_check_arg( (value!=0),"value");
00193     icalerror_check_value_type(value, ICAL_METHOD_VALUE);
00194     return ((struct icalvalue_impl*)value)->data.v_enum;
00195 }
00196 
00197 
00198 
00199 icalvalue* icalvalue_new_caladdress (const char* v){
00200    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_CALADDRESS_VALUE);
00201    icalerror_check_arg_rz( (v!=0),"v");
00202 
00203    icalvalue_set_caladdress((icalvalue*)impl,v);
00204    return (icalvalue*)impl;
00205 }
00206 void icalvalue_set_caladdress(icalvalue* value, const char* v) {
00207     struct icalvalue_impl* impl; 
00208     icalerror_check_arg_rv( (value!=0),"value");
00209     icalerror_check_arg_rv( (v!=0),"v");
00210 
00211     icalerror_check_value_type(value, ICAL_CALADDRESS_VALUE);
00212     impl = (struct icalvalue_impl*)value;
00213     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00214 
00215 
00216     impl->data.v_string = icalmemory_strdup(v);
00217 
00218     if (impl->data.v_string == 0){
00219       errno = ENOMEM;
00220     }
00221  
00222 
00223     icalvalue_reset_kind(impl);
00224 }
00225 const char* icalvalue_get_caladdress(const icalvalue* value) {
00226 
00227     icalerror_check_arg( (value!=0),"value");
00228     icalerror_check_value_type(value, ICAL_CALADDRESS_VALUE);
00229     return ((struct icalvalue_impl*)value)->data.v_string;
00230 }
00231 
00232 
00233 
00234 icalvalue* icalvalue_new_period (struct icalperiodtype v){
00235    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_PERIOD_VALUE);
00236    
00237    icalvalue_set_period((icalvalue*)impl,v);
00238    return (icalvalue*)impl;
00239 }
00240 void icalvalue_set_period(icalvalue* value, struct icalperiodtype v) {
00241     struct icalvalue_impl* impl; 
00242     icalerror_check_arg_rv( (value!=0),"value");
00243     
00244     icalerror_check_value_type(value, ICAL_PERIOD_VALUE);
00245     impl = (struct icalvalue_impl*)value;
00246 
00247 
00248     impl->data.v_period = v; 
00249 
00250     icalvalue_reset_kind(impl);
00251 }
00252 struct icalperiodtype icalvalue_get_period(const icalvalue* value) {
00253 
00254     icalerror_check_arg( (value!=0),"value");
00255     icalerror_check_value_type(value, ICAL_PERIOD_VALUE);
00256     return ((struct icalvalue_impl*)value)->data.v_period;
00257 }
00258 
00259 
00260 
00261 icalvalue* icalvalue_new_status (enum icalproperty_status v){
00262    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_STATUS_VALUE);
00263    
00264    icalvalue_set_status((icalvalue*)impl,v);
00265    return (icalvalue*)impl;
00266 }
00267 void icalvalue_set_status(icalvalue* value, enum icalproperty_status v) {
00268     struct icalvalue_impl* impl; 
00269     icalerror_check_arg_rv( (value!=0),"value");
00270     
00271     icalerror_check_value_type(value, ICAL_STATUS_VALUE);
00272     impl = (struct icalvalue_impl*)value;
00273 
00274 
00275     impl->data.v_enum = v; 
00276 
00277     icalvalue_reset_kind(impl);
00278 }
00279 enum icalproperty_status icalvalue_get_status(const icalvalue* value) {
00280 
00281     icalerror_check_arg( (value!=0),"value");
00282     icalerror_check_value_type(value, ICAL_STATUS_VALUE);
00283     return ((struct icalvalue_impl*)value)->data.v_enum;
00284 }
00285 
00286 
00287 
00288 icalvalue* icalvalue_new_binary (const char* v){
00289    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_BINARY_VALUE);
00290    icalerror_check_arg_rz( (v!=0),"v");
00291 
00292    icalvalue_set_binary((icalvalue*)impl,v);
00293    return (icalvalue*)impl;
00294 }
00295 void icalvalue_set_binary(icalvalue* value, const char* v) {
00296     struct icalvalue_impl* impl; 
00297     icalerror_check_arg_rv( (value!=0),"value");
00298     icalerror_check_arg_rv( (v!=0),"v");
00299 
00300     icalerror_check_value_type(value, ICAL_BINARY_VALUE);
00301     impl = (struct icalvalue_impl*)value;
00302     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00303 
00304 
00305     impl->data.v_string = icalmemory_strdup(v);
00306 
00307     if (impl->data.v_string == 0){
00308       errno = ENOMEM;
00309     }
00310  
00311 
00312     icalvalue_reset_kind(impl);
00313 }
00314 const char* icalvalue_get_binary(const icalvalue* value) {
00315 
00316     icalerror_check_arg( (value!=0),"value");
00317     icalerror_check_value_type(value, ICAL_BINARY_VALUE);
00318     return ((struct icalvalue_impl*)value)->data.v_string;
00319 }
00320 
00321 
00322 
00323 icalvalue* icalvalue_new_text (const char* v){
00324    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TEXT_VALUE);
00325    icalerror_check_arg_rz( (v!=0),"v");
00326 
00327    icalvalue_set_text((icalvalue*)impl,v);
00328    return (icalvalue*)impl;
00329 }
00330 void icalvalue_set_text(icalvalue* value, const char* v) {
00331     struct icalvalue_impl* impl; 
00332     icalerror_check_arg_rv( (value!=0),"value");
00333     icalerror_check_arg_rv( (v!=0),"v");
00334 
00335     icalerror_check_value_type(value, ICAL_TEXT_VALUE);
00336     impl = (struct icalvalue_impl*)value;
00337     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00338 
00339 
00340     impl->data.v_string = icalmemory_strdup(v);
00341 
00342     if (impl->data.v_string == 0){
00343       errno = ENOMEM;
00344     }
00345  
00346 
00347     icalvalue_reset_kind(impl);
00348 }
00349 const char* icalvalue_get_text(const icalvalue* value) {
00350 
00351     icalerror_check_arg( (value!=0),"value");
00352     icalerror_check_value_type(value, ICAL_TEXT_VALUE);
00353     return ((struct icalvalue_impl*)value)->data.v_string;
00354 }
00355 
00356 
00357 
00358 icalvalue* icalvalue_new_duration (struct icaldurationtype v){
00359    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DURATION_VALUE);
00360    
00361    icalvalue_set_duration((icalvalue*)impl,v);
00362    return (icalvalue*)impl;
00363 }
00364 void icalvalue_set_duration(icalvalue* value, struct icaldurationtype v) {
00365     struct icalvalue_impl* impl; 
00366     icalerror_check_arg_rv( (value!=0),"value");
00367     
00368     icalerror_check_value_type(value, ICAL_DURATION_VALUE);
00369     impl = (struct icalvalue_impl*)value;
00370 
00371 
00372     impl->data.v_duration = v; 
00373 
00374     icalvalue_reset_kind(impl);
00375 }
00376 struct icaldurationtype icalvalue_get_duration(const icalvalue* value) {
00377 
00378     icalerror_check_arg( (value!=0),"value");
00379     icalerror_check_value_type(value, ICAL_DURATION_VALUE);
00380     return ((struct icalvalue_impl*)value)->data.v_duration;
00381 }
00382 
00383 
00384 
00385 icalvalue* icalvalue_new_integer (int v){
00386    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_INTEGER_VALUE);
00387    
00388    icalvalue_set_integer((icalvalue*)impl,v);
00389    return (icalvalue*)impl;
00390 }
00391 void icalvalue_set_integer(icalvalue* value, int v) {
00392     struct icalvalue_impl* impl; 
00393     icalerror_check_arg_rv( (value!=0),"value");
00394     
00395     icalerror_check_value_type(value, ICAL_INTEGER_VALUE);
00396     impl = (struct icalvalue_impl*)value;
00397 
00398 
00399     impl->data.v_int = v; 
00400 
00401     icalvalue_reset_kind(impl);
00402 }
00403 int icalvalue_get_integer(const icalvalue* value) {
00404 
00405     icalerror_check_arg( (value!=0),"value");
00406     icalerror_check_value_type(value, ICAL_INTEGER_VALUE);
00407     return ((struct icalvalue_impl*)value)->data.v_int;
00408 }
00409 
00410 
00411 
00412 icalvalue* icalvalue_new_uri (const char* v){
00413    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_URI_VALUE);
00414    icalerror_check_arg_rz( (v!=0),"v");
00415 
00416    icalvalue_set_uri((icalvalue*)impl,v);
00417    return (icalvalue*)impl;
00418 }
00419 void icalvalue_set_uri(icalvalue* value, const char* v) {
00420     struct icalvalue_impl* impl; 
00421     icalerror_check_arg_rv( (value!=0),"value");
00422     icalerror_check_arg_rv( (v!=0),"v");
00423 
00424     icalerror_check_value_type(value, ICAL_URI_VALUE);
00425     impl = (struct icalvalue_impl*)value;
00426     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00427 
00428 
00429     impl->data.v_string = icalmemory_strdup(v);
00430 
00431     if (impl->data.v_string == 0){
00432       errno = ENOMEM;
00433     }
00434  
00435 
00436     icalvalue_reset_kind(impl);
00437 }
00438 const char* icalvalue_get_uri(const icalvalue* value) {
00439 
00440     icalerror_check_arg( (value!=0),"value");
00441     icalerror_check_value_type(value, ICAL_URI_VALUE);
00442     return ((struct icalvalue_impl*)value)->data.v_string;
00443 }
00444 
00445 
00446 
00447 icalvalue* icalvalue_new_class (enum icalproperty_class v){
00448    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_CLASS_VALUE);
00449    
00450    icalvalue_set_class((icalvalue*)impl,v);
00451    return (icalvalue*)impl;
00452 }
00453 void icalvalue_set_class(icalvalue* value, enum icalproperty_class v) {
00454     struct icalvalue_impl* impl; 
00455     icalerror_check_arg_rv( (value!=0),"value");
00456     
00457     icalerror_check_value_type(value, ICAL_CLASS_VALUE);
00458     impl = (struct icalvalue_impl*)value;
00459 
00460 
00461     impl->data.v_enum = v; 
00462 
00463     icalvalue_reset_kind(impl);
00464 }
00465 enum icalproperty_class icalvalue_get_class(const icalvalue* value) {
00466 
00467     icalerror_check_arg( (value!=0),"value");
00468     icalerror_check_value_type(value, ICAL_CLASS_VALUE);
00469     return ((struct icalvalue_impl*)value)->data.v_enum;
00470 }
00471 
00472 
00473 
00474 icalvalue* icalvalue_new_float (float v){
00475    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_FLOAT_VALUE);
00476    
00477    icalvalue_set_float((icalvalue*)impl,v);
00478    return (icalvalue*)impl;
00479 }
00480 void icalvalue_set_float(icalvalue* value, float v) {
00481     struct icalvalue_impl* impl; 
00482     icalerror_check_arg_rv( (value!=0),"value");
00483     
00484     icalerror_check_value_type(value, ICAL_FLOAT_VALUE);
00485     impl = (struct icalvalue_impl*)value;
00486 
00487 
00488     impl->data.v_float = v; 
00489 
00490     icalvalue_reset_kind(impl);
00491 }
00492 float icalvalue_get_float(const icalvalue* value) {
00493 
00494     icalerror_check_arg( (value!=0),"value");
00495     icalerror_check_value_type(value, ICAL_FLOAT_VALUE);
00496     return ((struct icalvalue_impl*)value)->data.v_float;
00497 }
00498 
00499 
00500 
00501 icalvalue* icalvalue_new_query (const char* v){
00502    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_QUERY_VALUE);
00503    icalerror_check_arg_rz( (v!=0),"v");
00504 
00505    icalvalue_set_query((icalvalue*)impl,v);
00506    return (icalvalue*)impl;
00507 }
00508 void icalvalue_set_query(icalvalue* value, const char* v) {
00509     struct icalvalue_impl* impl; 
00510     icalerror_check_arg_rv( (value!=0),"value");
00511     icalerror_check_arg_rv( (v!=0),"v");
00512 
00513     icalerror_check_value_type(value, ICAL_QUERY_VALUE);
00514     impl = (struct icalvalue_impl*)value;
00515     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00516 
00517 
00518     impl->data.v_string = icalmemory_strdup(v);
00519 
00520     if (impl->data.v_string == 0){
00521       errno = ENOMEM;
00522     }
00523  
00524 
00525     icalvalue_reset_kind(impl);
00526 }
00527 const char* icalvalue_get_query(const icalvalue* value) {
00528 
00529     icalerror_check_arg( (value!=0),"value");
00530     icalerror_check_value_type(value, ICAL_QUERY_VALUE);
00531     return ((struct icalvalue_impl*)value)->data.v_string;
00532 }
00533 
00534 
00535 
00536 icalvalue* icalvalue_new_string (const char* v){
00537    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_STRING_VALUE);
00538    icalerror_check_arg_rz( (v!=0),"v");
00539 
00540    icalvalue_set_string((icalvalue*)impl,v);
00541    return (icalvalue*)impl;
00542 }
00543 void icalvalue_set_string(icalvalue* value, const char* v) {
00544     struct icalvalue_impl* impl; 
00545     icalerror_check_arg_rv( (value!=0),"value");
00546     icalerror_check_arg_rv( (v!=0),"v");
00547 
00548     icalerror_check_value_type(value, ICAL_STRING_VALUE);
00549     impl = (struct icalvalue_impl*)value;
00550     if(impl->data.v_string!=0) {free((void*)impl->data.v_string);}
00551 
00552 
00553     impl->data.v_string = icalmemory_strdup(v);
00554 
00555     if (impl->data.v_string == 0){
00556       errno = ENOMEM;
00557     }
00558  
00559 
00560     icalvalue_reset_kind(impl);
00561 }
00562 const char* icalvalue_get_string(const icalvalue* value) {
00563 
00564     icalerror_check_arg( (value!=0),"value");
00565     icalerror_check_value_type(value, ICAL_STRING_VALUE);
00566     return ((struct icalvalue_impl*)value)->data.v_string;
00567 }
00568 
00569 
00570 
00571 icalvalue* icalvalue_new_transp (enum icalproperty_transp v){
00572    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TRANSP_VALUE);
00573    
00574    icalvalue_set_transp((icalvalue*)impl,v);
00575    return (icalvalue*)impl;
00576 }
00577 void icalvalue_set_transp(icalvalue* value, enum icalproperty_transp v) {
00578     struct icalvalue_impl* impl; 
00579     icalerror_check_arg_rv( (value!=0),"value");
00580     
00581     icalerror_check_value_type(value, ICAL_TRANSP_VALUE);
00582     impl = (struct icalvalue_impl*)value;
00583 
00584 
00585     impl->data.v_enum = v; 
00586 
00587     icalvalue_reset_kind(impl);
00588 }
00589 enum icalproperty_transp icalvalue_get_transp(const icalvalue* value) {
00590 
00591     icalerror_check_arg( (value!=0),"value");
00592     icalerror_check_value_type(value, ICAL_TRANSP_VALUE);
00593     return ((struct icalvalue_impl*)value)->data.v_enum;
00594 }
00595 
00596 
00597 
00598 icalvalue* icalvalue_new_datetime (struct icaltimetype v){
00599    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIME_VALUE);
00600    
00601    icalvalue_set_datetime((icalvalue*)impl,v);
00602    return (icalvalue*)impl;
00603 }
00604 void icalvalue_set_datetime(icalvalue* value, struct icaltimetype v) {
00605     struct icalvalue_impl* impl; 
00606     icalerror_check_arg_rv( (value!=0),"value");
00607     
00608     icalerror_check_value_type(value, ICAL_DATETIME_VALUE);
00609     impl = (struct icalvalue_impl*)value;
00610 
00611 
00612     impl->data.v_time = v; 
00613 
00614     icalvalue_reset_kind(impl);
00615 }
00616 struct icaltimetype icalvalue_get_datetime(const icalvalue* value) {
00617 
00618     icalerror_check_arg( (value!=0),"value");
00619     icalerror_check_value_type(value, ICAL_DATETIME_VALUE);
00620     return ((struct icalvalue_impl*)value)->data.v_time;
00621 }
00622 
00623 
00624 
00625 icalvalue* icalvalue_new_requeststatus (struct icalreqstattype v){
00626    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_REQUESTSTATUS_VALUE);
00627    
00628    icalvalue_set_requeststatus((icalvalue*)impl,v);
00629    return (icalvalue*)impl;
00630 }
00631 void icalvalue_set_requeststatus(icalvalue* value, struct icalreqstattype v) {
00632     struct icalvalue_impl* impl; 
00633     icalerror_check_arg_rv( (value!=0),"value");
00634     
00635     icalerror_check_value_type(value, ICAL_REQUESTSTATUS_VALUE);
00636     impl = (struct icalvalue_impl*)value;
00637 
00638 
00639     impl->data.v_requeststatus = v; 
00640 
00641     icalvalue_reset_kind(impl);
00642 }
00643 struct icalreqstattype icalvalue_get_requeststatus(const icalvalue* value) {
00644 
00645     icalerror_check_arg( (value!=0),"value");
00646     icalerror_check_value_type(value, ICAL_REQUESTSTATUS_VALUE);
00647     return ((struct icalvalue_impl*)value)->data.v_requeststatus;
00648 }
00649 
00650 
00651 
00652 icalvalue* icalvalue_new_geo (struct icalgeotype v){
00653    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_GEO_VALUE);
00654    
00655    icalvalue_set_geo((icalvalue*)impl,v);
00656    return (icalvalue*)impl;
00657 }
00658 void icalvalue_set_geo(icalvalue* value, struct icalgeotype v) {
00659     struct icalvalue_impl* impl; 
00660     icalerror_check_arg_rv( (value!=0),"value");
00661     
00662     icalerror_check_value_type(value, ICAL_GEO_VALUE);
00663     impl = (struct icalvalue_impl*)value;
00664 
00665 
00666     impl->data.v_geo = v; 
00667 
00668     icalvalue_reset_kind(impl);
00669 }
00670 struct icalgeotype icalvalue_get_geo(const icalvalue* value) {
00671 
00672     icalerror_check_arg( (value!=0),"value");
00673     icalerror_check_value_type(value, ICAL_GEO_VALUE);
00674     return ((struct icalvalue_impl*)value)->data.v_geo;
00675 }
00676 
00677 
00678 
00679 icalvalue* icalvalue_new_date (struct icaltimetype v){
00680    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATE_VALUE);
00681    
00682    icalvalue_set_date((icalvalue*)impl,v);
00683    return (icalvalue*)impl;
00684 }
00685 void icalvalue_set_date(icalvalue* value, struct icaltimetype v) {
00686     struct icalvalue_impl* impl; 
00687     icalerror_check_arg_rv( (value!=0),"value");
00688     
00689     icalerror_check_value_type(value, ICAL_DATE_VALUE);
00690     impl = (struct icalvalue_impl*)value;
00691 
00692 
00693     impl->data.v_time = v; 
00694 
00695     icalvalue_reset_kind(impl);
00696 }
00697 struct icaltimetype icalvalue_get_date(const icalvalue* value) {
00698 
00699     icalerror_check_arg( (value!=0),"value");
00700     icalerror_check_value_type(value, ICAL_DATE_VALUE);
00701     return ((struct icalvalue_impl*)value)->data.v_time;
00702 }
00703 
00704 
00705 
00706 icalvalue* icalvalue_new_action (enum icalproperty_action v){
00707    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_ACTION_VALUE);
00708    
00709    icalvalue_set_action((icalvalue*)impl,v);
00710    return (icalvalue*)impl;
00711 }
00712 void icalvalue_set_action(icalvalue* value, enum icalproperty_action v) {
00713     struct icalvalue_impl* impl; 
00714     icalerror_check_arg_rv( (value!=0),"value");
00715     
00716     icalerror_check_value_type(value, ICAL_ACTION_VALUE);
00717     impl = (struct icalvalue_impl*)value;
00718 
00719 
00720     impl->data.v_enum = v; 
00721 
00722     icalvalue_reset_kind(impl);
00723 }
00724 enum icalproperty_action icalvalue_get_action(const icalvalue* value) {
00725 
00726     icalerror_check_arg( (value!=0),"value");
00727     icalerror_check_value_type(value, ICAL_ACTION_VALUE);
00728     return ((struct icalvalue_impl*)value)->data.v_enum;
00729 }
00730 
00731 
00732 int icalvalue_kind_is_valid(const icalvalue_kind kind)
00733 {
00734     int i = 0;
00735     do {
00736       if (value_map[i].kind == kind)
00737        return 1;
00738     } while (value_map[i++].kind != ICAL_NO_VALUE);
00739 
00740     return 0;
00741 }  
00742 
00743 const char* icalvalue_kind_to_string(const icalvalue_kind kind)
00744 {
00745     int i;
00746 
00747     for (i=0; value_map[i].kind != ICAL_NO_VALUE; i++) {
00748        if (value_map[i].kind == kind) {
00749            return value_map[i].name;
00750        }
00751     }
00752 
00753     return 0;
00754 }
00755 
00756 icalvalue_kind icalvalue_string_to_kind(const char* str)
00757 {
00758     int i;
00759 
00760     for (i=0; value_map[i].kind != ICAL_NO_VALUE; i++) {
00761        if (strcmp(value_map[i].name,str) == 0) {
00762            return value_map[i].kind;
00763        }
00764     }
00765 
00766     return  value_map[i].kind;
00767 
00768 }
00769 
00770 icalvalue* icalvalue_new_x (const char* v){
00771    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_X_VALUE);
00772    icalerror_check_arg_rz( (v!=0),"v");
00773 
00774    icalvalue_set_x((icalvalue*)impl,v);
00775    return (icalvalue*)impl;
00776 }
00777 void icalvalue_set_x(icalvalue* impl, const char* v) {
00778     icalerror_check_arg_rv( (impl!=0),"value");
00779     icalerror_check_arg_rv( (v!=0),"v");
00780 
00781     if(impl->x_value!=0) {free((void*)impl->x_value);}
00782 
00783     impl->x_value = icalmemory_strdup(v);
00784 
00785     if (impl->x_value == 0){
00786       errno = ENOMEM;
00787     }
00788  
00789  }
00790 const char* icalvalue_get_x(const icalvalue* value) {
00791 
00792     icalerror_check_arg( (value!=0),"value");
00793     icalerror_check_value_type(value, ICAL_X_VALUE);
00794     return value->x_value;
00795 }
00796 
00797 /* Recur is a special case, so it is not auto generated. */
00798 icalvalue*
00799 icalvalue_new_recur (struct icalrecurrencetype v)
00800 {
00801    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_RECUR_VALUE);
00802     
00803    icalvalue_set_recur((icalvalue*)impl,v);
00804 
00805    return (icalvalue*)impl;
00806 }
00807 
00808 void
00809 icalvalue_set_recur(icalvalue* impl, struct icalrecurrencetype v)
00810 {
00811     icalerror_check_arg_rv( (impl!=0),"value");
00812     icalerror_check_value_type(value, ICAL_RECUR_VALUE);
00813 
00814     if (impl->data.v_recur != 0){
00815        free(impl->data.v_recur);
00816        impl->data.v_recur = 0;
00817     }
00818 
00819     impl->data.v_recur = malloc(sizeof(struct icalrecurrencetype));
00820 
00821     if (impl->data.v_recur == 0){
00822        icalerror_set_errno(ICAL_NEWFAILED_ERROR);
00823        return;
00824     } else {
00825        memcpy(impl->data.v_recur, &v, sizeof(struct icalrecurrencetype));
00826     }
00827               
00828 }
00829 
00830 struct icalrecurrencetype
00831 icalvalue_get_recur(const icalvalue* value)
00832 {
00833     icalerror_check_arg( (value!=0),"value");
00834     icalerror_check_value_type(value, ICAL_RECUR_VALUE);
00835   
00836     return *(value->data.v_recur);
00837 }
00838 
00839 
00840 
00841 
00842 icalvalue*
00843 icalvalue_new_trigger (struct icaltriggertype v)
00844 {
00845    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_TRIGGER_VALUE);
00846  
00847    icalvalue_set_trigger((icalvalue*)impl,v);
00848 
00849    return (icalvalue*)impl;
00850 }
00851 
00852 void
00853 icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v)
00854 {
00855     icalerror_check_arg_rv( (value!=0),"value");
00856     
00857    if(!icaltime_is_null_time(v.time)){
00858        icalvalue_set_datetime(value,v.time);
00859        value->kind = ICAL_DATETIME_VALUE;
00860    } else {
00861        icalvalue_set_duration(value,v.duration);
00862        value->kind = ICAL_DURATION_VALUE;
00863    }
00864 }
00865 
00866 struct icaltriggertype
00867 icalvalue_get_trigger(const icalvalue* impl)
00868 {
00869     struct icaltriggertype tr;
00870 
00871     icalerror_check_arg( (impl!=0),"value");
00872     icalerror_check_arg( (impl!=0),"value");
00873 
00874     if(impl->kind == ICAL_DATETIME_VALUE){
00875         tr.duration = icaldurationtype_from_int(0);
00876         tr.time = impl->data.v_time;
00877     } else if(impl->kind == ICAL_DURATION_VALUE){
00878        tr.time = icaltime_null_time();
00879        tr.duration = impl->data.v_duration;
00880     } else {
00881        tr.duration = icaldurationtype_from_int(0);
00882        tr.time = icaltime_null_time();
00883        icalerror_set_errno(ICAL_BADARG_ERROR);
00884     }
00885 
00886     return tr;
00887 }
00888 
00889 /* DATE-TIME-PERIOD is a special case, and is not auto generated */
00890 
00891 icalvalue*
00892 icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v)
00893 {
00894    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIMEPERIOD_VALUE);
00895 
00896    icalvalue_set_datetimeperiod(impl,v);
00897 
00898    return (icalvalue*)impl;
00899 }
00900 
00901 void
00902 icalvalue_set_datetimeperiod(icalvalue* impl, struct icaldatetimeperiodtype v)
00903 {
00904     icalerror_check_arg_rv( (impl!=0),"value");
00905     
00906     icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE);
00907 
00908     if(!icaltime_is_null_time(v.time)){
00909        if(!icaltime_is_valid_time(v.time)){
00910            icalerror_set_errno(ICAL_BADARG_ERROR);
00911            return;
00912        }
00913        impl->kind = ICAL_DATETIME_VALUE;
00914        icalvalue_set_datetime(impl,v.time);
00915     } else if (!icalperiodtype_is_null_period(v.period)) {
00916        if(!icalperiodtype_is_valid_period(v.period)){
00917            icalerror_set_errno(ICAL_BADARG_ERROR);
00918            return;
00919        }
00920        impl->kind = ICAL_PERIOD_VALUE;
00921        icalvalue_set_period(impl,v.period);
00922     } else {
00923        icalerror_set_errno(ICAL_BADARG_ERROR);
00924     }
00925 }
00926 
00927 struct icaldatetimeperiodtype
00928 icalvalue_get_datetimeperiod(const icalvalue* impl)
00929 {
00930   struct icaldatetimeperiodtype dtp;
00931   
00932   icalerror_check_arg( (impl!=0),"value");
00933   icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE);
00934   
00935   if(impl->kind == ICAL_DATETIME_VALUE){
00936       dtp.period = icalperiodtype_null_period();
00937       dtp.time = impl->data.v_time;
00938   } else if(impl->kind == ICAL_PERIOD_VALUE) {
00939       dtp.period = impl->data.v_period;
00940       dtp.time = icaltime_null_time();
00941   } else {
00942       dtp.period = icalperiodtype_null_period();
00943       dtp.time = icaltime_null_time();
00944       icalerror_set_errno(ICAL_BADARG_ERROR);
00945   }    
00946 
00947   return dtp;
00948 }
00949 
00950 
00951 
00952 icalvalue *
00953 icalvalue_new_attach (icalattach *attach)
00954 {
00955     struct icalvalue_impl *impl;
00956 
00957     icalerror_check_arg_rz ((attach != NULL), "attach");
00958 
00959     impl = icalvalue_new_impl (ICAL_ATTACH_VALUE);
00960     if (!impl) {
00961        errno = ENOMEM;
00962        return NULL;
00963     }
00964 
00965     icalvalue_set_attach ((icalvalue *) impl, attach);
00966     return (icalvalue *) impl;
00967 }
00968 
00969 void
00970 icalvalue_set_attach (icalvalue *value, icalattach *attach)
00971 {
00972     struct icalvalue_impl *impl;
00973  
00974     icalerror_check_arg_rv ((value != NULL), "value");
00975     icalerror_check_value_type (value, ICAL_ATTACH_VALUE);
00976     icalerror_check_arg_rv ((attach != NULL), "attach");
00977   
00978     impl = (struct icalvalue_impl *) value;
00979  
00980     icalattach_ref (attach);
00981 
00982     if (impl->data.v_attach)
00983        icalattach_unref (impl->data.v_attach);
00984   
00985     impl->data.v_attach = attach;
00986 }
00987 
00988 icalattach *
00989 icalvalue_get_attach (const icalvalue *value)
00990 {
00991     icalerror_check_arg_rz ((value != NULL), "value");
00992     icalerror_check_value_type (value, ICAL_ATTACH_VALUE);
00993     
00994     return value->data.v_attach;
00995 }
00996 
00997 
00998 
00999 
01000 
01001 
01002 
01003 /* The remaining interfaces are 'new', 'set' and 'get' for each of the value
01004    types */
01005 
01006 
01007 /* Everything below this line is machine generated. Do not edit. */