* fix COND:PREFS
[citadel.git] / webcit / webcit.h
index 1e02177b5a821915bef29c9689fbba19c1bb2d0f..365c2e67f36b6727ce4c12ee064add24a3687c1b 100644 (file)
@@ -74,24 +74,7 @@ extern locale_t wc_locales[];
 #include <zlib.h>
 #endif
 
-
-/* Work around PACKAGE/VERSION defs that are (not supposed to be?) in ical.h */
-#ifdef PACKAGE
-# define CTDL_PACKAGE PACKAGE
-# undef PACKAGE
-#endif
-
-#ifdef PACKAGE_STRING
-# define CTDL_PACKAGE_STRING PACKAGE_STRING
-//# undef PACKAGE_STRING
-#endif
-
-#ifdef VERSION
-# define CTDL_VERSION VERSION
-# undef VERSION
-#endif
-
-#include <ical.h>
+#include <libical/ical.h>
 
 #undef PACKAGE
 #undef VERSION
@@ -129,9 +112,6 @@ extern locale_t wc_locales[];
 #define        LIBCITADEL_MIN          738             /* min required libcitadel ver */
 #define DEFAULT_HOST           "localhost"     /* Default Citadel server */
 #define DEFAULT_PORT           "504"
-#define LB                     (1)             /* Internal escape chars */
-#define RB                     (2)
-#define QU                     (3)
 #define TARGET                 "webcit01"      /* Target for inline URL's */
 #define HOUSEKEEPING           15              /* Housekeeping frequency */
 #define MIN_WORKER_THREADS     5
@@ -228,8 +208,7 @@ struct httprequest {
 typedef struct urlcontent urlcontent;
 struct urlcontent {
        char url_key[32];          /**< the variable name */
-       char *url_data;            /**< its value */
-       size_t url_data_size;      /**< how big is it? */
+       StrBuf *url_data;            /**< its value */
 };
 
 /**
@@ -286,19 +265,82 @@ struct roomlisting {
  * \brief Dynamic content for variable substitution in templates
  */
 typedef struct _wcsubst {
-       int wcs_type;                       /**< which type of ??? */
-       char wcs_key[32];                   /**< ??? what?*/
-       void *wcs_value;                    /**< ???? what?*/
+       int wcs_type;                       /**< which type of Substitution are we */
+       char wcs_key[32];                   /**< copy of our hashkey for debugging */
+       StrBuf *wcs_value;                  /**< if we're a string, keep it here */
+       long lvalue;                        /**< type long? keep data here */
        void (*wcs_function)(void); /**< funcion hook ???*/
 } wcsubst;
 
+#define TYPE_STR   1
+#define TYPE_LONG  2
+#define MAXPARAM  20
+typedef struct _TemplateParam {
+       const char *Start;
+       int Type;
+       long len;
+       long lvalue;
+} TemplateParam;
+
+typedef struct _TemplateToken {
+       StrBuf *FlatToken;
+       long Line;
+       const char *pTokenStart;
+       size_t TokenStart;
+       size_t TokenEnd;
+       const char *pTokenEnd;
+       int Flags;
+
+       const char *pName;
+       size_t NameEnd;
+
+       int HaveParameters;
+       int nParameters;
+       TemplateParam *Params[MAXPARAM];
+} WCTemplateToken;
+
+
+typedef void (*WCHandlerFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context);
+void RegisterNS(const char *NSName, long len, 
+               int nMinArgs, 
+               int nMaxArgs, 
+               WCHandlerFunc HandlerFunc);
+#define RegisterNamespace(a, b, c, d) RegisterNS(a, sizeof(a)-1, b, c, d)
+
+
+
+typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context);
+typedef struct _ConditionalStruct {
+       int nParams;
+       WCConditionalFunc CondF;
+} ConditionalStruct;
+void RegisterConditional(const char *Name, long len, 
+                        int nParams,
+                        WCConditionalFunc CondF);
+
+
+
+typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context);
+typedef HashList *(*RetrieveHashlistFunc)(void);
+typedef void (*HashDestructorFunc) (HashList *KillMe);
+void RegisterITERATOR(const char *Name, long len, 
+                     HashList *StaticList, 
+                     RetrieveHashlistFunc GetHash, 
+                     SubTemplFunc DoSubTempl,
+                     HashDestructorFunc Destructor);
+#define RegisterIterator(a, b, c, d, e) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e)
+
+
 /**
  * \brief Values for wcs_type
  */
 enum {
-       WCS_STRING,   /**< its a string */
-       WCS_FUNCTION, /**< its a function callback */
-       WCS_SERVCMD   /**< its a command to send to the citadel server */
+       WCS_STRING,       /**< its a string */
+       WCS_FUNCTION,     /**< its a function callback */
+       WCS_SERVCMD,      /**< its a command to send to the citadel server */
+       WCS_STRBUF,       /**< its a strbuf we own */
+       WCS_STRBUF_REF,   /**< its a strbuf we mustn't free */
+       WCS_LONG          /**< its an integer */
 };
 
 /**
@@ -310,6 +352,7 @@ struct wc_attachment {
        char content_type[SIZ];    /**< the content itself ???*/
        char filename[SIZ];                /**< the filename hooked to this content ??? */
        char *data;                /**< the data pool; aka this content */
