X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=textclient%2Fcitadel_ipc.c;h=f810edf001b4bec57052946659a45637787e25a9;hb=HEAD;hp=52859d65d52260bf6d4b99ac47963048ba2ef5fb;hpb=b54b3da07ed61e85c054f12a989f752507f7a6cd;p=citadel.git diff --git a/textclient/citadel_ipc.c b/textclient/citadel_ipc.c index 52859d65d..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,13 +8,13 @@ static SSL_CTX *ssl_ctx; char arg_encrypt; char rc_encrypt; -#endif /* HAVE_OPENSSL */ +#endif // HAVE_OPENSSL #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif -static void (*status_hook) (char *s) = NULL; +static void (*status_hook)(char *s) = NULL; char ctdl_autoetc_dir[PATH_MAX] = ""; char file_citadel_rc[PATH_MAX] = ""; char ctdl_run_dir[PATH_MAX] = ""; @@ -124,11 +118,11 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, i DBG_PRINT(file_citadel_rc); } -void setCryptoStatusHook(void (*hook) (char *s)) { +void setCryptoStatusHook(void (*hook)(char *s)) { status_hook = hook; } -void CtdlIPC_SetNetworkStatusCallback(CtdlIPC * ipc, void (*hook) (int state)) { +void CtdlIPC_SetNetworkStatusCallback(CtdlIPC * ipc, void (*hook)(int state)) { ipc->network_status_cb = hook; } @@ -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,34 +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. - */ -int CtdlIPCEcho(CtdlIPC * ipc, const char *arg, char *cret) -{ +// 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); @@ -186,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); @@ -201,24 +187,23 @@ 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! - */ -int CtdlIPCLogout(CtdlIPC * ipc) -{ +// 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]; @@ -231,24 +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. - */ -int CtdlIPCTryLogin(CtdlIPC * ipc, const char *username, char *cret) -{ +// 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); @@ -257,23 +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. - */ -int CtdlIPCTryPassword(CtdlIPC * ipc, const char *passwd, char *cret) -{ +// 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); @@ -282,51 +267,26 @@ int CtdlIPCTryPassword(CtdlIPC * ipc, const char *passwd, char *cret) } -/* - * Second stage of authentication - provide password. The server returns - * 200 and several arguments in cret relating to the user's account. - */ -int CtdlIPCTryApopPassword(CtdlIPC * ipc, const char *response, char *cret) -{ - int ret; - char *aaa; - - if (!response) - return -2; - if (!cret) - return -2; - - aaa = (char *) malloc((size_t) (strlen(response) + 6)); - if (!aaa) - return -1; - - sprintf(aaa, "PAS2 %s", response); - ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); - free(aaa); - return ret; -} - - -/* - * 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) -{ +// 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); @@ -335,22 +295,22 @@ int CtdlIPCCreateUser(CtdlIPC * ipc, const char *username, int selfservice, char } -/* - * Changes the user's password. Returns 200 if changed, errors otherwise. - */ -int CtdlIPCChangePassword(CtdlIPC * ipc, const char *passwd, char *cret) -{ +// 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); @@ -359,12 +319,14 @@ int CtdlIPCChangePassword(CtdlIPC * ipc, const char *passwd, char *cret) } -/* LKRN */ -/* Caller must free the march list */ -/* Room types are defined in enum RoomList; keep these in sync! */ -/* floor is -1 for all, or floornum */ -int CtdlIPCKnownRooms(CtdlIPC * ipc, enum RoomList which, int floor, struct march **listing, char *cret) -{ +// LKRN + +// Caller must free the march list + +// Room types are defined in enum RoomList; keep these in sync! + +// 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; static char *proto[] = { "LKRA", "LKRN", "LKRO", "LZRM", "LRMS", "LPRM" }; @@ -375,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); @@ -423,9 +385,9 @@ int CtdlIPCKnownRooms(CtdlIPC * ipc, enum RoomList which, int floor, struct marc /* GETU */ + /* Caller must free the struct ctdluser; caller may pass an existing one */ -int CtdlIPCGetConfig(CtdlIPC * ipc, struct ctdluser **uret, char *cret) -{ +int CtdlIPCGetConfig(CtdlIPC * ipc, struct ctdluser **uret, char *cret) { int ret; if (!cret) @@ -446,8 +408,7 @@ int CtdlIPCGetConfig(CtdlIPC * ipc, struct ctdluser **uret, char *cret) /* SETU */ -int CtdlIPCSetConfig(CtdlIPC * ipc, struct ctdluser *uret, char *cret) -{ +int CtdlIPCSetConfig(CtdlIPC * ipc, struct ctdluser *uret, char *cret) { char aaa[48]; if (!uret) @@ -461,8 +422,7 @@ int CtdlIPCSetConfig(CtdlIPC * ipc, struct ctdluser *uret, char *cret) /* RENU */ -int CtdlIPCRenameUser(CtdlIPC * ipc, char *oldname, char *newname, char *cret) -{ +int CtdlIPCRenameUser(CtdlIPC * ipc, char *oldname, char *newname, char *cret) { int ret; char cmd[256]; @@ -480,8 +440,7 @@ int CtdlIPCRenameUser(CtdlIPC * ipc, char *oldname, char *newname, char *cret) /* GOTO */ -int CtdlIPCGotoRoom(CtdlIPC * ipc, const char *room, const char *passwd, struct ctdlipcroom **rret, char *cret) -{ +int CtdlIPCGotoRoom(CtdlIPC * ipc, const char *room, const char *passwd, struct ctdlipcroom **rret, char *cret) { int ret; char *aaa; @@ -501,7 +460,8 @@ int CtdlIPCGotoRoom(CtdlIPC * ipc, const char *room, const char *passwd, struct return -1; } sprintf(aaa, "GOTO %s|%s", room, passwd); - } else { + } + else { aaa = (char *) malloc(strlen(room) + 6); if (!aaa) { free(*rret); @@ -520,13 +480,14 @@ 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 { + } + else { free(*rret); *rret = NULL; } @@ -536,10 +497,11 @@ int CtdlIPCGotoRoom(CtdlIPC * ipc, const char *room, const char *passwd, struct /* MSGS */ + /* which is 0 = all, 1 = old, 2 = new, 3 = last, 4 = first, 5 = gt, 6 = lt */ + /* whicharg is number of messages, applies to last, first, gt, lt */ -int CtdlIPCGetMessages(CtdlIPC * ipc, enum MessageList which, int whicharg, const char *mtemplate, unsigned long **mret, char *cret) -{ +int CtdlIPCGetMessages(CtdlIPC * ipc, enum MessageList which, int whicharg, const char *mtemplate, unsigned long **mret, char *cret) { int ret; unsigned long count = 0; static char *proto[] = { "ALL", "OLD", "NEW", "LAST", "FIRST", "GT", "LT" }; @@ -576,7 +538,8 @@ int CtdlIPCGetMessages(CtdlIPC * ipc, enum MessageList which, int whicharg, cons if (*mret) { (*mret)[count++] = atol(aaa); (*mret)[count] = 0L; - } else { + } + else { break; } } @@ -586,9 +549,8 @@ int CtdlIPCGetMessages(CtdlIPC * ipc, enum MessageList which, int whicharg, cons } -/* MSG0, MSG2 */ -int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret) -{ +/* MSG0, MSG2, MSG4 */ +int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret) { int ret; char aaa[SIZ]; char *bbb = NULL; @@ -651,7 +613,8 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime if (!strcasecmp(multipart_prefix, "multipart/alternative")) { ++multipart_hunting; } - } else if (!strncasecmp(aaa, "suff=", 5)) { + } + else if (!strncasecmp(aaa, "suff=", 5)) { extract_token(multipart_prefix, &aaa[5], 1, '|', sizeof multipart_prefix); if (!strcasecmp(multipart_prefix, "multipart/alternative")) { ++multipart_hunting; @@ -700,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 @@ -714,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')); @@ -736,7 +699,8 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime ccc = malloc(strlen(bbb) + 32768); if (!strcasecmp(encoding, "base64")) { bytes_decoded = CtdlDecodeBase64(ccc, bbb, strlen(bbb)); - } else if (!strcasecmp(encoding, "quoted-printable")) { + } + else if (!strcasecmp(encoding, "quoted-printable")) { bytes_decoded = CtdlDecodeQuotedPrintable(ccc, bbb, strlen(bbb)); } ccc[bytes_decoded] = 0; @@ -747,7 +711,8 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime /* FIXME: Strip trailing whitespace */ bbb = (char *) realloc(bbb, (size_t) (strlen(bbb) + 1)); - } else { + } + else { bbb = (char *) realloc(bbb, 1); *bbb = '\0'; } @@ -758,8 +723,7 @@ int CtdlIPCGetSingleMessage(CtdlIPC * ipc, long msgnum, int headers, int as_mime /* WHOK */ -int CtdlIPCWhoKnowsRoom(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCWhoKnowsRoom(CtdlIPC * ipc, char **listing, char *cret) { int ret; size_t bytes; @@ -776,8 +740,7 @@ int CtdlIPCWhoKnowsRoom(CtdlIPC * ipc, char **listing, char *cret) /* INFO */ -int CtdlIPCServerInfo(CtdlIPC * ipc, char *cret) -{ +int CtdlIPCServerInfo(CtdlIPC * ipc, char *cret) { int ret; size_t bytes; char *listing = NULL; @@ -865,8 +828,7 @@ int CtdlIPCServerInfo(CtdlIPC * ipc, char *cret) /* RDIR */ -int CtdlIPCReadDirectory(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCReadDirectory(CtdlIPC * ipc, char **listing, char *cret) { int ret; size_t bytes; @@ -885,8 +847,7 @@ int CtdlIPCReadDirectory(CtdlIPC * ipc, char **listing, char *cret) /* * Set last-read pointer in this room to msgnum, or 0 for HIGHEST. */ -int CtdlIPCSetLastRead(CtdlIPC * ipc, long msgnum, char *cret) -{ +int CtdlIPCSetLastRead(CtdlIPC * ipc, long msgnum, char *cret) { int ret; char aaa[64]; @@ -895,7 +856,8 @@ int CtdlIPCSetLastRead(CtdlIPC * ipc, long msgnum, char *cret) if (msgnum) { sprintf(aaa, "SLRP %ld", msgnum); - } else { + } + else { sprintf(aaa, "SLRP HIGHEST"); } ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); @@ -904,8 +866,7 @@ int CtdlIPCSetLastRead(CtdlIPC * ipc, long msgnum, char *cret) /* INVT */ -int CtdlIPCInviteUserToRoom(CtdlIPC * ipc, const char *username, char *cret) -{ +int CtdlIPCInviteUserToRoom(CtdlIPC * ipc, const char *username, char *cret) { int ret; char *aaa; @@ -926,8 +887,7 @@ int CtdlIPCInviteUserToRoom(CtdlIPC * ipc, const char *username, char *cret) /* KICK */ -int CtdlIPCKickoutUserFromRoom(CtdlIPC * ipc, const char *username, char *cret) -{ +int CtdlIPCKickoutUserFromRoom(CtdlIPC * ipc, const char *username, char *cret) { int ret; char *aaa; @@ -946,8 +906,7 @@ int CtdlIPCKickoutUserFromRoom(CtdlIPC * ipc, const char *username, char *cret) /* GETR */ -int CtdlIPCGetRoomAttributes(CtdlIPC * ipc, struct ctdlroom **qret, char *cret) -{ +int CtdlIPCGetRoomAttributes(CtdlIPC * ipc, struct ctdlroom **qret, char *cret) { int ret; if (!cret) @@ -975,11 +934,8 @@ int CtdlIPCGetRoomAttributes(CtdlIPC * ipc, struct ctdlroom **qret, char *cret) /* SETR */ -int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, - int forget, // if nonzero, kick all users out of the room - struct ctdlroom *qret, - char *cret -) { +int CtdlIPCSetRoomAttributes(CtdlIPC * ipc, int forget, // if nonzero, kick all users out of the room + struct ctdlroom *qret, char *cret) { int ret; char *cmd; @@ -1002,8 +958,7 @@ int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, /* GETA */ -int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret) -{ +int CtdlIPCGetRoomAide(CtdlIPC * ipc, char *cret) { if (!cret) return -1; @@ -1012,7 +967,7 @@ int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret) /* SETA */ -int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret) { +int CtdlIPCSetRoomAide(CtdlIPC * ipc, const char *username, char *cret) { int ret; char *aaa; @@ -1033,8 +988,7 @@ int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret) { /* ENT0 */ -int CtdlIPCPostMessage(CtdlIPC * ipc, int flag, int *subject_required, struct ctdlipcmessage *mr, char *cret) -{ +int CtdlIPCPostMessage(CtdlIPC * ipc, int flag, int *subject_required, struct ctdlipcmessage *mr, char *cret) { int ret; char cmd[SIZ]; char *ptr; @@ -1132,8 +1086,7 @@ int CtdlIPCDeleteRoom(CtdlIPC * ipc, int for_real, char *cret) { /* CRE8 */ -int CtdlIPCCreateRoom(CtdlIPC * ipc, int for_real, const char *roomname, int type, const char *password, int floor, char *cret) -{ +int CtdlIPCCreateRoom(CtdlIPC * ipc, int for_real, const char *roomname, int type, const char *password, int floor, char *cret) { int ret; char *aaa; @@ -1196,7 +1149,7 @@ int CtdlIPCSystemMessage(CtdlIPC * ipc, const char *message, char **mret, char * /* GNUR */ -int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret) { +int CtdlIPCNextUnvalidatedUser(CtdlIPC * ipc, char *cret) { if (!cret) return -2; @@ -1258,8 +1211,7 @@ int CtdlIPCValidateUser(CtdlIPC * ipc, const char *username, int axlevel, char * /* EINF */ -int CtdlIPCSetRoomInfo(CtdlIPC * ipc, int for_real, const char *info, char *cret) -{ +int CtdlIPCSetRoomInfo(CtdlIPC * ipc, int for_real, const char *info, char *cret) { char aaa[64]; if (!cret) @@ -1273,8 +1225,7 @@ int CtdlIPCSetRoomInfo(CtdlIPC * ipc, int for_real, const char *info, char *cret /* LIST */ -int CtdlIPCUserListing(CtdlIPC * ipc, char *searchstring, char **listing, char *cret) -{ +int CtdlIPCUserListing(CtdlIPC * ipc, char *searchstring, char **listing, char *cret) { size_t bytes; char *cmd; int ret; @@ -1298,8 +1249,7 @@ int CtdlIPCUserListing(CtdlIPC * ipc, char *searchstring, char **listing, char * /* REGI */ -int CtdlIPCSetRegistration(CtdlIPC * ipc, const char *info, char *cret) -{ +int CtdlIPCSetRegistration(CtdlIPC * ipc, const char *info, char *cret) { if (!cret) return -1; if (!info) @@ -1310,8 +1260,7 @@ int CtdlIPCSetRegistration(CtdlIPC * ipc, const char *info, char *cret) /* CHEK */ -int CtdlIPCMiscCheck(CtdlIPC * ipc, struct ctdlipcmisc *chek, char *cret) -{ +int CtdlIPCMiscCheck(CtdlIPC * ipc, struct ctdlipcmisc *chek, char *cret) { int ret; if (!cret) @@ -1330,8 +1279,7 @@ int CtdlIPCMiscCheck(CtdlIPC * ipc, struct ctdlipcmisc *chek, char *cret) /* DELF */ -int CtdlIPCDeleteFile(CtdlIPC * ipc, const char *filename, char *cret) -{ +int CtdlIPCDeleteFile(CtdlIPC * ipc, const char *filename, char *cret) { int ret; char *aaa; @@ -1352,8 +1300,7 @@ int CtdlIPCDeleteFile(CtdlIPC * ipc, const char *filename, char *cret) /* MOVF */ -int CtdlIPCMoveFile(CtdlIPC * ipc, const char *filename, const char *destroom, char *cret) -{ +int CtdlIPCMoveFile(CtdlIPC * ipc, const char *filename, const char *destroom, char *cret) { int ret; char *aaa; @@ -1376,8 +1323,7 @@ int CtdlIPCMoveFile(CtdlIPC * ipc, const char *filename, const char *destroom, c /* RWHO */ -int CtdlIPCOnlineUsers(CtdlIPC * ipc, char **listing, time_t * stamp, char *cret) -{ +int CtdlIPCOnlineUsers(CtdlIPC * ipc, char **listing, time_t * stamp, char *cret) { int ret; size_t bytes; @@ -1398,8 +1344,7 @@ int CtdlIPCOnlineUsers(CtdlIPC * ipc, char **listing, time_t * stamp, char *cret /* OPEN */ int CtdlIPCFileDownload(CtdlIPC * ipc, const char *filename, void **buf, size_t resume, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret; size_t bytes; time_t last_mod; @@ -1440,8 +1385,7 @@ int CtdlIPCFileDownload(CtdlIPC * ipc, const char *filename, void **buf, size_t /* OPNA */ int CtdlIPCAttachmentDownload(CtdlIPC * ipc, long msgnum, const char *part, void **buf, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret; size_t bytes; time_t last_mod; @@ -1482,8 +1426,7 @@ int CtdlIPCAttachmentDownload(CtdlIPC * ipc, long msgnum, const char *part, void /* OIMG */ int CtdlIPCImageDownload(CtdlIPC * ipc, const char *filename, void **buf, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret; size_t bytes; time_t last_mod; @@ -1513,6 +1456,7 @@ int CtdlIPCImageDownload(CtdlIPC * ipc, const char *filename, void **buf, void ( bytes = extract_long(cret, 0); last_mod = extract_int(cret, 1); extract_token(mimetype, cret, 2, '|', sizeof mimetype); + /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */ ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); ret = CtdlIPCEndDownload(ipc, cret); @@ -1525,8 +1469,7 @@ int CtdlIPCImageDownload(CtdlIPC * ipc, const char *filename, void **buf, void ( /* UOPN */ int CtdlIPCFileUpload(CtdlIPC * ipc, const char *save_as, const char *comment, const char *path, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret; char *aaa; FILE *uploadFP; @@ -1576,8 +1519,7 @@ int CtdlIPCFileUpload(CtdlIPC * ipc, const char *save_as, const char *comment, c /* UIMG */ int CtdlIPCImageUpload(CtdlIPC * ipc, int for_real, const char *path, const char *save_as, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret; FILE *uploadFP; char *aaa; @@ -1624,8 +1566,7 @@ int CtdlIPCImageUpload(CtdlIPC * ipc, int for_real, const char *path, const char /* QUSR */ -int CtdlIPCQueryUsername(CtdlIPC * ipc, const char *username, char *cret) -{ +int CtdlIPCQueryUsername(CtdlIPC * ipc, const char *username, char *cret) { int ret; char *aaa; @@ -1646,8 +1587,7 @@ int CtdlIPCQueryUsername(CtdlIPC * ipc, const char *username, char *cret) /* LFLR */ -int CtdlIPCFloorListing(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCFloorListing(CtdlIPC * ipc, char **listing, char *cret) { size_t bytes; if (!cret) @@ -1662,8 +1602,7 @@ int CtdlIPCFloorListing(CtdlIPC * ipc, char **listing, char *cret) /* CFLR */ -int CtdlIPCCreateFloor(CtdlIPC * ipc, int for_real, const char *name, char *cret) -{ +int CtdlIPCCreateFloor(CtdlIPC * ipc, int for_real, const char *name, char *cret) { int ret; char aaa[SIZ]; @@ -1679,8 +1618,7 @@ int CtdlIPCCreateFloor(CtdlIPC * ipc, int for_real, const char *name, char *cret /* KFLR */ -int CtdlIPCDeleteFloor(CtdlIPC * ipc, int for_real, int floornum, char *cret) -{ +int CtdlIPCDeleteFloor(CtdlIPC * ipc, int for_real, int floornum, char *cret) { char aaa[SIZ]; if (!cret) @@ -1694,8 +1632,7 @@ int CtdlIPCDeleteFloor(CtdlIPC * ipc, int for_real, int floornum, char *cret) /* EFLR */ -int CtdlIPCEditFloor(CtdlIPC * ipc, int floornum, const char *floorname, char *cret) -{ +int CtdlIPCEditFloor(CtdlIPC * ipc, int floornum, const char *floorname, char *cret) { int ret; char aaa[SIZ]; @@ -1719,8 +1656,7 @@ int CtdlIPCEditFloor(CtdlIPC * ipc, int floornum, const char *floorname, char *c * other fields are not set properly. */ int CtdlIPCIdentifySoftware(CtdlIPC * ipc, int developerid, int clientid, - int revision, const char *software_name, const char *hostname, char *cret) -{ + int revision, const char *software_name, const char *hostname, char *cret) { int ret; char *aaa; @@ -1728,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; @@ -1745,8 +1681,7 @@ int CtdlIPCIdentifySoftware(CtdlIPC * ipc, int developerid, int clientid, /* SEXP */ -int CtdlIPCSendInstantMessage(CtdlIPC * ipc, const char *username, const char *text, char *cret) -{ +int CtdlIPCSendInstantMessage(CtdlIPC * ipc, const char *username, const char *text, char *cret) { int ret; char *aaa; @@ -1762,7 +1697,8 @@ int CtdlIPCSendInstantMessage(CtdlIPC * ipc, const char *username, const char *t if (text) { sprintf(aaa, "SEXP %s|-", username); ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret); - } else { + } + else { sprintf(aaa, "SEXP %s||", username); ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } @@ -1772,8 +1708,7 @@ int CtdlIPCSendInstantMessage(CtdlIPC * ipc, const char *username, const char *t /* GEXP */ -int CtdlIPCGetInstantMessage(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCGetInstantMessage(CtdlIPC * ipc, char **listing, char *cret) { size_t bytes; if (!cret) @@ -1788,9 +1723,9 @@ int CtdlIPCGetInstantMessage(CtdlIPC * ipc, char **listing, char *cret) /* DEXP */ + /* mode is 0 = enable, 1 = disable, 2 = status */ -int CtdlIPCEnableInstantMessageReceipt(CtdlIPC * ipc, int mode, char *cret) -{ +int CtdlIPCEnableInstantMessageReceipt(CtdlIPC * ipc, int mode, char *cret) { char aaa[64]; if (!cret) @@ -1802,8 +1737,7 @@ int CtdlIPCEnableInstantMessageReceipt(CtdlIPC * ipc, int mode, char *cret) /* EBIO */ -int CtdlIPCSetBio(CtdlIPC * ipc, char *bio, char *cret) -{ +int CtdlIPCSetBio(CtdlIPC * ipc, char *bio, char *cret) { if (!cret) return -2; if (!bio) @@ -1814,8 +1748,7 @@ int CtdlIPCSetBio(CtdlIPC * ipc, char *bio, char *cret) /* RBIO */ -int CtdlIPCGetBio(CtdlIPC * ipc, const char *username, char **listing, char *cret) -{ +int CtdlIPCGetBio(CtdlIPC * ipc, const char *username, char **listing, char *cret) { int ret; size_t bytes; char *aaa; @@ -1841,8 +1774,7 @@ int CtdlIPCGetBio(CtdlIPC * ipc, const char *username, char **listing, char *cre /* LBIO */ -int CtdlIPCListUsersWithBios(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCListUsersWithBios(CtdlIPC * ipc, char **listing, char *cret) { size_t bytes; if (!cret) @@ -1857,8 +1789,7 @@ int CtdlIPCListUsersWithBios(CtdlIPC * ipc, char **listing, char *cret) /* STEL */ -int CtdlIPCStealthMode(CtdlIPC * ipc, int mode, char *cret) -{ +int CtdlIPCStealthMode(CtdlIPC * ipc, int mode, char *cret) { char aaa[64]; if (!cret) @@ -1870,8 +1801,7 @@ int CtdlIPCStealthMode(CtdlIPC * ipc, int mode, char *cret) /* TERM */ -int CtdlIPCTerminateSession(CtdlIPC * ipc, int sid, char *cret) -{ +int CtdlIPCTerminateSession(CtdlIPC * ipc, int sid, char *cret) { char aaa[64]; if (!cret) @@ -1883,8 +1813,7 @@ int CtdlIPCTerminateSession(CtdlIPC * ipc, int sid, char *cret) /* DOWN */ -int CtdlIPCTerminateServerNow(CtdlIPC * ipc, char *cret) -{ +int CtdlIPCTerminateServerNow(CtdlIPC * ipc, char *cret) { if (!cret) return -1; @@ -1893,8 +1822,7 @@ int CtdlIPCTerminateServerNow(CtdlIPC * ipc, char *cret) /* SCDN */ -int CtdlIPCTerminateServerScheduled(CtdlIPC * ipc, int mode, char *cret) -{ +int CtdlIPCTerminateServerScheduled(CtdlIPC * ipc, int mode, char *cret) { char aaa[16]; if (!cret) @@ -1906,8 +1834,7 @@ int CtdlIPCTerminateServerScheduled(CtdlIPC * ipc, int mode, char *cret) /* EMSG */ -int CtdlIPCEnterSystemMessage(CtdlIPC * ipc, const char *filename, const char *text, char *cret) -{ +int CtdlIPCEnterSystemMessage(CtdlIPC * ipc, const char *filename, const char *text, char *cret) { int ret; char *aaa; @@ -1930,16 +1857,17 @@ int CtdlIPCEnterSystemMessage(CtdlIPC * ipc, const char *filename, const char *t /* TIME */ + /* This function returns the actual server time reported, or 0 if error */ -time_t CtdlIPCServerTime(CtdlIPC * ipc, char *cret) -{ +time_t CtdlIPCServerTime(CtdlIPC * ipc, char *cret) { time_t tret; int ret; ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { tret = extract_long(cret, 0); - } else { + } + else { tret = 0L; } return tret; @@ -1947,8 +1875,7 @@ time_t CtdlIPCServerTime(CtdlIPC * ipc, char *cret) /* AGUP */ -int CtdlIPCAideGetUserParameters(CtdlIPC * ipc, const char *who, struct ctdluser **uret, char *cret) -{ +int CtdlIPCAideGetUserParameters(CtdlIPC * ipc, const char *who, struct ctdluser **uret, char *cret) { int ret; char aaa[SIZ]; @@ -1968,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); @@ -1980,8 +1905,7 @@ int CtdlIPCAideGetUserParameters(CtdlIPC * ipc, const char *who, struct ctdluser /* ASUP */ -int CtdlIPCAideSetUserParameters(CtdlIPC * ipc, const struct ctdluser *uret, char *cret) -{ +int CtdlIPCAideSetUserParameters(CtdlIPC * ipc, const struct ctdluser *uret, char *cret) { int ret; char *aaa; @@ -1994,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; @@ -2004,8 +1927,7 @@ int CtdlIPCAideSetUserParameters(CtdlIPC * ipc, const struct ctdluser *uret, cha /* AGEA */ -int CtdlIPCAideGetEmailAddresses(CtdlIPC * ipc, const char *who, char *target_buf, char *cret) -{ +int CtdlIPCAideGetEmailAddresses(CtdlIPC * ipc, const char *who, char *target_buf, char *cret) { int ret; char aaa[SIZ]; char *emailaddrs = NULL; @@ -2027,8 +1949,7 @@ int CtdlIPCAideGetEmailAddresses(CtdlIPC * ipc, const char *who, char *target_bu /* ASEA */ -int CtdlIPCAideSetEmailAddresses(CtdlIPC * ipc, const char *who, char *emailaddrs, char *cret) -{ +int CtdlIPCAideSetEmailAddresses(CtdlIPC * ipc, const char *who, char *emailaddrs, char *cret) { char aaa[SIZ]; int ret; @@ -2046,10 +1967,11 @@ int CtdlIPCAideSetEmailAddresses(CtdlIPC * ipc, const char *who, char *emailaddr /* GPEX */ + /* which is 0 = room, 1 = floor, 2 = site, 3 = default for mailboxes */ + /* caller must free the struct ExpirePolicy */ -int CtdlIPCGetMessageExpirationPolicy(CtdlIPC * ipc, GPEXWhichPolicy which, struct ExpirePolicy **policy, char *cret) -{ +int CtdlIPCGetMessageExpirationPolicy(CtdlIPC * ipc, GPEXWhichPolicy which, struct ExpirePolicy **policy, char *cret) { static char *proto[] = { strof(roompolicy), strof(floorpolicy), @@ -2081,10 +2003,11 @@ int CtdlIPCGetMessageExpirationPolicy(CtdlIPC * ipc, GPEXWhichPolicy which, stru /* SPEX */ + /* which is 0 = room, 1 = floor, 2 = site, 3 = default for mailboxes */ + /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */ -int CtdlIPCSetMessageExpirationPolicy(CtdlIPC * ipc, int which, struct ExpirePolicy *policy, char *cret) -{ +int CtdlIPCSetMessageExpirationPolicy(CtdlIPC * ipc, int which, struct ExpirePolicy *policy, char *cret) { char aaa[38]; char *whichvals[] = { "room", "floor", "site", "mailboxes" }; @@ -2105,8 +2028,7 @@ int CtdlIPCSetMessageExpirationPolicy(CtdlIPC * ipc, int which, struct ExpirePol /* CONF GET */ -int CtdlIPCGetSystemConfig(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCGetSystemConfig(CtdlIPC * ipc, char **listing, char *cret) { size_t bytes; if (!cret) @@ -2121,8 +2043,7 @@ int CtdlIPCGetSystemConfig(CtdlIPC * ipc, char **listing, char *cret) /* CONF SET */ -int CtdlIPCSetSystemConfig(CtdlIPC * ipc, const char *listing, char *cret) -{ +int CtdlIPCSetSystemConfig(CtdlIPC * ipc, const char *listing, char *cret) { if (!cret) return -2; if (!listing) @@ -2133,8 +2054,7 @@ int CtdlIPCSetSystemConfig(CtdlIPC * ipc, const char *listing, char *cret) /* CONF GETSYS */ -int CtdlIPCGetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, char **listing, char *cret) -{ +int CtdlIPCGetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, char **listing, char *cret) { int ret; char *aaa; size_t bytes; @@ -2159,8 +2079,7 @@ int CtdlIPCGetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, char **lis /* CONF PUTSYS */ -int CtdlIPCSetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, const char *listing, char *cret) -{ +int CtdlIPCSetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, const char *listing, char *cret) { int ret; char *aaa; @@ -2182,8 +2101,7 @@ int CtdlIPCSetSystemConfigByType(CtdlIPC * ipc, const char *mimetype, const char /* GNET */ -int CtdlIPCGetRoomNetworkConfig(CtdlIPC * ipc, char **listing, char *cret) -{ +int CtdlIPCGetRoomNetworkConfig(CtdlIPC * ipc, char **listing, char *cret) { size_t bytes; if (!cret) @@ -2198,8 +2116,7 @@ int CtdlIPCGetRoomNetworkConfig(CtdlIPC * ipc, char **listing, char *cret) /* SNET */ -int CtdlIPCSetRoomNetworkConfig(CtdlIPC * ipc, const char *listing, char *cret) -{ +int CtdlIPCSetRoomNetworkConfig(CtdlIPC * ipc, const char *listing, char *cret) { if (!cret) return -2; if (!listing) @@ -2210,8 +2127,7 @@ int CtdlIPCSetRoomNetworkConfig(CtdlIPC * ipc, const char *listing, char *cret) /* REQT */ -int CtdlIPCRequestClientLogout(CtdlIPC * ipc, int session, char *cret) -{ +int CtdlIPCRequestClientLogout(CtdlIPC * ipc, int session, char *cret) { char aaa[64]; if (!cret) @@ -2225,8 +2141,7 @@ int CtdlIPCRequestClientLogout(CtdlIPC * ipc, int session, char *cret) /* SEEN */ -int CtdlIPCSetMessageSeen(CtdlIPC * ipc, long msgnum, int seen, char *cret) -{ +int CtdlIPCSetMessageSeen(CtdlIPC * ipc, long msgnum, int seen, char *cret) { char aaa[27]; if (!cret) @@ -2240,8 +2155,7 @@ int CtdlIPCSetMessageSeen(CtdlIPC * ipc, long msgnum, int seen, char *cret) /* STLS */ -int CtdlIPCStartEncryption(CtdlIPC * ipc, char *cret) -{ +int CtdlIPCStartEncryption(CtdlIPC * ipc, char *cret) { int a; int r; char buf[SIZ]; @@ -2297,8 +2211,7 @@ int CtdlIPCStartEncryption(CtdlIPC * ipc, char *cret) #ifdef HAVE_OPENSSL -static void endtls(SSL * ssl) -{ +static void endtls(SSL * ssl) { if (ssl) { SSL_shutdown(ssl); SSL_free(ssl); @@ -2308,8 +2221,7 @@ static void endtls(SSL * ssl) /* QDIR */ -int CtdlIPCDirectoryLookup(CtdlIPC * ipc, const char *address, char *cret) -{ +int CtdlIPCDirectoryLookup(CtdlIPC * ipc, const char *address, char *cret) { int ret; char *aaa; @@ -2330,8 +2242,7 @@ int CtdlIPCDirectoryLookup(CtdlIPC * ipc, const char *address, char *cret) /* IPGM */ -int CtdlIPCInternalProgram(CtdlIPC * ipc, int secret, char *cret) -{ +int CtdlIPCInternalProgram(CtdlIPC * ipc, int secret, char *cret) { char aaa[30]; if (!cret) @@ -2344,13 +2255,14 @@ int CtdlIPCInternalProgram(CtdlIPC * ipc, int secret, char *cret) /* ************************************************************************** */ + /* Stuff below this line is not for public consumption */ + /* ************************************************************************** */ /* Read a listing from the server up to 000. Append to dest if it exists */ -char *CtdlIPCReadListing(CtdlIPC * ipc, char *dest) -{ +char *CtdlIPCReadListing(CtdlIPC * ipc, char *dest) { size_t length = 0; size_t linelength; char *ret = NULL; @@ -2359,7 +2271,8 @@ char *CtdlIPCReadListing(CtdlIPC * ipc, char *dest) ret = dest; if (ret != NULL) { length = strlen(ret); - } else { + } + else { length = 0; } @@ -2378,8 +2291,7 @@ char *CtdlIPCReadListing(CtdlIPC * ipc, char *dest) /* Send a listing to the server; generate the ending 000. */ -int CtdlIPCSendListing(CtdlIPC * ipc, const char *listing) -{ +int CtdlIPCSendListing(CtdlIPC * ipc, const char *listing) { char *text; text = (char *) malloc(strlen(listing) + 6); @@ -2391,7 +2303,8 @@ int CtdlIPCSendListing(CtdlIPC * ipc, const char *listing) CtdlIPC_putline(ipc, text); free(text); text = NULL; - } else { + } + else { /* Malloc failed but we are committed to send */ /* This may result in extra blanks at the bottom */ CtdlIPC_putline(ipc, text); @@ -2402,8 +2315,7 @@ int CtdlIPCSendListing(CtdlIPC * ipc, const char *listing) /* Partial read of file from server */ -size_t CtdlIPCPartialRead(CtdlIPC * ipc, void **buf, size_t offset, size_t bytes, char *cret) -{ +size_t CtdlIPCPartialRead(CtdlIPC * ipc, void **buf, size_t offset, size_t bytes, char *cret) { size_t len = 0; char aaa[SIZ]; @@ -2426,7 +2338,8 @@ size_t CtdlIPCPartialRead(CtdlIPC * ipc, void **buf, size_t offset, size_t bytes if (*buf) { /* I know what I'm doing */ serv_read(ipc, ((char *) (*buf) + offset), len); - } else { + } + else { /* We have to read regardless */ serv_read(ipc, aaa, len); len = 0; @@ -2438,8 +2351,7 @@ size_t CtdlIPCPartialRead(CtdlIPC * ipc, void **buf, size_t offset, size_t bytes /* CLOS */ -int CtdlIPCEndDownload(CtdlIPC * ipc, char *cret) -{ +int CtdlIPCEndDownload(CtdlIPC * ipc, char *cret) { int ret; if (!cret) @@ -2455,8 +2367,7 @@ int CtdlIPCEndDownload(CtdlIPC * ipc, char *cret) /* MSGP */ -int CtdlIPCSpecifyPreferredFormats(CtdlIPC * ipc, char *cret, char *formats) -{ +int CtdlIPCSpecifyPreferredFormats(CtdlIPC * ipc, char *cret, char *formats) { int ret; char cmd[SIZ]; @@ -2469,8 +2380,7 @@ int CtdlIPCSpecifyPreferredFormats(CtdlIPC * ipc, char *cret, char *formats) /* READ */ int CtdlIPCReadDownload(CtdlIPC * ipc, void **buf, size_t bytes, size_t resume, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { size_t len; if (!cret) @@ -2502,8 +2412,7 @@ int CtdlIPCReadDownload(CtdlIPC * ipc, void **buf, size_t bytes, size_t resume, /* READ - pipelined */ int CtdlIPCHighSpeedReadDownload(CtdlIPC * ipc, void **buf, size_t bytes, size_t resume, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { size_t len; int calls; /* How many calls in the pipeline */ int i; /* iterator */ @@ -2557,8 +2466,7 @@ int CtdlIPCHighSpeedReadDownload(CtdlIPC * ipc, void **buf, size_t bytes, size_t /* UCLS */ -int CtdlIPCEndUpload(CtdlIPC * ipc, int discard, char *cret) -{ +int CtdlIPCEndUpload(CtdlIPC * ipc, int discard, char *cret) { int ret; char cmd[8]; @@ -2576,8 +2484,7 @@ int CtdlIPCEndUpload(CtdlIPC * ipc, int discard, char *cret) /* WRIT */ int CtdlIPCWriteUpload(CtdlIPC * ipc, FILE * uploadFP, void (*progress_gauge_callback) - (CtdlIPC *, unsigned long, unsigned long), char *cret) -{ + (CtdlIPC *, unsigned long, unsigned long), char *cret) { int ret = -1; size_t offset = 0; size_t bytes; @@ -2620,7 +2527,8 @@ int CtdlIPCWriteUpload(CtdlIPC * ipc, FILE * uploadFP, void (*progress_gauge_cal /* Detect short reads and back up if needed */ /* offset will never be negative anyway */ fseek(fd, (signed) offset, SEEK_SET); - } else { + } + else { break; } } @@ -2660,13 +2568,14 @@ 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; @@ -2696,7 +2605,8 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, case 1: /* LISTING_FOLLOWS */ if (to_receive && !*to_receive && bytes_to_receive) { *to_receive = CtdlIPCReadListing(ipc, NULL); - } else { /* Drain */ + } + else { /* Drain */ while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")); ret = -ret; } @@ -2704,7 +2614,8 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, case 4: /* SEND_LISTING */ if (to_send) { CtdlIPCSendListing(ipc, to_send); - } else { + } + else { /* No listing given, fake it */ CtdlIPC_putline(ipc, "000"); ret = -ret; @@ -2714,13 +2625,15 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, if (to_receive && !*to_receive && bytes_to_receive) { *bytes_to_receive = extract_long(proto_response, 0); *to_receive = (char *) - malloc((size_t) * bytes_to_receive); + malloc((size_t) *bytes_to_receive); if (!*to_receive) { ret = -1; - } else { + } + else { serv_read(ipc, *to_receive, *bytes_to_receive); } - } else { + } + else { /* Drain */ size_t drain; @@ -2736,7 +2649,8 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, case 7: /* SEND_BINARY */ if (to_send && bytes_to_send) { serv_write(ipc, to_send, bytes_to_send); - } else if (bytes_to_send) { + } + else if (bytes_to_send) { /* Fake it, send nulls */ size_t fake; @@ -2750,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"); @@ -2929,6 +2843,7 @@ void serv_write(CtdlIPC * ipc, const char *buf, unsigned int nbytes) { #ifdef HAVE_OPENSSL + /* * input binary data from encrypted connection */ @@ -3111,16 +3026,26 @@ 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 + } + } + else #endif { if (ipc->Buf == NULL) { @@ -3153,7 +3078,8 @@ static void CtdlIPC_getline(CtdlIPC * ipc, char *buf) { /* is there more in the buffer we need to read later? */ if (ipc->Buf + ipc->BufUsed > aptr) { ipc->BufPtr = aptr; - } else { + } + else { ipc->BufUsed = 0; ipc->BufPtr = ipc->Buf; } @@ -3363,7 +3289,7 @@ CtdlIPC *CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf) { /* * Disconnect and delete the IPC class (destructor) */ -void CtdlIPC_delete(CtdlIPC *ipc) { +void CtdlIPC_delete(CtdlIPC * ipc) { #ifdef HAVE_OPENSSL if (ipc->ssl) { SSL_shutdown(ipc->ssl); @@ -3387,7 +3313,7 @@ void CtdlIPC_delete(CtdlIPC *ipc) { * Disconnect and delete the IPC class (destructor) * Also NULLs out the pointer */ -void CtdlIPC_delete_ptr(CtdlIPC **pipc) { +void CtdlIPC_delete_ptr(CtdlIPC ** pipc) { CtdlIPC_delete(*pipc); *pipc = NULL; }