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);
306 mptr->march_flags2 = (unsigned int) extract_int(aaa, 4);
307 mptr->march_access = (char) extract_int(aaa, 5);
314 while (mptr2->next != NULL)
327 /* Caller must free the struct usersupp; caller may pass an existing one */
328 int CtdlIPCGetConfig(CtdlIPC *ipc, struct usersupp **uret, char *cret)
332 if (!cret) return -2;
333 if (!uret) return -2;
334 if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof (struct usersupp));
335 if (!*uret) return -1;
337 ret = CtdlIPCGenericCommand(ipc, "GETU", NULL, 0, NULL, NULL, cret);
338 if (ret / 100 == 2) {
339 uret[0]->USscreenwidth = extract_int(cret, 0);
340 uret[0]->USscreenheight = extract_int(cret, 1);
341 uret[0]->flags = extract_int(cret, 2);
348 int CtdlIPCSetConfig(CtdlIPC *ipc, struct usersupp *uret, char *cret)
352 if (!uret) return -2;
353 if (!cret) return -2;
355 sprintf(aaa, "SETU %d|%d|%d",
356 uret->USscreenwidth, uret->USscreenheight,
358 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
363 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
364 struct ctdlipcroom **rret, char *cret)
369 if (!cret) return -2;
370 if (!rret) return -2;
371 if (!*rret) *rret = (struct ctdlipcroom *)calloc(1, sizeof (struct ctdlipcroom));
372 if (!*rret) return -1;
375 aaa = (char *)malloc(strlen(room) + strlen(passwd) + 7);
380 sprintf(aaa, "GOTO %s|%s", room, passwd);
382 aaa = (char *)malloc(strlen(room) + 6);
387 sprintf(aaa, "GOTO %s", room);
389 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
390 if (ret / 100 == 2) {
391 extract(rret[0]->RRname, cret, 0);
392 rret[0]->RRunread = extract_long(cret, 1);
393 rret[0]->RRtotal = extract_long(cret, 2);
394 rret[0]->RRinfoupdated = extract_int(cret, 3);
395 rret[0]->RRflags = extract_int(cret, 4);
396 rret[0]->RRhighest = extract_long(cret, 5);
397 rret[0]->RRlastread = extract_long(cret, 6);
398 rret[0]->RRismailbox = extract_int(cret, 7);
399 rret[0]->RRaide = extract_int(cret, 8);
400 rret[0]->RRnewmail = extract_long(cret, 9);
401 rret[0]->RRfloor = extract_int(cret, 10);
410 /* which is 0 = all, 1 = old, 2 = new, 3 = last, 4 = first, 5 = gt, 6 = lt */
411 /* whicharg is number of messages, applies to last, first, gt, lt */
412 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
413 const char *mtemplate, unsigned long **mret, char *cret)
416 register unsigned long count = 0;
417 static char *proto[] =
418 { "ALL", "OLD", "NEW", "LAST", "FIRST", "GT", "LT" };
423 if (!cret) return -2;
424 if (!mret) return -2;
425 if (*mret) return -2;
426 if (which < 0 || which > 6) return -2;
429 sprintf(aaa, "MSGS %s||%d", proto[which],
430 (mtemplate) ? 1 : 0);
432 sprintf(aaa, "MSGS %s|%d|%d", proto[which], whicharg,
433 (mtemplate) ? 1 : 0);
434 if (mtemplate) count = strlen(mtemplate);
435 ret = CtdlIPCGenericCommand(ipc, aaa, mtemplate, count, &bbb, &bbbsize, cret);
439 *mret = (unsigned long *)calloc(1, sizeof(unsigned long));
442 while (bbb && strlen(bbb)) {
443 extract_token(aaa, bbb, 0, '\n');
444 remove_token(bbb, 0, '\n');
445 *mret = (unsigned long *)realloc(*mret, (size_t)((count + 2) *
446 sizeof (unsigned long)));
448 (*mret)[count++] = atol(aaa);
460 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
461 struct ctdlipcmessage **mret, char *cret)
467 int multipart_hunting = 0;
468 char multipart_prefix[SIZ];
470 if (!cret) return -1;
471 if (!mret) return -1;
472 if (!*mret) *mret = (struct ctdlipcmessage *)calloc(1, sizeof (struct ctdlipcmessage));
473 if (!*mret) return -1;
474 if (!msgnum) return -1;
476 strcpy(mret[0]->content_type, "");
477 sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
478 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
479 if (ret / 100 == 1) {
481 strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
482 while (strlen(bbb) > 4 && bbb[4] == '=') {
483 extract_token(aaa, bbb, 0, '\n');
484 remove_token(bbb, 0, '\n');
486 if (!strncasecmp(aaa, "nhdr=yes", 8))
488 else if (!strncasecmp(aaa, "from=", 5))
489 strcpy(mret[0]->author, &aaa[5]);
490 else if (!strncasecmp(aaa, "type=", 5))
491 mret[0]->type = atoi(&aaa[5]);
492 else if (!strncasecmp(aaa, "msgn=", 5))
493 strcpy(mret[0]->msgid, &aaa[5]);
494 else if (!strncasecmp(aaa, "subj=", 5))
495 strcpy(mret[0]->subject, &aaa[5]);
496 else if (!strncasecmp(aaa, "rfca=", 5))
497 strcpy(mret[0]->email, &aaa[5]);
498 else if (!strncasecmp(aaa, "hnod=", 5))
499 strcpy(mret[0]->hnod, &aaa[5]);
500 else if (!strncasecmp(aaa, "room=", 5))
501 strcpy(mret[0]->room, &aaa[5]);
502 else if (!strncasecmp(aaa, "node=", 5))
503 strcpy(mret[0]->node, &aaa[5]);
504 else if (!strncasecmp(aaa, "rcpt=", 5))
505 strcpy(mret[0]->recipient, &aaa[5]);
506 else if (!strncasecmp(aaa, "time=", 5))
507 mret[0]->time = atol(&aaa[5]);
509 /* Multipart/alternative prefix & suffix strings help
510 * us to determine which part we want to download.
512 else if (!strncasecmp(aaa, "pref=", 5)) {
513 extract(multipart_prefix, &aaa[5], 1);
514 if (!strcasecmp(multipart_prefix,
515 "multipart/alternative")) {
519 else if (!strncasecmp(aaa, "suff=", 5)) {
520 extract(multipart_prefix, &aaa[5], 1);
521 if (!strcasecmp(multipart_prefix,
522 "multipart/alternative")) {
527 else if (!strncasecmp(aaa, "part=", 5)) {
528 struct parts *ptr, *chain;
530 ptr = (struct parts *)calloc(1, sizeof (struct parts));
533 /* Fill the buffers for the caller */
534 extract(ptr->name, &aaa[5], 0);
535 extract(ptr->filename, &aaa[5], 1);
536 extract(ptr->number, &aaa[5], 2);
537 extract(ptr->disposition, &aaa[5], 3);
538 extract(ptr->mimetype, &aaa[5], 4);
539 ptr->length = extract_long(&aaa[5], 5);
540 if (!mret[0]->attachments)
541 mret[0]->attachments = ptr;
543 chain = mret[0]->attachments;
549 /* Now handle multipart/alternative */
550 if (multipart_hunting > 0) {
551 if ( (!strcasecmp(ptr->mimetype,
553 || (!strcasecmp(ptr->mimetype,
555 strcpy(mret[0]->mime_chosen,
563 /* Eliminate "text\n" */
564 remove_token(bbb, 0, '\n');
566 /* If doing a MIME thing, pull out the extra headers */
569 if (!strncasecmp(bbb, "Content-type: ", 14)) {
570 extract_token(mret[0]->content_type, bbb, 0, '\n');
571 strcpy(mret[0]->content_type,
572 &mret[0]->content_type[14]);
573 striplt(mret[0]->content_type);
575 remove_token(bbb, 0, '\n');
576 } while ((bbb[0] != 0) && (bbb[0] != '\n'));
577 remove_token(bbb, 0, '\n');
583 /* FIXME: Strip trailing whitespace */
584 bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1));
586 bbb = (char *)realloc(bbb, 1);
596 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret)
601 if (!cret) return -2;
602 if (!listing) return -2;
603 if (*listing) return -2;
605 ret = CtdlIPCGenericCommand(ipc, "WHOK", NULL, 0, listing, &bytes, cret);
611 int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret)
615 char *listing = NULL;
618 if (!cret) return -2;
619 if (!ServInfo) return -2;
621 ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret);
622 if (ret / 100 == 1) {
625 while (*listing && strlen(listing)) {
626 extract_token(buf, listing, 0, '\n');
627 remove_token(listing, 0, '\n');
629 case 0: ServInfo->serv_pid = atoi(buf);
631 case 1: strcpy(ServInfo->serv_nodename,buf);
633 case 2: strcpy(ServInfo->serv_humannode,buf);
635 case 3: strcpy(ServInfo->serv_fqdn,buf);
637 case 4: strcpy(ServInfo->serv_software,buf);
639 case 5: ServInfo->serv_rev_level = atoi(buf);
641 case 6: strcpy(ServInfo->serv_bbs_city,buf);
643 case 7: strcpy(ServInfo->serv_sysadm,buf);
645 case 9: strcpy(ServInfo->serv_moreprompt,buf);
647 case 10: ServInfo->serv_ok_floors = atoi(buf);
649 case 11: ServInfo->serv_paging_level = atoi(buf);
651 case 13: ServInfo->serv_supports_qnop = atoi(buf);
662 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret)
667 if (!cret) return -2;
668 if (!listing) return -2;
669 if (*listing) return -2;
671 ret = CtdlIPCGenericCommand(ipc, "RDIR", NULL, 0, listing, &bytes, cret);
677 * Set last-read pointer in this room to msgnum, or 0 for HIGHEST.
679 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret)
684 if (!cret) return -2;
687 sprintf(aaa, "SLRP %ld", msgnum);
690 sprintf(aaa, "SLRP HIGHEST");
692 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
698 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret)
703 if (!cret) return -2;
704 if (!username) return -2;
706 aaa = (char *)malloc(strlen(username) + 6);
709 sprintf(aaa, "INVT %s", username);
710 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
717 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret)
722 if (!cret) return -1;
723 if (!username) return -1;
725 aaa = (char *)malloc(strlen(username) + 6);
727 sprintf(aaa, "KICK %s", username);
728 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
735 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct quickroom **qret, char *cret)
739 if (!cret) return -2;
740 if (!qret) return -2;
741 if (!*qret) *qret = (struct quickroom *)calloc(1, sizeof (struct quickroom));
742 if (!*qret) return -1;
744 ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
745 if (ret / 100 == 2) {
746 extract(qret[0]->QRname, cret, 0);
747 extract(qret[0]->QRpasswd, cret, 1);
748 extract(qret[0]->QRdirname, cret, 2);
749 qret[0]->QRflags = extract_int(cret, 3);
750 qret[0]->QRfloor = extract_int(cret, 4);
751 qret[0]->QRorder = extract_int(cret, 5);
752 qret[0]->QRdefaultview = extract_int(cret, 6);
753 qret[0]->QRflags2 = extract_int(cret, 7);
760 /* set forget to kick all users out of room */
761 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct quickroom *qret, char *cret)
766 if (!cret) return -2;
767 if (!qret) return -2;
769 aaa = (char *)malloc(strlen(qret->QRname) + strlen(qret->QRpasswd) +
770 strlen(qret->QRdirname) + 52);
773 sprintf(aaa, "SETR %s|%s|%s|%d|%d|%d|%d",
774 qret->QRname, qret->QRpasswd, qret->QRdirname,
775 qret->QRflags, forget, qret->QRfloor, qret->QRorder);
776 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
783 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret)
785 if (!cret) return -1;
787 return CtdlIPCGenericCommand(ipc, "GETA", NULL, 0, NULL, NULL, cret);
792 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret)
797 if (!cret) return -2;
798 if (!username) return -2;
800 aaa = (char *)malloc(strlen(username) + 6);
803 sprintf(aaa, "SETA %s", username);
804 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
811 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret)
816 if (!cret) return -2;
819 snprintf(cmd, sizeof cmd,
820 "ENT0 %d|%s|%d|%d|%s|%s", flag, mr->recipient,
821 mr->anonymous, mr->type, mr->subject, mr->author);
822 ret = CtdlIPCGenericCommand(ipc, cmd, mr->text, strlen(mr->text), NULL,
829 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret)
833 if (!cret) return -2;
834 if (!iret) return -2;
835 if (*iret) return -2;
837 return CtdlIPCGenericCommand(ipc, "RINF", NULL, 0, iret, &bytes, cret);
842 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret)
846 if (!cret) return -2;
847 if (!msgnum) return -2;
849 sprintf(aaa, "DELE %ld", msgnum);
850 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
855 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret)
860 if (!cret) return -2;
861 if (!destroom) return -2;
862 if (!msgnum) return -2;
864 aaa = (char *)malloc(strlen(destroom) + 28);
867 sprintf(aaa, "MOVE %ld|%s|%d", msgnum, destroom, copy);
868 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
875 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret)
879 if (!cret) return -2;
881 sprintf(aaa, "KILL %d", for_real);
882 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
887 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type,
888 const char *password, int floor, char *cret)
893 if (!cret) return -2;
894 if (!roomname) return -2;
897 aaa = (char *)malloc(strlen(roomname) + strlen(password) + 40);
899 sprintf(aaa, "CRE8 %d|%s|%d|%s|%d", for_real, roomname, type,
902 aaa = (char *)malloc(strlen(roomname) + 40);
904 sprintf(aaa, "CRE8 %d|%s|%d||%d", for_real, roomname, type,
907 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
914 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret)
916 if (!cret) return -2;
918 return CtdlIPCGenericCommand(ipc, "FORG", NULL, 0, NULL, NULL, cret);
923 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret)
929 if (!cret) return -2;
930 if (!mret) return -2;
931 if (*mret) return -2;
932 if (!message) return -2;
934 aaa = (char *)malloc(strlen(message) + 6);
937 sprintf(aaa, "MESG %s", message);
938 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, mret, &bytes, cret);
945 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret)
947 if (!cret) return -2;
949 return CtdlIPCGenericCommand(ipc, "GNUR", NULL, 0, NULL, NULL, cret);
954 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret)
960 if (!cret) return -2;
961 if (!rret) return -2;
962 if (*rret) return -2;
965 aaa = (char *)malloc(strlen(username) + 6);
967 aaa = (char *)malloc(12);
971 sprintf(aaa, "GREG %s", username);
973 sprintf(aaa, "GREG _SELF_");
974 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, rret, &bytes, cret);
981 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret)
986 if (!cret) return -2;
987 if (!username) return -2;
988 if (axlevel < 0 || axlevel > 7) return -2;
990 aaa = (char *)malloc(strlen(username) + 17);
993 sprintf(aaa, "VALI %s|%d", username, axlevel);
994 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1001 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret)
1005 if (!cret) return -1;
1006 if (!info) return -1;
1008 sprintf(aaa, "EINF %d", for_real);
1009 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1014 int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret)
1018 if (!cret) return -1;
1019 if (!listing) return -1;
1020 if (*listing) return -1;
1022 return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret);
1027 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret)
1029 if (!cret) return -1;
1030 if (!info) return -1;
1032 return CtdlIPCGenericCommand(ipc, "REGI", info, strlen(info),
1038 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret)
1042 if (!cret) return -1;
1043 if (!chek) return -1;
1045 ret = CtdlIPCGenericCommand(ipc, "CHEK", NULL, 0, NULL, NULL, cret);
1046 if (ret / 100 == 2) {
1047 chek->newmail = extract_long(cret, 0);
1048 chek->needregis = extract_int(cret, 1);
1049 chek->needvalid = extract_int(cret, 2);
1056 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret)
1061 if (!cret) return -2;
1062 if (!filename) return -2;
1064 aaa = (char *)malloc(strlen(filename) + 6);
1065 if (!aaa) return -1;
1067 sprintf(aaa, "DELF %s", filename);
1068 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1075 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret)
1080 if (!cret) return -2;
1081 if (!filename) return -2;
1082 if (!destroom) return -2;
1084 aaa = (char *)malloc(strlen(filename) + strlen(destroom) + 7);
1085 if (!aaa) return -1;
1087 sprintf(aaa, "MOVF %s|%s", filename, destroom);
1088 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1095 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret)
1100 if (!cret) return -2;
1101 if (!filename) return -2;
1102 if (!destnode) return -2;
1104 aaa = (char *)malloc(strlen(filename) + strlen(destnode) + 7);
1105 if (!aaa) return -1;
1107 sprintf(aaa, "NETF %s|%s", filename, destnode);
1108 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1115 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret)
1120 if (!cret) return -1;
1121 if (!listing) return -1;
1122 if (*listing) return -1;
1124 *stamp = CtdlIPCServerTime(ipc, cret);
1126 *stamp = time(NULL);
1127 ret = CtdlIPCGenericCommand(ipc, "RWHO", NULL, 0, listing, &bytes, cret);
1133 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
1135 void (*progress_gauge_callback)(unsigned long, unsigned long),
1144 if (!cret) return -2;
1145 if (!filename) return -2;
1146 if (!buf) return -2;
1147 if (*buf) return -2;
1148 if (ipc->downloading) return -2;
1150 aaa = (char *)malloc(strlen(filename) + 6);
1151 if (!aaa) return -1;
1153 sprintf(aaa, "OPEN %s", filename);
1154 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1156 if (ret / 100 == 2) {
1157 ipc->downloading = 1;
1158 bytes = extract_long(cret, 0);
1159 last_mod = extract_int(cret, 1);
1160 extract(mimetype, cret, 2);
1161 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret); */
1162 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, resume, progress_gauge_callback, cret);
1163 ret = CtdlIPCEndDownload(ipc, cret);
1165 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1166 filename, mimetype);
1173 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
1175 void (*progress_gauge_callback)(unsigned long, unsigned long),
1185 if (!cret) return -2;
1186 if (!buf) return -2;
1187 if (*buf) return -2;
1188 if (!part) return -2;
1189 if (!msgnum) return -2;
1190 if (ipc->downloading) return -2;
1192 sprintf(aaa, "OPNA %ld|%s", msgnum, part);
1193 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1194 if (ret / 100 == 2) {
1195 ipc->downloading = 1;
1196 bytes = extract_long(cret, 0);
1197 last_mod = extract_int(cret, 1);
1198 extract(filename, cret, 2);
1199 extract(mimetype, cret, 3);
1200 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1201 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1202 ret = CtdlIPCEndDownload(ipc, cret);
1204 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1205 filename, mimetype);
1212 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
1213 void (*progress_gauge_callback)(unsigned long, unsigned long),
1222 if (!cret) return -1;
1223 if (!buf) return -1;
1224 if (*buf) return -1;
1225 if (!filename) return -1;
1226 if (ipc->downloading) return -1;
1228 aaa = (char *)malloc(strlen(filename) + 6);
1229 if (!aaa) return -1;
1231 sprintf(aaa, "OIMG %s", filename);
1232 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1234 if (ret / 100 == 2) {
1235 ipc->downloading = 1;
1236 bytes = extract_long(cret, 0);
1237 last_mod = extract_int(cret, 1);
1238 extract(mimetype, cret, 2);
1239 /* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
1240 ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
1241 ret = CtdlIPCEndDownload(ipc, cret);
1243 sprintf(cret, "%d|%ld|%s|%s", (int)bytes, last_mod,
1244 filename, mimetype);
1251 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
1253 void (*progress_gauge_callback)(unsigned long, unsigned long),
1259 if (!cret) return -1;
1260 if (!save_as) return -1;
1261 if (!comment) return -1;
1262 if (!path) return -1;
1263 if (!*path) return -1;
1264 if (ipc->uploading) return -1;
1266 aaa = (char *)malloc(strlen(save_as) + strlen(comment) + 7);
1267 if (!aaa) return -1;
1269 sprintf(aaa, "UOPN %s|%s", save_as, comment);
1270 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1272 if (ret / 100 == 2) {
1274 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1275 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1283 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
1284 const char *save_as,
1285 void (*progress_gauge_callback)(unsigned long, unsigned long),
1291 if (!cret) return -1;
1292 if (!save_as) return -1;
1293 if (!path && for_real) return -1;
1294 if (!*path && for_real) return -1;
1295 if (ipc->uploading) return -1;
1297 aaa = (char *)malloc(strlen(save_as) + 17);
1298 if (!aaa) return -1;
1300 sprintf(aaa, "UIMG %d|%s", for_real, save_as);
1301 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1303 if (ret / 100 == 2 && for_real) {
1305 ret = CtdlIPCWriteUpload(ipc, path, progress_gauge_callback, cret);
1306 ret = CtdlIPCEndUpload(ipc, (ret == -2 ? 1 : 0), cret);
1314 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret)
1319 if (!cret) return -2;
1320 if (!username) return -2;
1322 aaa = (char *)malloc(strlen(username) + 6);
1323 if (!aaa) return -1;
1325 sprintf(aaa, "QUSR %s", username);
1326 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1333 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret)
1337 if (!cret) return -2;
1338 if (!listing) return -2;
1339 if (*listing) return -2;
1341 return CtdlIPCGenericCommand(ipc, "LFLR", NULL, 0, listing, &bytes, cret);
1346 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret)
1351 if (!cret) return -2;
1352 if (!name) return -2;
1354 sprintf(aaa, "CFLR %s|%d", name, for_real);
1355 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1361 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret)
1365 if (!cret) return -1;
1366 if (floornum < 0) return -1;
1368 sprintf(aaa, "KFLR %d|%d", floornum, for_real);
1369 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1374 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret)
1379 if (!cret) return -2;
1380 if (!floorname) return -2;
1381 if (floornum < 0) return -2;
1383 sprintf(aaa, "EFLR %d|%s", floornum, floorname);
1384 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1392 * You only need to fill out hostname, the defaults will be used if any of the
1393 * other fields are not set properly.
1395 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
1396 int revision, const char *software_name, const char *hostname,
1402 if (developerid < 0 || clientid < 0 || revision < 0 ||
1406 revision = REV_LEVEL - 600;
1407 software_name = "Citadel/UX (libcitadel)";
1409 if (!hostname) return -2;
1411 aaa = (char *)malloc(strlen(software_name) + strlen(hostname) + 29);
1412 if (!aaa) return -1;
1414 sprintf(aaa, "IDEN %d|%d|%d|%s|%s", developerid, clientid,
1415 revision, software_name, hostname);
1416 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1423 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text,
1429 if (!cret) return -2;
1430 if (!username) return -2;
1432 aaa = (char *)malloc(strlen(username) + 8);
1433 if (!aaa) return -1;
1436 sprintf(aaa, "SEXP %s|-", username);
1437 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text),
1440 sprintf(aaa, "SEXP %s||", username);
1441 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1449 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret)
1453 if (!cret) return -2;
1454 if (!listing) return -2;
1455 if (*listing) return -2;
1457 return CtdlIPCGenericCommand(ipc, "GEXP", NULL, 0, listing, &bytes, cret);
1462 /* mode is 0 = enable, 1 = disable, 2 = status */
1463 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret)
1467 if (!cret) return -2;
1469 sprintf(aaa, "DEXP %d", mode);
1470 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1475 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret)
1477 if (!cret) return -2;
1478 if (!bio) return -2;
1480 return CtdlIPCGenericCommand(ipc, "EBIO", bio, strlen(bio),
1486 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret)
1492 if (!cret) return -2;
1493 if (!username) return -2;
1494 if (!listing) return -2;
1495 if (*listing) return -2;
1497 aaa = (char *)malloc(strlen(username) + 6);
1498 if (!aaa) return -1;
1500 sprintf(aaa, "RBIO %s", username);
1501 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, listing, &bytes, cret);
1508 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret)
1512 if (!cret) return -2;
1513 if (!listing) return -2;
1514 if (*listing) return -2;
1516 return CtdlIPCGenericCommand(ipc, "LBIO", NULL, 0, listing, &bytes, cret);
1521 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret)
1525 if (!cret) return -1;
1527 sprintf(aaa, "STEL %d", mode ? 1 : 0);
1528 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1533 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret)
1537 if (!cret) return -1;
1539 sprintf(aaa, "TERM %d", sid);
1540 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1545 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret)
1547 if (!cret) return -1;
1549 return CtdlIPCGenericCommand(ipc, "DOWN", NULL, 0, NULL, NULL, cret);
1554 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret)
1558 if (!cret) return -1;
1560 sprintf(aaa, "SCDN %d", mode ? 1 : 0);
1561 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1566 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
1572 if (!cret) return -2;
1573 if (!text) return -2;
1574 if (!filename) return -2;
1576 aaa = (char *)malloc(strlen(filename) + 6);
1577 if (!aaa) return -1;
1579 sprintf(aaa, "EMSG %s", filename);
1580 ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret);
1587 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret)
1592 if (!cret) return -2;
1593 if (!hostname) return -2;
1595 aaa = (char *)malloc(strlen(hostname) + 6);
1596 if (!aaa) return -1;
1598 sprintf(aaa, "HCHG %s", hostname);
1599 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1606 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret)
1611 if (!cret) return -2;
1612 if (!roomname) return -2;
1614 aaa = (char *)malloc(strlen(roomname) + 6);
1615 if (!aaa) return -1;
1617 sprintf(aaa, "RCHG %s", roomname);
1618 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1625 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret)
1630 if (!cret) return -2;
1631 if (!username) return -2;
1633 aaa = (char *)malloc(strlen(username) + 6);
1634 if (!aaa) return -1;
1636 sprintf(aaa, "UCHG %s", username);
1637 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1644 /* This function returns the actual server time reported, or 0 if error */
1645 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *cret)
1647 register time_t tret;
1650 ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret);
1651 if (ret / 100 == 2) {
1652 tret = extract_long(cret, 0);
1661 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
1662 struct usersupp **uret, char *cret)
1667 if (!cret) return -2;
1668 if (!uret) return -2;
1669 if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof(struct usersupp));
1670 if (!*uret) return -1;
1672 sprintf(aaa, "AGUP %s", who);
1673 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1675 if (ret / 100 == 2) {
1676 extract(uret[0]->fullname, cret, 0);
1677 extract(uret[0]->password, cret, 1);
1678 uret[0]->flags = extract_int(cret, 2);
1679 uret[0]->timescalled = extract_long(cret, 3);
1680 uret[0]->posted = extract_long(cret, 4);
1681 uret[0]->axlevel = extract_int(cret, 5);
1682 uret[0]->usernum = extract_long(cret, 6);
1683 uret[0]->lastcall = extract_long(cret, 7);
1684 uret[0]->USuserpurge = extract_int(cret, 8);
1691 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret)
1696 if (!cret) return -2;
1697 if (!uret) return -2;
1699 aaa = (char *)malloc(strlen(uret->fullname) + strlen(uret->password) + 84);
1700 if (!aaa) return -1;
1702 sprintf(aaa, "ASUP %s|%s|%d|%ld|%ld|%d|%ld|%ld|%d",
1703 uret->fullname, uret->password, uret->flags,
1704 uret->timescalled, uret->posted, uret->axlevel,
1705 uret->usernum, uret->lastcall, uret->USuserpurge);
1706 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1713 /* which is 0 = room, 1 = floor, 2 = site */
1714 /* caller must free the struct ExpirePolicy */
1715 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1716 struct ExpirePolicy **policy, char *cret)
1718 static char *proto[] = {"room", "floor", "site"};
1722 if (!cret) return -2;
1723 if (!policy) return -2;
1724 if (!*policy) *policy = (struct ExpirePolicy *)calloc(1, sizeof(struct ExpirePolicy));
1725 if (!*policy) return -1;
1726 if (which < 0 || which > 2) return -2;
1728 sprintf(aaa, "GPEX %s", proto[which]);
1729 ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1730 if (ret / 100 == 2) {
1731 policy[0]->expire_mode = extract_int(cret, 0);
1732 policy[0]->expire_value = extract_int(cret, 1);
1740 /* which is 0 = room, 1 = floor, 2 = site */
1741 /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */
1742 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
1743 struct ExpirePolicy *policy, char *cret)
1746 char *whichvals[] = { "room", "floor", "site" };
1748 if (!cret) return -2;
1749 if (which < 0 || which > 2) return -2;
1750 if (!policy) return -2;
1751 if (policy->expire_mode < 0 || policy->expire_mode > 3) return -2;
1752 if (policy->expire_mode >= 2 && policy->expire_value < 1) return -2;
1754 sprintf(aaa, "SPEX %s|%d|%d", whichvals[which],
1755 policy->expire_mode, policy->expire_value);
1756 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1761 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret)
1765 if (!cret) return -2;
1766 if (!listing) return -2;
1767 if (*listing) return -2;
1769 return CtdlIPCGenericCommand(ipc, "CONF GET", NULL, 0,
1770 listing, &bytes, cret);
1775 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret)
1777 if (!cret) return -2;
1778 if (!listing) return -2;
1780 return CtdlIPCGenericCommand(ipc, "CONF SET", listing, strlen(listing),
1786 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1787 char **listing, char *cret)
1792 if (!cret) return -2;
1793 if (!mimetype) return -2;
1794 if (!listing) return -2;
1795 if (*listing) return -2;
1797 aaa = malloc(strlen(mimetype) + 13);
1798 if (!aaa) return -1;
1799 sprintf(aaa, "CONF GETSYS|%s", mimetype);
1800 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
1801 listing, &bytes, cret);
1806 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
1807 const char *listing, char *cret)
1811 if (!cret) return -2;
1812 if (!mimetype) return -2;
1813 if (!listing) return -2;
1815 aaa = malloc(strlen(mimetype) + 13);
1816 if (!aaa) return -1;
1817 sprintf(aaa, "CONF PUTSYS|%s", mimetype);
1818 return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
1824 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret)
1828 if (!cret) return -2;
1829 if (session < 0) return -2;
1831 sprintf(aaa, "REQT %d", session);
1832 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1837 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret)
1841 if (!cret) return -2;
1842 if (msgnum < 0) return -2;
1844 sprintf(aaa, "SEEN %ld|%d", msgnum, seen ? 1 : 0);
1845 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1850 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret)
1859 /* New SSL object */
1860 temp_ssl = SSL_new(ssl_ctx);
1862 error_printf("SSL_new failed: %s\n",
1863 ERR_reason_error_string(ERR_get_error()));
1866 /* Pointless flag waving */
1867 #if SSLEAY_VERSION_NUMBER >= 0x0922
1868 SSL_set_session_id_context(temp_ssl, "Citadel/UX SID", 14);
1871 if (!access("/var/run/egd-pool", F_OK))
1872 RAND_egd("/var/run/egd-pool");
1874 if (!RAND_status()) {
1875 error_printf("PRNG not properly seeded\n");
1879 /* Associate network connection with SSL object */
1880 if (SSL_set_fd(temp_ssl, ipc->sock) < 1) {
1881 error_printf("SSL_set_fd failed: %s\n",
1882 ERR_reason_error_string(ERR_get_error()));
1886 if (status_hook != NULL)
1887 status_hook("Requesting encryption...\r");
1889 /* Ready to start SSL/TLS */
1891 CtdlIPC_putline(ipc, "STLS");
1892 CtdlIPC_getline(ipc, buf);
1893 if (buf[0] != '2') {
1894 error_printf("Server can't start TLS: %s\n", buf);
1898 r = CtdlIPCGenericCommand(ipc,
1899 "STLS", NULL, 0, NULL, NULL, cret);
1901 error_printf("Server can't start TLS: %s\n", buf);
1906 /* Do SSL/TLS handshake */
1907 if ((a = SSL_connect(temp_ssl)) < 1) {
1908 error_printf("SSL_connect failed: %s\n",
1909 ERR_reason_error_string(ERR_get_error()));
1913 ipc->ssl = temp_ssl;
1915 BIO_set_close(ipc->ssl->rbio, BIO_NOCLOSE);
1919 bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ipc->ssl), &alg_bits);
1920 error_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
1921 SSL_CIPHER_get_version(SSL_get_current_cipher(ipc->ssl)),
1922 SSL_CIPHER_get_name(SSL_get_current_cipher(ipc->ssl)),
1928 #endif /* HAVE_OPENSSL */
1933 static void endtls(SSL *ssl)
1944 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret)
1948 if (!address) return -2;
1949 if (!cret) return -2;
1951 aaa = (char *)malloc(strlen(address) + 6);
1952 if (!aaa) return -1;
1954 sprintf(aaa, "QDIR %s", address);
1955 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1960 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret)
1964 if (!cret) return -2;
1965 sprintf(aaa, "IPGM %d", secret);
1966 return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
1971 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret)
1975 if (!cret) return -2;
1976 if (!mret) return -2;
1977 if (*mret) return -2;
1979 return CtdlIPCGenericCommand(ipc, "FSCK", NULL, 0, mret, &size, cret);
2000 /* ************************************************************************** */
2001 /* Stuff below this line is not for public consumption */
2002 /* ************************************************************************** */
2005 inline void CtdlIPC_lock(CtdlIPC *ipc)
2007 if (ipc->network_status_cb) ipc->network_status_cb(1);
2008 #ifdef THREADED_CLIENT
2009 pthread_mutex_lock(&(ipc->mutex));
2014 inline void CtdlIPC_unlock(CtdlIPC *ipc)
2016 #ifdef THREADED_CLIENT
2017 pthread_mutex_unlock(&(ipc->mutex));
2019 if (ipc->network_status_cb) ipc->network_status_cb(0);
2023 /* Read a listing from the server up to 000. Append to dest if it exists */
2024 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest)
2033 length = strlen(ret);
2038 while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) {
2039 linelength = strlen(aaa);
2040 ret = (char *)realloc(ret, (size_t)(length + linelength + 2));
2042 strcpy(&ret[length], aaa);
2043 length += linelength;
2044 strcpy(&ret[length++], "\n");
2052 /* Send a listing to the server; generate the ending 000. */
2053 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing)
2057 text = (char *)malloc(strlen(listing) + 6);
2059 strcpy(text, listing);
2060 while (text[strlen(text) - 1] == '\n')
2061 text[strlen(text) - 1] = '\0';
2062 strcat(text, "\n000");
2063 CtdlIPC_putline(ipc, text);
2067 /* Malloc failed but we are committed to send */
2068 /* This may result in extra blanks at the bottom */
2069 CtdlIPC_putline(ipc, text);
2070 CtdlIPC_putline(ipc, "000");
2076 /* Partial read of file from server */
2077 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret)
2079 register size_t len = 0;
2083 if (!cret) return 0;
2084 if (bytes < 1) return 0;
2085 if (offset < 0) return 0;
2088 sprintf(aaa, "READ %d|%d", (int)offset, (int)bytes);
2089 CtdlIPC_putline(ipc, aaa);
2090 CtdlIPC_getline(ipc, aaa);
2092 strcpy(cret, &aaa[4]);
2094 len = extract_long(&aaa[4], 0);
2095 *buf = (void *)realloc(*buf, (size_t)(offset + len));
2097 /* I know what I'm doing */
2098 serv_read(ipc, (*buf + offset), len);
2100 /* We have to read regardless */
2101 serv_read(ipc, aaa, len);
2105 CtdlIPC_unlock(ipc);
2111 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret)
2115 if (!cret) return -2;
2116 if (!ipc->downloading) return -2;
2118 ret = CtdlIPCGenericCommand(ipc, "CLOS", NULL, 0, NULL, NULL, cret);
2120 ipc->downloading = 0;
2126 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) {
2130 snprintf(cmd, sizeof cmd, "MSGP %s", formats);
2131 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2138 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
2139 void (*progress_gauge_callback)(unsigned long, unsigned long),
2142 register size_t len;
2144 if (!cret) return -1;
2145 if (!buf) return -1;
2146 if (*buf) return -1;
2147 if (!ipc->downloading) return -1;
2150 if (progress_gauge_callback)
2151 progress_gauge_callback(len, bytes);
2152 while (len < bytes) {
2153 register size_t block;
2155 block = CtdlIPCPartialRead(ipc, buf, len, 4096, cret);
2161 if (progress_gauge_callback)
2162 progress_gauge_callback(len, bytes);
2167 /* READ - pipelined */
2168 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
2170 void (*progress_gauge_callback)(unsigned long, unsigned long),
2173 register size_t len;
2174 register int calls; /* How many calls in the pipeline */
2175 register int i; /* iterator */
2178 if (!cret) return -1;
2179 if (!buf) return -1;
2180 if (*buf) return -1;
2181 if (!ipc->downloading) return -1;
2183 *buf = (void *)realloc(*buf, bytes - resume);
2184 if (!*buf) return -1;
2188 if (progress_gauge_callback)
2189 progress_gauge_callback(len, bytes);
2191 /* How many calls will be in the pipeline? */
2192 calls = (bytes - resume) / 4096;
2193 if ((bytes - resume) % 4096) calls++;
2195 /* Send all requests at once */
2196 for (i = 0; i < calls; i++) {
2197 sprintf(aaa, "READ %d|4096", (int)(i * 4096 + resume) );
2198 CtdlIPC_putline(ipc, aaa);
2201 /* Receive all responses at once */
2202 for (i = 0; i < calls; i++) {
2203 CtdlIPC_getline(ipc, aaa);
2205 strcpy(cret, &aaa[4]);
2207 len = extract_long(&aaa[4], 0);
2208 /* I know what I'm doing */
2209 serv_read(ipc, ((*buf) + (i * 4096)), len);
2211 if (progress_gauge_callback)
2212 progress_gauge_callback(i * 4096 + len, bytes);
2214 CtdlIPC_unlock(ipc);
2220 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret)
2225 if (!cret) return -1;
2226 if (!ipc->uploading) return -1;
2228 sprintf(cmd, "UCLS %d", discard ? 0 : 1);
2229 ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
2236 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
2237 void (*progress_gauge_callback)(unsigned long, unsigned long),
2240 register int ret = -1;
2241 register size_t offset = 0;
2247 if (!cret) return -1;
2248 if (!path) return -1;
2249 if (!*path) return -1;
2251 fd = fopen(path, "r");
2254 fseek(fd, 0L, SEEK_END);
2258 if (progress_gauge_callback)
2259 progress_gauge_callback(0, bytes);
2261 while (offset < bytes) {
2262 register size_t to_write;
2264 /* Read some data in */
2265 to_write = fread(buf, 1, 4096, fd);
2267 if (feof(fd) || ferror(fd)) break;
2269 sprintf(aaa, "WRIT %d", (int)to_write);
2270 CtdlIPC_putline(ipc, aaa);
2271 CtdlIPC_getline(ipc, aaa);
2272 strcpy(cret, &aaa[4]);
2274 if (aaa[0] == '7') {
2275 to_write = extract_long(&aaa[4], 0);
2277 serv_write(ipc, buf, to_write);
2279 if (progress_gauge_callback)
2280 progress_gauge_callback(offset, bytes);
2281 /* Detect short reads and back up if needed */
2282 /* offset will never be negative anyway */
2283 fseek(fd, (signed)offset, SEEK_SET);
2288 if (progress_gauge_callback)
2289 progress_gauge_callback(1, 1);
2290 return (!ferror(fd) ? ret : -2);
2295 * Generic command method. This method should handle any server command
2296 * except for CHAT. It takes the following arguments:
2298 * ipc The server to speak with
2299 * command Preformatted command to send to server
2300 * to_send A text or binary file to send to server
2301 * (only sent if server requests it)
2302 * bytes_to_send The number of bytes in to_send (required if
2303 * sending binary, optional if sending listing)
2304 * to_receive Pointer to a NULL pointer, if the server
2305 * sends text or binary we will allocate memory
2306 * for the file and stuff it here
2307 * bytes_to_receive If a file is received, we will store its
2309 * proto_response The protocol response. Caller must provide
2310 * this buffer and ensure that it is at least
2311 * 128 bytes in length.
2313 * This function returns a number equal to the protocol response number,
2314 * -1 if an internal error occurred, -2 if caller provided bad values,
2315 * or 0 - the protocol response number if bad values were found during
2316 * the protocol exchange.
2317 * It stores the protocol response string (minus the number) in
2318 * protocol_response as described above. Some commands send additional
2319 * data in this string.
2321 int CtdlIPCGenericCommand(CtdlIPC *ipc,
2322 const char *command, const char *to_send,
2323 size_t bytes_to_send, char **to_receive,
2324 size_t *bytes_to_receive, char *proto_response)
2330 if (!command) return -2;
2331 if (!proto_response) return -2;
2334 if (ipc->ssl) watch_ssl = 1;
2338 CtdlIPC_putline(ipc, command);
2340 CtdlIPC_getline(ipc, proto_response);
2341 if (proto_response[3] == '*')
2343 ret = atoi(proto_response);
2344 strcpy(proto_response, &proto_response[4]);
2345 switch (ret / 100) {
2346 default: /* Unknown, punt */
2348 case 3: /* MORE_DATA */
2350 /* Don't need to do anything */
2352 case 1: /* LISTING_FOLLOWS */
2353 if (to_receive && !*to_receive && bytes_to_receive) {
2354 *to_receive = CtdlIPCReadListing(ipc, NULL);
2355 } else { /* Drain */
2356 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ;
2360 case 4: /* SEND_LISTING */
2362 CtdlIPCSendListing(ipc, to_send);
2364 /* No listing given, fake it */
2365 CtdlIPC_putline(ipc, "000");
2369 case 6: /* BINARY_FOLLOWS */
2370 if (to_receive && !*to_receive && bytes_to_receive) {
2372 extract_long(proto_response, 0);
2373 *to_receive = (char *)
2374 malloc((size_t)*bytes_to_receive);
2378 serv_read(ipc, *to_receive,
2385 drain = extract_long(proto_response, 0);
2386 while (drain > SIZ) {
2387 serv_read(ipc, buf, SIZ);
2390 serv_read(ipc, buf, drain);
2394 case 7: /* SEND_BINARY */
2395 if (to_send && bytes_to_send) {
2396 serv_write(ipc, to_send, bytes_to_send);
2397 } else if (bytes_to_send) {
2398 /* Fake it, send nulls */
2401 fake = bytes_to_send;
2402 memset(buf, '\0', SIZ);
2403 while (fake > SIZ) {
2404 serv_write(ipc, buf, SIZ);
2407 serv_write(ipc, buf, fake);
2409 } /* else who knows? DANGER WILL ROBINSON */
2411 case 8: /* START_CHAT_MODE */
2412 if (!strncasecmp(command, "CHAT", 4)) {
2413 /* Don't call chatmode with generic! */
2414 CtdlIPC_putline(ipc, "/quit");
2417 /* In this mode we send then receive listing */
2419 CtdlIPCSendListing(ipc, to_send);
2421 /* No listing given, fake it */
2422 CtdlIPC_putline(ipc, "000");
2425 if (to_receive && !*to_receive
2426 && bytes_to_receive) {
2427 *to_receive = CtdlIPCReadListing(ipc, NULL);
2428 } else { /* Drain */
2429 while (CtdlIPC_getline(ipc, buf),
2430 strcmp(buf, "000")) ;
2435 case 9: /* ASYNC_MSG */
2436 /* CtdlIPCDoAsync(ret, proto_response); */
2437 free(CtdlIPCReadListing(ipc, NULL)); /* STUB FIXME */
2443 CtdlIPC_unlock(ipc);
2448 static int connectsock(char *host, char *service, char *protocol, int defaultPort)
2450 struct hostent *phe;
2451 struct servent *pse;
2452 struct protoent *ppe;
2453 struct sockaddr_in sin;
2456 memset(&sin, 0, sizeof(sin));
2457 sin.sin_family = AF_INET;
2459 pse = getservbyname(service, protocol);
2461 sin.sin_port = pse->s_port;
2463 else if (atoi(service) > 0) {
2464 sin.sin_port = htons(atoi(service));
2467 sin.sin_port = htons(defaultPort);
2469 phe = gethostbyname(host);
2471 memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
2472 } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
2475 if ((ppe = getprotobyname(protocol)) == 0) {
2478 if (!strcmp(protocol, "udp")) {
2484 s = socket(PF_INET, type, ppe->p_proto);
2489 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
2496 static int uds_connectsock(int *isLocal, char *sockpath)
2498 struct sockaddr_un addr;
2501 memset(&addr, 0, sizeof(addr));
2502 addr.sun_family = AF_UNIX;
2503 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
2505 s = socket(AF_UNIX, SOCK_STREAM, 0);
2510 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2520 * input binary data from socket
2522 static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes)
2524 unsigned int len, rlen;
2526 #if defined(HAVE_OPENSSL)
2528 serv_read_ssl(ipc, buf, bytes);
2533 while (len < bytes) {
2534 rlen = read(ipc->sock, &buf[len], bytes - len);
2536 connection_died(ipc);
2545 * send binary to server
2547 static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2549 unsigned int bytes_written = 0;
2552 #if defined(HAVE_OPENSSL)
2554 serv_write_ssl(ipc, buf, nbytes);
2558 while (bytes_written < nbytes) {
2559 retval = write(ipc->sock, &buf[bytes_written],
2560 nbytes - bytes_written);
2562 connection_died(ipc);
2565 bytes_written += retval;
2572 * input binary data from encrypted connection
2574 static void serv_read_ssl(CtdlIPC* ipc, char *buf, unsigned int bytes)
2580 while (len < bytes) {
2581 if (SSL_want_read(ipc->ssl)) {
2582 if ((SSL_write(ipc->ssl, junk, 0)) < 1) {
2583 error_printf("SSL_write in serv_read:\n");
2584 ERR_print_errors_fp(stderr);
2587 rlen = SSL_read(ipc->ssl, &buf[len], bytes - len);
2591 errval = SSL_get_error(ipc->ssl, rlen);
2592 if (errval == SSL_ERROR_WANT_READ ||
2593 errval == SSL_ERROR_WANT_WRITE) {
2597 if (errval == SSL_ERROR_ZERO_RETURN ||
2598 errval == SSL_ERROR_SSL) {
2599 serv_read(ipc, &buf[len], bytes - len);
2602 error_printf("SSL_read in serv_read:\n");
2603 ERR_print_errors_fp(stderr);
2604 connection_died(ipc);
2613 * send binary to server encrypted
2615 static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes)
2617 unsigned int bytes_written = 0;
2621 while (bytes_written < nbytes) {
2622 if (SSL_want_write(ipc->ssl)) {
2623 if ((SSL_read(ipc->ssl, junk, 0)) < 1) {
2624 error_printf("SSL_read in serv_write:\n");
2625 ERR_print_errors_fp(stderr);
2628 retval = SSL_write(ipc->ssl, &buf[bytes_written],
2629 nbytes - bytes_written);
2633 errval = SSL_get_error(ipc->ssl, retval);
2634 if (errval == SSL_ERROR_WANT_READ ||
2635 errval == SSL_ERROR_WANT_WRITE) {
2639 if (errval == SSL_ERROR_ZERO_RETURN ||
2640 errval == SSL_ERROR_SSL) {
2641 serv_write(ipc, &buf[bytes_written],
2642 nbytes - bytes_written);
2645 error_printf("SSL_write in serv_write:\n");
2646 ERR_print_errors_fp(stderr);
2647 connection_died(ipc);
2650 bytes_written += retval;
2655 static void CtdlIPC_init_OpenSSL(void)
2658 SSL_METHOD *ssl_method;
2661 /* already done init */
2669 SSL_load_error_strings();
2670 SSLeay_add_ssl_algorithms();
2672 /* Set up the SSL context in which we will oeprate */
2673 ssl_method = SSLv23_client_method();
2674 ssl_ctx = SSL_CTX_new(ssl_method);
2676 error_printf("SSL_CTX_new failed: %s\n",
2677 ERR_reason_error_string(ERR_get_error()));
2680 /* Any reasonable cipher we can get */
2681 if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
2682 error_printf("No ciphers available for encryption\n");
2685 SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH);
2687 /* Load DH parameters into the context */
2690 error_printf("Can't allocate a DH object: %s\n",
2691 ERR_reason_error_string(ERR_get_error()));
2694 if (!(BN_hex2bn(&(dh->p), DH_P))) {
2695 error_printf("Can't assign DH_P: %s\n",
2696 ERR_reason_error_string(ERR_get_error()));
2700 if (!(BN_hex2bn(&(dh->g), DH_G))) {
2701 error_printf("Can't assign DH_G: %s\n",
2702 ERR_reason_error_string(ERR_get_error()));
2707 SSL_CTX_set_tmp_dh(ssl_ctx, dh);
2710 #ifdef THREADED_CLIENT
2711 /* OpenSSL requires callbacks for threaded clients */
2712 CRYPTO_set_locking_callback(ssl_lock);
2713 CRYPTO_set_id_callback(id_callback);
2715 /* OpenSSL requires us to do semaphores for threaded clients */
2716 Critters = malloc(CRYPTO_num_locks() * sizeof (pthread_mutex_t *));
2718 perror("malloc failed");
2721 for (a = 0; a < CRYPTO_num_locks(); a++) {
2722 Critters[a] = malloc(sizeof (pthread_mutex_t));
2724 perror("malloc failed");
2727 pthread_mutex_init(Critters[a], NULL);
2730 #endif /* THREADED_CLIENT */
2734 static void ssl_lock(int mode, int n, const char *file, int line)
2736 #ifdef THREADED_CLIENT
2737 if (mode & CRYPTO_LOCK)
2738 pthread_mutex_lock(Critters[n]);
2740 pthread_mutex_unlock(Critters[n]);
2741 #endif /* THREADED_CLIENT */
2744 #ifdef THREADED_CLIENT
2745 static unsigned long id_callback(void) {
2746 return (unsigned long)pthread_self();
2748 #endif /* THREADED_CLIENT */
2749 #endif /* HAVE_OPENSSL */
2753 * input string from socket - implemented in terms of serv_read()
2755 void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
2759 /* Read one character at a time. */
2761 serv_read(ipc, &buf[i], 1);
2762 if (buf[i] == '\n' || i == (SIZ-1))
2766 /* If we got a long line, discard characters until the newline. */
2768 while (buf[i] != '\n')
2769 serv_read(ipc, &buf[i], 1);
2771 /* Strip the trailing newline (and carriage return, if present) */
2772 if (buf[i] == 10) buf[i--] = 0;
2773 if (buf[i] == 13) buf[i--] = 0;
2778 * send line to server - implemented in terms of serv_write()
2780 void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
2782 /* error_printf("< %s\n", buf); */
2783 serv_write(ipc, buf, strlen(buf));
2784 serv_write(ipc, "\n", 1);
2786 ipc->last_command_sent = time(NULL);
2793 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
2800 CtdlIPC *ipc = ialloc(CtdlIPC);
2804 #if defined(HAVE_OPENSSL)
2806 CtdlIPC_init_OpenSSL();
2808 #if defined(HAVE_PTHREAD_H)
2809 pthread_mutex_init(&(ipc->mutex), NULL); /* Default fast mutex */
2811 ipc->sock = -1; /* Not connected */
2812 ipc->isLocal = 0; /* Not local, of course! */
2813 ipc->downloading = 0;
2815 ipc->last_command_sent = 0L;
2816 ipc->network_status_cb = NULL;
2818 strcpy(cithost, DEFAULT_HOST); /* default host */
2819 strcpy(citport, DEFAULT_PORT); /* default port */
2821 for (a = 0; a < argc; ++a) {
2824 } else if (a == 1) {
2825 strcpy(cithost, argv[a]);
2826 } else if (a == 2) {
2827 strcpy(citport, argv[a]);
2829 error_printf("%s: usage: ",argv[0]);
2830 error_printf("%s [host] [port] ",argv[0]);
2837 if ((!strcmp(cithost, "localhost"))
2838 || (!strcmp(cithost, "127.0.0.1"))) {
2842 /* If we're using a unix domain socket we can do a bunch of stuff */
2843 if (!strcmp(cithost, UDS)) {
2844 snprintf(sockpath, sizeof sockpath, BBSDIR "/citadel.socket");
2845 ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath);
2846 if (ipc->sock == -1) {
2850 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2851 if (portbuf != NULL) strcpy(portbuf, sockpath);
2855 ipc->sock = connectsock(cithost, citport, "tcp", 504);
2856 if (ipc->sock == -1) {
2860 if (hostbuf != NULL) strcpy(hostbuf, cithost);
2861 if (portbuf != NULL) strcpy(portbuf, citport);
2866 * return the file descriptor of the server socket so we can select() on it.
2868 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2871 int CtdlIPC_getsockfd(CtdlIPC* ipc)
2878 * return one character
2880 * FIXME: This is only used in chat mode; eliminate it when chat mode gets
2883 char CtdlIPC_get(CtdlIPC* ipc)
2888 serv_read(ipc, buf, 1);