Updated the MIME Parser API to include Content-ID in
[citadel.git] / libcitadel / lib / libcitadel.h
index 5d80409505835388f0c31fe0785e8a891cb999d1..35438cdd7625121041795f56c4a409d1f77acdb6 100644 (file)
@@ -4,13 +4,18 @@
  */
 
 
+/* protect against double includes */
+#ifndef LIBCITADEL_H
+#define LIBCITADEL_H
+
 
 /*
  * since we reference time_t...
  */
 #include <time.h>
 #include <stdlib.h>
-#define LIBCITADEL_VERSION_NUMBER      106
+#include <stdarg.h>
+#define LIBCITADEL_VERSION_NUMBER      739
 
 /*
  * Here's a bunch of stupid magic to make the MIME parser portable.
 #endif
 
 
+/* Logging levels - correspond to syslog(3) */
+enum LogLevel {
+       /* When about to exit the server for an unrecoverable error */
+        CTDL_EMERG,    /* system is unusable */
+       /* Manual intervention is required to avoid an abnormal exit */
+        CTDL_ALERT,    /* action must be taken immediately */
+       /* The server can continue to run with degraded functionality */
+        CTDL_CRIT,     /* critical conditions */
+       /* An error occurs but the server continues to run normally */
+        CTDL_ERR,      /* error conditions */
+       /* An abnormal condition was detected; server will continue normally */
+        CTDL_WARNING,  /* warning conditions */
+       /* Normal messages (login/out, activity, etc.) */
+        CTDL_NOTICE,   /* normal but significant condition */
+       /* Unimportant progress messages, etc. */
+        CTDL_INFO,     /* informational */
+       /* Debugging messages */
+        CTDL_DEBUG     /* debug-level messages */
+};
+
+
 /*
  * View definitions.
  * Note that not all views are implemented in all clients.
@@ -64,6 +90,7 @@ void mime_parser(char *content_start, char *content_end,
                        char *cbcharset,
                        size_t cblength,
                        char *cbencoding,
+                       char *cbid,
                        void *cbuserdata),
                void (*PreMultiPartCallBack)
                        (char *cbname,
@@ -75,6 +102,7 @@ void mime_parser(char *content_start, char *content_end,
                        char *cbcharset,
                        size_t cblength,
                        char *cbencoding,
+                       char *cbid,
                        void *cbuserdata),
                void (*PostMultiPartCallBack)
                        (char *cbname,
@@ -86,6 +114,7 @@ void mime_parser(char *content_start, char *content_end,
                        char *cbcharset,
                        size_t cblength,
                        char *cbencoding,
+                       char *cbid,
                        void *cbuserdata),
                void *userdata,
                int dont_decode
@@ -98,6 +127,7 @@ void mime_decode(char *partnum,
                 char *part_start, size_t length,
                 char *content_type, char *charset, char *encoding,
                 char *disposition,
+                char *id,
                 char *name, char *filename,
                 void (*CallBack)
                  (char *cbname,
@@ -109,6 +139,7 @@ void mime_decode(char *partnum,
                   char *cbcharset,
                   size_t cblength,
                   char *cbencoding,
+                  char *cbid,
                   void *cbuserdata),
                 void (*PreMultiPartCallBack)
                  (char *cbname,
@@ -120,6 +151,7 @@ void mime_decode(char *partnum,
                   char *cbcharset,
                   size_t cblength,
                   char *cbencoding,
+                  char *cbid,
                   void *cbuserdata),
                 void (*PostMultiPartCallBack)
                  (char *cbname,
@@ -131,6 +163,7 @@ void mime_decode(char *partnum,
                   char *cbcharset,
                   size_t cblength,
                   char *cbencoding,
+                  char *cbid,
                   void *cbuserdata),
                  void *userdata,
                  int dont_decode
@@ -147,6 +180,7 @@ void the_mime_parser(char *partnum,
                       char *cbcharset,
                       size_t cblength,
                       char *cbencoding,
+                      char *cbid,
                       void *cbuserdata),
                     void (*PreMultiPartCallBack)
                      (char *cbname,
@@ -158,6 +192,7 @@ void the_mime_parser(char *partnum,
                       char *cbcharset,
                       size_t cblength,
                       char *cbencoding,
+                      char *cbid,
                       void *cbuserdata),
                     void (*PostMultiPartCallBack)
                      (char *cbname,
@@ -169,23 +204,93 @@ void the_mime_parser(char *partnum,
                       char *cbcharset,
                       size_t cblength,
                       char *cbencoding,
+                      char *cbid,
                       void *cbuserdata),
                      void *userdata,
                      int dont_decode
 );
 
-const char *GuessMimeType(char *data, size_t dlen);
+typedef struct StrBuf StrBuf;
+
+StrBuf* NewStrBuf(void);
+StrBuf* NewStrBufDup(const StrBuf *CopyMe);
+StrBuf* NewStrBufPlain(const char* ptr, int nChars);
+int StrBufPlain(StrBuf *Buf, const char* ptr, int nChars);
+StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant);
+#define NewConstStrBuf(a) _NewConstStrBuf(a, sizeof(a))
+void FreeStrBuf (StrBuf **FreeMe);
+void HFreeStrBuf (void *VFreeMe);
+int FlushStrBuf(StrBuf *buf);
+
+const char *ChrPtr(const StrBuf *Str);
+int StrLength(const StrBuf *Str);
+#define SKEY(a) ChrPtr(a), StrLength(a)
+long StrBufPeek(StrBuf *Buf, const char* ptr, long nThChar, char PeekValue);
+
+int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error);
+int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **Error);
+int StrBufTCP_read_buffered_line(StrBuf *Line, 
+                                StrBuf *buf, 
+                                int *fd, 
+                                int timeout, 
+                                int selectresolution, 
+                                const char **Error);
+
+int StrBufExtract_token(StrBuf *dest, const StrBuf *Source, int parmnum, char separator);
+int StrBufSub(StrBuf *dest, const StrBuf *Source, size_t Offset, size_t nChars);
+unsigned long StrBufExtract_unsigned_long(const StrBuf* Source, int parmnum, char separator);
+long StrBufExtract_long(const StrBuf* Source, int parmnum, char separator);
+int StrBufExtract_int(const StrBuf* Source, int parmnum, char separator);
+inline int StrBufNum_tokens(const StrBuf *source, char tok);
+int StrBufRemove_token(StrBuf *Source, int parmnum, char separator);
+
+void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, size_t Offset);
+void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, size_t Offset);
+void StrBufAppendPrintf(StrBuf *Buf, const char *format, ...);
+#ifdef SHOW_ME_VAPPEND_PRINTF
+/* so owe don't create an include depndency, this is just visible on demand. */
+void StrBufVAppendPrintf(StrBuf *Buf, const char *format, va_list ap);
+#endif
+void StrBufPrintf(StrBuf *Buf, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
+void StrBufCutLeft(StrBuf *Buf, int nChars);
+void StrBufCutRight(StrBuf *Buf, int nChars);
+void StrBufUpCase(StrBuf *Buf);
+void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source);
+void StrBufEUid_escapize(StrBuf *target, const StrBuf *source);
+
+void StrBufReplaceChars(StrBuf *buf, char search, char replace);
+
+int CompressBuffer(StrBuf *Buf);
+int StrBufDecodeBase64(StrBuf *Buf);
+int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
+#define LB                     (1)             /* Internal escape chars */
+#define RB                     (2)
+#define QU                     (3)
+void StrBufUrlescAppend(StrBuf *OutBuf, const StrBuf *In, const char *PlainIn);
+long StrEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks);
+void StrMsgEscAppend(StrBuf *Target, StrBuf *Source, const char *PlainIn);
+
+long StrTol(const StrBuf *Buf);
+int StrToi(const StrBuf *Buf);
+
+const char *GuessMimeType(const char *data, size_t dlen);
 const char* GuessMimeByFilename(const char *what, size_t len);
 
