* Applied matt's patch to have it show a loading graphic for ajax operations
authorArt Cancro <ajc@citadel.org>
Fri, 17 Nov 2006 15:03:06 +0000 (15:03 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 17 Nov 2006 15:03:06 +0000 (15:03 +0000)
* Applied matt's patch to add javascript for  other features such as the new header view
* Cleaned up the gratuitous overuse of realloc() when outputting HTML messages.
  Although the code wasn't buggy, gnu malloc was choking on it.

webcit/html2html.c
webcit/static/wclib.js

index ca8804c1aa6d707699863bbf91785d12c9ad984e..abd5904e846a1577fa6c2af0c5a2d3fa3e72eed6 100644 (file)
@@ -77,6 +77,7 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
        char *msgstart;
        char *msgend;
        char *converted_msg;
+       size_t converted_alloc = 0;
        int buffer_length = 1;
        int line_length = 0;
        int content_length = 0;
@@ -251,7 +252,11 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
         */
 
        /** Now go through the message, parsing tags as necessary. */
-       converted_msg = malloc(content_length);
+       converted_alloc = content_length + 8192;
+       converted_msg = malloc(converted_alloc);
+       if (converted_msg == NULL) {
+               abort();                        /* FIXME */
+       }
        strcpy(converted_msg, "");
        ptr = msg;
        msgend = strchr(msg, 0);
@@ -265,7 +270,13 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
                 */
                if (!strncasecmp(ptr, "<a href=\"mailto:", 16)) {
                        content_length += 64;
-                       converted_msg = realloc(converted_msg, content_length);
+                       if (content_length >= converted_alloc) {
+                               converted_alloc += 8192;
+                               converted_msg = realloc(converted_msg, converted_alloc);
+                               if (converted_msg == NULL) {
+                                       abort();
+                               }
+                       }
                        sprintf(&converted_msg[output_length],
                                "<a href=\"display_enter"
                                "?force_room=_MAIL_&recp=");
@@ -281,14 +292,26 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
                             ) {
                                /* open external links to new window */
                                content_length += 64;
-                               converted_msg = realloc(converted_msg, content_length);
+                               if (content_length >= converted_alloc) {
+                                       converted_alloc += 8192;
+                                       converted_msg = realloc(converted_msg, converted_alloc);
+                                       if (converted_msg == NULL) {
+                                               abort();
+                                       }
+                               }
                                sprintf(&converted_msg[output_length], new_window);
                                output_length += strlen(new_window);
                                ptr = &ptr[8];
                        }
                        else if ( (treat_as_wiki) && (strncasecmp(ptr, "<a href=\"wiki?", 14)) ) {
                                content_length += 64;
-                               converted_msg = realloc(converted_msg, content_length);
+                               if (content_length >= converted_alloc) {
+                                       converted_alloc += 8192;
+                                       converted_msg = realloc(converted_msg, converted_alloc);
+                                       if (converted_msg == NULL) {
+                                               abort();
+                                       }
+                               }
                                sprintf(&converted_msg[output_length], "<a href=\"wiki?page=");
                                output_length += 19;
                                ptr = &ptr[9];
@@ -323,7 +346,13 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
                                }
                                if (linklen > 0) {
                                        content_length += (32 + linklen);
-                                       converted_msg = realloc(converted_msg, content_length);
+                                       if (content_length >= converted_alloc) {
+                                               converted_alloc += 8192;
+                                               converted_msg = realloc(converted_msg, converted_alloc);
+                                               if (converted_msg == NULL) {
+                                                       abort();
+                                               }
+                                       }
                                        sprintf(&converted_msg[output_length], new_window);
                                        output_length += strlen(new_window);
                                        converted_msg[output_length] = '\"';
@@ -367,8 +396,8 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
        wprintf("<br /><br />\n");
 
        /** Now give back the memory */
-       free(converted_msg);
-       free(msg);
+       if (converted_msg != NULL) free(converted_msg);
+       if (msg != NULL) free(msg);
 }
 
 /*@}*/
index bb3f3783f7d376a1b285e42eb70a8f05d8d40903..fbe50fde5a673aa3f427d4940b7ebee76a730c04 100644 (file)
@@ -73,6 +73,7 @@ var drop_targets_roomnames = new Array();
 
 function switch_to_room_list() {
        $('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
+       CtdlLoadScreen('iconbar');
        new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
 }
 
@@ -111,6 +112,7 @@ function expand_floor(floor_div) {
 function switch_to_menu_buttons() {
        which_div_expanded = null;
        num_drop_targets = 0;
+       CtdlLoadScreen('iconbar');
        new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
 }
 
@@ -217,6 +219,8 @@ function CtdlSingleClickMsg(evt, msgnum) {
                CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
                CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
 
+               // Gradient
+               CtdlLoadScreen('preview_pane');
                // Update the preview pane
                new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
        
@@ -559,3 +563,91 @@ function add_new_note() {
        new Ajax.InPlaceEditor('note' + new_eid,
                'updatenote?eid=' + new_eid , {rows:5,cols:72});
 }
+
+function CtdlShowRaw(msgnum) {
+var customnav = document.createElement("span");
+var mode_citadel = document.createElement("a");
+mode_citadel.appendChild(document.createTextNode("Citadel Source"));
+var mode_rfc822 = document.createElement("a");
+mode_rfc822.appendChild(document.createTextNode(" RFC822 Source"));
+mode_citadel.setAttribute("href","#");
+mode_rfc822.setAttribute("href","#");
+mode_rfc822.setAttribute("onclick","rawSwitch822('" + msgnum + "');");
+mode_citadel.setAttribute("onclick","rawSwitchCitadel('" + msgnum + "');");
+customnav.appendChild(mode_citadel);
+customnav.appendChild(mode_rfc822);
+customnav.setAttribute("class","floatcustomnav");
+floatwindow("headerscreen","pre",customnav);
+rawSwitch822(msgnum);
+}
+function rawSwitch822(msgnum) {
+CtdlLoadScreen("headerscreen");
+new Ajax.Updater("headerscreen", 
+'ajax_servcmd_esc',
+ { method: 'post',parameters: 'g_cmd=MSG2 ' +msgnum  } );
+
+}
+function rawSwitchCitadel(msgnum) {
+CtdlLoadScreen("headerscreen");
+new Ajax.Updater("headerscreen", 
+'ajax_servcmd_esc',
+ { method: 'post',parameters: 'g_cmd=MSG0 ' +msgnum  } );
+
+}
+function floatwindow(newdivid,contentelementtype,customnav) {
+var windiv = document.createElement("div");
+windiv.setAttribute("class","floatwindow");
+var winid = newdivid+"_window";
+windiv.setAttribute("id",winid);
+var nav = document.createElement("div");
+if (customnav != null) {
+nav.appendChild(customnav);
+}
+var minimizeA = document.createElement("a");
+var minimizeButton = document.createTextNode("Close");
+minimizeA.appendChild(minimizeButton);
+minimizeA.setAttribute("onclick","killFloatWindow(this);");
+minimizeA.setAttribute("href","#");
+nav.appendChild(minimizeA);
+nav.setAttribute("class","floatnav");
+windiv.appendChild(nav);
+var contentarea = document.createElement("pre");
+contentarea.setAttribute("class","floatcontent");
+contentarea.setAttribute("id",newdivid);
+windiv.appendChild(contentarea);
+document.body.appendChild(windiv);
+}
+function killFloatWindow(caller) {
+var span = caller.parentNode;
+var fwindow = span.parentNode;
+fwindow.parentNode.removeChild(fwindow);
+}
+// Place a gradient loadscreen on an element, e.g to use before Ajax.updater
+function CtdlLoadScreen(elementid) {
+var elem = document.getElementById(elementid);
+elem.innerHTML = "<b>Loading....</b> <img src=\"/static/gradientanim.gif\"/>";
+}
+// Show info for a user, basically replaces showuser()
+// matt@comalies is to blame for this poorly coded masterpiece. 
+function CtdlShowUserInfoPopup(Element) {
+try {
+// hopefully no one needs to use the class attribute... could be better done 
+// with xmlns though..
+var user = Element.getAttribute("class");
+var updname = "biospace_"+user;
+if (document.getElementById(updname) == null) {
+// insert a space for the bio
+var pNode = Element.parentNode;
+var newdiv = document.createElement("div");
+newdiv.id = updname;
+newdiv.innerHTML = "Getting user info....";
+pNode.appendChild(newdiv);
+CtdlLoadScreen(updname);
+new Ajax.Updater(updname, 'showuser_ajax?who='+user, { method: 'get' } );
+}
+}
+catch(err){
+return true;
+}
+return false;
+}