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