X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=textclient%2Fcitadel_ipc.c;h=5f3656e7ba47ca657d3ca09d476761a6ecb8f10d;hb=HEAD;hp=e5788ad4c6b5152e25ca7f4b09d9c718b9cb6724;hpb=8b537f8d15f353c4a1a97d18bf2aef0a045e6b29;p=citadel.git diff --git a/textclient/citadel_ipc.c b/textclient/citadel_ipc.c index e5788ad4c..c426a29e0 100644 --- a/textclient/citadel_ipc.c +++ b/textclient/citadel_ipc.c @@ -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); @@ -488,11 +480,11 @@ int CtdlIPCGotoRoom(CtdlIPC * ipc, const char *room, const char *passwd, struct rret[0]->RRlastread = extract_long(cret, 6); rret[0]->RRismailbox = extract_int(cret, 7); rret[0]->RRaide = extract_int(cret, 8); - rret[0]->RRnewmail = extract_long(cret, 9); + // position 9 is no longer used rret[0]->RRfloor = extract_int(cret, 10); rret[0]->RRcurrentview = extract_int(cret, 11); rret[0]->RRdefaultview = extract_int(cret, 12); - /* position 13 is a trash folder flag ... irrelevant in this client */ + // position 13 is a trash folder flag ... irrelevant in this client rret[0]->RRflags2 = extract_int(cret, 14); } else { @@ -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]; @@ -671,7 +663,7 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime if (!strncasecmp(bbb, "Content-type:", 13)) { extract_token(mret[0]->content_type, bbb, 0, '\n', sizeof mret[0]->content_type); strcpy(mret[0]->content_type, &mret[0]->content_type[13]); - striplt(mret[0]->content_type); + string_trim(mret[0]->content_type); /* strip out ";charset=" portion. FIXME do something with * the charset (like... convert it) instead of just throwing @@ -685,12 +677,12 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime if (!strncasecmp(bbb, "X-Citadel-MSG4-Partnum:", 23)) { extract_token(mret[0]->mime_chosen, bbb, 0, '\n', sizeof mret[0]->mime_chosen); strcpy(mret[0]->mime_chosen, &mret[0]->mime_chosen[23]); - striplt(mret[0]->mime_chosen); + string_trim(mret[0]->mime_chosen); } if (!strncasecmp(bbb, "Content-transfer-encoding:", 26)) { extract_token(encoding, bbb, 0, '\n', sizeof encoding); strcpy(encoding, &encoding[26]); - striplt(encoding); + string_trim(encoding); } remove_token(bbb, 0, '\n'); } while ((bbb[0] != 0) && (bbb[0] != '\n')); @@ -1672,7 +1664,7 @@ int CtdlIPCIdentifySoftware(CtdlIPC * ipc, int developerid, int clientid, developerid = 8; clientid = 0; revision = CLIENT_VERSION - 600; - software_name = "Citadel (libcitadel)"; + software_name = "Citadel text client"; } if (!hostname) return -2; @@ -1903,8 +1895,6 @@ int CtdlIPCAideGetUserParameters(CtdlIPC * ipc, const char *who, struct ctdluser extract_token(uret[0]->fullname, cret, 0, '|', sizeof uret[0]->fullname); extract_token(uret[0]->password, cret, 1, '|', sizeof uret[0]->password); uret[0]->flags = extract_int(cret, 2); - uret[0]->timescalled = extract_long(cret, 3); - uret[0]->posted = extract_long(cret, 4); uret[0]->axlevel = extract_int(cret, 5); uret[0]->usernum = extract_long(cret, 6); uret[0]->lastcall = extract_long(cret, 7); @@ -1928,9 +1918,8 @@ int CtdlIPCAideSetUserParameters(CtdlIPC * ipc, const struct ctdluser *uret, cha if (!aaa) return -1; - sprintf(aaa, "ASUP %s|%s|%d|%ld|%ld|%d|%ld|%ld|%d", - uret->fullname, uret->password, uret->flags, uret->timescalled, - uret->posted, uret->axlevel, uret->usernum, uret->lastcall, uret->USuserpurge); + 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); ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; @@ -2579,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; @@ -2670,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"); @@ -3032,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