4 #define DEFAULT_HOST UDS
5 #define DEFAULT_PORT "citadel"
13 # include <sys/time.h>
20 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <arpa/inet.h>
29 #include <netinet/in.h>
33 #ifdef THREADED_CLIENT
37 #include "citadel_ipc.h"
38 #include "citadel_decls.h"
41 #ifdef THREADED_CLIENT
42 pthread_mutex_t rwlock;
46 static SSL_CTX *ssl_ctx;
49 #ifdef THREADED_CLIENT
50 pthread_mutex_t **Critters; /* Things that need locking */
51 #endif /* THREADED_CLIENT */
53 #endif /* HAVE_OPENSSL */
56 #define INADDR_NONE 0xffffffff
59 static void (*status_hook)(char *s) = NULL;
61 void setCryptoStatusHook(void (*hook)(char *s)) {
65 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state)) {
66 ipc->network_status_cb = hook;
70 char express_msgs = 0;
73 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes);
74 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes);
76 static void serv_read_ssl(CtdlIPC *ipc, char *buf, unsigned int bytes);
77 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes);
78 static void ssl_lock(int mode, int n, const char *file, int line);
79 static void endtls(SSL *ssl);
80 #ifdef THREADED_CLIENT
81 static unsigned long id_callback(void);
82 #endif /* THREADED_CLIENT */
83 #endif /* HAVE_OPENSSL */
87 * Does nothing. The server should always return 200.
89 int CtdlIPCNoop(CtdlIPC *ipc)
93 return CtdlIPCGenericCommand(ipc, "NOOP", NULL, 0, NULL, NULL, aaa);
98 * Does nothing interesting. The server should always return 200
99 * along with your string.
101 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret)
107 if (!cret) return -2;
109 aaa = (char *)malloc((size_t)(strlen(arg) + 6));
112 sprintf(aaa, "ECHO %s", arg);
113 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
120 * Asks the server to close the connecction.
121 * Should always return 200.
123 int CtdlIPCQuit(CtdlIPC *ipc)
129 CtdlIPC_putline(ipc, "QUIT");
130 CtdlIPC_getline(ipc, aaa);
138 * Asks the server to logout. Should always return 200, even if no user
139 * was logged in. The user will not be logged in after this!
141 int CtdlIPCLogout(CtdlIPC *ipc)
147 CtdlIPC_putline(ipc, "LOUT");
148 CtdlIPC_getline(ipc, aaa);
156 * First stage of authentication - pass the username. Returns 300 if the
157 * username is able to log in, with the username correctly spelled in cret.
158 * Returns various 500 error codes if the user doesn't exist, etc.
160 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret)
165 if (!username) return -2;
166 if (!cret) return -2;
168 aaa = (char *)malloc((size_t)(strlen(username) + 6));
171 sprintf(aaa, "USER %s", username);
172 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
179 * Second stage of authentication - provide password. The server returns
180 * 200 and several arguments in cret relating to the user's account.
182 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret)
187 if (!passwd) return -2;
188 if (!cret) return -2;
190 aaa = (char *)malloc((size_t)(strlen(passwd) + 6));
193 sprintf(aaa, "PASS %s", passwd);
194 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
201 * Second stage of authentication - provide password. The server returns
202 * 200 and several arguments in cret relating to the user's account.
204 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret)
209 if (!response) return -2;
210 if (!cret) return -2;
212 aaa = (char *)malloc((size_t)(strlen(response) + 6));
215 sprintf(aaa, "PAS2 %s", response);
216 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
223 * Create a new user. This returns 200 plus the same arguments as TryPassword
224 * if selfservice is nonzero, unless there was a problem creating the account.
225 * If selfservice is zero, creates a new user but does not log out the existing
226 * user - intended for use by system administrators to create accounts on
227 * behalf of other users.
229 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice, char *cret)
234 if (!username) return -2;
235 if (!cret) return -2;
237 aaa = (char *)malloc((size_t)(strlen(username) + 6));
240 sprintf(aaa, "%s %s", selfservice ? "NEWU" : "CREU", username);
241 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
248 * Changes the user's password. Returns 200 if changed, errors otherwise.
250 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret)
255 if (!passwd) return -2;
256 if (!cret) return -2;
258 aaa = (char *)malloc((size_t)(strlen(passwd) + 6));
261 sprintf(aaa, "SETP %s", passwd);
262 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
269 /* Caller must free the march list */
270 /* Room types are defined in enum RoomList; keep these in sync! */
271 /* floor is -1 for all, or floornum */
272 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor, struct march **listing, char *cret)
275 struct march *march = NULL;
276 static char *proto[] =
277 {"LKRA", "LKRN", "LKRO", "LZRM", "LRMS", "LPRM" };
282 if (!listing) return -2;
283 if (*listing) return -2; /* Free the listing first */
284 if (!cret) return -2;
285 /* if (which < 0 || which > 4) return -2; */
286 if (floor < -1) return -2; /* Can't validate upper bound, sorry */
288 sprintf(aaa, "%s %d", proto[which], floor);
289 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
290 if (ret / 100 == 1) {
293 while (bbb && strlen(bbb)) {
296 extract_token(aaa, bbb, 0, '\n');
298 memmove(bbb, bbb + a + 1, strlen(bbb) - a);
299 mptr = (struct march *) malloc(sizeof (struct march));
302 extract(mptr->march_name, aaa, 0);
303 mptr->march_flags = (unsigned int) extract_int(aaa, 1);
304 mptr->march_floor = (char) extract_int(aaa, 2);
305 mptr->march_order = (char) extract_int(aaa, 3);
312 while (mptr2->next != NULL)
325 /* Caller must free the struct usersupp; caller may pass an existing one */
326 int CtdlIPCGetConfig(CtdlIPC *ipc, struct usersupp **uret, char *cret)
330 if (!cret) return -2;
331 if (!uret) return -2;
332 if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof (struct usersupp));
333 if (!*uret) return -1;
335 ret = CtdlIPCGenericCommand(ipc, "GETU", NULL, 0, NULL, NULL, cret);
336 if (ret / 100 == 2) {
337 uret[0]->USscreenwidth = extract_int(cret, 0);
338 uret[0]->USscreenheight = extract_int(cret, 1);
339 uret[0]->flags = extract_int(cret, 2);
346 int CtdlIPCSetConfig(CtdlIPC *ipc, struct usersupp *uret, char *cret)
350 if (!uret) return -2;
351 if (!cret) return -2;
353 sprintf(aaa, "SETU %d|%d|%d",
354 uret->USscreenwidth, uret->USscreenheight,
356 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
361 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
362 struct ctdlipcroom **rret, char *cret)
367 if (!cret) return -2;
368 if (!rret) return -2;
369 if (!*rret) *rret = (struct ctdlipcroom *)calloc(1, sizeof (struct ctdlipcroom));
370 if (!*rret) return -1;
373 aaa = (char *)malloc(strlen(room) + strlen(passwd) + 7);
378 sprintf(aaa, "GOTO %s|%s", room, passwd);
380 aaa = (char *)malloc(strlen(room) + 6);
385 sprintf(aaa, "GOTO %s", room);
387 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
388 if (ret / 100 == 2) {
389 extract(rret[0]->RRname, cret, 0);
390 rret[0]->RRunread = extract_long(cret, 1);
391 rret[0]->RRtotal = extract_long(cret, 2);
392 rret[0]->RRinfoupdated = extract_int(cret, 3);
393 rret[0]->RRflags = extract_int(cret, 4);
394 rret[0]->RRhighest = extract_long(cret, 5);
395 rret[0]->RRlastread = extract_long(cret, 6);
396 rret[0]->RRismailbox = extract_int(cret, 7);
397 rret[0]->RRaide = extract_int(cret, 8);
398 rret[0]->RRnewmail = extract_long(cret, 9);
399 rret[0]->RRfloor = extract_int(cret, 10);
408 /* which is 0 = all, 1 = old, 2 = new, 3 = last, 4 = first, 5 = gt, 6 = lt */
409 /* whicharg is number of messages, applies to last, first, gt, lt */
410 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
411 const char *mtemplate, unsigned long **mret, char *cret)
414 register unsigned long count = 0;
415 static char *proto[] =
416 { "ALL", "OLD", "NEW", "LAST", "FIRST", "GT", "LT" };
421 if (!cret) return -2;
422 if (!mret) return -2;
423 if (*mret) return -2;
424 if (which < 0 || which > 6) return -2;
427 sprintf(aaa, "MSGS %s||%d", proto[which],
428 (mtemplate) ? 1 : 0);
430 sprintf(aaa, "MSGS %s|%d|%d", proto[which], whicharg,
431 (mtemplate) ? 1 : 0);
432 if (mtemplate) count = strlen(mtemplate);
433 ret = CtdlIPCGenericCommand(ipc, aaa, mtemplate, count, &bbb, &bbbsize, cret);
437 *mret = (unsigned long *)calloc(1, sizeof(unsigned long));
440 while (bbb && strlen(bbb)) {
441 extract_token(aaa, bbb, 0, '\n');
442 remove_token(bbb, 0, '\n');
443 *mret = (unsigned long *)realloc(*mret, (size_t)((count + 2) *
444 sizeof (unsigned long)));
446 (*mret)[count++] = atol(aaa);
458 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
459 struct ctdlipcmessage **mret, char *cret)
465 int multipart_hunting = 0;
466 char multipart_prefix[SIZ];
468 if (!cret) return -1;
469 if (!mret) return -1;
470 if (!*mret) *mret = (struct ctdlipcmessage *)calloc(1, sizeof (struct ctdlipcmessage));
471 if (!*mret) return -1;
472 if (!msgnum) return -1;
474 strcpy(mret[0]->content_type, "");
475 sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
476 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
477 if (ret / 100 == 1) {
479 strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
480 while (strlen(bbb) > 4 && bbb[4] == '=') {
481 extract_token(aaa, bbb, 0, '\n');
482 remove_token(bbb, 0, '\n');
484 if (!strncasecmp(aaa, "nhdr=yes", 8))
486 else if (!strncasecmp(aaa, "from=", 5))
487 strcpy(mret[0]->author, &aaa[5]);
488 else if (!strncasecmp(aaa, "type=", 5))
489 mret[0]->type = atoi(&aaa[5]);
490 else if (!strncasecmp(aaa, "msgn=", 5))
491 strcpy(mret[0]->msgid, &aaa[5]);
492 else if (!strncasecmp(aaa, "subj=", 5))
493 strcpy(mret[0]->subject, &aaa[5]);
494 else if (!strncasecmp(aaa, "rfca=", 5))
495 strcpy(mret[0]->email, &aaa[5]);
496 else if (!strncasecmp(aaa, "hnod=", 5))
497 strcpy(mret[0]->hnod, &aaa[5]);
498 else if (!strncasecmp(aaa, "room=", 5))
499 strcpy(mret[0]->room, &aaa[5]);
500 else if (!strncasecmp(aaa, "node=", 5))
501 strcpy(mret[0]->node, &aaa[5]);
502 else if (!strncasecmp(aaa, "rcpt=", 5))
503 strcpy(mret[0]->recipient, &aaa[5]);
504 else if (!strncasecmp(aaa, "time=", 5))
505 mret[0]->time = atol(&aaa[5]);
507 /* Multipart/alternative prefix & suffix strings help
508 * us to determine which part we want to download.
510 else if (!strncasecmp(aaa, "pref=", 5)) {
511 extract(multipart_prefix, &aaa[5], 1);
512 if (!strcasecmp(multipart_prefix,
513 "multipart/alternative")) {
517 else if (!strncasecmp(aaa, "suff=", 5)) {
518 extract(multipart_prefix, &aaa[5], 1);
519 if (!strcasecmp(multipart_prefix,
520 "multipart/alternative")) {
525 else if (!strncasecmp(aaa, "part=", 5)) {
526 struct parts *ptr, *chain;
528 ptr = (struct parts *)calloc(1, sizeof (struct parts));
531 /* Fill the buffers for the caller */
532 extract(ptr->name, &aaa[5], 0);
533 extract(ptr->filename, &aaa[5], 1);
534 extract(ptr->number, &aaa[5], 2);
535 extract(ptr->disposition, &aaa[5], 3);
536 extract(ptr->mimetype, &aaa[5], 4);
537 ptr->length = extract_long(&aaa[5], 5);
538 if (!mret[0]->attachments)
539 mret[0]->attachments = ptr;
541 chain = mret[0]->attachments;
547 /* Now handle multipart/alternative */
548 if (multipart_hunting > 0) {
549 if ( (!strcasecmp(ptr->mimetype,
551 || (!strcasecmp(ptr->mimetype,
553 strcpy(mret[0]->mime_chosen,
561 /* Eliminate "text\n" */
562 remove_token(bbb, 0, '\n');
564 /* If doing a MIME thing, pull out the extra headers */
567 if (!strncasecmp(bbb, "Content-type: ", 14)) {
568 extract_token(mret[0]->content_type, bbb, 0, '\n');
569 strcpy(mret[0]->content_type,
570 &mret[0]->content_type[14]);
571 striplt(mret[0]->content_type);
573 remove_token(bbb, 0, '\n');
574 } while ((bbb[0] != 0) && (bbb[0] != '\n'));
575 /*ooga*/ remove_token(bbb, 0, '\n');
581 /* FIXME: Strip trailing whitespace */
582 bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1));
584 bbb = (char *)realloc(bbb, 1);
594 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret)
599 if (!cret) return -2;
600 if (!listing) return -2;
601 if (*listing) return -2;
603 ret = CtdlIPCGenericCommand(ipc, "WHOK", NULL, 0, listing, &bytes, cret);
609 int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret)
613 char *listing = NULL;
616 if (!cret) return -2;
617 if (!ServInfo) return -2;
619 ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret);
620 if (ret / 100 == 1) {
623 while (*listing && strlen(listing)) {
624 extract_token(buf, listing, 0, '\n');
625 remove_token(listing, 0, '\n');
627 case 0: ServInfo->serv_pid = atoi(buf);
629 case 1: strcpy(ServInfo->serv_nodename,buf);
631 case 2: strcpy(ServInfo->serv_humannode,buf);
633 case 3: strcpy(ServInfo->serv_fqdn,buf);
635 case 4: strcpy(ServInfo->serv_software,buf);
637 case 5: ServInfo->serv_rev_level = atoi(buf);
639 case 6: strcpy(ServInfo->serv_bbs_city,buf);
641 case 7: strcpy(ServInfo->serv_sysadm,buf);
643 case 9: strcpy(ServInfo->serv_moreprompt,buf);
645 case 10: ServInfo->serv_ok_floors = atoi(buf);
647 case 11: ServInfo->serv_paging_level = atoi(buf);
649 case 13: ServInfo->serv_supports_qnop = atoi(buf);
660 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret)
665 if (!cret) return -2;
666 if (!listing) return -2;
667 if (*listing) return -2;
669 ret = CtdlIPCGenericCommand(ipc, "RDIR", NULL, 0, listing, &bytes, cret);
675 * Set last-read pointer in this room to msgnum, or 0 for HIGHEST.
677 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret)
682 if (!cret) return -2;
685 sprintf(aaa, "SLRP %ld", msgnum);
688 sprintf(aaa, "SLRP HIGHEST");
690 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
696 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret)
701 if (!cret) return -2;
702 if (!username) return -2;
704 aaa = (char *)malloc(strlen(username) + 6);
707 sprintf(aaa, "INVT %s", username);
708 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
715 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret)
720 if (!cret) return -1;
721 if (!username) return -1;
723 aaa = (char *)malloc(strlen(username) + 6);
725 sprintf(aaa, "KICK %s", username);
726 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
733 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct quickroom **qret, char *cret)
737 if (!cret) return -2;
738 if (!qret) return -2;
739 if (!*qret) *qret = (struct quickroom *)calloc(1, sizeof (struct quickroom));
740 if (!*qret) return -1;
742 ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
743 if (ret / 100 == 2) {
744 extract(qret[0]->QRname, cret, 0);
745 extract(qret[0]->QRpasswd, cret, 1);
746 extract(qret[0]->QRdirname, cret, 2);
747 qret[0]->QRflags = extract_int(cret, 3);
748 qret[0]->QRfloor = extract_int(cret, 4);
749 qret[0]->QRorder = extract_int(cret, 5);
750 qret[0]->QRdefaultview = extract_int(cret, 6);
751 qret[0]->QRflags2 = extract_int(cret, 7);
758 /* set forget to kick all users out of room */
759 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct quickroom *qret, char *cret)
764 if (!cret) return -2;
765 if (!qret) return -2;
767 aaa = (char *)malloc(strlen(qret->QRname) + strlen(qret->QRpasswd) +
768 strlen(qret->QRdirname) + 52);
771 sprintf(aaa, "SETR %s|%s|%s|%d|%d|%d|%d",
772 qret->QRname, qret->QRpasswd, qret->QRdirname,
773 qret->QRflags, forget, qret->QRfloor, qret->QRorder);
774 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
781 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret)
783 if (!cret) return -1;
785 return CtdlIPCGenericCommand(ipc, "GETA", NULL, 0, NULL, NULL, cret);
790 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret)
795 if (!cret) return -2;
796 if (!username) return -2;
798 aaa = (char *)malloc(strlen(username) + 6);
801 sprintf(aaa, "SETA %s", username);
802 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
809 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret)
814 if (!cret) return -2;
817 snprintf(cmd, sizeof cmd,
818 "ENT0 %d|%s|%d|%d|%s|%s", flag, mr->recipient,
819 mr->anonymous, mr->type, mr->subject, mr->author);
820 ret = CtdlIPCGenericCommand(ipc, cmd, mr->text, strlen(mr->text), NULL,
827 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret)
831 if (!cret) return -2;
832 if (!iret) return -2;
833 if (*iret) return -2;
835 return CtdlIPCGenericCommand(ipc, "RINF", NULL, 0, iret, &bytes, cret);
840 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret)
844 if (!cret) return -2;
845 if (!msgnum) return -2;
847 sprintf(aaa, "DELE %ld", msgnum);
848 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
853 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret)
858 if (!cret) return -2;
859 if (!destroom) return -2;
860 if (!msgnum) return -2;
862 aaa = (char *)malloc(strlen(destroom) + 28);
865 sprintf(aaa, "MOVE %ld|%s|%d", msgnum, destroom, copy);
866 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
873 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret)
877 if (!cret) return -2;
879 sprintf(aaa, "KILL %d", for_real);
880 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
885 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type,
886 const char *password, int floor, char *cret)
891 if (!cret) return -2;
892 if (!roomname) return -2;
895 aaa = (char *)malloc(strlen(roomname) + strlen(password) + 40);
897 sprintf(aaa, "CRE8 %d|%s|%d|%s|%d", for_real, roomname, type,
900 aaa = (char *)malloc(strlen(roomname) + 40);
902 sprintf(aaa, "CRE8 %d|%s|%d||%d", for_real, roomname, type,
905 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
912 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret)
914 if (!cret) return -2;
916 return CtdlIPCGenericCommand(ipc, "FORG", NULL, 0, NULL, NULL, cret);
921 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret)
927 if (!cret) return -2;
928 if (!mret) return -2;
929 if (*mret) return -2;
930 if (!message) return -2;
932 aaa = (char *)malloc(strlen(message) + 6);
935 sprintf(aaa, "MESG %s", message);
936 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, mret, &bytes, cret);
943 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret)
945 if (!cret) return -2;
947 return CtdlIPCGenericCommand(ipc, "GNUR", NULL, 0, NULL, NULL, cret);
952 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret)
958 if (!cret) return -2;
959 if (!rret) return -2;
960 if (*rret) return -2;
963 aaa = (char *)malloc(strlen(username) + 6);
965 aaa = (char *)malloc(12);
969 sprintf(aaa, "GREG %s", username);
971 sprintf(aaa, "GREG _SELF_");
972 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, rret, &bytes, cret);
979 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret)
984 if (!cret) return -2;
985 if (!username) return -2;
986 if (axlevel < 0 || axlevel > 7) return -2;
988 aaa = (char *)malloc(strlen(username) + 17);
991 sprintf(aaa, "VALI %s|%d", username, axlevel);
992 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
999 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret)
1003 if (!cret) return -1;
1004 if (!info) return -1;
1006 sprintf(aaa, "EINF %d", for_real);
1007 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1012 int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret)
1016 if (!cret) return -1;
1017 if (!listing) return -1;
1018 if (*listing) return -1;
1020 return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret);
1025 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret)
1027 if (!cret) return -1;
1028 if (!info) return -1;
1030 return CtdlIPCGenericCommand(ipc, "REGI", info, strlen(info),
1036 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret)
1040 if (!cret) return -1;
1041 if (!chek) return -1;
1043 ret = CtdlIPCGenericCommand(ipc, "CHEK", NULL, 0, NULL, NULL, cret);
1044 if (ret / 100 == 2) {
1045 chek->newmail = extract_long(cret, 0);
1046 chek->needregis = extract_int(cret, 1);
1047 chek->needvalid = extract_int(cret, 2);
1054 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret)
1059 if (!cret) return -2;
1060 if (!filename) return -2;
1062 aaa = (char *)malloc(strlen(filename) + 6);
1063 if (!aaa) return -1;
1065 sprintf(aaa, "DELF %s", filename);
1066 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1073 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret)
1078 if (!cret) return -2;
1079 if (!filename) return -2;
1080 if (!destroom) return -2;
1082 aaa = (char *)malloc(strlen(filename) + strlen(destroom) + 7);
1083 if (!aaa) return -1;
1085 sprintf(aaa, "MOVF %s|%s", filename, destroom);
1086 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1093 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret)
1098 if (!cret) return -2;
1099 if (!filename) return -2;
1100 if (!destnode) return -2;
1102 aaa = (char *)malloc(strlen(filename) + strlen(destnode) + 7);
1103 if (!aaa) return -1;
1105 sprintf(aaa, "NETF %s|%s", filename, destnode);
1106 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1113 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret)
1118 if (!cret) return -1;
1119 if (!listing) return -1;
1120 if (*listing) return -1;
1122 *stamp = CtdlIPCServerTime(ipc, cret);
1124 *stamp = time(NULL);
1125 ret = CtdlIPCGenericCommand(ipc, "RWHO", NULL, 0, listing, &bytes, cret);
1131 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
1133 void (*progress_gauge_callback)(unsigned long, unsigned long),
1142 if (!cret) return -2;
1143 if (!filename) return -2;
1144 if (!buf) return -2;
1145 if (*buf) return -2;
1146 if (ipc->downloading) return -2;
1148 aaa = (char *)malloc(strlen(filename) + 6);
1149 if (!aaa) return -1;
1151 sprintf(aaa, "OPEN %s", filename);
1152 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1154 if (ret / 100 == 2) {
1155 ipc->downloading = 1;
1156 bytes = extract_long(cret, 0);
1157 last_mod = extract_int(cret, 1);
1158 extract(mimetype, cret, 2);
1159 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret); */
1160 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret);
1161 ret = CtdlIPCEndDownload(ipc, cret);
1163 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1164 filename, mimetype);
1171 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
1173 void (*progress_gauge_callback)(unsigned long, unsigned long),
1183 if (!cret) return -2;
1184 if (!buf) return -2;
1185 if (*buf) return -2;
1186 if (!part) return -2;
1187 if (!msgnum) return -2;
1188 if (ipc->downloading) return -2;
1190 sprintf(aaa, "OPNA %ld|%s", msgnum, part);
1191 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1192 if (ret / 100 == 2) {
1193 ipc->downloading = 1;
1194 bytes = extract_long(cret, 0);
1195 last_mod = extract_int(cret, 1);
1196 extract(filename, cret, 2);
1197 extract(mimetype, cret, 3);
1198 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1199 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1200 ret = CtdlIPCEndDownload(ipc, cret);
1202 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1203 filename, mimetype);
1210 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
1211 void (*progress_gauge_callback)(unsigned long, unsigned long),
1220 if (!cret) return -1;
1221 if (!buf) return -1;
1222 if (*buf) return -1;
1223 if (!filename) return -1;
1224 if (ipc->downloading) return -1;
1226 aaa = (char *)malloc(strlen(filename) + 6);
1227 if (!aaa) return -1;
1229 sprintf(aaa, "OIMG %s", filename);
1230 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1232 if (ret / 100 == 2) {
1233 ipc->downloading = 1;
1234 bytes = extract_long(cret, 0);
1235 last_mod = extract_int(cret, 1);
1236 extract(mimetype, cret, 2);
1237 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1238 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1239 ret = CtdlIPCEndDownload(ipc, cret);
1241 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1242 filename, mimetype);
1249 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
1251 void (*progress_gauge_callback)(unsigned long, unsigned long),
1257 if (!cret) return -1;
1258 if (!save_as) return -1;
1259 if (!comment) return -1;
1260 if (!path) return -1;
1261 if (!*path) return -1;
1262 if (ipc->uploading) return -1;
1264 aaa = (char *)malloc(strlen(save_as) + strlen(comment) + 7);
1265 if (!aaa) return -1;
1267 sprintf(aaa, "UOPN %s|%s", save_as, comment);
1268 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1270 if (ret / 100 == 2) {
1272 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1273 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1281 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
1282 const char *save_as,
1283 void (*progress_gauge_callback)(unsigned long, unsigned long),
1289 if (!cret) return -1;
1290 if (!save_as) return -1;
1291 if (!path && for_real) return -1;
1292 if (!*path && for_real) return -1;
1293 if (ipc->uploading) return -1;
1295 aaa = (char *)malloc(strlen(save_as) + 17);
1296 if (!aaa) return -1;
1298 sprintf(aaa, "UIMG %d|%s", for_real, save_as);
1299 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1301 if (ret / 100 == 2 && for_real) {
1303 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1304 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1312 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret)
1317 if (!cret) return -2;
1318 if (!username) return -2;
1320 aaa = (char *)malloc(strlen(username) + 6);
1321 if (!aaa) return -1;
1323 sprintf(aaa, "QUSR %s", username);
1324 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1331 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret)
1335 if (!cret) return -2;
1336 if (!listing) return -2;
1337 if (*listing) return -2;
1339 return CtdlIPCGenericCommand(ipc, "LFLR", NULL, 0, listing, &bytes, cret);
1344 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret)
1349 if (!cret) return -2;
1350 if (!name) return -2;
1351 if (!*name) return -2;
1353 aaa = (char *)malloc(strlen(name) + 17);
1354 if (!aaa) return -1;
1356 sprintf(aaa, "CFLR %s|%d", name, for_real);
1357 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1364 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret)
1368 if (!cret) return -1;
1369 if (floornum < 0) return -1;
1371 sprintf(aaa, "KFLR %d|%d", floornum, for_real);
1372 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1377 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret)
1382 if (!cret) return -2;
1383 if (!floorname) return -2;
1384 if (floornum < 0) return -2;
1386 aaa = (char *)malloc(strlen(floorname) + 17);
1387 if (!aaa) return -1;
1389 sprintf(aaa, "EFLR %d|%s", floornum, floorname);
1390 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1399 * You only need to fill out hostname, the defaults will be used if any of the
1400 * other fields are not set properly.
1402 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
1403 int revision, const char *software_name, const char *hostname,
1409 if (developerid < 0 || clientid < 0 || revision < 0 ||
1413 revision = REV_LEVEL - 600;
1414 software_name = "Citadel/UX (libcitadel)";
1416 if (!hostname) return -2;
1418 aaa = (char *)malloc(strlen(software_name) + strlen(hostname) + 29);
1419 if (!aaa) return -1;
1421 sprintf(aaa, "IDEN %d|%d|%d|%s|%s", developerid, clientid,
1422 revision, software_name, hostname);
1423 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1430 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text,
1436 if (!cret) return -2;
1437 if (!username) return -2;
1439 aaa = (char *)malloc(strlen(username) + 8);
1440 if (!aaa) return -1;
1443 sprintf(aaa, "SEXP %s|-", username);
1444 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text),
1447 sprintf(aaa, "SEXP %s||", username);
1448 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1456 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret)
1460 if (!cret) return -2;
1461 if (!listing) return -2;
1462 if (*listing) return -2;
1464 return CtdlIPCGenericCommand(ipc, "GEXP", NULL, 0, listing, &bytes, cret);
1469 /* mode is 0 = enable, 1 = disable, 2 = status */
1470 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret)
1474 if (!cret) return -2;
1476 sprintf(aaa, "DEXP %d", mode);
1477 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1482 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret)
1484 if (!cret) return -2;
1485 if (!bio) return -2;
1487 return CtdlIPCGenericCommand(ipc, "EBIO", bio, strlen(bio),
1493 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret)
1499 if (!cret) return -2;
1500 if (!username) return -2;
1501 if (!listing) return -2;
1502 if (*listing) return -2;
1504 aaa = (char *)malloc(strlen(username) + 6);
1505 if (!aaa) return -1;
1507 sprintf(aaa, "RBIO %s", username);
1508 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, listing, &bytes, cret);
1515 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret)
1519 if (!cret) return -2;
1520 if (!listing) return -2;
1521 if (*listing) return -2;
1523 return CtdlIPCGenericCommand(ipc, "LBIO", NULL, 0, listing, &bytes, cret);
1528 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret)
1532 if (!cret) return -1;
1534 sprintf(aaa, "STEL %d", mode ? 1 : 0);
1535 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1540 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret)
1544 if (!cret) return -1;
1546 sprintf(aaa, "TERM %d", sid);
1547 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1552 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret)
1554 if (!cret) return -1;
1556 return CtdlIPCGenericCommand(ipc, "DOWN", NULL, 0, NULL, NULL, cret);
1561 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret)
1565 if (!cret) return -1;
1567 sprintf(aaa, "SCDN %d", mode ? 1 : 0);
1568 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1573 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
1579 if (!cret) return -2;
1580 if (!text) return -2;
1581 if (!filename) return -2;
1583 aaa = (char *)malloc(strlen(filename) + 6);
1584 if (!aaa) return -1;
1586 sprintf(aaa, "EMSG %s", filename);
1587 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret);
1594 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret)
1599 if (!cret) return -2;
1600 if (!hostname) return -2;
1602 aaa = (char *)malloc(strlen(hostname) + 6);
1603 if (!aaa) return -1;
1605 sprintf(aaa, "HCHG %s", hostname);
1606 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1613 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret)
1618 if (!cret) return -2;
1619 if (!roomname) return -2;
1621 aaa = (char *)malloc(strlen(roomname) + 6);
1622 if (!aaa) return -1;
1624 sprintf(aaa, "RCHG %s", roomname);
1625 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1632 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret)
1637 if (!cret) return -2;
1638 if (!username) return -2;
1640 aaa = (char *)malloc(strlen(username) + 6);
1641 if (!aaa) return -1;
1643 sprintf(aaa, "UCHG %s", username);
1644 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1651 /* This function returns the actual server time reported, or 0 if error */
1652 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *cret)
1654 register time_t tret;
1657 ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret);
1658 if (ret / 100 == 2) {
1659 tret = extract_long(cret, 0);
1668 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
1669 struct usersupp **uret, char *cret)
1674 if (!cret) return -2;
1675 if (!uret) return -2;
1676 if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof(struct usersupp));
1677 if (!*uret) return -1;
1679 sprintf(aaa, "AGUP %s", who);
1680 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1682 if (ret / 100 == 2) {
1683 extract(uret[0]->fullname, cret, 0);
1684 extract(uret[0]->password, cret, 1);
1685 uret[0]->flags = extract_int(cret, 2);
1686 uret[0]->timescalled = extract_long(cret, 3);
1687 uret[0]->posted = extract_long(cret, 4);
1688 uret[0]->axlevel = extract_int(cret, 5);
1689 uret[0]->usernum = extract_long(cret, 6);
1690 uret[0]->lastcall = extract_long(cret, 7);
1691 uret[0]->USuserpurge = extract_int(cret, 8);
1698 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret)
1703 if (!cret) return -2;
1704 if (!uret) return -2;
1706 aaa = (char *)malloc(strlen(uret->fullname) + strlen(uret->password) + 84);
1707 if (!aaa) return -1;
1709 sprintf(aaa, "ASUP %s|%s|%d|%ld|%ld|%d|%ld|%ld|%d",
1710 uret->fullname, uret->password, uret->flags,
1711 uret->timescalled, uret->posted, uret->axlevel,
1712 uret->usernum, uret->lastcall, uret->USuserpurge);
1713 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1720 /* which is 0 = room, 1 = floor, 2 = site */
1721 /* caller must free the struct ExpirePolicy */
1722 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1723 struct ExpirePolicy **policy, char *cret)
1725 static char *proto[] = {"room", "floor", "site"};
1729 if (!cret) return -2;
1730 if (!policy) return -2;
1731 if (!*policy) *policy = (struct ExpirePolicy *)calloc(1, sizeof(struct ExpirePolicy));
1732 if (!*policy) return -1;
1733 if (which < 0 || which > 2) return -2;
1735 sprintf(aaa, "GPEX %s", proto[which]);
1736 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1737 if (ret / 100 == 2) {
1738 policy[0]->expire_mode = extract_int(cret, 0);
1739 policy[0]->expire_value = extract_int(cret, 1);
1747 /* which is 0 = room, 1 = floor, 2 = site */
1748 /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */
1749 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1750 struct ExpirePolicy *policy, char *cret)
1753 char *whichvals[] = { "room", "floor", "site" };
1755 if (!cret) return -2;
1756 if (which < 0 || which > 2) return -2;
1757 if (!policy) return -2;
1758 if (policy->expire_mode < 0 || policy->expire_mode > 3) return -2;
1759 if (policy->expire_mode >= 2 && policy->expire_value < 1) return -2;
1761 sprintf(aaa, "SPEX %s|%d|%d", whichvals[which],
1762 policy->expire_mode, policy->expire_value);
1763 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1768 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret)
1772 if (!cret) return -2;
1773 if (!listing) return -2;
1774 if (*listing) return -2;
1776 return CtdlIPCGenericCommand(ipc, "CONF GET", NULL, 0,
1777 listing, &bytes, cret);
1782 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret)
1784 if (!cret) return -2;
1785 if (!listing) return -2;
1787 return CtdlIPCGenericCommand(ipc, "CONF SET", listing, strlen(listing),
1793 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1794 char **listing, char *cret)
1799 if (!cret) return -2;
1800 if (!mimetype) return -2;
1801 if (!listing) return -2;
1802 if (*listing) return -2;
1804 aaa = malloc(strlen(mimetype) + 13);
1805 if (!aaa) return -1;
1806 sprintf(aaa, "CONF GETSYS|%s", mimetype);
1807 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
1808 listing, &bytes, cret);
1813 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1814 const char *listing, char *cret)
1818 if (!cret) return -2;
1819 if (!mimetype) return -2;
1820 if (!listing) return -2;
1822 aaa = malloc(strlen(mimetype) + 13);
1823 if (!aaa) return -1;
1824 sprintf(aaa, "CONF PUTSYS|%s", mimetype);
1825 return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
1831 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret)
1835 if (!cret) return -2;
1836 if (session < 0) return -2;
1838 sprintf(aaa, "REQT %d", session);
1839 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1844 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret)
1848 if (!cret) return -2;
1849 if (msgnum < 0) return -2;
1851 sprintf(aaa, "SEEN %ld|%d", msgnum, seen ? 1 : 0);
1852 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1857 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret)
1866 /* New SSL object */
1867 temp_ssl = SSL_new(ssl_ctx);
1869 error_printf("SSL_new failed: %s\n",
1870 ERR_reason_error_string(ERR_get_error()));
1873 /* Pointless flag waving */
1874 #if SSLEAY_VERSION_NUMBER >= 0x0922
1875 SSL_set_session_id_context(temp_ssl, "Citadel/UX SID", 14);
1878 if (!access("/var/run/egd-pool", F_OK))
1879 RAND_egd("/var/run/egd-pool");
1881 if (!RAND_status()) {
1882 error_printf("PRNG not properly seeded\n");
1886 /* Associate network connection with SSL object */
1887 if (SSL_set_fd(temp_ssl, ipc->sock) < 1) {
1888 error_printf("SSL_set_fd failed: %s\n",
1889 ERR_reason_error_string(ERR_get_error()));
1893 if (status_hook != NULL)
1894 status_hook("Requesting encryption...\r");
1896 /* Ready to start SSL/TLS */
1898 CtdlIPC_putline(ipc, "STLS");
1899 CtdlIPC_getline(ipc, buf);
1900 if (buf[0] != '2') {
1901 error_printf("Server can't start TLS: %s\n", buf);
1905 r = CtdlIPCGenericCommand(ipc,
1906 "STLS", NULL, 0, NULL, NULL, cret);
1908 error_printf("Server can't start TLS: %s\n", buf);
1913 /* Do SSL/TLS handshake */
1914 if ((a = SSL_connect(temp_ssl)) < 1) {
1915 error_printf("SSL_connect failed: %s\n",
1916 ERR_reason_error_string(ERR_get_error()));
1920 ipc->ssl = temp_ssl;
1922 BIO_set_close(ipc->ssl->rbio, BIO_NOCLOSE);
1926 bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ipc->ssl), &alg_bits);
1927 error_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
1928 SSL_CIPHER_get_version(SSL_get_current_cipher(ipc->ssl)),
1929 SSL_CIPHER_get_name(SSL_get_current_cipher(ipc->ssl)),
1935 #endif /* HAVE_OPENSSL */
1940 static void endtls(SSL *ssl)
1951 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret)
1955 if (!address) return -2;
1956 if (!cret) return -2;
1958 aaa = (char *)malloc(strlen(address) + 6);
1959 if (!aaa) return -1;
1961 sprintf(aaa, "QDIR %s", address);
1962 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1967 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret)
1971 if (!cret) return -2;
1972 sprintf(aaa, "IPGM %d", secret);
1973 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1978 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret)
1982 if (!cret) return -2;
1983 if (!mret) return -2;
1984 if (*mret) return -2;
1986 return CtdlIPCGenericCommand(ipc, "FSCK", NULL, 0, mret, &size, cret);
2007 /* ************************************************************************** */
2008 /* Stuff below this line is not for public consumption */
2009 /* ************************************************************************** */
2012 inline void CtdlIPC_lock(CtdlIPC *ipc)
2014 if (ipc->network_status_cb) ipc->network_status_cb(1);
2015 #ifdef THREADED_CLIENT
2016 pthread_mutex_lock(&(ipc->mutex));
2021 inline void CtdlIPC_unlock(CtdlIPC *ipc)
2023 #ifdef THREADED_CLIENT
2024 pthread_mutex_unlock(&(ipc->mutex));
2026 if (ipc->network_status_cb) ipc->network_status_cb(0);
2030 /* Read a listing from the server up to 000. Append to dest if it exists */
2031 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest)
2040 length = strlen(ret);
2045 while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) {
2046 linelength = strlen(aaa);
2047 ret = (char *)realloc(ret, (size_t)(length + linelength + 2));
2049 strcpy(&ret[length], aaa);
2050 length += linelength;
2051 strcpy(&ret[length++], "\n");
2059 /* Send a listing to the server; generate the ending 000. */
2060 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing)
2064 text = (char *)malloc(strlen(listing) + 6);
2066 strcpy(text, listing);
2067 while (text[strlen(text) - 1] == '\n')
2068 text[strlen(text) - 1] = '\0';
2069 strcat(text, "\n000");
2070 CtdlIPC_putline(ipc, text);
2074 /* Malloc failed but we are committed to send */
2075 /* This may result in extra blanks at the bottom */
2076 CtdlIPC_putline(ipc, text);
2077 CtdlIPC_putline(ipc, "000");
2083 /* Partial read of file from server */
2084 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret)
2086 register size_t len = 0;
2090 if (!cret) return 0;
2091 if (bytes < 1) return 0;
2092 if (offset < 0) return 0;
2095 sprintf(aaa, "READ %d|%d", (int)offset, (int)bytes);
2096 CtdlIPC_putline(ipc, aaa);
2097 CtdlIPC_getline(ipc, aaa);
2099 strcpy(cret, &aaa[4]);
2101 len = extract_long(&aaa[4], 0);
2102 *buf = (void *)realloc(*buf, (size_t)(offset + len));
2104 /* I know what I'm doing */
2105 serv_read(ipc, (*buf + offset), len);
2107 /* We have to read regardless */
2108 serv_read(ipc, aaa, len);
2112 CtdlIPC_unlock(ipc);
2118 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret)
2122 if (!cret) return -2;
2123 if (!ipc->downloading) return -2;
2125 ret = CtdlIPCGenericCommand(ipc, "CLOS", NULL, 0, NULL, NULL, cret);
2127 ipc->downloading = 0;
2133 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) {
2137 snprintf(cmd, sizeof cmd, "MSGP %s", formats);
2138 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2145 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
2146 void (*progress_gauge_callback)(unsigned long, unsigned long),
2149 register size_t len;
2151 if (!cret) return -1;
2152 if (!buf) return -1;
2153 if (*buf) return -1;
2154 if (!ipc->downloading) return -1;
2157 if (progress_gauge_callback)
2158 progress_gauge_callback(len, bytes);
2159 while (len < bytes) {
2160 register size_t block;
2162 block = CtdlIPCPartialRead(ipc, buf, len, 4096, cret);
2168 if (progress_gauge_callback)
2169 progress_gauge_callback(len, bytes);
2174 /* READ - pipelined */
2175 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
2177 void (*progress_gauge_callback)(unsigned long, unsigned long),
2180 register size_t len;
2181 register int calls; /* How many calls in the pipeline */
2182 register int i; /* iterator */
2185 if (!cret) return -1;
2186 if (!buf) return -1;
2187 if (*buf) return -1;
2188 if (!ipc->downloading) return -1;
2190 *buf = (void *)realloc(*buf, bytes - resume);
2191 if (!*buf) return -1;
2195 if (progress_gauge_callback)
2196 progress_gauge_callback(len, bytes);
2198 /* How many calls will be in the pipeline? */
2199 calls = (bytes - resume) / 4096;
2200 if ((bytes - resume) % 4096) calls++;
2202 /* Send all requests at once */
2203 for (i = 0; i < calls; i++) {
2204 sprintf(aaa, "READ %d|4096", (int)(i * 4096 + resume) );
2205 CtdlIPC_putline(ipc, aaa);
2208 /* Receive all responses at once */
2209 for (i = 0; i < calls; i++) {
2210 CtdlIPC_getline(ipc, aaa);
2212 strcpy(cret, &aaa[4]);
2214 len = extract_long(&aaa[4], 0);
2215 /* I know what I'm doing */
2216 serv_read(ipc, ((*buf) + (i * 4096)), len);
2218 if (progress_gauge_callback)
2219 progress_gauge_callback(i * 4096 + len, bytes);
2221 CtdlIPC_unlock(ipc);
2227 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret)
2232 if (!cret) return -1;
2233 if (!ipc->uploading) return -1;
2235 sprintf(cmd, "UCLS %d", discard ? 0 : 1);
2236 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2243 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
2244 void (*progress_gauge_callback)(unsigned long, unsigned long),
2247 register int ret = -1;
2248 register size_t offset = 0;
2254 if (!cret) return -1;
2255 if (!path) return -1;
2256 if (!*path) return -1;
2258 fd = fopen(path, "r");
2261 fseek(fd, 0L, SEEK_END);
2265 if (progress_gauge_callback)
2266 progress_gauge_callback(0, bytes);
2268 while (offset < bytes) {
2269 register size_t to_write;
2271 /* Read some data in */
2272 to_write = fread(buf, 1, 4096, fd);
2274 if (feof(fd) || ferror(fd)) break;
2276 sprintf(aaa, "WRIT %d", (int)to_write);
2277 CtdlIPC_putline(ipc, aaa);
2278 CtdlIPC_getline(ipc, aaa);
2279 strcpy(cret, &aaa[4]);
2281 if (aaa[0] == '7') {
2282 to_write = extract_long(&aaa[4], 0);
2284 serv_write(ipc, buf, to_write);
2286 if (progress_gauge_callback)
2287 progress_gauge_callback(offset, bytes);
2288 /* Detect short reads and back up if needed */
2289 /* offset will never be negative anyway */
2290 fseek(fd, (signed)offset, SEEK_SET);
2295 if (progress_gauge_callback)
2296 progress_gauge_callback(1, 1);
2297 return (!ferror(fd) ? ret : -2);
2302 * Generic command method. This method should handle any server command
2303 * except for CHAT. It takes the following arguments:
2305 * ipc The server to speak with
2306 * command Preformatted command to send to server
2307 * to_send A text or binary file to send to server
2308 * (only sent if server requests it)
2309 * bytes_to_send The number of bytes in to_send (required if
2310 * sending binary, optional if sending listing)
2311 * to_receive Pointer to a NULL pointer, if the server
2312 * sends text or binary we will allocate memory
2313 * for the file and stuff it here
2314 * bytes_to_receive If a file is received, we will store its
2316 * proto_response The protocol response. Caller must provide
2317 * this buffer and ensure that it is at least
2318 * 128 bytes in length.
2320 * This function returns a number equal to the protocol response number,
2321 * -1 if an internal error occurred, -2 if caller provided bad values,
2322 * or 0 - the protocol response number if bad values were found during
2323 * the protocol exchange.
2324 * It stores the protocol response string (minus the number) in
2325 * protocol_response as described above. Some commands send additional
2326 * data in this string.
2328 int CtdlIPCGenericCommand(CtdlIPC *ipc,
2329 const char *command, const char *to_send,
2330 size_t bytes_to_send, char **to_receive,
2331 size_t *bytes_to_receive, char *proto_response)
2337 if (!command) return -2;
2338 if (!proto_response) return -2;
2341 if (ipc->ssl) watch_ssl = 1;
2345 CtdlIPC_putline(ipc, command);
2347 CtdlIPC_getline(ipc, proto_response);
2348 if (proto_response[3] == '*')
2350 ret = atoi(proto_response);
2351 strcpy(proto_response, &proto_response[4]);
2352 switch (ret / 100) {
2353 default: /* Unknown, punt */
2355 case 3: /* MORE_DATA */
2357 /* Don't need to do anything */
2359 case 1: /* LISTING_FOLLOWS */
2360 if (to_receive && !*to_receive && bytes_to_receive) {
2361 *to_receive = CtdlIPCReadListing(ipc, NULL);
2362 } else { /* Drain */
2363 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ;
2367 case 4: /* SEND_LISTING */
2369 CtdlIPCSendListing(ipc, to_send);
2371 /* No listing given, fake it */
2372 CtdlIPC_putline(ipc, "000");
2376 case 6: /* BINARY_FOLLOWS */
2377 if (to_receive && !*to_receive && bytes_to_receive) {
2379 extract_long(proto_response, 0);
2380 *to_receive = (char *)
2381 malloc((size_t)*bytes_to_receive);
2385 serv_read(ipc, *to_receive,
2392 drain = extract_long(proto_response, 0);
2393 while (drain > SIZ) {
2394 serv_read(ipc, buf, SIZ);
2397 serv_read(ipc, buf, drain);
2401 case 7: /* SEND_BINARY */
2402 if (to_send && bytes_to_send) {
2403 serv_write(ipc, to_send, bytes_to_send);
2404 } else if (bytes_to_send) {
2405 /* Fake it, send nulls */
2408 fake = bytes_to_send;
2409 memset(buf, '\0', SIZ);
2410 while (fake > SIZ) {
2411 serv_write(ipc, buf, SIZ);
2414 serv_write(ipc, buf, fake);
2416 } /* else who knows? DANGER WILL ROBINSON */
2418 case 8: /* START_CHAT_MODE */
2419 if (!strncasecmp(command, "CHAT", 4)) {
2420 /* Don't call chatmode with generic! */
2421 CtdlIPC_putline(ipc, "/quit");
2424 /* In this mode we send then receive listing */
2426 CtdlIPCSendListing(ipc, to_send);
2428 /* No listing given, fake it */
2429 CtdlIPC_putline(ipc, "000");
2432 if (to_receive && !*to_receive
2433 && bytes_to_receive) {
2434 *to_receive = CtdlIPCReadListing(ipc, NULL);
2435 } else { /* Drain */
2436 while (CtdlIPC_getline(ipc, buf),
2437 strcmp(buf, "000")) ;
2442 case 9: /* ASYNC_MSG */
2443 /* CtdlIPCDoAsync(ret, proto_response); */
2444 free(CtdlIPCReadListing(ipc, NULL)); /* STUB FIXME */
2450 CtdlIPC_unlock(ipc);
2455 static int connectsock(char *host, char *service, char *protocol, int defaultPort)
2457 struct hostent *phe;
2458 struct servent *pse;
2459 struct protoent *ppe;
2460 struct sockaddr_in sin;
2463 memset(&sin, 0, sizeof(sin));
2464 sin.sin_family = AF_INET;
2466 pse = getservbyname(service, protocol);
2468 sin.sin_port = pse->s_port;
2470 else if (atoi(service) > 0) {
2471 sin.sin_port = htons(atoi(service));
2474 sin.sin_port = htons(defaultPort);
2476 phe = gethostbyname(host);
2478 memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
2479 } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
2482 if ((ppe = getprotobyname(protocol)) == 0) {
2485 if (!strcmp(protocol, "udp")) {
2491 s = socket(PF_INET, type, ppe->p_proto);
2496 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
2503 static int uds_connectsock(int *isLocal, char *sockpath)
2505 struct sockaddr_un addr;
2508 memset(&addr, 0, sizeof(addr));
2509 addr.sun_family = AF_UNIX;
2510 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
2512 s = socket(AF_UNIX, SOCK_STREAM, 0);
2517 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2527 * input binary data from socket
2529 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes)
2531 unsigned int len, rlen;
2533 #if defined(HAVE_OPENSSL)
2535 serv_read_ssl(ipc, buf, bytes);
2540 while (len < bytes) {
2541 rlen = read(ipc->sock, &buf[len], bytes - len);
2543 connection_died(ipc);
2552 * send binary to server
2554 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2556 unsigned int bytes_written = 0;
2559 #if defined(HAVE_OPENSSL)
2561 serv_write_ssl(ipc, buf, nbytes);
2565 while (bytes_written < nbytes) {
2566 retval = write(ipc->sock, &buf[bytes_written],
2567 nbytes - bytes_written);
2569 connection_died(ipc);
2572 bytes_written += retval;
2579 * input binary data from encrypted connection
2581 static void serv_read_ssl(CtdlIPC* ipc, char *buf, unsigned int bytes)
2587 while (len < bytes) {
2588 if (SSL_want_read(ipc->ssl)) {
2589 if ((SSL_write(ipc->ssl, junk, 0)) < 1) {
2590 error_printf("SSL_write in serv_read:\n");
2591 ERR_print_errors_fp(stderr);
2594 rlen = SSL_read(ipc->ssl, &buf[len], bytes - len);
2598 errval = SSL_get_error(ipc->ssl, rlen);
2599 if (errval == SSL_ERROR_WANT_READ ||
2600 errval == SSL_ERROR_WANT_WRITE) {
2604 if (errval == SSL_ERROR_ZERO_RETURN ||
2605 errval == SSL_ERROR_SSL) {
2606 serv_read(ipc, &buf[len], bytes - len);
2609 error_printf("SSL_read in serv_read:\n");
2610 ERR_print_errors_fp(stderr);
2611 connection_died(ipc);
2620 * send binary to server encrypted
2622 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2624 unsigned int bytes_written = 0;
2628 while (bytes_written < nbytes) {
2629 if (SSL_want_write(ipc->ssl)) {
2630 if ((SSL_read(ipc->ssl, junk, 0)) < 1) {
2631 error_printf("SSL_read in serv_write:\n");
2632 ERR_print_errors_fp(stderr);
2635 retval = SSL_write(ipc->ssl, &buf[bytes_written],
2636 nbytes - bytes_written);
2640 errval = SSL_get_error(ipc->ssl, retval);
2641 if (errval == SSL_ERROR_WANT_READ ||
2642 errval == SSL_ERROR_WANT_WRITE) {
2646 if (errval == SSL_ERROR_ZERO_RETURN ||
2647 errval == SSL_ERROR_SSL) {
2648 serv_write(ipc, &buf[bytes_written],
2649 nbytes - bytes_written);
2652 error_printf("SSL_write in serv_write:\n");
2653 ERR_print_errors_fp(stderr);
2654 connection_died(ipc);
2657 bytes_written += retval;
2662 static void CtdlIPC_init_OpenSSL(void)
2665 SSL_METHOD *ssl_method;
2668 /* already done init */
2676 SSL_load_error_strings();
2677 SSLeay_add_ssl_algorithms();
2679 /* Set up the SSL context in which we will oeprate */
2680 ssl_method = SSLv23_client_method();
2681 ssl_ctx = SSL_CTX_new(ssl_method);
2683 error_printf("SSL_CTX_new failed: %s\n",
2684 ERR_reason_error_string(ERR_get_error()));
2687 /* Any reasonable cipher we can get */
2688 if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
2689 error_printf("No ciphers available for encryption\n");
2692 SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH);
2694 /* Load DH parameters into the context */
2697 error_printf("Can't allocate a DH object: %s\n",
2698 ERR_reason_error_string(ERR_get_error()));
2701 if (!(BN_hex2bn(&(dh->p), DH_P))) {
2702 error_printf("Can't assign DH_P: %s\n",
2703 ERR_reason_error_string(ERR_get_error()));
2707 if (!(BN_hex2bn(&(dh->g), DH_G))) {
2708 error_printf("Can't assign DH_G: %s\n",
2709 ERR_reason_error_string(ERR_get_error()));
2714 SSL_CTX_set_tmp_dh(ssl_ctx, dh);
2717 #ifdef THREADED_CLIENT
2718 /* OpenSSL requires callbacks for threaded clients */
2719 CRYPTO_set_locking_callback(ssl_lock);
2720 CRYPTO_set_id_callback(id_callback);
2722 /* OpenSSL requires us to do semaphores for threaded clients */
2723 Critters = malloc(CRYPTO_num_locks() * sizeof (pthread_mutex_t *));
2725 perror("malloc failed");
2728 for (a = 0; a < CRYPTO_num_locks(); a++) {
2729 Critters[a] = malloc(sizeof (pthread_mutex_t));
2731 perror("malloc failed");
2734 pthread_mutex_init(Critters[a], NULL);
2737 #endif /* THREADED_CLIENT */
2741 static void ssl_lock(int mode, int n, const char *file, int line)
2743 #ifdef THREADED_CLIENT
2744 if (mode & CRYPTO_LOCK)
2745 pthread_mutex_lock(Critters[n]);
2747 pthread_mutex_unlock(Critters[n]);
2748 #endif /* THREADED_CLIENT */
2751 #ifdef THREADED_CLIENT
2752 static unsigned long id_callback(void) {
2753 return (unsigned long)pthread_self();
2755 #endif /* THREADED_CLIENT */
2756 #endif /* HAVE_OPENSSL */
2760 * input string from socket - implemented in terms of serv_read()
2762 void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
2766 /* Read one character at a time. */
2768 serv_read(ipc, &buf[i], 1);
2769 if (buf[i] == '\n' || i == (SIZ-1))
2773 /* If we got a long line, discard characters until the newline. */
2775 while (buf[i] != '\n')
2776 serv_read(ipc, &buf[i], 1);
2778 /* Strip the trailing newline.
2785 * send line to server - implemented in terms of serv_write()
2787 void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
2789 /* error_printf("< %s\n", buf); */
2790 serv_write(ipc, buf, strlen(buf));
2791 serv_write(ipc, "\n", 1);
2793 ipc->last_command_sent = time(NULL);
2800 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
2807 CtdlIPC *ipc = ialloc(CtdlIPC);
2811 #if defined(HAVE_OPENSSL)
2813 CtdlIPC_init_OpenSSL();
2815 #if defined(HAVE_PTHREAD_H)
2816 pthread_mutex_init(&(ipc->mutex), NULL); /* Default fast mutex */
2818 ipc->sock = -1; /* Not connected */
2819 ipc->isLocal = 0; /* Not local, of course! */
2820 ipc->downloading = 0;
2822 ipc->last_command_sent = 0L;
2823 ipc->network_status_cb = NULL;
2825 strcpy(cithost, DEFAULT_HOST); /* default host */
2826 strcpy(citport, DEFAULT_PORT); /* default port */
2828 for (a = 0; a < argc; ++a) {
2831 } else if (a == 1) {
2832 strcpy(cithost, argv[a]);
2833 } else if (a == 2) {
2834 strcpy(citport, argv[a]);
2836 error_printf("%s: usage: ",argv[0]);
2837 error_printf("%s [host] [port] ",argv[0]);
2844 if ((!strcmp(cithost, "localhost"))
2845 || (!strcmp(cithost, "127.0.0.1"))) {
2849 /* If we're using a unix domain socket we can do a bunch of stuff */
2850 if (!strcmp(cithost, UDS)) {
2851 snprintf(sockpath, sizeof sockpath, BBSDIR "/citadel.socket");
2852 ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath);
2853 if (ipc->sock == -1) {
2857 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2858 if (portbuf != NULL) strcpy(portbuf, sockpath);
2862 ipc->sock = connectsock(cithost, citport, "tcp", 504);
2863 if (ipc->sock == -1) {
2867 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2868 if (portbuf != NULL) strcpy(portbuf, citport);
2873 * return the file descriptor of the server socket so we can select() on it.
2875 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2878 int CtdlIPC_getsockfd(CtdlIPC* ipc)
2885 * return one character
2887 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2890 char CtdlIPC_get(CtdlIPC* ipc)
2895 serv_read(ipc, buf, 1);