* rework login screen to utilize more modern templating
[citadel.git] / webcit / webcit.h
index 02b7ac6a228912ed7abe495296385ad9fdbd89fd..f431ac9e7f752e23c4f1bbe68707a9195b893807 100644 (file)
@@ -1,3 +1,4 @@
+
 /* $Id$ */
 
 #include "sysdep.h"
@@ -49,6 +50,9 @@
 #endif
 
 #ifdef ENABLE_NLS
+#ifdef HAVE_XLOCALE_H
+#include <xlocale.h>
+#endif
 #include <libintl.h>
 #include <locale.h>
 #ifdef HAVE_USELOCALE
@@ -256,7 +260,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;
@@ -265,6 +275,7 @@ typedef struct _TemplateParam {
 } TemplateParam;
 
 typedef struct _TemplateToken {
+       const StrBuf *FileName; /* Reference to print error messages; not to be freed */
        StrBuf *FlatToken;
        long Line;
        const char *pTokenStart;
@@ -306,6 +317,10 @@ typedef struct _wcsubst {
 #define CTX_PREF 6
 #define CTX_NODECONF 7
 #define CTX_USERLIST 8
+#define CTX_MAILSUM 9
+#define CTX_MIME_ATACH 10
+#define CTX_ATT 11
+#define CTX_STRBUF 12
 
 void RegisterNS(const char *NSName, long len, 
                int nMinArgs, 
@@ -316,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;
@@ -328,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)
@@ -359,6 +382,11 @@ 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);
 
 
 
@@ -377,29 +405,83 @@ enum {
 /*
  * \brief mail attachment ???
  */
-struct wc_attachment {
-       struct wc_attachment *next;/* pointer to next in list */
+typedef struct _wc_attachment {
        size_t length;                     /* length of the contenttype */
+       StrBuf *content_type;      /* the content itself ???*/
+       StrBuf *filename;                  /* the filename hooked to this content ??? */
+       char *data;                /* the data pool; aka this content */
+       long lvalue;               /* if we put a long... */
+} wc_attachment;
+void free_attachment(void *vattach);
+
+
+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;
+       StrBuf *Disposition;
+       StrBuf *ContentType;
+       StrBuf *Charset;
+       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 */
+       RenderMimeFunc Renderer;
 };
+void DestroyMime(void *vMime);
+
 
 /*
  * \brief message summary structure. ???
  */
-struct message_summary {
-       time_t date;        /* its creation date */
-       long msgnum;            /* the message number on the citadel server */
-       char from[128];         /* the author */
-       char to[128];           /* the recipient */
-       char subj[256];         /* the title / subject */
+typedef struct _message_summary {
+       time_t date;        /**< its creation date */
+       long msgnum;            /**< the message number on the citadel server */
+       int nhdr;
+       int format_type;
+       StrBuf *from;           /**< the author */
+       StrBuf *to;             /**< the recipient */
+       StrBuf *subj;           /**< the title / subject */
+       StrBuf *reply_inreplyto;
+       StrBuf *reply_references;
+       StrBuf *reply_to;
+       StrBuf *cccc;
+       StrBuf *hnod;
+       StrBuf *AllRcpt;
+       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? */
-       int is_new;         /* is it yet read? */
-};
 
-/*
+
+       /** The mime part of the message */
+       wc_mime_attachment *MsgBody;
+} message_summary;
+void DestroyMessageSummary(void *vMsg);
+
+typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
+
+void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime);
+
+
+
+/**
  * \brief  Data structure for roomlist-to-folderlist conversion 
  */
 struct folder {
@@ -427,84 +509,114 @@ 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.
  */
 struct wcsession {
-       struct 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 */
-       char wc_password[128];                  /* Password of current user */
-       char wc_roomname[256];                  /* Room we are currently in */
-       int connected;                          /* nonzero == we are connected to Citadel */
-       int logged_in;                          /* nonzero == we are logged in  */
-       int axlevel;                            /* this user's access level */
-       int is_aide;                            /* nonzero == this user is an Aide */
-       int is_room_aide;                       /* nonzero == this user is a Room Aide in this room */
-       int http_sock;                          /* HTTP server socket */
-       int serv_sock;                          /* Client socket to Citadel server */
-       int chat_sock;                          /* Client socket to Citadel server - for chat */
-       unsigned room_flags;                    /* flags associated with the current room */
-       unsigned room_flags2;                   /* flags associated with the current room */
-       int wc_view;                            /* view for the current room */
-       int wc_default_view;                    /* default view for the current room */
-       int wc_is_trash;                        /* nonzero == current room is a Trash folder */
-       int wc_floor;                           /* floor number of current room */
-       char ugname[128];                       /* where does 'ungoto' take us */
-       long uglsn;                             /* last seen message number for ungoto */
-       int upload_length;                      /* content length of http-uploaded data */
-       char *upload;                           /* pointer to http-uploaded data */
-       char upload_filename[PATH_MAX];         /* filename of http-uploaded data */
-       char upload_content_type[256];          /* content type of http-uploaded data */
-       int new_mail;                           /* user has new mail waiting */
-       int remember_new_mail;                  /* last count of new mail messages */
-       int need_regi;                          /* This user needs to register. */
-       int need_vali;                          /* New users require validation. */
-       char cs_inet_email[256];                /* User's preferred Internet addr. */
-       pthread_mutex_t SessionMutex;           /* mutex for exclusive access */
-       time_t lastreq;                         /* Timestamp of most recent HTTP */
-       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 */
-       int num_summ;                           /* number of messages in mailbox summary view */
-       struct message_summary *summ;           /* array of messages for mailbox summary view */
-       int is_mobile;                          /* Client is a handheld browser */
-       HashList *urlstrings;                   /* variables passed to webcit in a URL */
-       HashList *vars;                         /* HTTP variable substitutions for this page */
-       char this_page[512];                    /* URL of current page */
-       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' */
-       char last_chat_user[256];
-       char ImportantMessage[SIZ];
-       int ctdl_pid;                           /* Session ID on the Citadel server */
-       char httpauth_user[256];                /* only for GroupDAV sessions */
-       char httpauth_pass[256];                /* only for GroupDAV sessions */
-       int gzip_ok;                            /* Nonzero if Accept-encoding: gzip */
-       int is_mailbox;                         /* the current room is a private mailbox */
-       struct folder *cache_fold;              /* cache the iconbar room list */
-       int cache_max_folders;
-       int cache_num_floors;
-       time_t cache_timestamp;
-       HashList *IconBarSetttings;             /* which icons should be shown / not shown? */
-       long current_iconbar;                   /* What is currently in the iconbar? */
-       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) */
-       int time_format_cache;                  /* which timeformat does our user like? */
-       StrBuf *UrlFragment1;                   /* first urlfragment, if NEED_URL is specified by handler*/
-       StrBuf *UrlFragment2;                   /* second urlfragment, if NEED_URL is specified by handler*/
-       StrBuf *WBuf;                           /* Our output buffer */
-       StrBuf *HBuf;                           /* Our HeaderBuffer */
-       StrBuf *CLineBuf;                       /* linebuffering client stuff */
-       HashList *ServCfg;                      /* cache our server config for editing */
-       HashList *InetCfg;                      /* Our inet server config for editing */
-       StrBuf *trailing_javascript;            /* extra javascript to be appended to page */
+       struct 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 */
+       char wc_password[128];                  /**< Password of current user */
+       char wc_roomname[256];                  /**< Room we are currently in */
+       int connected;                          /**< nonzero == we are connected to Citadel */
+       int logged_in;                          /**< nonzero == we are logged in  */
+       int axlevel;                            /**< this user's access level */
+       int is_aide;                            /**< nonzero == this user is an Aide */
+       int is_room_aide;                       /**< nonzero == this user is a Room Aide in this room */
+       int http_sock;                          /**< HTTP server socket */
+       int serv_sock;                          /**< Client socket to Citadel server */
+       int chat_sock;                          /**< Client socket to Citadel server - for chat */
+       unsigned room_flags;                    /**< flags associated with the current room */
+       unsigned room_flags2;                   /**< flags associated with the current room */
+       int wc_view;                            /**< view for the current room */
+       int wc_default_view;                    /**< default view for the current room */
+       int wc_is_trash;                        /**< nonzero == current room is a Trash folder */
+       int wc_floor;                           /**< floor number of current room */
+       char ugname[128];                       /**< where does 'ungoto' take us */
+       long uglsn;                             /**< last seen message number for ungoto */
+       int upload_length;                      /**< content length of http-uploaded data */
+       char *upload;                           /**< pointer to http-uploaded data */
+       char upload_filename[PATH_MAX];         /**< filename of http-uploaded data */
+       char upload_content_type[256];          /**< content type of http-uploaded data */
+       int new_mail;                           /**< user has new mail waiting */
+       int remember_new_mail;                  /**< last count of new mail messages */
+       int need_regi;                          /**< This user needs to register. */
+       int need_vali;                          /**< New users require validation. */
+       char cs_inet_email[256];                /**< User's preferred Internet addr. */
+       pthread_mutex_t SessionMutex;           /**< mutex for exclusive access */
+       time_t lastreq;                         /**< Timestamp of most recent HTTP */
+       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 */
+       HashList *vars;                         /**< HTTP variable substitutions for this page */
+       char this_page[512];                    /**< URL of current page */
+       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. */
+       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 */
+       char httpauth_user[256];                /**< only for GroupDAV sessions */
+       char httpauth_pass[256];                /**< only for GroupDAV sessions */
+       int gzip_ok;                            /**< Nonzero if Accept-encoding: gzip */
+       int is_mailbox;                         /**< the current room is a private mailbox */
+       struct folder *cache_fold;              /**< cache the iconbar room list */
+       int cache_max_folders;                  /**< ??? todo */
+       int cache_num_floors;                   /**< ??? todo */
+       time_t cache_timestamp;                 /**< ??? todo */
+       HashList *IconBarSetttings;             /**< which icons should be shown / not shown? */
+       long current_iconbar;                   /**< What is currently in the iconbar? */
+       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) */
+       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 *WBuf;                           /**< Our output buffer */
+       StrBuf *HBuf;                           /**< Our HeaderBuffer */
+       StrBuf *CLineBuf;                       /**< linebuffering client stuff */
+       StrBuf *DefaultCharset;                 /**< Charset the user preferes */
+       HashList *ServCfg;                      /**< cache our server config for editing */
+       HashList *InetCfg;                      /**< Our inet server config for editing */
+
+       StrBuf *trailing_javascript;            /**< extra javascript to be appended to page */
 };
 
 /* values for WC->current_iconbar */
