* Handle vCard registration updates for users other than the one currently
authorArt Cancro <ajc@citadel.org>
Fri, 22 Mar 2002 04:35:39 +0000 (04:35 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 22 Mar 2002 04:35:39 +0000 (04:35 +0000)
  logged in.  (Allows administrative editing of contact information.)

citadel/ChangeLog
citadel/serv_vcard.c

index 3807aac56536753628d9929e1bacb52ba3a8a4a1..fdd15760924aa055c8047547b405ee550572f4ef 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 590.160  2002/03/22 04:35:38  ajc
+ * Handle vCard registration updates for users other than the one currently
+   logged in.  (Allows administrative editing of contact information.)
+
  Revision 590.159  2002/03/20 19:03:27  ajc
  * Don't re-declare timezone variables ('cuz FreeBSD chokes on that)
 
@@ -3525,3 +3529,4 @@ 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 9e30a74923b6f374053758a92a84e78f71724c1a..dd9af715188092b81c3c2063d8e494253bd3687c 100644 (file)
@@ -246,19 +246,26 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
 int vcard_upload_beforesave(struct CtdlMessage *msg) {
        char *ptr;
        int linelen;
-        char config_rm[ROOMNAMELEN];
        char buf[SIZ];
+       struct usersupp usbuf;
+       long what_user;
 
        if (!CC->logged_in) return(0);  /* Only do this if logged in. */
 
-       /* If this isn't the configuration room, or if this isn't a MIME
-        * message, don't bother.  (Check for NULL room first, otherwise
-        * some messages will cause it to crash!!)
-        */
-       if (msg->cm_fields['O'] == NULL) return(0);
-       if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
+       /* If this isn't a "My Citadel Config" room, don't bother. */
+       if ( (CC->quickroom.QRflags && QR_MAILBOX)
+          && (!strcasecmp(&CC->quickroom.QRname[11], USERCONFIGROOM)) ) {
+               /* Yes, we want to do this */
+       }
+       else {
+               return(0);
+       }
+
+       /* If this isn't a MIME message, don't bother. */
        if (msg->cm_format_type != 4) return(0);
 
+       /* Ok, if we got this far, look into the situation further... */
+
        ptr = msg->cm_fields['M'];
        if (ptr == NULL) return(0);
        while (ptr != NULL) {
@@ -268,21 +275,33 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                
                if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
                        /* Bingo!  The user is uploading a new vCard, so
-                        * delete the old one.
+                        * delete the old one.  First, figure out which user
+                        * is being re-registered...
                         */
+                       what_user = atol(CC->quickroom.QRname);
+
+                       if (what_user == CC->usersupp.usernum) {
+                               /* It's the logged in user.  That was easy. */
+                               memcpy(&usbuf, &CC->usersupp,
+                                       sizeof(struct usersupp) );
+                       }
+                       
+                       else if (getuserbynumber(&usbuf, what_user) == 0) {
+                               /* We fetched a valid user record */
+                       }
+               
+                       else {
+                               /* No user with that number! */
+                               return(0);
+                       }
 
                        /* Delete the user's old vCard.  This would probably
                         * get taken care of by the replication check, but we
                         * want to make sure there is absolutely only one
                         * vCard in the user's config room at all times.
-                        * 
-                        * FIXME ... this needs to be tweaked to allow an admin
-                        * to make changes to another user's vCard instead of
-                        * assuming that it's always the user saving his own.
                         */
-                       MailboxName(config_rm, sizeof config_rm,
-                                   &CC->usersupp, USERCONFIGROOM);
-                       CtdlDeleteMessages(config_rm, 0L, "text/x-vcard");
+                       CtdlDeleteMessages(CC->quickroom.QRname,
+                                       0L, "text/x-vcard");
 
                        /* Set the Extended-ID to a standardized one so the
                         * replication always works correctly
@@ -290,6 +309,11 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                         if (msg->cm_fields['E'] != NULL)
                                 phree(msg->cm_fields['E']);
 
+                        if (msg->cm_fields['A'] != NULL)
+                                phree(msg->cm_fields['A']);
+
+                       msg->cm_fields['A'] = strdoop(usbuf.fullname);
+
                         snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
                                 msg->cm_fields['A'], NODENAME);
                         msg->cm_fields['E'] = strdoop(buf);