From cb6c5c9591b156968d81d8ac35d90741f69e7ce7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 5 Jan 2022 23:41:41 -0500 Subject: [PATCH] random acts of style cleanup --- citadel/citadel_dirs.c | 14 +--- citadel/citmail.c | 49 ++++--------- citadel/citserver.c | 67 ++++++++---------- citadel/clientsocket.c | 136 +++++++++++++++---------------------- citadel/config.c | 33 +++------ citadel/context.c | 85 +++++++---------------- citadel/contrib/getdoku.sh | 52 -------------- citadel/euidindex.c | 96 +++++++++++--------------- citadel/netconfig.c | 57 ++++++---------- 9 files changed, 196 insertions(+), 393 deletions(-) delete mode 100755 citadel/contrib/getdoku.sh diff --git a/citadel/citadel_dirs.c b/citadel/citadel_dirs.c index 7ba78e138..056047718 100644 --- a/citadel/citadel_dirs.c +++ b/citadel/citadel_dirs.c @@ -19,9 +19,7 @@ #include "citadel.h" #include "citadel_dirs.h" -/* - * Generate an associated file name for a room - */ +// Generate an associated file name for a room size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix) { return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber); } @@ -39,18 +37,12 @@ int create_dir(char *which, long ACCESS, long UID, long GID) { } rv = chmod(which, ACCESS); if (rv == -1) { - syslog(LOG_ERR, - "failed to set permissions for directory %s: %s", - which, - strerror(errno)); + syslog(LOG_ERR, "failed to set permissions for directory %s: %s", which, strerror(errno)); return rv; } rv = chown(which, UID, GID); if (rv == -1) { - syslog(LOG_ERR, - "failed to set owner for directory %s: %s", - which, - strerror(errno)); + syslog(LOG_ERR, "failed to set owner for directory %s: %s", which, strerror(errno)); return rv; } return rv; diff --git a/citadel/citmail.c b/citadel/citmail.c index bd4049008..924b67571 100644 --- a/citadel/citmail.c +++ b/citadel/citmail.c @@ -3,7 +3,7 @@ // listener on a unix domain socket and transmits the message. Really though, // if your MTA supports LMTP then you definitely should be using that instead. // -// Copyright (c) 1987-2021 by the citadel.org team +// Copyright (c) 1987-2022 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -69,11 +69,8 @@ int uds_connectsock(char *sockpath) { } -/* - * input binary data from socket - */ -void serv_read(char *buf, int bytes) -{ +// input binary data from socket +void serv_read(char *buf, int bytes) { int len, rlen; len = 0; @@ -87,11 +84,8 @@ void serv_read(char *buf, int bytes) } -/* - * send binary to server - */ -void serv_write(char *buf, int nbytes) -{ +// send binary to server +void serv_write(char *buf, int nbytes) { int bytes_written = 0; int retval; while (bytes_written < nbytes) { @@ -105,48 +99,37 @@ void serv_write(char *buf, int nbytes) } - -/* - * input string from socket - implemented in terms of serv_read() - */ -void serv_gets(char *buf) -{ +// input string from socket - implemented in terms of serv_read() +void serv_gets(char *buf) { int i; - /* Read one character at a time. - */ + // Read one character at a time. for (i = 0;; i++) { serv_read(&buf[i], 1); if (buf[i] == '\n' || i == (SIZ-1)) break; } - /* If we got a long line, discard characters until the newline. - */ + // If we got a long line, discard characters until the newline. if (i == (SIZ-1)) while (buf[i] != '\n') serv_read(&buf[i], 1); - /* Strip all trailing nonprintables (crlf) - */ + // Strip all trailing nonprintables (crlf) buf[i] = 0; strip_trailing_nonprint(buf); if (debug) fprintf(stderr, "> %s\n", buf); } -/* - * send line to server - implemented in terms of serv_write() - */ -void serv_puts(char *buf) -{ +// send line to server - implemented in terms of serv_write() +void serv_puts(char *buf) { if (debug) fprintf(stderr, "< %s\n", buf); serv_write(buf, strlen(buf)); serv_write("\n", 1); } - void cleanup(int exitcode) { char buf[1024]; @@ -160,7 +143,6 @@ void cleanup(int exitcode) { } - int main(int argc, char **argv) { char buf[1024]; char fromline[1024]; @@ -330,9 +312,8 @@ int main(int argc, char **argv) { cleanup(0); } - /* We won't actually reach this statement but the compiler will - * display a spurious warning about an invalid return type if - * we don't return an int. - */ + // We won't actually reach this statement but the compiler will + // display a spurious warning about an invalid return type if + // we don't return an int. return(0); } diff --git a/citadel/citserver.c b/citadel/citserver.c index 7801761f6..f12543acc 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -29,11 +29,8 @@ int panic_fd; int openid_level_supported = 0; -/* - * Various things that need to be initialized at startup - */ -void master_startup(void) -{ +// Various things that need to be initialized at startup +void master_startup(void) { struct timeval tv; unsigned int seed; FILE *urandom; @@ -60,7 +57,7 @@ void master_startup(void) syslog(LOG_INFO, "Opening databases"); open_databases(); - /* Load site-specific configuration */ + // Load site-specific configuration syslog(LOG_INFO, "Initializing configuration system"); initialize_config_system(); validate_config(); @@ -73,7 +70,7 @@ void master_startup(void) ForEachUser(reindex_user_928, NULL); } - /* Check floor reference counts */ + // Check floor reference counts check_ref_counts(); syslog(LOG_INFO, "Creating base rooms (if necessary)"); @@ -82,13 +79,13 @@ void master_startup(void) CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS); CtdlCreateRoom(CtdlGetConfigStr("c_twitroom"), 0, "", 0, 1, 0, VIEW_BBS); - /* The "Local System Configuration" room doesn't need to be visible */ + // The "Local System Configuration" room doesn't need to be visible if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) { qrbuf.QRflags2 |= QR2_SYSTEM; CtdlPutRoomLock(&qrbuf); } - /* Aide needs to be public postable, else we're not RFC conformant. */ + // Aide needs to be public postable, else we're not RFC conformant. if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) { qrbuf.QRflags2 |= QR2_SMTP_PUBLIC; CtdlPutRoomLock(&qrbuf); @@ -102,7 +99,8 @@ void master_startup(void) syslog(LOG_ERR, "citserver: failed to read random seed: %m"); } fclose(urandom); - } else { + } + else { gettimeofday(&tv, NULL); seed = tv.tv_usec; } @@ -113,11 +111,8 @@ void master_startup(void) } -/* - * Cleanup routine to be called when the server is shutting down. Returns the needed exit code. - */ -int master_cleanup(int exitcode) -{ +// Cleanup routine to be called when the server is shutting down. Returns the needed exit code. +int master_cleanup(int exitcode) { static int already_cleaning_up = 0; if (already_cleaning_up) { @@ -127,17 +122,17 @@ int master_cleanup(int exitcode) } already_cleaning_up = 1; - /* Do system-dependent stuff */ + // Do system-dependent stuff sysdep_master_cleanup(); - /* Close the configuration system */ + // Close the configuration system shutdown_config_system(); - /* Close databases */ + // Close databases syslog(LOG_INFO, "citserver: closing databases"); close_databases(); - /* If the operator requested a halt but not an exit, halt here. */ + // If the operator requested a halt but not an exit, halt here. if (shutdown_and_halt) { syslog(LOG_ERR, "citserver: Halting server without exiting."); fflush(stdout); @@ -147,59 +142,53 @@ int master_cleanup(int exitcode) } } - /* Now go away. */ + // Now go away. syslog(LOG_ERR, "citserver: Exiting with status %d", exitcode); fflush(stdout); fflush(stderr); if (restart_server != 0) { exitcode = 1; - } else if ((running_as_daemon != 0) && ((exitcode == 0))) { + } + else if ((running_as_daemon != 0) && ((exitcode == 0))) { exitcode = CTDLEXIT_SHUTDOWN; } return (exitcode); } -/* - * returns an asterisk if there are any instant messages waiting, - * space otherwise. - */ -char CtdlCheckExpress(void) -{ +// returns an asterisk if there are any instant messages waiting, space otherwise. +char CtdlCheckExpress(void) { if (CC->FirstExpressMessage == NULL) { return (' '); - } else { + } + else { return ('*'); } } -void citproto_begin_session() -{ +void citproto_begin_session() { if (CC->nologin == 1) { cprintf("%d Too many users are already online (maximum is %d)\n", ERROR + MAX_SESSIONS_EXCEEDED, CtdlGetConfigInt("c_maxsessions") - ); + ); CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED; - } else { + } + else { cprintf("%d %s Citadel server ready.\n", CIT_OK, CtdlGetConfigStr("c_fqdn")); CC->can_receive_im = 1; } } -void citproto_begin_admin_session() -{ +void citproto_begin_admin_session() { CC->internal_pgm = 1; cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, CtdlGetConfigStr("c_fqdn")); } -/* - * This loop performs all asynchronous functions. - */ -void do_async_loop(void) -{ +// This loop performs all asynchronous functions. +void do_async_loop(void) { PerformSessionHooks(EVT_ASYNC); } diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index e71410e9f..07ec4c382 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -17,8 +17,7 @@ #include "ctdl_module.h" #include "clientsocket.h" -int sock_connect(char *host, char *service) -{ +int sock_connect(char *host, char *service) { struct in6_addr serveraddr; struct addrinfo hints; struct addrinfo *res = NULL; @@ -36,32 +35,28 @@ int sock_connect(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 { + } + 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) { syslog(LOG_ERR, "%s: %s", host, gai_strerror(rc)); 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) { sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (sock < 0) { @@ -84,22 +79,18 @@ int sock_connect(char *host, char *service) } - -/* - * Read data from the client socket. - * - * sock socket fd to read from - * buf buffer to read into - * bytes number of bytes to read - * timeout Number of seconds to wait before timing out - * - * Possible return values: - * 1 Requested number of bytes has been read. - * 0 Request timed out. - * -1 Connection is broken, or other error. - */ -int socket_read_blob(int *Socket, StrBuf *Target, int bytes, int timeout) -{ +// Read data from the client socket. +// +// sock socket fd to read from +// buf buffer to read into +// bytes number of bytes to read +// timeout Number of seconds to wait before timing out +// +// Possible return values: +// 1 Requested number of bytes has been read. +// 0 Request timed out. +// -1 Connection is broken, or other error. +int socket_read_blob(int *Socket, StrBuf *Target, int bytes, int timeout) { const char *Error; int retval = 0; @@ -111,16 +102,14 @@ int socket_read_blob(int *Socket, StrBuf *Target, int bytes, int timeout) } -int CtdlSockGetLine(int *sock, StrBuf *Target, int nSec) -{ - CitContext *CCC = MyContext(); +int CtdlSockGetLine(int *sock, StrBuf *Target, int nSec) { const char *Error; int rc; FlushStrBuf(Target); rc = StrBufTCP_read_buffered_line_fast(Target, - CCC->SBuf.Buf, - &CCC->SBuf.ReadWritePointer, + CC->SBuf.Buf, + &CC->SBuf.ReadWritePointer, sock, nSec, 1, &Error); if ((rc < 0) && (Error != NULL)) { syslog(LOG_ERR, "clientsocket: CtdlSockGetLine() failed: %s", Error); @@ -129,24 +118,20 @@ int CtdlSockGetLine(int *sock, StrBuf *Target, int nSec) } -/* - * client_getln() ... Get a LF-terminated line of text from the client. - */ -int sock_getln(int *sock, char *buf, int bufsize) -{ +// client_getln() ... Get a LF-terminated line of text from the client. +int sock_getln(int *sock, char *buf, int bufsize) { int i, retval; - CitContext *CCC = MyContext(); const char *pCh; - FlushStrBuf(CCC->sMigrateBuf); - retval = CtdlSockGetLine(sock, CCC->sMigrateBuf, 5); + FlushStrBuf(CC->sMigrateBuf); + retval = CtdlSockGetLine(sock, CC->sMigrateBuf, 5); - i = StrLength(CCC->sMigrateBuf); - pCh = ChrPtr(CCC->sMigrateBuf); + i = StrLength(CC->sMigrateBuf); + pCh = ChrPtr(CC->sMigrateBuf); memcpy(buf, pCh, i + 1); - FlushStrBuf(CCC->sMigrateBuf); + FlushStrBuf(CC->sMigrateBuf); if (retval < 0) { safestrncpy(&buf[i], "000", bufsize - i); i += 3; @@ -155,14 +140,14 @@ int sock_getln(int *sock, char *buf, int bufsize) } -/* - * sock_write() - send binary to server. - * Returns the number of bytes written, or -1 for error. - */ -int sock_write(int *sock, const char *buf, int nbytes) -{ return sock_write_timeout(sock, buf, nbytes, 50); } -int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout) -{ +// sock_write() - send binary to server. +// Returns the number of bytes written, or -1 for error. +int sock_write(int *sock, const char *buf, int nbytes) { + return sock_write_timeout(sock, buf, nbytes, 50); +} + + +int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout) { int nSuccessLess = 0; int bytes_written = 0; int retval; @@ -175,11 +160,8 @@ int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout) fdflags = fcntl(*sock, F_GETFL); IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK; - while ((nSuccessLess < timeout) && - (*sock != -1) && - (bytes_written < nbytes)) - { - if (IsNonBlock){ + while ((nSuccessLess < timeout) && (*sock != -1) && (bytes_written < nbytes)) { + if (IsNonBlock) { tv.tv_sec = selectresolution; tv.tv_usec = 0; @@ -220,24 +202,20 @@ int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout) } -/* - * client_getln() ... Get a LF-terminated line of text from the client. - */ -int sock_getln_err(int *sock, char *buf, int bufsize, int *rc, int nSec) -{ +// client_getln() ... Get a LF-terminated line of text from the client. +int sock_getln_err(int *sock, char *buf, int bufsize, int *rc, int nSec) { int i, retval; - CitContext *CCC = MyContext(); const char *pCh; - FlushStrBuf(CCC->sMigrateBuf); - *rc = retval = CtdlSockGetLine(sock, CCC->sMigrateBuf, nSec); + FlushStrBuf(CC->sMigrateBuf); + *rc = retval = CtdlSockGetLine(sock, CC->sMigrateBuf, nSec); - i = StrLength(CCC->sMigrateBuf); - pCh = ChrPtr(CCC->sMigrateBuf); + i = StrLength(CC->sMigrateBuf); + pCh = ChrPtr(CC->sMigrateBuf); memcpy(buf, pCh, i + 1); - FlushStrBuf(CCC->sMigrateBuf); + FlushStrBuf(CC->sMigrateBuf); if (retval < 0) { safestrncpy(&buf[i], "000", bufsize - i); i += 3; @@ -246,13 +224,10 @@ int sock_getln_err(int *sock, char *buf, int bufsize, int *rc, int nSec) } -/* - * Multiline version of sock_gets() ... this is a convenience function for - * client side protocol implementations. It only returns the first line of - * a multiline response, discarding the rest. - */ -int ml_sock_gets(int *sock, char *buf, int nSec) -{ +// Multiline version of sock_gets() ... this is a convenience function for +// client side protocol implementations. It only returns the first line of +// a multiline response, discarding the rest. +int ml_sock_gets(int *sock, char *buf, int nSec) { int rc = 0; char bigbuf[1024]; int g; @@ -277,12 +252,9 @@ int ml_sock_gets(int *sock, char *buf, int nSec) } -/* - * sock_puts() - send line to server - implemented in terms of serv_write() - * Returns the number of bytes written, or -1 for error. - */ -int sock_puts(int *sock, char *buf) -{ +// sock_puts() - send line to server - implemented in terms of serv_write() +// Returns the number of bytes written, or -1 for error. +int sock_puts(int *sock, char *buf) { int i, j; i = sock_write(sock, buf, strlen(buf)); diff --git a/citadel/config.c b/citadel/config.c index d04f87434..9abc9af4b 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -22,8 +22,7 @@ long config_msgnum = 0; HashList *ctdlconfig = NULL; // new configuration -void config_warn_if_port_unset(char *key, int default_port) -{ +void config_warn_if_port_unset(char *key, int default_port) { int p = CtdlGetConfigInt(key); if ((p < -1) || (p == 0) || (p > UINT16_MAX)) { @@ -33,10 +32,8 @@ void config_warn_if_port_unset(char *key, int default_port) } -void config_warn_if_empty(char *key) -{ - if (IsEmptyStr(CtdlGetConfigStr(key))) - { +void config_warn_if_empty(char *key) { + if (IsEmptyStr(CtdlGetConfigStr(key))) { syslog(LOG_ERR, "config: setting %s is empty, but must not - check your config!", key); } } @@ -139,8 +136,7 @@ void brand_new_installation_set_defaults(void) { * Migrate a supplied legacy configuration to the new in-db format. * No individual site should ever have to do this more than once. */ -void migrate_legacy_config(struct legacy_config *lconfig) -{ +void migrate_legacy_config(struct legacy_config *lconfig) { CtdlSetConfigStr( "c_nodename" , lconfig->c_nodename ); CtdlSetConfigStr( "c_fqdn" , lconfig->c_fqdn ); CtdlSetConfigStr( "c_humannode" , lconfig->c_humannode ); @@ -305,8 +301,7 @@ void initialize_config_system(void) { * Called when Citadel server is shutting down. * Clears out the config hash table. */ -void shutdown_config_system(void) -{ +void shutdown_config_system(void) { DeleteHash(&ctdlconfig); } @@ -314,8 +309,7 @@ void shutdown_config_system(void) /* * Set a system config value. Simple key/value here. */ -void CtdlSetConfigStr(char *key, char *value) -{ +void CtdlSetConfigStr(char *key, char *value) { int key_len = strlen(key); int value_len = strlen(value); @@ -336,8 +330,7 @@ void CtdlSetConfigStr(char *key, char *value) /* * Set a numeric system config value (long integer) */ -void CtdlSetConfigLong(char *key, long value) -{ +void CtdlSetConfigLong(char *key, long value) { char longstr[256]; sprintf(longstr, "%ld", value); CtdlSetConfigStr(key, longstr); @@ -347,8 +340,7 @@ void CtdlSetConfigLong(char *key, long value) /* * Set a numeric system config value (integer) */ -void CtdlSetConfigInt(char *key, int value) -{ +void CtdlSetConfigInt(char *key, int value) { char intstr[256]; sprintf(intstr, "%d", value); CtdlSetConfigStr(key, intstr); @@ -358,8 +350,7 @@ void CtdlSetConfigInt(char *key, int value) /* * Delete a system config value. */ -void CtdlDelConfig(char *key) -{ +void CtdlDelConfig(char *key) { int key_len = strlen(key); if (IsEmptyStr(key)) return; @@ -381,8 +372,7 @@ void CtdlDelConfig(char *key) /* * Fetch a system config value. Caller does *not* own the returned value and may not alter it. */ -char *CtdlGetConfigStr(char *key) -{ +char *CtdlGetConfigStr(char *key) { char *value = NULL; struct cdbdata *cdb; int key_len = strlen(key); @@ -414,8 +404,7 @@ char *CtdlGetConfigStr(char *key) /* * Fetch a system config value - integer */ -int CtdlGetConfigInt(char *key) -{ +int CtdlGetConfigInt(char *key) { char *s = CtdlGetConfigStr(key); if (s) return atoi(s); return 0; diff --git a/citadel/context.c b/citadel/context.c index 1a2816f54..bca317d23 100644 --- a/citadel/context.c +++ b/citadel/context.c @@ -29,8 +29,7 @@ static int want_single_user = 0; /* Try to go single user */ -int CtdlTrySingleUser(void) -{ +int CtdlTrySingleUser(void) { int can_do = 0; begin_critical_section(S_SINGLE_USER); @@ -46,24 +45,20 @@ int CtdlTrySingleUser(void) } -void CtdlEndSingleUser(void) -{ +void CtdlEndSingleUser(void) { begin_critical_section(S_SINGLE_USER); want_single_user = 0; end_critical_section(S_SINGLE_USER); } -int CtdlWantSingleUser(void) -{ +int CtdlWantSingleUser(void) { return want_single_user; } -int CtdlIsSingleUser(void) -{ - if (want_single_user) - { +int CtdlIsSingleUser(void) { + if (want_single_user) { /* check for only one context here */ if (num_sessions == 1) return 1; @@ -78,23 +73,21 @@ int CtdlIsSingleUser(void) * User CAN terminate any other session that has them logged in. * Aide CAN terminate any session except the current one. */ -int CtdlTerminateOtherSession (int session_num) -{ - struct CitContext *CCC = CC; +int CtdlTerminateOtherSession (int session_num) { int ret = 0; CitContext *ccptr; int aide; - if (session_num == CCC->cs_pid) return TERM_NOTALLOWED; + if (session_num == CC->cs_pid) return TERM_NOTALLOWED; - aide = ( (CCC->user.axlevel >= AxAideU) || (CCC->internal_pgm) ) ; + aide = ( (CC->user.axlevel >= AxAideU) || (CC->internal_pgm) ) ; syslog(LOG_DEBUG, "context: locating session to kill"); begin_critical_section(S_SESSION_TABLE); for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) { if (session_num == ccptr->cs_pid) { ret |= TERM_FOUND; - if ((ccptr->user.usernum == CCC->user.usernum) || aide) { + if ((ccptr->user.usernum == CC->user.usernum) || aide) { ret |= TERM_ALLOWED; } break; @@ -103,7 +96,7 @@ int CtdlTerminateOtherSession (int session_num) if (((ret & TERM_FOUND) != 0) && ((ret & TERM_ALLOWED) != 0)) { - if (ccptr->user.usernum == CCC->user.usernum) + if (ccptr->user.usernum == CC->user.usernum) ccptr->kill_me = KILLME_ADMIN_TERMINATE; else ccptr->kill_me = KILLME_IDLE; @@ -116,19 +109,17 @@ int CtdlTerminateOtherSession (int session_num) } - /* * Check to see if the user who we just sent mail to is logged in. If yes, * bump the 'new mail' counter for their session. That enables them to * receive a new mail notification without having to hit the database. */ -void BumpNewMailCounter(long which_user) -{ +void BumpNewMailCounter(long which_user) { CtdlBumpNewMailCounter(which_user); } -void CtdlBumpNewMailCounter(long which_user) -{ + +void CtdlBumpNewMailCounter(long which_user) { CitContext *ptr; begin_critical_section(S_SESSION_TABLE); @@ -149,8 +140,7 @@ void CtdlBumpNewMailCounter(long which_user) * The user may not have been logged in when this function was called BUT * because of threading the user might be logged in before you test the result. */ -int CtdlIsUserLoggedIn (char *user_name) -{ +int CtdlIsUserLoggedIn(char *user_name) { CitContext *cptr; int ret = 0; @@ -166,7 +156,6 @@ int CtdlIsUserLoggedIn (char *user_name) } - /* * Check to see if a user is currently logged in. * Basically same as CtdlIsUserLoggedIn() but uses the user number instead. @@ -174,8 +163,7 @@ int CtdlIsUserLoggedIn (char *user_name) * The user may not have been logged in when this function was called BUT * because of threading the user might be logged in before you test the result. */ -int CtdlIsUserLoggedInByNum (long usernum) -{ +int CtdlIsUserLoggedInByNum (long usernum) { CitContext *cptr; int ret = 0; @@ -190,7 +178,6 @@ int CtdlIsUserLoggedInByNum (long usernum) } - /* * Return a pointer to the CitContext structure bound to the thread which * called this function. If there's no such binding (for example, if it's @@ -204,16 +191,13 @@ CitContext *MyContext(void) { } - - /* * Terminate idle sessions. This function pounds through the session table * comparing the current time to each session's time-of-last-command. If an * idle session is found it is terminated, then the search restarts at the * beginning because the pointer to our place in the list becomes invalid. */ -void terminate_idle_sessions(void) -{ +void terminate_idle_sessions(void) { CitContext *ccptr; time_t now; int killed = 0; @@ -249,8 +233,7 @@ void terminate_idle_sessions(void) /* * During shutdown, close the sockets of any sessions still connected. */ -void terminate_all_sessions(void) -{ +void terminate_all_sessions(void) { CitContext *ccptr; int killed = 0; @@ -271,12 +254,10 @@ void terminate_all_sessions(void) } - /* * Terminate a session. */ -void RemoveContext (CitContext *con) -{ +void RemoveContext (CitContext *con) { const char *c; if (con == NULL) { syslog(LOG_ERR, "context: RemoveContext() called with NULL, this should not happen"); @@ -304,8 +285,7 @@ void RemoveContext (CitContext *con) * If the client is still connected, blow 'em away. * if the socket is 0 or -1, its already gone or was never there. */ - if (con->client_socket > 0) - { + if (con->client_socket > 0) { syslog(LOG_INFO, "context: closing socket %d", con->client_socket); close(con->client_socket); } @@ -326,7 +306,6 @@ void RemoveContext (CitContext *con) } - /* * Initialize a new context and place it in the list. The session number * used to be the PID (which is why it's called cs_pid), but that was when we @@ -442,8 +421,7 @@ CitContext *CloneContext(CitContext *CloneMe) { * This allows worker threads to perform "for each context" operations without * having to lock and traverse the live list. */ -CitContext *CtdlGetContextArray(int *count) -{ +CitContext *CtdlGetContextArray(int *count) { int nContexts, i; CitContext *nptr, *cptr; @@ -464,12 +442,10 @@ CitContext *CtdlGetContextArray(int *count) } - /* * Back-end function for starting a session */ -void begin_session(CitContext *con) -{ +void begin_session(CitContext *con) { /* * Initialize some variables specific to our context. */ @@ -553,8 +529,7 @@ void begin_session(CitContext *con) * This function fills in a context and its user field correctly * Then creates/loads that user */ -void CtdlFillSystemContext(CitContext *context, char *name) -{ +void CtdlFillSystemContext(CitContext *context, char *name) { char sysname[SIZ]; long len; @@ -575,8 +550,7 @@ void CtdlFillSystemContext(CitContext *context, char *name) internal_create_user(sysname, &(context->user), -1) ; /* Check to see if the system user needs upgrading */ - if (context->user.usernum == 0) - { /* old system user with number 0, upgrade it */ + if (context->user.usernum == 0) { /* old system user with number 0, upgrade it */ context->user.usernum = get_new_user_number(); syslog(LOG_INFO, "context: upgrading system user \"%s\" from user number 0 to user number %ld", context->user.fullname, context->user.usernum); /* add user to the database */ @@ -589,8 +563,7 @@ void CtdlFillSystemContext(CitContext *context, char *name) /* * Cleanup any contexts that are left lying around */ -void context_cleanup(void) -{ +void context_cleanup(void) { CitContext *ptr = NULL; CitContext *rem = NULL; @@ -620,7 +593,6 @@ void context_cleanup(void) } - /* * Purge all sessions which have the 'kill_me' flag set. * This function has code to prevent it from running more than once every @@ -681,9 +653,6 @@ void dead_session_purge(int force) { } - - - /* * masterCC is the context we use when not attached to a session. This * function initializes it. @@ -695,14 +664,10 @@ void InitializeMasterCC(void) { } - - - /* * Set the "async waiting" flag for a session, if applicable */ -void set_async_waiting(struct CitContext *ccptr) -{ +void set_async_waiting(struct CitContext *ccptr) { syslog(LOG_DEBUG, "context: setting async_waiting flag for session %d", ccptr->cs_pid); if (ccptr->is_async) { ccptr->async_waiting++; diff --git a/citadel/contrib/getdoku.sh b/citadel/contrib/getdoku.sh deleted file mode 100755 index 55d5e922f..000000000 --- a/citadel/contrib/getdoku.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -BASE_SITE=http://www.citadel.org - - - -#retrieves an index document from the citadel.org website, and filters it -# 1: URL -# 2: outfile where to put the filtered content at -GetIndex() -{ - cd /tmp/; wget -q "${BASE_SITE}/${1}" - cat "/tmp/${1}" | \ - grep /doku.php/ | \ - grep -v "do=" | \ - sed -e "s;.*href=\";;" \ - -e "s;\" .*;;" \ - -e "s;doku.php/;doku.php?id=;"| \ - grep "^/doku" > \ - "/tmp/$2" -} - -rm -f /tmp/mainindex /tmp/doku.php* -GetIndex "doku.php?id=faq:start" mainindex - -for i in `cat /tmp/mainindex`; do - TMPNAME=`echo $i|sed "s;.*=;;"` - echo $i $TMPNAME - mkdir /tmp/$TMPNAME - GetIndex "$i" "$TMPNAME/$TMPNAME" - for j in `cat /tmp/$TMPNAME/$TMPNAME`; do - echo "-----------$j----------------" - cd /tmp/$TMPNAME/; - DOCUMENT_NAME=`echo $j|sed -e "s;/doku.php?id=.*:;;"` - PLAIN_NAME=`grep "$DOCUMENT_NAME" /tmp/doku*$TMPNAME |head -n1 |sed -e "s;','/doku.*;;" -e "s;.*';;"` - - echo "********** retrieving $DOCUMENT_NAME ************" - wget -q "${BASE_SITE}/${j}&do=export_xhtmlbody" - mv "/tmp/$TMPNAME/${j}&do=export_xhtmlbody" /tmp/$TMPNAME/$DOCUMENT_NAME - - echo "
  • $PLAIN_NAME
  • " >>collect_index - echo "" >>collect_bodies - cat $DOCUMENT_NAME>>collect_bodies - done - ( - echo "$TMPNAME" - cat "/tmp/$TMPNAME/collect_bodies" - echo "" - ) >/tmp/`echo $TMPNAME|sed "s;:;_;g"`.html -done \ No newline at end of file diff --git a/citadel/euidindex.c b/citadel/euidindex.c index 6d87c19a8..59d67deb9 100644 --- a/citadel/euidindex.c +++ b/citadel/euidindex.c @@ -1,16 +1,14 @@ -/* - * Index messages by EUID per room. - * - * Copyright (c) 1987-2020 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ +// Index messages by EUID per room. +// +// Copyright (c) 1987-2022 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. #include "sysdep.h" #include @@ -19,24 +17,19 @@ #include "citserver.h" #include "room_ops.h" -/* - * The structure of an euidindex record *key* is: - * - * |----room_number----|----------EUID-------------| - * (sizeof long) (actual length of euid) - * - * - * The structure of an euidindex record *value* is: - * - * |-----msg_number----|----room_number----|----------EUID-------------| - * (sizeof long) (sizeof long) (actual length of euid) - * - */ - -/* - * Return nonzero if the supplied room is one which should have - * an EUID index. - */ +// The structure of an euidindex record *key* is: +// +// |----room_number----|----------EUID-------------| +// (sizeof long) (actual length of euid) +// +// +// The structure of an euidindex record *value* is: +// +// |-----msg_number----|----room_number----|----------EUID-------------| +// (sizeof long) (sizeof long) (actual length of euid) + +// Return nonzero if the supplied room is one which should have +// an EUID index. int DoesThisRoomNeedEuidIndexing(struct ctdlroom *qrbuf) { switch(qrbuf->QRdefaultview) { @@ -55,10 +48,8 @@ int DoesThisRoomNeedEuidIndexing(struct ctdlroom *qrbuf) { } -/* - * Locate a message in a given room with a given euid, and return - * its message number. - */ +// Locate a message in a given room with a given euid, and return +// its message number. long locate_message_by_euid(char *euid, struct ctdlroom *qrbuf) { return CtdlLocateMessageByEuid (euid, qrbuf); } @@ -84,9 +75,7 @@ long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf) { msgnum = (-1L); } else { - /* The first (sizeof long) of the record is what we're - * looking for. Throw away the rest. - */ + // The first (sizeof long) of the record is what we're looking for. Throw away the rest. memcpy(&msgnum, cdb_euid->ptr, sizeof(long)); cdb_free(cdb_euid); } @@ -95,10 +84,8 @@ long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf) { } -/* - * Store the euid index for a message, which has presumably just been - * stored in this room by the caller. - */ +// Store the euid index for a message, which has presumably just been +// stored in this room by the caller. void index_message_by_euid(char *euid, struct ctdlroom *qrbuf, long msgnum) { char *key; int key_len; @@ -124,9 +111,7 @@ void index_message_by_euid(char *euid, struct ctdlroom *qrbuf, long msgnum) { } -/* - * Called by rebuild_euid_index_for_room() to index one message. - */ +// Called by rebuild_euid_index_for_room() to index one message. void rebuild_euid_index_for_msg(long msgnum, void *userdata) { struct CtdlMessage *msg = NULL; @@ -144,10 +129,9 @@ void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) { struct RoomProcList *ptr; struct ctdlroom qr; - /* Lazy programming here. Call this function as a CtdlForEachRoom backend - * in order to queue up the room names, or call it with a null room - * to make it do the processing. - */ + // Lazy programming here. Call this function as a CtdlForEachRoom backend + // in order to queue up the room names, or call it with a null room + // to make it do the processing. if (qrbuf != NULL) { ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList)); @@ -176,19 +160,15 @@ void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) { } -/* - * Globally rebuild the EUID indices in every room. - */ +// Globally rebuild the EUID indices in every room. void rebuild_euid_index(void) { - cdb_trunc(CDB_EUIDINDEX); /* delete the old indices */ - CtdlForEachRoom(rebuild_euid_index_for_room, NULL); /* enumerate rm names */ - rebuild_euid_index_for_room(NULL, NULL); /* and index them */ + cdb_trunc(CDB_EUIDINDEX); // delete the old indices + CtdlForEachRoom(rebuild_euid_index_for_room, NULL); // enumerate room names + rebuild_euid_index_for_room(NULL, NULL); // and index them } -/* - * Server command to fetch a message number given an euid. - */ +// Server command to fetch a message number given an euid. void cmd_euid(char *cmdbuf) { char euid[256]; long msgnum; diff --git a/citadel/netconfig.c b/citadel/netconfig.c index 73ab22f4f..ab4741280 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -1,17 +1,14 @@ -/* - * This module handles loading, saving, and parsing of room network configurations. - * - * Copyright (c) 2000-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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ +// This module handles loading, saving, and parsing of room network configurations. +// +// Copyright (c) 2000-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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. #include "sysdep.h" #include @@ -35,18 +32,14 @@ #include "config.h" -/* - * Create a config key for a room's netconfig entry - */ +// Create a config key for a room's netconfig entry void netcfg_keyname(char *keybuf, long roomnum) { if (!keybuf) return; sprintf(keybuf, "c_netconfig_%010ld", roomnum); } -/* - * Given a room number and a textual netconfig, convert to base64 and write to the configdb - */ +// Given a room number and a textual netconfig, convert to base64 and write to the configdb void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig) { char keyname[25]; char *enc; @@ -69,11 +62,9 @@ void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig) { } -/* - * Given a room number, attempt to load the netconfig configdb entry for that room. - * If it returns NULL, there is no netconfig. - * Otherwise the caller owns the returned memory and is responsible for freeing it. - */ +// Given a room number, attempt to load the netconfig configdb entry for that room. +// If it returns NULL, there is no netconfig. +// Otherwise the caller owns the returned memory and is responsible for freeing it. char *LoadRoomNetConfigFile(long roomnum) { char keyname[25]; char *encoded_netconfig = NULL; @@ -89,13 +80,12 @@ char *LoadRoomNetConfigFile(long roomnum) { } -/*-----------------------------------------------------------------------------* - * Per room network configs : exchange with client * - *-----------------------------------------------------------------------------*/ - +//----------------------------------------------------------------------------- +// Per room network configs : exchange with client +//----------------------------------------------------------------------------- void cmd_gnet(char *argbuf) { if ( (CC->room.QRflags & QR_MAILBOX) && (CC->user.usernum == atol(CC->room.QRname)) ) { - /* users can edit the netconfigs for their own mailbox rooms */ + // users can edit the netconfigs for their own mailbox rooms } else if (CtdlAccessCheck(ac_room_aide)) return; @@ -140,11 +130,8 @@ void cmd_snet(char *argbuf) { } -/* - * Convert any legacy configuration files in the "netconfigs" directory - */ -void convert_legacy_netcfg_files(void) -{ +// Convert any legacy configuration files in the "netconfigs" directory +void convert_legacy_netcfg_files(void) { DIR *dh = NULL; struct dirent *dit = NULL; char filename[PATH_MAX]; -- 2.30.2