Annotation of researchv9/ipc/src/mgrs/svcmgr/action.c, revision 1.1

1.1     ! root        1: #include "mgr.h"
        !             2: #include <ctype.h>
        !             3: 
        !             4: /*
        !             5:  * routines used by actions 
        !             6:  */
        !             7: int doconn(), doexec(), docmd();
        !             8: int auth(), v9auth(), inauth();
        !             9: int mesgld(), ttyld();
        !            10: int parms(), asuser(), term();
        !            11: int gateout(), gateway();
        !            12: 
        !            13: /*
        !            14:  * table of actions
        !            15:  * one per possible action
        !            16:  */
        !            17: 
        !            18: typedef struct {
        !            19:        char *name;     /* as used in the services file */
        !            20:        int (*func)();  /* function for this action */
        !            21:        int flag;
        !            22: } ProtoAction;
        !            23: 
        !            24: #define TAKEARG 1
        !            25: #define NEEDARG 2
        !            26: #define IPCACCEPT 4
        !            27: 
        !            28: ProtoAction actions[] = {
        !            29:        { "login",      doconn,         0 },
        !            30:        { "exec",       doexec,         0 },
        !            31:        { "cmd",        docmd,          TAKEARG },      /* arg=command to exec */
        !            32:        { "auth",       auth,           0 },
        !            33:        { "v9auth",     v9auth,         0 },
        !            34:        { "inauth",     inauth,         0 },
        !            35:        { "mesgld",     mesgld,         0 },
        !            36:        { "ttyld",      ttyld,          0 },
        !            37:        { "args",       parms,          0 },
        !            38:        { "term",       term,           TAKEARG },
        !            39:        { "user",       asuser,         NEEDARG },      /* arg=user id */
        !            40:        { "gateout",    gateout,        NEEDARG|IPCACCEPT }, /* arg=addr prefix */
        !            41:        { "gateway",    gateway,        NEEDARG|IPCACCEPT }, /* arg=addr prefix */
        !            42:        { NULL }
        !            43: };
        !            44: 
        !            45: /*
        !            46:  *  Parse a string for an action.  Actions are of the form `xxx(yyy)'.
        !            47:  *  `xxx' selects the action and `yyy' is the argument to the action.
        !            48:  */
        !            49: Action *
        !            50: newaction(cp)
        !            51:        char *cp;
        !            52: {
        !            53:        ProtoAction *pap;
        !            54:        Action *ap = (Action *)malloc(sizeof(Action));
        !            55:        char *arg;
        !            56:        char *rp;
        !            57: 
        !            58:        if(ap==NULL) {
        !            59:                logevent("out of memory parsing action\n");
        !            60:                return NULL;
        !            61:        }
        !            62:        ap->arg = NULL;
        !            63: 
        !            64:        /* find the xxx */
        !            65:        for(; isspace(*cp); cp++)
        !            66:                ;
        !            67:        for(arg=cp; *arg && !isspace(*arg) && *arg!='('; arg++)
        !            68:                ;
        !            69: 
        !            70:        /* find the yyy */
        !            71:        if(*arg=='(') {
        !            72:                rp = strrchr(arg, ')');
        !            73:                if (rp == NULL) {
        !            74:                        logevent("missing `)' in action `%s'\n", cp);
        !            75:                        freeaction(ap);
        !            76:                        return NULL;
        !            77:                }
        !            78:                *arg++ = '\0';
        !            79:                for(; isspace(*arg); arg++)
        !            80:                        ;
        !            81:                *rp = '\0';
        !            82:        } else
        !            83:                arg = NULL;
        !            84: 
        !            85:        /* look for the action */
        !            86:        for(pap=actions; pap->name!=NULL; pap++) {
        !            87:                if(strcmp(pap->name, cp)==0) {
        !            88:                        if(pap->flag&NEEDARG && arg==NULL) {
        !            89:                                logevent("missing arg in action `%s'\n", cp);
        !            90:                                freeaction(ap);
        !            91:                                return NULL;
        !            92:                        }
        !            93:                        if(arg!=NULL && !pap->flag&TAKEARG) {
        !            94:                                logevent("expected no arg in action `%s'\n", cp);
        !            95:                                freeaction(ap);
        !            96:                                return NULL;
        !            97:                        }
        !            98:                        ap->func = pap->func;
        !            99:                        if (arg == NULL)
        !           100:                                ap->arg = NULL;
        !           101:                        else
        !           102:                                ap->arg = strdup(arg);
        !           103:                        ap->accept = pap->flag&IPCACCEPT;
        !           104:                        return ap;
        !           105:                }
        !           106:        }
        !           107:        logevent("unknown action `%s'\n", cp);
        !           108:        return NULL;
        !           109: }
        !           110: 
        !           111: freeaction(ap)
        !           112:        Action *ap;
        !           113: {
        !           114:        if (ap==(Action *)NULL)
        !           115:                return;
        !           116:        if (ap->arg!=NULL)
        !           117:                free(ap->arg);
        !           118:        free((char *)ap);
        !           119: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.