* cmd_regi() is now in serv_vcard and writes to the vcard instead of to the
authorArt Cancro <ajc@citadel.org>
Mon, 27 Sep 1999 03:33:41 +0000 (03:33 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 27 Sep 1999 03:33:41 +0000 (03:33 +0000)
  usersupp file.  Still needs tweaking.

citadel/ChangeLog
citadel/Makefile.in
citadel/citserver.c
citadel/serv_vcard.c
citadel/user_ops.c
citadel/user_ops.h
citadel/vcard.c
citadel/vcard.h

index 2ba0368a60dce47cd23a236199d60df4d8d7e62b..d66c0aef99363451a5d40ef75a007dfa5173201f 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.372  1999/09/27 03:33:40  ajc
+* cmd_regi() is now in serv_vcard and writes to the vcard instead of to the
+  usersupp file.  Still needs tweaking.
+
 Revision 1.371  1999/09/24 03:32:19  ajc
 * "read my vCard" and "write my vCard" are written and tested.
 
@@ -1271,3 +1275,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index f2f49c7dfc48a13d3752748f4c6d95b2baf90130..4ca56c8ca398fd0eb2024f9d4b839c8f038285e9 100644 (file)
@@ -104,7 +104,7 @@ netpoll: netpoll.o config.o ipc_c_tcp.o tools.o $(LIBOBJS)
 SERV_OBJS = citserver.ro user_ops.ro support.ro room_ops.ro file_ops.ro \
        msgbase.ro config.ro sysdep.ro locate_host.ro housekeeping.ro \
        database.ro control.ro logging.ro policy.ro dynloader.ro tools.ro \
-       mime_parser.ro html.ro vcard.ro $(AUTH) $(LIBOBJS:.o=.ro)
+       mime_parser.ro html.ro $(AUTH) $(LIBOBJS:.o=.ro)
 
 citserver: $(SERV_OBJS)
        $(CC) $(SERV_OBJS) $(LDFLAGS) $(SERVER_LDFLAGS) $(LIBS) $(NETLIBS) $(GDBM) -o citserver
@@ -139,12 +139,15 @@ modules/serv_icq.so: serv_icq.mo
 modules/serv_icq.mo: serv_icq.mo
        ln -f serv_icq.mo modules
 
-modules/serv_vcard.so: serv_vcard.mo
-       $(LINK_SHARED) -o modules/serv_vcard.so serv_vcard.mo
+modules/serv_vcard.so: serv_vcard.mo vcard.mo
+       $(LINK_SHARED) -o modules/serv_vcard.so serv_vcard.mo vcard.mo
 
 modules/serv_vcard.mo: serv_vcard.mo
        ln -f serv_vcard.mo modules
 
+modules/vcard.mo: vcard.mo
+       ln -f vcard.mo modules
+
 aidepost: aidepost.o config.o $(LIBOBJS)
        $(CC) aidepost.o config.o $(LIBOBJS) $(LDFLAGS) -o aidepost
 
index b60557af76333b34ea0dc314ebb7ca84d1227d81..2459af8c583cff413540de88d8e2a7d59dca2de1 100644 (file)
@@ -1078,10 +1078,6 @@ void *context_loop(struct CitContext *con)
                        cmd_list();
                        }
 
-               else if (!strncasecmp(cmdbuf,"REGI",4)) {
-                       cmd_regi();
-                       }
-
                else if (!strncasecmp(cmdbuf,"CHEK",4)) {
                        cmd_chek();
                        }
index 650f1304f592f0c3293723ac2a6e15a542e98ffc..5452451191161451df94703935853b335f400add 100644 (file)
@@ -23,6 +23,7 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
+#include "control.h"
 #include "dynloader.h"
 #include "room_ops.h"
 #include "user_ops.h"
