]> code.citadel.org Git - citadel.git/blobdiff - textclient/citadel_ipc.c
Getting navigation in place for week view.
[citadel.git] / textclient / citadel_ipc.c
index 26d2fa2adba91162d70ede35d6c3599177f5e61d..c426a29e0ad0092abfbda6fed9e2b542e7015992 100644 (file)
@@ -1,12 +1,6 @@
 // Copyright (c) 1987-2022 by the citadel.org team
 //
-// This program is open source software.  Use, duplication, and/or
-// disclosure are subject to the GNU General Purpose 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 program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
 
 #include "textclient.h"
 
@@ -14,7 +8,7 @@
 static SSL_CTX *ssl_ctx;
 char arg_encrypt;
 char rc_encrypt;
-#endif                         /* HAVE_OPENSSL */
+#endif                         // HAVE_OPENSSL
 
 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff
@@ -142,7 +136,7 @@ static void serv_write(CtdlIPC * ipc, const char *buf, unsigned int nbytes);
 static void serv_read_ssl(CtdlIPC * ipc, char *buf, unsigned int bytes);
 static void serv_write_ssl(CtdlIPC * ipc, const char *buf, unsigned int nbytes);
 static void endtls(SSL * ssl);
-#endif                         /* HAVE_OPENSSL */
+#endif                         // HAVE_OPENSSL
 static void CtdlIPC_getline(CtdlIPC * ipc, char *buf);
 static void CtdlIPC_putline(CtdlIPC * ipc, const char *buf);
 
@@ -150,32 +144,29 @@ static void CtdlIPC_putline(CtdlIPC * ipc, const char *buf);
 
 const char *svn_revision(void);
 
