649a78d5dee5ec376d6363d75f81bcc376045fa3
[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 #include <stdlib.h>
13 #define LIBCITADEL_VERSION_NUMBER       109
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 /** Run once at Programstart */
181 int LoadIconDir(const char *DirName);
182 /** guess an icon to the mimetype */
183 const char *GetIconFilename(char *MimeType, size_t len);
184 void ShutDownLibCitadel(void);
185
186
187 /* tools */
188
189 int Ctdl_IsUtf8SequenceStart(char Char);
190 int Ctdl_GetUtf8SequenceLength(char Char);
191 int Ctdl_Utf8StrLen(char *str);
192 char *Ctdl_Utf8StrCut(char *str, int maxlen);
193
194
195 int safestrncpy(char *dest, const char *src, size_t n);
196 int num_tokens (const char *source, char tok);
197 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
198 long grab_token(char **dest, const char *source, int parmnum, char separator);
199 int extract_int (const char *source, int parmnum);
200 long extract_long (const char *source, int parmnum);
201 unsigned long extract_unsigned_long(const char *source, int parmnum);
202 void CtdlInitBase64Table(void);
203 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
204 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
205 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
206 void striplt(char *);
207 int haschar(const char *st, int ch);
208 void remove_token(char *source, int parmnum, char separator);
209 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
210 int is_msg_in_sequence_set(char *mset, long msgnum);
211 char *memreadline(char *start, char *buf, int maxlen);
212 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
213 #define IsEmptyStr(a) ((a)[0] == '\0')
214 #define num_parms(source)               num_tokens(source,(char)'|')
215 void stripout(char *str, char leftboundary, char rightboundary);
216 void stripallbut(char *str, char leftboundary, char rightboundary);
217 char *myfgets(char *s, int size, FILE *stream);
218 void urlesc(char *outbuf, size_t oblen, char *strbuf);
219 char *CtdlTempFileName(char *prefix1, int prefix2);
220 FILE *CtdlTempFile(void);
221 void generate_uuid(char *buf);
222 char *bmstrcasestr(char *text, char *pattern);
223 void CtdlMakeTempFileName(char *name, int len);
224 char *rfc2047encode(char *line, long length);
225 int is_msg_in_mset(char *mset, long msgnum);
226 int pattern2(char *search, char *patn);
227 void stripltlen(char *, int *);
228 char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat);
229
230
231
232 /* vCard stuff */
233
234 #define CTDL_VCARD_MAGIC        0xa1f9
235
236 /* This data structure represents a vCard object currently in memory. */
237 struct vCard {
238         int magic;
239         int numprops;
240         struct vCardProp {
241                 char *name;
242                 char *value;
243         } *prop;
244 };
245
246
247 struct vCard *vcard_new(void);
248 void vcard_add_prop(struct vCard *v, char *propname, char *propvalue);
249 struct vCard *vcard_load(char *);
250 void vcard_free(struct vCard *);
251 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
252 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
253                         int instance, int return_propname);
254 char *vcard_serialize(struct vCard *);
255 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
256 void remove_charset_attribute(char *strbuf);
257
258 /**
259  * Citadels Hashlist Implementation
260  */
261 #define HKEY(a) a, sizeof(a) - 1
262 typedef struct HashList HashList;
263
264 typedef struct HashKey HashKey;
265
266 typedef struct HashPos HashPos;
267
268 typedef void (*DeleteHashDataFunc)(void * Data);
269 typedef const char *(*PrintHashContent)(void * Data);
270 typedef int (*CompareFunc)(const void* Item1, const void*Item2);
271
272 HashList *NewHash(void);
273
274 void DeleteHash(HashList **Hash);
275
276 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
277
278 void Put(HashList *Hash, char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
279
280 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
281
282 int GetHashKeys(HashList *Hash, char ***List);
283
284 int PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
285
286 HashPos *GetNewHashPos(void);
287
288 void DeleteHashPos(HashPos **DelMe);
289
290 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data);
291
292 void SortByHashKey(HashList *Hash);
293 void SortByHashKeyStr(HashList *Hash);
294
295 const void *GetSearchPayload(const void *HashVoid);
296 void SortByPayload(HashList *Hash, CompareFunc SortBy);
297
298 void convert_spaces_to_underscores(char *str);