--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);
}
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);
}
+#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)
}
}
-#if 0
// Threaded view (entry point)
//
#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)
{
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);
+}
h->response_body_length = StrLength(sj);
h->response_body = SmashStrBuf(&sj);
return;
-
-
}
{
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
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);