-/*
- * Does nothing.  The server should always return 200.
- */
-int CtdlIPCNoop(CtdlIPC * ipc) {
+// Does nothing.  The server should always return 200.
+int CtdlIPCNoop(CtdlIPC *ipc) {
        char aaa[128];
-
        return CtdlIPCGenericCommand(ipc, "NOOP", NULL, 0, NULL, NULL, aaa);
 }
 
 
-/*
- * Does nothing interesting.  The server should always return 200
- * along with your string.
- */
+// Does nothing interesting.  The server should always return 200 along with your string.
 int CtdlIPCEcho(CtdlIPC * ipc, const char *arg, char *cret) {
        int ret;
        char *aaa;
 
-       if (!arg)
+       if (!arg) {
                return -2;
-       if (!cret)
+       }
+       if (!cret) {
                return -2;
+       }
 
        aaa = (char *) malloc((size_t) (strlen(arg) + 6));
-       if (!aaa)
+       if (!aaa) {
                return -1;
+       }
 
        sprintf(aaa, "ECHO %s", arg);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
@@ -184,12 +175,9 @@ int CtdlIPCEcho(CtdlIPC * ipc, const char *arg, char *cret) {
 }
 
 
-/*
- * Asks the server to close the connecction.
- * Should always return 200.
- */
+// Asks the server to close the connection.  Should always return 200.
 int CtdlIPCQuit(CtdlIPC * ipc) {
-       int ret = 221;          /* Default to successful quit */
+       int ret = 221;          // Default to successful quit
        char aaa[SIZ];
 
        CtdlIPC_lock(ipc);
@@ -199,22 +187,22 @@ int CtdlIPCQuit(CtdlIPC * ipc) {
                ret = atoi(aaa);
        }
 #ifdef HAVE_OPENSSL
-       if (ipc->ssl)
+       if (ipc->ssl) {
                SSL_shutdown(ipc->ssl);
+       }
        ipc->ssl = NULL;
 #endif
-       if (ipc->sock)
-               shutdown(ipc->sock, 2); /* Close connection; we're dead */
+       if (ipc->sock) {
+               shutdown(ipc->sock, 2);         // Close connection; we're dead.
+       }
        ipc->sock = -1;
        CtdlIPC_unlock(ipc);
        return ret;
 }
 
 
-/*
- * Asks the server to log out.  Should always return 200, even if no user
- * was logged in.  The user will not be logged in after this!
- */
+// Asks the server to log out.  Should always return 200, even if no user
+// was logged in.  The user will not be logged in after this!
 int CtdlIPCLogout(CtdlIPC * ipc) {
        int ret;
        char aaa[SIZ];
@@ -228,23 +216,24 @@ int CtdlIPCLogout(CtdlIPC * ipc) {
 }
 
 
-/*
- * First stage of authentication - pass the username.  Returns 300 if the
- * username is able to log in, with the username correctly spelled in cret.
- * Returns various 500 error codes if the user doesn't exist, etc.
- */
+// First stage of authentication - pass the username.  Returns 300 if the
+// username is able to log in, with the username correctly spelled in cret.
+// Returns various 500 error codes if the user doesn't exist, etc.
 int CtdlIPCTryLogin(CtdlIPC * ipc, const char *username, char *cret) {
        int ret;
        char *aaa;
 
-       if (!username)
+       if (!username) {
                return -2;
-       if (!cret)
+       }
+       if (!cret) {
                return -2;
+       }
 
        aaa = (char *) malloc((size_t) (strlen(username) + 6));
-       if (!aaa)
+       if (!aaa) {
                return -1;
+       }
 
        sprintf(aaa, "USER %s", username);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
@@ -253,22 +242,23 @@ int CtdlIPCTryLogin(CtdlIPC * ipc, const char *username, char *cret) {
 }
 
 
-/*
- * Second stage of authentication - provide password.  The server returns
- * 200 and several arguments in cret relating to the user's account.
- */
+// Second stage of authentication - provide password.  The server returns
+// 200 and several arguments in cret relating to the user's account.
 int CtdlIPCTryPassword(CtdlIPC * ipc, const char *passwd, char *cret) {
        int ret;
        char *aaa;
 
-       if (!passwd)
+       if (!passwd) {
                return -2;
-       if (!cret)
+       }
+       if (!cret) {
                return -2;
+       }
 
        aaa = (char *) malloc((size_t) (strlen(passwd) + 6));
-       if (!aaa)
+       if (!aaa) {
                return -1;
+       }
 
        sprintf(aaa, "PASS %s", passwd);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
@@ -277,25 +267,26 @@ int CtdlIPCTryPassword(CtdlIPC * ipc, const char *passwd, char *cret) {
 }
 
 
-/*
- * Create a new user.  This returns 200 plus the same arguments as TryPassword
- * if selfservice is nonzero, unless there was a problem creating the account.
- * If selfservice is zero, creates a new user but does not log out the existing
- * user - intended for use by system administrators to create accounts on
- * behalf of other users.
- */
+// Create a new user.  This returns 200 plus the same arguments as TryPassword
+// if selfservice is nonzero, unless there was a problem creating the account.
+// If selfservice is zero, creates a new user but does not log out the existing
+// user - intended for use by system administrators to create accounts on
+// behalf of other users.
 int CtdlIPCCreateUser(CtdlIPC * ipc, const char *username, int selfservice, char *cret) {
        int ret;
        char *aaa;
 
-       if (!username)
+       if (!username) {
                return -2;
-       if (!cret)
+       }
+       if (!cret) {
                return -2;
+       }
 
        aaa = (char *) malloc((size_t) (strlen(username) + 6));
-       if (!aaa)
+       if (!aaa) {
                return -1;
+       }
 
        sprintf(aaa, "%s %s", selfservice ? "NEWU" : "CREU", username);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
@@ -304,21 +295,22 @@ int CtdlIPCCreateUser(CtdlIPC * ipc, const char *username, int selfservice, char
 }
 
 
-/*
- * Changes the user's password.  Returns 200 if changed, errors otherwise.
- */
+// Changes the user's password.  Returns 200 if changed, errors otherwise.
 int CtdlIPCChangePassword(CtdlIPC * ipc, const char *passwd, char *cret) {
        int ret;
        char *aaa;
 
-       if (!passwd)
+       if (!passwd) {
                return -2;
-       if (!cret)
+       }
+       if (!cret) {
                return -2;
+       }
 
        aaa = (char *) malloc((size_t) (strlen(passwd) + 6));
-       if (!aaa)
+       if (!aaa) {
                return -1;
+       }
 
        sprintf(aaa, "SETP %s", passwd);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
@@ -327,13 +319,13 @@ int CtdlIPCChangePassword(CtdlIPC * ipc, const char *passwd, char *cret) {
 }
 
 
-/* LKRN */
+// LKRN
 
-/* Caller must free the march list */
+// Caller must free the march list
 
-/* Room types are defined in enum RoomList; keep these in sync! */
+// Room types are defined in enum RoomList; keep these in sync!
 
-/* floor is -1 for all, or floornum */
+// floor is -1 for all, or floornum
 int CtdlIPCKnownRooms(CtdlIPC * ipc, enum RoomList which, int floor, struct march **listing, char *cret) {
        int ret;
        struct march *march = NULL;
@@ -345,12 +337,12 @@ int CtdlIPCKnownRooms(CtdlIPC * ipc, enum RoomList which, int floor, struct marc
        if (!listing)
                return -2;
        if (*listing)
-               return -2;      /* Free the listing first */
+               return -2;      // Free the listing first
        if (!cret)
                return -2;
-       /* if (which < 0 || which > 4) return -2; */
+       // if (which < 0 || which > 4) return -2;
        if (floor < -1)
-               return -2;      /* Can't validate upper bound, sorry */
+               return -2;      // Can't validate upper bound, sorry
 
        sprintf(aaa, "%s %d", proto[which], floor);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbb_len, cret);
@@ -557,7 +549,7 @@ int CtdlIPCGetMessages(CtdlIPC * ipc, enum MessageList which, int whicharg, cons
 }
 
 
-/* MSG0, MSG2 */
+/* MSG0, MSG2, MSG4 */
 int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret) {
        int ret;
        char aaa[SIZ];
@@ -1927,8 +1919,7 @@ int CtdlIPCAideSetUserParameters(CtdlIPC * ipc, const struct ctdluser *uret, cha
                return -1;
 
        sprintf(aaa, "ASUP %s|%s|%d|0|0|%d|%ld|%ld|%d",
-               uret->fullname, uret->password, uret->flags,
-               uret->axlevel, uret->usernum, uret->lastcall, uret->USuserpurge);
+               uret->fullname, uret->password, uret->flags, uret->axlevel, uret->usernum, uret->lastcall, uret->USuserpurge);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
        free(aaa);
        return ret;
@@ -2577,10 +2568,15 @@ int CtdlIPCWriteUpload(CtdlIPC * ipc, FILE * uploadFP, void (*progress_gauge_cal
  * protocol_response as described above.  Some commands send additional
  * data in this string.
  */
-int CtdlIPCGenericCommand(CtdlIPC * ipc,
-                         const char *command,
-                         const char *to_send,
-                         size_t bytes_to_send, char **to_receive, size_t *bytes_to_receive, char *proto_response) {
+int CtdlIPCGenericCommand(
+       CtdlIPC * ipc,
+       const char *command,
+       const char *to_send,
+       size_t bytes_to_send,
+       char **to_receive,
+       size_t *bytes_to_receive,
+       char *proto_response
+) {
        char buf[SIZ];
        int ret;
 
@@ -2668,7 +2664,7 @@ int CtdlIPCGenericCommand(CtdlIPC * ipc,
                                ret = -ret;
                        }       /* else who knows?  DANGER WILL ROBINSON */
                        break;
-               case 8: /* START_CHAT_MODE */
+               case 8: /* SEND_THEN_RECV */
                        if (!strncasecmp(command, "CHAT", 4)) {
                                /* Don't call chatmode with generic! */
                                CtdlIPC_putline(ipc, "/quit");
@@ -3030,15 +3026,24 @@ static void CtdlIPC_getline(CtdlIPC * ipc, char *buf) {
                }
 
                /* If we got a long line, discard characters until the newline. */
-               if (i == (SIZ - 1))
-                       while (buf[i] != '\n')
+               if (i == (SIZ - 1)) {
+
+
+                       abort();
+
+
+                       while (buf[i] != '\n') {
                                serv_read(ipc, &buf[i], 1);
+                       }
+               }
 
                /* Strip the trailing newline (and carriage return, if present) */
-               if (i >= 0 && buf[i] == 10)
+               if (i >= 0 && buf[i] == 10) {
                        buf[i--] = 0;
-               if (i >= 0 && buf[i] == 13)
+               }
+               if (i >= 0 && buf[i] == 13) {
                        buf[i--] = 0;
+               }
        }
        else
 #endif