Finished converting all the comments in webcit-ng to C99 style
authorArt Cancro <ajc@citadel.org>
Sat, 16 Oct 2021 23:21:06 +0000 (19:21 -0400)
committerArt Cancro <ajc@citadel.org>
Sat, 16 Oct 2021 23:21:06 +0000 (19:21 -0400)
webcit-ng/html2html.c
webcit-ng/ssl.c
webcit-ng/static.c
webcit-ng/user_functions.c
webcit-ng/util.c

index 7518a29bfaa87dd2745c7595c6b562507a64988d..0d0264a43b28ab2024b3aec5cfaae6b732f3a472 100644 (file)
@@ -492,7 +492,7 @@ StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomnam
        //      memcpy(converted_msg, msg, content_length);
        //      output_length = content_length;
 
-       /* Output our big pile of markup */
+       // Output our big pile of markup
        StrBufAppendBuf(Target, converted_msg, 0);
 
       BAIL:                    // A little trailing vertical whitespace...
index b8d53d2787e829256fd028cf001af204ad3cfb53..8d33fe45f24f8cc5d9b8fd707666563321e7dd10 100644 (file)
@@ -16,8 +16,8 @@
 
 #include "webcit.h"
 
-SSL_CTX *ssl_ctx;              /* SSL context */
-pthread_mutex_t **SSLCritters; /* Things needing locking */
+SSL_CTX *ssl_ctx;              // SSL context
+pthread_mutex_t **SSLCritters; // Things needing locking
 char *ssl_cipher_list = DEFAULT_SSL_CIPHER_LIST;
 void ssl_lock(int mode, int n, const char *file, int line);
 
@@ -41,9 +41,7 @@ void ssl_lock(int mode, int n, const char *file, int line) {
 }
 
 
-/*
- * Generate a private key for SSL
- */
+// Generate a private key for SSL
 void generate_key(char *keyfilename) {
        int ret = 0;
        RSA *rsa = NULL;
@@ -155,12 +153,10 @@ void init_ssl(void) {
        if ((access(CTDL_CER_PATH, R_OK) != 0) && (access(CTDL_CSR_PATH, R_OK) != 0)) {
                syslog(LOG_INFO, "Generating a certificate signing request.");
 
-               /*
-                * Read our key from the file.  No, we don't just keep this
-                * in memory from the above key-generation function, because
-                * there is the possibility that the key was already on disk
-                * and we didn't just generate it now.
-                */
+               // Read our key from the file.  No, we don't just keep this
+               // in memory from the above key-generation function, because
+               // there is the possibility that the key was already on disk
+               // and we didn't just generate it now.
                fp = fopen(CTDL_KEY_PATH, "r");
                if (fp) {
                        rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
@@ -168,30 +164,26 @@ void init_ssl(void) {
                }
 
                if (rsa) {
-                       /* Create a public key from the private key */
+                       // Create a public key from the private key
                        if (pk = EVP_PKEY_new(), pk != NULL) {
                                EVP_PKEY_assign_RSA(pk, rsa);
                                if (req = X509_REQ_new(), req != NULL) {
                                        const char *env;
-                                       /* Set the public key */
+                                       // Set the public key
                                        X509_REQ_set_pubkey(req, pk);
                                        X509_REQ_set_version(req, 0L);
                                        name = X509_REQ_get_subject_name(req);
-                                       X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC,
-                                                                  (unsigned char *) "Citadel Server", -1, -1, 0);
-                                       X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC,
-                                                                  (unsigned char *) "Default Certificate PLEASE CHANGE",
-                                                                  -1, -1, 0);
+                                       X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char *) "Citadel Server", -1, -1, 0);
+                                       X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, (unsigned char *) "Default Certificate PLEASE CHANGE", -1, -1, 0);
                                        X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *) "*", -1, -1, 0);
-
                                        X509_REQ_set_subject_name(req, name);
 
