* move policy.c into modules/expire/expire_policy.c, since it just controls this.
[citadel.git] / citadel / modules / listsub / serv_listsub.c
index 93e93553b5a54c92618cb64125e6596b93baeced..2e1355f55f8ee7bd76f53d6cf180125a9d64b85c 100644 (file)
@@ -3,8 +3,21 @@
  *
  * This module handles self-service subscription/unsubscription to mail lists.
  *
- * Copyright (C) 2002-2005 by Art Cancro and others.
- * This code is released under the terms of the GNU General Public License.
+ * Copyright (c) 2002-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
 
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
-#include "serv_network.h"
 #include "clientsocket.h"
 #include "file_ops.h"
 
@@ -75,7 +85,7 @@ void listsub_generate_token(char *buf) {
        );
 
        /* Convert it to base64 so it looks cool */     
-       CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf));
+       CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf), 0);
 }
 
 
@@ -94,7 +104,7 @@ void do_subscribe(char *room, char *email, char *subtype, char *webpage) {
        char scanemail[256];
        int found_sub = 0;
 
-       if (getroom(&qrbuf, room) != 0) {
+       if (CtdlGetRoom(&qrbuf, room) != 0) {
                cprintf("%d There is no list called '%s'\n", ERROR + ROOM_NOT_FOUND, room);
                return;
        }
@@ -157,7 +167,7 @@ void do_subscribe(char *room, char *email, char *subtype, char *webpage) {
 
        /* Generate and send the confirmation request */
 
-       urlesc(urlroom, qrbuf.QRname);
+       urlesc(urlroom, ROOMNAMELEN, qrbuf.QRname);
 
        snprintf(confirmation_request, sizeof confirmation_request,
 
@@ -234,7 +244,7 @@ void do_unsubscribe(char *room, char *email, char *webpage) {
        char scanemail[256];
        int found_sub = 0;
 
-       if (getroom(&qrbuf, room) != 0) {
+       if (CtdlGetRoom(&qrbuf, room) != 0) {
                cprintf("%d There is no list called '%s'\n",
                        ERROR + ROOM_NOT_FOUND, room);
                return;
@@ -297,7 +307,7 @@ void do_unsubscribe(char *room, char *email, char *webpage) {
 
        /* Generate and send the confirmation request */
 
-       urlesc(urlroom, qrbuf.QRname);
+       urlesc(urlroom, ROOMNAMELEN, qrbuf.QRname);
 
        snprintf(confirmation_request, sizeof confirmation_request,
 
@@ -383,7 +393,7 @@ void do_confirm(char *room, char *token) {
 
        strcpy(address_to_unsubscribe, "");
 
-       if (getroom(&qrbuf, room) != 0) {
+       if (CtdlGetRoom(&qrbuf, room) != 0) {
                cprintf("%d There is no list called '%s'\n",
                        ERROR + ROOM_NOT_FOUND, room);
                return;
@@ -451,7 +461,7 @@ void do_confirm(char *room, char *token) {
         * make another pass at the file, stripping out lines referring to
         * that address.
         */
-       if (strlen(address_to_unsubscribe) > 0) {
+       if (!IsEmptyStr(address_to_unsubscribe)) {
                holdbuf = malloc(SIZ);
                begin_critical_section(S_NETCONFIGS);
                ncfp = fopen(filename, "r+");
@@ -507,7 +517,12 @@ void do_confirm(char *room, char *token) {
         */
        if (success) {
                cprintf("%d %d operation(s) confirmed.\n", CIT_OK, success);
-               lprintf(CTDL_NOTICE, "Mailing list: %s %ssubscribed to %s with token %s\n", email, (strlen(address_to_unsubscribe) > 0) ? "un" : "", room, token);
+               CtdlLogPrintf(CTDL_NOTICE, 
+                       "Mailing list: %s %ssubscribed to %s with token %s\n", 
+                       email, 
+                       (!IsEmptyStr(address_to_unsubscribe)) ? "un" : "", 
+                       room, 
+                       token);
        }
        else {
                cprintf("%d Invalid token.\n", ERROR + ILLEGAL_VALUE);
@@ -566,8 +581,11 @@ void cmd_subs(char *cmdbuf) {
  */
 CTDL_MODULE_INIT(listsub)
 {
-       CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe");
-
+       if (!threading)
+       {
+               CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe");
+       }
+       
        /* return our Subversion id for the Log */
        return "$Id$";
 }