4 * Manage user preferences with a little help from the Citadel server.
15 #include <sys/types.h>
17 #include <sys/socket.h>
20 #include <netinet/in.h>
32 void load_preferences(void) {
36 serv_printf("GOTO My Citadel Config");
38 if (buf[0] != '2') return;
40 serv_puts("MSGS ALL|0|1");
43 serv_puts("subj|__ WebCit Preferences __");
46 while (serv_gets(buf), strcmp(buf, "000")) {
51 serv_printf("MSG0 %ld", msgnum);
54 while (serv_gets(buf),
55 (strcmp(buf, "text") && strcmp(buf, "000"))) {
57 if (!strcmp(buf, "text")) {
58 while (serv_gets(buf), strcmp(buf, "000")) {
59 if (WC->preferences == NULL) {
60 WC->preferences = malloc(SIZ);
61 strcpy(WC->preferences, "");
64 WC->preferences = realloc(
66 strlen(WC->preferences)
70 strcat(WC->preferences, buf);
71 strcat(WC->preferences, "\n");
77 /* Go back to the room we're supposed to be in */
78 serv_printf("GOTO %s", WC->wc_roomname);
82 void save_preferences(void) {
86 serv_printf("GOTO My Citadel Config");
88 if (buf[0] != '2') { /* try to create the config room if not there */
89 serv_printf("CRE8 1|My Citadel Config|4|0");
91 serv_printf("GOTO My Citadel Config");
93 if (buf[0] != '2') return; /* oh well. */
96 serv_puts("MSGS ALL|0|1");
99 serv_puts("subj|__ WebCit Preferences __");
102 while (serv_gets(buf), strcmp(buf, "000")) {
107 serv_printf("DELE %ld", msgnum);
111 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
114 serv_puts(WC->preferences);
119 /* Go back to the room we're supposed to be in */
120 serv_printf("GOTO %s", WC->wc_roomname);
124 void get_preference(char *key, char *value) {
132 num_prefs = num_tokens(WC->preferences, '\n');
133 for (i=0; i<num_prefs; ++i) {
134 extract_token(buf, WC->preferences, i, '\n');
135 extract_token(thiskey, buf, 0, '|');
136 if (!strcasecmp(thiskey, key)) {
137 extract_token(value, buf, 1, '|');
142 void set_preference(char *key, char *value) {
147 char *newprefs = NULL;
149 num_prefs = num_tokens(WC->preferences, '\n');
150 for (i=0; i<num_prefs; ++i) {
151 extract_token(buf, WC->preferences, i, '\n');
152 extract_token(thiskey, buf, 0, '|');
153 if (strcasecmp(thiskey, key)) {
154 if (newprefs == NULL) newprefs = strdup("");
156 newprefs = realloc(newprefs,
157 strlen(newprefs) + SIZ );
159 strcat(newprefs, buf);
160 strcat(newprefs, "\n");
165 if (newprefs == NULL) newprefs = strdup("");
167 newprefs = realloc(newprefs,
168 strlen(newprefs) + SIZ );
170 sprintf(&newprefs[strlen(newprefs)], "%s|%s\n", key, value);