]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/libcitadel.h
+ add C-to-Json serializer
[citadel.git] / libcitadel / lib / libcitadel.h
index 9a5ec9a0f99004e4fe5b22466c1b4f5327384031..a20bf1a1d9ec454b98feed75acaa8d6e43e0208d 100644 (file)
@@ -244,15 +244,15 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
 
 int StrBufSipLine(StrBuf *LineBuf, StrBuf *Buf, const char **Ptr);
 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);
+int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long 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 StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset);
+void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long 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. */
@@ -281,6 +281,7 @@ int StrBufRFC2047encode(StrBuf **target, const StrBuf *source);
 #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);
+long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn);
 void StrMsgEscAppend(StrBuf *Target, StrBuf *Source, const char *PlainIn);
 
 long StrTol(const StrBuf *Buf);
@@ -324,7 +325,7 @@ void striplt(char *);
 int haschar(const char *st, int ch);
 void remove_token(char *source, int parmnum, char separator);
 void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
-int is_msg_in_sequence_set(char *mset, long msgnum);
+int is_msg_in_sequence_set(const char *mset, long msgnum);
 char *memreadline(char *start, char *buf, int maxlen);
 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
 #define IsEmptyStr(a) ((a)[0] == '\0')
@@ -339,7 +340,7 @@ void generate_uuid(char *buf);
 char *bmstrcasestr(char *text, char *pattern);
 void CtdlMakeTempFileName(char *name, int len);
 char *rfc2047encode(char *line, long length);
-int is_msg_in_mset(char *mset, long msgnum);
+int is_msg_in_mset(const 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);
@@ -453,4 +454,81 @@ char *vnote_serialize(struct vnote *v);
 void vnote_serialize_output_field(char *append_to, char *field, char *label);
 
 
+
+
+/*
+ * Create JSON style structures in C plus serialize them to one string
+ */
+
+typedef struct JsonValue JsonValue;
+
+
+void DeleteJSONValue(void *vJsonValue);
+
+JsonValue *NewJsonObject(const char *Key, long keylen);
+
+JsonValue *NewJsonArray(const char *Key, long keylen);
+
+JsonValue *NewJsonNumber(const char *Key, long keylen, long Number);
+
+JsonValue *NewJsonBigNumber(const char *Key, long keylen, double Number);
+
+JsonValue *NewJsonString(const char *Key, long keylen, StrBuf *CopyMe);
+
+JsonValue *NewJsonPlainString(const char *Key, long keylen, const char *CopyMe, long len);
+
+JsonValue *NewJsonNull(const char *Key, long keylen);
+
+JsonValue *NewJsonBool(const char *Key, long keylen, int value);
+
+void JsonArrayAppend(JsonValue *Array, JsonValue *Val);
+
+void JsonObjectAppend(JsonValue *Array, JsonValue *Val);
+
+void SerializeJson(StrBuf *Target, JsonValue *Val);
+
+
+
+/*
+ * Citadels Wildfire implementation, see 
+ * http://www.firephp.org/Wiki/Reference/Protocol
+ * and http://wildfirehq.org/ for details
+ */
+typedef void (*AddHeaderFunc)(const char *HdrName, const char *HdrValue);
+
+typedef enum _WF_MessageType {
+       eLOG, 
+       eINFO,
+       eWARN,
+       eERROR,
+       eTRACE,
+       eEXCEPTION
+} WF_MessageType;
+
+JsonValue *WildFireException(StrBuf *Message,
+                            const char *Filename, long FileLen,
+                            long LineNo,
+                            int StackOffset);
+
+void WildFireAddArray(JsonValue *ReportBase, JsonValue *Array, WF_MessageType Type);
+
+JsonValue *WildFireMessagePlain(const char *Filename, long fnlen,
+                                  long LineNo,
+                                  const char *Message, long len, 
+                                  WF_MessageType Type);
+
+JsonValue *WildFireMessage(const char *Filename, long fnlen,
+                          long lineno,
+                          StrBuf *Msg, 
+                          WF_MessageType Type);
+
+void WildFireInitBacktrace(const char *argvNull, int AddBaseFrameSkip);
+
+void WildFireSerializePayload(StrBuf *JsonBuffer, StrBuf *OutBuf, int *MsgCount, AddHeaderFunc AddHdr);
+
+#define WF_MAJOR "1"
+#define WF_STRUCTINDEX "1"
+#define WF_SUB "1"
+
+
 #endif // LIBCITADEL_H