@@ -103,7 +104,7 @@ struct vCard *vcard_get_my(void) {
 
         if (getroom(&CC->quickroom, config_rm) != 0) {
                 getroom(&CC->quickroom, hold_rm);
-                return new_vcard();
+                return vcard_new();
         }
 
         /* We want the last (and probably only) vcard in this room */
@@ -111,12 +112,12 @@ struct vCard *vcard_get_my(void) {
         CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard", vcard_gm_backend);
         getroom(&CC->quickroom, hold_rm);      /* return to saved room */
 
-       if (VC->msgnum < 0L) return new_vcard();
+       if (VC->msgnum < 0L) return vcard_new();
 
        msg = CtdlFetchMessage(VC->msgnum);
-       if (msg == NULL) return new_vcard();
+       if (msg == NULL) return vcard_new();
 
-       v = load_vcard(msg->cm_fields['M']);
+       v = vcard_load(msg->cm_fields['M']);
        CtdlFreeMessage(msg);
        return v;
 }
@@ -134,7 +135,7 @@ void vcard_write_my(struct vCard *v) {
        char *ser;
 
         strcpy(temp, tmpnam(NULL));
-       ser = serialize_vcard(v);
+       ser = vcard_serialize(v);
 
         fp = fopen(temp, "w");
         if (fp == NULL) return;
@@ -155,10 +156,96 @@ void vcard_write_my(struct vCard *v) {
 
 
 
+/*
+ * old style "enter registration info" command
+ */
+void cmd_regi(char *argbuf) {
+       int a,b,c;
+       char buf[256];
+       struct vCard *my_vcard;
+
+       char tmpaddr[256];
+       char tmpcity[256];
+       char tmpstate[256];
+       char tmpzip[256];
+       char tmpphone[256];
+       char tmpaddress[512];
+
+       if (!(CC->logged_in)) {
+               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
+               return;
+               }
+
+       my_vcard = vcard_get_my();
+       strcpy(tmpaddr, "");
+       strcpy(tmpcity, "");
+       strcpy(tmpstate, "");
+       strcpy(tmpzip, "");
+
+       cprintf("%d Send registration...\n", SEND_LISTING);
+       a=0;
+       while (client_gets(buf), strcmp(buf,"000")) {
+               if (a==0) vcard_set_prop(my_vcard, "n", buf);
+               if (a==1) strcpy(tmpaddr,buf);
+               if (a==2) strcpy(tmpcity,buf);
+               if (a==3) strcpy(tmpstate,buf);
+               if (a==4) {
+                       for (c=0; c<strlen(buf); ++c) {
+                               if ((buf[c]>='0')&&(buf[c]<='9')) {
+                                       b=strlen(tmpzip);
+                                       tmpzip[b]=buf[c];
+                                       tmpzip[b+1]=0;
+                                       }
+                               }
+                       }
+               if (a==5) {
+                       strcpy(tmpphone, "");
+                       for (c=0; c<strlen(buf); ++c) {
+                               if ((buf[c]>='0')&&(buf[c]<='9')) {
+                                       b=strlen(tmpphone);
+                                       tmpphone[b]=buf[c];
+                                       tmpphone[b+1]=0;
+                                       }
+                               }
+                       vcard_set_prop(my_vcard, "tel;home", tmpphone);
+                       }
+               if (a==6) vcard_set_prop(my_vcard, "email;internet", buf);
+               ++a;
+               }
+       sprintf(tmpaddress, ";;%s;%s;%s;%s;USA",
+               tmpaddr, tmpcity, tmpstate, tmpzip);
+       lprintf(9, "setting address\n");
+       vcard_set_prop(my_vcard, "adr", tmpaddress);
+       lprintf(9, "writing my vcard\n");
+       vcard_write_my(my_vcard);
+       lprintf(9, "freeing my vcard\n");
+       vcard_free(my_vcard);
+
+       lprintf(9, "marking account as needing validation\n");
+       lgetuser(&CC->usersupp,CC->curr_user);
+       CC->usersupp.flags=(CC->usersupp.flags|US_REGIS|US_NEEDVALID);
+       lputuser(&CC->usersupp);
+
+       /* set global flag calling for validation */
+       lprintf(9, "setting global flag\n");
+       begin_critical_section(S_CONTROL);
+       get_control();
+       CitControl.MMflags = CitControl.MMflags | MM_VALID ;
+       put_control();
+       end_critical_section(S_CONTROL);
+       }
+
+
+void vcard_session_startup_hook(void) {
+       CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
+}
+
 
 char *Dynamic_Module_Init(void)
 {
-       CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
+       SYM_VCARD = CtdlGetDynamicSymbol();
+       CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
        CtdlRegisterMessageHook(vcard_personal_upload, EVT_BEFORESAVE);
+       CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
        return "$Id$";
 }
index 5815f1a2aafea9a454a6a2065e4f40464df12870..39fcab1de916295ebf8efd0451b7e78a22a801bb 100644 (file)
@@ -1047,89 +1047,6 @@ void cmd_list(void) {
        }
 
 
-/*
- * enter registration info
- */
-void cmd_regi(void) {
-       int a,b,c;
-       char buf[256];
-
-       char tmpname[256];
-       char tmpaddr[256];
-       char tmpcity[256];
-       char tmpstate[256];
-       char tmpzip[256];
-       char tmpphone[256];
-       char tmpemail[256];
-
-       if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
-               return;
-               }
-
-       strcpy(tmpname,"");
-       strcpy(tmpaddr,"");
-       strcpy(tmpcity,"");
-       strcpy(tmpstate,"");
-       strcpy(tmpzip,"");
-       strcpy(tmpphone,"");
-       strcpy(tmpemail,"");
-
-       cprintf("%d Send registration...\n",SEND_LISTING);
-       a=0;
-       while (client_gets(buf), strcmp(buf,"000")) {
-               if (a==0) strcpy(tmpname,buf);
-               if (a==1) strcpy(tmpaddr,buf);
-               if (a==2) strcpy(tmpcity,buf);
-               if (a==3) strcpy(tmpstate,buf);
-               if (a==4) {
-                       for (c=0; c<strlen(buf); ++c) {
-                               if ((buf[c]>='0')&&(buf[c]<='9')) {
-                                       b=strlen(tmpzip);
-                                       tmpzip[b]=buf[c];
-                                       tmpzip[b+1]=0;
-                                       }
-                               }
-                       }
-               if (a==5) {
-                       for (c=0; c<strlen(buf); ++c) {
-                               if ((buf[c]>='0')&&(buf[c]<='9')) {
-                                       b=strlen(tmpphone);
-                                       tmpphone[b]=buf[c];
-                                       tmpphone[b+1]=0;
-                                       }
-                               }
-                       }
-               if (a==6) strncpy(tmpemail,buf,31);
-               ++a;
-               }
-
-       tmpname[29]=0;
-       tmpaddr[24]=0;
-       tmpcity[14]=0;
-       tmpstate[2]=0;
-       tmpzip[9]=0;
-       tmpphone[10]=0;
-       tmpemail[31]=0;
-
-       lgetuser(&CC->usersupp,CC->curr_user);
-       strcpy(CC->usersupp.USname,tmpname);
-       strcpy(CC->usersupp.USaddr,tmpaddr);
-       strcpy(CC->usersupp.UScity,tmpcity);
-       strcpy(CC->usersupp.USstate,tmpstate);
-       strcpy(CC->usersupp.USzip,tmpzip);
-       strcpy(CC->usersupp.USphone,tmpphone);
-       strcpy(CC->usersupp.USemail,tmpemail);
-       CC->usersupp.flags=(CC->usersupp.flags|US_REGIS|US_NEEDVALID);
-       lputuser(&CC->usersupp);
-
-       /* set global flag calling for validation */
-       begin_critical_section(S_CONTROL);
-       get_control();
-       CitControl.MMflags = CitControl.MMflags | MM_VALID ;
-       put_control();
-       end_critical_section(S_CONTROL);
-       }
 
 
 /*
index d804514ea0b9fea494557dca4ab25fac027d6815..568d09a8022f7e264243381737a47b837ab7b920 100644 (file)
@@ -26,7 +26,6 @@ void cmd_vali (char *v_args);
 void ForEachUser(void (*CallBack)(struct usersupp *EachUser));
 void ListThisUser(struct usersupp *usbuf);
 void cmd_list (void);
-void cmd_regi (void);
 void cmd_chek (void);
 void cmd_qusr (char *who);
 void cmd_ebio (void);
index 8cf2d2d8c0b0c94cbab643c4d93641a808f777ee..3755848cc7d26fec2d51dd6bea44814dd0eda8b5 100644 (file)
@@ -34,7 +34,7 @@
 /* 
  * Constructor (empty vCard)
  */
-struct vCard *new_vcard() {
+struct vCard *vcard_new() {
        struct vCard *v;
 
        v = (struct vCard *) mallok(sizeof(struct vCard));
@@ -51,7 +51,7 @@ struct vCard *new_vcard() {
 /*
  * Constructor (supply serialized vCard)
  */
-struct vCard *load_vcard(char *vtext) {
+struct vCard *vcard_load(char *vtext) {
        struct vCard *v;
        int valid = 0;
        char *mycopy, *ptr;
@@ -75,7 +75,7 @@ struct vCard *load_vcard(char *vtext) {
                }
        }
 
-       v = new_vcard();
+       v = vcard_new();
        if (v == NULL) return v;
 
        ptr = mycopy;
@@ -123,11 +123,34 @@ struct vCard *load_vcard(char *vtext) {
 }
 
 
+/*
+ * Fetch the value of a particular key
+ * If is_partial is set to 1, a partial match is ok (for example,
+ * a key of "tel;home" will satisfy a search for "tel")
+ */
+char *vcard_get_prop(struct vCard *v, char *propname, int is_partial) {
+       int i;
+
+       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+               if ( (!strcasecmp(v->prop[i].name, propname))
+                  || (  (!strncasecmp(v->prop[i].name,
+                                       propname, strlen(propname)))
+                        && (v->prop[i].name[strlen(propname)] == ';')
+                        && (is_partial) ) ) {
+                       return(v->prop[i].value);
+               }
+       }
+
+       return NULL;
+}
+
+
+
 
 /*
  * Destructor
  */
-void free_vcard(struct vCard *v) {
+void vcard_free(struct vCard *v) {
        int i;
 
        if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
@@ -146,7 +169,7 @@ void free_vcard(struct vCard *v) {
 /*
  * Set a name/value pair in the card
  */
-void set_prop(struct vCard *v, char *name, char *value) {
+void vcard_set_prop(struct vCard *v, char *name, char *value) {
        int i;
 
        if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
@@ -177,7 +200,7 @@ void set_prop(struct vCard *v, char *name, char *value) {
  * Serialize a struct vcard into a standard text/x-vcard MIME type.
  *
  */
-char *serialize_vcard(struct vCard *v)
+char *vcard_serialize(struct vCard *v)
 {
        char *ser;
        int i;
@@ -200,7 +223,7 @@ char *serialize_vcard(struct vCard *v)
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
                strcat(ser, v->prop[i].name);
                strcat(ser, ":");
-               strcat(ser, v->prop[i].name);
+               strcat(ser, v->prop[i].value);
                strcat(ser, "\r\n");
        }
        strcat(ser, "end:vcard\r\n");
index 6e6260e274420d283a8b6f822cec2721a37734c2..b034d7d0e31d146527c0315882ce709a2fd4ba55 100644 (file)
@@ -24,8 +24,9 @@ struct vCard {
 };
 
 
-struct vCard *new_vcard(void);
-struct vCard *load_vcard(char *);
-void free_vcard(struct vCard *);
-void set_prop(struct vCard *v, char *name, char *value);
-char *serialize_vcard(struct vCard *);
+struct vCard *vcard_new(void);
+struct vCard *vcard_load(char *);
+void vcard_free(struct vCard *);
+void vcard_set_prop(struct vCard *v, char *name, char *value);
+char *vcard_get_prop(struct vCard *v, char *propname, int is_partial);
+char *vcard_serialize(struct vCard *);