* First cut at static-linking the citserver. Ripped out libtool and
[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         snprintf(citadel_address, sizeof 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++, 0);
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, "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", CIT_OK);
193 }
194
195
196
197
198 /*
199  * See if there is a valid Internet address in a vCard to use for outbound
200  * Internet 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         /* Go through the vCard searching for *all* instances of
208          * the "email;internet" key
209          */
210         do {
211                 s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
212                 if (s != NULL) {
213                         continue_searching = 1;
214                         addr = strdoop(s);
215                         striplt(addr);
216                         if (strlen(addr) > 0) {
217                                 if (IsDirectory(addr)) {
218                                         continue_searching = 0;
219                                         safestrncpy(CC->cs_inet_email,
220                                                 addr,
221                                                 sizeof(CC->cs_inet_email)
222                                         );
223                                 }
224                         }
225                         phree(addr);
226                 }
227                 else {
228                         continue_searching = 0;
229                 }
230         } while(continue_searching);
231 }
232
233
234
235 /*
236  * This handler detects whether the user is attempting to save a new
237  * vCard as part of his/her personal configuration, and handles the replace
238  * function accordingly (delete the user's existing vCard in the config room
239  * and in the global address book).
240  */
241 int vcard_upload_beforesave(struct CtdlMessage *msg) {
242         char *ptr;
243         int linelen;
244         char buf[SIZ];
245         struct usersupp usbuf;
246         long what_user;
247
248         if (!CC->logged_in) return(0);  /* Only do this if logged in. */
249
250         /* If this isn't a "My Citadel Config" room, don't bother. */
251         if ( (CC->quickroom.QRflags && QR_MAILBOX)
252            && (!strcasecmp(&CC->quickroom.QRname[11], USERCONFIGROOM)) ) {
253                 /* Yes, we want to do this */
254         }
255         else {
256                 return(0);
257         }
258
259         /* If this isn't a MIME message, don't bother. */
260         if (msg->cm_format_type != 4) return(0);
261
262         /* Ok, if we got this far, look into the situation further... */
263
264         ptr = msg->cm_fields['M'];
265         if (ptr == NULL) return(0);
266         while (ptr != NULL) {
267         
268                 linelen = strcspn(ptr, "\n");
269                 if (linelen == 0) return(0);    /* end of headers */    
270                 
271                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
272                         /* Bingo!  The user is uploading a new vCard, so
273                          * delete the old one.  First, figure out which user
274                          * is being re-registered...
275                          */
276                         what_user = atol(CC->quickroom.QRname);
277
278                         if (what_user == CC->usersupp.usernum) {
279                                 /* It's the logged in user.  That was easy. */
280                                 memcpy(&usbuf, &CC->usersupp,
281                                         sizeof(struct usersupp) );
282                         }
283                         
284                         else if (getuserbynumber(&usbuf, what_user) == 0) {
285                                 /* We fetched a valid user record */
286                         }
287                 
288                         else {
289                                 /* No user with that number! */
290                                 return(0);
291                         }
292
293                         /* Delete the user's old vCard.  This would probably
294                          * get taken care of by the replication check, but we
295                          * want to make sure there is absolutely only one
296                          * vCard in the user's config room at all times.
297                          */
298                         CtdlDeleteMessages(CC->quickroom.QRname,
299                                         0L, "text/x-vcard");
300
301                         /* Set the Extended-ID to a standardized one so the
302                          * replication always works correctly
303                          */
304                         if (msg->cm_fields['E'] != NULL)
305                                 phree(msg->cm_fields['E']);
306
307                         if (msg->cm_fields['A'] != NULL)
308                                 phree(msg->cm_fields['A']);
309
310                         msg->cm_fields['A'] = strdoop(usbuf.fullname);
311
312                         snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
313                                 msg->cm_fields['A'], NODENAME);
314                         msg->cm_fields['E'] = strdoop(buf);
315
316                         /* Now allow the save to complete. */
317                         return(0);
318                 }
319
320                 ptr = strchr((char *)ptr, '\n');
321                 if (ptr != NULL) ++ptr;
322         }
323
324         return(0);
325 }
326
327
328
329 /*
330  * This handler detects whether the user is attempting to save a new
331  * vCard as part of his/her personal configuration, and handles the replace
332  * function accordingly (copy the vCard from the config room to the global
333  * address book).
334  */
335 int vcard_upload_aftersave(struct CtdlMessage *msg) {
336         char *ptr;
337         int linelen;
338         long I;
339         struct vCard *v;
340
341         if (!CC->logged_in) return(0);  /* Only do this if logged in. */
342
343         /* If this isn't the configuration room, or if this isn't a MIME
344          * message, don't bother.
345          */
346         if (msg->cm_fields['O'] == NULL) return(0);
347         if (strcasecmp(msg->cm_fields['O'], USERCONFIGROOM)) return(0);
348         if (msg->cm_format_type != 4) return(0);
349
350         ptr = msg->cm_fields['M'];
351         if (ptr == NULL) return(0);
352         while (ptr != NULL) {
353         
354                 linelen = strcspn(ptr, "\n");
355                 if (linelen == 0) return(0);    /* end of headers */    
356                 
357                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
358                         /* Bingo!  The user is uploading a new vCard, so
359                          * copy it to the Global Address Book room.
360                          */
361
362                         I = atol(msg->cm_fields['I']);
363                         if (I < 0L) return(0);
364
365                         /* Put it in the Global Address Book room... */
366                         CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I,
367                                 (SM_VERIFY_GOODNESS | SM_DO_REPL_CHECK) );
368
369                         /* ...and also in the directory database. */
370                         vcard_add_to_directory(I, NULL);
371
372                         /* Store our Internet return address in memory */
373                         v = vcard_load(msg->cm_fields['M']);
374                         vcard_populate_cs_inet_email(v);
375                         vcard_free(v);
376
377                         return(0);
378                 }
379
380                 ptr = strchr((char *)ptr, '\n');
381                 if (ptr != NULL) ++ptr;
382         }
383
384         return(0);
385 }
386
387
388
389 /*
390  * back end function used for callbacks
391  */
392 void vcard_gu_backend(long msgnum, void *userdata) {
393         VC->msgnum = msgnum;
394 }
395
396
397 /*
398  * If this user has a vcard on disk, read it into memory, otherwise allocate
399  * and return an empty vCard.
400  */
401 struct vCard *vcard_get_user(struct usersupp *u) {
402         char hold_rm[ROOMNAMELEN];
403         char config_rm[ROOMNAMELEN];
404         struct CtdlMessage *msg;
405         struct vCard *v;
406
407         strcpy(hold_rm, CC->quickroom.QRname);  /* save current room */
408         MailboxName(config_rm, sizeof config_rm, u, USERCONFIGROOM);
409
410         if (getroom(&CC->quickroom, config_rm) != 0) {
411                 getroom(&CC->quickroom, hold_rm);
412                 return vcard_new();
413         }
414
415         /* We want the last (and probably only) vcard in this room */
416         VC->msgnum = (-1);
417         CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard",
418                 NULL, vcard_gu_backend, NULL);
419         getroom(&CC->quickroom, hold_rm);       /* return to saved room */
420
421         if (VC->msgnum < 0L) return vcard_new();
422
423         msg = CtdlFetchMessage(VC->msgnum);
424         if (msg == NULL) return vcard_new();
425
426         v = vcard_load(msg->cm_fields['M']);
427         CtdlFreeMessage(msg);
428         return v;
429 }
430
431
432 /*
433  * Store this user's vCard in the appropriate place
434  */
435 /*
436  * Write our config to disk
437  */
438 void vcard_write_user(struct usersupp *u, struct vCard *v) {
439         char temp[PATH_MAX];
440         FILE *fp;
441         char *ser;
442
443         strcpy(temp, tmpnam(NULL));
444         ser = vcard_serialize(v);
445
446         fp = fopen(temp, "w");
447         if (fp == NULL) return;
448         if (ser == NULL) {
449                 fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
450         } else {
451                 fwrite(ser, strlen(ser), 1, fp);
452                 phree(ser);
453         }
454         fclose(fp);
455
456         /* This handy API function does all the work for us.
457          * NOTE: normally we would want to set that last argument to 1, to
458          * force the system to delete the user's old vCard.  But it doesn't
459          * have to, because the vcard_upload_beforesave() hook above
460          * is going to notice what we're trying to do, and delete the old vCard.
461          */
462         CtdlWriteObject(USERCONFIGROOM, /* which room */
463                         "text/x-vcard", /* MIME type */
464                         temp,           /* temp file */
465                         u,              /* which user */
466                         0,              /* not binary */
467                         0,              /* don't delete others of this type */
468                         0);             /* no flags */
469
470         unlink(temp);
471 }
472
473
474
475 /*
476  * Old style "enter registration info" command.  This function simply honors
477  * the REGI protocol command, translates the entered parameters into a vCard,
478  * and enters the vCard into the user's configuration.
479  */
480 void cmd_regi(char *argbuf) {
481         int a,b,c;
482         char buf[SIZ];
483         struct vCard *my_vcard;
484
485         char tmpaddr[SIZ];
486         char tmpcity[SIZ];
487         char tmpstate[SIZ];
488         char tmpzip[SIZ];
489         char tmpaddress[SIZ];
490         char tmpcountry[SIZ];
491
492         if (!(CC->logged_in)) {
493                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
494                 return;
495         }
496
497         my_vcard = vcard_get_user(&CC->usersupp);
498         strcpy(tmpaddr, "");
499         strcpy(tmpcity, "");
500         strcpy(tmpstate, "");
501         strcpy(tmpzip, "");
502         strcpy(tmpcountry, "USA");
503
504         cprintf("%d Send registration...\n", SEND_LISTING);
505         a=0;
506         while (client_gets(buf), strcmp(buf,"000")) {
507                 if (a==0) vcard_set_prop(my_vcard, "n", buf, 0);
508                 if (a==1) strcpy(tmpaddr, buf);
509                 if (a==2) strcpy(tmpcity, buf);
510                 if (a==3) strcpy(tmpstate, buf);
511                 if (a==4) {
512                         for (c=0; c<strlen(buf); ++c) {
513                                 if ((buf[c]>='0') && (buf[c]<='9')) {
514                                         b = strlen(tmpzip);
515                                         tmpzip[b] = buf[c];
516                                         tmpzip[b+1] = 0;
517                                 }
518                         }
519                 }
520                 if (a==5) vcard_set_prop(my_vcard, "tel;home", buf, 0);
521                 if (a==6) vcard_set_prop(my_vcard, "email;internet", buf, 0);
522                 if (a==7) strcpy(tmpcountry, buf);
523                 ++a;
524         }
525
526         snprintf(tmpaddress, sizeof tmpaddress, ";;%s;%s;%s;%s;%s",
527                 tmpaddr, tmpcity, tmpstate, tmpzip, tmpcountry);
528         vcard_set_prop(my_vcard, "adr", tmpaddress, 0);
529         vcard_write_user(&CC->usersupp, my_vcard);
530         vcard_free(my_vcard);
531
532         lgetuser(&CC->usersupp, CC->curr_user);
533         CC->usersupp.flags=(CC->usersupp.flags|US_REGIS|US_NEEDVALID);
534         lputuser(&CC->usersupp);
535
536         /* set global flag calling for validation */
537         begin_critical_section(S_CONTROL);
538         get_control();
539         CitControl.MMflags = CitControl.MMflags | MM_VALID ;
540         put_control();
541         end_critical_section(S_CONTROL);
542 }
543
544
545
546 /*
547  * Protocol command to fetch registration info for a user
548  */
549 void cmd_greg(char *argbuf)
550 {
551         struct usersupp usbuf;
552         struct vCard *v;
553         char *s;
554         char who[SIZ];
555         char adr[SIZ];
556         char buf[SIZ];
557
558         extract(who, argbuf, 0);
559
560         if (!(CC->logged_in)) {
561                 cprintf("%d Not logged in.\n", ERROR+NOT_LOGGED_IN);
562                 return;
563         }
564
565         if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
566
567         if ((CC->usersupp.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
568                 cprintf("%d Higher access required.\n",
569                         ERROR+HIGHER_ACCESS_REQUIRED);
570                 return;
571         }
572
573         if (getuser(&usbuf, who) != 0) {
574                 cprintf("%d '%s' not found.\n", ERROR+NO_SUCH_USER, who);
575                 return;
576         }
577
578         v = vcard_get_user(&usbuf);
579
580         cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
581         cprintf("%ld\n", usbuf.usernum);
582         cprintf("%s\n", usbuf.password);
583         s = vcard_get_prop(v, "n", 0, 0, 0);
584         cprintf("%s\n", s ? s : " ");   /* name */
585
586         s = vcard_get_prop(v, "adr", 0, 0, 0);
587         snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
588
589         extract_token(buf, adr, 2, ';');
590         cprintf("%s\n", buf);                           /* street */
591         extract_token(buf, adr, 3, ';');
592         cprintf("%s\n", buf);                           /* city */
593         extract_token(buf, adr, 4, ';');
594         cprintf("%s\n", buf);                           /* state */
595         extract_token(buf, adr, 5, ';');
596         cprintf("%s\n", buf);                           /* zip */
597
598         s = vcard_get_prop(v, "tel;home", 0, 0, 0);
599         if (s == NULL) s = vcard_get_prop(v, "tel", 1, 0, 0);
600         if (s != NULL) {
601                 cprintf("%s\n", s);
602         }
603         else {
604                 cprintf(" \n");
605         }
606
607         cprintf("%d\n", usbuf.axlevel);
608
609         s = vcard_get_prop(v, "email;internet", 0, 0, 0);
610         cprintf("%s\n", s ? s : " ");
611         s = vcard_get_prop(v, "adr", 0, 0, 0);
612         snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
613
614         extract_token(buf, adr, 6, ';');
615         cprintf("%s\n", buf);                           /* country */
616         cprintf("000\n");
617 }
618
619
620 /*
621  * When a user is being deleted, we have to remove his/her vCard.
622  * This is accomplished by issuing a message with 'CANCEL' in the S (special)
623  * field, and the same Extended ID as the existing card.
624  */
625 void vcard_purge(char *username, long usernum) {
626         struct CtdlMessage *msg;
627         char buf[SIZ];
628
629         msg = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
630         if (msg == NULL) return;
631         memset(msg, 0, sizeof(struct CtdlMessage));
632
633         msg->cm_magic = CTDLMESSAGE_MAGIC;
634         msg->cm_anon_type = MES_NORMAL;
635         msg->cm_format_type = 0;
636         msg->cm_fields['A'] = strdoop(username);
637         msg->cm_fields['O'] = strdoop(ADDRESS_BOOK_ROOM);
638         msg->cm_fields['N'] = strdoop(NODENAME);
639         msg->cm_fields['M'] = strdoop("Purge this vCard\n");
640
641         snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
642                         msg->cm_fields['A'], NODENAME);
643         msg->cm_fields['E'] = strdoop(buf);
644
645         msg->cm_fields['S'] = strdoop("CANCEL");
646
647         CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM);
648         CtdlFreeMessage(msg);
649 }
650
651
652 /*
653  * Grab vCard directory stuff out of incoming network messages
654  */
655 int vcard_extract_from_network(struct CtdlMessage *msg, char *target_room) {
656         char *ptr;
657         int linelen;
658
659         if (msg == NULL) return(0);
660
661         if (strcasecmp(target_room, ADDRESS_BOOK_ROOM)) {
662                 return(0);
663         }
664
665         if (msg->cm_format_type != 4) return(0);
666
667         ptr = msg->cm_fields['M'];
668         if (ptr == NULL) return(0);
669         while (ptr != NULL) {
670         
671                 linelen = strcspn(ptr, "\n");
672                 if (linelen == 0) return(0);    /* end of headers */    
673                 
674                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
675                          /* It's a vCard.  Add it to the directory. */
676                         vcard_extract_internet_addresses(msg,
677                                                         CtdlDirectoryAddUser);
678                         return(0);
679                 }
680
681                 ptr = strchr((char *)ptr, '\n');
682                 if (ptr != NULL) ++ptr;
683         }
684
685         return(0);
686 }
687
688
689
690 /* 
691  * When a vCard is being removed from the Global Address Book room, remove it
692  * from the directory as well.
693  */
694 void vcard_delete_remove(char *room, long msgnum) {
695         struct CtdlMessage *msg;
696         char *ptr;
697         int linelen;
698
699         if (msgnum <= 0L) return;
700
701         if (strcasecmp(room, ADDRESS_BOOK_ROOM)) {
702                 return;
703         }
704
705         msg = CtdlFetchMessage(msgnum);
706         if (msg == NULL) return;
707
708         ptr = msg->cm_fields['M'];
709         if (ptr == NULL) goto EOH;
710         while (ptr != NULL) {
711                 linelen = strcspn(ptr, "\n");
712                 if (linelen == 0) goto EOH;
713                 
714                 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
715                         /* Bingo!  A vCard is being deleted.
716                         */
717                         vcard_extract_internet_addresses(msg,
718                                                         CtdlDirectoryDelUser);
719                 }
720                 ptr = strchr((char *)ptr, '\n');
721                 if (ptr != NULL) ++ptr;
722         }
723
724 EOH:    CtdlFreeMessage(msg);
725 }
726
727
728
729 /*
730  * Query Directory
731  */
732 void cmd_qdir(char *argbuf) {
733         char citadel_addr[SIZ];
734         char internet_addr[SIZ];
735
736         if (CtdlAccessCheck(ac_logged_in)) return;
737
738         extract(internet_addr, argbuf, 0);
739
740         if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
741                 cprintf("%d %s was not found.\n",
742                         ERROR+NO_SUCH_USER, internet_addr);
743                 return;
744         }
745
746         cprintf("%d %s\n", CIT_OK, citadel_addr);
747 }
748
749
750
751
752 /*
753  * Session startup, allocate some per-session data
754  */
755 void vcard_session_startup_hook(void) {
756         CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
757 }
758
759
760 /*
761  * When a user logs in...
762  */
763 void vcard_session_login_hook(void) {
764         struct vCard *v;
765
766         v = vcard_get_user(&CC->usersupp);
767         vcard_populate_cs_inet_email(v);
768
769         vcard_free(v);
770 }
771
772
773
774 char *serv_vcard_init(void)
775 {
776         SYM_VCARD = CtdlGetDynamicSymbol();
777         CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
778         CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
779         CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
780         CtdlRegisterMessageHook(vcard_upload_aftersave, EVT_AFTERSAVE);
781         CtdlRegisterDeleteHook(vcard_delete_remove);
782         CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
783         CtdlRegisterProtoHook(cmd_greg, "GREG", "Get registration info");
784         CtdlRegisterProtoHook(cmd_igab, "IGAB",
785                                         "Initialize Global Address Book");
786         CtdlRegisterProtoHook(cmd_qdir, "QDIR", "Query Directory");
787         CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
788         CtdlRegisterNetprocHook(vcard_extract_from_network);
789         create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0);
790         return "$Id$";
791 }