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