From e322a532492f9f4e50bae5a7955a6218b24a26ea Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 20 Feb 2021 11:26:00 -0500 Subject: [PATCH] Renamed SUBS command to LSUB and changed its parameters. Subscription Type no longer applies because it never worked right anyway. There will now be only one variety of list subscription, and you will like it. Am I making myself clear? Also updated the version of citadel/libcitadel/webcit to 931 across the board, because we changed everything. --- citadel/citadel.h | 4 +- citadel/modules/listsub/serv_listsub.c | 128 ++++++++++++++++++++----- libcitadel/lib/libcitadel.h | 4 +- webcit/listsub.c | 32 ++----- webcit/webcit.h | 6 +- 5 files changed, 122 insertions(+), 52 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index fe4654d60..437b6ceed 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -35,10 +35,10 @@ extern "C" { */ #define CITADEL PACKAGE_STRING -#define REV_LEVEL 930 // This version +#define REV_LEVEL 931 // This version #define REV_MIN 591 // Oldest compatible database #define EXPORT_REV_MIN 760 // Oldest compatible export files -#define LIBCITADEL_MIN 926 // Minimum required version of libcitadel +#define LIBCITADEL_MIN 931 // Minimum required version of libcitadel #define SERVER_TYPE 0 // zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations #ifdef LIBCITADEL_VERSION_NUMBER diff --git a/citadel/modules/listsub/serv_listsub.c b/citadel/modules/listsub/serv_listsub.c index 9cf3fb86c..d4db241bf 100644 --- a/citadel/modules/listsub/serv_listsub.c +++ b/citadel/modules/listsub/serv_listsub.c @@ -94,7 +94,10 @@ void send_subscribe_confirmation_email(char *roomname, char *emailaddr, char *ur "\n" "--__ctdlmultipart__--\n" , - emailaddr, roomname, url, urlroom, confirmation_token, roomname, + emailaddr, roomname, + url, urlroom, confirmation_token, + roomname + , emailaddr, roomname, url, urlroom, confirmation_token, url, urlroom, confirmation_token, @@ -151,14 +154,17 @@ void send_unsubscribe_confirmation_email(char *roomname, char *emailaddr, char * "\n" "--__ctdlmultipart__--\n" , - emailaddr, roomname, url, urlroom, confirmation_token, roomname, + emailaddr, roomname, + url, urlroom, confirmation_token, + roomname + , emailaddr, roomname, url, urlroom, confirmation_token, url, urlroom, confirmation_token, roomname ); - quickie_message("Citadel", from_address, emailaddr, NULL, emailtext, FMT_RFC822, "Please confirm your list subscription"); + quickie_message("Citadel", from_address, emailaddr, NULL, emailtext, FMT_RFC822, "Please confirm your list unsubscription"); } @@ -195,21 +201,21 @@ void do_subscribe_or_unsubscribe(int action, char *emailaddr, char *url) { keep_this_line = 0; } - char buf_token[1024]; + char buf_directive[1024]; char buf_email[1024]; - extract_token(buf_token, buf, 0, '|', sizeof buf_token); + extract_token(buf_directive, buf, 0, '|', sizeof buf_directive); extract_token(buf_email, buf, 1, '|', sizeof buf_email); - if ( ( (!strcasecmp(buf_token, "listrecp")) || (!strcasecmp(buf_token, "digestrecp")) ) + if ( ( (!strcasecmp(buf_directive, "listrecp")) || (!strcasecmp(buf_directive, "digestrecp")) ) && (!strcasecmp(buf_email, emailaddr)) ) { is_already_subscribed = 1; } - if ( (!strcasecmp(buf_token, "subpending")) || (!strcasecmp(buf_token, "unsubpending")) ) { + if ( (!strcasecmp(buf_directive, "subpending")) || (!strcasecmp(buf_directive, "unsubpending")) ) { time_t pendingtime = extract_long(buf, 3); if ((time(NULL) - pendingtime) > 259200) { - syslog(LOG_DEBUG, "%s %s is %ld seconds old - deleting it", buf_email, buf_token, time(NULL) - pendingtime); + syslog(LOG_DEBUG, "%s %s is %ld seconds old - deleting it", buf_email, buf_directive, time(NULL) - pendingtime); keep_this_line = 0; } } @@ -232,8 +238,6 @@ void do_subscribe_or_unsubscribe(int action, char *emailaddr, char *url) { } // Write the new netconfig back to disk - syslog(LOG_DEBUG, "old: <\033[31m%s\033[0m>", oldnetconfig); - syslog(LOG_DEBUG, "new: <\033[32m%s\033[0m>", newnetconfig); SaveRoomNetConfigFile(CC->room.QRnumber, newnetconfig); end_critical_section(S_NETCONFIGS); free(newnetconfig); // this was the new netconfig, free it because we're done with it @@ -241,27 +245,109 @@ void do_subscribe_or_unsubscribe(int action, char *emailaddr, char *url) { // Tell the client what happened. if ((action == SUBSCRIBE) && (is_already_subscribed)) { - cprintf("%d This email is already subscribed.\n", ERROR + ALREADY_EXISTS); + cprintf("%d This email address is already subscribed.\n", ERROR + ALREADY_EXISTS); } else if ((action == SUBSCRIBE) && (!is_already_subscribed)) { - cprintf("%d Confirmation email sent.\n", CIT_OK); + cprintf("%d Subscription was requested, and a confirmation email was sent.\n", CIT_OK); } else if ((action == UNSUBSCRIBE) && (!is_already_subscribed)) { - cprintf("%d This email is not subscribed.\n", ERROR + NO_SUCH_USER); + cprintf("%d This email address is not subscribed.\n", ERROR + NO_SUCH_USER); } else if ((action == UNSUBSCRIBE) && (is_already_subscribed)) { - cprintf("%d Confirmation email sent.\n", CIT_OK); + cprintf("%d Unsubscription was requested, and a confirmation email was sent.\n", CIT_OK); } else { - cprintf("%d FIXME tell the client what we did\n", ERROR); + cprintf("%d Nothing happens.\n", ERROR); + } +} + + +/* + * Confirm a list subscription or unsubscription + */ +void do_confirm(char *token) { + int yes_subscribe = 0; // Set to 1 if the confirmation to subscribe is validated. + int yes_unsubscribe = 0; // Set to 1 if the confirmation to unsubscribe is validated. + int i; + char buf[1024]; + int config_lines = 0; + char pending_directive[128]; + char pending_email[256]; + char pending_token[128]; + + // We will have to do this in two passes. The first pass checks to see if we have a confirmation request matching the token. + char *oldnetconfig = LoadRoomNetConfigFile(CC->room.QRnumber); + if (!oldnetconfig) { + cprintf("%d There are no pending requests.\n", ERROR + NO_SUCH_USER); + return; } + + config_lines = num_tokens(oldnetconfig, '\n'); + for (i=0; iroom.QRnumber); + if (!oldnetconfig) { + oldnetconfig = strdup(""); + } + + // The new netconfig begins with an empty buffer... + begin_critical_section(S_NETCONFIGS); + char *newnetconfig = malloc(strlen(oldnetconfig) + 1024); + newnetconfig[0] = 0; + + config_lines = num_tokens(oldnetconfig, '\n'); + for (i=0; iroom.QRnumber, newnetconfig); + end_critical_section(S_NETCONFIGS); + free(oldnetconfig); + free(newnetconfig); + cprintf("%d The pending request was confirmed.\n", CIT_OK); } /* * process subscribe/unsubscribe requests and confirmations */ -void cmd_subs(char *cmdbuf) { +void cmd_lsub(char *cmdbuf) { char cmd[20]; char roomname[ROOMNAMELEN]; char emailaddr[1024]; @@ -287,21 +373,19 @@ void cmd_subs(char *cmdbuf) { if (!strcasecmp(cmd, "subscribe")) { extract_token(emailaddr, cmdbuf, 2, '|', sizeof emailaddr); // token 2 is the subscriber's email address - extract_token(options, cmdbuf, 3, '|', sizeof options); // there are no options ... ignore this token - extract_token(url, cmdbuf, 4, '|', sizeof url); // token 3 is the URL at which we subscribed + extract_token(url, cmdbuf, 3, '|', sizeof url); // token 3 is the URL at which we subscribed do_subscribe_or_unsubscribe(SUBSCRIBE, emailaddr, url); } else if (!strcasecmp(cmd, "unsubscribe")) { extract_token(emailaddr, cmdbuf, 2, '|', sizeof emailaddr); // token 2 is the subscriber's email address - extract_token(options, cmdbuf, 3, '|', sizeof options); // there are no options ... ignore this token - extract_token(url, cmdbuf, 4, '|', sizeof url); // token 3 is the URL at which we subscribed + extract_token(url, cmdbuf, 3, '|', sizeof url); // token 3 is the URL at which we subscribed do_subscribe_or_unsubscribe(UNSUBSCRIBE, emailaddr, url); } else if (!strcasecmp(cmd, "confirm")) { extract_token(token, cmdbuf, 2, '|', sizeof token); // token 2 is the confirmation token - cprintf("%d not implemented\n", ERROR); + do_confirm(token); } else { // sorry man, I can't deal with that @@ -317,7 +401,7 @@ CTDL_MODULE_INIT(listsub) { if (!threading) { - CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe"); + CtdlRegisterProtoHook(cmd_lsub, "LSUB", "List subscribe/unsubscribe"); } /* return our module name for the log */ diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index fe9cbd700..7740dc190 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -1,7 +1,7 @@ /* * Header file for libcitadel * - * Copyright (c) 1987-2019 by the citadel.org team + * Copyright (c) 1987-2021 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -26,7 +26,7 @@ #include #include -#define LIBCITADEL_VERSION_NUMBER 926 +#define LIBCITADEL_VERSION_NUMBER 931 /* * Here's a bunch of stupid magic to make the MIME parser portable. diff --git a/webcit/listsub.c b/webcit/listsub.c index 64f809e52..d445d05bd 100644 --- a/webcit/listsub.c +++ b/webcit/listsub.c @@ -17,13 +17,11 @@ /* * List subscription handling */ - -int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) -{ +int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) { int rc; StrBuf *Line; const char *ImpMsg; - const StrBuf *Room, *Email, *SubType; + const StrBuf *Room, *Email; if (strcmp(bstr("cmd"), "subscribe")) { return 0; @@ -43,25 +41,20 @@ int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) AppendImportantMessage(ImpMsg, -1); return 0; } - SubType = sbstr("subtype"); Line = NewStrBuf(); - serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub", - ChrPtr(Room), - ChrPtr(Email), - ChrPtr(SubType), - ChrPtr(site_prefix) - ); + serv_printf("LSUB subscribe|%s|%s|%s/listsub", ChrPtr(Room), ChrPtr(Email), ChrPtr(site_prefix)); StrBuf_ServGetln(Line); rc = GetServerStatusMsg(Line, NULL, 1, 2); FreeStrBuf(&Line); - if (rc == 2) + if (rc == 2) { putbstr("__FAIL", NewStrBufPlain(HKEY("1"))); + } return rc == 2; } -int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) -{ + +int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) { int rc; StrBuf *Line; const char *ImpMsg; @@ -86,11 +79,7 @@ int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP return 0; } - serv_printf("SUBS unsubscribe|%s|%s|%s/listsub", - ChrPtr(Room), - ChrPtr(Email), - ChrPtr(site_prefix) - ); + serv_printf("LSUB unsubscribe|%s|%s|%s/listsub", ChrPtr(Room), ChrPtr(Email), ChrPtr(site_prefix)); Line = NewStrBuf(); StrBuf_ServGetln(Line); rc = GetServerStatusMsg(Line, NULL, 1, 2); @@ -127,10 +116,7 @@ int Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE(StrBuf *Target, WCTemplputPara } Line = NewStrBuf(); - serv_printf("SUBS confirm|%s|%s", - ChrPtr(Room), - ChrPtr(Token) - ); + serv_printf("LSUB confirm|%s|%s", ChrPtr(Room), ChrPtr(Token)); StrBuf_ServGetln(Line); rc = GetServerStatusMsg(Line, NULL, 1, 2); FreeStrBuf(&Line); diff --git a/webcit/webcit.h b/webcit/webcit.h index d263ef246..cd48d5166 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1987-2020 by the citadel.org team + * Copyright (c) 1987-2021 by the citadel.org team * * This program is open source software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 3. @@ -128,8 +128,8 @@ extern char *ssl_cipher_list; #define DEVELOPER_ID 0 #define CLIENT_ID 4 #define CLIENT_VERSION 927 /* This version of WebCit */ -#define MINIMUM_CIT_VERSION 930 /* Minimum required version of Citadel server */ -#define LIBCITADEL_MIN 924 /* Minimum required version of libcitadel */ +#define MINIMUM_CIT_VERSION 931 /* Minimum required version of Citadel server */ +#define LIBCITADEL_MIN 931 /* Minimum required version of libcitadel */ #define DEFAULT_HOST "localhost" /* Default Citadel server */ #define DEFAULT_PORT "504" #define TARGET "webcit01" /* Window target for inline URL's */ -- 2.30.2