* Fully migrated cmd_greg() and cmd_regi() into serv_vcard (still has bugs)
authorArt Cancro <ajc@citadel.org>
Tue, 28 Sep 1999 03:27:38 +0000 (03:27 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 28 Sep 1999 03:27:38 +0000 (03:27 +0000)
citadel/ChangeLog
citadel/citserver.c
citadel/routines2.c
citadel/serv_vcard.c
citadel/tools.c
citadel/tools.h
citadel/user_ops.c
citadel/user_ops.h
citadel/vcard.c

index d66c0aef99363451a5d40ef75a007dfa5173201f..2f5e7bd8f9429305a4d74f89457a9c98be50d2f8 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.373  1999/09/28 03:27:37  ajc
+* Fully migrated cmd_greg() and cmd_regi() into serv_vcard (still has bugs)
+
 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.
@@ -1275,4 +1278,3 @@ 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 2459af8c583cff413540de88d8e2a7d59dca2de1..ef7cb29ed609ef56ea5a086db1ca2f45ca09ad83 100644 (file)
@@ -1062,10 +1062,6 @@ void *context_loop(struct CitContext *con)
                        cmd_gnur();
                        }
 
-               else if (!strncasecmp(cmdbuf,"GREG",4)) {
-                       cmd_greg(&cmdbuf[5]);
-                       }
-
                else if (!strncasecmp(cmdbuf,"VALI",4)) {
                        cmd_vali(&cmdbuf[5]);
                        }
index a6345b31ea3e27de6ceec2ee437cefd1c86d6746..e3ea568606b9f796bc9fb84cb2081b84a6142787 100644 (file)
@@ -34,7 +34,6 @@ void newprompt(char *prompt, char *str, int len);
 void sttybbs(int cmd);
 int inkey(void);
 void serv_write(char *buf, int nbytes);
-void extract(char *dest, char *source, int parmnum);
 int haschar(char *st, int ch);
 void progress(long int curr, long int cmax);
 void citedit(FILE *fp, long int base_pos);
