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