]> code.citadel.org Git - citadel.git/commitdiff
* More work on the self-service subscribe/unsubscribe infrastructure
authorArt Cancro <ajc@citadel.org>
Tue, 13 Aug 2002 03:46:31 +0000 (03:46 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 13 Aug 2002 03:46:31 +0000 (03:46 +0000)
citadel/ChangeLog
citadel/serv_listsub.c
citadel/techdoc/netconfigs.txt

index 09e4b305f3e44584f1b18a4efb6350a9d7e2bc1d..978332909cdf23def06e5039c05f2254795e245b 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 591.88  2002/08/13 03:46:31  ajc
+ * More work on the self-service subscribe/unsubscribe infrastructure
+
  Revision 591.87  2002/08/12 03:00:20  ajc
  * Fixed bug in <R>eplacestring which caused it to lock up in certain conditions
 
@@ -3888,4 +3891,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 38bb7c834c47f282d6ca393010b27092f0747425..7995ed540fda91f6d878519ec1c0a7ae78f9c35b 100644 (file)
  */
 void listsub_generate_token(char *buf) {
        char sourcebuf[SIZ];
+       static int seq = 0;
 
        /* Theo, please sit down and shut up.  This key doesn't have to be
-        * tinfoil-hat secure, it just needs to be reasonably unguessable.
+        * tinfoil-hat secure, it just needs to be reasonably unguessable
+        * and unique.
         */
        sprintf(sourcebuf, "%d%d%ld",
-               rand,
+               ++seq,
                getpid(),
                time(NULL)
        );
@@ -77,9 +79,149 @@ void listsub_generate_token(char *buf) {
 }
 
 
+/*
+ * Enter a subscription request
+ */
+void do_subscribe(char *room, char *email, char *subtype) {
+       struct quickroom qrbuf;
+       FILE *ncfp;
+       char filename[SIZ];
+       char token[SIZ];
+
+       if (getroom(&qrbuf, room) != 0) {
+               cprintf("%d There is no list called '%s'\n", ERROR, room);
+               return;
+       }
+
+       listsub_generate_token(token);
+
+       begin_critical_section(S_NETCONFIGS);
+       assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
+       ncfp = fopen(filename, "a");
+       if (ncfp != NULL) {
+               fprintf(ncfp, "subpending|%s|%s|%s|%ld\n",
+                       email,
+                       subtype,
+                       token,
+                       time(NULL)
+               );
+               fclose(ncfp);
+       }
+       end_critical_section(S_NETCONFIGS);
+
+       /* FIXME  --  generate and send the confirmation request */
 
+       cprintf("%d Subscription entered; confirmation request sent\n", CIT_OK);
+
+}
+
+
+/*
+ * Confirm a subscribe/unsubscribe request.
+ */
+void do_confirm(char *room, char *token) {
+       struct quickroom qrbuf;
+       FILE *ncfp;
+       char filename[SIZ];
+       char line_token[SIZ];
+       long line_offset;
+       int line_length;
+       char buf[SIZ];
+       char cmd[SIZ];
+       char email[SIZ];
+       char subtype[SIZ];
+       int success = 0;
+
+       if (getroom(&qrbuf, room) != 0) {
+               cprintf("%d There is no list called '%s'\n", ERROR, room);
+               return;
+       }
+
+       begin_critical_section(S_NETCONFIGS);
+       assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
+       ncfp = fopen(filename, "r+");
+       if (ncfp != NULL) {
+               while (line_offset = ftell(ncfp),
+                     (fgets(buf, sizeof buf, ncfp) != NULL) ) {
+                       buf[strlen(buf)-1] = 0;
+                       line_length = strlen(buf);
+                       extract(cmd, buf, 0);
+                       if (!strcasecmp(cmd, "subpending")) {
+                               extract(email, buf, 1);
+                               extract(subtype, buf, 2);
+                               extract(line_token, buf, 3);
+                               if (!strcasecmp(token, line_token)) {
+                                       if (!strcasecmp(subtype, "digest")) {
+                                               strcpy(buf, "digestrecp|");
+                                       }
+                                       else {
+                                               strcpy(buf, "listrecp|");
+                                       }
+                                       strcat(buf, email);
+                                       strcat(buf, "|");
+                                       /* SLEAZY HACK: pad the line out so
+                                        * it's the same length as the line
+                                        * we're replacing.
+                                        */
+                                       while (strlen(buf) < line_length) {
+                                               strcat(buf, " ");
+                                       }
+                                       fseek(ncfp, line_offset, SEEK_SET);
+                                       fprintf(ncfp, "%s\n", buf);
+                                       ++success;
+                               }
+                       }
+               }
+               fclose(ncfp);
+       }
+       end_critical_section(S_NETCONFIGS);
+
+       if (success) {
+               cprintf("%d %d operation(s) confirmed.\n", CIT_OK, success);
+       }
+       else {
+               cprintf("%d Invalid token.\n", ERROR);
+       }
+
+}
+
+
+
+/* 
+ * process subscribe/unsubscribe requests and confirmations
+ */
 void cmd_subs(char *cmdbuf) {
-       cprintf("%d not yet implemented, dumbass...\n", ERROR);
+
+       char opr[SIZ];
+       char room[SIZ];
+       char email[SIZ];
+       char subtype[SIZ];
+       char token[SIZ];
+
+       extract(opr, cmdbuf, 0);
+       if (!strcasecmp(opr, "subscribe")) {
+               extract(subtype, cmdbuf, 3);
+               if ( (strcasecmp(subtype, "list"))
+                  && (strcasecmp(subtype, "digest")) ) {
+                       cprintf("%d Invalid subscription type.\n", ERROR);
+               }
+               else {
+                       extract(room, cmdbuf, 1);
+                       extract(email, cmdbuf, 2);
+                       do_subscribe(room, email, subtype);
+               }
+       }
+       else if (!strcasecmp(opr, "unsubscribe")) {
+               cprintf("%d not yet implemented\n", ERROR);
+       }
+       else if (!strcasecmp(opr, "confirm")) {
+               extract(room, cmdbuf, 1);
+               extract(token, cmdbuf, 2);
+               do_confirm(room, token);
+       }
+       else {
+               cprintf("%d Invalid command\n", ERROR);
+       }
 }
 
 
index 9d66b620388113f8feb6de5bb132b3468299c191..02bc01a8416bf694d20db84f9bff4aa537defeb9 100644 (file)
@@ -51,8 +51,8 @@ data in the other direction.
  SYNTAX:       subpending|friko@mumjiboolean.com|listrecp|A234Z|1234567890
     "Subscription pending" for the specified address.  This means that
 someone has requested to subscribe an e-mail address (in this case,
-friko@mumjiboolean.com) to the list.  The third parameter is either "listrecp"
-or "digestrecp" to specify a normal subscription or a digest subscription.
+friko@mumjiboolean.com) to the list.  The third parameter is either "list"
+or "digest" to specify a normal subscription or a digest subscription.
 The fourth parameter is an authentication token which is generated by the server
 and e-mailed to the specified address.  When the user comes back and supplies
 this token, the subscription is complete.  The fifth parameter is a simple