* Silently refuse to add directory entries for Internet addresses already
[citadel.git] / citadel / serv_vcard.c
1 /*
2  * $Id$
3  * 
4  * A server-side module for Citadel which supports address book information
5  * using the standard vCard format.
6  * 
7  * Copyright (c) 1999-2002 / released under the GNU General Public License
8  */
9
10 /*
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.
14  */
15 #define ADDRESS_BOOK_ROOM       "Global Address Book"
16
17 /*
18  * Format of the "Extended 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).
22  */
23 #define VCARD_EXT_FORMAT        "Citadel vCard: personal card for %s at %s"
24
25
26 #include "sysdep.h"
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <fcntl.h>
31 #include <signal.h>
32 #include <pwd.h>
33 #include <errno.h>
34 #include <sys/types.h>
35
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
38 # include <time.h>
39 #else
40 # if HAVE_SYS_TIME_H
41 #  include <sys/time.h>
42 # else
43 #  include <time.h>
44 # endif
45 #endif
46
47 #include <sys/wait.h>
48 #include <string.h>
49 #include <limits.h>
50 #include "citadel.h"
51 #include "server.h"
52 #include "sysdep_decls.h"
53 #include "citserver.h"
54 #include "support.h"
55 #include "config.h"
56 #include "control.h"
57 #include "dynloader.h"
58 #include "room_ops.h"
59 #include "user_ops.h"
60 #include "policy.h"
61 #include "database.h"
62 #include "msgbase.h"
63 #include "internet_addressing.h"
64 #include "tools.h"
65 #include "vcard.h"
66
67 struct vcard_internal_info {
68         long msgnum;
69 };
70
71 /* Message number symbol used internally by these functions */
72 unsigned long SYM_VCARD;
73 #define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
74
75
76 /*
77  * Extract Internet e-mail addresses from a message containing a vCard, and
78  * perform a callback for any found.
79  */
80 void vcard_extract_internet_addresses(struct CtdlMessage *msg,
81                                 void (*callback)(char *, char *) ) {
82         struct vCard *v;
83         char *s;
84         char *addr;
85         char citadel_address[SIZ];
86         int instance = 0;
87         int found_something = 0;
88
89         if (msg->cm_fields['A'] == NULL) return;
90         if (msg->cm_fields['N'] == NULL) return;
91         sprintf(citadel_address, "%s @ %s",
92                 msg->cm_fields['A'], msg->cm_fields['N']);
93
94         v = vcard_load(msg->cm_fields['M']);
95         if (v == NULL) return;
96
97         /* Go through the vCard searching for *all* instances of
98          * the "email;internet" key
99          */
100         do {
101                 s = vcard_get_prop(v, "email;internet", 0, instance++);
102                 if (s != NULL) {
103                         addr = strdoop(s);
104                         striplt(addr);
105                         if (strlen(addr) > 0) {
106                                 if (callback != NULL) {
107                                         callback(addr, citadel_address);
108                                 }
109                         }
110                         phree(addr);
111                         found_something = 1;
112                 }
113                 else {
114                         found_something = 0;
115                 }
116         } while(found_something);
117
118         vcard_free(v);
119 }
120
121
122
123 /*
124  * Callback for vcard_add_to_directory()
125  * (Lotsa ugly nested callbacks.  Oh well.)
126  * This little shim function makes sure we're not 
127  */
128 void vcard_directory_add_user(char *internet_addr, char *citadel_addr) {
129         char buf[SIZ];
130
131         /* We have to validate that we're not stepping on someone else's
132          * email address ... but only if we're logged in.  Otherwise it's
133          * probably just the networker or something.
134          */
135         if (CC->logged_in) {
136                 lprintf(9, "Checking for <%s>...\n", internet_addr);
137                 if (CtdlDirectoryLookup(buf, internet_addr) == 0) {
138                         if (strcasecmp(buf, citadel_addr)) {
139                                 /* This address belongs to someone else.
140                                  * Bail out silently without saving.
141                                  */
142                                 lprintf(9, "DOOP!\n");
143                                 return;
144                         }
145                 }
146         }
147         lprintf(9, "ADDING!\n");
148         CtdlDirectoryAddUser(internet_addr, citadel_addr);
149 }
150
151
152 /*
153  * Back end function for cmd_igab()
154  */
155 void vcard_add_to_directory(long msgnum, void *data) {
156         struct CtdlMessage *msg;
157
158         msg = CtdlFetchMessage(msgnum);
159         if (msg != NULL) {
160                 vcard_extract_internet_addresses(msg, vcard_directory_add_user);
161         }
162
163         CtdlFreeMessage(msg);
164 }
165
166
167 /*
168  * Initialize Global Adress Book
169  */
170 void cmd_igab(char *argbuf) {
171         char hold_rm[ROOMNAMELEN];
172
173         if (CtdlAccessCheck(ac_aide)) return;
174
175         strcpy(hold_rm, CC->quickroom.QRname);  /* save current room */
176
177         if (getroom(&CC->quickroom, ADDRESS_BOOK_ROOM) != 0) {
178                 getroom(&CC->quickroom, hold_rm);
179                 cprintf("%d cannot get address book room\n", ERROR);
180                 return;
181         }
182
183         /* Empty the existing database first.
184          */
185         CtdlDirectoryInit();
186
187         /* We want the last (and probably only) vcard in this room */
188         CtdlForEachMessage(MSGS_ALL, 0, (-127), "text/x-vcard",
189                 NULL, vcard_add_to_directory, NULL);
190
191         getroom(&CC->quickroom, hold_rm);       /* return to saved room */
192         cprintf("%d Directory has been rebuilt.\n", OK);
193 }
194
195
196
197
198 /*
199  * See if there is a valid Internet address in a vCard to use for outbound
200  * Interet messages.  If there is, stick it in CC->cs_inet_email.
201  */
202 void vcard_populate_cs_inet_email(struct vCard *v) {
203         char *s, *addr;
204         int continue_searching = 1;
205         int instance = 0;
206
207         /* 
208          * Clear whatever was in there previously.
209          */
210         if (CC->cs_inet_email != NULL) {
211                 phree(CC->cs_inet_email);
212                 CC->cs_inet_email = NULL;
213         }
214
215         /* Go through the vCard searching for *all* instances of
216          * the "email;internet" key
217          */
218         do {
219                 s = vcard_get_prop(v, "email;internet", 0, instance++);
220                 if (s != NULL) {
221                         continue_searching = 1;
222                         addr = strdoop(s);
223                         striplt(addr);
224                         if (strlen(addr) > 0) {
225                                 if (IsDirectory(addr)) {
226                                         continue_searching = 0;
227                                         CC->cs_inet_email = strdoop(addr);
228                                 }
229                         }
230                         phree(addr);
231                 }
232                 else {
233                         continue_searching = 0;
234                 }
235         } while(continue_searching);
236 }
237
238
239
240 /*
241  * This handler detects whether the user is attempting to save a new
242  * vCard as part of his/her personal configuration, and handles the replace
243  * function accordingly (delete the user's existing vCard in the config room
244  * and in the global address book).
245  */
246 int vcard_upload_beforesave(struct CtdlMessage *msg) {
247         char *ptr;
248         int linelen;
249         char config_rm[ROOMNAMELEN];
250         char buf[SIZ];
251
252         if (!CC->logged_in) return(0);  /* Only do this if logged in. */
253
254         /* If this isn't the configuration room, or if this isn't a MIME
255          * message, don't bother.  (Check for NULL room first, otherwise
256          * some messages will cause it to crash!!)
257          */
258         if (msg->cm_fields['O'] == NULL) return(0);
259         if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
260         if (msg->cm_format_type != 4) return(0);
261
262         ptr = msg->cm_fields['M'];
263         if (ptr == NULL) return(0);
264         while (ptr != NULL) {
265         
266                 linelen = strcspn(ptr, "\n");
267                 if (linelen == 0) return(0);    /* end of headers */    
268                 
269                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
270                         /* Bingo!  The user is uploading a new vCard, so
271                          * delete the old one.
272                          */
273
274                         /* Delete the user's old vCard.  This would probably
275                          * get taken care of by the replication check, but we
276                          * want to make sure there is absolutely only one
277                          * vCard in the user's config room at all times.
278                          * 
279                          * FIXME ... this needs to be tweaked to allow an admin
280                          * to make changes to another user's vCard instead of
281                          * assuming that it's always the user saving his own.
282                          */
283                         MailboxName(config_rm, &CC->usersupp, USERCONFIGROOM);
284                         CtdlDeleteMessages(config_rm, 0L, "text/x-vcard");
285
286                         /* Set the Extended-ID to a standardized one so the
287                          * replication always works correctly
288                          */
289                         if (msg->cm_fields['E'] != NULL)
290                                 phree(msg->cm_fields['E']);
291
292                         sprintf(buf, VCARD_EXT_FORMAT,
293                                 msg->cm_fields['A'], NODENAME);
294                         msg->cm_fields['E'] = strdoop(buf);
295
296                         /* Now allow the save to complete. */
297                         return(0);
298                 }
299
300                 ptr = strchr((char *)ptr, '\n');
301                 if (ptr != NULL) ++ptr;
302         }
303
304         return(0);
305 }
306
307
308
309 /*
310  * This handler detects whether the user is attempting to save a new
311  * vCard as part of his/her personal configuration, and handles the replace
312  * function accordingly (copy the vCard from the config room to the global
313  * address book).
314  */
315 int vcard_upload_aftersave(struct CtdlMessage *msg) {
316         char *ptr;
317         int linelen;
318         long I;
319         struct vCard *v;
320
321         if (!CC->logged_in) return(0);  /* Only do this if logged in. */
322
323         /* If this isn't the configuration room, or if this isn't a MIME
324          * message, don't bother.
325          */
326         if (msg->cm_fields['O'] == NULL) return(0);
327         if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
328         if (msg->cm_format_type != 4) return(0);
329
330         ptr = msg->cm_fields['M'];
331         if (ptr == NULL) return(0);
332         while (ptr != NULL) {
333         
334                 linelen = strcspn(ptr, "\n");
335                 if (linelen == 0) return(0);    /* end of headers */    
336                 
337                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
338                         /* Bingo!  The user is uploading a new vCard, so
339                          * copy it to the Global Address Book room.
340                          */
341
342                         I = atol(msg->cm_fields['I']);
343                         if (I < 0L) return(0);
344
345                         /* Put it in the Global Address Book room... */
346                         CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I,
347                                 (SM_VERIFY_GOODNESS | SM_DO_REPL_CHECK) );
348
349                         /* ...and also in the directory database. */
350                         vcard_add_to_directory(I, NULL);
351
352                         /* Store our Internet return address in memory */
353                         v = vcard_load(msg->cm_fields['M']);
354                         vcard_populate_cs_inet_email(v);
355                         vcard_free(v);
356
357                         return(0);
358                 }
359
360                 ptr = strchr((char *)ptr, '\n');
361                 if (ptr != NULL) ++ptr;
362         }
363
364         return(0);
365 }
366
367
368
369 /*
370  * back end function used for callbacks
371  */
372 void vcard_gu_backend(long msgnum, void *userdata) {
373         VC->msgnum = msgnum;
374 }
375
376
377 /*
378  * If this user has a vcard on disk, read it into memory, otherwise allocate
379  * and return an empty vCard.
380  */
381 struct vCard *vcard_get_user(struct usersupp *u) {
382         char hold_rm[ROOMNAMELEN];
383         char config_rm[ROOMNAMELEN];
384         struct CtdlMessage *msg;
385         struct vCard *v;
386
387         strcpy(hold_rm, CC->quickroom.QRname);  /* save current room */
388         MailboxName(config_rm, u, USERCONFIGROOM);
389
390         if (getroom(&CC->quickroom, config_rm) != 0) {
391                 getroom(&CC->quickroom, hold_rm);
392                 return vcard_new();
393         }
394
395         /* We want the last (and probably only) vcard in this room */
396         VC->msgnum = (-1);
397         CtdlForEachMessage(MSGS_LAST, 1, (-127), "text/x-vcard",
398                 NULL, vcard_gu_backend, NULL);
399         getroom(&CC->quickroom, hold_rm);       /* return to saved room */
400
401         if (VC->msgnum < 0L) return vcard_new();
402
403         msg = CtdlFetchMessage(VC->msgnum);
404         if (msg == NULL) return vcard_new();
405
406         v = vcard_load(msg->cm_fields['M']);
407         CtdlFreeMessage(msg);
408         return v;
409 }
410
411
412 /*
413  * Store this user's vCard in the appropriate place
414  */
415 /*
416  * Write our config to disk
417  */
418 void vcard_write_user(struct usersupp *u, struct vCard *v) {
419         char temp[PATH_MAX];
420         FILE *fp;
421         char *ser;
422
423         strcpy(temp, tmpnam(NULL));
424         ser = vcard_serialize(v);
425
426         fp = fopen(temp, "w");
427         if (fp == NULL) return;
428         if (ser == NULL) {
429                 fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
430         } else {
431                 fwrite(ser, strlen(ser), 1, fp);
432                 phree(ser);
433         }
434         fclose(fp);
435
436         /* This handy API function does all the work for us.
437          * NOTE: normally we would want to set that last argument to 1, to
438          * force the system to delete the user's old vCard.  But it doesn't
439          * have to, because the vcard_upload_beforesave() hook above
440          * is going to notice what we're trying to do, and delete the old vCard.
441          */
442         CtdlWriteObject(USERCONFIGROOM, /* which room */
443                         "text/x-vcard", /* MIME type */
444                         temp,           /* temp file */
445                         u,              /* which user */
446                         0,              /* not binary */
447                         0,              /* don't delete others of this type */
448                         0);             /* no flags */
449
450         unlink(temp);
451 }
452
453
454
455 /*
456  * Old style "enter registration info" command.  This function simply honors
457  * the REGI protocol command, translates the entered parameters into a vCard,
458  * and enters the vCard into the user's configuration.
459  */
460 void cmd_regi(char *argbuf) {
461         int a,b,c;
462         char buf[SIZ];
463         struct vCard *my_vcard;
464
465         char tmpaddr[SIZ];
466         char tmpcity[SIZ];
467         char tmpstate[SIZ];
468         char tmpzip[SIZ];
469         char tmpaddress[SIZ];
470         char tmpcountry[SIZ];
471
472         if (!(CC->logged_in)) {
473                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
474                 return;
475         }
476
477         my_vcard = vcard_get_user(&CC->usersupp);
478         strcpy(tmpaddr, "");
479         strcpy(tmpcity, "");
480         strcpy(tmpstate, "");
481         strcpy(tmpzip, "");
482         strcpy(tmpcountry, "USA");
483
484         cprintf("%d Send registration...\n", SEND_LISTING);
485         a=0;
486         while (client_gets(buf), strcmp(buf,"000")) {
487                 if (a==0) vcard_set_prop(my_vcard, "n", buf, 0);
488                 if (a==1) strcpy(tmpaddr, buf);
489                 if (a==2) strcpy(tmpcity, buf);
490                 if (a==3) strcpy(tmpstate, buf);
491                 if (a==4) {
492                         for (c=0; c<strlen(buf); ++c) {
493                                 if ((buf[c]>='0') && (buf[c]<='9')) {
494                                         b = strlen(tmpzip);
495                                         tmpzip[b] = buf[c];
496                                         tmpzip[b+1] = 0;
497                                 }
498                         }
499                 }
500                 if (a==5) vcard_set_prop(my_vcard, "tel;home", buf, 0);
501                 if (a==6) vcard_set_prop(my_vcard, "email;internet", buf, 0);
502                 if (a==7) strcpy(tmpcountry, buf);
503                 ++a;
504         }
505
506         sprintf(tmpaddress, ";;%s;%s;%s;%s;%s",
507                 tmpaddr, tmpcity, tmpstate, tmpzip, tmpcountry);
508         vcard_set_prop(my_vcard, "adr", tmpaddress, 0);
509         vcard_write_user(&CC->usersupp, my_vcard);
510         vcard_free(my_vcard);
511
512         lgetuser(&CC->usersupp, CC->curr_user);
513         CC->usersupp.flags=(CC->usersupp.flags|US_REGIS|US_NEEDVALID);
514         lputuser(&CC->usersupp);
515
516         /* set global flag calling for validation */
517         begin_critical_section(S_CONTROL);
518         get_control();
519         CitControl.MMflags = CitControl.MMflags | MM_VALID ;
520         put_control();
521         end_critical_section(S_CONTROL);
522 }
523
524
525
526 /*
527  * Protocol command to fetch registration info for a user
528  */
529 void cmd_greg(char *argbuf)
530 {
531         struct usersupp usbuf;
532         struct vCard *v;
533         char *s;
534         char who[SIZ];
535         char adr[SIZ];
536         char buf[SIZ];
537
538         extract(who, argbuf, 0);
539
540         if (!(CC->logged_in)) {
541                 cprintf("%d Not logged in.\n", ERROR+NOT_LOGGED_IN);
542                 return;
543         }
544
545         if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
546
547         if ((CC->usersupp.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
548                 cprintf("%d Higher access required.\n",
549                         ERROR+HIGHER_ACCESS_REQUIRED);
550                 return;
551         }
552
553         if (getuser(&usbuf, who) != 0) {
554                 cprintf("%d '%s' not found.\n", ERROR+NO_SUCH_USER, who);
555                 return;
556         }
557
558         v = vcard_get_user(&usbuf);
559
560         cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
561         cprintf("%ld\n", usbuf.usernum);
562         cprintf("%s\n", usbuf.password);
563         s = vcard_get_prop(v, "n", 0, 0);
564         cprintf("%s\n", s ? s : " ");   /* name */
565
566         s = vcard_get_prop(v, "adr", 0, 0);
567         sprintf(adr, "%s", s ? s : " ");/* address... */
568
569         extract_token(buf, adr, 2, ';');
570         cprintf("%s\n", buf);                           /* street */
571         extract_token(buf, adr, 3, ';');
572         cprintf("%s\n", buf);                           /* city */
573         extract_token(buf, adr, 4, ';');
574         cprintf("%s\n", buf);                           /* state */
575         extract_token(buf, adr, 5, ';');
576         cprintf("%s\n", buf);                           /* zip */
577
578         s = vcard_get_prop(v, "tel;home", 0, 0);
579         if (s == NULL) s = vcard_get_prop(v, "tel", 1, 0);
580         if (s != NULL) {
581                 cprintf("%s\n", s);
582         }
583         else {
584                 cprintf(" \n");
585         }
586
587         cprintf("%d\n", usbuf.axlevel);
588
589         s = vcard_get_prop(v, "email;internet", 0, 0);
590         cprintf("%s\n", s ? s : " ");
591         s = vcard_get_prop(v, "adr", 0, 0);
592         sprintf(adr, "%s", s ? s : " ");/* address... */
593
594         extract_token(buf, adr, 6, ';');
595         cprintf("%s\n", buf);                           /* country */
596         cprintf("000\n");
597 }
598
599
600 /*
601  * When a user is being deleted, we have to remove his/her vCard.
602  * This is accomplished by issuing a message with 'CANCEL' in the S (special)
603  * field, and the same Extended ID as the existing card.
604  */
605 void vcard_purge(char *username, long usernum) {
606         struct CtdlMessage *msg;
607         char buf[SIZ];
608
609         msg = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
610         if (msg == NULL) return;
611         memset(msg, 0, sizeof(struct CtdlMessage));
612
613         msg->cm_magic = CTDLMESSAGE_MAGIC;
614         msg->cm_anon_type = MES_NORMAL;
615         msg->cm_format_type = 0;
616         msg->cm_fields['A'] = strdoop(username);
617         msg->cm_fields['O'] = strdoop(ADDRESS_BOOK_ROOM);
618         msg->cm_fields['N'] = strdoop(NODENAME);
619         msg->cm_fields['M'] = strdoop("Purge this vCard\n");
620
621         sprintf(buf, VCARD_EXT_FORMAT, msg->cm_fields['A'], NODENAME);
622         msg->cm_fields['E'] = strdoop(buf);
623
624         msg->cm_fields['S'] = strdoop("CANCEL");
625
626         CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM);
627         CtdlFreeMessage(msg);
628 }
629
630
631 /*
632  * Grab vCard directory stuff out of incoming network messages
633  */
634 int vcard_extract_from_network(struct CtdlMessage *msg, char *target_room) {
635         char *ptr;
636         int linelen;
637
638         if (msg == NULL) return(0);
639
640         if (strcasecmp(target_room, ADDRESS_BOOK_ROOM)) {
641                 return(0);
642         }
643
644         if (msg->cm_format_type != 4) return(0);
645
646         ptr = msg->cm_fields['M'];
647         if (ptr == NULL) return(0);
648         while (ptr != NULL) {
649         
650                 linelen = strcspn(ptr, "\n");
651                 if (linelen == 0) return(0);    /* end of headers */    
652                 
653                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
654                          /* It's a vCard.  Add it to the directory. */
655                         vcard_extract_internet_addresses(msg,
656                                                         CtdlDirectoryAddUser);
657                         return(0);
658                 }
659
660                 ptr = strchr((char *)ptr, '\n');
661                 if (ptr != NULL) ++ptr;
662         }
663
664         return(0);
665 }
666
667
668
669 /* 
670  * When a vCard is being removed from the Global Address Book room, remove it
671  * from the directory as well.
672  */
673 void vcard_delete_remove(char *room, long msgnum) {
674         struct CtdlMessage *msg;
675
676         if (msgnum <= 0L) return;
677
678         if (strcasecmp(room, ADDRESS_BOOK_ROOM)) {
679                 return;
680         }
681
682         msg = CtdlFetchMessage(msgnum);
683         if (msg != NULL) {
684                 vcard_extract_internet_addresses(msg, CtdlDirectoryDelUser);
685         }
686
687         CtdlFreeMessage(msg);
688 }
689
690
691 /*
692  * Query Directory
693  */
694 void cmd_qdir(char *argbuf) {
695         char citadel_addr[SIZ];
696         char internet_addr[SIZ];
697
698         if (CtdlAccessCheck(ac_logged_in)) return;
699
700         extract(internet_addr, argbuf, 0);
701
702         if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
703                 cprintf("%d %s was not found.\n",
704                         ERROR+NO_SUCH_USER, internet_addr);
705                 return;
706         }
707
708         cprintf("%d %s\n", OK, citadel_addr);
709 }
710
711
712
713
714 /*
715  * Session startup, allocate some per-session data
716  */
717 void vcard_session_startup_hook(void) {
718         CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
719 }
720
721
722 /*
723  * When a user logs in...
724  */
725 void vcard_session_login_hook(void) {
726         struct vCard *v;
727
728         v = vcard_get_user(&CC->usersupp);
729         vcard_populate_cs_inet_email(v);
730
731         vcard_free(v);
732 }
733
734
735 /*
736  * When a user logs out...
737  */
738 void vcard_session_logout_hook(void) {
739         if (CC->cs_inet_email != NULL) {
740                 phree(CC->cs_inet_email);
741                 CC->cs_inet_email = NULL;
742         }
743 }
744
745
746 char *Dynamic_Module_Init(void)
747 {
748         SYM_VCARD = CtdlGetDynamicSymbol();
749         CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
750         CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
751         CtdlRegisterSessionHook(vcard_session_logout_hook, EVT_LOGOUT);
752         CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
753         CtdlRegisterMessageHook(vcard_upload_aftersave, EVT_AFTERSAVE);
754         CtdlRegisterDeleteHook(vcard_delete_remove);
755         CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
756         CtdlRegisterProtoHook(cmd_greg, "GREG", "Get registration info");
757         CtdlRegisterProtoHook(cmd_igab, "IGAB",
758                                         "Initialize Global Address Book");
759         CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
760         CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
761         CtdlRegisterNetprocHook(vcard_extract_from_network);
762         create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1);
763         return "$Id$";
764 }