]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* Add specific error codes for every command on the wire protocol, so that
[citadel.git] / citadel / serv_vcard.c
index b3bb09b1e72fb8b158b6a380cfb4329a0c7b35f7..c1c30c670572f9d49cfd26e4dfb150fd499e47fa 100644 (file)
 #include "internet_addressing.h"
 #include "tools.h"
 #include "vcard.h"
+#include "serv_ldap.h"
 
 struct vcard_internal_info {
        long msgnum;
 };
 
 /* Message number symbol used internally by these functions */
-unsigned long SYM_VCARD;
 #define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
 
 
@@ -173,6 +173,10 @@ void vcard_add_to_directory(long msgnum, void *data) {
                vcard_extract_internet_addresses(msg, vcard_directory_add_user);
        }
 
+#ifdef HAVE_LDAP
+       ctdl_vcard_to_ldap(msg, V2L_WRITE);
+#endif
+
        CtdlFreeMessage(msg);
 }
 
@@ -189,7 +193,7 @@ void cmd_igab(char *argbuf) {
 
         if (getroom(&CC->room, ADDRESS_BOOK_ROOM) != 0) {
                 getroom(&CC->room, hold_rm);
-               cprintf("%d cannot get address book room\n", ERROR);
+               cprintf("%d cannot get address book room\n", ERROR + ROOM_NOT_FOUND);
                return;
         }
 
@@ -197,7 +201,7 @@ void cmd_igab(char *argbuf) {
         */
        CtdlDirectoryInit();
 
-        /* We want the last (and probably only) vcard in this room */
+        /* We want *all* vCards in this room */
         CtdlForEachMessage(MSGS_ALL, 0, "text/x-vcard",
                NULL, vcard_add_to_directory, NULL);
 
@@ -513,7 +517,7 @@ void cmd_regi(char *argbuf) {
        char tmpcountry[SIZ];
 
        if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
+               cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
                return;
        }
 
@@ -569,7 +573,7 @@ void cmd_greg(char *argbuf)
        extract(who, argbuf, 0);
 
        if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n", ERROR+NOT_LOGGED_IN);
+               cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
                return;
        }
 
@@ -577,12 +581,12 @@ void cmd_greg(char *argbuf)
 
        if ((CC->user.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
                cprintf("%d Higher access required.\n",
-                       ERROR+HIGHER_ACCESS_REQUIRED);
+                       ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
 
        if (getuser(&usbuf, who) != 0) {
-               cprintf("%d '%s' not found.\n", ERROR+NO_SUCH_USER, who);
+               cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, who);
                return;
        }
 
@@ -727,6 +731,9 @@ void vcard_delete_remove(char *room, long msgnum) {
                        */
                        vcard_extract_internet_addresses(msg,
                                                        CtdlDirectoryDelUser);
+#ifdef HAVE_LDAP
+                       ctdl_vcard_to_ldap(msg, V2L_DELETE);
+#endif
                }
                ptr = strchr((char *)ptr, '\n');
                if (ptr != NULL) ++ptr;
@@ -750,7 +757,7 @@ void cmd_qdir(char *argbuf) {
 
        if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
                cprintf("%d %s was not found.\n",
-                       ERROR+NO_SUCH_USER, internet_addr);
+                       ERROR + NO_SUCH_USER, internet_addr);
                return;
        }
 
@@ -758,6 +765,35 @@ void cmd_qdir(char *argbuf) {
 }
 
 
+/*
+ * We don't know if the Contacts room exists so we just create it at login
+ */
+void vcard_create_room(void)
+{
+       struct ctdlroom qr;
+       struct visit vbuf;
+
+       /* Create the calendar room if it doesn't already exist */
+       create_room(USERCONTACTSROOM, 4, "", 0, 1, 0);
+
+       /* Set expiration policy to manual; otherwise objects will be lost! */
+       if (lgetroom(&qr, USERCONTACTSROOM)) {
+               lprintf(3, "Couldn't get the user CONTACTS room!\n");
+               return;
+       }
+       qr.QRep.expire_mode = EXPIRE_MANUAL;
+       qr.QRdefaultview = 2;   /* 2 = address book view */
+       lputroom(&qr);
+
+       /* Set the view to a calendar view */
+       CtdlGetRelationship(&vbuf, &CC->user, &qr);
+       vbuf.v_view = 2;        /* 2 = address book view */
+       CtdlSetRelationship(&vbuf, &CC->user, &qr);
+
+       return;
+}
+
+
 
 
 /*
@@ -778,13 +814,16 @@ void vcard_session_login_hook(void) {
        vcard_populate_cs_inet_email(v);
 
        vcard_free(v);
+
+       vcard_create_room();
 }
 
 
 
 char *serv_vcard_init(void)
 {
-       SYM_VCARD = CtdlGetDynamicSymbol();
+       struct ctdlroom qr;
+
        CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
        CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
        CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
@@ -797,6 +836,16 @@ char *serv_vcard_init(void)
        CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
        CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
        CtdlRegisterNetprocHook(vcard_extract_from_network);
+
+       /* Create the Global ADdress Book room if necessary */
        create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0);
+
+       /* Set expiration policy to manual; otherwise objects will be lost! */
+       if (!lgetroom(&qr, ADDRESS_BOOK_ROOM)) {
+               qr.QRep.expire_mode = EXPIRE_MANUAL;
+               qr.QRdefaultview = 2;   /* 2 = address book view */
+               lputroom(&qr);
+       }
+
        return "$Id$";
 }