@@ -577,8 +689,9 @@ extern HashList *LocalTemplateCache;
 extern HashList *GlobalNS;
 extern HashList *Iterators;
 extern HashList *ZoneHash;
-extern HashList *Contitionals;
-
+extern HashList *Conditionals;
+extern HashList *MsgHeaderHandler;
+extern HashList *MimeRenderHandler;
 
 void InitialiseSemaphores(void);
 void begin_critical_section(int which_one);
@@ -594,7 +707,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);
@@ -607,15 +720,20 @@ int uds_connectsock(char *);
 int tcp_connectsock(char *, char *);
 int serv_getln(char *strbuf, int bufsize);
 int StrBuf_ServGetln(StrBuf *buf);
+int GetServerStatus(StrBuf *Line, long* FullState);
 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 FmOut(StrBuf *Target, char *align, StrBuf *Source);
 void pullquote_fmout(void);
 void wDumpContent(int);
 
+int Flathash(const char *str, long len);
+
+
 /* These may return NULL if not foud */
 #define sbstr(a) SBstr(a, sizeof(a) - 1)
 const StrBuf *SBSTR(const char *key);
@@ -670,6 +788,7 @@ 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);
 void url(char *buf, size_t bufsize);
+void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
 void escputs1(char *strbuf, int nbsp, int nolinebreaks);
 void msgesc(char *target, size_t tlen, char *strbuf);
 void msgescputs(char *strbuf);
@@ -679,7 +798,9 @@ 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);
+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 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);
@@ -724,6 +845,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 *);
@@ -763,14 +885,15 @@ 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(char *, int, int);
+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 load_calendar_item(long msgnum, int unread, struct calview *c);
-void display_task(long msgnum, int unread);
-void display_note(long msgnum, int unread);
+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);
+void display_note(message_summary *Msg, int unread);
 void updatenote(void);
 void parse_calendar_view_request(struct calview *c);
 void render_calendar_view(struct calview *c);
@@ -830,7 +953,6 @@ void sleeeeeeeeeep(int);
 void http_transmit_thing(const char *content_type, int is_static);
 long unescape_input(char *buf);
 void do_selected_iconbar(void);
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void spawn_another_worker_thread(void);
 void display_rss(char *roomname, StrBuf *request_method);
 void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType);
@@ -854,10 +976,6 @@ int fetch_http(char *url, char *target_buf, int maxbytes);
 
 int is_mobile_ua(char *user_agent);
 
-#ifdef HAVE_ICONV
-iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);
-#endif
-
 void embed_room_banner(char *, int);
 
 /* navbar types that can be passed to embed_room_banner */