-/** Run once at Programstart */
+/* Run once at Programstart */
 int LoadIconDir(const char *DirName);
-/** guess an icon to the mimetype */
+
+/* Select the icon for a given MIME type */
 const char *GetIconFilename(char *MimeType, size_t len);
+
 void ShutDownLibCitadel(void);
 
 
 /* tools */
 
+int Ctdl_IsUtf8SequenceStart(char Char);
+int Ctdl_GetUtf8SequenceLength(char Char);
+int Ctdl_Utf8StrLen(char *str);
+char *Ctdl_Utf8StrCut(char *str, int maxlen);
 
 
 int safestrncpy(char *dest, const char *src, size_t n);
@@ -221,6 +326,8 @@ char *rfc2047encode(char *line, long length);
 int is_msg_in_mset(char *mset, long msgnum);
 int pattern2(char *search, char *patn);
 void stripltlen(char *, int *);
+char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaformat);
+void LoadEntityList(char *FileName);
 
 
 
@@ -249,11 +356,12 @@ char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
 char *vcard_serialize(struct vCard *);
 void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
 void remove_charset_attribute(char *strbuf);
+long StrBufUnescape(StrBuf *Buf, int StripBlanks);
 
-/**
- * Citadels Hashlist Implementation
+/*
+ * Hash list implementation for Citadel
  */
