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, int which, int whicharg,
411 const char *mtemplate, 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);
435 while (strlen(bbb)) {
438 extract_token(aaa, bbb, 0, '\n');
440 memmove(aaa, bbb + a + 1, strlen(bbb) - a - 1);
441 *mret = (long *)realloc(mret,
442 (size_t)((count + 1) * sizeof (long)));
444 *mret[count++] = atol(aaa);
452 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
453 struct ctdlipcmessage **mret, char *cret)
459 int multipart_hunting = 0;
460 char multipart_prefix[SIZ];
462 if (!cret) return -1;
463 if (!mret) return -1;
464 if (!*mret) *mret = (struct ctdlipcmessage *)calloc(1, sizeof (struct ctdlipcmessage));
465 if (!*mret) return -1;
466 if (!msgnum) return -1;
468 strcpy(mret[0]->content_type, "");
469 sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
470 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
471 if (ret / 100 == 1) {
473 strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
474 while (strlen(bbb) > 4 && bbb[4] == '=') {
475 extract_token(aaa, bbb, 0, '\n');
476 remove_token(bbb, 0, '\n');
478 if (!strncasecmp(aaa, "nhdr=yes", 8))
480 else if (!strncasecmp(aaa, "from=", 5))
481 strcpy(mret[0]->author, &aaa[5]);
482 else if (!strncasecmp(aaa, "type=", 5))
483 mret[0]->type = atoi(&aaa[5]);
484 else if (!strncasecmp(aaa, "msgn=", 5))
485 strcpy(mret[0]->msgid, &aaa[5]);
486 else if (!strncasecmp(aaa, "subj=", 5))
487 strcpy(mret[0]->subject, &aaa[5]);
488 else if (!strncasecmp(aaa, "rfca=", 5))
489 strcpy(mret[0]->email, &aaa[5]);
490 else if (!strncasecmp(aaa, "hnod=", 5))
491 strcpy(mret[0]->hnod, &aaa[5]);
492 else if (!strncasecmp(aaa, "room=", 5))
493 strcpy(mret[0]->room, &aaa[5]);
494 else if (!strncasecmp(aaa, "node=", 5))
495 strcpy(mret[0]->node, &aaa[5]);
496 else if (!strncasecmp(aaa, "rcpt=", 5))
497 strcpy(mret[0]->recipient, &aaa[5]);
498 else if (!strncasecmp(aaa, "time=", 5))
499 mret[0]->time = atol(&aaa[5]);
501 /* Multipart/alternative prefix & suffix strings help
502 * us to determine which part we want to download.
504 else if (!strncasecmp(aaa, "pref=", 5)) {
505 extract(multipart_prefix, &aaa[5], 1);
506 if (!strcasecmp(multipart_prefix,
507 "multipart/alternative")) {
511 else if (!strncasecmp(aaa, "suff=", 5)) {
512 extract(multipart_prefix, &aaa[5], 1);
513 if (!strcasecmp(multipart_prefix,
514 "multipart/alternative")) {
519 else if (!strncasecmp(aaa, "part=", 5)) {
520 struct parts *ptr, *chain;
522 ptr = (struct parts *)calloc(1, sizeof (struct parts));
525 /* Fill the buffers for the caller */
526 extract(ptr->name, &aaa[5], 0);
527 extract(ptr->filename, &aaa[5], 1);
528 extract(ptr->number, &aaa[5], 2);
529 extract(ptr->disposition, &aaa[5], 3);
530 extract(ptr->mimetype, &aaa[5], 4);
531 ptr->length = extract_long(&aaa[5], 5);
532 if (!mret[0]->attachments)
533 mret[0]->attachments = ptr;
535 chain = mret[0]->attachments;
541 /* Now handle multipart/alternative */
542 if (multipart_hunting > 0) {
543 if ( (!strcasecmp(ptr->mimetype,
545 || (!strcasecmp(ptr->mimetype,
547 strcpy(mret[0]->mime_chosen,
555 /* Eliminate "text\n" */
556 remove_token(bbb, 0, '\n');
558 /* If doing a MIME thing, pull out the extra headers */
561 if (!strncasecmp(bbb, "Content-type: ", 14)) {
562 extract_token(mret[0]->content_type, bbb, 0, '\n');
563 strcpy(mret[0]->content_type,
564 &mret[0]->content_type[14]);
565 striplt(mret[0]->content_type);
567 remove_token(bbb, 0, '\n');
568 } while ((bbb[0] != 0) && (bbb[0] != '\n'));
569 /*ooga*/ remove_token(bbb, 0, '\n');
575 /* FIXME: Strip trailing whitespace */
576 bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1));
578 bbb = (char *)realloc(bbb, 1);
588 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret)
593 if (!cret) return -2;
594 if (!listing) return -2;
595 if (*listing) return -2;
597 ret = CtdlIPCGenericCommand(ipc, "WHOK", NULL, 0, listing, &bytes, cret);
603 int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret)
607 char *listing = NULL;
610 if (!cret) return -2;
611 if (!ServInfo) return -2;
613 ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret);
614 if (ret / 100 == 1) {
617 while (*listing && strlen(listing)) {
618 extract_token(buf, listing, 0, '\n');
619 remove_token(listing, 0, '\n');
621 case 0: ServInfo->serv_pid = atoi(buf);
623 case 1: strcpy(ServInfo->serv_nodename,buf);
625 case 2: strcpy(ServInfo->serv_humannode,buf);
627 case 3: strcpy(ServInfo->serv_fqdn,buf);
629 case 4: strcpy(ServInfo->serv_software,buf);
631 case 5: ServInfo->serv_rev_level = atoi(buf);
633 case 6: strcpy(ServInfo->serv_bbs_city,buf);
635 case 7: strcpy(ServInfo->serv_sysadm,buf);
637 case 9: strcpy(ServInfo->serv_moreprompt,buf);
639 case 10: ServInfo->serv_ok_floors = atoi(buf);
641 case 11: ServInfo->serv_paging_level = atoi(buf);
643 case 13: ServInfo->serv_supports_qnop = atoi(buf);
654 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret)
659 if (!cret) return -2;
660 if (!listing) return -2;
661 if (*listing) return -2;
663 ret = CtdlIPCGenericCommand(ipc, "RDIR", NULL, 0, listing, &bytes, cret);
669 * Set last-read pointer in this room to msgnum, or 0 for HIGHEST.
671 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret)
676 if (!cret) return -2;
679 sprintf(aaa, "SLRP %ld", msgnum);
681 sprintf(aaa, "SLRP HIGHEST");
682 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
688 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret)
693 if (!cret) return -2;
694 if (!username) return -2;
696 aaa = (char *)malloc(strlen(username) + 6);
699 sprintf(aaa, "INVT %s", username);
700 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
707 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret)
712 if (!cret) return -1;
713 if (!username) return -1;
715 aaa = (char *)malloc(strlen(username) + 6);
717 sprintf(aaa, "KICK %s", username);
718 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
725 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct quickroom **qret, char *cret)
729 if (!cret) return -2;
730 if (!qret) return -2;
731 if (!*qret) *qret = (struct quickroom *)calloc(1, sizeof (struct quickroom));
732 if (!*qret) return -1;
734 ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
735 if (ret / 100 == 2) {
736 extract(qret[0]->QRname, cret, 0);
737 extract(qret[0]->QRpasswd, cret, 1);
738 extract(qret[0]->QRdirname, cret, 2);
739 qret[0]->QRflags = extract_int(cret, 3);
740 qret[0]->QRfloor = extract_int(cret, 4);
741 qret[0]->QRorder = extract_int(cret, 5);
742 qret[0]->QRdefaultview = extract_int(cret, 6);
743 qret[0]->QRflags2 = extract_int(cret, 7);
750 /* set forget to kick all users out of room */
751 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct quickroom *qret, char *cret)
756 if (!cret) return -2;
757 if (!qret) return -2;
759 aaa = (char *)malloc(strlen(qret->QRname) + strlen(qret->QRpasswd) +
760 strlen(qret->QRdirname) + 52);
763 sprintf(aaa, "SETR %s|%s|%s|%d|%d|%d|%d",
764 qret->QRname, qret->QRpasswd, qret->QRdirname,
765 qret->QRflags, forget, qret->QRfloor, qret->QRorder);
766 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
773 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret)
775 if (!cret) return -1;
777 return CtdlIPCGenericCommand(ipc, "GETA", NULL, 0, NULL, NULL, cret);
782 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret)
787 if (!cret) return -2;
788 if (!username) return -2;
790 aaa = (char *)malloc(strlen(username) + 6);
793 sprintf(aaa, "SETA %s", username);
794 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
801 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret)
806 if (!cret) return -2;
809 aaa = (char *)malloc(strlen(mr->recipient) + strlen(mr->author) + 40);
812 sprintf(aaa, "ENT0 %d|%s|%d|%d|%s", flag, mr->recipient, mr->anonymous,
813 mr->type, mr->author);
814 ret = CtdlIPCGenericCommand(ipc, aaa, mr->text, strlen(mr->text), NULL,
822 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret)
826 if (!cret) return -2;
827 if (!iret) return -2;
828 if (*iret) return -2;
830 return CtdlIPCGenericCommand(ipc, "RINF", NULL, 0, iret, &bytes, cret);
835 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret)
839 if (!cret) return -2;
840 if (!msgnum) return -2;
842 sprintf(aaa, "DELE %ld", msgnum);
843 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
848 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret)
853 if (!cret) return -2;
854 if (!destroom) return -2;
855 if (!msgnum) return -2;
857 aaa = (char *)malloc(strlen(destroom) + 28);
860 sprintf(aaa, "MOVE %ld|%s|%d", msgnum, destroom, copy);
861 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
868 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret)
872 if (!cret) return -2;
874 sprintf(aaa, "KILL %d", for_real);
875 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
880 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type,
881 const char *password, int floor, char *cret)
886 if (!cret) return -2;
887 if (!roomname) return -2;
890 aaa = (char *)malloc(strlen(roomname) + strlen(password) + 40);
892 sprintf(aaa, "CRE8 %d|%s|%d|%s|%d", for_real, roomname, type,
895 aaa = (char *)malloc(strlen(roomname) + 40);
897 sprintf(aaa, "CRE8 %d|%s|%d||%d", for_real, roomname, type,
900 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
907 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret)
909 if (!cret) return -2;
911 return CtdlIPCGenericCommand(ipc, "FORG", NULL, 0, NULL, NULL, cret);
916 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret)
922 if (!cret) return -2;
923 if (!mret) return -2;
924 if (*mret) return -2;
925 if (!message) return -2;
927 aaa = (char *)malloc(strlen(message) + 6);
930 sprintf(aaa, "MESG %s", message);
931 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, mret, &bytes, cret);
938 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret)
940 if (!cret) return -2;
942 return CtdlIPCGenericCommand(ipc, "GNUR", NULL, 0, NULL, NULL, cret);
947 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret)
953 if (!cret) return -2;
954 if (!rret) return -2;
955 if (*rret) return -2;
958 aaa = (char *)malloc(strlen(username) + 6);
960 aaa = (char *)malloc(12);
964 sprintf(aaa, "GREG %s", username);
966 sprintf(aaa, "GREG _SELF_");
967 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, rret, &bytes, cret);
974 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret)
979 if (!cret) return -2;
980 if (!username) return -2;
981 if (axlevel < 0 || axlevel > 7) return -2;
983 aaa = (char *)malloc(strlen(username) + 17);
986 sprintf(aaa, "VALI %s|%d", username, axlevel);
987 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
994 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret)
998 if (!cret) return -1;
999 if (!info) return -1;
1001 sprintf(aaa, "EINF %d", for_real);
1002 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1007 int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret)
1011 if (!cret) return -1;
1012 if (!listing) return -1;
1013 if (*listing) return -1;
1015 return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret);
1020 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret)
1022 if (!cret) return -1;
1023 if (!info) return -1;
1025 return CtdlIPCGenericCommand(ipc, "REGI", info, strlen(info),
1031 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret)
1035 if (!cret) return -1;
1036 if (!chek) return -1;
1038 ret = CtdlIPCGenericCommand(ipc, "CHEK", NULL, 0, NULL, NULL, cret);
1039 if (ret / 100 == 2) {
1040 chek->newmail = extract_long(cret, 0);
1041 chek->needregis = extract_int(cret, 1);
1042 chek->needvalid = extract_int(cret, 2);
1049 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret)
1054 if (!cret) return -2;
1055 if (!filename) return -2;
1057 aaa = (char *)malloc(strlen(filename) + 6);
1058 if (!aaa) return -1;
1060 sprintf(aaa, "DELF %s", filename);
1061 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1068 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret)
1073 if (!cret) return -2;
1074 if (!filename) return -2;
1075 if (!destroom) return -2;
1077 aaa = (char *)malloc(strlen(filename) + strlen(destroom) + 7);
1078 if (!aaa) return -1;
1080 sprintf(aaa, "MOVF %s|%s", filename, destroom);
1081 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1088 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret)
1093 if (!cret) return -2;
1094 if (!filename) return -2;
1095 if (!destnode) return -2;
1097 aaa = (char *)malloc(strlen(filename) + strlen(destnode) + 7);
1098 if (!aaa) return -1;
1100 sprintf(aaa, "NETF %s|%s", filename, destnode);
1101 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1108 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret)
1113 if (!cret) return -1;
1114 if (!listing) return -1;
1115 if (*listing) return -1;
1117 *stamp = CtdlIPCServerTime(ipc, cret);
1119 *stamp = time(NULL);
1120 ret = CtdlIPCGenericCommand(ipc, "RWHO", NULL, 0, listing, &bytes, cret);
1126 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
1128 void (*progress_gauge_callback)(unsigned long, unsigned long),
1137 if (!cret) return -2;
1138 if (!filename) return -2;
1139 if (!buf) return -2;
1140 if (*buf) return -2;
1141 if (ipc->downloading) return -2;
1143 aaa = (char *)malloc(strlen(filename) + 6);
1144 if (!aaa) return -1;
1146 sprintf(aaa, "OPEN %s", filename);
1147 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1149 if (ret / 100 == 2) {
1150 ipc->downloading = 1;
1151 bytes = extract_long(cret, 0);
1152 last_mod = extract_int(cret, 1);
1153 extract(mimetype, cret, 2);
1154 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret); */
1155 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret);
1156 ret = CtdlIPCEndDownload(ipc, cret);
1158 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1159 filename, mimetype);
1166 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
1168 void (*progress_gauge_callback)(unsigned long, unsigned long),
1178 if (!cret) return -2;
1179 if (!buf) return -2;
1180 if (*buf) return -2;
1181 if (!part) return -2;
1182 if (!msgnum) return -2;
1183 if (ipc->downloading) return -2;
1185 aaa = (char *)malloc(strlen(part) + 17);
1186 if (!aaa) return -1;
1188 sprintf(aaa, "OPNA %ld|%s", msgnum, part);
1189 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1191 if (ret / 100 == 2) {
1192 ipc->downloading = 1;
1193 bytes = extract_long(cret, 0);
1194 last_mod = extract_int(cret, 1);
1195 extract(mimetype, cret, 2);
1196 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1197 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1198 ret = CtdlIPCEndDownload(ipc, cret);
1200 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1201 filename, mimetype);
1208 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
1209 void (*progress_gauge_callback)(unsigned long, unsigned long),
1218 if (!cret) return -1;
1219 if (!buf) return -1;
1220 if (*buf) return -1;
1221 if (!filename) return -1;
1222 if (ipc->downloading) return -1;
1224 aaa = (char *)malloc(strlen(filename) + 6);
1225 if (!aaa) return -1;
1227 sprintf(aaa, "OIMG %s", filename);
1228 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1230 if (ret / 100 == 2) {
1231 ipc->downloading = 1;
1232 bytes = extract_long(cret, 0);
1233 last_mod = extract_int(cret, 1);
1234 extract(mimetype, cret, 2);
1235 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1236 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1237 ret = CtdlIPCEndDownload(ipc, cret);
1239 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1240 filename, mimetype);
1247 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
1249 void (*progress_gauge_callback)(unsigned long, unsigned long),
1255 if (!cret) return -1;
1256 if (!save_as) return -1;
1257 if (!comment) return -1;
1258 if (!path) return -1;
1259 if (!*path) return -1;
1260 if (ipc->uploading) return -1;
1262 aaa = (char *)malloc(strlen(save_as) + strlen(comment) + 7);
1263 if (!aaa) return -1;
1265 sprintf(aaa, "UOPN %s|%s", save_as, comment);
1266 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1268 if (ret / 100 == 2) {
1270 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1271 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1279 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
1280 const char *save_as,
1281 void (*progress_gauge_callback)(unsigned long, unsigned long),
1287 if (!cret) return -1;
1288 if (!save_as) return -1;
1289 if (!path && for_real) return -1;
1290 if (!*path && for_real) return -1;
1291 if (ipc->uploading) return -1;
1293 aaa = (char *)malloc(strlen(save_as) + 17);
1294 if (!aaa) return -1;
1296 sprintf(aaa, "UIMG %d|%s", for_real, save_as);
1297 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1299 if (ret / 100 == 2 && for_real) {
1301 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1302 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1310 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret)
1315 if (!cret) return -2;
1316 if (!username) return -2;
1318 aaa = (char *)malloc(strlen(username) + 6);
1319 if (!aaa) return -1;
1321 sprintf(aaa, "QUSR %s", username);
1322 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1329 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret)
1333 if (!cret) return -2;
1334 if (!listing) return -2;
1335 if (*listing) return -2;
1337 return CtdlIPCGenericCommand(ipc, "LFLR", NULL, 0, listing, &bytes, cret);
1342 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret)
1347 if (!cret) return -2;
1348 if (!name) return -2;
1349 if (!*name) return -2;
1351 aaa = (char *)malloc(strlen(name) + 17);
1352 if (!aaa) return -1;
1354 sprintf(aaa, "CFLR %s|%d", name, for_real);
1355 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1362 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret)
1366 if (!cret) return -1;
1367 if (floornum < 0) return -1;
1369 sprintf(aaa, "KFLR %d|%d", floornum, for_real);
1370 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1375 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret)
1380 if (!cret) return -2;
1381 if (!floorname) return -2;
1382 if (floornum < 0) return -2;
1384 aaa = (char *)malloc(strlen(floorname) + 17);
1385 if (!aaa) return -1;
1387 sprintf(aaa, "EFLR %d|%s", floornum, floorname);
1388 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1397 * You only need to fill out hostname, the defaults will be used if any of the
1398 * other fields are not set properly.
1400 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
1401 int revision, const char *software_name, const char *hostname,
1407 if (developerid < 0 || clientid < 0 || revision < 0 ||
1411 revision = REV_LEVEL - 600;
1412 software_name = "Citadel/UX (libcitadel)";
1414 if (!hostname) return -2;
1416 aaa = (char *)malloc(strlen(software_name) + strlen(hostname) + 29);
1417 if (!aaa) return -1;
1419 sprintf(aaa, "IDEN %d|%d|%d|%s|%s", developerid, clientid,
1420 revision, software_name, hostname);
1421 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1428 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text,
1434 if (!cret) return -2;
1435 if (!username) return -2;
1437 aaa = (char *)malloc(strlen(username) + 8);
1438 if (!aaa) return -1;
1441 sprintf(aaa, "SEXP %s|-", username);
1442 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text),
1445 sprintf(aaa, "SEXP %s||", username);
1446 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1454 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret)
1458 if (!cret) return -2;
1459 if (!listing) return -2;
1460 if (*listing) return -2;
1462 return CtdlIPCGenericCommand(ipc, "GEXP", NULL, 0, listing, &bytes, cret);
1467 /* mode is 0 = enable, 1 = disable, 2 = status */
1468 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret)
1472 if (!cret) return -2;
1474 sprintf(aaa, "DEXP %d", mode);
1475 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1480 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret)
1482 if (!cret) return -2;
1483 if (!bio) return -2;
1485 return CtdlIPCGenericCommand(ipc, "EBIO", bio, strlen(bio),
1491 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret)
1497 if (!cret) return -2;
1498 if (!username) return -2;
1499 if (!listing) return -2;
1500 if (*listing) return -2;
1502 aaa = (char *)malloc(strlen(username) + 6);
1503 if (!aaa) return -1;
1505 sprintf(aaa, "RBIO %s", username);
1506 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, listing, &bytes, cret);
1513 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret)
1517 if (!cret) return -2;
1518 if (!listing) return -2;
1519 if (*listing) return -2;
1521 return CtdlIPCGenericCommand(ipc, "LBIO", NULL, 0, listing, &bytes, cret);
1526 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret)
1530 if (!cret) return -1;
1532 sprintf(aaa, "STEL %d", mode ? 1 : 0);
1533 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1538 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret)
1542 if (!cret) return -1;
1544 sprintf(aaa, "TERM %d", sid);
1545 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1550 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret)
1552 if (!cret) return -1;
1554 return CtdlIPCGenericCommand(ipc, "DOWN", NULL, 0, NULL, NULL, cret);
1559 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret)
1563 if (!cret) return -1;
1565 sprintf(aaa, "SCDN %d", mode ? 1 : 0);
1566 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1571 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
1577 if (!cret) return -2;
1578 if (!text) return -2;
1579 if (!filename) return -2;
1581 aaa = (char *)malloc(strlen(filename) + 6);
1582 if (!aaa) return -1;
1584 sprintf(aaa, "EMSG %s", filename);
1585 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret);
1592 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret)
1597 if (!cret) return -2;
1598 if (!hostname) return -2;
1600 aaa = (char *)malloc(strlen(hostname) + 6);
1601 if (!aaa) return -1;
1603 sprintf(aaa, "HCHG %s", hostname);
1604 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1611 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret)
1616 if (!cret) return -2;
1617 if (!roomname) return -2;
1619 aaa = (char *)malloc(strlen(roomname) + 6);
1620 if (!aaa) return -1;
1622 sprintf(aaa, "RCHG %s", roomname);
1623 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1630 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret)
1635 if (!cret) return -2;
1636 if (!username) return -2;
1638 aaa = (char *)malloc(strlen(username) + 6);
1639 if (!aaa) return -1;
1641 sprintf(aaa, "UCHG %s", username);
1642 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1649 /* This function returns the actual server time reported, or 0 if error */
1650 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *cret)
1652 register time_t tret;
1655 ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret);
1656 if (ret / 100 == 2) {
1657 tret = extract_long(cret, 0);
1666 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
1667 struct usersupp **uret, char *cret)
1672 if (!cret) return -2;
1673 if (!uret) return -2;
1674 if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof(struct usersupp));
1675 if (!*uret) return -1;
1677 sprintf(aaa, "AGUP %s", who);
1678 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1680 if (ret / 100 == 2) {
1681 extract(uret[0]->fullname, cret, 0);
1682 extract(uret[0]->password, cret, 1);
1683 uret[0]->flags = extract_int(cret, 2);
1684 uret[0]->timescalled = extract_long(cret, 3);
1685 uret[0]->posted = extract_long(cret, 4);
1686 uret[0]->axlevel = extract_int(cret, 5);
1687 uret[0]->usernum = extract_long(cret, 6);
1688 uret[0]->lastcall = extract_long(cret, 7);
1689 uret[0]->USuserpurge = extract_int(cret, 8);
1696 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret)
1701 if (!cret) return -2;
1702 if (!uret) return -2;
1704 aaa = (char *)malloc(strlen(uret->fullname) + strlen(uret->password) + 84);
1705 if (!aaa) return -1;
1707 sprintf(aaa, "ASUP %s|%s|%d|%ld|%ld|%d|%ld|%ld|%d",
1708 uret->fullname, uret->password, uret->flags,
1709 uret->timescalled, uret->posted, uret->axlevel,
1710 uret->usernum, uret->lastcall, uret->USuserpurge);
1711 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1718 /* which is 0 = room, 1 = floor, 2 = site */
1719 /* caller must free the struct ExpirePolicy */
1720 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1721 struct ExpirePolicy **policy, char *cret)
1723 static char *proto[] = {"room", "floor", "site"};
1727 if (!cret) return -2;
1728 if (!policy) return -2;
1729 if (!*policy) *policy = (struct ExpirePolicy *)calloc(1, sizeof(struct ExpirePolicy));
1730 if (!*policy) return -1;
1731 if (which < 0 || which > 2) return -2;
1733 sprintf(aaa, "GPEX %s", proto[which]);
1734 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1735 if (ret / 100 == 2) {
1736 policy[0]->expire_mode = extract_int(cret, 0);
1737 policy[0]->expire_value = extract_int(cret, 1);
1745 /* which is 0 = room, 1 = floor, 2 = site */
1746 /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */
1747 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1748 struct ExpirePolicy *policy, char *cret)
1751 char *whichvals[] = { "room", "floor", "site" };
1753 if (!cret) return -2;
1754 if (which < 0 || which > 2) return -2;
1755 if (!policy) return -2;
1756 if (policy->expire_mode < 0 || policy->expire_mode > 3) return -2;
1757 if (policy->expire_mode >= 2 && policy->expire_value < 1) return -2;
1759 sprintf(aaa, "SPEX %s|%d|%d", whichvals[which],
1760 policy->expire_mode, policy->expire_value);
1761 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1766 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret)
1770 if (!cret) return -2;
1771 if (!listing) return -2;
1772 if (*listing) return -2;
1774 return CtdlIPCGenericCommand(ipc, "CONF GET", NULL, 0,
1775 listing, &bytes, cret);
1780 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret)
1782 if (!cret) return -2;
1783 if (!listing) return -2;
1785 return CtdlIPCGenericCommand(ipc, "CONF SET", listing, strlen(listing),
1791 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1792 char **listing, char *cret)
1797 if (!cret) return -2;
1798 if (!mimetype) return -2;
1799 if (!listing) return -2;
1800 if (*listing) return -2;
1802 aaa = malloc(strlen(mimetype) + 13);
1803 if (!aaa) return -1;
1804 sprintf(aaa, "CONF GETSYS|%s", mimetype);
1805 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
1806 listing, &bytes, cret);
1811 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1812 const char *listing, char *cret)
1816 if (!cret) return -2;
1817 if (!mimetype) return -2;
1818 if (!listing) return -2;
1820 aaa = malloc(strlen(mimetype) + 13);
1821 if (!aaa) return -1;
1822 sprintf(aaa, "CONF PUTSYS|%s", mimetype);
1823 return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
1829 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret)
1833 if (!cret) return -2;
1834 if (session < 0) return -2;
1836 sprintf(aaa, "REQT %d", session);
1837 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1842 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret)
1846 if (!cret) return -2;
1847 if (msgnum < 0) return -2;
1849 sprintf(aaa, "SEEN %ld|%d", msgnum, seen ? 1 : 0);
1850 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1855 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret)
1864 /* New SSL object */
1865 temp_ssl = SSL_new(ssl_ctx);
1867 error_printf("SSL_new failed: %s\n",
1868 ERR_reason_error_string(ERR_get_error()));
1871 /* Pointless flag waving */
1872 #if SSLEAY_VERSION_NUMBER >= 0x0922
1873 SSL_set_session_id_context(temp_ssl, "Citadel/UX SID", 14);
1876 if (!access("/var/run/egd-pool", F_OK))
1877 RAND_egd("/var/run/egd-pool");
1879 if (!RAND_status()) {
1880 error_printf("PRNG not properly seeded\n");
1884 /* Associate network connection with SSL object */
1885 if (SSL_set_fd(temp_ssl, ipc->sock) < 1) {
1886 error_printf("SSL_set_fd failed: %s\n",
1887 ERR_reason_error_string(ERR_get_error()));
1891 if (status_hook != NULL)
1892 status_hook("Requesting encryption...\r");
1894 /* Ready to start SSL/TLS */
1896 CtdlIPC_putline(ipc, "STLS");
1897 CtdlIPC_getline(ipc, buf);
1898 if (buf[0] != '2') {
1899 error_printf("Server can't start TLS: %s\n", buf);
1903 r = CtdlIPCGenericCommand(ipc,
1904 "STLS", NULL, 0, NULL, NULL, cret);
1906 error_printf("Server can't start TLS: %s\n", buf);
1911 /* Do SSL/TLS handshake */
1912 if ((a = SSL_connect(temp_ssl)) < 1) {
1913 error_printf("SSL_connect failed: %s\n",
1914 ERR_reason_error_string(ERR_get_error()));
1918 ipc->ssl = temp_ssl;
1920 BIO_set_close(ipc->ssl->rbio, BIO_NOCLOSE);
1924 bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ipc->ssl), &alg_bits);
1925 error_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
1926 SSL_CIPHER_get_version(SSL_get_current_cipher(ipc->ssl)),
1927 SSL_CIPHER_get_name(SSL_get_current_cipher(ipc->ssl)),
1933 #endif /* HAVE_OPENSSL */
1938 static void endtls(SSL *ssl)
1949 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret)
1953 if (!address) return -2;
1954 if (!cret) return -2;
1956 aaa = (char *)malloc(strlen(address) + 6);
1957 if (!aaa) return -1;
1959 sprintf(aaa, "QDIR %s", address);
1960 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1965 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret)
1969 if (!cret) return -2;
1970 sprintf(aaa, "IPGM %d", secret);
1971 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1992 /* ************************************************************************** */
1993 /* Stuff below this line is not for public consumption */
1994 /* ************************************************************************** */
1997 inline void CtdlIPC_lock(CtdlIPC *ipc)
1999 if (ipc->network_status_cb) ipc->network_status_cb(1);
2000 #ifdef THREADED_CLIENT
2001 pthread_mutex_lock(&(ipc->mutex));
2006 inline void CtdlIPC_unlock(CtdlIPC *ipc)
2008 #ifdef THREADED_CLIENT
2009 pthread_mutex_unlock(&(ipc->mutex));
2011 if (ipc->network_status_cb) ipc->network_status_cb(0);
2015 /* Read a listing from the server up to 000. Append to dest if it exists */
2016 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest)
2025 length = strlen(ret);
2032 while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) {
2033 linelength = strlen(aaa);
2034 ret = (char *)realloc(ret, (size_t)(length + linelength + 2));
2036 strcpy(&ret[length], aaa);
2037 length += linelength;
2038 strcpy(&ret[length++], "\n");
2046 /* Send a listing to the server; generate the ending 000. */
2047 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing)
2051 text = (char *)malloc(strlen(listing) + 6);
2053 strcpy(text, listing);
2054 while (text[strlen(text) - 1] == '\n')
2055 text[strlen(text) - 1] = '\0';
2056 strcat(text, "\n000");
2057 CtdlIPC_putline(ipc, text);
2061 /* Malloc failed but we are committed to send */
2062 /* This may result in extra blanks at the bottom */
2063 CtdlIPC_putline(ipc, text);
2064 CtdlIPC_putline(ipc, "000");
2070 /* Partial read of file from server */
2071 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret)
2073 register size_t len = 0;
2077 if (!cret) return 0;
2078 if (bytes < 1) return 0;
2079 if (offset < 0) return 0;
2082 sprintf(aaa, "READ %d|%d", (int)offset, (int)bytes);
2083 CtdlIPC_putline(ipc, aaa);
2084 CtdlIPC_getline(ipc, aaa);
2086 strcpy(cret, &aaa[4]);
2088 len = extract_long(&aaa[4], 0);
2089 *buf = (void *)realloc(*buf, (size_t)(offset + len));
2091 /* I know what I'm doing */
2092 serv_read(ipc, (*buf + offset), len);
2094 /* We have to read regardless */
2095 serv_read(ipc, aaa, len);
2099 CtdlIPC_unlock(ipc);
2105 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret)
2109 if (!cret) return -2;
2110 if (!ipc->downloading) return -2;
2112 ret = CtdlIPCGenericCommand(ipc, "CLOS", NULL, 0, NULL, NULL, cret);
2114 ipc->downloading = 0;
2120 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) {
2124 snprintf(cmd, sizeof cmd, "MSGP %s", formats);
2125 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2132 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
2133 void (*progress_gauge_callback)(unsigned long, unsigned long),
2136 register size_t len;
2138 if (!cret) return -1;
2139 if (!buf) return -1;
2140 if (*buf) return -1;
2141 if (!ipc->downloading) return -1;
2144 if (progress_gauge_callback)
2145 progress_gauge_callback(len, bytes);
2146 while (len < bytes) {
2147 register size_t block;
2149 block = CtdlIPCPartialRead(ipc, buf, len, 4096, cret);
2155 if (progress_gauge_callback)
2156 progress_gauge_callback(len, bytes);
2162 /* READ - pipelined */
2163 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
2165 void (*progress_gauge_callback)(unsigned long, unsigned long),
2168 register size_t len;
2169 register int calls; /* How many calls in the pipeline */
2170 register int i; /* iterator */
2173 if (!cret) return -1;
2174 if (!buf) return -1;
2175 if (*buf) return -1;
2176 if (!ipc->downloading) return -1;
2178 *buf = (void *)realloc(*buf, bytes - resume);
2179 if (!*buf) return -1;
2183 if (progress_gauge_callback)
2184 progress_gauge_callback(len, bytes);
2186 /* How many calls will be in the pipeline? */
2187 calls = (bytes - resume) / 4096;
2188 if ((bytes - resume) % 4096) calls++;
2190 /* Send all requests at once */
2191 for (i = 0; i < calls; i++) {
2192 sprintf(aaa, "READ %d|4096", (int)(i * 4096 + resume) );
2193 CtdlIPC_putline(ipc, aaa);
2196 /* Receive all responses at once */
2197 for (i = 0; i < calls; i++) {
2198 CtdlIPC_getline(ipc, aaa);
2200 strcpy(cret, &aaa[4]);
2202 len = extract_long(&aaa[4], 0);
2203 /* I know what I'm doing */
2204 serv_read(ipc, ((*buf) + (i * 4096)), len);
2206 if (progress_gauge_callback)
2207 progress_gauge_callback(i * 4096 + len, bytes);
2209 CtdlIPC_unlock(ipc);
2215 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret)
2220 if (!cret) return -1;
2221 if (!ipc->uploading) return -1;
2223 sprintf(cmd, "UCLS %d", discard ? 0 : 1);
2224 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2231 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
2232 void (*progress_gauge_callback)(unsigned long, unsigned long),
2235 register int ret = -1;
2236 register size_t offset = 0;
2242 if (!cret) return -1;
2243 if (!path) return -1;
2244 if (!*path) return -1;
2246 fd = fopen(path, "r");
2249 fseek(fd, 0L, SEEK_END);
2253 if (progress_gauge_callback)
2254 progress_gauge_callback(0, bytes);
2256 while (offset < bytes) {
2257 register size_t to_write;
2259 /* Read some data in */
2260 to_write = fread(buf, 1, 4096, fd);
2262 if (feof(fd) || ferror(fd)) break;
2264 sprintf(aaa, "WRIT %d", (int)to_write);
2265 CtdlIPC_putline(ipc, aaa);
2266 CtdlIPC_getline(ipc, aaa);
2267 strcpy(cret, &aaa[4]);
2269 if (aaa[0] == '7') {
2270 to_write = extract_long(&aaa[4], 0);
2272 serv_write(ipc, buf, to_write);
2274 if (progress_gauge_callback)
2275 progress_gauge_callback(offset, bytes);
2276 /* Detect short reads and back up if needed */
2277 /* offset will never be negative anyway */
2278 fseek(fd, (signed)offset, SEEK_SET);
2283 if (progress_gauge_callback)
2284 progress_gauge_callback(1, 1);
2285 return (!ferror(fd) ? ret : -2);
2290 * Generic command method. This method should handle any server command
2291 * except for CHAT. It takes the following arguments:
2293 * ipc The server to speak with
2294 * command Preformatted command to send to server
2295 * to_send A text or binary file to send to server
2296 * (only sent if server requests it)
2297 * bytes_to_send The number of bytes in to_send (required if
2298 * sending binary, optional if sending listing)
2299 * to_receive Pointer to a NULL pointer, if the server
2300 * sends text or binary we will allocate memory
2301 * for the file and stuff it here
2302 * bytes_to_receive If a file is received, we will store its
2304 * proto_response The protocol response. Caller must provide
2305 * this buffer and ensure that it is at least
2306 * 128 bytes in length.
2308 * This function returns a number equal to the protocol response number,
2309 * -1 if an internal error occurred, -2 if caller provided bad values,
2310 * or 0 - the protocol response number if bad values were found during
2311 * the protocol exchange.
2312 * It stores the protocol response string (minus the number) in
2313 * protocol_response as described above. Some commands send additional
2314 * data in this string.
2316 int CtdlIPCGenericCommand(CtdlIPC *ipc,
2317 const char *command, const char *to_send,
2318 size_t bytes_to_send, char **to_receive,
2319 size_t *bytes_to_receive, char *proto_response)
2325 if (!command) return -2;
2326 if (!proto_response) return -2;
2329 if (ipc->ssl) watch_ssl = 1;
2333 CtdlIPC_putline(ipc, command);
2335 CtdlIPC_getline(ipc, proto_response);
2336 if (proto_response[3] == '*')
2338 ret = atoi(proto_response);
2339 strcpy(proto_response, &proto_response[4]);
2340 switch (ret / 100) {
2341 default: /* Unknown, punt */
2343 case 3: /* MORE_DATA */
2345 /* Don't need to do anything */
2347 case 1: /* LISTING_FOLLOWS */
2348 if (to_receive && !*to_receive && bytes_to_receive) {
2349 *to_receive = CtdlIPCReadListing(ipc, NULL);
2350 } else { /* Drain */
2351 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ;
2355 case 4: /* SEND_LISTING */
2357 CtdlIPCSendListing(ipc, to_send);
2359 /* No listing given, fake it */
2360 CtdlIPC_putline(ipc, "000");
2364 case 6: /* BINARY_FOLLOWS */
2365 if (to_receive && !*to_receive && bytes_to_receive) {
2367 extract_long(proto_response, 0);
2368 *to_receive = (char *)
2369 malloc((size_t)*bytes_to_receive);
2373 serv_read(ipc, *to_receive,
2380 drain = extract_long(proto_response, 0);
2381 while (drain > SIZ) {
2382 serv_read(ipc, buf, SIZ);
2385 serv_read(ipc, buf, drain);
2389 case 7: /* SEND_BINARY */
2390 if (to_send && bytes_to_send) {
2391 serv_write(ipc, to_send, bytes_to_send);
2392 } else if (bytes_to_send) {
2393 /* Fake it, send nulls */
2396 fake = bytes_to_send;
2397 memset(buf, '\0', SIZ);
2398 while (fake > SIZ) {
2399 serv_write(ipc, buf, SIZ);
2402 serv_write(ipc, buf, fake);
2404 } /* else who knows? DANGER WILL ROBINSON */
2406 case 8: /* START_CHAT_MODE */
2407 if (!strncasecmp(command, "CHAT", 4)) {
2408 /* Don't call chatmode with generic! */
2409 CtdlIPC_putline(ipc, "/quit");
2412 /* In this mode we send then receive listing */
2414 CtdlIPCSendListing(ipc, to_send);
2416 /* No listing given, fake it */
2417 CtdlIPC_putline(ipc, "000");
2420 if (to_receive && !*to_receive
2421 && bytes_to_receive) {
2422 *to_receive = CtdlIPCReadListing(ipc, NULL);
2423 } else { /* Drain */
2424 while (CtdlIPC_getline(ipc, buf),
2425 strcmp(buf, "000")) ;
2430 case 9: /* ASYNC_MSG */
2431 /* CtdlIPCDoAsync(ret, proto_response); */
2432 free(CtdlIPCReadListing(ipc, NULL)); /* STUB FIXME */
2438 CtdlIPC_unlock(ipc);
2443 static int connectsock(char *host, char *service, char *protocol, int defaultPort)
2445 struct hostent *phe;
2446 struct servent *pse;
2447 struct protoent *ppe;
2448 struct sockaddr_in sin;
2451 memset(&sin, 0, sizeof(sin));
2452 sin.sin_family = AF_INET;
2454 pse = getservbyname(service, protocol);
2456 sin.sin_port = pse->s_port;
2458 else if (atoi(service) > 0) {
2459 sin.sin_port = htons(atoi(service));
2462 sin.sin_port = htons(defaultPort);
2464 phe = gethostbyname(host);
2466 memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
2467 } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
2470 if ((ppe = getprotobyname(protocol)) == 0) {
2473 if (!strcmp(protocol, "udp")) {
2479 s = socket(PF_INET, type, ppe->p_proto);
2484 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
2491 static int uds_connectsock(int *isLocal, char *sockpath)
2493 struct sockaddr_un addr;
2496 memset(&addr, 0, sizeof(addr));
2497 addr.sun_family = AF_UNIX;
2498 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
2500 s = socket(AF_UNIX, SOCK_STREAM, 0);
2505 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2515 * input binary data from socket
2517 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes)
2519 unsigned int len, rlen;
2521 #if defined(HAVE_OPENSSL)
2523 serv_read_ssl(ipc, buf, bytes);
2528 while (len < bytes) {
2529 rlen = read(ipc->sock, &buf[len], bytes - len);
2531 connection_died(ipc);
2540 * send binary to server
2542 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2544 unsigned int bytes_written = 0;
2547 #if defined(HAVE_OPENSSL)
2549 serv_write_ssl(ipc, buf, nbytes);
2553 while (bytes_written < nbytes) {
2554 retval = write(ipc->sock, &buf[bytes_written],
2555 nbytes - bytes_written);
2557 connection_died(ipc);
2560 bytes_written += retval;
2567 * input binary data from encrypted connection
2569 static void serv_read_ssl(CtdlIPC* ipc, char *buf, unsigned int bytes)
2575 while (len < bytes) {
2576 if (SSL_want_read(ipc->ssl)) {
2577 if ((SSL_write(ipc->ssl, junk, 0)) < 1) {
2578 error_printf("SSL_write in serv_read:\n");
2579 ERR_print_errors_fp(stderr);
2582 rlen = SSL_read(ipc->ssl, &buf[len], bytes - len);
2586 errval = SSL_get_error(ipc->ssl, rlen);
2587 if (errval == SSL_ERROR_WANT_READ ||
2588 errval == SSL_ERROR_WANT_WRITE) {
2592 if (errval == SSL_ERROR_ZERO_RETURN ||
2593 errval == SSL_ERROR_SSL) {
2594 serv_read(ipc, &buf[len], bytes - len);
2597 error_printf("SSL_read in serv_read:\n");
2598 ERR_print_errors_fp(stderr);
2599 connection_died(NULL);
2608 * send binary to server encrypted
2610 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2612 unsigned int bytes_written = 0;
2616 while (bytes_written < nbytes) {
2617 if (SSL_want_write(ipc->ssl)) {
2618 if ((SSL_read(ipc->ssl, junk, 0)) < 1) {
2619 error_printf("SSL_read in serv_write:\n");
2620 ERR_print_errors_fp(stderr);
2623 retval = SSL_write(ipc->ssl, &buf[bytes_written],
2624 nbytes - bytes_written);
2628 errval = SSL_get_error(ipc->ssl, retval);
2629 if (errval == SSL_ERROR_WANT_READ ||
2630 errval == SSL_ERROR_WANT_WRITE) {
2634 if (errval == SSL_ERROR_ZERO_RETURN ||
2635 errval == SSL_ERROR_SSL) {
2636 serv_write(ipc, &buf[bytes_written],
2637 nbytes - bytes_written);
2640 error_printf("SSL_write in serv_write:\n");
2641 ERR_print_errors_fp(stderr);
2642 connection_died(NULL);
2645 bytes_written += retval;
2650 static void CtdlIPC_init_OpenSSL(void)
2653 SSL_METHOD *ssl_method;
2656 /* already done init */
2664 SSL_load_error_strings();
2665 SSLeay_add_ssl_algorithms();
2667 /* Set up the SSL context in which we will oeprate */
2668 ssl_method = SSLv23_client_method();
2669 ssl_ctx = SSL_CTX_new(ssl_method);
2671 error_printf("SSL_CTX_new failed: %s\n",
2672 ERR_reason_error_string(ERR_get_error()));
2675 /* Any reasonable cipher we can get */
2676 if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
2677 error_printf("No ciphers available for encryption\n");
2680 SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH);
2682 /* Load DH parameters into the context */
2685 error_printf("Can't allocate a DH object: %s\n",
2686 ERR_reason_error_string(ERR_get_error()));
2689 if (!(BN_hex2bn(&(dh->p), DH_P))) {
2690 error_printf("Can't assign DH_P: %s\n",
2691 ERR_reason_error_string(ERR_get_error()));
2695 if (!(BN_hex2bn(&(dh->g), DH_G))) {
2696 error_printf("Can't assign DH_G: %s\n",
2697 ERR_reason_error_string(ERR_get_error()));
2702 SSL_CTX_set_tmp_dh(ssl_ctx, dh);
2705 #ifdef THREADED_CLIENT
2706 /* OpenSSL requires callbacks for threaded clients */
2707 CRYPTO_set_locking_callback(ssl_lock);
2708 CRYPTO_set_id_callback(id_callback);
2710 /* OpenSSL requires us to do semaphores for threaded clients */
2711 Critters = malloc(CRYPTO_num_locks() * sizeof (pthread_mutex_t *));
2713 perror("malloc failed");
2716 for (a = 0; a < CRYPTO_num_locks(); a++) {
2717 Critters[a] = malloc(sizeof (pthread_mutex_t));
2719 perror("malloc failed");
2722 pthread_mutex_init(Critters[a], NULL);
2725 #endif /* THREADED_CLIENT */
2729 static void ssl_lock(int mode, int n, const char *file, int line)
2731 #ifdef THREADED_CLIENT
2732 if (mode & CRYPTO_LOCK)
2733 pthread_mutex_lock(Critters[n]);
2735 pthread_mutex_unlock(Critters[n]);
2736 #endif /* THREADED_CLIENT */
2739 #ifdef THREADED_CLIENT
2740 static unsigned long id_callback(void) {
2741 return (unsigned long)pthread_self();
2743 #endif /* THREADED_CLIENT */
2744 #endif /* HAVE_OPENSSL */
2748 * input string from socket - implemented in terms of serv_read()
2750 void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
2754 /* Read one character at a time. */
2756 serv_read(ipc, &buf[i], 1);
2757 if (buf[i] == '\n' || i == (SIZ-1))
2761 /* If we got a long line, discard characters until the newline. */
2763 while (buf[i] != '\n')
2764 serv_read(ipc, &buf[i], 1);
2766 /* Strip the trailing newline.
2773 * send line to server - implemented in terms of serv_write()
2775 void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
2777 /* error_printf("< %s\n", buf); */
2778 serv_write(ipc, buf, strlen(buf));
2779 serv_write(ipc, "\n", 1);
2781 ipc->last_command_sent = time(NULL);
2788 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
2795 CtdlIPC *ipc = ialloc(CtdlIPC);
2799 #if defined(HAVE_OPENSSL)
2801 CtdlIPC_init_OpenSSL();
2803 #if defined(HAVE_PTHREAD_H)
2804 pthread_mutex_init(&(ipc->mutex), NULL); /* Default fast mutex */
2806 ipc->sock = -1; /* Not connected */
2807 ipc->isLocal = 0; /* Not local, of course! */
2808 ipc->downloading = 0;
2810 ipc->last_command_sent = 0L;
2811 ipc->network_status_cb = NULL;
2813 strcpy(cithost, DEFAULT_HOST); /* default host */
2814 strcpy(citport, DEFAULT_PORT); /* default port */
2816 for (a = 0; a < argc; ++a) {
2819 } else if (a == 1) {
2820 strcpy(cithost, argv[a]);
2821 } else if (a == 2) {
2822 strcpy(citport, argv[a]);
2824 error_printf("%s: usage: ",argv[0]);
2825 error_printf("%s [host] [port] ",argv[0]);
2832 if ((!strcmp(cithost, "localhost"))
2833 || (!strcmp(cithost, "127.0.0.1"))) {
2837 /* If we're using a unix domain socket we can do a bunch of stuff */
2838 if (!strcmp(cithost, UDS)) {
2839 snprintf(sockpath, sizeof sockpath, BBSDIR "/citadel.socket");
2840 ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath);
2841 if (ipc->sock == -1) {
2845 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2846 if (portbuf != NULL) strcpy(portbuf, sockpath);
2850 ipc->sock = connectsock(cithost, citport, "tcp", 504);
2851 if (ipc->sock == -1) {
2855 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2856 if (portbuf != NULL) strcpy(portbuf, citport);
2861 * return the file descriptor of the server socket so we can select() on it.
2863 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2866 int CtdlIPC_getsockfd(CtdlIPC* ipc)
2873 * return one character
2875 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2878 char CtdlIPC_get(CtdlIPC* ipc)
2883 serv_read(ipc, buf, 1);