2 * Header file for libcitadel
6 /* protect against double includes */
12 * since we reference time_t...
17 #define LIBCITADEL_VERSION_NUMBER 789
20 * Here's a bunch of stupid magic to make the MIME parser portable.
27 /* Logging levels - correspond to syslog(3) */
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 */
47 typedef enum AXLevel {
60 lastsent, /* Server internal use only */
70 enum GNET_POP3_PARTS { /* pop3client splits into these columns: */
74 GNET_POP3_DONT_DELETE_REMOTE = 4,
75 GNET_POP3_INTERVAL = 5
78 enum GNET_PUSH_SHARE { /* ignet_push_share splits into these columns: */
83 typedef enum __GPEXWhichPolicy {
93 * Note that not all views are implemented in all clients.
95 typedef enum _room_views {
96 VIEW_BBS = 0, /* Bulletin board view */
97 VIEW_MAILBOX = 1, /* Mailbox summary */
98 VIEW_ADDRESSBOOK = 2, /* Address book view */
99 VIEW_CALENDAR = 3, /* Calendar view */
100 VIEW_TASKS = 4, /* Tasks view */
101 VIEW_NOTES = 5, /* Notes view */
102 VIEW_WIKI = 6, /* Wiki view */
103 VIEW_CALBRIEF = 7, /* Brief Calendar view */
104 VIEW_JOURNAL = 8, /* Journal view */
105 VIEW_DRAFTS = 9, /* Drafts view */
106 VIEW_BLOG = 10, /* Blog view */
111 #define IsEmptyStr(a) ((a)[0] == '\0')
116 * another word to indicate n/a for a pointer if NULL already has a "meaning"
118 extern const char *StrBufNOTNULL;
124 char *libcitadel_version_string(void);
125 int libcitadel_version_number(void);
126 void StartLibCitadel(size_t basesize);
127 void ShutDownLibCitadel(void);
130 * MIME parser declarations
133 void extract_key(char *target, char *source, long sourcelen, char *key, long keylen, char KeyEnd);
136 typedef void (*MimeParserCallBackType)(char *cbname,
148 void mime_parser(char *content_start, char *content_end,
149 MimeParserCallBackType CallBack,
150 MimeParserCallBackType PreMultiPartCallBack,
151 MimeParserCallBackType PostMultiPartCallBack,
157 char *fixed_partnum(char *);
158 void mime_decode(char *partnum,
159 char *part_start, size_t length,
160 char *content_type, char *charset, char *encoding,
163 char *name, char *filename,
164 MimeParserCallBackType CallBack,
165 MimeParserCallBackType PreMultiPartCallBack,
166 MimeParserCallBackType PostMultiPartCallBack,
169 void the_mime_parser(char *partnum,
170 char *content_start, char *content_end,
171 MimeParserCallBackType CallBack,
172 MimeParserCallBackType PreMultiPartCallBack,
173 MimeParserCallBackType PostMultiPartCallBack,
177 typedef struct StrBuf StrBuf;
180 #define CStrOf(a) #a, sizeof(#a) - 1
181 typedef struct _ConstStr {
185 #define CKEY(a) (a).Key, (a).len
187 StrBuf* NewStrBuf(void);
188 StrBuf* NewStrBufDup(const StrBuf *CopyMe);
189 StrBuf* NewStrBufPlain(const char* ptr, int nChars);
190 long StrBufShrinkToFit(StrBuf *Buf, int Force);
191 void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize);
192 void NewStrBufDupAppendFlush(StrBuf **CreateRelpaceMe, StrBuf *CopyFlushMe, const char *NoMe, int KeepOriginal);
194 int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars);
195 StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant);
196 #define NewConstStrBuf(a) _NewConstStrBuf(a, sizeof(a))
197 void FreeStrBuf (StrBuf **FreeMe);
198 char *SmashStrBuf (StrBuf **SmashMe);
199 void HFreeStrBuf (void *VFreeMe);
200 int FlushStrBuf(StrBuf *buf);
201 int FLUSHStrBuf(StrBuf *buf); /* expensive but doesn't leave content behind for others to find in case of errors */
203 const char *ChrPtr(const StrBuf *Str);
204 int StrLength(const StrBuf *Str);
205 #define SKEY(a) ChrPtr(a), StrLength(a)
206 long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue);
207 long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue);
209 int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error);
210 int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error);
213 int StrBufReadBLOBBuffered(StrBuf *Buf,
221 int StrBufTCP_read_buffered_line(StrBuf *Line,
225 int selectresolution,
227 int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
232 int selectresolution,
235 int StrBufSipLine(StrBuf *LineBuf, StrBuf *Buf, const char **Ptr);
236 int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong, const char *Repl, long ReplLen);
237 int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator);
238 int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars);
240 unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator);
241 long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator);
242 int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator);
243 int StrBufNum_tokens(const StrBuf *source, char tok);
244 int StrBufRemove_token(StrBuf *Source, int parmnum, char separator);
246 int StrBufHaveNextToken(const StrBuf *Source, const char **pStart);
247 int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator);
248 int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens);
249 unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator);
250 long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator);
251 int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator);
254 void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset);
255 void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset);
256 size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream);
257 void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...);
258 #ifdef SHOW_ME_VAPPEND_PRINTF
259 /* so owe don't create an include depndency, this is just visible on demand. */
260 void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap);
262 void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
263 void StrBufCutLeft(StrBuf *Buf, int nChars);
264 void StrBufCutRight(StrBuf *Buf, int nChars);
265 void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At);
266 void StrBufTrim(StrBuf *Buf);
267 void StrBufSpaceToBlank(StrBuf *Buf);
268 void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary);
269 void StrBufUpCase(StrBuf *Buf);
270 void StrBufLowerCase(StrBuf *Buf);
271 void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash);
272 void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source);
273 void StrBufEUid_escapize(StrBuf *target, const StrBuf *source);
275 void StrBufToUnixLF(StrBuf *buf);
276 void StrBufReplaceChars(StrBuf *buf, char search, char replace);
278 int CompressBuffer(StrBuf *Buf);
279 void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic);
280 void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic);
281 void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset);
282 int StrBufDecodeBase64(StrBuf *Buf);
283 int StrBufDecodeHex(StrBuf *Buf);
284 int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
285 StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
287 StrBuf *EmailAddress,
289 int StrBufSanitizeAscii(StrBuf *Buf, const char Mute);
290 #define LB (1) /* Internal escape chars */
293 void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
294 void StrBufHexescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
295 long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
296 long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
297 long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
298 void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
299 void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
301 long StrTol(const StrBuf *Buf);
302 int StrToi(const StrBuf *Buf);
303 int StrBufIsNumber(const StrBuf *Buf);
304 long StrBuf_Utf8StrLen(StrBuf *Buf);
305 long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen);
307 const char *GuessMimeType(const char *data, size_t dlen);
308 const char* GuessMimeByFilename(const char *what, size_t len);
310 /* Run once at Programstart */
311 int LoadIconDir(const char *DirName);
313 /* Select the icon for a given MIME type */
314 const char *GetIconFilename(char *MimeType, size_t len);
320 int safestrncpy(char *dest, const char *src, size_t n);
321 int num_tokens (const char *source, char tok);
322 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
323 long grab_token(char **dest, const char *source, int parmnum, char separator);
324 int extract_int (const char *source, int parmnum);
325 long extract_long (const char *source, int parmnum);
326 unsigned long extract_unsigned_long(const char *source, int parmnum);
327 void CtdlInitBase64Table(void);
328 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
329 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
330 unsigned int decode_hex(char *Source);
331 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
332 void StripSlashes(char *Dir, int TrailingSlash);
333 size_t striplt(char *);
334 int haschar(const char *st, int ch);
335 void remove_token(char *source, int parmnum, char separator);
336 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
337 int is_msg_in_sequence_set(const char *mset, long msgnum);
338 char *memreadline(char *start, char *buf, int maxlen);
339 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
340 const char *cmemreadline(const char *start, char *buf, int maxlen);
341 const char *cmemreadlinelen(const char *start, char *buf, int maxlen, int *retlen);
342 #define IsEmptyStr(a) ((a)[0] == '\0')
343 #define num_parms(source) num_tokens(source,(char)'|')
344 int stripout(char *str, char leftboundary, char rightboundary);
345 void stripallbut(char *str, char leftboundary, char rightboundary);
346 char *myfgets(char *s, int size, FILE *stream);
347 void urlesc(char *outbuf, size_t oblen, char *strbuf);
348 char *CtdlTempFileName(char *prefix1, int prefix2);
349 FILE *CtdlTempFile(void);
350 void generate_uuid(char *buf);
351 char *bmstrcasestr(char *text, const char *pattern);
352 char *bmstrcasestr_len(char *text, size_t textlen, const char *pattern, size_t patlen);
353 const char *cbmstrcasestr(const char *text, const char *pattern);
354 const char *cbmstrcasestr_len(const char *text, size_t textlen, const char *pattern, size_t patlen);
355 void CtdlMakeTempFileName(char *name, int len);
356 char *rfc2047encode(char *line, long length);
357 int is_msg_in_mset(const char *mset, long msgnum);
358 int pattern2(char *search, char *patn);
359 void stripltlen(char *, int *);
360 char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat);
361 void LoadEntityList(char *FileName);
367 #define CTDL_VCARD_MAGIC 0xa1f9
369 /* This data structure represents a vCard object currently in memory. */
380 struct vCard *vcard_new(void);
381 void vcard_add_prop(struct vCard *v, char *propname, char *propvalue);
382 struct vCard *vcard_load(char *vtext);
383 struct vCard *VCardLoad(StrBuf *vbtext);
385 void vcard_free(struct vCard *);
386 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
387 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
388 int instance, int return_propname);
389 char *vcard_serialize(struct vCard *);
390 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
391 void remove_charset_attribute(char *strbuf);
392 long StrBufUnescape(StrBuf *Buf, int StripBlanks);
395 * Hash list implementation for Citadel
397 #define HKEY(a) a, (sizeof(a) - 1)
399 typedef struct HashList HashList;
401 typedef struct HashKey HashKey;
403 typedef struct HashPos HashPos;
405 typedef void (*DeleteHashDataFunc)(void * Data);
406 typedef const char *(*PrintHashContent)(void * Data);
407 typedef int (*CompareFunc)(const void* Item1, const void*Item2);
408 typedef int (*HashFunc)(const char *Str, long Len);
409 typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd);
410 typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd);
412 int Flathash(const char *str, long len);
413 #define IKEY(a) (const char*) &a, sizeof(a)
415 HashList *NewHash(int Uniq, HashFunc F);
416 void DeleteHash(HashList **Hash);
417 void HDeleteHash(void *vHash);
418 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
419 void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
420 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
421 int GetHashKeys(HashList *Hash, char ***List);
422 int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
423 int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry);
424 HashPos *GetNewHashPos(HashList *Hash, int StepWidth);
425 int GetHashPosFromKey(HashList *Hash, const char *HKey, long HKLen, HashPos *At);
426 int DeleteEntryFromHash(HashList *Hash, HashPos *At);
427 int GetHashPosCounter(HashList *Hash, HashPos *At);
428 void DeleteHashPos(HashPos **DelMe);
429 int NextHashPos(HashList *Hash, HashPos *At);
430 int GetHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
431 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
432 int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **Data);
433 void SortByHashKey(HashList *Hash, int Order);
434 void SortByHashKeyStr(HashList *Hash);
435 int GetCount(HashList *Hash);
436 const void *GetSearchPayload(const void *HashVoid);
437 void SortByPayload(HashList *Hash, CompareFunc SortBy);
438 void reference_free_handler(void *ptr);
439 int HashLittle(const void *key, size_t length);
442 void convert_spaces_to_underscores(char *str);
443 int CheckEncode(const char *pch, long len, const char *pche);
446 * Convert 4 bytes char into an Integer.
447 * usefull for easy inexpensive hashing
448 * of for char strings.
450 #define CHAR4TO_INT(a) ((int) (a[0] | (a[1]<<8) | (a[2]<<16) | (a[3]<<24)))
452 /* vNote implementation */
454 #define CTDL_VNOTE_MAGIC 0xa1fa
472 struct vnote *vnote_new(void);
473 struct vnote *vnote_new_from_str(char *s);
474 void vnote_free(struct vnote *v);
475 char *vnote_serialize(struct vnote *v);
476 void vnote_serialize_output_field(char *append_to, char *field, char *label);
482 * Create JSON style structures in C plus serialize them to one string
485 typedef struct JsonValue JsonValue;
488 void DeleteJSONValue(void *vJsonValue);
490 JsonValue *NewJsonObject(const char *Key, long keylen);
492 JsonValue *NewJsonArray(const char *Key, long keylen);
494 JsonValue *NewJsonNumber(const char *Key, long keylen, long Number);
496 JsonValue *NewJsonBigNumber(const char *Key, long keylen, double Number);
498 JsonValue *NewJsonString(const char *Key, long keylen, StrBuf *CopyMe);
500 JsonValue *NewJsonPlainString(const char *Key, long keylen, const char *CopyMe, long len);
502 JsonValue *NewJsonNull(const char *Key, long keylen);
504 JsonValue *NewJsonBool(const char *Key, long keylen, int value);
506 void JsonArrayAppend(JsonValue *Array, JsonValue *Val);
508 void JsonObjectAppend(JsonValue *Array, JsonValue *Val);
510 void SerializeJson(StrBuf *Target, JsonValue *Val, int FreeVal);
515 * Citadels Wildfire implementation, see
516 * http://www.firephp.org/Wiki/Reference/Protocol
517 * and http://wildfirehq.org/ for details
519 typedef void (*AddHeaderFunc)(const char *HdrName, const char *HdrValue);
521 typedef enum _WF_MessageType {
530 JsonValue *WildFireException(const char *Filename, long FileLen,
535 void WildFireAddArray(JsonValue *ReportBase, JsonValue *Array, WF_MessageType Type);
537 JsonValue *WildFireMessagePlain(const char *Filename, long fnlen,
539 const char *Message, long len,
540 WF_MessageType Type);
542 JsonValue *WildFireMessage(const char *Filename, long fnlen,
545 WF_MessageType Type);
547 void WildFireInitBacktrace(const char *argvNull, int AddBaseFrameSkip);
549 void WildFireSerializePayload(StrBuf *JsonBuffer, StrBuf *OutBuf, int *MsgCount, AddHeaderFunc AddHdr);
552 #define WF_STRUCTINDEX "1"
556 #endif // LIBCITADEL_H