10 #include <sys/types.h>
22 #include "sysdep_decls.h"
23 #include "citserver.h"
27 #include "dynloader.h"
36 struct vcard_internal_info {
40 /* Message number symbol used internally by these functions */
41 unsigned long SYM_VCARD;
42 #define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
46 * This handler detects whether the user is attempting to save a new
47 * vCard as part of his/her personal configuration, and handles the replace
48 * function accordingly.
50 int vcard_personal_upload(struct CtdlMessage *msg) {
54 /* If this isn't the configuration room, or if this isn't a MIME
55 * message, don't bother.
57 if (strcasecmp(msg->cm_fields['O'], CONFIGROOM)) return(0);
58 if (msg->cm_format_type != 4) return(0);
60 ptr = msg->cm_fields['M'];
63 linelen = strcspn(ptr, "\n");
64 if (linelen == 0) return(0); /* end of headers */
66 if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
67 /* Bingo! The user is uploading a new vCard, so
70 CtdlDeleteMessages(msg->cm_fields['O'],
75 ptr = strchr((char *)ptr, '\n');
76 if (ptr != NULL) ++ptr;
85 * back end function used by vcard_get_user()
87 void vcard_gm_backend(long msgnum) {
93 * If this user has a vcard on disk, read it into memory, otherwise allocate
94 * and return an empty vCard.
96 struct vCard *vcard_get_user(struct usersupp *u) {
97 char hold_rm[ROOMNAMELEN];
98 char config_rm[ROOMNAMELEN];
99 struct CtdlMessage *msg;
102 strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
103 MailboxName(config_rm, u, CONFIGROOM);
105 if (getroom(&CC->quickroom, config_rm) != 0) {
106 getroom(&CC->quickroom, hold_rm);
110 /* We want the last (and probably only) vcard in this room */
112 CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard", vcard_gm_backend);
113 getroom(&CC->quickroom, hold_rm); /* return to saved room */
115 if (VC->msgnum < 0L) return vcard_new();
117 msg = CtdlFetchMessage(VC->msgnum);
118 if (msg == NULL) return vcard_new();
120 v = vcard_load(msg->cm_fields['M']);
121 CtdlFreeMessage(msg);
127 * Store this user's vCard in the appropriate place
130 * Write our config to disk
132 void vcard_write_user(struct usersupp *u, struct vCard *v) {
137 strcpy(temp, tmpnam(NULL));
138 ser = vcard_serialize(v);
140 fp = fopen(temp, "w");
141 if (fp == NULL) return;
142 fprintf(fp, "Content-type: text/x-vcard\r\n\r\n");
144 fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
146 fwrite(ser, strlen(ser), 1, fp);
151 /* This handy API function does all the work for us */
152 CtdlWriteObject(CONFIGROOM, "text/x-vcard", temp, u, 0, 1);
160 * old style "enter registration info" command
162 void cmd_regi(char *argbuf) {
165 struct vCard *my_vcard;
172 char tmpaddress[512];
174 if (!(CC->logged_in)) {
175 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
179 my_vcard = vcard_get_user(&CC->usersupp);
182 strcpy(tmpstate, "");
185 cprintf("%d Send registration...\n", SEND_LISTING);
187 while (client_gets(buf), strcmp(buf,"000")) {
188 if (a==0) vcard_set_prop(my_vcard, "n", buf);
189 if (a==1) strcpy(tmpaddr,buf);
190 if (a==2) strcpy(tmpcity,buf);
191 if (a==3) strcpy(tmpstate,buf);
193 for (c=0; c<strlen(buf); ++c) {
194 if ((buf[c]>='0')&&(buf[c]<='9')) {
202 strcpy(tmpphone, "");
203 for (c=0; c<strlen(buf); ++c) {
204 if ((buf[c]>='0')&&(buf[c]<='9')) {
210 vcard_set_prop(my_vcard, "tel;home", tmpphone);
212 if (a==6) vcard_set_prop(my_vcard, "email;internet", buf);
215 sprintf(tmpaddress, ";;%s;%s;%s;%s;USA",
216 tmpaddr, tmpcity, tmpstate, tmpzip);
217 vcard_set_prop(my_vcard, "adr", tmpaddress);
218 vcard_write_user(&CC->usersupp, my_vcard);
219 vcard_free(my_vcard);
221 lgetuser(&CC->usersupp, CC->curr_user);
222 CC->usersupp.flags=(CC->usersupp.flags|US_REGIS|US_NEEDVALID);
223 lputuser(&CC->usersupp);
225 /* set global flag calling for validation */
226 begin_critical_section(S_CONTROL);
228 CitControl.MMflags = CitControl.MMflags | MM_VALID ;
230 end_critical_section(S_CONTROL);
236 * get registration info for a user
238 void cmd_greg(char *argbuf)
240 struct usersupp usbuf;
247 extract(who, argbuf, 0);
249 if (!(CC->logged_in)) {
250 cprintf("%d Not logged in.\n", ERROR+NOT_LOGGED_IN);
254 if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
256 if ((CC->usersupp.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
257 cprintf("%d Higher access required.\n",
258 ERROR+HIGHER_ACCESS_REQUIRED);
262 if (getuser(&usbuf, who) != 0) {
263 cprintf("%d '%s' not found.\n", ERROR+NO_SUCH_USER, who);
267 v = vcard_get_user(&usbuf);
269 cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
270 cprintf("%ld\n", usbuf.usernum);
271 cprintf("%s\n", usbuf.password);
272 cprintf("%s\n", vcard_get_prop(v, "n", 0)); /* name */
274 sprintf(adr, "%s", vcard_get_prop(v, "adr", 0));/* address... */
276 lprintf(9, "adr is <%s>\n", adr);
277 extract_token(buf, adr, 2, ';');
278 cprintf("%s\n", buf); /* street */
279 extract_token(buf, adr, 3, ';');
280 cprintf("%s\n", buf); /* city */
281 extract_token(buf, adr, 4, ';');
282 cprintf("%s\n", buf); /* state */
283 extract_token(buf, adr, 5, ';');
284 cprintf("%s\n", buf); /* zip */
286 tel = vcard_get_prop(v, "tel;home", 0);
287 if (tel == NULL) tel = vcard_get_prop(v, "tel", 1);
289 cprintf("%s\n", tel);
295 cprintf("%d\n", usbuf.axlevel);
297 cprintf("%s\n", vcard_get_prop(v, "email;internet", 0));
303 void vcard_session_startup_hook(void) {
304 CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
309 char *Dynamic_Module_Init(void)
311 SYM_VCARD = CtdlGetDynamicSymbol();
312 CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
313 CtdlRegisterMessageHook(vcard_personal_upload, EVT_BEFORESAVE);
314 CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
315 CtdlRegisterProtoHook(cmd_greg, "GREG", "Get registration info");