2 * More client-side support functions.
3 * Unlike routines.c, some of these DO use global variables.
16 #if TIME_WITH_SYS_TIME
17 # include <sys/time.h>
21 # include <sys/time.h>
31 #include <libcitadel.h>
34 #include "citadel_ipc.h"
35 #include "citadel_decls.h"
36 #include "routines2.h"
45 /* work around solaris include files */
51 extern char tempdir[];
52 extern char *axdefs[8];
53 extern long highest_msg_read;
54 extern long maxmsgnum;
55 extern unsigned room_flags;
56 extern int screenwidth;
60 int eopen(char *name, int mode)
63 ret = open(name, mode);
65 scr_printf("Cannot open file '%s', mode=%d, errno=%d\n",
74 int room_prompt(unsigned int qrflags)
75 { /* return proper room prompt character */
78 if (qrflags & QR_DIRECTORY)
80 if ((a == ']') && (qrflags & QR_NETWORK))
82 if ((a == '>') && (qrflags & QR_NETWORK))
87 void entregis(CtdlIPC *ipc)
88 { /* register with name and address */
104 int r; /* IPC response code */
109 strcpy(tmpstate, "");
111 strcpy(tmpphone, "");
112 strcpy(tmpemail, "");
113 strcpy(tmpcountry, "");
115 r = CtdlIPCGetUserRegistration(ipc, NULL, ®, buf);
119 while (reg && !IsEmptyStr(reg)) {
121 extract_token(buf, reg, 0, '\n', sizeof buf);
122 remove_token(reg, 0, '\n');
125 safestrncpy(tmpname, buf, sizeof tmpname);
127 safestrncpy(tmpaddr, buf, sizeof tmpaddr);
129 safestrncpy(tmpcity, buf, sizeof tmpcity);
131 safestrncpy(tmpstate, buf, sizeof tmpstate);
133 safestrncpy(tmpzip, buf, sizeof tmpzip);
135 safestrncpy(tmpphone, buf, sizeof tmpphone);
137 safestrncpy(tmpemail, buf, sizeof tmpemail);
139 safestrncpy(tmpcountry, buf, sizeof tmpcountry);
143 strprompt("REAL name", tmpname, 29);
144 strprompt("Address", tmpaddr, 24);
145 strprompt("City/town", tmpcity, 14);
146 strprompt("State/province", tmpstate, 2);
147 strprompt("ZIP/Postal Code", tmpzip, 10);
148 strprompt("Country", tmpcountry, 31);
149 strprompt("Telephone number", tmpphone, 14);
153 safestrncpy(holdemail, tmpemail, sizeof holdemail);
154 strprompt("Email address", tmpemail, 31);
155 r = CtdlIPCDirectoryLookup(ipc, tmpemail, buf);
157 extract_token(diruser, buf, 0, '@', sizeof diruser);
158 extract_token(dirnode, buf, 1, '@', sizeof dirnode);
161 if ((strcasecmp(diruser, fullname))
162 || (strcasecmp(dirnode, ipc->ServInfo.nodename))) {
164 "\nYou can't use %s as your address.\n",
167 "It is already in use by %s @ %s.\n",
170 safestrncpy(tmpemail, holdemail, sizeof tmpemail);
175 /* now send the registration info back to the server */
176 reg = (char *)realloc(reg, SIZ);
178 sprintf(reg, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
179 tmpname, tmpaddr, tmpcity, tmpstate,
180 tmpzip, tmpphone, tmpemail, tmpcountry);
181 r = CtdlIPCSetRegistration(ipc, reg, buf);
183 scr_printf("%s\n", buf);
189 void updatels(CtdlIPC *ipc)
190 { /* make all messages old in current room */
192 int r; /* IPC response code */
194 if (rc_alt_semantics) {
195 if (maxmsgnum == 0 && highest_msg_read == 0) {
198 r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
199 maxmsgnum : highest_msg_read, buf);
201 r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
202 maxmsgnum : highest_msg_read, buf);
203 /* r = CtdlIPCSetLastRead(ipc, maxmsgnum, buf); */
204 /* This is a quick-and-dirty fix to all msgs becoming new in Mail>.
205 * It will need to be rethought when messages.c is rewritten.
209 scr_printf("%s\n", buf);
213 * only make messages old in this room that have been read
215 void updatelsa(CtdlIPC *ipc)
218 int r; /* IPC response code */
220 r = CtdlIPCSetLastRead(ipc, highest_msg_read, buf);
222 scr_printf("%s\n", &buf[4]);
227 * client-based uploads (for users with their own clientware)
229 void cli_upload(CtdlIPC *ipc)
235 int r; /* IPC response code */
239 if ((room_flags & QR_UPLOAD) == 0) {
240 scr_printf("*** You cannot upload to this room.\n");
243 newprompt("File to be uploaded: ", flnm, 55);
244 fd = open(flnm, O_RDONLY);
246 scr_printf("Cannot open '%s': %s\n", flnm, strerror(errno));
249 scr_printf("Enter a description of this file:\n");
250 newprompt(": ", desc, 75);
252 /* Keep generating filenames in hope of finding a unique one */
255 /* basename of filename */
257 if (haschar(tbuf, '/'))
258 extract_token(tbuf, flnm,
259 num_tokens(tbuf, '/') - 1,
262 /* filename.1, filename.2, etc */
264 sprintf(&tbuf[strlen(tbuf)], ".%d", a);
267 r = CtdlIPCFileUpload(ipc, tbuf, desc, flnm, progress, buf);
268 if (r / 100 == 5 || r < 0)
269 scr_printf("%s\n", buf);
274 if (a > 0) scr_printf("Saved as '%s'\n", tbuf);
279 * Function used for various image upload commands
281 void cli_image_upload(CtdlIPC *ipc, char *keyname)
287 /* Can we upload this image? */
288 r = CtdlIPCImageUpload(ipc, 0, NULL, keyname, NULL, buf);
290 scr_printf("%s\n", buf);
293 newprompt("Image file to be uploaded: ", flnm, 55);
294 r = CtdlIPCImageUpload(ipc, 1, flnm, keyname, progress, buf);
296 scr_printf("%s\n", buf);
298 scr_printf("Cannot upload '%s': %s\n", flnm, strerror(errno));
300 /* else upload succeeded */
305 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
307 void upload(CtdlIPC *ipc, int c)
308 { /* c = upload mode */
319 if ((room_flags & QR_UPLOAD) == 0) {
320 scr_printf("*** You cannot upload to this room.\n");
323 /* we don't need a filename when receiving batch y/z modem */
324 if ((c == 2) || (c == 3))
327 newprompt("Enter filename: ", flnm, 15);
329 for (a = 0; !IsEmptyStr(&flnm[a]); ++a)
330 if ((flnm[a] == '/') || (flnm[a] == '\\') || (flnm[a] == '>')
331 || (flnm[a] == '?') || (flnm[a] == '*')
332 || (flnm[a] == ';') || (flnm[a] == '&'))
335 /* create a temporary directory... */
336 if (mkdir(tempdir, 0700) != 0) {
337 scr_printf("*** Could not create temporary directory %s: %s\n",
338 tempdir, strerror(errno));
341 /* now do the transfer ... in a separate process */
348 scr_printf("Receiving %s - press Ctrl-D to end.\n", flnm);
349 fp = fopen(flnm, "w");
365 execlp("rx", "rx", flnm, NULL);
370 execlp("rb", "rb", NULL);
375 execlp("rz", "rz", NULL);
381 } while ((b != xfer_pid) && (b != (-1)));
386 scr_printf("\r*** Transfer unsuccessful.\n");
390 scr_printf("\r*** Transfer successful.\n");
391 snprintf(buf, sizeof buf, "cd %s; ls", tempdir);
392 lsfp = popen(buf, "r");
394 while (fgets(flnm, sizeof flnm, lsfp) != NULL) {
395 flnm[strlen(flnm) - 1] = 0; /* chop newline */
396 snprintf(buf, sizeof buf,
397 "Enter a short description of '%s':\n: ",
399 newprompt(buf, desc, 150);
400 snprintf(buf, sizeof buf, "%s/%s", tempdir, flnm);
401 r = CtdlIPCFileUpload(ipc, flnm, desc, buf, progress, tbuf);
402 scr_printf("%s\n", tbuf);
410 * validate a user (returns 0 for successful validation, nonzero if quitting)
412 int val_user(CtdlIPC *ipc, char *user, int do_validate)
420 int r; /* IPC response code */
423 r = CtdlIPCGetUserRegistration(ipc, user, &resp, cmd);
427 extract_token(buf, resp, 0, '\n', sizeof buf);
428 remove_token(resp, 0, '\n');
431 scr_printf("User #%s - %s ", buf, cmd);
433 scr_printf("PW: %s\n", (IsEmptyStr(buf) ? "<NOT SET>" : "<SET>") );
435 scr_printf("%s\n", buf);
437 scr_printf("%s\n", buf);
439 scr_printf("%s, ", buf);
441 scr_printf("%s ", buf);
443 scr_printf("%s\n", buf);
445 scr_printf("%s\n", buf);
449 scr_printf("%s\n", buf);
451 scr_printf("%s\n", buf);
452 } while (!IsEmptyStr(resp));
454 /* TODODRW: discrepancy here. Parts of the code refer to axdefs[7] as the highest
455 * but most of it limits it to axdefs[6].
456 * Webcit limits to 6 as does the code here but there are 7 in axdefs.h
458 scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
460 scr_printf("%s\n%s\n", user, &cmd[4]);
462 if (resp) free(resp);
465 /* now set the access level */
467 sprintf(answer, "%d", ax);
468 strprompt("New access level (? for help, q to quit)",
470 if ((answer[0] >= '0') && (answer[0] <= '6')) {
472 r = CtdlIPCValidateUser(ipc, user, ax, cmd);
474 scr_printf("%s\n\n", cmd);
477 if (tolower(answer[0]) == 'q') {
478 scr_printf("*** Aborted.\n\n");
481 if (answer[0] == '?') {
482 scr_printf("Available access levels:\n");
483 for (a=0; a<7; ++a) {
484 scr_printf("%d - %s\n",
494 void validate(CtdlIPC *ipc)
495 { /* validate new users */
499 int r; /* IPC response code */
502 r = CtdlIPCNextUnvalidatedUser(ipc, cmd);
506 scr_printf("%s\n", cmd);
508 extract_token(buf, cmd, 0, '|', sizeof buf);
509 if (val_user(ipc, buf, 1) != 0) finished = 1;
511 } while (finished == 0);
519 stty_ctdl(SB_RESTORE);
522 signal(SIGINT, SIG_DFL);
523 signal(SIGQUIT, SIG_DFL);
524 execlp(getenv("SHELL"), getenv("SHELL"), NULL);
525 scr_printf("Could not open a shell: %s\n", strerror(errno));
530 } while ((a != b) && (a != (-1)));
536 * <.A>ide <F>ile <D>elete command
538 void deletefile(CtdlIPC *ipc)
543 newprompt("Filename: ", filename, 31);
544 if (IsEmptyStr(filename))
546 CtdlIPCDeleteFile(ipc, filename, buf);
547 scr_printf("%s\n", buf);
552 * <.A>ide <F>ile <M>ove command
554 void movefile(CtdlIPC *ipc)
557 char newroom[ROOMNAMELEN];
560 newprompt("Filename: ", filename, 63);
561 if (IsEmptyStr(filename))
563 newprompt("Enter target room: ", newroom, ROOMNAMELEN - 1);
564 CtdlIPCMoveFile(ipc, filename, newroom, buf);
565 scr_printf("%s\n", buf);
570 * list of users who have filled out a bio
572 void list_bio(CtdlIPC *ipc)
577 int r; /* IPC response code */
579 r = CtdlIPCListUsersWithBios(ipc, &resp, buf);
581 pprintf("%s\n", buf);
584 while (resp && !IsEmptyStr(resp)) {
585 extract_token(buf, resp, 0, '\n', sizeof buf);
586 remove_token(resp, 0, '\n');
587 if ((pos + strlen(buf) + 5) > screenwidth) {
591 pprintf("%s, ", buf);
592 pos = pos + strlen(buf) + 2;
594 pprintf("%c%c \n\n", 8, 8);
595 if (resp) free(resp);
602 void read_bio(CtdlIPC *ipc)
607 int r; /* IPC response code */
610 newprompt("Read bio for who ('?' for list) : ", who, 25);
612 if (!strcmp(who, "?"))
614 } while (!strcmp(who, "?"));
616 r = CtdlIPCGetBio(ipc, who, &resp, buf);
618 pprintf("%s\n", buf);
621 while (!IsEmptyStr(resp)) {
622 extract_token(buf, resp, 0, '\n', sizeof buf);
623 remove_token(resp, 0, '\n');
624 pprintf("%s\n", buf);
626 if (resp) free(resp);