-void do_subscribe(char *room, char *email, char *subtype, char *webpage) {
- struct ctdlroom qrbuf;
- FILE *ncfp;
- char filename[256];
- char token[256];
- char confirmation_request[2048];
- char buf[512];
- char urlroom[ROOMNAMELEN];
- char scancmd[64];
- char scanemail[256];
- int found_sub = 0;
-
- if (CtdlGetRoom(&qrbuf, room) != 0) {
- cprintf("%d There is no list called '%s'\n", ERROR + ROOM_NOT_FOUND, room);
- return;
- }
-
- if ((qrbuf.QRflags2 & QR2_SELFLIST) == 0) {
- cprintf("%d '%s' "
- "does not accept subscribe/unsubscribe requests.\n",
- ERROR + HIGHER_ACCESS_REQUIRED, qrbuf.QRname);
- return;
- }
-
- listsub_generate_token(token);
-
- assoc_file_name(filename, sizeof filename, &qrbuf, ctdl_netcfg_dir);
-
- /*
- * Make sure the requested address isn't already subscribed
- */
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "r");
- if (ncfp != NULL) {
- while (fgets(buf, sizeof buf, ncfp) != NULL) {
- buf[strlen(buf)-1] = 0;
- extract_token(scancmd, buf, 0, '|', sizeof scancmd);
- extract_token(scanemail, buf, 1, '|', sizeof scanemail);
- if ((!strcasecmp(scancmd, "listrecp"))
- || (!strcasecmp(scancmd, "digestrecp"))) {
- if (!strcasecmp(scanemail, email)) {
- ++found_sub;
- }
- }
- }
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
-
- if (found_sub != 0) {
- cprintf("%d '%s' is already subscribed to '%s'.\n",
- ERROR + ALREADY_EXISTS,
- email, qrbuf.QRname);
- return;
- }
-
- /*
- * Now add it to the file
- */
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "a");
- if (ncfp != NULL) {
- fprintf(ncfp, "subpending|%s|%s|%s|%ld|%s\n",
- email,
- subtype,
- token,
- time(NULL),
- webpage
- );
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
-
- /* Generate and send the confirmation request */
-
- urlesc(urlroom, ROOMNAMELEN, qrbuf.QRname);