THIS IS 1.05
[citadel.git] / libcitadel / lib / libcitadel.h
1 /*
2  * $Id$
3  *
4  */
5
6
7
8 /*
9  * since we reference time_t...
10  */
11 #include <time.h>
12
13 #define LIBCITADEL_VERSION_NUMBER       105
14
15 /*
16  * Here's a bunch of stupid magic to make the MIME parser portable.
17  */
18 #ifndef SIZ
19 #define SIZ     4096
20 #endif
21
22
23 /*
24  * View definitions.
25  * Note that not all views are implemented in all clients.
26  */
27 #define VIEW_BBS                0       /* Bulletin board view */
28 #define VIEW_MAILBOX            1       /* Mailbox summary */
29 #define VIEW_ADDRESSBOOK        2       /* Address book view */
30 #define VIEW_CALENDAR           3       /* Calendar view */
31 #define VIEW_TASKS              4       /* Tasks view */
32 #define VIEW_NOTES              5       /* Notes view */
33 #define VIEW_WIKI               6       /* Wiki view */
34 #define VIEW_CALBRIEF           7       /* Brief Calendar view */
35 #define VIEW_JOURNAL            8       /* Journal view */
36
37
38 #ifndef IsEmptyStr
39 #define IsEmptyStr(a) ((a)[0] == '\0')
40 #endif
41
42 /*
43  * Misc declarations
44  */
45
46 char *libcitadel_version_string(void);
47 int libcitadel_version_number(void);
48
49
50 /*
51  * MIME parser declarations
52  */
53
54 void extract_key(char *target, char *source, char *key);
55
56 void mime_parser(char *content_start, char *content_end,
57                 void (*CallBack)
58                         (char *cbname,
59                         char *cbfilename,
60                         char *cbpartnum,
61                         char *cbdisp,
62                         void *cbcontent,
63                         char *cbtype,
64                         char *cbcharset,
65                         size_t cblength,
66                         char *cbencoding,
67                         void *cbuserdata),
68                 void (*PreMultiPartCallBack)
69                         (char *cbname,
70                         char *cbfilename,
71                         char *cbpartnum,
72                         char *cbdisp,
73                         void *cbcontent,
74                         char *cbtype,
75                         char *cbcharset,
76                         size_t cblength,
77                         char *cbencoding,
78                         void *cbuserdata),
79                 void (*PostMultiPartCallBack)
80                         (char *cbname,
81                         char *cbfilename,
82                         char *cbpartnum,
83                         char *cbdisp,
84                         void *cbcontent,
85                         char *cbtype,
86                         char *cbcharset,
87                         size_t cblength,
88                         char *cbencoding,
89                         void *cbuserdata),
90                 void *userdata,
91                 int dont_decode
92                 );
93
94
95
96 char *fixed_partnum(char *);
97 void mime_decode(char *partnum,
98                  char *part_start, size_t length,
99                  char *content_type, char *charset, char *encoding,
100                  char *disposition,
101                  char *name, char *filename,
102                  void (*CallBack)
103                   (char *cbname,
104                    char *cbfilename,
105                    char *cbpartnum,
106                    char *cbdisp,
107                    void *cbcontent,
108                    char *cbtype,
109                    char *cbcharset,
110                    size_t cblength,
111                    char *cbencoding,
112                    void *cbuserdata),
113                  void (*PreMultiPartCallBack)
114                   (char *cbname,
115                    char *cbfilename,
116                    char *cbpartnum,
117                    char *cbdisp,
118                    void *cbcontent,
119                    char *cbtype,
120                    char *cbcharset,
121                    size_t cblength,
122                    char *cbencoding,
123                    void *cbuserdata),
124                  void (*PostMultiPartCallBack)
125                   (char *cbname,
126                    char *cbfilename,
127                    char *cbpartnum,
128                    char *cbdisp,
129                    void *cbcontent,
130                    char *cbtype,
131                    char *cbcharset,
132                    size_t cblength,
133                    char *cbencoding,
134                    void *cbuserdata),
135                   void *userdata,
136                   int dont_decode
137 );
138 void the_mime_parser(char *partnum,
139                      char *content_start, char *content_end,
140                      void (*CallBack)
141                       (char *cbname,
142                        char *cbfilename,
143                        char *cbpartnum,
144                        char *cbdisp,
145                        void *cbcontent,
146                        char *cbtype,
147                        char *cbcharset,
148                        size_t cblength,
149                        char *cbencoding,
150                        void *cbuserdata),
151                      void (*PreMultiPartCallBack)
152                       (char *cbname,
153                        char *cbfilename,
154                        char *cbpartnum,
155                        char *cbdisp,
156                        void *cbcontent,
157                        char *cbtype,
158                        char *cbcharset,
159                        size_t cblength,
160                        char *cbencoding,
161                        void *cbuserdata),
162                      void (*PostMultiPartCallBack)
163                       (char *cbname,
164                        char *cbfilename,
165                        char *cbpartnum,
166                        char *cbdisp,
167                        void *cbcontent,
168                        char *cbtype,
169                        char *cbcharset,
170                        size_t cblength,
171                        char *cbencoding,
172                        void *cbuserdata),
173                       void *userdata,
174                       int dont_decode
175 );
176
177 const char *GuessMimeType(char *data, size_t dlen);
178 const char* GuessMimeByFilename(const char *what, size_t len);
179
180
181
182 /* tools */
183
184
185
186 char *safestrncpy(char *dest, const char *src, size_t n);
187 int num_tokens (const char *source, char tok);
188 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
189 long grab_token(char **dest, const char *source, int parmnum, char separator);
190 int extract_int (const char *source, int parmnum);
191 long extract_long (const char *source, int parmnum);
192 unsigned long extract_unsigned_long(const char *source, int parmnum);
193 void CtdlInitBase64Table(void);
194 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
195 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
196 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
197 void striplt(char *);
198 int haschar(const char *st, int ch);
199 void remove_token(char *source, int parmnum, char separator);
200 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
201 int is_msg_in_sequence_set(char *mset, long msgnum);
202 char *memreadline(char *start, char *buf, int maxlen);
203 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
204 #define IsEmptyStr(a) ((a)[0] == '\0')
205 #define num_parms(source)               num_tokens(source,(char)'|')
206 void stripout(char *str, char leftboundary, char rightboundary);
207 void stripallbut(char *str, char leftboundary, char rightboundary);
208 char *myfgets(char *s, int size, FILE *stream);
209 void urlesc(char *outbuf, size_t oblen, char *strbuf);
210 char *CtdlTempFileName(char *prefix1, int prefix2);
211 FILE *CtdlTempFile(void);
212 void generate_uuid(char *buf);
213 char *bmstrcasestr(char *text, char *pattern);
214 void CtdlMakeTempFileName(char *name, int len);
215 char *rfc2047encode(char *line, long length);
216 int is_msg_in_mset(char *mset, long msgnum);
217 int pattern2(char *search, char *patn);
218 void stripltlen(char *, int *);
219
220
221
222 /* vCard stuff */
223
224 #define CTDL_VCARD_MAGIC        0xa1f9
225
226 /* This data structure represents a vCard object currently in memory. */
227 struct vCard {
228         int magic;
229         int numprops;
230         struct vCardProp {
231                 char *name;
232                 char *value;
233         } *prop;
234 };
235
236
237 struct vCard *vcard_new(void);
238 void vcard_add_prop(struct vCard *v, char *propname, char *propvalue);
239 struct vCard *vcard_load(char *);
240 void vcard_free(struct vCard *);
241 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
242 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
243                         int instance, int return_propname);
244 char *vcard_serialize(struct vCard *);
245 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
246 void remove_charset_attribute(char *strbuf);
247
248 typedef struct HashList HashList;
249
250 typedef struct HashKey HashKey;
251
252 typedef struct HashPos HashPos;
253
254 typedef void (*DeleteHashDataFunc)(void * Data);
255
256
257
258 HashList *NewHash(void);
259 void DeleteHash(HashList **Hash);
260
261
262 int GetHash(HashList *Hash, char *HKey, long HKLen, void **Data);
263
264 void Put(HashList *Hash, char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
265
266 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
267
268 int GetHashKeys(HashList *Hash, const char ***List);
269
270 int PrintHash(HashList *Hash);
271
272 HashPos *GetNewHashPos(void);
273 void DeleteHashPos(HashPos **DelMe);
274
275 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data);