$Log$
+ Revision 614.77 2004/03/15 16:36:50 error
+ * Multiple files: Convert most remaining client code to use new Citadel IPC
+ functions. A few bits remain and will be converted when the chat system
+ is rewritten.
+
Revision 614.76 2004/03/14 06:35:46 ajc
* Cache IMAP "BODY" fetches in an already-converted format. This speeds
up clients like Mozilla and Thunderbird that request big messages in
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
#endif
ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
- CtdlIPC_getline(ipc, aaa);
+ CtdlIPC_chat_recv(ipc, aaa);
if (aaa[0] != '2') {
scr_printf("%s\n", &aaa[4]);
logoff(ipc, atoi(aaa));
entmsg(ipc, 0, 2);
break;
case 78:
- newprompt("What do you want your username to be? ", aaa, 32);
- snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
- CtdlIPC_putline(ipc, bbb);
- CtdlIPC_getline(ipc, aaa);
- if (strncmp("200", aaa, 3))
- scr_printf("\n%s\n", aaa);
- else
- entmsg(ipc, 0, 0);
+ {
+ /* Only m.author is used */
+ struct ctdlipcmessage m;
+ newprompt("What do you want your username to be? ", m.author, USERNAME_SIZE - 1);
+ r = CtdlIPCPostMessage(ipc, 2, &m, aaa);
+ if (r / 100 != 2)
+ scr_printf("%s\n", aaa);
+ else
+ entmsg(ipc, 0, 0);
+ }
break;
case 5: /* <G>oto */
updatels(ipc);
static unsigned long id_callback(void);
#endif /* THREADED_CLIENT */
#endif /* HAVE_OPENSSL */
-/* static */ void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
-/* static */ void CtdlIPC_putline(CtdlIPC *ipc, const char *buf);
+static void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
+static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf);
/*
/*
* input string from socket - implemented in terms of serv_read()
*/
-/* static */ void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
+static void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
{
int i;
/*
* send line to server - implemented in terms of serv_write()
*/
-/* static */ void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
+static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
{
/* error_printf("< %s\n", buf); */
serv_write(ipc, buf, strlen(buf));
struct timeval tv;
int retval;
- CtdlIPC_putline(ipc, "CHAT");
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, "CHAT");
+ CtdlIPC_chat_recv(ipc, buf);
if (buf[0] != '8') {
scr_printf("%s\n", &buf[4]);
return;
/* If there's data from the server... */
if (FD_ISSET(CtdlIPC_getsockfd(ipc), &rfds)) {
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
recv_complete_line = 1;
goto RCL; /* ugly, but we've gotta get out! */
}
/* if the user hit return, send the line */
RCL: if (send_complete_line) {
- CtdlIPC_putline(ipc, wbuf);
+ CtdlIPC_chat_send(ipc, wbuf);
last_transmit = time(NULL);
strcpy(wbuf, "");
send_complete_line = 0;
pos = a;
}
if (pos == 0) {
- CtdlIPC_putline(ipc, wbuf);
+ CtdlIPC_chat_send(ipc, wbuf);
last_transmit = time(NULL);
strcpy(wbuf, "");
send_complete_line = 0;
} else {
wbuf[pos] = 0;
- CtdlIPC_putline(ipc, wbuf);
+ CtdlIPC_chat_send(ipc, wbuf);
last_transmit = time(NULL);
strcpy(wbuf, &wbuf[pos + 1]);
}
* exiting chat. This little dialog forces
* everything to be hunky-dory.
*/
- CtdlIPC_putline(ipc, "ECHO __ExitingChat__");
+ CtdlIPC_chat_send(ipc, "ECHO __ExitingChat__");
do {
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
} while (strcmp(buf, "200 __ExitingChat__"));
return;
}
* server to prevent session timeout.
*/
if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
- CtdlIPC_putline(ipc, "NOOP");
+ CtdlIPC_chat_send(ipc, "NOOP");
last_transmit = time(NULL);
}
if (ipc->ServInfo.paging_level == 0) {
newprompt("Message: ", msg, 69);
snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
if (!strncmp(buf, "200", 3)) {
strcpy(last_paged, touser);
}
/* new server -- use extended paging */
else if (ipc->ServInfo.paging_level >= 1) {
snprintf(buf, sizeof buf, "SEXP %s||", touser);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
if (buf[0] != '2') {
scr_printf("%s\n", &buf[4]);
return;
pagefp = fopen(temp, "r");
unlink(temp);
snprintf(buf, sizeof buf, "SEXP %s|-", touser);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
if (buf[0] == '4') {
strcpy(last_paged, touser);
while (fgets(buf, sizeof buf, pagefp) != NULL) {
buf[strlen(buf) - 1] = 0;
- CtdlIPC_putline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
}
fclose(pagefp);
- CtdlIPC_putline(ipc, "000");
+ CtdlIPC_chat_send(ipc, "000");
scr_printf("Message sent.\n");
} else {
scr_printf("%s\n", &buf[4]);
*/
if ( (keepalives_enabled == KA_HALF)
&& (ipc_for_signal_handlers->ServInfo.supports_qnop > 0) ) {
- CtdlIPC_putline(ipc_for_signal_handlers, "QNOP");
+ CtdlIPC_chat_send(ipc_for_signal_handlers, "QNOP");
}
}
scr_printf(" ");
}
}
- scr_printf(" -> ");
+ scr_printf("-> ");
display_prompt = 0;
}
ch = lkey();
scr_putc(buf[a]);
}
}
- scr_printf("\n\n");
+ scr_printf("\n");
return ch;
}
}
char flsz[32];
char comment[SIZ];
char buf[SIZ];
+ char *listing = NULL; /* Returned directory listing */
+ int r;
- CtdlIPC_putline(ipc, "RDIR");
- CtdlIPC_getline(ipc, buf);
- if (buf[0] != '1') {
- pprintf("%s\n", &buf[4]);
+ r = CtdlIPCReadDirectory(ipc, &listing, buf);
+ if (r / 100 != 1) {
+ pprintf("%s\n", buf);
return;
}
- extract(comment, &buf[4], 0);
- extract(flnm, &buf[4], 1);
+ extract(comment, buf, 0);
+ extract(flnm, buf, 1);
pprintf("\nDirectory of %s on %s\n", flnm, comment);
pprintf("-----------------------\n");
- while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
+ while (*listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n');
+ remove_token(listing, 0, '\n');
+
extract(flnm, buf, 0);
extract(flsz, buf, 1);
extract(comment, buf, 2);
fp = fopen(temp, "w");
fclose(fp);
- CtdlIPC_putline(ipc, check_cmd);
- CtdlIPC_getline(ipc, cmd);
+ CtdlIPC_chat_send(ipc, check_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
if (cmd[0] != '2') {
scr_printf("%s\n", &cmd[4]);
return;
}
if (strlen(editor_paths[0]) > 0) {
- CtdlIPC_putline(ipc, read_cmd);
- CtdlIPC_getline(ipc, cmd);
+ CtdlIPC_chat_send(ipc, read_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
if (cmd[0] == '1') {
fp = fopen(temp, "w");
- while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
+ while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
fprintf(fp, "%s\n", cmd);
}
fclose(fp);
}
else {
- CtdlIPC_putline(ipc, write_cmd);
- CtdlIPC_getline(ipc, cmd);
+ CtdlIPC_chat_send(ipc, write_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
if (cmd[0] != '4') {
scr_printf("%s\n", &cmd[4]);
return;
fp = fopen(temp, "r");
while (fgets(cmd, SIZ - 1, fp) != NULL) {
cmd[strlen(cmd) - 1] = 0;
- CtdlIPC_putline(ipc, cmd);
+ CtdlIPC_chat_send(ipc, cmd);
}
fclose(fp);
- CtdlIPC_putline(ipc, "000");
+ CtdlIPC_chat_send(ipc, "000");
}
unlink(temp);
void misc_server_cmd(CtdlIPC *ipc, char *cmd) {
char buf[SIZ];
- CtdlIPC_putline(ipc, cmd);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, cmd);
+ CtdlIPC_chat_recv(ipc, buf);
scr_printf("%s\n",buf);
if (buf[0]=='1') {
set_keepalives(KA_HALF);
- while (CtdlIPC_getline(ipc, buf), strcmp(buf,"000")) {
+ while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf,"000")) {
scr_printf("%s\n",buf);
}
set_keepalives(KA_YES);
if (buf[0]=='4') {
do {
newprompt("> ",buf,255);
- CtdlIPC_putline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
} while(strcmp(buf,"000"));
return;
}
int badkey;
int i, j;
int quitting = 0;
+ int modified = 0;
int r;
r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
&buf[strlen(buf)]);
recs[num_recs-1] = strdup(buf);
}
+ modified = 1;
break;
case 'd':
i = intprompt("Delete which one",
--num_recs;
for (j=i; j<num_recs; ++j)
recs[j] = recs[j+1];
+ modified = 1;
break;
case 's':
r = 1;
r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
if (r / 100 != 4) {
err_printf("%s\n", buf);
+ } else {
+ scr_printf("Wrote %d records.\n", num_recs);
+ modified = 0;
}
- quitting = 1;
break;
case 'q':
- quitting = boolprompt(
+ quitting = !modified || boolprompt(
"Quit without saving", 0);
break;
default:
badkey = 1;
}
- } while (quitting == 0);
+ } while (!quitting);
if (recs != NULL) {
for (i=0; i<num_recs; ++i) free(recs[i]);
if (e_ex_code == 0) { /* Save changes */
changefp = fopen(changefile, "w");
- CtdlIPC_putline(ipc, "GNET");
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '1') {
- while(CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
+ r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
+ if (r / 100 == 1) {
+ while(listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n');
+ remove_token(listing, 0, '\n');
extract(instr, buf, 0);
if (strcasecmp(instr, entrytype)) {
fprintf(changefp, "%s\n", buf);
}
}
}
+ if (listing) {
+ free(listing);
+ listing = NULL;
+ }
tempfp = fopen(filename, "r");
while (fgets(buf, sizeof buf, tempfp) != NULL) {
for (i=0; i<strlen(buf); ++i) {
fclose(changefp);
/* now write it to the server... */
- CtdlIPC_putline(ipc, "SNET");
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '4') {
- changefp = fopen(changefile, "r");
- if (changefp != NULL) {
- while (fgets(buf, sizeof buf,
- changefp) != NULL) {
- buf[strlen(buf) - 1] = 0;
- CtdlIPC_putline(ipc, buf);
- }
- fclose(changefp);
+ changefp = fopen(changefile, "r");
+ if (changefp != NULL) {
+ listing = load_message_from_file(changefp);
+ if (listing) {
+ r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
+ free(listing);
+ listing = NULL;
}
- CtdlIPC_putline(ipc, "000");
+ fclose(changefp);
}
}
int badkey;
int i, j;
int quitting = 0;
+ int modified = 0;
char *listing = NULL;
int r;
scr_printf("%-3s\n", buf);
color(DIM_WHITE);
}
+ scr_printf("\n");
ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
switch(ch) {
strprompt("Enter port number : ",
&buf[strlen(buf)-3], 5);
recs[num_recs-1] = strdup(buf);
+ modified = 1;
break;
case 'd':
i = intprompt("Delete which one",
--num_recs;
for (j=i; j<num_recs; ++j)
recs[j] = recs[j+1];
+ modified = 1;
break;
case 's':
r = 1;
r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
if (r / 100 != 4) {
scr_printf("%s\n", buf);
+ } else {
+ scr_printf("Wrote %d records.\n", num_recs);
+ modified = 0;
}
- quitting = 1;
break;
case 'q':
- quitting = boolprompt(
+ quitting = !modified || boolprompt(
"Quit without saving", 0);
break;
default:
badkey = 1;
}
- } while (quitting == 0);
+ } while (!quitting);
if (recs != NULL) {
for (i=0; i<num_recs; ++i) free(recs[i]);
int badkey;
int i, j;
int quitting = 0;
+ int modified = 0;
char *listing = NULL;
int r;
&buf[strlen(buf)], 16);
strcat(buf, "|");
recs[num_recs-1] = strdup(buf);
+ modified = 1;
break;
case 'd':
i = intprompt("Delete which one",
--num_recs;
for (j=i; j<num_recs; ++j)
recs[j] = recs[j+1];
+ modified = 1;
break;
case 's':
r = 1;
r = CtdlIPCSetSystemConfigByType(ipc, FILTERLIST, listing, buf);
if (r / 100 != 4) {
scr_printf("%s\n", buf);
+ } else {
+ scr_printf("Wrote %d records.\n", num_recs);
+ modified = 0;
}
- quitting = 1;
break;
case 'q':
- quitting = boolprompt(
+ quitting = !modified || boolprompt(
"Quit without saving", 0);
break;
default:
badkey = 1;
}
- } while (quitting == 0);
+ } while (!quitting);
if (recs != NULL) {
for (i=0; i<num_recs; ++i) free(recs[i]);
strcpy(portbuf, "."); /* IPGM will refuse to run on the network */
fprintf(stderr, "Attaching to server...\n");
ipc = CtdlIPC_new(1, args, hostbuf, portbuf);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
fprintf(stderr, "%s\n", &buf[4]);
snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret);
r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf);
fflush(stderr);
fprintf(stderr, "%s\n", cmd);
- CtdlIPC_putline(ipc, cmd);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_send(ipc, cmd);
+ CtdlIPC_chat_recv(ipc, buf);
fprintf(stderr, "%s\n", buf);
if (buf[0] == '1') {
- while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
+ while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf, "000")) {
printf("%s\n", buf);
}
} else if (buf[0] == '4') {
if (buf[strlen(buf) - 1] == '\r')
buf[strlen(buf) - 1] = 0;
if (strcmp(buf, "000"))
- CtdlIPC_putline(ipc, buf);
+ CtdlIPC_chat_send(ipc, buf);
} while (strcmp(buf, "000"));
- CtdlIPC_putline(ipc, "000");
+ CtdlIPC_chat_send(ipc, "000");
}
fprintf(stderr, "sendcommand: processing ended.\n");
cleanup(0);
CtdlIPC *ipc = NULL;
ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
logoff(atoi(buf));
fprintf(stderr, "Server not available: %s\n", strerror(errno));
logoff(errno);
}
- CtdlIPC_getline(ipc, buf);
+ CtdlIPC_chat_recv(ipc, buf);
if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
logoff(atoi(buf));