index 5452451191161451df94703935853b335f400add..1301d54d0d6688a1b087837ffc7edfdcd6e25be6 100644 (file)
@@ -30,6 +30,7 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
+#include "tools.h"
 #include "vcard.h"
 
 struct vcard_internal_info {
@@ -60,7 +61,6 @@ int vcard_personal_upload(struct CtdlMessage *msg) {
        while (ptr != NULL) {
        
                linelen = strcspn(ptr, "\n");
-               lprintf(9, "linelen == %d\n", linelen);
                if (linelen == 0) return(0);    /* end of headers */    
                
                if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
@@ -82,7 +82,7 @@ int vcard_personal_upload(struct CtdlMessage *msg) {
 
 
 /*
- * back end function used by vcard_get_my()
+ * back end function used by vcard_get_user()
  */
 void vcard_gm_backend(long msgnum) {
        VC->msgnum = msgnum;
@@ -93,14 +93,14 @@ void vcard_gm_backend(long msgnum) {
  * If this user has a vcard on disk, read it into memory, otherwise allocate
  * and return an empty vCard.
  */
-struct vCard *vcard_get_my(void) {
+struct vCard *vcard_get_user(struct usersupp *u) {
         char hold_rm[ROOMNAMELEN];
         char config_rm[ROOMNAMELEN];
        struct CtdlMessage *msg;
        struct vCard *v;
 
         strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
-        MailboxName(config_rm, &CC->usersupp, CONFIGROOM);
+        MailboxName(config_rm, u, CONFIGROOM);
 
         if (getroom(&CC->quickroom, config_rm) != 0) {
                 getroom(&CC->quickroom, hold_rm);
@@ -129,10 +129,11 @@ struct vCard *vcard_get_my(void) {
 /*
  * Write our config to disk
  */
-void vcard_write_my(struct vCard *v) {
+void vcard_write_user(struct usersupp *u, struct vCard *v) {
         char temp[PATH_MAX];
         FILE *fp;
        char *ser;
+        char config_rm[ROOMNAMELEN];
 
         strcpy(temp, tmpnam(NULL));
        ser = vcard_serialize(v);
@@ -148,8 +149,9 @@ void vcard_write_my(struct vCard *v) {
        }
         fclose(fp);
 
-        /* this handy API function does all the work for us */
-        CtdlWriteObject(CONFIGROOM, "text/x-vcard", temp, 1, 0, 1);
+        /* these handy API functions do all the work for us */
+        MailboxName(config_rm, u, CONFIGROOM);
+        CtdlWriteObject(config_rm, "text/x-vcard", temp, 1, 0, 1);
 
         unlink(temp);
 }
@@ -176,7 +178,7 @@ void cmd_regi(char *argbuf) {
                return;
                }
 
-       my_vcard = vcard_get_my();
+       my_vcard = vcard_get_user(&CC->usersupp);
        strcpy(tmpaddr, "");
        strcpy(tmpcity, "");
        strcpy(tmpstate, "");
@@ -214,20 +216,15 @@ void cmd_regi(char *argbuf) {
                }
        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_write_user(&CC->usersupp, my_vcard);
        vcard_free(my_vcard);
 
-       lprintf(9, "marking account as needing validation\n");
-       lgetuser(&CC->usersupp,CC->curr_user);
+       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 ;
@@ -236,16 +233,86 @@ void cmd_regi(char *argbuf) {
        }
 
 
+
+/*
+ * get registration info for a user
+ */
+void cmd_greg(char *argbuf)
+{
+       struct usersupp usbuf;
+       struct vCard *v;
+       char *tel;
+       char who[256];
+       char adr[256];
+       char buf[256];
+
+       extract(who, argbuf, 0);
+
+       if (!(CC->logged_in)) {
+               cprintf("%d Not logged in.\n", ERROR+NOT_LOGGED_IN);
+               return;
+       }
+
+       if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
+
+       if ((CC->usersupp.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
+               cprintf("%d Higher access required.\n",
+                       ERROR+HIGHER_ACCESS_REQUIRED);
+               return;
+       }
+
+       if (getuser(&usbuf, who) != 0) {
+               cprintf("%d '%s' not found.\n", ERROR+NO_SUCH_USER, who);
+               return;
+       }
+
+       v = vcard_get_user(&usbuf);
+
+       cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
+       cprintf("%ld\n", usbuf.usernum);
+       cprintf("%s\n", usbuf.password);
+       cprintf("%s\n", vcard_get_prop(v, "n", 0));     /* name */
+
+       strcpy(adr, vcard_get_prop(v, "adr", 0));       /* address... */
+
+       extract_token(buf, adr, 2, ';');
+       cprintf("%s\n", buf);                           /* street */
+       extract_token(buf, adr, 2, ';');
+       cprintf("%s\n", buf);                           /* city */
+       extract_token(buf, adr, 2, ';');
+       cprintf("%s\n", buf);                           /* state */
+       extract_token(buf, adr, 2, ';');
+       cprintf("%s\n", buf);                           /* zip */
+
+       tel = vcard_get_prop(v, "tel;home", 0);
+       if (tel == NULL) tel = vcard_get_prop(v, "tel", 1);
+       if (tel != NULL) {
+               cprintf("%s\n", tel);
+               }
+       else {
+               cprintf(" \n");
+       }
+
+       cprintf("%d\n", usbuf.axlevel);
+
+       cprintf("%s\n", vcard_get_prop(v, "email;internet", 0));
+       cprintf("000\n");
+       }
+
+
+
 void vcard_session_startup_hook(void) {
        CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
 }
 
 
+
 char *Dynamic_Module_Init(void)
 {
        SYM_VCARD = CtdlGetDynamicSymbol();
        CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
        CtdlRegisterMessageHook(vcard_personal_upload, EVT_BEFORESAVE);
        CtdlRegisterProtoHook(cmd_regi, "REGI", "Enter registration info");
+       CtdlRegisterProtoHook(cmd_greg, "GREG", "Get registration info");
        return "$Id$";
 }
index 9335cbe98ee6628650aad1bb1d526c6d58fc520c..189f922cd4039d2c3f66abe80944ec6ee28fd691 100644 (file)
@@ -37,7 +37,7 @@ int num_parms(char *source)
 /*
  * extract()  -  extract a parameter from a series of "|" separated...
  */
-void extract(char *dest, char *source, int parmnum)
+void extract_token(char *dest, char *source, int parmnum, char separator)
 {
        char buf[256];
        int count = 0;
@@ -58,16 +58,16 @@ void extract(char *dest, char *source, int parmnum)
        if ( (parmnum == 0) && (n == 1) ) {
                strcpy(dest,buf);
                for (n=0; n<strlen(dest); ++n)
-                       if (dest[n]=='|') dest[n] = 0;
+                       if (dest[n]==separator) dest[n] = 0;
                return;
                }
 
        while (count++ < parmnum) do {
                strcpy(buf,&buf[1]);
-               } while( (strlen(buf)>0) && (buf[0]!='|') );
-       if (buf[0]=='|') strcpy(buf,&buf[1]);
+               } while( (strlen(buf)>0) && (buf[0]!=separator) );
+       if (buf[0]==separator) strcpy(buf,&buf[1]);
        for (count = 0; count<strlen(buf); ++count)
-               if (buf[count] == '|') buf[count] = 0;
+               if (buf[count] == separator) buf[count] = 0;
        strcpy(dest,buf);
        }
 
index 68e1dc8b58e6effa9681f7164c10b329b18f2841..7024f3117a7e0ae4deb65cdc1be9538c922a8562 100644 (file)
@@ -1,6 +1,8 @@
 /* $Id$ */
 char *safestrncpy(char *dest, const char *src, size_t n);
 int num_parms (char *source);
-void extract (char *dest, char *source, int parmnum);
+void extract_token(char *dest, char *source, int parmnum, char separator);
 int extract_int (char *source, int parmnum);
 long int extract_long (char *source, long int parmnum);
+
+#define extract(dest,source,parmnum)   extract_token(dest,source,parmnum,'|')
index 39fcab1de916295ebf8efd0451b7e78a22a801bb..dcdbbe555bea7fdd3ecf1cc767dd51e6438ac037 100644 (file)
@@ -888,67 +888,6 @@ void cmd_gnur(void) {
        }
 
 
-/*
- * get registration info for a user
- */
-void cmd_greg(char *who)
-{
-       struct usersupp usbuf;
-       int a,b;
-       char pbuf[32];
-
-       if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
-               return;
-               }
-
-       if (!strcasecmp(who,"_SELF_")) strcpy(who,CC->curr_user);
-
-       if ((CC->usersupp.axlevel < 6) && (strcasecmp(who,CC->curr_user))) {
-               cprintf("%d Higher access required.\n",
-                       ERROR+HIGHER_ACCESS_REQUIRED);
-               return;
-               }
-
-       if (getuser(&usbuf,who) != 0) {
-               cprintf("%d '%s' not found.\n",ERROR+NO_SUCH_USER,who);
-               return;
-               }
-
-       cprintf("%d %s\n",LISTING_FOLLOWS,usbuf.fullname);
-       cprintf("%ld\n",usbuf.usernum);
-       cprintf("%s\n",usbuf.password);
-       cprintf("%s\n",usbuf.USname);
-       cprintf("%s\n",usbuf.USaddr);
-       cprintf("%s\n%s\n%s\n",
-               usbuf.UScity,usbuf.USstate,usbuf.USzip);
-       strcpy(pbuf,usbuf.USphone);
-       usbuf.USphone[0]=0;
-       for (a=0; a<strlen(pbuf); ++a) {
-               if ((pbuf[a]>='0')&&(pbuf[a]<='9')) {
-                       b=strlen(usbuf.USphone);
-                       usbuf.USphone[b]=pbuf[a];
-                       usbuf.USphone[b+1]=0;
-                       }
-               }
-       while(strlen(usbuf.USphone)<10) {
-               strcpy(pbuf,usbuf.USphone);
-               strcpy(usbuf.USphone," ");
-               strcat(usbuf.USphone,pbuf);
-               }
-
-       cprintf("(%c%c%c) %c%c%c-%c%c%c%c\n",
-               usbuf.USphone[0],usbuf.USphone[1],
-               usbuf.USphone[2],usbuf.USphone[3],
-               usbuf.USphone[4],usbuf.USphone[5],
-               usbuf.USphone[6],usbuf.USphone[7],
-               usbuf.USphone[8],usbuf.USphone[9]);
-
-       cprintf("%d\n",usbuf.axlevel);
-       cprintf("%s\n",usbuf.USemail);
-       cprintf("000\n");
-       }
-
 /*
  * validate a user
  */
index 568d09a8022f7e264243381737a47b837ab7b920..553e185b3807d3c31f1fff43da767026cff14072 100644 (file)
@@ -21,7 +21,6 @@ void cmd_slrp (char *new_ptr);
 void cmd_invt_kick (char *iuser, int op);
 void cmd_forg (void);
 void cmd_gnur (void);
-void cmd_greg (char *who);
 void cmd_vali (char *v_args);
 void ForEachUser(void (*CallBack)(struct usersupp *EachUser));
 void ListThisUser(struct usersupp *usbuf);
index 3755848cc7d26fec2d51dd6bea44814dd0eda8b5..a34a466b0306800270a033358f41142254da1b3f 100644 (file)
@@ -93,18 +93,18 @@ struct vCard *vcard_load(char *vtext) {
                        strncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1);
                        valuebuf[nlpos-colonpos-1] = 0;
 
-                       if ( (!strcasecmp(namebuf, "begin"))
-                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 1;
                        if ( (!strcasecmp(namebuf, "end"))
                           && (!strcasecmp(valuebuf, "vcard")) )  valid = 0;
+                       if ( (!strcasecmp(namebuf, "begin"))
+                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 1;
 
-                       if (valid) {
+                       if ( (valid) && (strcasecmp(namebuf, "begin")) ) {
                                ++v->numprops;
                                v->prop = reallok(v->prop,
                                        (v->numprops * sizeof(char *) * 2) );
                                v->prop[v->numprops-1].name = namebuf;
                                v->prop[v->numprops-1].value = valuebuf;
-                       }
+                       } 
                        else {
                                phree(namebuf);
                                phree(valuebuf);
@@ -152,7 +152,7 @@ char *vcard_get_prop(struct vCard *v, char *propname, int is_partial) {
  */
 void vcard_free(struct vCard *v) {
        int i;
-
+       
        if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
        
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
@@ -163,6 +163,7 @@ void vcard_free(struct vCard *v) {
        if (v->prop != NULL) phree(v->prop);
        
        memset(v, 0, sizeof(struct vCard));
+       phree(v);
 }
 
 
@@ -190,7 +191,7 @@ void vcard_set_prop(struct vCard *v, char *name, char *value) {
        v->prop = reallok(v->prop,
                (v->numprops * sizeof(char *) * 2) );
        v->prop[v->numprops-1].name = strdoop(name);
-       v->prop[v->numprops-1].value = (value);
+       v->prop[v->numprops-1].value = strdoop(value);
 }