vformat.h

00001 /*
00002  * Copyright (C) 2003 Ximian, Inc. 2005 Armin Bauer
00003  *
00004  * Copyright (C) 2003 Ximian, Inc.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019  *
00020  * Author: Chris Toshok (toshok@ximian.com)
00021  * Author: Armin Bauer (armin.bauer@opensync.org)
00022  *
00023  */
00024 
00025 #ifndef _VFORMAT_H
00026 #define _VFORMAT_H
00027 
00028 #include "dll.h"
00029 #include <glib.h>
00030 #include <time.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 typedef enum {
00037         VFORMAT_CARD_21,
00038         VFORMAT_CARD_30,
00039         VFORMAT_NOTE,
00040         VFORMAT_EVENT_10,
00041         VFORMAT_EVENT_20,
00042         VFORMAT_TODO_10,
00043         VFORMAT_TODO_20,
00044         VFORMAT_JOURNAL
00045 } b_VFormatType;
00046 
00047 typedef struct b_VFormat {
00048         //b_VFormatType type;
00049         GList *attributes;
00050 } b_VFormat;
00051 
00052 #define CRLF "\r\n"
00053 
00054 typedef enum {
00055         VF_ENCODING_RAW,    /* no encoding */
00056         VF_ENCODING_BASE64, /* base64 */
00057         VF_ENCODING_QP,     /* quoted-printable */
00058         VF_ENCODING_8BIT
00059 } b_VFormatEncoding;
00060 
00061 typedef struct b_VFormatAttribute {
00062         char  *block;       /* "vtimezone/standard", or "vevent", depending on
00063                                 current begin/end location... may be null */
00064         char  *group;
00065         char  *name;
00066         GList *params; /* b_VFormatParam */
00067         GList *values;
00068         GList *decoded_values;
00069         b_VFormatEncoding encoding;
00070         gboolean encoding_set;
00071 } b_VFormatAttribute;
00072 
00073 typedef struct b_VFormatParam {
00074         char     *name;
00075         GList    *values;  /* GList of char*'s*/
00076 } b_VFormatParam;
00077 
00078 
00079 /*b_VFormat *vcard_new(b_VFormatType type);
00080 b_VFormat *vcard_new_from_string (const char *str, b_VFormatType type);
00081 //char *vcard_to_string(VFormat *card, VFormatType format);
00082 
00083 VFormat *vnote_new(void);
00084 VFormat *vnote_new_from_string(const char *str);
00085 //char *vnote_to_string(VFormat *note);
00086 
00087 
00088 VFormat *vevent_new(void);
00089 VFormat *vevent_new_from_string(const char *str);
00090 //char *vevent_to_string(VFormat *event);
00091 
00092 VFormat *vtodo_new(void);
00093 VFormat *vtodo_new_from_string(const char *str);*/
00094 //char *vtodo_to_string(VFormat *todo);
00095 
00096 /* mostly for debugging */
00097 b_VFormat *b_vformat_new(void);
00098 b_VFormat *b_vformat_new_from_string(const char *str);
00099 void b_vformat_dump_structure(b_VFormat *format);
00100 char *b_vformat_to_string(b_VFormat *evc, b_VFormatType type);
00101 time_t b_vformat_time_to_unix(const char *inptime);
00102 void b_vformat_free(b_VFormat *format);
00103 
00104 /* attributes */
00105 b_VFormatAttribute *b_vformat_attribute_new               (const char *attr_group, const char *attr_name);
00106 void             b_vformat_attribute_free              (b_VFormatAttribute *attr);
00107 b_VFormatAttribute *b_vformat_attribute_copy              (b_VFormatAttribute *attr);
00108 void             b_vformat_remove_attributes           (b_VFormat *vformat, const char *attr_group, const char *attr_name);
00109 void             b_vformat_remove_attribute            (b_VFormat *vformat, b_VFormatAttribute *attr);
00110 void             b_vformat_add_attribute               (b_VFormat *vformat, b_VFormatAttribute *attr);
00111 void             b_vformat_add_attribute_with_value    (b_VFormat *vformat, b_VFormatAttribute *attr, const char *value);
00112 void             b_vformat_add_attribute_with_values   (b_VFormat *vformat, b_VFormatAttribute *attr, ...);
00113 void             b_vformat_attribute_add_value         (b_VFormatAttribute *attr, const char *value);
00114 void             b_vformat_attribute_set_value         (b_VFormatAttribute *attr, int nth, const char *value);
00115 void             b_vformat_attribute_add_value_decoded (b_VFormatAttribute *attr, const char *value, int len);
00116 void             b_vformat_attribute_add_values        (b_VFormatAttribute *attr, ...);
00117 void             b_vformat_attribute_remove_values     (b_VFormatAttribute *attr);
00118 void             b_vformat_attribute_remove_params     (b_VFormatAttribute *attr);
00119 b_VFormatAttribute *b_vformat_find_attribute             (b_VFormat *evc, const char *name, int nth, const char *block);
00120 
00121 /* attribute parameters */
00122 b_VFormatParam* b_vformat_attribute_param_new             (const char *param_name);
00123 void                  b_vformat_attribute_param_free            (b_VFormatParam *param);
00124 b_VFormatParam* b_vformat_attribute_param_copy            (b_VFormatParam *param);
00125 void                  b_vformat_attribute_add_param             (b_VFormatAttribute *attr, b_VFormatParam *param);
00126 b_VFormatParam *b_vformat_attribute_find_param(b_VFormatAttribute *attr, const char *name, int level);
00127 void                  b_vformat_attribute_add_param_with_value  (b_VFormatAttribute *attr, const char *name, const char *value);
00128 void                  b_vformat_attribute_add_param_with_values (b_VFormatAttribute *attr,
00129                                                                b_VFormatParam *param, ...);
00130 
00131 void                  b_vformat_attribute_param_add_value       (b_VFormatParam *param,
00132                                                                const char *value);
00133 void                  b_vformat_attribute_param_add_values      (b_VFormatParam *param,
00134                                                                ...);
00135 void                  b_vformat_attribute_param_remove_values   (b_VFormatParam *param);
00136 gboolean b_vformat_attribute_has_param(b_VFormatAttribute *attr, const char *name);
00137 
00138 /* b_VFormat* accessors.  nothing returned from these functions should be
00139    freed by the caller. */
00140 GList*           b_vformat_get_attributes       (b_VFormat *vformat);
00141 const char*      b_vformat_attribute_get_group  (b_VFormatAttribute *attr);
00142 const char*      b_vformat_attribute_get_name   (b_VFormatAttribute *attr);
00143 const char*      b_vformat_attribute_get_block  (b_VFormatAttribute *attr);
00144 GList*           b_vformat_attribute_get_values (b_VFormatAttribute *attr);  /* GList elements are of type char* */
00145 GList*           b_vformat_attribute_get_values_decoded (b_VFormatAttribute *attr); /* GList elements are of type GString* */
00146 const char *b_vformat_attribute_get_nth_value(b_VFormatAttribute *attr, int nth);
00147 
00148 /* special accessors for single valued attributes */
00149 gboolean              b_vformat_attribute_is_single_valued      (b_VFormatAttribute *attr);
00150 char*                 b_vformat_attribute_get_value             (b_VFormatAttribute *attr);
00151 GString*              b_vformat_attribute_get_value_decoded     (b_VFormatAttribute *attr);
00152 
00153 GList*           b_vformat_attribute_get_params       (b_VFormatAttribute *attr);
00154 const char*      b_vformat_attribute_param_get_name   (b_VFormatParam *param);
00155 GList*           b_vformat_attribute_param_get_values (b_VFormatParam *param);
00156 const char *b_vformat_attribute_param_get_nth_value(b_VFormatParam *param, int nth);
00157 
00158 /* special TYPE= parameter predicate (checks for TYPE=@typestr */
00159 gboolean         b_vformat_attribute_has_type         (b_VFormatAttribute *attr, const char *typestr);
00160 
00161 /* Utility functions. */
00162 char*            b_vformat_escape_string (const char *str, b_VFormatType type);
00163 char*            b_vformat_unescape_string (const char *str);
00164 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168 
00169 #endif /* _VFORMAT_H */