*
*/
-#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <stdarg.h>
+#include "sysdep.h"
#include "citadel.h"
#include "citadel_ipc.h"
#include "citadel_decls.h"
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]);
char addr[SIZ];
FILE *tempfp;
FILE *changefp;
+ char *listing = NULL;
+ int r;
if (strlen(editor_paths[0]) == 0) {
scr_printf("You must have an external editor configured in"
fprintf(tempfp, "# Specify one per line.\n"
"\n\n");
- 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)) {
extract(addr, buf, 1);
}
}
}
+ if (listing) {
+ free(listing);
+ listing = NULL;
+ }
fclose(tempfp);
e_ex_code = 1; /* start with a failed exit code */
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;
+
+ r = CtdlIPCGetSystemConfigByType(ipc, IGNETCFG, &listing, buf);
+ if (r / 100 == 1) while (*listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n');
+ remove_token(listing, 0, '\n');
- snprintf(buf, sizeof buf, "CONF getsys|%s", IGNETCFG);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
++num_recs;
if (num_recs == 1) recs = malloc(sizeof(char *));
else recs = realloc(recs, (sizeof(char *)) * num_recs);
recs[num_recs-1] = malloc(SIZ);
strcpy(recs[num_recs-1], buf);
}
+ if (listing) free(listing);
do {
scr_printf("\n");
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':
- snprintf(buf, sizeof buf, "CONF putsys|%s", IGNETCFG);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '4') {
- for (i=0; i<num_recs; ++i) {
- CtdlIPC_putline(ipc, recs[i]);
- }
- CtdlIPC_putline(ipc, "000");
+ r = 1;
+ for (i = 0; i < num_recs; ++i)
+ r += 1 + strlen(recs[i]);
+ listing = (char*) calloc(1, r);
+ if (!listing) {
+ err_printf("Can't save config - out of memory!\n");
+ logoff(ipc, 1);
}
- else {
- scr_printf("%s\n", &buf[4]);
+ if (num_recs) for (i = 0; i < num_recs; ++i) {
+ strcat(listing, recs[i]);
+ strcat(listing, "\n");
+ }
+ 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;
+
+ r = CtdlIPCGetSystemConfigByType(ipc, FILTERLIST, &listing, buf);
+ if (r / 100 == 1) while (*listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n');
+ remove_token(listing, 0, '\n');
- snprintf(buf, sizeof buf, "CONF getsys|%s", FILTERLIST);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
++num_recs;
if (num_recs == 1) recs = malloc(sizeof(char *));
else recs = realloc(recs, (sizeof(char *)) * num_recs);
recs[num_recs-1] = malloc(SIZ);
strcpy(recs[num_recs-1], buf);
}
+ if (listing) free(listing);
do {
scr_printf("\n");
&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':
- snprintf(buf, sizeof buf, "CONF putsys|%s", FILTERLIST);
- CtdlIPC_putline(ipc, buf);
- CtdlIPC_getline(ipc, buf);
- if (buf[0] == '4') {
- for (i=0; i<num_recs; ++i) {
- CtdlIPC_putline(ipc, recs[i]);
- }
- CtdlIPC_putline(ipc, "000");
+ r = 1;
+ for (i = 0; i < num_recs; ++i)
+ r += 1 + strlen(recs[i]);
+ listing = (char*) calloc(1, r);
+ if (!listing) {
+ err_printf("Can't save config - out of memory!\n");
+ logoff(ipc, 1);
+ }
+ if (num_recs) for (i = 0; i < num_recs; ++i) {
+ strcat(listing, recs[i]);
+ strcat(listing, "\n");
}
- else {
- scr_printf("%s\n", &buf[4]);
+ 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]);