+       long lvalue;               /**< if we put a long... */
 };
 
 /**
@@ -418,7 +461,7 @@ struct wcsession {
        time_t cache_timestamp;                 /**< ??? todo */
        HashList *IconBarSetttings;             /**< which icons should be shown / not shown? */
        long current_iconbar;                   /**< What is currently in the iconbar? */
-       StrBuf *floordiv_expanded;              /**< which floordiv currently expanded */
+       const StrBuf *floordiv_expanded;        /**< which floordiv currently expanded */
        int selected_language;                  /**< Language selected by user */
        time_t last_pager_check;                /**< last time we polled for instant msgs */
        int nonce;                              /**< session nonce (to prevent session riding) */
@@ -427,6 +470,8 @@ struct wcsession {
        StrBuf *UrlFragment2;                   /**< second urlfragment, if NEED_URL is specified by the handler*/
        StrBuf *WBuf;                           /**< Our output buffer */
        StrBuf *HBuf;                           /**< Our HeaderBuffer */
+
+       HashList *ServCfg;                      /**< cache our server config for editing */
 };
 
 /** values for WC->current_iconbar */
@@ -470,6 +515,16 @@ extern char wizard_filename[];
 extern time_t if_modified_since;
 extern int follow_xff;
 extern HashList *HandlerHash;
+extern HashList *PreferenceHooks;
+extern HashList *WirelessTemplateCache;
+extern HashList *WirelessLocalTemplateCache;
+extern HashList *TemplateCache;
+extern HashList *LocalTemplateCache;
+extern HashList *GlobalNS;
+extern HashList *Iterators;
+extern HashList *ZoneHash;
+extern HashList *Contitionals;
+
 
 void InitialiseSemaphores(void);
 void begin_critical_section(int which_one);
@@ -498,41 +553,53 @@ int uds_connectsock(char *);
 int tcp_connectsock(char *, char *);
 int serv_getln(char *strbuf, int bufsize);
 int StrBuf_ServGetln(StrBuf *buf);
-void serv_puts(char *string);
+void serv_puts(const char *string);
 void who(void);
 void who_inner_div(void);
 void ajax_mini_calendar(void);
 void fmout(char *align);
+void _fmout(StrBuf *Targt, char *align);
 void pullquote_fmout(void);
 void wDumpContent(int);
 
-/* TODO: get rid of the non-const-typecast */
-#define bstr(a) (char*) Bstr(a, sizeof(a) - 1)
-const char *BSTR(char *key);
-const char *Bstr(char *key, size_t keylen);
+/* These may return NULL if not foud */
+#define sbstr(a) SBstr(a, sizeof(a) - 1)
+const StrBuf *SBSTR(const char *key);
+const StrBuf *SBstr(const char *key, size_t keylen);
 
 #define xbstr(a, b) (char*) XBstr(a, sizeof(a) - 1, b)
-const char *XBstr(char *key, size_t keylen, size_t *len);
-const char *XBSTR(char *key, size_t *len);
+const char *XBstr(const char *key, size_t keylen, size_t *len);
+const char *XBSTR(const char *key, size_t *len);
 
 #define lbstr(a) LBstr(a, sizeof(a) - 1)
-long LBstr(char *key, size_t keylen);
-long LBSTR(char *key);
+long LBstr(const char *key, size_t keylen);
+long LBSTR(const char *key);
 
 #define ibstr(a) IBstr(a, sizeof(a) - 1)
