* move policy.c into modules/expire/expire_policy.c, since it just controls this.
[citadel.git] / citadel / modules / vcard / serv_vcard.c
index 18b30ae6eadb883d1b301b36e469b5fde8af4991..fdd41ef64642b837deb1b1eb37ef17aa7de53069 100644 (file)
@@ -4,7 +4,21 @@
  * A server-side module for Citadel which supports address book information
  * using the standard vCard format.
  * 
- * Copyright (c) 1999-2007 / released under the GNU General Public License
+ * Copyright (c) 1999-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 "support.h"
 #include "config.h"
 #include "control.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
 #include "serv_vcard.h"
-
+#include "citadel_ldap.h"
 #include "ctdl_module.h"
 
-
-
 /*
  * set global flag calling for an aide to validate new users
  */
@@ -83,8 +93,7 @@ void set_mm_valid(void) {
  * Extract Internet e-mail addresses from a message containing a vCard, and
  * perform a callback for any found.
  */
-void vcard_extract_internet_addresses(struct CtdlMessage *msg,
-                               void (*callback)(char *, char *) ) {
+void vcard_extract_internet_addresses(struct CtdlMessage *msg, void (*callback)(char *, char *) ) {
        struct vCard *v;
        char *s;
        char *k;
@@ -180,8 +189,8 @@ void cmd_igab(char *argbuf) {
 
        strcpy(hold_rm, CC->room.QRname);       /* save current room */
 
-       if (getroom(&CC->room, ADDRESS_BOOK_ROOM) != 0) {
-               getroom(&CC->room, hold_rm);
+       if (CtdlGetRoom(&CC->room, ADDRESS_BOOK_ROOM) != 0) {
+               CtdlGetRoom(&CC->room, hold_rm);
                cprintf("%d cannot get address book room\n", ERROR + ROOM_NOT_FOUND);
                return;
        }
@@ -194,7 +203,7 @@ void cmd_igab(char *argbuf) {
        CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
                NULL, vcard_add_to_directory, NULL);
 
-       getroom(&CC->room, hold_rm);    /* return to saved room */
+       CtdlGetRoom(&CC->room, hold_rm);        /* return to saved room */
        cprintf("%d Directory has been rebuilt.\n", CIT_OK);
 }
 
@@ -314,7 +323,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
 
 #ifdef VCARD_SAVES_BY_AIDES_ONLY
                /* Prevent non-aides from performing registration changes */
-               if (CC->user.axlevel < 6) {
+               if (CC->user.axlevel < AxAideU) {
                        return(1);
                }
 #endif
@@ -350,7 +359,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
        if (v == NULL) return(0);       /* no vCards were found in this message */
 
        /* If users cannot create their own accounts, they cannot re-register either. */
-       if ( (yes_my_citadel_config) && (config.c_disable_newu) && (CC->user.axlevel < 6) ) {
+       if ( (yes_my_citadel_config) && (config.c_disable_newu) && (CC->user.axlevel < AxAideU) ) {
                return(1);
        }
 
@@ -369,7 +378,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                        memcpy(&usbuf, &CC->user, sizeof(struct ctdluser));
                }
                
-               else if (getuserbynumber(&usbuf, what_user) == 0) {
+               else if (CtdlGetUserByNumber(&usbuf, what_user) == 0) {
                        /* We fetched a valid user record */
                }
 
@@ -490,7 +499,7 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
        if ( (strlen(CC->room.QRname) >= 12) && (!strcasecmp(&CC->room.QRname[11], USERCONFIGROOM)) ) {
                is_UserConf = 1;        /* It's someone's config room */
        }
-       MailboxName(roomname, sizeof roomname, &CC->user, USERCONFIGROOM);
+       CtdlMailboxName(roomname, sizeof roomname, &CC->user, USERCONFIGROOM);
        if (!strcasecmp(CC->room.QRname, roomname)) {
                is_UserConf = 1;
                is_MY_UserConf = 1;     /* It's MY config room */
@@ -542,19 +551,19 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
                         * But if the user was an Aide or was edited by an Aide then we can
                         * Assume they don't need validating.
                         */
-                       if (CC->user.axlevel >= 6) {
-                               lgetuser(&CC->user, CC->curr_user);
+                       if (CC->user.axlevel >= AxAideU) {
+                               CtdlGetUserLock(&CC->user, CC->curr_user);
                                CC->user.flags |= US_REGIS;
-                               lputuser(&CC->user);
+                               CtdlPutUserLock(&CC->user);
                                return (0);
                        }
                        
                        set_mm_valid();
 
                        /* ...which also means we need to flag the user */
-                       lgetuser(&CC->user, CC->curr_user);
+                       CtdlGetUserLock(&CC->user, CC->curr_user);
                        CC->user.flags |= (US_REGIS|US_NEEDVALID);
-                       lputuser(&CC->user);
+                       CtdlPutUserLock(&CC->user);
 
                        return(0);
                }
@@ -591,10 +600,10 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
        long VCmsgnum;
 
        strcpy(hold_rm, CC->room.QRname);       /* save current room */
-       MailboxName(config_rm, sizeof config_rm, u, USERCONFIGROOM);
+       CtdlMailboxName(config_rm, sizeof config_rm, u, USERCONFIGROOM);
 
-       if (getroom(&CC->room, config_rm) != 0) {
-               getroom(&CC->room, hold_rm);
+       if (CtdlGetRoom(&CC->room, config_rm) != 0) {
+               CtdlGetRoom(&CC->room, hold_rm);
                return vcard_new();
        }
 
@@ -602,7 +611,7 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
        VCmsgnum = (-1);
        CtdlForEachMessage(MSGS_LAST, 1, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
                NULL, vcard_gu_backend, (void *)&VCmsgnum );
-       getroom(&CC->room, hold_rm);    /* return to saved room */
+       CtdlGetRoom(&CC->room, hold_rm);        /* return to saved room */
 
        if (VCmsgnum < 0L) return vcard_new();
 
@@ -675,7 +684,7 @@ void cmd_regi(char *argbuf) {
        }
 
        /* If users cannot create their own accounts, they cannot re-register either. */
-       if ( (config.c_disable_newu) && (CC->user.axlevel < 6) ) {
+       if ( (config.c_disable_newu) && (CC->user.axlevel < AxAideU) ) {
                cprintf("%d Self-service registration is not allowed here.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED);
        }
@@ -738,13 +747,13 @@ void cmd_greg(char *argbuf)
 
        if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
 
-       if ((CC->user.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
+       if ((CC->user.axlevel < AxAideU) && (strcasecmp(who,CC->curr_user))) {
                cprintf("%d Higher access required.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
 
-       if (getuser(&usbuf, who) != 0) {
+       if (CtdlGetUser(&usbuf, who) != 0) {
                cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, who);
                return;
        }
@@ -1151,22 +1160,22 @@ void check_get_greeting(void) {
 /*
  * We don't know if the Contacts room exists so we just create it at login
  */
-void vcard_create_room(void)
+void vcard_CtdlCreateRoom(void)
 {
        struct ctdlroom qr;
        struct visit vbuf;
 
        /* Create the calendar room if it doesn't already exist */
-       create_room(USERCONTACTSROOM, 4, "", 0, 1, 0, VIEW_ADDRESSBOOK);
+       CtdlCreateRoom(USERCONTACTSROOM, 4, "", 0, 1, 0, VIEW_ADDRESSBOOK);
 
        /* Set expiration policy to manual; otherwise objects will be lost! */
-       if (lgetroom(&qr, USERCONTACTSROOM)) {
+       if (CtdlGetRoomLock(&qr, USERCONTACTSROOM)) {
                CtdlLogPrintf(CTDL_ERR, "Couldn't get the user CONTACTS room!\n");
                return;
        }
        qr.QRep.expire_mode = EXPIRE_MANUAL;
        qr.QRdefaultview = VIEW_ADDRESSBOOK;    /* 2 = address book view */
-       lputroom(&qr);
+       CtdlPutRoomLock(&qr);
 
        /* Set the view to a calendar view */
        CtdlGetRelationship(&vbuf, &CC->user, &qr);
@@ -1192,11 +1201,12 @@ void vcard_session_login_hook(void) {
         * into the user's vCard.
         */
        if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
-
-               /* FIXME do something with this.
-                * The DN of the account will be found in: CCC->ldap_dn
-                */
-
+               v = vcard_get_user(&CCC->user);
+               if (v) {
+                       if (Ctdl_LDAP_to_vCard(CCC->ldap_dn, v)) {
+                               vcard_write_user(&CCC->user, v);
+                       }
+               }
        }
 #endif
 
@@ -1217,7 +1227,7 @@ void vcard_session_login_hook(void) {
        /*
         * Create the user's 'Contacts' room (personal address book) if it doesn't already exist.
         */
-       vcard_create_room();
+       vcard_CtdlCreateRoom();
 }
 
 
@@ -1306,7 +1316,7 @@ void store_this_ha(struct addresses_to_be_filed *aptr) {
        int i;
 
        /* First remove any addresses we already have in the address book */
-       usergoto(aptr->roomname, 0, 0, NULL, NULL);
+       CtdlUserGoto(aptr->roomname, 0, 0, NULL, NULL);
        CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$", NULL,
                strip_addresses_already_have, aptr->collected_addresses);
 
@@ -1425,13 +1435,13 @@ CTDL_MODULE_INIT(vcard)
                CtdlRegisterFixedOutputHook("text/vcard", vcard_fixed_output);
 
                /* Create the Global ADdress Book room if necessary */
-               create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);
+               CtdlCreateRoom(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);
 
                /* Set expiration policy to manual; otherwise objects will be lost! */
-               if (!lgetroom(&qr, ADDRESS_BOOK_ROOM)) {
+               if (!CtdlGetRoomLock(&qr, ADDRESS_BOOK_ROOM)) {
                        qr.QRep.expire_mode = EXPIRE_MANUAL;
                        qr.QRdefaultview = VIEW_ADDRESSBOOK;    /* 2 = address book view */
-                       lputroom(&qr);
+                       CtdlPutRoomLock(&qr);
 
                        /*
                         * Also make sure it has a netconfig file, so the networker runs