4 * A server-side module for Citadel which supports address book information
5 * using the standard vCard format.
7 * Copyright (c) 1999-2002 / released under the GNU General Public License
11 * Where we keep messages containing the vCards that source our directory. It
12 * makes no sense to change this, because you'd have to change it on every
13 * system on the network. That would be stupid.
15 #define ADDRESS_BOOK_ROOM "Global Address Book"
18 * Format of the "Exclusive ID" field of the message containing a user's
19 * vCard. Doesn't matter what it really looks like as long as it's both
20 * unique and consistent (because we use it for replication checking to
21 * delete the old vCard network-wide when the user enters a new one).
23 #define VCARD_EXT_FORMAT "Citadel vCard: personal card for %s at %s"
34 #include <sys/types.h>
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
41 # include <sys/time.h>
52 #include "sysdep_decls.h"
53 #include "citserver.h"
57 #include "serv_extensions.h"
63 #include "internet_addressing.h"
66 #include "serv_ldap.h"
69 * set global flag calling for an aide to validate new users
71 void set_mm_valid(void) {
72 begin_critical_section(S_CONTROL);
74 CitControl.MMflags = CitControl.MMflags | MM_VALID ;
76 end_critical_section(S_CONTROL);
82 * Extract Internet e-mail addresses from a message containing a vCard, and
83 * perform a callback for any found.
85 void vcard_extract_internet_addresses(struct CtdlMessage *msg,
86 void (*callback)(char *, char *) ) {
90 char citadel_address[SIZ];
92 int found_something = 0;
94 if (msg->cm_fields['A'] == NULL) return;
95 if (msg->cm_fields['N'] == NULL) return;
96 snprintf(citadel_address, sizeof citadel_address, "%s @ %s",
97 msg->cm_fields['A'], msg->cm_fields['N']);
99 v = vcard_load(msg->cm_fields['M']);
100 if (v == NULL) return;
102 /* Go through the vCard searching for *all* instances of
103 * the "email;internet" key
106 s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
110 if (strlen(addr) > 0) {
111 if (callback != NULL) {
112 callback(addr, citadel_address);
121 } while(found_something);
129 * Callback for vcard_add_to_directory()
130 * (Lotsa ugly nested callbacks. Oh well.)
132 void vcard_directory_add_user(char *internet_addr, char *citadel_addr) {
135 /* We have to validate that we're not stepping on someone else's
136 * email address ... but only if we're logged in. Otherwise it's
137 * probably just the networker or something.
140 lprintf(CTDL_DEBUG, "Checking for <%s>...\n", internet_addr);
141 if (CtdlDirectoryLookup(buf, internet_addr, sizeof buf) == 0) {
142 if (strcasecmp(buf, citadel_addr)) {
143 /* This address belongs to someone else.
144 * Bail out silently without saving.
146 lprintf(CTDL_DEBUG, "DOOP!\n");
151 lprintf(CTDL_INFO, "Adding %s (%s) to directory\n",
152 citadel_addr, internet_addr);
153 CtdlDirectoryAddUser(internet_addr, citadel_addr);
158 * Back end function for cmd_igab()
160 void vcard_add_to_directory(long msgnum, void *data) {
161 struct CtdlMessage *msg;
163 msg = CtdlFetchMessage(msgnum, 1);
165 vcard_extract_internet_addresses(msg, vcard_directory_add_user);
169 ctdl_vcard_to_ldap(msg, V2L_WRITE);
172 CtdlFreeMessage(msg);
177 * Initialize Global Adress Book
179 void cmd_igab(char *argbuf) {
180 char hold_rm[ROOMNAMELEN];
182 if (CtdlAccessCheck(ac_aide)) return;
184 strcpy(hold_rm, CC->room.QRname); /* save current room */
186 if (getroom(&CC->room, ADDRESS_BOOK_ROOM) != 0) {
187 getroom(&CC->room, hold_rm);
188 cprintf("%d cannot get address book room\n", ERROR + ROOM_NOT_FOUND);
192 /* Empty the existing database first.
196 /* We want *all* vCards in this room */
197 CtdlForEachMessage(MSGS_ALL, 0, "text/x-vcard",
198 NULL, vcard_add_to_directory, NULL);
200 getroom(&CC->room, hold_rm); /* return to saved room */
201 cprintf("%d Directory has been rebuilt.\n", CIT_OK);
208 * See if there is a valid Internet address in a vCard to use for outbound
209 * Internet messages. If there is, stick it in CC->cs_inet_email.
211 void vcard_populate_cs_inet_email(struct vCard *v) {
213 int continue_searching = 1;
216 /* Go through the vCard searching for *all* instances of
217 * the "email;internet" key
220 s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
222 continue_searching = 1;
225 if (strlen(addr) > 0) {
226 if (IsDirectory(addr)) {
227 continue_searching = 0;
228 safestrncpy(CC->cs_inet_email,
230 sizeof(CC->cs_inet_email)
237 continue_searching = 0;
239 } while(continue_searching);
245 * This handler detects whether the user is attempting to save a new
246 * vCard as part of his/her personal configuration, and handles the replace
247 * function accordingly (delete the user's existing vCard in the config room
248 * and in the global address book).
250 int vcard_upload_beforesave(struct CtdlMessage *msg) {
255 struct ctdluser usbuf;
257 struct vCard *v = NULL;
260 int yes_my_citadel_config = 0;
261 int yes_any_vcard_room = 0;
263 if (!CC->logged_in) return(0); /* Only do this if logged in. */
265 /* Is this some user's "My Citadel Config" room? */
266 if ( (CC->room.QRflags && QR_MAILBOX)
267 && (!strcasecmp(&CC->room.QRname[11], USERCONFIGROOM)) ) {
268 /* Yes, we want to do this */
269 yes_my_citadel_config = 1;
272 /* Is this a room with an address book in it? */
273 if (CC->curr_view == VIEW_ADDRESSBOOK) {
274 yes_any_vcard_room = 1;
277 /* If neither condition exists, don't run this hook. */
278 if ( (!yes_my_citadel_config) && (!yes_any_vcard_room) ) {
282 /* If this isn't a MIME message, don't bother. */
283 if (msg->cm_format_type != 4) return(0);
285 /* Ok, if we got this far, look into the situation further... */
287 ptr = msg->cm_fields['M'];
288 if (ptr == NULL) return(0);
289 while (ptr != NULL) {
291 linelen = strcspn(ptr, "\n");
292 if (linelen == 0) return(0); /* end of headers */
294 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
297 if (yes_my_citadel_config) {
298 /* Bingo! The user is uploading a new vCard, so
299 * delete the old one. First, figure out which user
300 * is being re-registered...
302 what_user = atol(CC->room.QRname);
304 if (what_user == CC->user.usernum) {
305 /* It's the logged in user. That was easy. */
306 memcpy(&usbuf, &CC->user,
307 sizeof(struct ctdluser) );
310 else if (getuserbynumber(&usbuf, what_user) == 0) {
311 /* We fetched a valid user record */
315 /* No user with that number! */
319 /* Delete the user's old vCard. This would probably
320 * get taken care of by the replication check, but we
321 * want to make sure there is absolutely only one
322 * vCard in the user's config room at all times.
324 CtdlDeleteMessages(CC->room.QRname,
325 0L, "text/x-vcard", 1);
327 /* Make the author of the message the name of the user.
329 if (msg->cm_fields['A'] != NULL) {
330 free(msg->cm_fields['A']);
332 msg->cm_fields['A'] = strdup(usbuf.fullname);
335 /* Manipulate the vCard data structure */
336 v = vcard_load(msg->cm_fields['M']);
339 /* Insert or replace RFC2739-compliant free/busy URL */
340 if (yes_my_citadel_config) {
341 sprintf(buf, "http://%s/%s.vfb",
344 for (i=0; i<strlen(buf); ++i) {
345 if (buf[i] == ' ') buf[i] = '_';
347 vcard_set_prop(v, "FBURL;PREF", buf, 0);
350 /* If this is an address book room, and the vCard has
351 * no UID, then give it one.
353 if (yes_any_vcard_room) {
354 s = vcard_get_prop(v, "UID", 0, 0, 0);
357 vcard_set_prop(v, "UID", buf, 0);
361 /* Enforce local UID policy if applicable */
362 if (yes_my_citadel_config) {
363 snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
364 msg->cm_fields['A'], NODENAME);
365 vcard_set_prop(v, "UID", buf, 0);
369 * Set the EUID of the message to the UID of the vCard.
371 if (msg->cm_fields['E'] != NULL) free(msg->cm_fields['E']);
372 s = vcard_get_prop(v, "UID", 0, 0, 0);
374 msg->cm_fields['E'] = strdup(s);
375 if (msg->cm_fields['U'] == NULL) {
376 msg->cm_fields['U'] = strdup(s);
381 * Set the Subject to the name in the vCard.
383 s = vcard_get_prop(v, "FN", 0, 0, 0);
385 s = vcard_get_prop(v, "N", 0, 0, 0);
388 if (msg->cm_fields['U'] != NULL) {
389 free(msg->cm_fields['U']);
391 msg->cm_fields['U'] = strdup(s);
394 /* Re-serialize it back into the msg body */
395 ser = vcard_serialize(v);
397 msg->cm_fields['M'] = realloc(
401 sprintf(msg->cm_fields['M'],
402 "Content-type: text/x-vcard"
403 "\r\n\r\n%s\r\n", ser);
409 /* Now allow the save to complete. */
413 ptr = strchr((char *)ptr, '\n');
414 if (ptr != NULL) ++ptr;
423 * This handler detects whether the user is attempting to save a new
424 * vCard as part of his/her personal configuration, and handles the replace
425 * function accordingly (copy the vCard from the config room to the global
428 int vcard_upload_aftersave(struct CtdlMessage *msg) {
434 if (!CC->logged_in) return(0); /* Only do this if logged in. */
436 /* If this isn't the configuration room, or if this isn't a MIME
437 * message, don't bother.
439 if (msg->cm_fields['O'] == NULL) return(0);
440 if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
441 if (msg->cm_format_type != 4) return(0);
443 ptr = msg->cm_fields['M'];
444 if (ptr == NULL) return(0);
445 while (ptr != NULL) {
447 linelen = strcspn(ptr, "\n");
448 if (linelen == 0) return(0); /* end of headers */
450 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
451 /* Bingo! The user is uploading a new vCard, so
452 * copy it to the Global Address Book room.
455 I = atol(msg->cm_fields['I']);
456 if (I < 0L) return(0);
458 /* Store our Internet return address in memory */
459 v = vcard_load(msg->cm_fields['M']);
460 vcard_populate_cs_inet_email(v);
463 /* Put it in the Global Address Book room... */
464 CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I,
465 (SM_VERIFY_GOODNESS | SM_DO_REPL_CHECK) );
467 /* ...and also in the directory database. */
468 vcard_add_to_directory(I, NULL);
470 /* Some sites want an Aide to be notified when a
471 * user registers or re-registers...
475 /* ...which also means we need to flag the user */
476 lgetuser(&CC->user, CC->curr_user);
477 CC->user.flags |= (US_REGIS|US_NEEDVALID);
483 ptr = strchr((char *)ptr, '\n');
484 if (ptr != NULL) ++ptr;
493 * back end function used for callbacks
495 void vcard_gu_backend(long supplied_msgnum, void *userdata) {
498 msgnum = (long *) userdata;
499 *msgnum = supplied_msgnum;
504 * If this user has a vcard on disk, read it into memory, otherwise allocate
505 * and return an empty vCard.
507 struct vCard *vcard_get_user(struct ctdluser *u) {
508 char hold_rm[ROOMNAMELEN];
509 char config_rm[ROOMNAMELEN];
510 struct CtdlMessage *msg;
514 strcpy(hold_rm, CC->room.QRname); /* save current room */
515 MailboxName(config_rm, sizeof config_rm, u, USERCONFIGROOM);
517 if (getroom(&CC->room, config_rm) != 0) {
518 getroom(&CC->room, hold_rm);
522 /* We want the last (and probably only) vcard in this room */
524 CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard",
525 NULL, vcard_gu_backend, (void *)&VCmsgnum );
526 getroom(&CC->room, hold_rm); /* return to saved room */
528 if (VCmsgnum < 0L) return vcard_new();
530 msg = CtdlFetchMessage(VCmsgnum, 1);
531 if (msg == NULL) return vcard_new();
533 v = vcard_load(msg->cm_fields['M']);
534 CtdlFreeMessage(msg);
540 * Store this user's vCard in the appropriate place
543 * Write our config to disk
545 void vcard_write_user(struct ctdluser *u, struct vCard *v) {
550 strcpy(temp, tmpnam(NULL));
551 ser = vcard_serialize(v);
553 fp = fopen(temp, "w");
554 if (fp == NULL) return;
556 fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
558 fwrite(ser, strlen(ser), 1, fp);
563 /* This handy API function does all the work for us.
564 * NOTE: normally we would want to set that last argument to 1, to
565 * force the system to delete the user's old vCard. But it doesn't
566 * have to, because the vcard_upload_beforesave() hook above
567 * is going to notice what we're trying to do, and delete the old vCard.
569 CtdlWriteObject(USERCONFIGROOM, /* which room */
570 "text/x-vcard", /* MIME type */
571 temp, /* temp file */
574 0, /* don't delete others of this type */
583 * Old style "enter registration info" command. This function simply honors
584 * the REGI protocol command, translates the entered parameters into a vCard,
585 * and enters the vCard into the user's configuration.
587 void cmd_regi(char *argbuf) {
590 struct vCard *my_vcard;
596 char tmpaddress[SIZ];
597 char tmpcountry[SIZ];
601 if (!(CC->logged_in)) {
602 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
606 my_vcard = vcard_get_user(&CC->user);
609 strcpy(tmpstate, "");
611 strcpy(tmpcountry, "USA");
613 cprintf("%d Send registration...\n", SEND_LISTING);
615 while (client_getln(buf, sizeof buf), strcmp(buf,"000")) {
616 if (a==0) vcard_set_prop(my_vcard, "n", buf, 0);
617 if (a==1) strcpy(tmpaddr, buf);
618 if (a==2) strcpy(tmpcity, buf);
619 if (a==3) strcpy(tmpstate, buf);
621 for (c=0; c<strlen(buf); ++c) {
622 if ((buf[c]>='0') && (buf[c]<='9')) {
629 if (a==5) vcard_set_prop(my_vcard, "tel;home", buf, 0);
630 if (a==6) vcard_set_prop(my_vcard, "email;internet", buf, 0);
631 if (a==7) strcpy(tmpcountry, buf);
635 snprintf(tmpaddress, sizeof tmpaddress, ";;%s;%s;%s;%s;%s",
636 tmpaddr, tmpcity, tmpstate, tmpzip, tmpcountry);
637 vcard_set_prop(my_vcard, "adr", tmpaddress, 0);
638 vcard_write_user(&CC->user, my_vcard);
639 vcard_free(my_vcard);
644 * Protocol command to fetch registration info for a user
646 void cmd_greg(char *argbuf)
648 struct ctdluser usbuf;
651 char who[USERNAME_SIZE];
655 extract_token(who, argbuf, 0, '|', sizeof who);
657 if (!(CC->logged_in)) {
658 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
662 if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
664 if ((CC->user.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
665 cprintf("%d Higher access required.\n",
666 ERROR + HIGHER_ACCESS_REQUIRED);
670 if (getuser(&usbuf, who) != 0) {
671 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, who);
675 v = vcard_get_user(&usbuf);
677 cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
678 cprintf("%ld\n", usbuf.usernum);
679 cprintf("%s\n", usbuf.password);
680 s = vcard_get_prop(v, "n", 0, 0, 0);
681 cprintf("%s\n", s ? s : " "); /* name */
683 s = vcard_get_prop(v, "adr", 0, 0, 0);
684 snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
686 extract_token(buf, adr, 2, ';', sizeof buf);
687 cprintf("%s\n", buf); /* street */
688 extract_token(buf, adr, 3, ';', sizeof buf);
689 cprintf("%s\n", buf); /* city */
690 extract_token(buf, adr, 4, ';', sizeof buf);
691 cprintf("%s\n", buf); /* state */
692 extract_token(buf, adr, 5, ';', sizeof buf);
693 cprintf("%s\n", buf); /* zip */
695 s = vcard_get_prop(v, "tel;home", 0, 0, 0);
696 if (s == NULL) s = vcard_get_prop(v, "tel", 1, 0, 0);
704 cprintf("%d\n", usbuf.axlevel);
706 s = vcard_get_prop(v, "email;internet", 0, 0, 0);
707 cprintf("%s\n", s ? s : " ");
708 s = vcard_get_prop(v, "adr", 0, 0, 0);
709 snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
711 extract_token(buf, adr, 6, ';', sizeof buf);
712 cprintf("%s\n", buf); /* country */
718 * When a user is being created, create his/her vCard.
720 void vcard_newuser(struct ctdluser *usbuf) {
726 char middlename[256];
727 char honorific_prefixes[256];
728 char honorific_suffixes[256];
733 /* Try to intelligently convert the screen name to a
734 * fully expanded vCard name based on the number of
737 safestrncpy(lastname, "", sizeof lastname);
738 safestrncpy(firstname, "", sizeof firstname);
739 safestrncpy(middlename, "", sizeof middlename);
740 safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
741 safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
743 safestrncpy(buf, usbuf->fullname, sizeof buf);
745 /* Honorific suffixes */
746 if (num_tokens(buf, ',') > 1) {
747 extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',',
748 sizeof honorific_suffixes);
749 remove_token(buf, (num_tokens(buf, ',') - 1), ',');
752 /* Find a last name */
753 extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof lastname);
754 remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
756 /* Find honorific prefixes */
757 if (num_tokens(buf, ' ') > 2) {
758 extract_token(honorific_prefixes, buf, 0, ' ', sizeof honorific_prefixes);
759 remove_token(buf, 0, ' ');
762 /* Find a middle name */
763 if (num_tokens(buf, ' ') > 1) {
764 extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof middlename);
765 remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
768 /* Anything left is probably the first name */
769 safestrncpy(firstname, buf, sizeof firstname);
772 /* Compose the structured name */
773 snprintf(vname, sizeof vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
774 honorific_prefixes, honorific_suffixes);
776 lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
778 /* Create and save the vCard */
780 if (v == NULL) return;
781 sprintf(buf, "%s@%s", usbuf->fullname, config.c_fqdn);
782 for (i=0; i<strlen(buf); ++i) {
783 if (buf[i] == ' ') buf[i] = '_';
785 vcard_add_prop(v, "fn", usbuf->fullname);
786 vcard_add_prop(v, "n", vname);
787 vcard_add_prop(v, "adr", "adr:;;_;_;_;00000;__");
788 vcard_add_prop(v, "email;internet", buf);
789 vcard_write_user(usbuf, v);
795 * When a user is being deleted, we have to remove his/her vCard.
796 * This is accomplished by issuing a message with 'CANCEL' in the S (special)
797 * field, and the same Exclusive ID as the existing card.
799 void vcard_purge(struct ctdluser *usbuf) {
800 struct CtdlMessage *msg;
803 msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
804 if (msg == NULL) return;
805 memset(msg, 0, sizeof(struct CtdlMessage));
807 msg->cm_magic = CTDLMESSAGE_MAGIC;
808 msg->cm_anon_type = MES_NORMAL;
809 msg->cm_format_type = 0;
810 msg->cm_fields['A'] = strdup(usbuf->fullname);
811 msg->cm_fields['O'] = strdup(ADDRESS_BOOK_ROOM);
812 msg->cm_fields['N'] = strdup(NODENAME);
813 msg->cm_fields['M'] = strdup("Purge this vCard\n");
815 snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
816 msg->cm_fields['A'], NODENAME);
817 msg->cm_fields['E'] = strdup(buf);
819 msg->cm_fields['S'] = strdup("CANCEL");
821 CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM);
822 CtdlFreeMessage(msg);
827 * Grab vCard directory stuff out of incoming network messages
829 int vcard_extract_from_network(struct CtdlMessage *msg, char *target_room) {
833 if (msg == NULL) return(0);
835 if (strcasecmp(target_room, ADDRESS_BOOK_ROOM)) {
839 if (msg->cm_format_type != 4) return(0);
841 ptr = msg->cm_fields['M'];
842 if (ptr == NULL) return(0);
843 while (ptr != NULL) {
845 linelen = strcspn(ptr, "\n");
846 if (linelen == 0) return(0); /* end of headers */
848 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
849 /* It's a vCard. Add it to the directory. */
850 vcard_extract_internet_addresses(msg,
851 CtdlDirectoryAddUser);
855 ptr = strchr((char *)ptr, '\n');
856 if (ptr != NULL) ++ptr;
865 * When a vCard is being removed from the Global Address Book room, remove it
866 * from the directory as well.
868 void vcard_delete_remove(char *room, long msgnum) {
869 struct CtdlMessage *msg;
873 if (msgnum <= 0L) return;
875 if (strcasecmp(room, ADDRESS_BOOK_ROOM)) {
879 msg = CtdlFetchMessage(msgnum, 1);
880 if (msg == NULL) return;
882 ptr = msg->cm_fields['M'];
883 if (ptr == NULL) goto EOH;
884 while (ptr != NULL) {
885 linelen = strcspn(ptr, "\n");
886 if (linelen == 0) goto EOH;
888 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
889 /* Bingo! A vCard is being deleted.
891 vcard_extract_internet_addresses(msg,
892 CtdlDirectoryDelUser);
894 ctdl_vcard_to_ldap(msg, V2L_DELETE);
897 ptr = strchr((char *)ptr, '\n');
898 if (ptr != NULL) ++ptr;
901 EOH: CtdlFreeMessage(msg);
909 void cmd_qdir(char *argbuf) {
910 char citadel_addr[256];
911 char internet_addr[256];
913 if (CtdlAccessCheck(ac_logged_in)) return;
915 extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr);
917 if (CtdlDirectoryLookup(citadel_addr, internet_addr, sizeof citadel_addr) != 0) {
918 cprintf("%d %s was not found.\n",
919 ERROR + NO_SUCH_USER, internet_addr);
923 cprintf("%d %s\n", CIT_OK, citadel_addr);
928 * We don't know if the Contacts room exists so we just create it at login
930 void vcard_create_room(void)
935 /* Create the calendar room if it doesn't already exist */
936 create_room(USERCONTACTSROOM, 4, "", 0, 1, 0, VIEW_ADDRESSBOOK);
938 /* Set expiration policy to manual; otherwise objects will be lost! */
939 if (lgetroom(&qr, USERCONTACTSROOM)) {
940 lprintf(CTDL_ERR, "Couldn't get the user CONTACTS room!\n");
943 qr.QRep.expire_mode = EXPIRE_MANUAL;
944 qr.QRdefaultview = VIEW_ADDRESSBOOK; /* 2 = address book view */
947 /* Set the view to a calendar view */
948 CtdlGetRelationship(&vbuf, &CC->user, &qr);
949 vbuf.v_view = 2; /* 2 = address book view */
950 CtdlSetRelationship(&vbuf, &CC->user, &qr);
959 * When a user logs in...
961 void vcard_session_login_hook(void) {
964 v = vcard_get_user(&CC->user);
965 vcard_populate_cs_inet_email(v);
974 char *serv_vcard_init(void)
978 CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
979 CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
980 CtdlRegisterMessageHook(vcard_upload_aftersave, EVT_AFTERSAVE);
981 CtdlRegisterDeleteHook(vcard_delete_remove);
982 CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
983 CtdlRegisterProtoHook(cmd_greg, "GREG", "Get registration info");
984 CtdlRegisterProtoHook(cmd_igab, "IGAB",
985 "Initialize Global Address Book");
986 CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
987 CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER);
988 CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
989 CtdlRegisterNetprocHook(vcard_extract_from_network);
991 /* Create the Global ADdress Book room if necessary */
992 create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);
994 /* Set expiration policy to manual; otherwise objects will be lost! */
995 if (!lgetroom(&qr, ADDRESS_BOOK_ROOM)) {
996 qr.QRep.expire_mode = EXPIRE_MANUAL;
997 qr.QRdefaultview = VIEW_ADDRESSBOOK; /* 2 = address book view */