-                                       /* Sign the CSR */
+                                       // Sign the CSR
                                        if (!X509_REQ_sign(req, pk, EVP_md5())) {
                                                syslog(LOG_WARNING, "X509_REQ_sign(): error");
                                        }
                                        else {
-                                               /* Write it to disk. */
+                                               // Write it to disk
                                                fp = fopen(CTDL_CSR_PATH, "w");
                                                if (fp != NULL) {
                                                        chmod(CTDL_CSR_PATH, 0600);
@@ -213,22 +205,19 @@ void init_ssl(void) {
                }
        }
 
-       /*
-        * Generate a self-signed certificate if we don't have one.
-        */
+       // Generate a self-signed certificate if we don't have one.
        if (access(CTDL_CER_PATH, R_OK) != 0) {
                syslog(LOG_INFO, "Generating a self-signed certificate.");
 
-               /* Same deal as before: always read the key from disk because
-                * it may or may not have just been generated.
-                */
+               // Same deal as before: always read the key from disk because
+               // it may or may not have just been generated.
                fp = fopen(CTDL_KEY_PATH, "r");
                if (fp) {
                        rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
                        fclose(fp);
                }
 
-               /* This also holds true for the CSR. */
+               // This also holds true for the CSR
                req = NULL;
                cer = NULL;
                pk = NULL;
@@ -250,16 +239,15 @@ void init_ssl(void) {
                                        X509_set_subject_name(cer, X509_REQ_get_subject_name(req));
                                        X509_gmtime_adj(X509_get_notBefore(cer), 0);
                                        X509_gmtime_adj(X509_get_notAfter(cer), (long) 60 * 60 * 24 * SIGN_DAYS);
-
                                        req_pkey = X509_REQ_get_pubkey(req);
                                        X509_set_pubkey(cer, req_pkey);
                                        EVP_PKEY_free(req_pkey);
 
-                                       /* Sign the cert */
+                                       // Sign the cert
                                        if (!X509_sign(cer, pk, EVP_md5())) {
                                                syslog(LOG_WARNING, "X509_sign(): error");
                                        }
-                                       else {  /* Write it to disk. */
+                                       else {  // Write it to disk
                                                fp = fopen(CTDL_CER_PATH, "w");
                                                if (fp != NULL) {
                                                        chmod(CTDL_CER_PATH, 0600);
@@ -278,11 +266,9 @@ void init_ssl(void) {
                }
        }
 
-       /*
-        * Now try to bind to the key and certificate.
-        * Note that we use SSL_CTX_use_certificate_chain_file() which allows
-        * the certificate file to contain intermediate certificates.
-        */
+       // Now try to bind to the key and certificate.
+       // Note that we use SSL_CTX_use_certificate_chain_file() which allows
+       // the certificate file to contain intermediate certificates.
        SSL_CTX_use_certificate_chain_file(ssl_ctx, CTDL_CER_PATH);
        SSL_CTX_use_PrivateKey_file(ssl_ctx, CTDL_KEY_PATH, SSL_FILETYPE_PEM);
        if (!SSL_CTX_check_private_key(ssl_ctx)) {
@@ -292,9 +278,7 @@ void init_ssl(void) {
 }
 
 
-/*
- * starts SSL/TLS encryption for the current session.
- */
+// starts SSL/TLS encryption for the current session.
 void starttls(struct client_handle *ch) {
        int retval, bits, alg_bits;
 
@@ -354,9 +338,7 @@ void starttls(struct client_handle *ch) {
 }
 
 
-/*
- * shuts down the TLS connection
- */
+// shuts down the TLS connection
 void endtls(struct client_handle *ch) {
        syslog(LOG_INFO, "Ending SSL/TLS");
        if (ch->ssl_handle != NULL) {
@@ -368,9 +350,7 @@ void endtls(struct client_handle *ch) {
 }
 
 
-/*
- * Send binary data to the client encrypted.
- */
+// Send binary data to the client encrypted.
 int client_write_ssl(struct client_handle *ch, char *buf, int nbytes) {
        int retval;
        int nremain;
@@ -408,9 +388,7 @@ int client_write_ssl(struct client_handle *ch, char *buf, int nbytes) {
 }
 
 
-/*
- * read data from the encrypted layer.
- */
+// read data from the encrypted layer
 int client_read_ssl(struct client_handle *ch, char *buf, int nbytes) {
        int bytes_read = 0;
        int rlen = 0;
index bd8d3cda8efdea826dd4c0d832f2d9ae787f8e65..8b74834244a140b9ad9b75198e40431ab3d7264e 100644 (file)
@@ -23,8 +23,8 @@ void output_static(struct http_transaction *h) {
 
        snprintf(filename, sizeof filename, "static/%s", &h->uri[8]);
 
-       if (strstr(filename, "../")) {  // 100% guaranteed attacker.
-               do_404(h);      // Die in a car fire.
+       if (strstr(filename, "../")) {          // 100% guaranteed attacker.
+               do_404(h);                      // Die in a car fire.
                return;
        }
 
@@ -43,7 +43,7 @@ void output_static(struct http_transaction *h) {
        else {
                h->response_body_length = 0;
        }
-       fclose(fp);             // Content is now in memory.
+       fclose(fp);                             // Content is now in memory.
 
        h->response_code = 200;
        h->response_string = strdup("OK");
index a0519d6279650a14ee7811cb667a257bc9c677ec..5f668049f89380b7bddb0d85456c322242c5432e 100644 (file)
@@ -71,7 +71,7 @@ void object_in_user(struct http_transaction *h, struct ctdlsession *c, char *req
                return;
        }
 
-       do_404(h);                                      // unknown object
+       do_404(h);                                              // unknown object
        return;
 }
 
index 5ae5da728e5a073069e1b5eb05ab50b321eec038..17dca336c5a2c67656a8737762a58cee4f8a40a5 100644 (file)
@@ -80,8 +80,9 @@ char *http_datestring(time_t xtime) {
        char offsign;
        int n = 40;
        char *buf = malloc(n);
-       if (!buf)
+       if (!buf) {
                return (NULL);
+       }
 
        localtime_r(&xtime, &t);
 
@@ -89,7 +90,8 @@ char *http_datestring(time_t xtime) {
        offset = t.tm_gmtoff;
        if (offset > 0) {
                offsign = '+';
-       } else {
+       }
+       else {
                offset = 0L - offset;
                offsign = '-';
        }