skeleton code for json render
authorArt Cancro <ajc@citadel.org>
Sat, 17 Feb 2018 18:43:13 +0000 (13:43 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 17 Feb 2018 18:43:13 +0000 (13:43 -0500)
webcit-ng/ctdlclient.c
webcit-ng/forum_view.c
webcit-ng/room_functions.c
webcit-ng/webcit.h

index a75d18a02eb25cb08e9973e16df07593cc7b45e9..decb31adba036ada8d0554d3d8626e0cba544289 100644 (file)
@@ -41,12 +41,12 @@ int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes)
                                --len;
                        }
                        buf[len] = 0;
-                       // syslog(LOG_DEBUG, "[ %s", buf);
+                       // syslog(LOG_DEBUG, "\033[33m[ %s\033[0m", buf);
                        return(len);
                }
                ++len;
        }
-       // syslog(LOG_DEBUG, "[ %s", buf);
+       // syslog(LOG_DEBUG, "\033[33m[ %s\033[0m", buf);
        return(len);
 }
 
@@ -93,7 +93,7 @@ void ctdl_printf(struct ctdlsession *ctdl, const char *format,...)
        StrBufVAppendPrintf(Buf, format, arg_ptr);
        va_end(arg_ptr);
 
-       // syslog(LOG_DEBUG, "] %s", ChrPtr(Buf));
+       syslog(LOG_DEBUG, "\033[32m] %s\033[0m", ChrPtr(Buf));
        ctdl_write(ctdl, (char *)ChrPtr(Buf), StrLength(Buf));
        ctdl_write(ctdl, "\n", 1);
        FreeStrBuf(&Buf);
index 0eeaf8566566729a6ea6ab4e46ea07c420f48a9c..016b8116da9c97d91affe0a3e5d109a984791233 100644 (file)
@@ -144,6 +144,11 @@ void setup_for_forum_view(struct ctdlsession *c)
 }
 
 
+#if 0
+
+// This code implements the thread display code.  The thread sorting algorithm is working nicely but we're trying
+// not to do rendering in the C server of webcit.  Maybe move it into the server as "MSGS threaded" or something like that?
+
 // Threaded view (recursive section)
 //
 void thread_o_print(struct ctdlsession *c, StrBuf *sj, struct mthread *m, int num_msgs, int where_parent_is, int nesting_level)
@@ -173,7 +178,6 @@ void thread_o_print(struct ctdlsession *c, StrBuf *sj, struct mthread *m, int nu
        }
 }
 
-#if 0
 
 // Threaded view (entry point)
 //
@@ -293,7 +297,7 @@ void flat_view(struct http_transaction *h, struct ctdlsession *c, char *which)
 
 #endif
 
-// render one message (entire transaction)
+// render one message (entire transaction)     FIXME EXTERMINATE
 //
 void html_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum)
 {
@@ -310,3 +314,19 @@ void html_render_one_message(struct http_transaction *h, struct ctdlsession *c,
        return;
 }
 
+
+// Fetch a single message and return it in JSON format for client-side rendering
+//
+void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum)
+{
+       JsonValue *j = NULL;                            // FIXME do something useful
+
+       StrBuf *sj = NewStrBuf();
+       SerializeJson(sj, j, 1);                        // '1' == free the source object
+
+       add_response_header(h, strdup("Content-type"), strdup("application/json"));
+       h->response_code = 200;
+       h->response_string = strdup("OK");
+       h->response_body_length = StrLength(sj);
+       h->response_body = SmashStrBuf(&sj);
+}
index 3d82b63146c02696d042ffbb8a6dd88449c657ab..8136ced9e74547f72c194cbcf9046001c5895aa4 100644 (file)
@@ -120,8 +120,6 @@ void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which
        h->response_body_length = StrLength(sj);
        h->response_body = SmashStrBuf(&sj);
        return;
-
-
 }
 
 
@@ -191,9 +189,12 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c)
        {
                extract_token(buf, h->uri, 5, '/', sizeof buf);
                if (!IsEmptyStr(buf)) {
-                       if (!strcasecmp(buf, "html"))
+                       if (!strcasecmp(buf, "json"))
+                       {
+                               json_render_one_message(h, c, msgnum);
+                       }
+                       else if (!strcasecmp(buf, "html"))                      // FIXME exterminate this, we don't want any server-side rendering
                        {
-                               // FIXME render as html
                                html_render_one_message(h, c, msgnum);
                        }
                        else
index de529ae83536dc01184c839245cdb2b91ac6f9c4..5321c9b995a389727a17ff44bdf9286767d1849c 100644 (file)
@@ -163,4 +163,5 @@ void do_502(struct http_transaction *h);
 void do_404(struct http_transaction *h);
 void do_412(struct http_transaction *h);
 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
+void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
 void html_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);