-
+#define HKEY(a) a, sizeof(a) - 1
 typedef struct HashList HashList;
 
 typedef struct HashKey HashKey;
@@ -262,23 +370,65 @@ typedef struct HashPos HashPos;
 
 typedef void (*DeleteHashDataFunc)(void * Data);
 typedef const char *(*PrintHashContent)(void * Data);
+typedef int (*CompareFunc)(const void* Item1, const void*Item2);
+typedef int (*HashFunc)(const char *Str, long Len);
+typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd);
+typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd);
 
-HashList *NewHash(void);
-
+HashList *NewHash(int Uniq, HashFunc F);
 void DeleteHash(HashList **Hash);
-
+void HDeleteHash(void *vHash);
 int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
+void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
+int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
+int GetHashKeys(HashList *Hash, char ***List);
+int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
+int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry);
+HashPos *GetNewHashPos(void);
+void DeleteHashPos(HashPos **DelMe);
+int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
+void SortByHashKey(HashList *Hash, int Order);
+void SortByHashKeyStr(HashList *Hash);
+int GetCount(HashList *Hash);
+const void *GetSearchPayload(const void *HashVoid);
+void SortByPayload(HashList *Hash, CompareFunc SortBy);
+void generic_free_handler(void *ptr);
 
-void Put(HashList *Hash, char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
 
-int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
+void convert_spaces_to_underscores(char *str);
 
-int GetHashKeys(HashList *Hash, char ***List);
+/*
+ * Convert 4 bytes char into an Integer.
+ * usefull for easy inexpensive hashing 
+ * of for char strings.
+ */
+#define CHAR4TO_INT(a) ((int) (a[0] | (a[1]<<8) | (a[2]<<16) | (a[3]<<24)))
 
-int PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
+/* vNote implementation */
 
-HashPos *GetNewHashPos(void);
+#define CTDL_VNOTE_MAGIC       0xa1fa
+
+struct vnote {
+       int magic;
+       char *uid;
+       char *summary;
+       char *body;
+       int pos_left;
+       int pos_top;
+       int pos_width;
+       int pos_height;
+       int color_red;
+       int color_green;
+       int color_blue;
+};
+
+
+
+struct vnote *vnote_new(void);
+struct vnote *vnote_new_from_str(char *s);
+void vnote_free(struct vnote *v);
+char *vnote_serialize(struct vnote *v);
+void vnote_serialize_output_field(char *append_to, char *field, char *label);
 
-void DeleteHashPos(HashPos **DelMe);
 
-int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data);
+#endif // LIBCITADEL_H