]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* Create a "Contacts" room for personal address book use
[citadel.git] / citadel / serv_vcard.c
index beed02f7f1663461506bdd9dd2420aab4d11e4fc..443783172a31781ffeb00da5022a9802a9373a32 100644 (file)
@@ -69,7 +69,6 @@ struct vcard_internal_info {
 };
 
 /* Message number symbol used internally by these functions */
-unsigned long SYM_VCARD;
 #define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
 
 
@@ -255,7 +254,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
        char *ptr;
        int linelen;
        char buf[SIZ];
-       struct user usbuf;
+       struct ctdluser usbuf;
        long what_user;
 
        if (!CC->logged_in) return(0);  /* Only do this if logged in. */
@@ -291,7 +290,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                        if (what_user == CC->user.usernum) {
                                /* It's the logged in user.  That was easy. */
                                memcpy(&usbuf, &CC->user,
-                                       sizeof(struct user) );
+                                       sizeof(struct ctdluser) );
                        }
                        
                        else if (getuserbynumber(&usbuf, what_user) == 0) {
@@ -421,7 +420,7 @@ void vcard_gu_backend(long msgnum, void *userdata) {
  * If this user has a vcard on disk, read it into memory, otherwise allocate
  * and return an empty vCard.
  */
-struct vCard *vcard_get_user(struct user *u) {
+struct vCard *vcard_get_user(struct ctdluser *u) {
         char hold_rm[ROOMNAMELEN];
         char config_rm[ROOMNAMELEN];
        struct CtdlMessage *msg;
@@ -458,7 +457,7 @@ struct vCard *vcard_get_user(struct user *u) {
 /*
  * Write our config to disk
  */
-void vcard_write_user(struct user *u, struct vCard *v) {
+void vcard_write_user(struct ctdluser *u, struct vCard *v) {
         char temp[PATH_MAX];
         FILE *fp;
        char *ser;
@@ -559,7 +558,7 @@ void cmd_regi(char *argbuf) {
  */
 void cmd_greg(char *argbuf)
 {
-       struct user usbuf;
+       struct ctdluser usbuf;
        struct vCard *v;
        char *s;
        char who[SIZ];
@@ -758,6 +757,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 +806,14 @@ 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();
        CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
        CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
        CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);