-int IBstr(char *key, size_t keylen);
-int IBSTR(char *key);
+int IBstr(const char *key, size_t keylen);
+int IBSTR(const char *key);
 
 #define havebstr(a) HaveBstr(a, sizeof(a) - 1)
-int HaveBstr(char *key, size_t keylen);
-int HAVEBSTR(char *key);
+int HaveBstr(const char *key, size_t keylen);
+int HAVEBSTR(const char *key);
 
 #define yesbstr(a) YesBstr(a, sizeof(a) - 1)
-int YesBstr(char *key, size_t keylen);
-int YESBSTR(char *key);
+int YesBstr(const char *key, size_t keylen);
+int YESBSTR(const char *key);
 
+/* TODO: get rid of the non-const-typecast */
+#define bstr(a) (char*) Bstr(a, sizeof(a) - 1)
+const char *BSTR(const char *key);
+const char *Bstr(const char *key, size_t keylen);
 
-void urlescputs(char *);
+
+
+void UrlescPutStrBuf(const StrBuf *strbuf);
+void StrEscPuts(const StrBuf *strbuf);
+void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks);
+
+void urlescputs(const char *);
+void hurlescputs(const char *);
 void jsesc(char *, size_t, char *);
 void jsescputs(char *);
 void output_headers(    int do_httpheaders,
@@ -575,8 +642,9 @@ void display_graphics_upload(char *, char *, char *);
 void do_graphics_upload(char *upl_cmd);
 void serv_read(char *buf, int bytes);
 void serv_gets(char *strbuf);
-void serv_write(char *buf, int nbytes);
-void serv_puts(char *string);
+void serv_write(const char *buf, int nbytes);
+void serv_puts(const char *string);
+void serv_putbuf(const StrBuf *string);
 void serv_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
 void load_floorlist(void);
 void shutdown_sessions(void);
@@ -600,14 +668,23 @@ typedef void (*var_callback_fptr)();
 
 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
+void SVPutLong(char *keyname, size_t keylen, long Data);
+#define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
 void SVCALLBACK(char *keyname, var_callback_fptr fcn_ptr);
 void SVCallback(char *keyname, size_t keylen,  var_callback_fptr fcn_ptr);
 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
 
-void do_template(void *templatename);
+void SVPUTBuf(const char *keyname, int keylen, StrBuf *Buf, int ref);
+#define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
+
+void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target);
+#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL);
+void url_do_template(void);
 
+int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
+int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
 
 int lingering_close(int fd);
 char *memreadline(char *start, char *buf, int maxlen);
@@ -644,7 +721,11 @@ int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default);
 #define set_pref_yesno(a, b, c) set_PREF_YESNO(a, sizeof(a) - 1, b, c)
 void set_PREF_YESNO(const char *key, size_t keylen, int value, int save_to_server);
 
+#define get_room_pref(a) get_ROOM_PREFS(a, sizeof(a) - 1)
+StrBuf *get_ROOM_PREFS(const char *key, size_t keylen);
 
+#define set_room_pref(a, b, c) set_ROOM_PREFS(a, sizeof(a) - 1, b, c)
+void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server);
 
 int is_msg_in_mset(char *mset, long msgnum);
 void display_addressbook(long msgnum, char alpha);
@@ -699,7 +780,9 @@ int ical_ctdl_is_overlap(
 
 #ifdef ENABLE_NLS
 void initialize_locales(void);
+void ShutdownLocale(void);
 #endif
+void TmplGettext(StrBuf *Target, int nTokens, WCTemplateToken *Token);
 
 extern char *months[];
 extern char *days[];
@@ -721,6 +804,9 @@ void go_selected_language(void);
 void stop_selected_language(void);
 void preset_locale(void);
 void httplang_to_locale(char *LocaleString);
+void StrEndTab(StrBuf *Target, int tabnum, int num_tabs);
+void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs);
+void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]);
 void tabbed_dialog(int num_tabs, char *tabnames[]);
 void begin_tab(int tabnum, int num_tabs);
 void end_tab(int tabnum, int num_tabs);
@@ -752,7 +838,7 @@ void ssl_lock(int mode, int n, const char *file, int line);
 int starttls(int sock);
 extern SSL_CTX *ssl_ctx;  
 int client_read_ssl(char *buf, int bytes, int timeout);
-void client_write_ssl(const char *buf, int nbytes);
+void client_write_ssl(const StrBuf *Buf);
 #endif
 
 #ifdef HAVE_ZLIB