528df6cd3abc5bcd7ebd58668dce4b6c75a9cd66
[citadel.git] / libcitadel / lib / libcitadel.h
1 /*
2  * $Id$
3  *
4  */
5
6
7 /* protect against double includes */
8 #ifndef LIBCITADEL_H
9 #define LIBCITADEL_H
10
11
12 /*
13  * since we reference time_t...
14  */
15 #include <time.h>
16 #include <stdlib.h>
17 #define LIBCITADEL_VERSION_NUMBER       115
18
19 /*
20  * Here's a bunch of stupid magic to make the MIME parser portable.
21  */
22 #ifndef SIZ
23 #define SIZ     4096
24 #endif
25
26
27 /* Logging levels - correspond to syslog(3) */
28 enum LogLevel {
29         /* When about to exit the server for an unrecoverable error */
30          CTDL_EMERG,    /* system is unusable */
31         /* Manual intervention is required to avoid an abnormal exit */
32          CTDL_ALERT,    /* action must be taken immediately */
33         /* The server can continue to run with degraded functionality */
34          CTDL_CRIT,     /* critical conditions */
35         /* An error occurs but the server continues to run normally */
36          CTDL_ERR,      /* error conditions */
37         /* An abnormal condition was detected; server will continue normally */
38          CTDL_WARNING,  /* warning conditions */
39         /* Normal messages (login/out, activity, etc.) */
40          CTDL_NOTICE,   /* normal but significant condition */
41         /* Unimportant progress messages, etc. */
42          CTDL_INFO,     /* informational */
43         /* Debugging messages */
44          CTDL_DEBUG     /* debug-level messages */
45 };
46
47
48 /*
49  * View definitions.
50  * Note that not all views are implemented in all clients.
51  */
52 #define VIEW_BBS                0       /* Bulletin board view */
53 #define VIEW_MAILBOX            1       /* Mailbox summary */
54 #define VIEW_ADDRESSBOOK        2       /* Address book view */
55 #define VIEW_CALENDAR           3       /* Calendar view */
56 #define VIEW_TASKS              4       /* Tasks view */
57 #define VIEW_NOTES              5       /* Notes view */
58 #define VIEW_WIKI               6       /* Wiki view */
59 #define VIEW_CALBRIEF           7       /* Brief Calendar view */
60 #define VIEW_JOURNAL            8       /* Journal view */
61
62
63 #ifndef IsEmptyStr
64 #define IsEmptyStr(a) ((a)[0] == '\0')
65 #endif
66
67 /*
68  * Misc declarations
69  */
70
71 char *libcitadel_version_string(void);
72 int libcitadel_version_number(void);
73
74
75 /*
76  * MIME parser declarations
77  */
78
79 void extract_key(char *target, char *source, char *key);
80
81 void mime_parser(char *content_start, char *content_end,
82                 void (*CallBack)
83                         (char *cbname,
84                         char *cbfilename,
85                         char *cbpartnum,
86                         char *cbdisp,
87                         void *cbcontent,
88                         char *cbtype,
89                         char *cbcharset,
90                         size_t cblength,
91                         char *cbencoding,
92                         void *cbuserdata),
93                 void (*PreMultiPartCallBack)
94                         (char *cbname,
95                         char *cbfilename,
96                         char *cbpartnum,
97                         char *cbdisp,
98                         void *cbcontent,
99                         char *cbtype,
100                         char *cbcharset,
101                         size_t cblength,
102                         char *cbencoding,
103                         void *cbuserdata),
104                 void (*PostMultiPartCallBack)
105                         (char *cbname,
106                         char *cbfilename,
107                         char *cbpartnum,
108                         char *cbdisp,
109                         void *cbcontent,
110                         char *cbtype,
111                         char *cbcharset,
112                         size_t cblength,
113                         char *cbencoding,
114                         void *cbuserdata),
115                 void *userdata,
116                 int dont_decode
117                 );
118
119
120
121 char *fixed_partnum(char *);
122 void mime_decode(char *partnum,
123                  char *part_start, size_t length,
124                  char *content_type, char *charset, char *encoding,
125                  char *disposition,
126                  char *name, char *filename,
127                  void (*CallBack)
128                   (char *cbname,
129                    char *cbfilename,
130                    char *cbpartnum,
131                    char *cbdisp,
132                    void *cbcontent,
133                    char *cbtype,
134                    char *cbcharset,
135                    size_t cblength,
136                    char *cbencoding,
137                    void *cbuserdata),
138                  void (*PreMultiPartCallBack)
139                   (char *cbname,
140                    char *cbfilename,
141                    char *cbpartnum,
142                    char *cbdisp,
143                    void *cbcontent,
144                    char *cbtype,
145                    char *cbcharset,
146                    size_t cblength,
147                    char *cbencoding,
148                    void *cbuserdata),
149                  void (*PostMultiPartCallBack)
150                   (char *cbname,
151                    char *cbfilename,
152                    char *cbpartnum,
153                    char *cbdisp,
154                    void *cbcontent,
155                    char *cbtype,
156                    char *cbcharset,
157                    size_t cblength,
158                    char *cbencoding,
159                    void *cbuserdata),
160                   void *userdata,
161                   int dont_decode
162 );
163 void the_mime_parser(char *partnum,
164                      char *content_start, char *content_end,
165                      void (*CallBack)
166                       (char *cbname,
167                        char *cbfilename,
168                        char *cbpartnum,
169                        char *cbdisp,
170                        void *cbcontent,
171                        char *cbtype,
172                        char *cbcharset,
173                        size_t cblength,
174                        char *cbencoding,
175                        void *cbuserdata),
176                      void (*PreMultiPartCallBack)
177                       (char *cbname,
178                        char *cbfilename,
179                        char *cbpartnum,
180                        char *cbdisp,
181                        void *cbcontent,
182                        char *cbtype,
183                        char *cbcharset,
184                        size_t cblength,
185                        char *cbencoding,
186                        void *cbuserdata),
187                      void (*PostMultiPartCallBack)
188                       (char *cbname,
189                        char *cbfilename,
190                        char *cbpartnum,
191                        char *cbdisp,
192                        void *cbcontent,
193                        char *cbtype,
194                        char *cbcharset,
195                        size_t cblength,
196                        char *cbencoding,
197                        void *cbuserdata),
198                       void *userdata,
199                       int dont_decode
200 );
201
202 const char *GuessMimeType(char *data, size_t dlen);
203 const char* GuessMimeByFilename(const char *what, size_t len);
204
205 /* Run once at Programstart */
206 int LoadIconDir(const char *DirName);
207
208 /* Select the icon for a given MIME type */
209 const char *GetIconFilename(char *MimeType, size_t len);
210
211 void ShutDownLibCitadel(void);
212
213
214 /* tools */
215
216 int Ctdl_IsUtf8SequenceStart(char Char);
217 int Ctdl_GetUtf8SequenceLength(char Char);
218 int Ctdl_Utf8StrLen(char *str);
219 char *Ctdl_Utf8StrCut(char *str, int maxlen);
220
221
222 int safestrncpy(char *dest, const char *src, size_t n);
223 int num_tokens (const char *source, char tok);
224 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
225 long grab_token(char **dest, const char *source, int parmnum, char separator);
226 int extract_int (const char *source, int parmnum);
227 long extract_long (const char *source, int parmnum);
228 unsigned long extract_unsigned_long(const char *source, int parmnum);
229 void CtdlInitBase64Table(void);
230 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
231 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
232 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
233 void striplt(char *);
234 int haschar(const char *st, int ch);
235 void remove_token(char *source, int parmnum, char separator);
236 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
237 int is_msg_in_sequence_set(char *mset, long msgnum);
238 char *memreadline(char *start, char *buf, int maxlen);
239 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
240 #define IsEmptyStr(a) ((a)[0] == '\0')
241 #define num_parms(source)               num_tokens(source,(char)'|')
242 void stripout(char *str, char leftboundary, char rightboundary);
243 void stripallbut(char *str, char leftboundary, char rightboundary);
244 char *myfgets(char *s, int size, FILE *stream);
245 void urlesc(char *outbuf, size_t oblen, char *strbuf);
246 char *CtdlTempFileName(char *prefix1, int prefix2);
247 FILE *CtdlTempFile(void);
248 void generate_uuid(char *buf);
249 char *bmstrcasestr(char *text, char *pattern);
250 void CtdlMakeTempFileName(char *name, int len);
251 char *rfc2047encode(char *line, long length);
252 int is_msg_in_mset(char *mset, long msgnum);
253 int pattern2(char *search, char *patn);
254 void stripltlen(char *, int *);
255 char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat);
256
257
258
259 /* vCard stuff */
260
261 #define CTDL_VCARD_MAGIC        0xa1f9
262
263 /* This data structure represents a vCard object currently in memory. */
264 struct vCard {
265         int magic;
266         int numprops;
267         struct vCardProp {
268                 char *name;
269                 char *value;
270         } *prop;
271 };
272
273
274 struct vCard *vcard_new(void);
275 void vcard_add_prop(struct vCard *v, char *propname, char *propvalue);
276 struct vCard *vcard_load(char *);
277 void vcard_free(struct vCard *);
278 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
279 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
280                         int instance, int return_propname);
281 char *vcard_serialize(struct vCard *);
282 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
283 void remove_charset_attribute(char *strbuf);
284
285 /*
286  * Hash list implementation for Citadel
287  */
288 #define HKEY(a) a, sizeof(a) - 1
289 typedef struct HashList HashList;
290
291 typedef struct HashKey HashKey;
292
293 typedef struct HashPos HashPos;
294
295 typedef void (*DeleteHashDataFunc)(void * Data);
296 typedef const char *(*PrintHashContent)(void * Data);
297 typedef int (*CompareFunc)(const void* Item1, const void*Item2);
298 typedef int (*HashFunc)(const char *Str, long Len);
299 typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd);
300 typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd);
301
302 HashList *NewHash(int Uniq, HashFunc F);
303 void DeleteHash(HashList **Hash);
304 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
305 void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
306 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
307 int GetHashKeys(HashList *Hash, char ***List);
308 int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
309 int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry);
310 HashPos *GetNewHashPos(void);
311 void DeleteHashPos(HashPos **DelMe);
312 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data);
313 void SortByHashKey(HashList *Hash, int Order);
314 void SortByHashKeyStr(HashList *Hash);
315 int GetCount(HashList *Hash);
316 const void *GetSearchPayload(const void *HashVoid);
317 void SortByPayload(HashList *Hash, CompareFunc SortBy);
318 void generic_free_handler(void *ptr);
319
320
321 void convert_spaces_to_underscores(char *str);
322
323 /*
324  * Convert 4 bytes char into an Integer.
325  * usefull for easy inexpensive hashing 
326  * of for char strings.
327  */
328 #define CHAR4TO_INT(a) ((int) (a[0] | (a[1]<<8) | (a[2]<<16) | (a[3]<<24)))
329
330 /* vNote implementation */
331
332 #define CTDL_VNOTE_MAGIC        0xa1fa
333
334 struct vnote {
335         int magic;
336         char *uid;
337         char *summary;
338         char *body;
339         int pos_left;
340         int pos_top;
341         int pos_width;
342         int pos_height;
343         int color_red;
344         int color_green;
345         int color_blue;
346 };
347
348
349
350 struct vnote *vnote_new(void);
351 struct vnote *vnote_new_from_str(char *s);
352 void vnote_free(struct vnote *v);
353 char *vnote_serialize(struct vnote *v);
354 void vnote_serialize_output_field(char *append_to, char *field, char *label);
355
356
357 #endif  // LIBCITADEL_H