* shortcut notation to tokens for hashkeys; TKEY(n) will make str,len for Hash access
[citadel.git] / webcit / webcit.h
index 5140def263cdaa8d6b469b0e38bf9dd09ea3de18..73dce523e2ba77c7d9e76bf402bd6b00d055ec1f 100644 (file)
@@ -55,9 +55,6 @@
 #endif
 #include <libintl.h>
 #include <locale.h>
-#ifdef HAVE_USELOCALE
-extern locale_t wc_locales[];
-#endif
 #define _(string)      gettext(string)
 #else
 #define _(string)      (string)
@@ -260,7 +257,13 @@ struct roomlisting {
 
 #define TYPE_STR   1
 #define TYPE_LONG  2
+#define TYPE_PREFSTR 3
+#define TYPE_PREFINT 4
+#define TYPE_GETTEXT 5
+#define TYPE_BSTR 6
 #define MAXPARAM  20
+
+
 typedef struct _TemplateParam {
        const char *Start;
        int Type;
@@ -268,7 +271,10 @@ typedef struct _TemplateParam {
        long lvalue;
 } TemplateParam;
 
+/* make a template token a lookup key: */
+#define TKEY(a) Tokens->Params[a]->Start, Tokens->Params[a]->len
 typedef struct _TemplateToken {
+       const StrBuf *FileName; /* Reference to print error messages; not to be freed */
        StrBuf *FlatToken;
        long Line;
        const char *pTokenStart;
@@ -311,6 +317,9 @@ typedef struct _wcsubst {
 #define CTX_NODECONF 7
 #define CTX_USERLIST 8
 #define CTX_MAILSUM 9
+#define CTX_MIME_ATACH 10
+#define CTX_STRBUF 12
+#define CTX_LONGVECTOR 13
 
 
 void RegisterNS(const char *NSName, long len, 
@@ -322,6 +331,7 @@ void RegisterNS(const char *NSName, long len,
 
 typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context, int ContextType);
 typedef struct _ConditionalStruct {
+       const char *PlainName;
        int nParams;
        int ContextRequired;
        WCConditionalFunc CondF;
@@ -334,16 +344,23 @@ void RegisterConditional(const char *Name, long len,
 
 
 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
-typedef HashList *(*RetrieveHashlistFunc)(WCTemplateToken *Token);
+typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType);
 typedef void (*HashDestructorFunc) (HashList **KillMe);
-void RegisterITERATOR(const char *Name, long len,
-                     int AdditionalParams, 
-                     HashList *StaticList, 
-                     RetrieveHashlistFunc GetHash, 
-                     SubTemplFunc DoSubTempl,
-                     HashDestructorFunc Destructor,
-                     int ContextType);
-#define RegisterIterator(a, b, c, d, e, f, g) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g)
+void RegisterITERATOR(const char *Name, long len, /* Our identifier */
+                     int AdditionalParams,       /* doe we use more parameters? */
+                     HashList *StaticList,       /* pointer to webcit lifetime hashlists */
+                     RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
+                     SubTemplFunc DoSubTempl,       /* call this function on each iteration for svput & friends */
+                     HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
+                     int ContextType,               /* which context do we provide to the subtemplate? */
+                     int XPectContextType);         /* which context do we expct to be called in? */
+#define RegisterIterator(a, b, c, d, e, f, g, h) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h)
+
+void GetTemplateTokenString(WCTemplateToken *Tokens,
+                           int N, 
+                           const char **Value, 
+                           long *len);
+
 
 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
@@ -365,7 +382,18 @@ void url_do_template(void);
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
 
-
+void StrBufAppendTemplate(StrBuf *Target, 
+                         int nArgs, 
+                         WCTemplateToken *Tokens,
+                         void *Context, int ContextType,
+                         const StrBuf *Source, int FormatTypeIndex);
+CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix, 
+                        const char *Default, long ldefault, long DefaultDirection);
+void RegisterSortFunc(const char *name, long len, 
+                     const char *prepend, long preplen,
+                     CompareFunc Forward, 
+                     CompareFunc Reverse, 
+                     long ContextType);
 
 
 /*
@@ -380,19 +408,12 @@ enum {
        WCS_LONG          /* its an integer */
 };
 
-/*
- * \brief mail attachment ???
- */
-struct wc_attachment {
-       struct wc_attachment *next;/* pointer to next in list */
-       size_t length;                     /* length of the contenttype */
-       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... */
-};
 
-typedef struct _wc_mime_attachment {
+
+typedef struct wc_mime_attachment wc_mime_attachment;
+typedef void (*RenderMimeFunc)(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset);
+struct wc_mime_attachment {
+       int level;
        StrBuf *Name;
        StrBuf *FileName;
        StrBuf *PartNum;
@@ -402,15 +423,12 @@ typedef struct _wc_mime_attachment {
        StrBuf *Data;
        size_t length;                     /* length of the mimeatachment */
        long size_known;
-       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... */
        long msgnum;            /**< the message number on the citadel server derived from message_summary */
-}wc_mime_attachment;
-
+       RenderMimeFunc Renderer;
+};
+void DestroyMime(void *vMime);
 
-typedef void (*RenderMimeFunc)(wc_mime_attachment *Mime, StrBuf *RawData);
 
 /*
  * \brief message summary structure. ???
@@ -432,26 +450,27 @@ typedef struct _message_summary {
        StrBuf *Room;
        StrBuf *Rfca;
        StrBuf *OtherNode;
+       const StrBuf *PartNum;
 
        HashList *Attachments;  /**< list of Accachments */
        HashList *Submessages;
        HashList *AttachLinks;
 
+       HashList *AllAttach;
+
        int is_new;         /**< is it yet read? */
        int hasattachments;     /* does it have atachments? */
 
 
        /** The mime part of the message */
-       wc_mime_attachment MsgBody;
-
-
-       /** Referencces; don't neeed to be freed: */
-       wc_mime_attachment *cal_partnum_ref;
-       wc_mime_attachment *vcard_partnum_ref;
+       wc_mime_attachment *MsgBody;
 } message_summary;
+void DestroyMessageSummary(void *vMsg);
+inline message_summary* GetMessagePtrAt(int n, HashList *Summ);
 
-typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine);
+typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
 
+void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime);
 
 
 
@@ -483,12 +502,42 @@ typedef struct _disp_cal {
 } disp_cal;                                            
 
 
+
+/*
+ * Address book entry (keep it short and sweet, it's just a quickie lookup
+ * which we can use to get to the real meat and bones later)
+ */
+typedef struct _addrbookent {
+       char ab_name[64]; /**< name string */
+       long ab_msgnum;   /**< message number of address book entry */
+} addrbookent;
+
+
+typedef struct _headereval {
+       ExamineMsgHeaderFunc evaluator;
+       int Type;
+} headereval;
+
+
+struct attach_link {
+       char partnum[32];
+       char html[1024];
+};
+
+
+enum {
+       eUp,
+       eDown,
+       eNone
+};
+
 /*
  * One of these is kept for each active Citadel session.
  * HTTP transactions are bound to one at a time.
  */
+typedef struct wcsession wcsession;
 struct wcsession {
-       struct wcsession *next;                 /**< Linked list */
+       wcsession *next;                        /**< Linked list */
        int wc_session;                         /**< WebCit session ID */
        char wc_username[128];                  /**< login name of current user */
        char wc_fullname[128];                  /**< Screen name of current user */
@@ -524,7 +573,6 @@ struct wcsession {
        int killthis;                           /**< Nonzero == purge this session */
        struct march *march;                    /**< march mode room list */
        char reply_to[512];                     /**< reply-to address */
-       long msgarr[10000];                     /**< for read operations */
        HashList *summ;                         /**< list of messages for mailbox summary view */
        int is_mobile;                  /**< Client is a handheld browser */
        HashList *urlstrings;                   /**< variables passed to webcit in a URL */
@@ -533,7 +581,7 @@ struct wcsession {
        char http_host[512];                    /**< HTTP Host: header */
        HashList *hash_prefs;                   /**< WebCit preferences for this user */
        HashList *disp_cal_items;               /**< sorted list of calendar items; startdate is the sort criteria. */
-       struct wc_attachment *first_attachment; /**< linked list of attachments for 'enter message' */
+       HashList *attachments;                  /**< list of attachments for 'enter message' */
        char last_chat_user[256];               /**< ??? todo */
        char ImportantMessage[SIZ];             /**< ??? todo */
        int ctdl_pid;                           /**< Session ID on the Citadel server */
@@ -554,6 +602,7 @@ struct wcsession {
        int time_format_cache;                  /**< which timeformat does our user like? */
        StrBuf *UrlFragment1;                   /**< first urlfragment, if NEED_URL is specified by the handler*/
        StrBuf *UrlFragment2;                   /**< second urlfragment, if NEED_URL is specified by the handler*/
+       StrBuf *UrlFragment3;                   /**< third urlfragment, if NEED_URL is specified by the handler*/
        StrBuf *WBuf;                           /**< Our output buffer */
        StrBuf *HBuf;                           /**< Our HeaderBuffer */
        StrBuf *CLineBuf;                       /**< linebuffering client stuff */
@@ -634,9 +683,10 @@ extern HashList *LocalTemplateCache;
 extern HashList *GlobalNS;
 extern HashList *Iterators;
 extern HashList *ZoneHash;
-extern HashList *Contitionals;
+extern HashList *Conditionals;
 extern HashList *MsgHeaderHandler;
 extern HashList *MimeRenderHandler;
+extern HashList *SortHash;
 
 void InitialiseSemaphores(void);
 void begin_critical_section(int which_one);
@@ -652,7 +702,7 @@ void cookie_to_stuff(StrBuf *cookie, int *session,
 void locate_host(char *, int);
 void become_logged_in(char *, char *, char *);
 void openid_manual_create(void);
-void display_login(char *mesg);
+void display_login();
 void display_openids(void);
 void do_welcome(void);
 void do_logout(void);
@@ -679,6 +729,15 @@ void wDumpContent(int);
 int Flathash(const char *str, long len);
 
 
+
+/* URL / Mime Post parsing -> paramhandling.c */
+void upload_handler(char *name, char *filename, char *partnum, char *disp,
+                   void *content, char *cbtype, char *cbcharset,
+                   size_t length, char *encoding, char *cbid, void *userdata);
+
+void ParseURLParams(StrBuf *url);
+
+
 /* These may return NULL if not foud */
 #define sbstr(a) SBstr(a, sizeof(a) - 1)
 const StrBuf *SBSTR(const char *key);
@@ -708,6 +767,9 @@ int YESBSTR(const char *key);
 #define bstr(a) (char*) Bstr(a, sizeof(a) - 1)
 const char *BSTR(const char *key);
 const char *Bstr(const char *key, size_t keylen);
+/* if you want to ease some parts by just parametring yourself... */
+#define putbstr(a, b) PutBstr(a, sizeof(a) - 1, b)
+void PutBstr(const char *key, long keylen, StrBuf *Value);
 
 
 
@@ -728,7 +790,7 @@ void output_headers(    int do_httpheaders,
 void wprintf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
 void hprintf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
 void output_static(char *what);
-void display_mime_icon(void);
+
 void print_menu_box(char* Title, char *Class, int nLines, ...);
 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks);
 void escputs(char *strbuf);
@@ -742,8 +804,26 @@ void stripout(char *str, char leftboundary, char rightboundary);
 void dump_vars(void);
 void embed_main_menu(void);
 void serv_read(char *buf, int bytes);
-void readloop(char *oper);
-void read_message(long msgnum, int printable_view, char *section);
+
+enum {
+       do_search,
+       headers,
+       readfwd,
+       readnew,
+       readold
+};
+
+typedef void (*readloop_servcmd)(char *buf, long bufsize);
+
+typedef struct _readloopstruct {
+       ConstStr name;
+       readloop_servcmd cmd;
+} readloop_struct;
+void readloop(long oper);
+int  read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const StrBuf *section);
+void do_addrbook_view(addrbookent *addrbook, int num_ab);
+void fetch_ab_name(message_summary *Msg, char *namebuf);
+void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename, long msgnum);
 void text_to_server(char *ptr);
 void text_to_server_qp(char *ptr);
 void confirm_delete_msg(void);
@@ -788,6 +868,7 @@ char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
 void remove_token(char *source, int parmnum, char separator);
 char *load_mimepart(long msgnum, char *partnum);
+void MimeLoadData(wc_mime_attachment *Mime);
 int pattern2(char *search, char *patn);
 void do_edit_vcard(long, char *, char *, char *);
 void striplt(char *);
@@ -823,15 +904,13 @@ 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);
 void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType);
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
 void output_html(const char *, int, int, StrBuf *, StrBuf *);
 void do_listsub(void);
-void toggle_self_service(void);
 ssize_t write(int fd, const void *buf, size_t count);
-void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
+void cal_process_attachment(wc_mime_attachment *Mime);
 void load_calendar_item(message_summary *Msg, int unread, struct calview *c);
 void display_calendar(message_summary *Msg, int unread);
 void display_task(message_summary *Msg, int unread);
@@ -842,8 +921,8 @@ void render_calendar_view(struct calview *c);
 void do_tasks_view(void);
 void calendar_summary_view(void);
 int load_msg_ptrs(char *servcmd, int with_headers);
-void free_attachments(struct wcsession *sess);
-void free_march_list(struct wcsession *wcf);
+void free_attachments(wcsession *sess);
+void free_march_list(wcsession *wcf);
 void display_rules_editor_inner_div(void);
 void generate_uuid(char *);
 void CtdlMakeTempFileName(char *, int);