From d2cbd2ac0524468b6b74c63a6ca337a43e8e0d6a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 27 Sep 2021 19:27:43 -0400 Subject: [PATCH] Did a little more style updating. Realized that I started this thing in 2018 and really ought to get my act together and finish it. --- webcit-ng/admin_functions.c | 28 ++----- webcit-ng/caldav_reports.c | 78 ++++++------------ webcit-ng/ctdlclient.c | 116 ++++++++++----------------- webcit-ng/ctdlfunctions.c | 10 +-- webcit-ng/forum_view.c | 8 +- webcit-ng/html2html.c | 152 +++++++++++++++--------------------- webcit-ng/main.c | 21 +++-- webcit-ng/webcit.h | 16 ++-- 8 files changed, 160 insertions(+), 269 deletions(-) diff --git a/webcit-ng/admin_functions.c b/webcit-ng/admin_functions.c index 27b93cc05..551c06d13 100644 --- a/webcit-ng/admin_functions.c +++ b/webcit-ng/admin_functions.c @@ -16,11 +16,8 @@ #include "webcit.h" -/* - * /ctdl/a/login is called when a user is trying to log in - */ -void try_login(struct http_transaction *h, struct ctdlsession *c) -{ +// /ctdl/a/login is called when a user is trying to log in +void try_login(struct http_transaction *h, struct ctdlsession *c) { char buf[1024]; char auth[AUTH_MAX]; char username[256]; @@ -50,11 +47,8 @@ void try_login(struct http_transaction *h, struct ctdlsession *c) } -/* - * /ctdl/a/logout is called when a user is trying to log out. Don't use this as an ajax. - */ -void logout(struct http_transaction *h, struct ctdlsession *c) -{ +// /ctdl/a/logout is called when a user is trying to log out. Don't use this as an ajax. +void logout(struct http_transaction *h, struct ctdlsession *c) { char buf[1024]; char auth[AUTH_MAX]; char username[256]; @@ -71,11 +65,8 @@ void logout(struct http_transaction *h, struct ctdlsession *c) } -/* - * /ctdl/a/whoami returns the name of the currently logged in user, or an empty string if not logged in - */ -void whoami(struct http_transaction *h, struct ctdlsession *c) -{ +// /ctdl/a/whoami returns the name of the currently logged in user, or an empty string if not logged in +void whoami(struct http_transaction *h, struct ctdlsession *c) { h->response_code = 200; h->response_string = strdup("OK"); add_response_header(h, strdup("Content-type"), strdup("text/plain")); @@ -84,11 +75,8 @@ void whoami(struct http_transaction *h, struct ctdlsession *c) } -/* - * Dispatcher for paths starting with /ctdl/a/ - */ -void ctdl_a(struct http_transaction *h, struct ctdlsession *c) -{ +// Dispatcher for paths starting with /ctdl/a/ +void ctdl_a(struct http_transaction *h, struct ctdlsession *c) { if (!strcasecmp(h->uri, "/ctdl/a/login")) { // log in try_login(h, c); return; diff --git a/webcit-ng/caldav_reports.c b/webcit-ng/caldav_reports.c index 26fbec8d9..b5ae8744a 100644 --- a/webcit-ng/caldav_reports.c +++ b/webcit-ng/caldav_reports.c @@ -17,9 +17,7 @@ #include "webcit.h" -/* - * A CalDAV REPORT can only be one type. This is stored in the report_type member. - */ +// A CalDAV REPORT can only be one type. This is stored in the report_type member. enum cr_type { cr_calendar_query, cr_calendar_multiget, @@ -27,11 +25,9 @@ enum cr_type { }; -/* - * Data type for CalDAV Report Parameters. - * As we slog our way through the XML we learn what the client is asking for - * and build up the contents of this data type. - */ +// Data type for CalDAV Report Parameters. +// As we slog our way through the XML we learn what the client is asking for +// and build up the contents of this data type. struct cr_parms { int tag_nesting_level; // not needed, just kept for pretty-printing enum cr_type report_type; // which RFC4791 section 7 REPORT are we generating @@ -40,11 +36,8 @@ struct cr_parms { }; -/* - * XML parser callback - */ -void caldav_xml_start(void *data, const char *el, const char **attr) -{ +// XML parser callback +void caldav_xml_start(void *data, const char *el, const char **attr) { struct cr_parms *crp = (struct cr_parms *) data; int i; @@ -70,11 +63,8 @@ void caldav_xml_start(void *data, const char *el, const char **attr) } -/* - * XML parser callback - */ -void caldav_xml_end(void *data, const char *el) -{ +// XML parser callback +void caldav_xml_end(void *data, const char *el) { struct cr_parms *crp = (struct cr_parms *) data; --crp->tag_nesting_level; @@ -99,11 +89,8 @@ void caldav_xml_end(void *data, const char *el) } -/* - * XML parser callback - */ -void caldav_xml_chardata(void *data, const XML_Char * s, int len) -{ +// XML parser callback +void caldav_xml_chardata(void *data, const XML_Char * s, int len) { struct cr_parms *crp = (struct cr_parms *) data; if (crp->Chardata == NULL) { @@ -116,15 +103,12 @@ void caldav_xml_chardata(void *data, const XML_Char * s, int len) } -/* - * Called by caldav_response() to fetch a message (by number) in the current room, - * and return only the icalendar data as a StrBuf. Returns NULL if not found. - * - * NOTE: this function expects that "MSGP text/calendar" was issued at the beginning - * of a REPORT operation to set our preferred MIME type to calendar data. - */ -StrBuf *fetch_ical(struct ctdlsession * c, long msgnum) -{ +// Called by caldav_response() to fetch a message (by number) in the current room, +// and return only the icalendar data as a StrBuf. Returns NULL if not found. +// +// NOTE: this function expects that "MSGP text/calendar" was issued at the beginning +// of a REPORT operation to set our preferred MIME type to calendar data. +StrBuf *fetch_ical(struct ctdlsession * c, long msgnum) { char buf[1024]; StrBuf *Buf = NULL; @@ -165,12 +149,9 @@ StrBuf *fetch_ical(struct ctdlsession * c, long msgnum) } -/* - * Called by caldav_report() to output a single item. - * Our policy is to throw away the list of properties the client asked for, and just send everything. - */ -void caldav_response(struct http_transaction *h, struct ctdlsession *c, StrBuf * ReportOut, StrBuf * ThisHref) -{ +// Called by caldav_report() to output a single item. +// Our policy is to throw away the list of properties the client asked for, and just send everything. +void caldav_response(struct http_transaction *h, struct ctdlsession *c, StrBuf * ReportOut, StrBuf * ThisHref) { long msgnum; StrBuf *Caldata = NULL; char *euid; @@ -226,13 +207,10 @@ void caldav_response(struct http_transaction *h, struct ctdlsession *c, StrBuf * } -/* - * Called by report_the_room_itself() in room_functions.c when a CalDAV REPORT method - * is requested on a calendar room. We fire up an XML Parser to decode the request and - * hopefully produce the correct output. - */ -void caldav_report(struct http_transaction *h, struct ctdlsession *c) -{ +// Called by report_the_room_itself() in room_functions.c when a CalDAV REPORT method +// is requested on a calendar room. We fire up an XML Parser to decode the request and +// hopefully produce the correct output. +void caldav_report(struct http_transaction *h, struct ctdlsession *c) { struct cr_parms crp; char buf[1024]; @@ -257,16 +235,12 @@ void caldav_report(struct http_transaction *h, struct ctdlsession *c) crp.Chardata = NULL; } - /* - * We're going to make a lot of MSG4 calls, and the preferred MIME type we want is "text/calendar". - * The iCalendar standard is mature now, and we are no longer interested in text/x-vcal or application/ics. - */ + // We're going to make a lot of MSG4 calls, and the preferred MIME type we want is "text/calendar". + // The iCalendar standard is mature now, and we are no longer interested in text/x-vcal or application/ics. ctdl_printf(c, "MSGP text/calendar"); ctdl_readline(c, buf, sizeof buf); - /* - * Now begin the REPORT. - */ + // Now begin the REPORT. syslog(LOG_DEBUG, "CalDAV REPORT type is: %d", crp.report_type); StrBuf *ReportOut = NewStrBuf(); StrBufAppendPrintf(ReportOut, "" diff --git a/webcit-ng/ctdlclient.c b/webcit-ng/ctdlclient.c index ddbc0926a..eb74598e4 100644 --- a/webcit-ng/ctdlclient.c +++ b/webcit-ng/ctdlclient.c @@ -19,12 +19,9 @@ struct ctdlsession *cpool = NULL; // linked list of connections to the Citade pthread_mutex_t cpool_mutex = PTHREAD_MUTEX_INITIALIZER; // Lock it before modifying -/* - * Read a specific number of bytes of binary data from the Citadel server. - * Returns the number of bytes read or -1 for error. - */ -int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested) -{ +// Read a specific number of bytes of binary data from the Citadel server. +// Returns the number of bytes read or -1 for error. +int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested) { int bytes_read = 0; int c = 0; @@ -40,12 +37,9 @@ int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested) } -/* - * Read a newline-terminated line of text from the Citadel server. - * Returns the string length or -1 for error. - */ -int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes) -{ +// Read a newline-terminated line of text from the Citadel server. +// Returns the string length or -1 for error. +int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes) { int len = 0; int c = 0; @@ -73,13 +67,10 @@ int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes) } -/* - * Read lines of text from the Citadel server until a 000 terminator is received. - * Implemented in terms of ctdl_readline() and is therefore transparent... - * Returns a newly allocated StrBuf or NULL for error. - */ -StrBuf *ctdl_readtextmsg(struct ctdlsession * ctdl) -{ +// Read lines of text from the Citadel server until a 000 terminator is received. +// Implemented in terms of ctdl_readline() and is therefore transparent... +// Returns a newly allocated StrBuf or NULL for error. +StrBuf *ctdl_readtextmsg(struct ctdlsession * ctdl) { char buf[1024]; StrBuf *sj = NewStrBuf(); if (!sj) { @@ -94,21 +85,15 @@ StrBuf *ctdl_readtextmsg(struct ctdlsession * ctdl) } -/* - * Write to the Citadel server. For now we're just wrapping write() in case we - * need to add anything else later. - */ -ssize_t ctdl_write(struct ctdlsession * ctdl, const void *buf, size_t count) -{ +// Write to the Citadel server. For now we're just wrapping write() in case we +// need to add anything else later. +ssize_t ctdl_write(struct ctdlsession * ctdl, const void *buf, size_t count) { return write(ctdl->sock, buf, count); } -/* - * printf() type function to send data to the Citadel Server. - */ -void ctdl_printf(struct ctdlsession *ctdl, const char *format, ...) -{ +// printf() type function to send data to the Citadel Server. +void ctdl_printf(struct ctdlsession *ctdl, const char *format, ...) { va_list arg_ptr; StrBuf *Buf = NewStrBuf(); @@ -123,11 +108,8 @@ void ctdl_printf(struct ctdlsession *ctdl, const char *format, ...) } -/* - * Client side - connect to a unix domain socket - */ -int uds_connectsock(char *sockpath) -{ +// Client side - connect to a unix domain socket +int uds_connectsock(char *sockpath) { struct sockaddr_un addr; int s; @@ -150,11 +132,8 @@ int uds_connectsock(char *sockpath) } -/* - * TCP client - connect to a host/port - */ -int tcp_connectsock(char *host, char *service) -{ +// TCP client - connect to a host/port +int tcp_connectsock(char *host, char *service) { struct in6_addr serveraddr; struct addrinfo hints; struct addrinfo *res = NULL; @@ -174,22 +153,20 @@ int tcp_connectsock(char *host, char *service) hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - /* - * Handle numeric IPv4 and IPv6 addresses - */ + // Handle numeric IPv4 and IPv6 addresses rc = inet_pton(AF_INET, host, &serveraddr); - if (rc == 1) { /* dotted quad */ + if (rc == 1) { // dotted quad hints.ai_family = AF_INET; hints.ai_flags |= AI_NUMERICHOST; } else { rc = inet_pton(AF_INET6, host, &serveraddr); - if (rc == 1) { /* IPv6 address */ + if (rc == 1) { // IPv6 address hints.ai_family = AF_INET6; hints.ai_flags |= AI_NUMERICHOST; } } - /* Begin the connection process */ + // Begin the connection process rc = getaddrinfo(host, service, &hints, &res); if (rc != 0) { @@ -198,9 +175,7 @@ int tcp_connectsock(char *host, char *service) return (-1); } - /* - * Try all available addresses until we connect to one or until we run out. - */ + // Try all available addresses until we connect to one or until we run out. for (ai = res; ai != NULL; ai = ai->ai_next) { if (ai->ai_family == AF_INET) @@ -245,12 +220,9 @@ int tcp_connectsock(char *host, char *service) } -/* - * Extract from the headers, the username and password the client is attempting to use. - * This could be HTTP AUTH or it could be in the cookies. - */ -void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen) -{ +// Extract from the headers, the username and password the client is attempting to use. +// This could be HTTP AUTH or it could be in the cookies. +void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen) { if (authbuf == NULL) return; authbuf[0] = 0; @@ -282,16 +254,13 @@ void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen) } -/* - * Log in to the Citadel server. Returns 0 on success or nonzero on error. - * - * 'auth' should be a base64-encoded "username:password" combination (like in http-auth) - * - * If 'resultbuf' is not NULL, it should be a buffer of at least 1024 characters, - * and will be filled with the result from a Citadel server command. - */ -int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf) -{ +// Log in to the Citadel server. Returns 0 on success or nonzero on error. +// +// 'auth' should be a base64-encoded "username:password" combination (like in http-auth) +// +// If 'resultbuf' is not NULL, it should be a buffer of at least 1024 characters, +// and will be filled with the result from a Citadel server command. +int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf) { char localbuf[1024]; char *buf; int buflen; @@ -300,7 +269,8 @@ int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf) if (resultbuf != NULL) { buf = resultbuf; - } else { + } + else { buf = localbuf; } @@ -331,11 +301,8 @@ int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf) } -/* - * Hunt for, or create, a connection to our Citadel Server - */ -struct ctdlsession *connect_to_citadel(struct http_transaction *h) -{ +// Hunt for, or create, a connection to our Citadel Server +struct ctdlsession *connect_to_citadel(struct http_transaction *h) { struct ctdlsession *cptr = NULL; struct ctdlsession *my_session = NULL; int is_new_session = 0; @@ -411,11 +378,8 @@ struct ctdlsession *connect_to_citadel(struct http_transaction *h) } -/* - * Release our Citadel Server connection back into the pool. - */ -void disconnect_from_citadel(struct ctdlsession *ctdl) -{ +// Release our Citadel Server connection back into the pool. +void disconnect_from_citadel(struct ctdlsession *ctdl) { pthread_mutex_lock(&cpool_mutex); ctdl->is_bound = 0; pthread_mutex_unlock(&cpool_mutex); diff --git a/webcit-ng/ctdlfunctions.c b/webcit-ng/ctdlfunctions.c index 70e394ae2..0365ad498 100644 --- a/webcit-ng/ctdlfunctions.c +++ b/webcit-ng/ctdlfunctions.c @@ -15,13 +15,9 @@ #include "webcit.h" - -/* - * Delete one or more messages from the connected Citadel server. - * This function expects the session to already be "in" the room from which the messages will be deleted. - */ -void ctdl_delete_msgs(struct ctdlsession *c, long *msgnums, int num_msgs) -{ +// Delete one or more messages from the connected Citadel server. +// This function expects the session to already be "in" the room from which the messages will be deleted. +void ctdl_delete_msgs(struct ctdlsession *c, long *msgnums, int num_msgs) { int i = 0; char buf[1024]; diff --git a/webcit-ng/forum_view.c b/webcit-ng/forum_view.c index e7c4820af..4c5481858 100644 --- a/webcit-ng/forum_view.c +++ b/webcit-ng/forum_view.c @@ -27,9 +27,7 @@ struct mthread { // Commands we need to send to Citadel Server before we begin rendering forum view. // These are common to flat and threaded views. -// -void setup_for_forum_view(struct ctdlsession *c) -{ +void setup_for_forum_view(struct ctdlsession *c) { char buf[1024]; ctdl_printf(c, "MSGP text/html|text/plain"); // Declare the MIME types we know how to render ctdl_readline(c, buf, sizeof(buf)); // Ignore the response @@ -39,9 +37,7 @@ void setup_for_forum_view(struct ctdlsession *c) // 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) -{ +void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum) { StrBuf *raw_msg = NULL; StrBuf *sanitized_msg = NULL; char buf[1024]; diff --git a/webcit-ng/html2html.c b/webcit-ng/html2html.c index f4f9e077e..4eaca438c 100644 --- a/webcit-ng/html2html.c +++ b/webcit-ng/html2html.c @@ -17,11 +17,8 @@ #include "webcit.h" -/* - * Strip surrounding single or double quotes from a string. - */ -void stripquotes(char *s) -{ +// Strip surrounding single or double quotes from a string. +void stripquotes(char *s) { int len; if (!s) @@ -38,15 +35,12 @@ void stripquotes(char *s) } -/* - * Check to see if a META tag has overridden the declared MIME character set. - * - * charset Character set name (left unchanged if we don't do anything) - * meta_http_equiv Content of the "http-equiv" portion of the META tag - * meta_content Content of the "content" portion of the META tag - */ -void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_content) -{ +// Check to see if a META tag has overridden the declared MIME character set. +// +// charset Character set name (left unchanged if we don't do anything) +// meta_http_equiv Content of the "http-equiv" portion of the META tag +// meta_content Content of the "content" portion of the META tag +void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_content) { char *ptr; char buf[64]; @@ -69,18 +63,16 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_ if (!strncasecmp(buf, "charset=", 8)) { strcpy(charset, &buf[8]); - /* - * The brain-damaged webmail program in Microsoft Exchange declares - * a charset of "unicode" when they really mean "UTF-8". GNU iconv - * treats "unicode" as an alias for "UTF-16" so we have to manually - * fix this here, otherwise messages generated in Exchange webmail - * show up as a big pile of weird characters. - */ + // The brain-damaged webmail program in Microsoft Exchange declares + // a charset of "unicode" when they really mean "UTF-8". GNU iconv + // treats "unicode" as an alias for "UTF-16" so we have to manually + // fix this here, otherwise messages generated in Exchange webmail + // show up as a big pile of weird characters. if (!strcasecmp(charset, "unicode")) { strcpy(charset, "UTF-8"); } - /* Remove wandering punctuation */ + // Remove wandering punctuation if ((ptr = strchr(charset, '\"'))) *ptr = 0; striplt(charset); @@ -88,14 +80,10 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_ } -/* - * Sanitize and enhance an HTML message for display. - * Also convert weird character sets to UTF-8 if necessary. - * Also fixup img src="cid:..." type inline images to fetch the image - * - */ -StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source) -{ +// Sanitize and enhance an HTML message for display. +// Also convert weird character sets to UTF-8 if necessary. +// Also fixup img src="cid:..." type inline images to fetch the image +StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source) { char buf[SIZ]; char *msg; char *ptr; @@ -116,11 +104,11 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam StrBuf *BodyArea = NULL; iconv_t ic = (iconv_t) (-1); - char *ibuf; /* Buffer of characters to be converted */ - char *obuf; /* Buffer for converted characters */ - size_t ibuflen; /* Length of input buffer */ - size_t obuflen; /* Length of output buffer */ - char *osav; /* Saved pointer to output buffer */ + char *ibuf; // Buffer of characters to be converted + char *obuf; // Buffer for converted characters + size_t ibuflen; // Length of input buffer + size_t obuflen; // Length of output buffer + char *osav; // Saved pointer to output buffer StrBuf *Target = NewStrBuf(); if (Target == NULL) { @@ -134,14 +122,14 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam msg = (char *) ChrPtr(Source); buffer_length = content_length; - /* Do a first pass to isolate the message body */ + // Do a first pass to isolate the message body ptr = msg + 1; msgstart = msg; msgend = &msg[content_length]; while (ptr < msgend) { - /* Advance to next tag */ + // Advance to next tag ptr = strchr(ptr, '<'); if ((ptr == NULL) || (ptr >= msgend)) break; @@ -149,12 +137,10 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam if ((ptr == NULL) || (ptr >= msgend)) break; - /* - * Look for META tags. Some messages (particularly in - * Asian locales) illegally declare a message's character - * set in the HTML instead of in the MIME headers. This - * is wrong but we have to work around it anyway. - */ + // Look for META tags. Some messages (particularly in + // Asian locales) illegally declare a message's character + // set in the HTML instead of in the MIME headers. This + // is wrong but we have to work around it anyway. if (!strncasecmp(ptr, "META", 4)) { char *meta_start; @@ -193,10 +179,8 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam } } - /* - * Any of these tags cause everything up to and including - * the tag to be removed. - */ + // Any of these tags cause everything up to and including + // the tag to be removed. if ((!strncasecmp(ptr, "HTML", 4)) || (!strncasecmp(ptr, "HEAD", 4)) || (!strncasecmp(ptr, "/HEAD", 5)) @@ -227,11 +211,11 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam while ((*cid_end != '"') && !isspace(*cid_end) && (cid_end < ptr)) cid_end++; - /* copy tag and attributes up to src="cid: */ + // copy tag and attributes up to src="cid: StrBufAppendBufPlain(BodyArea, pBody, src - pBody, 0); - /* add in /webcit/mimepart//CID/ - trailing / stops dumb URL filters getting excited */ + // add in /webcit/mimepart//CID/ + // trailing / stops dumb URL filters getting excited StrBufAppendPrintf(BodyArea, "/webcit/mimepart/%ld/", msgnum); StrBufAppendBufPlain(BodyArea, cid_start, cid_end - cid_start, 0); @@ -248,10 +232,8 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam msgstart = ptr; } - /* - * Any of these tags cause everything including and following - * the tag to be removed. - */ + // Any of these tags cause everything including and following + // the tag to be removed. if ((!strncasecmp(ptr, "/HTML", 5)) || (!strncasecmp(ptr, "/BODY", 5))) { --ptr; msgend = ptr; @@ -264,10 +246,10 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam strcpy(msg, msgstart); } - /* Now go through the message, parsing tags as necessary. */ + // Now go through the message, parsing tags as necessary. converted_msg = NewStrBufPlain(NULL, content_length + 8192); - /* Convert foreign character sets to UTF-8 if necessary. */ + // Convert foreign character sets to UTF-8 if necessary if ((strcasecmp(charset, "us-ascii")) && (strcasecmp(charset, "UTF-8")) && (strcasecmp(charset, "")) @@ -298,17 +280,15 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam StrBufConvert(Source, Buf, &ic); FreeStrBuf(&Buf); iconv_close(ic); - msg = (char *) ChrPtr(Source); /* TODO: get rid of this. */ + msg = (char *) ChrPtr(Source); // TODO: get rid of this. } } - /* - * At this point, the message has been stripped down to - * only the content inside the tags, and has - * been converted to UTF-8 if it was originally in a foreign - * character set. The text is also guaranteed to be null - * terminated now. - */ + // At this point, the message has been stripped down to + // only the content inside the tags, and has + // been converted to UTF-8 if it was originally in a foreign + // character set. The text is also guaranteed to be null + // terminated now. if (converted_msg == NULL) { StrBufAppendPrintf(Target, "Error %d: %s
%s:%d", errno, strerror(errno), __FILE__, __LINE__); @@ -324,7 +304,7 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam msgend = strchr(msg, 0); while (ptr < msgend) { - /* Try to sanitize the html of any rogue scripts */ + // Try to sanitize the html of any rogue scripts if (!strncasecmp(ptr, "')))) { - /* open external links to new window */ + // open external links to new window StrBufAppendPrintf(converted_msg, new_window); ptr = &ptr[8]; } else if ((treat_as_wiki) @@ -371,14 +351,14 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam ptr = &ptr[9]; } } - /* Fixup to fetch the mime part else if (!strncasecmp(ptr, "'); char *src; - /* FIXME - handle this situation (maybe someone opened an /CID/ - trailing / stops dumb URL filters getting excited */ + // add in /webcit/mimepart//CID/ + // trailing / stops dumb URL filters getting excited StrBufAppendPrintf(converted_msg, " src=\"/ctdl/r/"); StrBufXMLEscAppend(converted_msg, NULL, roomname, strlen(roomname), 0); syslog(LOG_DEBUG, "room name is '%s'", roomname); @@ -411,12 +391,10 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam ptr = tag_end; } - /* - * Turn anything that looks like a URL into a real link, as long - * as it's not inside a tag already - */ + // Turn anything that looks like a URL into a real link, as long + // as it's not inside a tag already else if ((brak == 0) && (alevel == 0) && ((!strncasecmp(ptr, "http://", 7)) || (!strncasecmp(ptr, "https://", 8)))) { - /* Find the end of the link */ + // Find the end of the link int strlenptr; linklen = 0; @@ -436,7 +414,7 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam || (ptr[i] == '\'') ) linklen = i; - /* entity tag? */ + // entity tag? if (ptr[i] == '&') { if ((ptr[i + 2] == ';') || (ptr[i + 3] == ';') || diff --git a/webcit-ng/main.c b/webcit-ng/main.c index aa674176e..2d30dabb2 100644 --- a/webcit-ng/main.c +++ b/webcit-ng/main.c @@ -18,11 +18,8 @@ char *ctdlhost = CTDLHOST; char *ctdlport = CTDLPORT; -/* - * Main entry point for the web server. - */ -int main(int argc, char **argv) -{ +// Main entry point for the web server. +int main(int argc, char **argv) { int webserver_port = WEBSERVER_PORT; char *webserver_interface = WEBSERVER_INTERFACE; int running_as_daemon = 0; @@ -30,7 +27,7 @@ int main(int argc, char **argv) int a; char *pid_file = NULL; - /* Parse command line */ + // Parse command line while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF) switch (a) { case 'u': @@ -53,7 +50,7 @@ int main(int argc, char **argv) case 'x': case 'T': case 'v': - /* The above options are no longer used, but ignored so old scripts don't break */ + // The above options are no longer used, but ignored so old scripts don't break break; case 'i': webserver_interface = optarg; @@ -100,12 +97,12 @@ int main(int argc, char **argv) ctdlport = argv[optind]; } - /* Start the logger */ + // Start the logger openlog("webcit", (running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR)), LOG_DAEMON); - /* Tell 'em who's in da house */ + // Tell 'em who's in da house syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!"); - syslog(LOG_NOTICE, "Copyright (C) 1996-2020 by the citadel.org team"); + syslog(LOG_NOTICE, "Copyright (C) 1996-2021 by the citadel.org team"); syslog(LOG_NOTICE, " "); syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or"); syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3."); @@ -116,14 +113,14 @@ int main(int argc, char **argv) syslog(LOG_NOTICE, "GNU General Public License for more details."); syslog(LOG_NOTICE, " "); - /* Ensure that we are linked to the correct version of libcitadel */ + // Ensure that we are linked to the correct version of libcitadel if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) { syslog(LOG_INFO, " You are running libcitadel version %d", libcitadel_version_number()); syslog(LOG_INFO, "WebCit was compiled against version %d", LIBCITADEL_VERSION_NUMBER); return (1); } - /* Go into the background if we were asked to run as a daemon */ + // Go into the background if we were asked to run as a daemon if (running_as_daemon) { daemon(1, 0); if (pid_file != NULL) { diff --git a/webcit-ng/webcit.h b/webcit-ng/webcit.h index 36f47acf7..94bd4b873 100644 --- a/webcit-ng/webcit.h +++ b/webcit-ng/webcit.h @@ -1,11 +1,9 @@ -/* - * webcit.h - "header of headers" - * - * Copyright (c) 1996-2018 by the citadel.org team - * - * This program is open source software. You can redistribute it and/or - * modify it under the terms of the GNU General Public License, version 3. - */ +// webcit.h - "header of headers" +// +// Copyright (c) 1996-2021 by the citadel.org team +// +// This program is open source software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License, version 3. #define SHOW_ME_VAPPEND_PRINTF @@ -44,7 +42,7 @@ #define _(x) x // temporary hack until we add i18n back in //#define DEBUG_HTTP // uncomment to debug HTTP headers -/* XML_StopParser is present in expat 2.x */ +// XML_StopParser is present in expat 2.x #if XML_MAJOR_VERSION > 1 #define HAVE_XML_STOPPARSER #endif -- 2.39.2