00001
00002
00003
00004
00005
00006
00007
00008 #ifndef LIBCITADEL_H
00009 #define LIBCITADEL_H
00010
00011
00012
00013
00014
00015 #include <time.h>
00016 #include <stdlib.h>
00017 #include <stdarg.h>
00018 #define LIBCITADEL_VERSION_NUMBER 783
00019
00020
00021
00022
00023 #ifndef SIZ
00024 #define SIZ 4096
00025 #endif
00026
00027
00028
00029 enum LogLevel {
00030
00031 CTDL_EMERG,
00032
00033 CTDL_ALERT,
00034
00035 CTDL_CRIT,
00036
00037 CTDL_ERR,
00038
00039 CTDL_WARNING,
00040
00041 CTDL_NOTICE,
00042
00043 CTDL_INFO,
00044
00045 CTDL_DEBUG
00046 };
00047
00048 typedef enum AXLevel {
00049 AxDeleted = 0,
00050 AxNewU = 1,
00051 AxProbU = 2,
00052 AxLocU = 3,
00053 AxNetU = 4,
00054 AxPrefU = 5,
00055 AxAideU = 6
00056 }eUsrAxlvl;
00057
00058 enum RoomNetCfg {
00059 subpending,
00060 unsubpending,
00061 lastsent,
00062 ignet_push_share,
00063 listrecp,
00064 digestrecp,
00065 pop3client,
00066 rssclient,
00067 participate,
00068 maxRoomNetCfg
00069 };
00070
00071
00072 typedef enum __GPEXWhichPolicy {
00073 roompolicy,
00074 floorpolicy,
00075 sitepolicy,
00076 mailboxespolicy,
00077 maxpolicy
00078 }GPEXWhichPolicy;
00079
00080
00081
00082
00083
00084 #define VIEW_BBS 0
00085 #define VIEW_MAILBOX 1
00086 #define VIEW_ADDRESSBOOK 2
00087 #define VIEW_CALENDAR 3
00088 #define VIEW_TASKS 4
00089 #define VIEW_NOTES 5
00090 #define VIEW_WIKI 6
00091 #define VIEW_CALBRIEF 7
00092 #define VIEW_JOURNAL 8
00093 #define VIEW_BLOG 9
00094
00095
00096 #ifndef IsEmptyStr
00097 #define IsEmptyStr(a) ((a)[0] == '\0')
00098 #endif
00099
00100
00101
00102
00103
00104 extern const char *StrBufNOTNULL;
00105
00106
00107
00108
00109
00110 char *libcitadel_version_string(void);
00111 int libcitadel_version_number(void);
00112 void StartLibCitadel(size_t basesize);
00113 void ShutDownLibCitadel(void);
00114
00115
00116
00117
00118
00119 void extract_key(char *target, char *source, long sourcelen, char *key, long keylen, char KeyEnd);
00120
00121
00122 typedef void (*MimeParserCallBackType)(char *cbname,
00123 char *cbfilename,
00124 char *cbpartnum,
00125 char *cbdisp,
00126 void *cbcontent,
00127 char *cbtype,
00128 char *cbcharset,
00129 size_t cblength,
00130 char *cbencoding,
00131 char *cbid,
00132 void *cbuserdata);
00133
00134 void mime_parser(char *content_start, char *content_end,
00135 MimeParserCallBackType CallBack,
00136 MimeParserCallBackType PreMultiPartCallBack,
00137 MimeParserCallBackType PostMultiPartCallBack,
00138 void *userdata,
00139 int dont_decode);
00140
00141
00142
00143 char *fixed_partnum(char *);
00144 void mime_decode(char *partnum,
00145 char *part_start, size_t length,
00146 char *content_type, char *charset, char *encoding,
00147 char *disposition,
00148 char *id,
00149 char *name, char *filename,
00150 MimeParserCallBackType CallBack,
00151 MimeParserCallBackType PreMultiPartCallBack,
00152 MimeParserCallBackType PostMultiPartCallBack,
00153 void *userdata,
00154 int dont_decode);
00155 void the_mime_parser(char *partnum,
00156 char *content_start, char *content_end,
00157 MimeParserCallBackType CallBack,
00158 MimeParserCallBackType PreMultiPartCallBack,
00159 MimeParserCallBackType PostMultiPartCallBack,
00160 void *userdata,
00161 int dont_decode);
00162
00163 typedef struct StrBuf StrBuf;
00164
00165 #define strof(a) #a
00166 #define CStrOf(a) #a, sizeof(#a) - 1
00167 typedef struct _ConstStr {
00168 const char *Key;
00169 long len;
00170 }ConstStr;
00171 #define CKEY(a) (a).Key, (a).len
00172
00173 StrBuf* NewStrBuf(void);
00174 StrBuf* NewStrBufDup(const StrBuf *CopyMe);
00175 StrBuf* NewStrBufPlain(const char* ptr, int nChars);
00176 long StrBufShrinkToFit(StrBuf *Buf, int Force);
00177 void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize);
00178
00179 int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars);
00180 StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant);
00181 #define NewConstStrBuf(a) _NewConstStrBuf(a, sizeof(a))
00182 void FreeStrBuf (StrBuf **FreeMe);
00183 char *SmashStrBuf (StrBuf **SmashMe);
00184 void HFreeStrBuf (void *VFreeMe);
00185 int FlushStrBuf(StrBuf *buf);
00186 int FLUSHStrBuf(StrBuf *buf);
00187
00188 const char *ChrPtr(const StrBuf *Str);
00189 int StrLength(const StrBuf *Str);
00190 #define SKEY(a) ChrPtr(a), StrLength(a)
00191 long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue);
00192 long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char PookValue);
00193
00194 int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error);
00195 int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error);
00196 #define NNN_TERM 1
00197 #define O_TERM 0
00198 int StrBufReadBLOBBuffered(StrBuf *Buf,
00199 StrBuf *IOBuf,
00200 const char **BufPos,
00201 int *fd,
00202 int append,
00203 long nBytes,
00204 int check,
00205 const char **Error);
00206 int StrBufTCP_read_buffered_line(StrBuf *Line,
00207 StrBuf *buf,
00208 int *fd,
00209 int timeout,
00210 int selectresolution,
00211 const char **Error);
00212 int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
00213 StrBuf *buf,
00214 const char **Pos,
00215 int *fd,
00216 int timeout,
00217 int selectresolution,
00218 const char **Error);
00219
00220 int StrBufSipLine(StrBuf *LineBuf, StrBuf *Buf, const char **Ptr);
00221 int StrBufReplaceToken(StrBuf *Buf, long where, long HowLong, const char *Repl, long ReplLen);
00222 int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator);
00223 int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t nChars);
00224
00225 unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator);
00226 long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator);
00227 int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator);
00228 int StrBufNum_tokens(const StrBuf *source, char tok);
00229 int StrBufRemove_token(StrBuf *Source, int parmnum, char separator);
00230
00231 int StrBufHaveNextToken(const StrBuf *Source, const char **pStart);
00232 int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pStart, char separator);
00233 int StrBufSkip_NTokenS(const StrBuf *Source, const char **pStart, char separator, int nTokens);
00234 unsigned long StrBufExtractNext_unsigned_long(const StrBuf* Source, const char **pStart, char separator);
00235 long StrBufExtractNext_long(const StrBuf* Source, const char **pStart, char separator);
00236 int StrBufExtractNext_int(const StrBuf* Source, const char **pStart, char separator);
00237
00238
00239 void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset);
00240 void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset);
00241 size_t CurlFillStrBuf_callback(void *ptr, size_t size, size_t nmemb, void *stream);
00242 void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...);
00243 #ifdef SHOW_ME_VAPPEND_PRINTF
00244
00245 void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap);
00246 #endif
00247 void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
00248 void StrBufCutLeft(StrBuf *Buf, int nChars);
00249 void StrBufCutRight(StrBuf *Buf, int nChars);
00250 void StrBufCutAt(StrBuf *Buf, int AfternChars, const char *At);
00251 void StrBufTrim(StrBuf *Buf);
00252 void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary);
00253 void StrBufUpCase(StrBuf *Buf);
00254 void StrBufLowerCase(StrBuf *Buf);
00255 void StrBufStripSlashes(StrBuf *Dir, int RemoveTrailingSlash);
00256 void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source);
00257 void StrBufEUid_escapize(StrBuf *target, const StrBuf *source);
00258
00259 void StrBufToUnixLF(StrBuf *buf);
00260 void StrBufReplaceChars(StrBuf *buf, char search, char replace);
00261
00262 int CompressBuffer(StrBuf *Buf);
00263 void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic);
00264 void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic);
00265 void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset);
00266 int StrBufDecodeBase64(StrBuf *Buf);
00267 int StrBufDecodeHex(StrBuf *Buf);
00268 int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
00269 StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
00270 StrBuf *UserName,
00271 StrBuf *EmailAddress,
00272 StrBuf *EncBuf);
00273 int StrBufSanitizeAscii(StrBuf *Buf, const char Mute);
00274 #define LB (1)
00275 #define RB (2)
00276 #define QU (3)
00277 void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
00278 void StrBufHexescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
00279 long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
00280 long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
00281 long StrHtmlEcmaEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
00282 void StrMsgEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
00283 void StrIcalEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
00284
00285 long StrTol(const StrBuf *Buf);
00286 int StrToi(const StrBuf *Buf);
00287 int StrBufIsNumber(const StrBuf *Buf);
00288 long StrBuf_Utf8StrLen(StrBuf *Buf);
00289 long StrBuf_Utf8StrCut(StrBuf *Buf, int maxlen);
00290
00291 const char *GuessMimeType(const char *data, size_t dlen);
00292 const char* GuessMimeByFilename(const char *what, size_t len);
00293
00294
00295 int LoadIconDir(const char *DirName);
00296
00297
00298 const char *GetIconFilename(char *MimeType, size_t len);
00299
00300
00301
00302
00303
00304 int safestrncpy(char *dest, const char *src, size_t n);
00305 int num_tokens (const char *source, char tok);
00306 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
00307 long grab_token(char **dest, const char *source, int parmnum, char separator);
00308 int extract_int (const char *source, int parmnum);
00309 long extract_long (const char *source, int parmnum);
00310 unsigned long extract_unsigned_long(const char *source, int parmnum);
00311 void CtdlInitBase64Table(void);
00312 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
00313 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
00314 unsigned int decode_hex(char *Source);
00315 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
00316 void StripSlashes(char *Dir, int TrailingSlash);
00317 size_t striplt(char *);
00318 int haschar(const char *st, int ch);
00319 void remove_token(char *source, int parmnum, char separator);
00320 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
00321 int is_msg_in_sequence_set(const char *mset, long msgnum);
00322 char *memreadline(char *start, char *buf, int maxlen);
00323 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
00324 const char *cmemreadline(const char *start, char *buf, int maxlen);
00325 const char *cmemreadlinelen(const char *start, char *buf, int maxlen, int *retlen);
00326 #define IsEmptyStr(a) ((a)[0] == '\0')
00327 #define num_parms(source) num_tokens(source,(char)'|')
00328 int stripout(char *str, char leftboundary, char rightboundary);
00329 void stripallbut(char *str, char leftboundary, char rightboundary);
00330 char *myfgets(char *s, int size, FILE *stream);
00331 void urlesc(char *outbuf, size_t oblen, char *strbuf);
00332 char *CtdlTempFileName(char *prefix1, int prefix2);
00333 FILE *CtdlTempFile(void);
00334 void generate_uuid(char *buf);
00335 char *bmstrcasestr(char *text, const char *pattern);
00336 char *bmstrcasestr_len(char *text, size_t textlen, const char *pattern, size_t patlen);
00337 const char *cbmstrcasestr(const char *text, const char *pattern);
00338 const char *cbmstrcasestr_len(const char *text, size_t textlen, const char *pattern, size_t patlen);
00339 void CtdlMakeTempFileName(char *name, int len);
00340 char *rfc2047encode(char *line, long length);
00341 int is_msg_in_mset(const char *mset, long msgnum);
00342 int pattern2(char *search, char *patn);
00343 void stripltlen(char *, int *);
00344 char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat);
00345 void LoadEntityList(char *FileName);
00346
00347
00348
00349
00350
00351 #define CTDL_VCARD_MAGIC 0xa1f9
00352
00353
00354 struct vCard {
00355 int magic;
00356 int numprops;
00357 struct vCardProp {
00358 char *name;
00359 char *value;
00360 } *prop;
00361 };
00362
00363
00364 struct vCard *vcard_new(void);
00365 void vcard_add_prop(struct vCard *v, char *propname, char *propvalue);
00366 struct vCard *vcard_load(char *vtext);
00367 struct vCard *VCardLoad(StrBuf *vbtext);
00368
00369 void vcard_free(struct vCard *);
00370 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
00371 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
00372 int instance, int return_propname);
00373 char *vcard_serialize(struct vCard *);
00374 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
00375 void remove_charset_attribute(char *strbuf);
00376 long StrBufUnescape(StrBuf *Buf, int StripBlanks);
00377
00378
00379
00380
00381 #define HKEY(a) a, (sizeof(a) - 1)
00382
00383 typedef struct HashList HashList;
00384
00385 typedef struct HashKey HashKey;
00386
00387 typedef struct HashPos HashPos;
00388
00389 typedef void (*DeleteHashDataFunc)(void * Data);
00390 typedef const char *(*PrintHashContent)(void * Data);
00391 typedef int (*CompareFunc)(const void* Item1, const void*Item2);
00392 typedef int (*HashFunc)(const char *Str, long Len);
00393 typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd);
00394 typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd);
00395
00396 int Flathash(const char *str, long len);
00397 #define IKEY(a) (const char*) &a, sizeof(a)
00398
00399 HashList *NewHash(int Uniq, HashFunc F);
00400 void DeleteHash(HashList **Hash);
00401 void HDeleteHash(void *vHash);
00402 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
00403 void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
00404 int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
00405 int GetHashKeys(HashList *Hash, char ***List);
00406 int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
00407 int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry);
00408 HashPos *GetNewHashPos(HashList *Hash, int StepWidth);
00409 int GetHashPosFromKey(HashList *Hash, const char *HKey, long HKLen, HashPos *At);
00410 int DeleteEntryFromHash(HashList *Hash, HashPos *At);
00411 int GetHashPosCounter(HashList *Hash, HashPos *At);
00412 void DeleteHashPos(HashPos **DelMe);
00413 int NextHashPos(HashList *Hash, HashPos *At);
00414 int GetHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
00415 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
00416 int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **Data);
00417 void SortByHashKey(HashList *Hash, int Order);
00418 void SortByHashKeyStr(HashList *Hash);
00419 int GetCount(HashList *Hash);
00420 const void *GetSearchPayload(const void *HashVoid);
00421 void SortByPayload(HashList *Hash, CompareFunc SortBy);
00422 void reference_free_handler(void *ptr);
00423 int HashLittle(const void *key, size_t length);
00424
00425
00426 void convert_spaces_to_underscores(char *str);
00427 int CheckEncode(const char *pch, long len, const char *pche);
00428
00429
00430
00431
00432
00433
00434 #define CHAR4TO_INT(a) ((int) (a[0] | (a[1]<<8) | (a[2]<<16) | (a[3]<<24)))
00435
00436
00437
00438 #define CTDL_VNOTE_MAGIC 0xa1fa
00439
00440 struct vnote {
00441 int magic;
00442 char *uid;
00443 char *summary;
00444 char *body;
00445 int pos_left;
00446 int pos_top;
00447 int pos_width;
00448 int pos_height;
00449 int color_red;
00450 int color_green;
00451 int color_blue;
00452 };
00453
00454
00455
00456 struct vnote *vnote_new(void);
00457 struct vnote *vnote_new_from_str(char *s);
00458 void vnote_free(struct vnote *v);
00459 char *vnote_serialize(struct vnote *v);
00460 void vnote_serialize_output_field(char *append_to, char *field, char *label);
00461
00462
00463
00464
00465
00466
00467
00468
00469 typedef struct JsonValue JsonValue;
00470
00471
00472 void DeleteJSONValue(void *vJsonValue);
00473
00474 JsonValue *NewJsonObject(const char *Key, long keylen);
00475
00476 JsonValue *NewJsonArray(const char *Key, long keylen);
00477
00478 JsonValue *NewJsonNumber(const char *Key, long keylen, long Number);
00479
00480 JsonValue *NewJsonBigNumber(const char *Key, long keylen, double Number);
00481
00482 JsonValue *NewJsonString(const char *Key, long keylen, StrBuf *CopyMe);
00483
00484 JsonValue *NewJsonPlainString(const char *Key, long keylen, const char *CopyMe, long len);
00485
00486 JsonValue *NewJsonNull(const char *Key, long keylen);
00487
00488 JsonValue *NewJsonBool(const char *Key, long keylen, int value);
00489
00490 void JsonArrayAppend(JsonValue *Array, JsonValue *Val);
00491
00492 void JsonObjectAppend(JsonValue *Array, JsonValue *Val);
00493
00494 void SerializeJson(StrBuf *Target, JsonValue *Val, int FreeVal);
00495
00496
00497
00498
00499
00500
00501
00502
00503 typedef void (*AddHeaderFunc)(const char *HdrName, const char *HdrValue);
00504
00505 typedef enum _WF_MessageType {
00506 eLOG,
00507 eINFO,
00508 eWARN,
00509 eERROR,
00510 eTRACE,
00511 eEXCEPTION
00512 } WF_MessageType;
00513
00514 JsonValue *WildFireException(const char *Filename, long FileLen,
00515 long LineNo,
00516 StrBuf *Message,
00517 int StackOffset);
00518
00519 void WildFireAddArray(JsonValue *ReportBase, JsonValue *Array, WF_MessageType Type);
00520
00521 JsonValue *WildFireMessagePlain(const char *Filename, long fnlen,
00522 long LineNo,
00523 const char *Message, long len,
00524 WF_MessageType Type);
00525
00526 JsonValue *WildFireMessage(const char *Filename, long fnlen,
00527 long lineno,
00528 StrBuf *Msg,
00529 WF_MessageType Type);
00530
00531 void WildFireInitBacktrace(const char *argvNull, int AddBaseFrameSkip);
00532
00533 void WildFireSerializePayload(StrBuf *JsonBuffer, StrBuf *OutBuf, int *MsgCount, AddHeaderFunc AddHdr);
00534
00535 #define WF_MAJOR "1"
00536 #define WF_STRUCTINDEX "1"
00537 #define WF_SUB "1"
00538
00539
00540 #endif // LIBCITADEL_H