5 #define DEFAULT_HOST "localhost"
7 #define DEFAULT_HOST UDS
9 #define DEFAULT_PORT "citadel"
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
17 # include <sys/time.h>
24 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <arpa/inet.h>
33 #include <netinet/in.h>
37 #ifdef THREADED_CLIENT
41 #include "citadel_ipc.h"
42 #include "citadel_decls.h"
45 #ifdef THREADED_CLIENT
46 pthread_mutex_t rwlock;
50 static SSL_CTX *ssl_ctx;
53 #ifdef THREADED_CLIENT
54 pthread_mutex_t **Critters; /* Things that need locking */
55 #endif /* THREADED_CLIENT */
57 #endif /* HAVE_OPENSSL */
60 #define INADDR_NONE 0xffffffff
63 static void (*status_hook)(char *s) = NULL;
65 void setCryptoStatusHook(void (*hook)(char *s)) {
69 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state)) {
70 ipc->network_status_cb = hook;
74 char express_msgs = 0;
77 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes);
78 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes);
80 static void serv_read_ssl(CtdlIPC *ipc, char *buf, unsigned int bytes);
81 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes);
82 static void ssl_lock(int mode, int n, const char *file, int line);
83 static void endtls(SSL *ssl);
84 #ifdef THREADED_CLIENT
85 static unsigned long id_callback(void);
86 #endif /* THREADED_CLIENT */
87 #endif /* HAVE_OPENSSL */
91 * Does nothing. The server should always return 200.
93 int CtdlIPCNoop(CtdlIPC *ipc)
97 return CtdlIPCGenericCommand(ipc, "NOOP", NULL, 0, NULL, NULL, aaa);
102 * Does nothing interesting. The server should always return 200
103 * along with your string.
105 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret)
111 if (!cret) return -2;
113 aaa = (char *)malloc((size_t)(strlen(arg) + 6));
116 sprintf(aaa, "ECHO %s", arg);
117 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
124 * Asks the server to close the connecction.
125 * Should always return 200.
127 int CtdlIPCQuit(CtdlIPC *ipc)
133 CtdlIPC_putline(ipc, "QUIT");
134 CtdlIPC_getline(ipc, aaa);
142 * Asks the server to logout. Should always return 200, even if no user
143 * was logged in. The user will not be logged in after this!
145 int CtdlIPCLogout(CtdlIPC *ipc)
151 CtdlIPC_putline(ipc, "LOUT");
152 CtdlIPC_getline(ipc, aaa);
160 * First stage of authentication - pass the username. Returns 300 if the
161 * username is able to log in, with the username correctly spelled in cret.
162 * Returns various 500 error codes if the user doesn't exist, etc.
164 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret)
169 if (!username) return -2;
170 if (!cret) return -2;
172 aaa = (char *)malloc((size_t)(strlen(username) + 6));
175 sprintf(aaa, "USER %s", username);
176 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
183 * Second stage of authentication - provide password. The server returns
184 * 200 and several arguments in cret relating to the user's account.
186 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret)
191 if (!passwd) return -2;
192 if (!cret) return -2;
194 aaa = (char *)malloc((size_t)(strlen(passwd) + 6));
197 sprintf(aaa, "PASS %s", passwd);
198 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
205 * Second stage of authentication - provide password. The server returns
206 * 200 and several arguments in cret relating to the user's account.
208 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret)
213 if (!response) return -2;
214 if (!cret) return -2;
216 aaa = (char *)malloc((size_t)(strlen(response) + 6));
219 sprintf(aaa, "PAS2 %s", response);
220 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
227 * Create a new user. This returns 200 plus the same arguments as TryPassword
228 * if selfservice is nonzero, unless there was a problem creating the account.
229 * If selfservice is zero, creates a new user but does not log out the existing
230 * user - intended for use by system administrators to create accounts on
231 * behalf of other users.
233 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice, char *cret)
238 if (!username) return -2;
239 if (!cret) return -2;
241 aaa = (char *)malloc((size_t)(strlen(username) + 6));
244 sprintf(aaa, "%s %s", selfservice ? "NEWU" : "CREU", username);
245 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
252 * Changes the user's password. Returns 200 if changed, errors otherwise.
254 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret)
259 if (!passwd) return -2;
260 if (!cret) return -2;
262 aaa = (char *)malloc((size_t)(strlen(passwd) + 6));
265 sprintf(aaa, "SETP %s", passwd);
266 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
273 /* Caller must free the march list */
274 /* Room types are defined in enum RoomList; keep these in sync! */
275 /* floor is -1 for all, or floornum */
276 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor, struct march **listing, char *cret)
279 struct march *march = NULL;
280 static char *proto[] =
281 {"LKRA", "LKRN", "LKRO", "LZRM", "LRMS", "LPRM" };
286 if (!listing) return -2;
287 if (*listing) return -2; /* Free the listing first */
288 if (!cret) return -2;
289 /* if (which < 0 || which > 4) return -2; */
290 if (floor < -1) return -2; /* Can't validate upper bound, sorry */
292 sprintf(aaa, "%s %d", proto[which], floor);
293 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
294 if (ret / 100 == 1) {
297 while (bbb && strlen(bbb)) {
300 extract_token(aaa, bbb, 0, '\n');
302 memmove(bbb, bbb + a + 1, strlen(bbb) - a);
303 mptr = (struct march *) malloc(sizeof (struct march));
306 extract(mptr->march_name, aaa, 0);
307 mptr->march_flags = (unsigned int) extract_int(aaa, 1);
308 mptr->march_floor = (char) extract_int(aaa, 2);
309 mptr->march_order = (char) extract_int(aaa, 3);
310 mptr->march_flags2 = (unsigned int) extract_int(aaa, 4);
311 mptr->march_access = (char) extract_int(aaa, 5);
318 while (mptr2->next != NULL)
331 /* Caller must free the struct ctdluser; caller may pass an existing one */
332 int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret)
336 if (!cret) return -2;
337 if (!uret) return -2;
338 if (!*uret) *uret = (struct ctdluser *)calloc(1, sizeof (struct ctdluser));
339 if (!*uret) return -1;
341 ret = CtdlIPCGenericCommand(ipc, "GETU", NULL, 0, NULL, NULL, cret);
342 if (ret / 100 == 2) {
343 uret[0]->USscreenwidth = extract_int(cret, 0);
344 uret[0]->USscreenheight = extract_int(cret, 1);
345 uret[0]->flags = extract_int(cret, 2);
352 int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret)
356 if (!uret) return -2;
357 if (!cret) return -2;
359 sprintf(aaa, "SETU %d|%d|%d",
360 uret->USscreenwidth, uret->USscreenheight,
362 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
367 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
368 struct ctdlipcroom **rret, char *cret)
373 if (!cret) return -2;
374 if (!rret) return -2;
375 if (!*rret) *rret = (struct ctdlipcroom *)calloc(1, sizeof (struct ctdlipcroom));
376 if (!*rret) return -1;
379 aaa = (char *)malloc(strlen(room) + strlen(passwd) + 7);
384 sprintf(aaa, "GOTO %s|%s", room, passwd);
386 aaa = (char *)malloc(strlen(room) + 6);
391 sprintf(aaa, "GOTO %s", room);
393 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
394 if (ret / 100 == 2) {
395 extract(rret[0]->RRname, cret, 0);
396 rret[0]->RRunread = extract_long(cret, 1);
397 rret[0]->RRtotal = extract_long(cret, 2);
398 rret[0]->RRinfoupdated = extract_int(cret, 3);
399 rret[0]->RRflags = extract_int(cret, 4);
400 rret[0]->RRhighest = extract_long(cret, 5);
401 rret[0]->RRlastread = extract_long(cret, 6);
402 rret[0]->RRismailbox = extract_int(cret, 7);
403 rret[0]->RRaide = extract_int(cret, 8);
404 rret[0]->RRnewmail = extract_long(cret, 9);
405 rret[0]->RRfloor = extract_int(cret, 10);
414 /* which is 0 = all, 1 = old, 2 = new, 3 = last, 4 = first, 5 = gt, 6 = lt */
415 /* whicharg is number of messages, applies to last, first, gt, lt */
416 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
417 const char *mtemplate, unsigned long **mret, char *cret)
420 register unsigned long count = 0;
421 static char *proto[] =
422 { "ALL", "OLD", "NEW", "LAST", "FIRST", "GT", "LT" };
427 if (!cret) return -2;
428 if (!mret) return -2;
429 if (*mret) return -2;
430 if (which < 0 || which > 6) return -2;
433 sprintf(aaa, "MSGS %s||%d", proto[which],
434 (mtemplate) ? 1 : 0);
436 sprintf(aaa, "MSGS %s|%d|%d", proto[which], whicharg,
437 (mtemplate) ? 1 : 0);
438 if (mtemplate) count = strlen(mtemplate);
439 ret = CtdlIPCGenericCommand(ipc, aaa, mtemplate, count, &bbb, &bbbsize, cret);
443 *mret = (unsigned long *)calloc(1, sizeof(unsigned long));
446 while (bbb && strlen(bbb)) {
447 extract_token(aaa, bbb, 0, '\n');
448 remove_token(bbb, 0, '\n');
449 *mret = (unsigned long *)realloc(*mret, (size_t)((count + 2) *
450 sizeof (unsigned long)));
452 (*mret)[count++] = atol(aaa);
464 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
465 struct ctdlipcmessage **mret, char *cret)
471 int multipart_hunting = 0;
472 char multipart_prefix[SIZ];
474 if (!cret) return -1;
475 if (!mret) return -1;
476 if (!*mret) *mret = (struct ctdlipcmessage *)calloc(1, sizeof (struct ctdlipcmessage));
477 if (!*mret) return -1;
478 if (!msgnum) return -1;
480 strcpy(mret[0]->content_type, "");
481 sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
482 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
483 if (ret / 100 == 1) {
485 strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
486 while (strlen(bbb) > 4 && bbb[4] == '=') {
487 extract_token(aaa, bbb, 0, '\n');
488 remove_token(bbb, 0, '\n');
490 if (!strncasecmp(aaa, "nhdr=yes", 8))
492 else if (!strncasecmp(aaa, "from=", 5))
493 strcpy(mret[0]->author, &aaa[5]);
494 else if (!strncasecmp(aaa, "type=", 5))
495 mret[0]->type = atoi(&aaa[5]);
496 else if (!strncasecmp(aaa, "msgn=", 5))
497 strcpy(mret[0]->msgid, &aaa[5]);
498 else if (!strncasecmp(aaa, "subj=", 5))
499 strcpy(mret[0]->subject, &aaa[5]);
500 else if (!strncasecmp(aaa, "rfca=", 5))
501 strcpy(mret[0]->email, &aaa[5]);
502 else if (!strncasecmp(aaa, "hnod=", 5))
503 strcpy(mret[0]->hnod, &aaa[5]);
504 else if (!strncasecmp(aaa, "room=", 5))
505 strcpy(mret[0]->room, &aaa[5]);
506 else if (!strncasecmp(aaa, "node=", 5))
507 strcpy(mret[0]->node, &aaa[5]);
508 else if (!strncasecmp(aaa, "rcpt=", 5))
509 strcpy(mret[0]->recipient, &aaa[5]);
510 else if (!strncasecmp(aaa, "time=", 5))
511 mret[0]->time = atol(&aaa[5]);
513 /* Multipart/alternative prefix & suffix strings help
514 * us to determine which part we want to download.
516 else if (!strncasecmp(aaa, "pref=", 5)) {
517 extract(multipart_prefix, &aaa[5], 1);
518 if (!strcasecmp(multipart_prefix,
519 "multipart/alternative")) {
523 else if (!strncasecmp(aaa, "suff=", 5)) {
524 extract(multipart_prefix, &aaa[5], 1);
525 if (!strcasecmp(multipart_prefix,
526 "multipart/alternative")) {
531 else if (!strncasecmp(aaa, "part=", 5)) {
532 struct parts *ptr, *chain;
534 ptr = (struct parts *)calloc(1, sizeof (struct parts));
537 /* Fill the buffers for the caller */
538 extract(ptr->name, &aaa[5], 0);
539 extract(ptr->filename, &aaa[5], 1);
540 extract(ptr->number, &aaa[5], 2);
541 extract(ptr->disposition, &aaa[5], 3);
542 extract(ptr->mimetype, &aaa[5], 4);
543 ptr->length = extract_long(&aaa[5], 5);
544 if (!mret[0]->attachments)
545 mret[0]->attachments = ptr;
547 chain = mret[0]->attachments;
553 /* Now handle multipart/alternative */
554 if (multipart_hunting > 0) {
555 if ( (!strcasecmp(ptr->mimetype,
557 || (!strcasecmp(ptr->mimetype,
559 strcpy(mret[0]->mime_chosen,
567 /* Eliminate "text\n" */
568 remove_token(bbb, 0, '\n');
570 /* If doing a MIME thing, pull out the extra headers */
573 if (!strncasecmp(bbb, "Content-type: ", 14)) {
574 extract_token(mret[0]->content_type, bbb, 0, '\n');
575 strcpy(mret[0]->content_type,
576 &mret[0]->content_type[14]);
577 striplt(mret[0]->content_type);
579 remove_token(bbb, 0, '\n');
580 } while ((bbb[0] != 0) && (bbb[0] != '\n'));
581 remove_token(bbb, 0, '\n');
587 /* FIXME: Strip trailing whitespace */
588 bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1));
590 bbb = (char *)realloc(bbb, 1);
600 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret)
605 if (!cret) return -2;
606 if (!listing) return -2;
607 if (*listing) return -2;
609 ret = CtdlIPCGenericCommand(ipc, "WHOK", NULL, 0, listing, &bytes, cret);
615 int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret)
619 char *listing = NULL;
622 if (!cret) return -2;
623 if (!ServInfo) return -2;
625 ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret);
626 if (ret / 100 == 1) {
629 while (*listing && strlen(listing)) {
630 extract_token(buf, listing, 0, '\n');
631 remove_token(listing, 0, '\n');
633 case 0: ServInfo->serv_pid = atoi(buf);
635 case 1: strcpy(ServInfo->serv_nodename,buf);
637 case 2: strcpy(ServInfo->serv_humannode,buf);
639 case 3: strcpy(ServInfo->serv_fqdn,buf);
641 case 4: strcpy(ServInfo->serv_software,buf);
643 case 5: ServInfo->serv_rev_level = atoi(buf);
645 case 6: strcpy(ServInfo->serv_bbs_city,buf);
647 case 7: strcpy(ServInfo->serv_sysadm,buf);
649 case 9: strcpy(ServInfo->serv_moreprompt,buf);
651 case 10: ServInfo->serv_ok_floors = atoi(buf);
653 case 11: ServInfo->serv_paging_level = atoi(buf);
655 case 13: ServInfo->serv_supports_qnop = atoi(buf);
666 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret)
671 if (!cret) return -2;
672 if (!listing) return -2;
673 if (*listing) return -2;
675 ret = CtdlIPCGenericCommand(ipc, "RDIR", NULL, 0, listing, &bytes, cret);
681 * Set last-read pointer in this room to msgnum, or 0 for HIGHEST.
683 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret)
688 if (!cret) return -2;
691 sprintf(aaa, "SLRP %ld", msgnum);
694 sprintf(aaa, "SLRP HIGHEST");
696 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
702 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret)
707 if (!cret) return -2;
708 if (!username) return -2;
710 aaa = (char *)malloc(strlen(username) + 6);
713 sprintf(aaa, "INVT %s", username);
714 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
721 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret)
726 if (!cret) return -1;
727 if (!username) return -1;
729 aaa = (char *)malloc(strlen(username) + 6);
731 sprintf(aaa, "KICK %s", username);
732 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
739 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret)
743 if (!cret) return -2;
744 if (!qret) return -2;
745 if (!*qret) *qret = (struct ctdlroom *)calloc(1, sizeof (struct ctdlroom));
746 if (!*qret) return -1;
748 ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
749 if (ret / 100 == 2) {
750 extract(qret[0]->QRname, cret, 0);
751 extract(qret[0]->QRpasswd, cret, 1);
752 extract(qret[0]->QRdirname, cret, 2);
753 qret[0]->QRflags = extract_int(cret, 3);
754 qret[0]->QRfloor = extract_int(cret, 4);
755 qret[0]->QRorder = extract_int(cret, 5);
756 qret[0]->QRdefaultview = extract_int(cret, 6);
757 qret[0]->QRflags2 = extract_int(cret, 7);
764 /* set forget to kick all users out of room */
765 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret, char *cret)
770 if (!cret) return -2;
771 if (!qret) return -2;
773 aaa = (char *)malloc(strlen(qret->QRname) + strlen(qret->QRpasswd) +
774 strlen(qret->QRdirname) + 52);
777 sprintf(aaa, "SETR %s|%s|%s|%d|%d|%d|%d",
778 qret->QRname, qret->QRpasswd, qret->QRdirname,
779 qret->QRflags, forget, qret->QRfloor, qret->QRorder);
780 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
787 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret)
789 if (!cret) return -1;
791 return CtdlIPCGenericCommand(ipc, "GETA", NULL, 0, NULL, NULL, cret);
796 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret)
801 if (!cret) return -2;
802 if (!username) return -2;
804 aaa = (char *)malloc(strlen(username) + 6);
807 sprintf(aaa, "SETA %s", username);
808 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
815 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret)
820 if (!cret) return -2;
823 snprintf(cmd, sizeof cmd,
824 "ENT0 %d|%s|%d|%d|%s|%s", flag, mr->recipient,
825 mr->anonymous, mr->type, mr->subject, mr->author);
826 ret = CtdlIPCGenericCommand(ipc, cmd, mr->text, strlen(mr->text), NULL,
833 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret)
837 if (!cret) return -2;
838 if (!iret) return -2;
839 if (*iret) return -2;
841 return CtdlIPCGenericCommand(ipc, "RINF", NULL, 0, iret, &bytes, cret);
846 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret)
850 if (!cret) return -2;
851 if (!msgnum) return -2;
853 sprintf(aaa, "DELE %ld", msgnum);
854 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
859 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret)
864 if (!cret) return -2;
865 if (!destroom) return -2;
866 if (!msgnum) return -2;
868 aaa = (char *)malloc(strlen(destroom) + 28);
871 sprintf(aaa, "MOVE %ld|%s|%d", msgnum, destroom, copy);
872 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
879 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret)
883 if (!cret) return -2;
885 sprintf(aaa, "KILL %d", for_real);
886 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
891 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type,
892 const char *password, int floor, char *cret)
897 if (!cret) return -2;
898 if (!roomname) return -2;
901 aaa = (char *)malloc(strlen(roomname) + strlen(password) + 40);
903 sprintf(aaa, "CRE8 %d|%s|%d|%s|%d", for_real, roomname, type,
906 aaa = (char *)malloc(strlen(roomname) + 40);
908 sprintf(aaa, "CRE8 %d|%s|%d||%d", for_real, roomname, type,
911 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
918 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret)
920 if (!cret) return -2;
922 return CtdlIPCGenericCommand(ipc, "FORG", NULL, 0, NULL, NULL, cret);
927 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret)
933 if (!cret) return -2;
934 if (!mret) return -2;
935 if (*mret) return -2;
936 if (!message) return -2;
938 aaa = (char *)malloc(strlen(message) + 6);
941 sprintf(aaa, "MESG %s", message);
942 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, mret, &bytes, cret);
949 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret)
951 if (!cret) return -2;
953 return CtdlIPCGenericCommand(ipc, "GNUR", NULL, 0, NULL, NULL, cret);
958 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret)
964 if (!cret) return -2;
965 if (!rret) return -2;
966 if (*rret) return -2;
969 aaa = (char *)malloc(strlen(username) + 6);
971 aaa = (char *)malloc(12);
975 sprintf(aaa, "GREG %s", username);
977 sprintf(aaa, "GREG _SELF_");
978 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, rret, &bytes, cret);
985 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret)
990 if (!cret) return -2;
991 if (!username) return -2;
992 if (axlevel < 0 || axlevel > 7) return -2;
994 aaa = (char *)malloc(strlen(username) + 17);
997 sprintf(aaa, "VALI %s|%d", username, axlevel);
998 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1005 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret)
1009 if (!cret) return -1;
1010 if (!info) return -1;
1012 sprintf(aaa, "EINF %d", for_real);
1013 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1018 int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret)
1022 if (!cret) return -1;
1023 if (!listing) return -1;
1024 if (*listing) return -1;
1026 return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret);
1031 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret)
1033 if (!cret) return -1;
1034 if (!info) return -1;
1036 return CtdlIPCGenericCommand(ipc, "REGI", info, strlen(info),
1042 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret)
1046 if (!cret) return -1;
1047 if (!chek) return -1;
1049 ret = CtdlIPCGenericCommand(ipc, "CHEK", NULL, 0, NULL, NULL, cret);
1050 if (ret / 100 == 2) {
1051 chek->newmail = extract_long(cret, 0);
1052 chek->needregis = extract_int(cret, 1);
1053 chek->needvalid = extract_int(cret, 2);
1060 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret)
1065 if (!cret) return -2;
1066 if (!filename) return -2;
1068 aaa = (char *)malloc(strlen(filename) + 6);
1069 if (!aaa) return -1;
1071 sprintf(aaa, "DELF %s", filename);
1072 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1079 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret)
1084 if (!cret) return -2;
1085 if (!filename) return -2;
1086 if (!destroom) return -2;
1088 aaa = (char *)malloc(strlen(filename) + strlen(destroom) + 7);
1089 if (!aaa) return -1;
1091 sprintf(aaa, "MOVF %s|%s", filename, destroom);
1092 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1099 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret)
1104 if (!cret) return -2;
1105 if (!filename) return -2;
1106 if (!destnode) return -2;
1108 aaa = (char *)malloc(strlen(filename) + strlen(destnode) + 7);
1109 if (!aaa) return -1;
1111 sprintf(aaa, "NETF %s|%s", filename, destnode);
1112 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1119 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret)
1124 if (!cret) return -1;
1125 if (!listing) return -1;
1126 if (*listing) return -1;
1128 *stamp = CtdlIPCServerTime(ipc, cret);
1130 *stamp = time(NULL);
1131 ret = CtdlIPCGenericCommand(ipc, "RWHO", NULL, 0, listing, &bytes, cret);
1137 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
1139 void (*progress_gauge_callback)(unsigned long, unsigned long),
1148 if (!cret) return -2;
1149 if (!filename) return -2;
1150 if (!buf) return -2;
1151 if (*buf) return -2;
1152 if (ipc->downloading) return -2;
1154 aaa = (char *)malloc(strlen(filename) + 6);
1155 if (!aaa) return -1;
1157 sprintf(aaa, "OPEN %s", filename);
1158 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1160 if (ret / 100 == 2) {
1161 ipc->downloading = 1;
1162 bytes = extract_long(cret, 0);
1163 last_mod = extract_int(cret, 1);
1164 extract(mimetype, cret, 2);
1165 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret); */
1166 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret);
1167 ret = CtdlIPCEndDownload(ipc, cret);
1169 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1170 filename, mimetype);
1177 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
1179 void (*progress_gauge_callback)(unsigned long, unsigned long),
1189 if (!cret) return -2;
1190 if (!buf) return -2;
1191 if (*buf) return -2;
1192 if (!part) return -2;
1193 if (!msgnum) return -2;
1194 if (ipc->downloading) return -2;
1196 sprintf(aaa, "OPNA %ld|%s", msgnum, part);
1197 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1198 if (ret / 100 == 2) {
1199 ipc->downloading = 1;
1200 bytes = extract_long(cret, 0);
1201 last_mod = extract_int(cret, 1);
1202 extract(filename, cret, 2);
1203 extract(mimetype, cret, 3);
1204 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1205 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1206 ret = CtdlIPCEndDownload(ipc, cret);
1208 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1209 filename, mimetype);
1216 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
1217 void (*progress_gauge_callback)(unsigned long, unsigned long),
1226 if (!cret) return -1;
1227 if (!buf) return -1;
1228 if (*buf) return -1;
1229 if (!filename) return -1;
1230 if (ipc->downloading) return -1;
1232 aaa = (char *)malloc(strlen(filename) + 6);
1233 if (!aaa) return -1;
1235 sprintf(aaa, "OIMG %s", filename);
1236 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1238 if (ret / 100 == 2) {
1239 ipc->downloading = 1;
1240 bytes = extract_long(cret, 0);
1241 last_mod = extract_int(cret, 1);
1242 extract(mimetype, cret, 2);
1243 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1244 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1245 ret = CtdlIPCEndDownload(ipc, cret);
1247 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1248 filename, mimetype);
1255 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
1257 void (*progress_gauge_callback)(unsigned long, unsigned long),
1263 if (!cret) return -1;
1264 if (!save_as) return -1;
1265 if (!comment) return -1;
1266 if (!path) return -1;
1267 if (!*path) return -1;
1268 if (ipc->uploading) return -1;
1270 aaa = (char *)malloc(strlen(save_as) + strlen(comment) + 7);
1271 if (!aaa) return -1;
1273 sprintf(aaa, "UOPN %s|%s", save_as, comment);
1274 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1276 if (ret / 100 == 2) {
1278 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1279 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1287 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
1288 const char *save_as,
1289 void (*progress_gauge_callback)(unsigned long, unsigned long),
1295 if (!cret) return -1;
1296 if (!save_as) return -1;
1297 if (!path && for_real) return -1;
1298 if (!*path && for_real) return -1;
1299 if (ipc->uploading) return -1;
1301 aaa = (char *)malloc(strlen(save_as) + 17);
1302 if (!aaa) return -1;
1304 sprintf(aaa, "UIMG %d|%s", for_real, save_as);
1305 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1307 if (ret / 100 == 2 && for_real) {
1309 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1310 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1318 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret)
1323 if (!cret) return -2;
1324 if (!username) return -2;
1326 aaa = (char *)malloc(strlen(username) + 6);
1327 if (!aaa) return -1;
1329 sprintf(aaa, "QUSR %s", username);
1330 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1337 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret)
1341 if (!cret) return -2;
1342 if (!listing) return -2;
1343 if (*listing) return -2;
1345 return CtdlIPCGenericCommand(ipc, "LFLR", NULL, 0, listing, &bytes, cret);
1350 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret)
1355 if (!cret) return -2;
1356 if (!name) return -2;
1358 sprintf(aaa, "CFLR %s|%d", name, for_real);
1359 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1365 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret)
1369 if (!cret) return -1;
1370 if (floornum < 0) return -1;
1372 sprintf(aaa, "KFLR %d|%d", floornum, for_real);
1373 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1378 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret)
1383 if (!cret) return -2;
1384 if (!floorname) return -2;
1385 if (floornum < 0) return -2;
1387 sprintf(aaa, "EFLR %d|%s", floornum, floorname);
1388 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1396 * You only need to fill out hostname, the defaults will be used if any of the
1397 * other fields are not set properly.
1399 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
1400 int revision, const char *software_name, const char *hostname,
1406 if (developerid < 0 || clientid < 0 || revision < 0 ||
1410 revision = REV_LEVEL - 600;
1411 software_name = "Citadel/UX (libcitadel)";
1413 if (!hostname) return -2;
1415 aaa = (char *)malloc(strlen(software_name) + strlen(hostname) + 29);
1416 if (!aaa) return -1;
1418 sprintf(aaa, "IDEN %d|%d|%d|%s|%s", developerid, clientid,
1419 revision, software_name, hostname);
1420 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1427 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text,
1433 if (!cret) return -2;
1434 if (!username) return -2;
1436 aaa = (char *)malloc(strlen(username) + 8);
1437 if (!aaa) return -1;
1440 sprintf(aaa, "SEXP %s|-", username);
1441 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text),
1444 sprintf(aaa, "SEXP %s||", username);
1445 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1453 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret)
1457 if (!cret) return -2;
1458 if (!listing) return -2;
1459 if (*listing) return -2;
1461 return CtdlIPCGenericCommand(ipc, "GEXP", NULL, 0, listing, &bytes, cret);
1466 /* mode is 0 = enable, 1 = disable, 2 = status */
1467 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret)
1471 if (!cret) return -2;
1473 sprintf(aaa, "DEXP %d", mode);
1474 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1479 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret)
1481 if (!cret) return -2;
1482 if (!bio) return -2;
1484 return CtdlIPCGenericCommand(ipc, "EBIO", bio, strlen(bio),
1490 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret)
1496 if (!cret) return -2;
1497 if (!username) return -2;
1498 if (!listing) return -2;
1499 if (*listing) return -2;
1501 aaa = (char *)malloc(strlen(username) + 6);
1502 if (!aaa) return -1;
1504 sprintf(aaa, "RBIO %s", username);
1505 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, listing, &bytes, cret);
1512 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret)
1516 if (!cret) return -2;
1517 if (!listing) return -2;
1518 if (*listing) return -2;
1520 return CtdlIPCGenericCommand(ipc, "LBIO", NULL, 0, listing, &bytes, cret);
1525 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret)
1529 if (!cret) return -1;
1531 sprintf(aaa, "STEL %d", mode ? 1 : 0);
1532 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1537 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret)
1541 if (!cret) return -1;
1543 sprintf(aaa, "TERM %d", sid);
1544 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1549 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret)
1551 if (!cret) return -1;
1553 return CtdlIPCGenericCommand(ipc, "DOWN", NULL, 0, NULL, NULL, cret);
1558 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret)
1562 if (!cret) return -1;
1564 sprintf(aaa, "SCDN %d", mode ? 1 : 0);
1565 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1570 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
1576 if (!cret) return -2;
1577 if (!text) return -2;
1578 if (!filename) return -2;
1580 aaa = (char *)malloc(strlen(filename) + 6);
1581 if (!aaa) return -1;
1583 sprintf(aaa, "EMSG %s", filename);
1584 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret);
1591 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret)
1596 if (!cret) return -2;
1597 if (!hostname) return -2;
1599 aaa = (char *)malloc(strlen(hostname) + 6);
1600 if (!aaa) return -1;
1602 sprintf(aaa, "HCHG %s", hostname);
1603 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1610 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret)
1615 if (!cret) return -2;
1616 if (!roomname) return -2;
1618 aaa = (char *)malloc(strlen(roomname) + 6);
1619 if (!aaa) return -1;
1621 sprintf(aaa, "RCHG %s", roomname);
1622 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1629 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret)
1634 if (!cret) return -2;
1635 if (!username) return -2;
1637 aaa = (char *)malloc(strlen(username) + 6);
1638 if (!aaa) return -1;
1640 sprintf(aaa, "UCHG %s", username);
1641 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1648 /* This function returns the actual server time reported, or 0 if error */
1649 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *cret)
1651 register time_t tret;
1654 ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret);
1655 if (ret / 100 == 2) {
1656 tret = extract_long(cret, 0);
1665 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
1666 struct ctdluser **uret, char *cret)
1671 if (!cret) return -2;
1672 if (!uret) return -2;
1673 if (!*uret) *uret = (struct ctdluser *)calloc(1, sizeof(struct ctdluser));
1674 if (!*uret) return -1;
1676 sprintf(aaa, "AGUP %s", who);
1677 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1679 if (ret / 100 == 2) {
1680 extract(uret[0]->fullname, cret, 0);
1681 extract(uret[0]->password, cret, 1);
1682 uret[0]->flags = extract_int(cret, 2);
1683 uret[0]->timescalled = extract_long(cret, 3);
1684 uret[0]->posted = extract_long(cret, 4);
1685 uret[0]->axlevel = extract_int(cret, 5);
1686 uret[0]->usernum = extract_long(cret, 6);
1687 uret[0]->lastcall = extract_long(cret, 7);
1688 uret[0]->USuserpurge = extract_int(cret, 8);
1695 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret)
1700 if (!cret) return -2;
1701 if (!uret) return -2;
1703 aaa = (char *)malloc(strlen(uret->fullname) + strlen(uret->password) + 84);
1704 if (!aaa) return -1;
1706 sprintf(aaa, "ASUP %s|%s|%d|%ld|%ld|%d|%ld|%ld|%d",
1707 uret->fullname, uret->password, uret->flags,
1708 uret->timescalled, uret->posted, uret->axlevel,
1709 uret->usernum, uret->lastcall, uret->USuserpurge);
1710 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1717 /* which is 0 = room, 1 = floor, 2 = site */
1718 /* caller must free the struct ExpirePolicy */
1719 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1720 struct ExpirePolicy **policy, char *cret)
1722 static char *proto[] = {"room", "floor", "site"};
1726 if (!cret) return -2;
1727 if (!policy) return -2;
1728 if (!*policy) *policy = (struct ExpirePolicy *)calloc(1, sizeof(struct ExpirePolicy));
1729 if (!*policy) return -1;
1730 if (which < 0 || which > 2) return -2;
1732 sprintf(aaa, "GPEX %s", proto[which]);
1733 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1734 if (ret / 100 == 2) {
1735 policy[0]->expire_mode = extract_int(cret, 0);
1736 policy[0]->expire_value = extract_int(cret, 1);
1744 /* which is 0 = room, 1 = floor, 2 = site */
1745 /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */
1746 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1747 struct ExpirePolicy *policy, char *cret)
1750 char *whichvals[] = { "room", "floor", "site" };
1752 if (!cret) return -2;
1753 if (which < 0 || which > 2) return -2;
1754 if (!policy) return -2;
1755 if (policy->expire_mode < 0 || policy->expire_mode > 3) return -2;
1756 if (policy->expire_mode >= 2 && policy->expire_value < 1) return -2;
1758 sprintf(aaa, "SPEX %s|%d|%d", whichvals[which],
1759 policy->expire_mode, policy->expire_value);
1760 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1765 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret)
1769 if (!cret) return -2;
1770 if (!listing) return -2;
1771 if (*listing) return -2;
1773 return CtdlIPCGenericCommand(ipc, "CONF GET", NULL, 0,
1774 listing, &bytes, cret);
1779 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret)
1781 if (!cret) return -2;
1782 if (!listing) return -2;
1784 return CtdlIPCGenericCommand(ipc, "CONF SET", listing, strlen(listing),
1790 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1791 char **listing, char *cret)
1796 if (!cret) return -2;
1797 if (!mimetype) return -2;
1798 if (!listing) return -2;
1799 if (*listing) return -2;
1801 aaa = malloc(strlen(mimetype) + 13);
1802 if (!aaa) return -1;
1803 sprintf(aaa, "CONF GETSYS|%s", mimetype);
1804 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
1805 listing, &bytes, cret);
1810 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1811 const char *listing, char *cret)
1815 if (!cret) return -2;
1816 if (!mimetype) return -2;
1817 if (!listing) return -2;
1819 aaa = malloc(strlen(mimetype) + 13);
1820 if (!aaa) return -1;
1821 sprintf(aaa, "CONF PUTSYS|%s", mimetype);
1822 return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
1828 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret)
1832 if (!cret) return -2;
1833 if (session < 0) return -2;
1835 sprintf(aaa, "REQT %d", session);
1836 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1841 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret)
1845 if (!cret) return -2;
1846 if (msgnum < 0) return -2;
1848 sprintf(aaa, "SEEN %ld|%d", msgnum, seen ? 1 : 0);
1849 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1854 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret)
1863 /* New SSL object */
1864 temp_ssl = SSL_new(ssl_ctx);
1866 error_printf("SSL_new failed: %s\n",
1867 ERR_reason_error_string(ERR_get_error()));
1870 /* Pointless flag waving */
1871 #if SSLEAY_VERSION_NUMBER >= 0x0922
1872 SSL_set_session_id_context(temp_ssl, "Citadel/UX SID", 14);
1875 if (!access("/var/run/egd-pool", F_OK))
1876 RAND_egd("/var/run/egd-pool");
1878 if (!RAND_status()) {
1879 error_printf("PRNG not properly seeded\n");
1883 /* Associate network connection with SSL object */
1884 if (SSL_set_fd(temp_ssl, ipc->sock) < 1) {
1885 error_printf("SSL_set_fd failed: %s\n",
1886 ERR_reason_error_string(ERR_get_error()));
1890 if (status_hook != NULL)
1891 status_hook("Requesting encryption...\r");
1893 /* Ready to start SSL/TLS */
1895 CtdlIPC_putline(ipc, "STLS");
1896 CtdlIPC_getline(ipc, buf);
1897 if (buf[0] != '2') {
1898 error_printf("Server can't start TLS: %s\n", buf);
1902 r = CtdlIPCGenericCommand(ipc,
1903 "STLS", NULL, 0, NULL, NULL, cret);
1905 error_printf("Server can't start TLS: %s\n", buf);
1910 /* Do SSL/TLS handshake */
1911 if ((a = SSL_connect(temp_ssl)) < 1) {
1912 error_printf("SSL_connect failed: %s\n",
1913 ERR_reason_error_string(ERR_get_error()));
1917 ipc->ssl = temp_ssl;
1919 BIO_set_close(ipc->ssl->rbio, BIO_NOCLOSE);
1923 bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ipc->ssl), &alg_bits);
1924 error_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
1925 SSL_CIPHER_get_version(SSL_get_current_cipher(ipc->ssl)),
1926 SSL_CIPHER_get_name(SSL_get_current_cipher(ipc->ssl)),
1932 #endif /* HAVE_OPENSSL */
1937 static void endtls(SSL *ssl)
1948 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret)
1952 if (!address) return -2;
1953 if (!cret) return -2;
1955 aaa = (char *)malloc(strlen(address) + 6);
1956 if (!aaa) return -1;
1958 sprintf(aaa, "QDIR %s", address);
1959 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1964 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret)
1968 if (!cret) return -2;
1969 sprintf(aaa, "IPGM %d", secret);
1970 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1975 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret)
1979 if (!cret) return -2;
1980 if (!mret) return -2;
1981 if (*mret) return -2;
1983 return CtdlIPCGenericCommand(ipc, "FSCK", NULL, 0, mret, &size, cret);
2004 /* ************************************************************************** */
2005 /* Stuff below this line is not for public consumption */
2006 /* ************************************************************************** */
2009 inline void CtdlIPC_lock(CtdlIPC *ipc)
2011 if (ipc->network_status_cb) ipc->network_status_cb(1);
2012 #ifdef THREADED_CLIENT
2013 pthread_mutex_lock(&(ipc->mutex));
2018 inline void CtdlIPC_unlock(CtdlIPC *ipc)
2020 #ifdef THREADED_CLIENT
2021 pthread_mutex_unlock(&(ipc->mutex));
2023 if (ipc->network_status_cb) ipc->network_status_cb(0);
2027 /* Read a listing from the server up to 000. Append to dest if it exists */
2028 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest)
2037 length = strlen(ret);
2042 while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) {
2043 linelength = strlen(aaa);
2044 ret = (char *)realloc(ret, (size_t)(length + linelength + 2));
2046 strcpy(&ret[length], aaa);
2047 length += linelength;
2048 strcpy(&ret[length++], "\n");
2056 /* Send a listing to the server; generate the ending 000. */
2057 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing)
2061 text = (char *)malloc(strlen(listing) + 6);
2063 strcpy(text, listing);
2064 while (text[strlen(text) - 1] == '\n')
2065 text[strlen(text) - 1] = '\0';
2066 strcat(text, "\n000");
2067 CtdlIPC_putline(ipc, text);
2071 /* Malloc failed but we are committed to send */
2072 /* This may result in extra blanks at the bottom */
2073 CtdlIPC_putline(ipc, text);
2074 CtdlIPC_putline(ipc, "000");
2080 /* Partial read of file from server */
2081 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret)
2083 register size_t len = 0;
2087 if (!cret) return 0;
2088 if (bytes < 1) return 0;
2089 if (offset < 0) return 0;
2092 sprintf(aaa, "READ %d|%d", (int)offset, (int)bytes);
2093 CtdlIPC_putline(ipc, aaa);
2094 CtdlIPC_getline(ipc, aaa);
2096 strcpy(cret, &aaa[4]);
2098 len = extract_long(&aaa[4], 0);
2099 *buf = (void *)realloc(*buf, (size_t)(offset + len));
2101 /* I know what I'm doing */
2102 serv_read(ipc, (*buf + offset), len);
2104 /* We have to read regardless */
2105 serv_read(ipc, aaa, len);
2109 CtdlIPC_unlock(ipc);
2115 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret)
2119 if (!cret) return -2;
2120 if (!ipc->downloading) return -2;
2122 ret = CtdlIPCGenericCommand(ipc, "CLOS", NULL, 0, NULL, NULL, cret);
2124 ipc->downloading = 0;
2130 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) {
2134 snprintf(cmd, sizeof cmd, "MSGP %s", formats);
2135 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2142 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
2143 void (*progress_gauge_callback)(unsigned long, unsigned long),
2146 register size_t len;
2148 if (!cret) return -1;
2149 if (!buf) return -1;
2150 if (*buf) return -1;
2151 if (!ipc->downloading) return -1;
2154 if (progress_gauge_callback)
2155 progress_gauge_callback(len, bytes);
2156 while (len < bytes) {
2157 register size_t block;
2159 block = CtdlIPCPartialRead(ipc, buf, len, 4096, cret);
2165 if (progress_gauge_callback)
2166 progress_gauge_callback(len, bytes);
2171 /* READ - pipelined */
2172 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
2174 void (*progress_gauge_callback)(unsigned long, unsigned long),
2177 register size_t len;
2178 register int calls; /* How many calls in the pipeline */
2179 register int i; /* iterator */
2182 if (!cret) return -1;
2183 if (!buf) return -1;
2184 if (*buf) return -1;
2185 if (!ipc->downloading) return -1;
2187 *buf = (void *)realloc(*buf, bytes - resume);
2188 if (!*buf) return -1;
2192 if (progress_gauge_callback)
2193 progress_gauge_callback(len, bytes);
2195 /* How many calls will be in the pipeline? */
2196 calls = (bytes - resume) / 4096;
2197 if ((bytes - resume) % 4096) calls++;
2199 /* Send all requests at once */
2200 for (i = 0; i < calls; i++) {
2201 sprintf(aaa, "READ %d|4096", (int)(i * 4096 + resume) );
2202 CtdlIPC_putline(ipc, aaa);
2205 /* Receive all responses at once */
2206 for (i = 0; i < calls; i++) {
2207 CtdlIPC_getline(ipc, aaa);
2209 strcpy(cret, &aaa[4]);
2211 len = extract_long(&aaa[4], 0);
2212 /* I know what I'm doing */
2213 serv_read(ipc, ((*buf) + (i * 4096)), len);
2215 if (progress_gauge_callback)
2216 progress_gauge_callback(i * 4096 + len, bytes);
2218 CtdlIPC_unlock(ipc);
2224 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret)
2229 if (!cret) return -1;
2230 if (!ipc->uploading) return -1;
2232 sprintf(cmd, "UCLS %d", discard ? 0 : 1);
2233 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2240 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
2241 void (*progress_gauge_callback)(unsigned long, unsigned long),
2244 register int ret = -1;
2245 register size_t offset = 0;
2251 if (!cret) return -1;
2252 if (!path) return -1;
2253 if (!*path) return -1;
2255 fd = fopen(path, "r");
2258 fseek(fd, 0L, SEEK_END);
2262 if (progress_gauge_callback)
2263 progress_gauge_callback(0, bytes);
2265 while (offset < bytes) {
2266 register size_t to_write;
2268 /* Read some data in */
2269 to_write = fread(buf, 1, 4096, fd);
2271 if (feof(fd) || ferror(fd)) break;
2273 sprintf(aaa, "WRIT %d", (int)to_write);
2274 CtdlIPC_putline(ipc, aaa);
2275 CtdlIPC_getline(ipc, aaa);
2276 strcpy(cret, &aaa[4]);
2278 if (aaa[0] == '7') {
2279 to_write = extract_long(&aaa[4], 0);
2281 serv_write(ipc, buf, to_write);
2283 if (progress_gauge_callback)
2284 progress_gauge_callback(offset, bytes);
2285 /* Detect short reads and back up if needed */
2286 /* offset will never be negative anyway */
2287 fseek(fd, (signed)offset, SEEK_SET);
2292 if (progress_gauge_callback)
2293 progress_gauge_callback(1, 1);
2294 return (!ferror(fd) ? ret : -2);
2299 * Generic command method. This method should handle any server command
2300 * except for CHAT. It takes the following arguments:
2302 * ipc The server to speak with
2303 * command Preformatted command to send to server
2304 * to_send A text or binary file to send to server
2305 * (only sent if server requests it)
2306 * bytes_to_send The number of bytes in to_send (required if
2307 * sending binary, optional if sending listing)
2308 * to_receive Pointer to a NULL pointer, if the server
2309 * sends text or binary we will allocate memory
2310 * for the file and stuff it here
2311 * bytes_to_receive If a file is received, we will store its
2313 * proto_response The protocol response. Caller must provide
2314 * this buffer and ensure that it is at least
2315 * 128 bytes in length.
2317 * This function returns a number equal to the protocol response number,
2318 * -1 if an internal error occurred, -2 if caller provided bad values,
2319 * or 0 - the protocol response number if bad values were found during
2320 * the protocol exchange.
2321 * It stores the protocol response string (minus the number) in
2322 * protocol_response as described above. Some commands send additional
2323 * data in this string.
2325 int CtdlIPCGenericCommand(CtdlIPC *ipc,
2326 const char *command, const char *to_send,
2327 size_t bytes_to_send, char **to_receive,
2328 size_t *bytes_to_receive, char *proto_response)
2334 if (!command) return -2;
2335 if (!proto_response) return -2;
2338 if (ipc->ssl) watch_ssl = 1;
2342 CtdlIPC_putline(ipc, command);
2344 CtdlIPC_getline(ipc, proto_response);
2345 if (proto_response[3] == '*')
2347 ret = atoi(proto_response);
2348 strcpy(proto_response, &proto_response[4]);
2349 switch (ret / 100) {
2350 default: /* Unknown, punt */
2352 case 3: /* MORE_DATA */
2354 /* Don't need to do anything */
2356 case 1: /* LISTING_FOLLOWS */
2357 if (to_receive && !*to_receive && bytes_to_receive) {
2358 *to_receive = CtdlIPCReadListing(ipc, NULL);
2359 } else { /* Drain */
2360 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ;
2364 case 4: /* SEND_LISTING */
2366 CtdlIPCSendListing(ipc, to_send);
2368 /* No listing given, fake it */
2369 CtdlIPC_putline(ipc, "000");
2373 case 6: /* BINARY_FOLLOWS */
2374 if (to_receive && !*to_receive && bytes_to_receive) {
2376 extract_long(proto_response, 0);
2377 *to_receive = (char *)
2378 malloc((size_t)*bytes_to_receive);
2382 serv_read(ipc, *to_receive,
2389 drain = extract_long(proto_response, 0);
2390 while (drain > SIZ) {
2391 serv_read(ipc, buf, SIZ);
2394 serv_read(ipc, buf, drain);
2398 case 7: /* SEND_BINARY */
2399 if (to_send && bytes_to_send) {
2400 serv_write(ipc, to_send, bytes_to_send);
2401 } else if (bytes_to_send) {
2402 /* Fake it, send nulls */
2405 fake = bytes_to_send;
2406 memset(buf, '\0', SIZ);
2407 while (fake > SIZ) {
2408 serv_write(ipc, buf, SIZ);
2411 serv_write(ipc, buf, fake);
2413 } /* else who knows? DANGER WILL ROBINSON */
2415 case 8: /* START_CHAT_MODE */
2416 if (!strncasecmp(command, "CHAT", 4)) {
2417 /* Don't call chatmode with generic! */
2418 CtdlIPC_putline(ipc, "/quit");
2421 /* In this mode we send then receive listing */
2423 CtdlIPCSendListing(ipc, to_send);
2425 /* No listing given, fake it */
2426 CtdlIPC_putline(ipc, "000");
2429 if (to_receive && !*to_receive
2430 && bytes_to_receive) {
2431 *to_receive = CtdlIPCReadListing(ipc, NULL);
2432 } else { /* Drain */
2433 while (CtdlIPC_getline(ipc, buf),
2434 strcmp(buf, "000")) ;
2439 case 9: /* ASYNC_MSG */
2440 /* CtdlIPCDoAsync(ret, proto_response); */
2441 free(CtdlIPCReadListing(ipc, NULL)); /* STUB FIXME */
2447 CtdlIPC_unlock(ipc);
2452 static int connectsock(char *host, char *service, char *protocol, int defaultPort)
2454 struct hostent *phe;
2455 struct servent *pse;
2456 struct protoent *ppe;
2457 struct sockaddr_in sin;
2460 memset(&sin, 0, sizeof(sin));
2461 sin.sin_family = AF_INET;
2463 pse = getservbyname(service, protocol);
2465 sin.sin_port = pse->s_port;
2467 else if (atoi(service) > 0) {
2468 sin.sin_port = htons(atoi(service));
2471 sin.sin_port = htons(defaultPort);
2473 phe = gethostbyname(host);
2475 memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
2476 } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
2479 if ((ppe = getprotobyname(protocol)) == 0) {
2482 if (!strcmp(protocol, "udp")) {
2488 s = socket(PF_INET, type, ppe->p_proto);
2493 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
2501 static int uds_connectsock(int *isLocal, char *sockpath)
2503 struct sockaddr_un addr;
2506 memset(&addr, 0, sizeof(addr));
2507 addr.sun_family = AF_UNIX;
2508 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
2510 s = socket(AF_UNIX, SOCK_STREAM, 0);
2515 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2526 * input binary data from socket
2528 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes)
2530 unsigned int len, rlen;
2532 #if defined(HAVE_OPENSSL)
2534 serv_read_ssl(ipc, buf, bytes);
2539 while (len < bytes) {
2540 rlen = read(ipc->sock, &buf[len], bytes - len);
2542 connection_died(ipc);
2551 * send binary to server
2553 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2555 unsigned int bytes_written = 0;
2558 #if defined(HAVE_OPENSSL)
2560 serv_write_ssl(ipc, buf, nbytes);
2564 while (bytes_written < nbytes) {
2565 retval = write(ipc->sock, &buf[bytes_written],
2566 nbytes - bytes_written);
2568 connection_died(ipc);
2571 bytes_written += retval;
2578 * input binary data from encrypted connection
2580 static void serv_read_ssl(CtdlIPC* ipc, char *buf, unsigned int bytes)
2586 while (len < bytes) {
2587 if (SSL_want_read(ipc->ssl)) {
2588 if ((SSL_write(ipc->ssl, junk, 0)) < 1) {
2589 error_printf("SSL_write in serv_read:\n");
2590 ERR_print_errors_fp(stderr);
2593 rlen = SSL_read(ipc->ssl, &buf[len], bytes - len);
2597 errval = SSL_get_error(ipc->ssl, rlen);
2598 if (errval == SSL_ERROR_WANT_READ ||
2599 errval == SSL_ERROR_WANT_WRITE) {
2603 if (errval == SSL_ERROR_ZERO_RETURN ||
2604 errval == SSL_ERROR_SSL) {
2605 serv_read(ipc, &buf[len], bytes - len);
2608 error_printf("SSL_read in serv_read:\n");
2609 ERR_print_errors_fp(stderr);
2610 connection_died(ipc);
2619 * send binary to server encrypted
2621 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2623 unsigned int bytes_written = 0;
2627 while (bytes_written < nbytes) {
2628 if (SSL_want_write(ipc->ssl)) {
2629 if ((SSL_read(ipc->ssl, junk, 0)) < 1) {
2630 error_printf("SSL_read in serv_write:\n");
2631 ERR_print_errors_fp(stderr);
2634 retval = SSL_write(ipc->ssl, &buf[bytes_written],
2635 nbytes - bytes_written);
2639 errval = SSL_get_error(ipc->ssl, retval);
2640 if (errval == SSL_ERROR_WANT_READ ||
2641 errval == SSL_ERROR_WANT_WRITE) {
2645 if (errval == SSL_ERROR_ZERO_RETURN ||
2646 errval == SSL_ERROR_SSL) {
2647 serv_write(ipc, &buf[bytes_written],
2648 nbytes - bytes_written);
2651 error_printf("SSL_write in serv_write:\n");
2652 ERR_print_errors_fp(stderr);
2653 connection_died(ipc);
2656 bytes_written += retval;
2661 static void CtdlIPC_init_OpenSSL(void)
2664 SSL_METHOD *ssl_method;
2667 /* already done init */
2675 SSL_load_error_strings();
2676 SSLeay_add_ssl_algorithms();
2678 /* Set up the SSL context in which we will oeprate */
2679 ssl_method = SSLv23_client_method();
2680 ssl_ctx = SSL_CTX_new(ssl_method);
2682 error_printf("SSL_CTX_new failed: %s\n",
2683 ERR_reason_error_string(ERR_get_error()));
2686 /* Any reasonable cipher we can get */
2687 if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
2688 error_printf("No ciphers available for encryption\n");
2691 SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH);
2693 /* Load DH parameters into the context */
2696 error_printf("Can't allocate a DH object: %s\n",
2697 ERR_reason_error_string(ERR_get_error()));
2700 if (!(BN_hex2bn(&(dh->p), DH_P))) {
2701 error_printf("Can't assign DH_P: %s\n",
2702 ERR_reason_error_string(ERR_get_error()));
2706 if (!(BN_hex2bn(&(dh->g), DH_G))) {
2707 error_printf("Can't assign DH_G: %s\n",
2708 ERR_reason_error_string(ERR_get_error()));
2713 SSL_CTX_set_tmp_dh(ssl_ctx, dh);
2716 #ifdef THREADED_CLIENT
2717 /* OpenSSL requires callbacks for threaded clients */
2718 CRYPTO_set_locking_callback(ssl_lock);
2719 CRYPTO_set_id_callback(id_callback);
2721 /* OpenSSL requires us to do semaphores for threaded clients */
2722 Critters = malloc(CRYPTO_num_locks() * sizeof (pthread_mutex_t *));
2724 perror("malloc failed");
2727 for (a = 0; a < CRYPTO_num_locks(); a++) {
2728 Critters[a] = malloc(sizeof (pthread_mutex_t));
2730 perror("malloc failed");
2733 pthread_mutex_init(Critters[a], NULL);
2736 #endif /* THREADED_CLIENT */
2740 static void ssl_lock(int mode, int n, const char *file, int line)
2742 #ifdef THREADED_CLIENT
2743 if (mode & CRYPTO_LOCK)
2744 pthread_mutex_lock(Critters[n]);
2746 pthread_mutex_unlock(Critters[n]);
2747 #endif /* THREADED_CLIENT */
2750 #ifdef THREADED_CLIENT
2751 static unsigned long id_callback(void) {
2752 return (unsigned long)pthread_self();
2754 #endif /* THREADED_CLIENT */
2755 #endif /* HAVE_OPENSSL */
2759 * input string from socket - implemented in terms of serv_read()
2761 void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
2765 /* Read one character at a time. */
2767 serv_read(ipc, &buf[i], 1);
2768 if (buf[i] == '\n' || i == (SIZ-1))
2772 /* If we got a long line, discard characters until the newline. */
2774 while (buf[i] != '\n')
2775 serv_read(ipc, &buf[i], 1);
2777 /* Strip the trailing newline (and carriage return, if present) */
2778 if (buf[i] == 10) buf[i--] = 0;
2779 if (buf[i] == 13) buf[i--] = 0;
2784 * send line to server - implemented in terms of serv_write()
2786 void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
2788 /* error_printf("< %s\n", buf); */
2789 serv_write(ipc, buf, strlen(buf));
2790 serv_write(ipc, "\n", 1);
2792 ipc->last_command_sent = time(NULL);
2799 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
2806 CtdlIPC *ipc = ialloc(CtdlIPC);
2810 #if defined(HAVE_OPENSSL)
2812 CtdlIPC_init_OpenSSL();
2814 #if defined(HAVE_PTHREAD_H)
2815 pthread_mutex_init(&(ipc->mutex), NULL); /* Default fast mutex */
2817 ipc->sock = -1; /* Not connected */
2818 ipc->isLocal = 0; /* Not local, of course! */
2819 ipc->downloading = 0;
2821 ipc->last_command_sent = 0L;
2822 ipc->network_status_cb = NULL;
2824 strcpy(cithost, DEFAULT_HOST); /* default host */
2825 strcpy(citport, DEFAULT_PORT); /* default port */
2827 /* Allow caller to supply our values (Windows) */
2828 if (hostbuf && strlen(hostbuf) > 0)
2829 strcpy(cithost, hostbuf);
2830 if (portbuf && strlen(portbuf) > 0)
2831 strcpy(citport, portbuf);
2833 /* Read host/port from command line if present */
2834 for (a = 0; a < argc; ++a) {
2837 } else if (a == 1) {
2838 strcpy(cithost, argv[a]);
2839 } else if (a == 2) {
2840 strcpy(citport, argv[a]);
2842 error_printf("%s: usage: ",argv[0]);
2843 error_printf("%s [host] [port] ",argv[0]);
2850 if ((!strcmp(cithost, "localhost"))
2851 || (!strcmp(cithost, "127.0.0.1"))) {
2855 /* If we're using a unix domain socket we can do a bunch of stuff */
2856 if (!strcmp(cithost, UDS)) {
2857 snprintf(sockpath, sizeof sockpath, BBSDIR "/citadel.socket");
2858 ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath);
2859 if (ipc->sock == -1) {
2863 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2864 if (portbuf != NULL) strcpy(portbuf, sockpath);
2868 ipc->sock = connectsock(cithost, citport, "tcp", 504);
2869 if (ipc->sock == -1) {
2873 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2874 if (portbuf != NULL) strcpy(portbuf, citport);
2879 * return the file descriptor of the server socket so we can select() on it.
2881 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2884 int CtdlIPC_getsockfd(CtdlIPC* ipc)
2891 * return one character
2893 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2896 char CtdlIPC_get(CtdlIPC* ipc)
2901 serv_read(ipc, buf, 1);