4 * This is the main transaction loop of the web service. It maintains a
5 * persistent session to the Citadel server, handling HTTP WebCit requests as
6 * they arrive and presenting a user interface.
8 #define SHOW_ME_VAPPEND_PRINTF
13 #include "webserver.h"
16 StrBuf *csslocal = NULL;
17 HashList *HandlerHash = NULL;
20 void DeleteWebcitHandler(void *vHandler)
22 WebcitHandler *Handler = (WebcitHandler*) vHandler;
23 FreeStrBuf(&Handler->Name);
24 FreeStrBuf(&Handler->DisplayName);
28 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
29 const char *DisplayName, long dslen,
33 WebcitHandler *NewHandler;
34 NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler));
36 NewHandler->Flags = Flags;
37 NewHandler->Name = NewStrBufPlain(UrlString, UrlSLen);
38 StrBufShrinkToFit(NewHandler->Name, 1);
39 NewHandler->DisplayName = NewStrBufPlain(DisplayName, dslen);
40 StrBufShrinkToFit(NewHandler->DisplayName, 1);
41 Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
44 void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
47 if (WCC->Hdr->HR.Handler != NULL)
48 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
51 void tmplput_HOST_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP)
54 StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.http_host, 0);
58 * web-printing funcion. uses our vsnprintf wrapper
60 #ifdef UBER_VERBOSE_DEBUGGING
61 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format,...)
63 void wc_printf(const char *format,...)
69 if (WCC->WBuf == NULL)
70 WCC->WBuf = NewStrBuf();
71 #ifdef UBER_VERBOSE_DEBUGGING
72 StrBufAppendPrintf(WCC->WBuf, "\n%s:%s:%d[", FILE, FUNCTION, LINE);
75 va_start(arg_ptr, format);
76 StrBufVAppendPrintf(WCC->WBuf, format, arg_ptr);
78 #ifdef UBER_VERBOSE_DEBUGGING
79 StrBufAppendPrintf(WCC->WBuf, "]\n");
84 * http-header-printing funcion. uses our vsnprintf wrapper
86 void hprintf(const char *format,...)
91 va_start(arg_ptr, format);
92 StrBufVAppendPrintf(WCC->HBuf, format, arg_ptr);
99 * wrap up an HTTP session, closes tags, etc.
101 * print_standard_html_footer should be set to:
102 * 0 - to transmit only,
103 * nonzero - to append the closing tags
105 void wDumpContent(int print_standard_html_footer)
107 if (print_standard_html_footer) {
108 wc_printf("</div> <!-- end of 'content' div -->\n");
109 do_template("trailing", NULL);
112 /* If we've been saving it all up for one big output burst,
113 * go ahead and do that now.
122 * Output HTTP headers and leading HTML for a page
124 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
125 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
127 int do_room_banner, /* 0=no, 1=yes,
128 * 2 = I'm going to embed my own, so don't open the
129 * <div id="content"> either.
132 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
133 int suppress_check, /* 1 = suppress check for instant messages */
134 int cache /* 1 = allow browser to cache this page */
139 hprintf("HTTP/1.1 200 OK\n");
140 http_datestring(httpnow, sizeof httpnow, time(NULL));
142 if (do_httpheaders) {
143 if (WCC->serv_info != NULL)
144 hprintf("Content-type: text/html; charset=utf-8\r\n"
146 "Connection: close\r\n",
148 ChrPtr(WCC->serv_info->serv_software));
150 hprintf("Content-type: text/html; charset=utf-8\r\n"
151 "Server: %s / [n/a]\n"
152 "Connection: close\r\n",
157 char httpTomorow[128];
159 http_datestring(httpTomorow, sizeof httpTomorow,
160 time(NULL) + 60 * 60 * 24 * 2);
162 hprintf("Pragma: public\r\n"
163 "Cache-Control: max-age=3600, must-revalidate\r\n"
164 "Last-modified: %s\r\n"
171 hprintf("Pragma: no-cache\r\n"
172 "Cache-Control: no-store\r\n"
177 if (cache < 2) stuff_to_cookie(unset_cookies);
181 do_template("head", NULL);
183 /* check for ImportantMessages (these display in a div overlaying the main screen) */
184 if (!IsEmptyStr(WCC->ImportantMessage)) {
185 wc_printf("<div id=\"important_message\">\n"
186 "<span class=\"imsg\">");
187 StrEscAppend(WCC->WBuf, NULL, WCC->ImportantMessage, 0, 0);
188 wc_printf("</span><br />\n"
191 StrBufAppendBufPlain(WCC->trailing_javascript,
192 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
195 WCC->ImportantMessage[0] = 0;
197 else if (StrLength(WCC->ImportantMsg) > 0) {
198 wc_printf("<div id=\"important_message\">\n"
199 "<span class=\"imsg\">");
200 StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0);
201 wc_printf("</span><br />\n"
204 StrBufAppendBufPlain(WCC->trailing_javascript,
205 HKEY("setTimeout('hide_imsg_popup()', 5000); \n"),
208 FlushStrBuf(WCC->ImportantMsg);
210 if ( (WCC->logged_in) && (!unset_cookies) ) {
211 DoTemplate(HKEY("paging"), NULL, &NoCtx);
214 if (do_room_banner == 1) {
215 tmplput_roombanner(NULL, NULL);
219 if (do_room_banner == 1) {
220 wc_printf("<div id=\"content\">\n");
224 void output_custom_content_header(const char *ctype) {
225 hprintf("HTTP/1.1 200 OK\r\n");
226 hprintf("Content-type: %s; charset=utf-8\r\n",ctype);
227 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
228 hprintf("Connection: close\r\n");
233 * Generic function to do an HTTP redirect. Easy and fun.
235 void http_redirect(const char *whichpage) {
236 hprintf("HTTP/1.1 302 Moved Temporarily\n");
237 hprintf("Location: %s\r\n", whichpage);
238 hprintf("URI: %s\r\n", whichpage);
239 hprintf("Content-type: text/html; charset=utf-8\r\n");
241 wc_printf("<html><body>");
242 wc_printf("Go <a href=\"%s\">here</A>.", whichpage);
243 wc_printf("</body></html>\n");
250 * Output a piece of content to the web browser using conformant HTTP and MIME semantics
252 void http_transmit_thing(const char *content_type,
256 lprintf(9, "http_transmit_thing(%s)%s\n",
258 ((is_static > 0) ? " (static)" : "")
261 output_headers(0, 0, 0, 0, 0, is_static);
263 hprintf("Content-type: %s\r\n"
265 "Connection: close\r\n",
274 * Convenience functions to display a page containing only a string
276 * titlebarcolor color of the titlebar of the frame
277 * titlebarmsg text to display in the title bar
278 * messagetext body of the box
280 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
282 hprintf("HTTP/1.1 200 OK\n");
283 output_headers(1, 1, 2, 0, 0, 0);
284 wc_printf("<div id=\"banner\">\n");
285 wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
286 wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
287 wc_printf("</td></tr></table>\n");
288 wc_printf("</div>\n<div id=\"content\">\n");
289 escputs(messagetext);
291 wc_printf("<hr />\n");
297 * Display a blank page.
299 void blank_page(void) {
300 output_headers(1, 1, 0, 0, 0, 0);
306 * A template has been requested
308 void url_do_template(void) {
309 const StrBuf *MimeType;
310 const StrBuf *Tmpl = sbstr("template");
312 MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
313 http_transmit_thing(ChrPtr(MimeType), 0);
319 * convenience function to indicate success
321 void display_success(char *successmessage)
323 convenience_page("007700", "OK", successmessage);
328 * Authorization required page
329 * This is probably temporary and should be revisited
331 void authorization_required(void)
334 const char *message = "";
336 hprintf("HTTP/1.1 401 Authorization Required\r\n");
338 "Server: %s / %s\r\n"
339 "Connection: close\r\n",
340 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
342 hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode));
343 hprintf("Content-Type: text/html\r\n");
346 wc_printf(_("Authorization Required"));
347 wc_printf("</h1>\r\n");
350 if (WCC->ImportantMsg != NULL)
351 message = ChrPtr(WCC->ImportantMsg);
352 else if (WCC->ImportantMessage != NULL)
353 message = WCC->ImportantMessage;
355 wc_printf(_("The resource you requested requires a valid username and password. "
356 "You could not be logged in: %s\n"), message);
358 end_webcit_session();
362 * Convenience functions to wrap around asynchronous ajax responses
364 void begin_ajax_response(void) {
367 FlushStrBuf(WCC->HBuf);
368 output_headers(0, 0, 0, 0, 0, 0);
370 hprintf("Content-type: text/html; charset=UTF-8\r\n"
372 "Connection: close\r\n"
379 * print ajax response footer
381 void end_ajax_response(void) {
388 * Wraps a Citadel server command in an AJAX transaction.
390 void ajax_servcmd(void)
398 begin_ajax_response();
400 serv_puts(bstr("g_cmd"));
401 StrBuf_ServGetln(Buf);
402 StrBufAppendBuf(WCC->WBuf, Buf, 0);
403 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
405 switch (GetServerStatus(Buf, NULL)) {
407 serv_puts("\n\n000");
408 if ( (StrLength(Buf)==3) &&
409 !strcmp(ChrPtr(Buf), "000")) {
410 StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
415 StrBuf_ServGetln(Buf);
416 if ( (StrLength(Buf)==3) &&
417 !strcmp(ChrPtr(Buf), "000")) {
420 StrBufAppendBuf(WCC->WBuf, Buf, 0);
421 StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0);
425 text_to_server(bstr("g_input"));
429 len = atol(&ChrPtr(Buf)[4]);
430 StrBuf_ServGetBLOBBuffered(Buf, len);
433 len = atol(&ChrPtr(Buf)[4]);
435 memset(junk, 0, len);
436 serv_write(junk, len);
443 * This is kind of an ugly hack, but this is the only place it can go.
444 * If the command was GEXP, then the instant messenger window must be
445 * running, so reset the "last_pager_check" watchdog timer so
446 * that page_popup() doesn't try to open it a second time.
448 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
449 WCC->last_pager_check = time(NULL);
456 * Helper function for the asynchronous check to see if we need
457 * to open the instant messenger window.
459 void seconds_since_last_gexp(void)
463 if ( (time(NULL) - WC->last_pager_check) < 30) {
469 serv_getln(buf, sizeof buf);
481 int ReadPostData(void)
486 StrBuf *content = NULL;
488 content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256);
490 StrBufPrintf(content,
492 "Content-length: %ld\n\n",
493 ChrPtr(WCC->Hdr->HR.ContentType),
494 WCC->Hdr->HR.ContentLength);
496 hprintf("Content-type: %s\n"
497 "Content-length: %d\n\n",
498 ContentType, ContentLength);
500 body_start = StrLength(content);
502 /** Read the entire input data at once. */
503 rc = client_read_to(WCC->Hdr, content,
504 WCC->Hdr->HR.ContentLength,
510 if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33)) {
511 StrBufCutLeft(content, body_start);
512 ParseURLParams(content);
513 } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) {
518 len = StrLength(content);
519 Buf = SmashStrBuf(&content);
521 mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0);
523 } else if (WCC->Hdr->HR.ContentLength > 0) {
524 WCC->upload = content;
525 WCC->upload_length = StrLength(WCC->upload);
528 FreeStrBuf(&content);
533 void ParseREST_URL(void)
536 StrBuf *pFloor = NULL;
539 const char *pCh = NULL;
543 lprintf(1, "parsing rest URL: %s\n", ChrPtr(WCC->Hdr->HR.ReqLine));
545 WCC->Directory = NewHash(1, Flathash);
546 WCC->CurrentFloor = NULL;
549 while (StrBufExtract_NextToken(Buf, WCC->Hdr->HR.ReqLine, &pCh, '/') >= 0)
551 if (StrLength(Buf) != 0) {
552 /* ignore empty path segments */
553 StrBufUnescape(Buf, 1);
554 Put(WCC->Directory, IKEY(i), Buf, HFreeStrBuf);
565 Floors = GetFloorListHash(NULL, NULL);
569 if (GetHash(WCC->FloorsByName, SKEY(pFloor), &vFloor))
570 WCC->CurrentFloor = (Floor*) vFloor;
575 int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
581 if (WCC->Hdr->HR.Handler != NULL)
583 Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
584 IsDepth = GetCount(WCC->Directory) + offset;
586 // LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
589 return IsDepth > Depth;
592 return Depth == IsDepth;
598 * Entry point for WebCit transaction
600 void session_loop(void)
607 * We stuff these with the values coming from the client cookies,
608 * so we can use them to reconnect a timed out session if we have to.
613 WCC->upload_length = 0;
616 WCC->Hdr->nWildfireHeaders = 0;
617 if (WCC->Hdr->HR.Handler != NULL)
618 Flags = WCC->Hdr->HR.Handler->Flags; /* so we can temporarily add our own... */
620 if (WCC->Hdr->HR.ContentLength > 0) {
621 if (ReadPostData() < 0) {
627 WCC->trailing_javascript = NewStrBuf();
629 /* If there are variables in the URL, we must grab them now */
630 if (WCC->Hdr->PlainArgs != NULL)
631 ParseURLParams(WCC->Hdr->PlainArgs);
633 /* If the client sent a nonce that is incorrect, kill the request. */
634 if (havebstr("nonce")) {
635 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
636 bstr("nonce"), WCC->nonce);
637 if (ibstr("nonce") != WCC->nonce) {
638 lprintf(9, "Ignoring request with mismatched nonce.\n");
639 hprintf("HTTP/1.1 404 Security check failed\r\n");
640 hprintf("Content-Type: text/plain\r\n");
642 wc_printf("Security check failed.\r\n");
644 goto SKIP_ALL_THIS_CRAP;
649 * If we're not connected to a Citadel server, try to hook up the
652 if (!WCC->connected) {
654 goto SKIP_ALL_THIS_CRAP;
659 * If we're not logged in, but we have authentication data (either from
660 * a cookie or from http-auth), try logging in to Citadel using that.
662 if ((!WCC->logged_in)
663 && (StrLength(WCC->Hdr->c_username) > 0)
664 && (StrLength(WCC->Hdr->c_password) > 0))
669 serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
670 StrBuf_ServGetln(Buf);
671 if (GetServerStatus(Buf, &Status) == 3) {
672 serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
673 StrBuf_ServGetln(Buf);
674 if (GetServerStatus(Buf, NULL) == 2) {
675 become_logged_in(WCC->Hdr->c_username,
676 WCC->Hdr->c_password, Buf);
678 /* Should only display when password is wrong */
679 WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4);
680 authorization_required();
682 goto SKIP_ALL_THIS_CRAP;
685 else if (Status == 541) {
690 xhttp = (WCC->Hdr->HR.eReqType != eGET) &&
691 (WCC->Hdr->HR.eReqType != ePOST) &&
692 (WCC->Hdr->HR.eReqType != eHEAD);
695 * If a 'gotofirst' parameter has been specified, attempt to goto that room
696 * prior to doing anything else.
698 if (havebstr("gotofirst")) {
700 ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */
701 if ((ret/100) != 2) {
702 lprintf(1, "GOTOFIRST: Unable to change to [%s]; Reason: %d\n",
703 bstr("gotofirst"), ret);
708 * If we aren't in any room yet, but we have cookie data telling us where we're
709 * supposed to be, and 'gotofirst' was not specified, then go there.
711 else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
714 lprintf(9, "We are in '%s' but cookie indicates '%s', going there...\n",
715 ChrPtr(WCC->CurRoom.name),
716 ChrPtr(WCC->Hdr->c_roomname)
718 ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */
719 if ((ret/100) != 2) {
720 lprintf(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d\n",
721 ChrPtr(WCC->Hdr->c_roomname), ret);
725 if (WCC->Hdr->HR.Handler != NULL) {
726 if (!WCC->logged_in && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0)) {
731 if ((WCC->Hdr->HR.Handler->Flags & PARSE_REST_URL) != 0)
734 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
735 begin_ajax_response();
736 WCC->Hdr->HR.Handler->F();
737 if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0)
741 /* When all else fais, display the main menu. */
744 * ordinary browser users get a nice login screen, DAV etc. requsets
745 * are given a 401 so they can handle it appropriate.
747 if (!WCC->logged_in) {
749 authorization_required();
754 * Toplevel dav requests? or just a flat browser request?
771 * Replacement for sleep() that uses select() in order to avoid SIGALRM
773 void sleeeeeeeeeep(int seconds)
779 select(0, NULL, NULL, NULL, &tv);
782 int Conditional_IS_HTTPS(StrBuf *Target, WCTemplputParams *TP)
784 return is_https != 0;
787 void AppendImportantMessage(const char *pch, long len)
791 if (StrLength(WCC->ImportantMsg) > 0) {
792 StrBufAppendBufPlain(WCC->ImportantMsg, HKEY("\n"), 0);
795 StrBufAppendBufPlain(WCC->ImportantMsg, pch, len, 0);
798 int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
802 return ((!IsEmptyStr(WCC->ImportantMessage)) ||
803 (StrLength(WCC->ImportantMsg) > 0));
808 void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
813 if (!IsEmptyStr(WCC->ImportantMessage)) {
814 StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
815 WCC->ImportantMessage[0] = '\0';
817 else if (StrLength(WCC->ImportantMsg) > 0) {
818 StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
819 FlushStrBuf(WCC->ImportantMsg);
824 void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
829 StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
832 void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
834 StrBufAppendBuf(Target,
838 extern char static_local_dir[PATH_MAX];
846 WebcitAddUrlHandler(HKEY("blank"), "", 0, blank_page, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC);
847 WebcitAddUrlHandler(HKEY("do_template"), "", 0, url_do_template, ANONYMOUS);
848 WebcitAddUrlHandler(HKEY("sslg"), "", 0, seconds_since_last_gexp, AJAX|LOGCHATTY);
849 WebcitAddUrlHandler(HKEY("ajax_servcmd"), "", 0, ajax_servcmd, 0);
850 WebcitAddUrlHandler(HKEY("webcit"), "", 0, blank_page, URLNAMESPACE);
852 WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
853 RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
854 RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
855 RegisterConditional(HKEY("COND:IS_HTTPS"), 0, Conditional_IS_HTTPS, CTX_NONE);
857 RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
858 RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
859 RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
860 RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
861 RegisterNamespace("URL:HOSTNAME", 0, 1, tmplput_HOST_DISPLAYNAME, NULL, CTX_NONE);
864 snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
865 if (!access(dir, R_OK)) {
866 lprintf(9, "Using local Stylesheet [%s]\n", dir);
867 csslocal = NewStrBufPlain(HKEY("<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\" />"));
870 lprintf(9, "No Site-local Stylesheet [%s] installed. \n", dir);
875 ServerStartModule_WEBCIT
878 HandlerHash = NewHash(1, NULL);
883 ServerShutdownModule_WEBCIT
886 FreeStrBuf(&csslocal);
887 DeleteHash(&HandlerHash);
893 SessionNewModule_WEBCIT
896 sess->ImportantMsg = NewStrBuf();
897 sess->WBuf = NewStrBufPlain(NULL, SIZ * 4);
898 sess->HBuf = NewStrBufPlain(NULL, SIZ / 4);
902 SessionDetachModule_WEBCIT
905 DeleteHash(&sess->Directory);
907 FreeStrBuf(&sess->upload);
908 sess->upload_length = 0;
910 FreeStrBuf(&sess->trailing_javascript);
912 if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */
914 FreeStrBuf(&sess->WBuf);
915 sess->WBuf = NewStrBuf();
918 FlushStrBuf(sess->WBuf);
919 FlushStrBuf(sess->HBuf);
923 SessionDestroyModule_WEBCIT
926 FreeStrBuf(&sess->WBuf);
927 FreeStrBuf(&sess->HBuf);
928 FreeStrBuf(&sess->ImportantMsg);