Annotation of 43BSDReno/contrib/isode-beta/dsap/common/attrv.c, revision 1.1

1.1     ! root        1: /* attrv.c - Attribute Value routines */
        !             2: 
        !             3: #ifndef lint
        !             4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/attrv.c,v 7.4 90/07/09 14:34:00 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /*
        !             8:  * $Header: /f/osi/dsap/common/RCS/attrv.c,v 7.4 90/07/09 14:34:00 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       attrv.c,v $
        !            12:  * Revision 7.4  90/07/09  14:34:00  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.3  90/04/18  08:50:00  mrose
        !            16:  * 6.2
        !            17:  * 
        !            18:  * Revision 7.2  90/03/15  11:17:26  mrose
        !            19:  * quipu-sync
        !            20:  * 
        !            21:  * Revision 7.1  90/01/11  18:35:30  mrose
        !            22:  * real-sync
        !            23:  * 
        !            24:  * Revision 7.0  89/11/23  21:41:44  mrose
        !            25:  * Release 6.0
        !            26:  * 
        !            27:  */
        !            28: 
        !            29: /*
        !            30:  *                                NOTICE
        !            31:  *
        !            32:  *    Acquisition, use, and distribution of this module and related
        !            33:  *    materials are subject to the restrictions of a license agreement.
        !            34:  *    Consult the Preface in the User's Manual for the full terms of
        !            35:  *    this agreement.
        !            36:  *
        !            37:  */
        !            38: 
        !            39: 
        !            40: /* LINTLIBRARY */
        !            41: 
        !            42: #include "quipu/util.h"
        !            43: #include "quipu/entry.h"
        !            44: #include "quipu/ds_error.h"
        !            45: #include "quipu/malloc.h"
        !            46: #include "cmd_srch.h"
        !            47: #include <sys/stat.h>
        !            48: 
        !            49: extern int oidformat;
        !            50: extern struct PSAPaddr * psap_cpy ();
        !            51: extern str2asn (), pe_print() ;
        !            52: AttributeValue str2file ();
        !            53: extern LLog * log_dsap;
        !            54: PE asn2pe();
        !            55: int quipu_pe_cmp();
        !            56: char t61_flag;
        !            57: char crypt_flag;
        !            58: char allow_crypt = FALSE;
        !            59: extern int file_cmp ();
        !            60: 
        !            61: static short num_syntax = 1;
        !            62: static sntx_table syntax_table [MAX_AV_SYNTAX] = { {
        !            63:        "ASN",          /* ASN - default type */
        !            64:        (IFP)pe_cpy,    /* default encode */ 
        !            65:        NULLIFP,        /* no decoding needed */
        !            66:        NULLIFP,        /* default parse */
        !            67:        NULLIFP,        /* default print */
        !            68:        (IFP)pe_cpy,    /* default copy */
        !            69:        quipu_pe_cmp,   /* default compare */
        !            70:        pe_free,        /* default free */
        !            71:        NULLCP,         /* no pe_printer */
        !            72:        NULLIFP,        /* NO approx matching */
        !            73:        TRUE,           /* one per line */
        !            74: } };
        !            75:        
        !            76: 
        !            77: short add_attribute_syntax (sntx,enc,dec,parse,print,cpy,cmp,sfree,print_pe,approx,multiline)
        !            78: char * sntx;
        !            79: IFP    enc,dec,parse,print,cpy,cmp,sfree,approx;
        !            80: char *  print_pe;
        !            81: char   multiline;
        !            82: {
        !            83:        if (num_syntax >= MAX_AV_SYNTAX)
        !            84:                return (-1); 
        !            85: 
        !            86:        syntax_table[num_syntax].s_sntx    = sntx;
        !            87:        set_attribute_syntax (num_syntax,enc,dec,parse,print,cpy,cmp,sfree,print_pe,approx,multiline);
        !            88:        
        !            89:        return (num_syntax++);
        !            90: }
        !            91: 
        !            92: set_attribute_syntax (sntx,enc,dec,parse,print,cpy,cmp,sfree,print_pe,approx,multiline)
        !            93: short sntx;
        !            94: IFP    enc,dec,parse,print,cpy,cmp,sfree,approx;
        !            95: char *  print_pe;
        !            96: char   multiline;
        !            97: {
        !            98:        syntax_table[sntx].s_encode  = enc;
        !            99:        syntax_table[sntx].s_decode  = dec;
        !           100:        syntax_table[sntx].s_parse   = parse;
        !           101:        syntax_table[sntx].s_print   = print;
        !           102:        syntax_table[sntx].s_copy    = cpy;
        !           103:        syntax_table[sntx].s_compare = cmp;
        !           104:        syntax_table[sntx].s_free    = sfree;
        !           105:        syntax_table[sntx].s_pe_print= print_pe;
        !           106:        syntax_table[sntx].s_approx  = approx;
        !           107:        syntax_table[sntx].s_multiline  = multiline;
        !           108: }
        !           109: 
        !           110: set_av_pe_print (sntx,print_pe)
        !           111: short sntx;
        !           112: char *  print_pe;
        !           113: {
        !           114:        syntax_table[sntx].s_pe_print= print_pe;
        !           115: }
        !           116: 
        !           117: split_attr (as)
        !           118: Attr_Sequence as;
        !           119: {
        !           120: 
        !           121:        if (as->attr_type == NULLTABLE_ATTR)
        !           122:                return (TRUE);
        !           123:        else
        !           124:                return (syntax_table[as->attr_type->oa_syntax].s_multiline);
        !           125: }
        !           126: 
        !           127: IFP approxfn (x)
        !           128: int x;
        !           129: {
        !           130:        return (syntax_table[x].s_approx);
        !           131: }
        !           132: 
        !           133: char * syntax2str (sntx)
        !           134: short sntx;
        !           135: {
        !           136:        return (syntax_table[sntx].s_sntx);
        !           137: }
        !           138: 
        !           139: short str2syntax (str)
        !           140: char * str;
        !           141: {
        !           142: sntx_table * ptr;
        !           143: register int i;
        !           144: 
        !           145:        for (i=0, ptr = &syntax_table[0] ; i<num_syntax; i++,ptr++) 
        !           146:                if ( lexequ (ptr->s_sntx,str) == 0)
        !           147:                        return (i);
        !           148: 
        !           149:        return (0);
        !           150: }
        !           151: 
        !           152: sntx_table * get_syntax_table (x)
        !           153: short x;
        !           154: {
        !           155:        return ( &syntax_table[x]);
        !           156: }
        !           157: 
        !           158: AttrV_free (x)
        !           159: register AttributeValue x;
        !           160: {
        !           161:        AttrV_free_aux (x);
        !           162:        free ((char *)  x);
        !           163: }
        !           164: 
        !           165: AttrV_free_aux (x)
        !           166: register AttributeValue x;
        !           167: {
        !           168:        if (x == NULLAttrV)
        !           169:                return;
        !           170: 
        !           171:        if (x->av_syntax == AV_FILE) {
        !           172:                file_free ((struct file_syntax *)x->av_struct);
        !           173:                return;
        !           174:        }
        !           175: 
        !           176:        if (( x->av_syntax < AV_WRITE_FILE ) 
        !           177:                && (syntax_table[x->av_syntax].s_free != NULLIFP)
        !           178:                && (x->av_struct != NULL))
        !           179:                        (*syntax_table[x->av_syntax].s_free) (x->av_struct);
        !           180: }
        !           181: 
        !           182: PE      grab_pe(av)
        !           183: AttributeValue  av;
        !           184: {
        !           185: PE ret_pe = NULLPE;
        !           186: PE grab_filepe ();
        !           187: 
        !           188:        if (av->av_syntax == AV_FILE) 
        !           189:                ret_pe = grab_filepe (av);
        !           190:        else if (syntax_table[av->av_syntax].s_encode != NULLIFP)
        !           191:                ret_pe = (PE)((*syntax_table[av->av_syntax].s_encode) (av->av_struct));
        !           192: 
        !           193:        return (ret_pe);
        !           194: }
        !           195: 
        !           196: AttrV_decode(x,y)
        !           197: register AttributeType x;
        !           198: register AttributeValue y;
        !           199: {
        !           200: int y_syntax;
        !           201: 
        !           202:        if (x == NULLAttrT)
        !           203:                return (NOTOK);
        !           204: 
        !           205:        if ((y == NULLAttrV) || (y->av_syntax != 0))
        !           206:                return (OK);
        !           207: 
        !           208:        if (y->av_struct == NULL)
        !           209:                return (OK);
        !           210: 
        !           211:        y->av_syntax = x->oa_syntax;
        !           212:        if ( (y_syntax = y->av_syntax) >= AV_WRITE_FILE ) 
        !           213:                y_syntax = y->av_syntax - AV_WRITE_FILE;
        !           214: 
        !           215:        ATTRIBUTE_HEAP;
        !           216: 
        !           217:        if (syntax_table[y_syntax].s_decode != NULLIFP) {
        !           218:                PE oldpe = (PE)y->av_struct;
        !           219:                if ((y->av_struct = (caddr_t)((*syntax_table[y_syntax].s_decode) (oldpe))) == NULL) {
        !           220:                        RESTORE_HEAP;
        !           221:                        y->av_struct = (caddr_t)oldpe;
        !           222:                        y->av_syntax = 0;
        !           223:                        return (NOTOK);
        !           224:                }
        !           225:                pe_free (oldpe);
        !           226:        } 
        !           227: 
        !           228:        if ( y->av_syntax >= AV_WRITE_FILE ) 
        !           229:                file_decode (y);
        !           230: 
        !           231:        RESTORE_HEAP;
        !           232: 
        !           233:        return (OK);
        !           234: }
        !           235: 
        !           236: static strip_header(str)
        !           237: char ** str;
        !           238: {
        !           239: register char * ptr, *save, val;
        !           240: int syntax;
        !           241: extern char * index();
        !           242: static CMD_TABLE cmd_syntax [] = {
        !           243:         "FILE",                1,
        !           244:        "ASN",          2,
        !           245:        "T.61",         3,
        !           246:        "CRYPT",        4,
        !           247:         0,              0,
        !           248:         } ;
        !           249: 
        !           250: 
        !           251:        if (*str == NULLCP)
        !           252:                return (0);
        !           253: 
        !           254:        *str = SkipSpace (*str);
        !           255:        if (**str == 0)
        !           256:                return (0);
        !           257:        ptr = *str;
        !           258: 
        !           259:        t61_flag = FALSE;
        !           260:        crypt_flag = FALSE;
        !           261: 
        !           262:        if (*ptr++ == '{') {
        !           263:                /* look for syntax */   
        !           264:                if (( *str = index (ptr,'}')) == 0) {
        !           265:                        parse_error ("syntax close bracket missing '%s'",--ptr);
        !           266:                        return (0);
        !           267:                }
        !           268:                 save = *str;
        !           269:                 val = **str;
        !           270: 
        !           271:                *(*str)++ = 0;
        !           272:                *str = SkipSpace (*str);
        !           273: 
        !           274:                if ((syntax = cmd_srch (ptr,cmd_syntax)) == 0) {
        !           275:                        parse_error ("unknown syntax '%s'",ptr);
        !           276:                        return (0);
        !           277:                }
        !           278:                 *save = val;
        !           279: 
        !           280:                if ((syntax == 4) && ! allow_crypt) {
        !           281:                        parse_error ("{CRYPT} not allowed",ptr);
        !           282:                        return (0);
        !           283:                }
        !           284:                return (syntax);
        !           285: 
        !           286:        }
        !           287:        return (5);
        !           288: }
        !           289: 
        !           290: str_at2AttrV_aux (str,at,rav)
        !           291: char * str;
        !           292: AttributeType at;
        !           293: AttributeValue rav;
        !           294: {
        !           295:        if (at == NULLAttrT)
        !           296:                return (NOTOK);
        !           297: 
        !           298:        switch (strip_header (&str)) {
        !           299:                case 0: /* error */
        !           300:                        return (NOTOK);
        !           301:                case 1: /* FILE */
        !           302:                        return (str2file_aux (str,at,rav));
        !           303:                case 2: /* ASN */
        !           304:                        (void) str2AttrV_aux (str,0,rav);
        !           305:                        return (AttrV_decode (at,rav));
        !           306:                case 3: /* T.61 */
        !           307:                        t61_flag = TRUE;
        !           308:                        return (str2AttrV_aux (SkipSpace(str),at->oa_syntax,rav));
        !           309:                case 4:
        !           310:                        crypt_flag = TRUE;
        !           311:                        /* fall */
        !           312:                case 5:
        !           313:                        return (str2AttrV_aux (str,at->oa_syntax,rav));
        !           314:        }
        !           315:        return (NOTOK);
        !           316: }
        !           317: 
        !           318: 
        !           319: AttributeValue str_at2AttrV (str,at)
        !           320: char * str;
        !           321: AttributeType at;
        !           322: {
        !           323: AttributeValue av;
        !           324: 
        !           325:        if (at == NULLAttrT)
        !           326:                return (NULLAttrV);
        !           327: 
        !           328:        switch (strip_header(&str)) {
        !           329:                case 0: /* error */
        !           330:                        return (NULLAttrV);
        !           331:                case 1: /* FILE */
        !           332:                        return (str2file (str,at));
        !           333:                case 2: /* ASN */
        !           334:                        av = str2AttrV (str,0);
        !           335:                        if (AttrV_decode (at,av) == NOTOK)
        !           336:                                return (NULLAttrV);
        !           337:                        return (av);
        !           338:                case 3: /* T.61 */
        !           339:                        t61_flag = TRUE;
        !           340:                        return (str2AttrV (str,at->oa_syntax));
        !           341:                case 4:
        !           342:                        crypt_flag = TRUE;
        !           343:                        /* fall */
        !           344:                case 5:
        !           345:                        return (str2AttrV (str,at->oa_syntax));
        !           346:        }
        !           347:        return (NULLAttrV);
        !           348: }
        !           349: 
        !           350: AttributeValue str2AttrV (str,syntax)
        !           351: register char * str;
        !           352: short syntax;
        !           353: {
        !           354: AttributeValue x;
        !           355: 
        !           356:        x = AttrV_alloc();
        !           357:        if (str2AttrV_aux (str,syntax,x) == OK)
        !           358:                return (x);
        !           359:        free ((char *)x);
        !           360:        return NULLAttrV;
        !           361: }
        !           362: 
        !           363: str2AttrV_aux (str,syntax,x)
        !           364: register char * str;
        !           365: short syntax;
        !           366: AttributeValue x;
        !           367: {
        !           368: 
        !           369:        if (str == NULLCP)
        !           370:                return (NOTOK);
        !           371: 
        !           372:        if ((x->av_syntax = syntax) > AV_WRITE_FILE)
        !           373:                x->av_syntax = syntax - AV_WRITE_FILE;
        !           374:        x->av_struct = NULL;
        !           375: 
        !           376:        if (syntax_table[syntax].s_parse != NULLIFP) {
        !           377:                if ((x->av_struct = (caddr_t)(*syntax_table[syntax].s_parse) (str)) == NULL) 
        !           378:                        return (NOTOK);
        !           379:                if (t61_flag) {
        !           380:                        parse_error ("invalid use of {T.61}",NULLCP);
        !           381:                        return (NOTOK);
        !           382:                }
        !           383:                if (crypt_flag) {
        !           384:                        parse_error ("invalid use of {CRYPT}",NULLCP);
        !           385:                        return (NOTOK);
        !           386:                }
        !           387:        } else if ((x->av_struct = (caddr_t) asn2pe (str)) == NULL) {
        !           388:                parse_error ("invalid ASN attribute",NULLCP);
        !           389:                return NOTOK;
        !           390:        }
        !           391:        return (OK);
        !           392: }
        !           393: 
        !           394: AttributeValue AttrV_cpy (x)
        !           395: register AttributeValue x;
        !           396: {
        !           397: register AttributeValue y = NULLAttrV;
        !           398: 
        !           399:        y = AttrV_alloc();
        !           400:        AttrV_cpy_aux (x,y);
        !           401:        return (y);
        !           402: }
        !           403: 
        !           404: AttrV_cpy_aux (x,y)
        !           405: register AttributeValue x;
        !           406: register AttributeValue y;
        !           407: {
        !           408: struct file_syntax * fileattr_cpy();
        !           409: 
        !           410:        y->av_syntax = x->av_syntax;
        !           411: 
        !           412:        if (x->av_struct == NULL) {
        !           413:                y->av_struct = NULL;
        !           414:                return;
        !           415:        }
        !           416: 
        !           417:        if (x->av_syntax == AV_FILE) 
        !           418:                y->av_struct = (caddr_t) fileattr_cpy ((struct file_syntax *)x->av_struct);
        !           419:        else if (syntax_table[x->av_syntax].s_copy != NULLIFP) 
        !           420:                y->av_struct = (caddr_t)(*syntax_table[x->av_syntax].s_copy) (x->av_struct);
        !           421:        else 
        !           422:                y->av_struct = NULL;
        !           423: }
        !           424: 
        !           425: 
        !           426: rdn_cmp (a,b)
        !           427: register RDN  a,b;
        !           428: {
        !           429: register int i;
        !           430: 
        !           431:        for (; (a != NULLRDN) && (b != NULLRDN) ; a = a->rdn_next, b = b->rdn_next) {
        !           432:                if (a->rdn_at != b->rdn_at) 
        !           433:                        return ((a->rdn_at > b->rdn_at) ? 1 : -1);
        !           434:                
        !           435:                if (syntax_table[a->rdn_av.av_syntax].s_compare == NULLIFP) 
        !           436:                        return (2); /* can't compare */
        !           437:                else 
        !           438:                        if (( i = (*syntax_table[a->rdn_av.av_syntax].s_compare) (a->rdn_av.av_struct,b->rdn_av.av_struct)) != 0)
        !           439:                                return i;
        !           440:        }
        !           441: 
        !           442:        if ( (a == NULLRDN) && (b == NULLRDN) )  {
        !           443:                return 0;
        !           444:        } else {
        !           445:                return ( a  ?  1  : -1);
        !           446:        }
        !           447: 
        !           448: }
        !           449: 
        !           450: AttrV_cmp (x,y)
        !           451: register AttributeValue x,y;
        !           452: {
        !           453:        if (x->av_syntax != y->av_syntax) 
        !           454:                return (-2);
        !           455: 
        !           456:        if (x->av_syntax == AV_FILE)
        !           457:                return (file_cmp ((struct file_syntax *)x->av_struct,(struct file_syntax *)y->av_struct));
        !           458: 
        !           459:        if (syntax_table[x->av_syntax].s_compare != NULLIFP) 
        !           460:                return ((*syntax_table[x->av_syntax].s_compare) (x->av_struct,y->av_struct));
        !           461:        else 
        !           462:                return (2); /* can't compare */
        !           463: }
        !           464: 
        !           465: IFP av_cmp_fn (syntax)
        !           466: int syntax;
        !           467: {
        !           468:        if ( syntax >= AV_WRITE_FILE )
        !           469:                return NULLIFP;
        !           470: 
        !           471:        if (syntax == AV_FILE)
        !           472:                return (file_cmp);
        !           473: 
        !           474:        if (syntax_table[syntax].s_compare != NULLIFP) 
        !           475:                return (syntax_table[syntax].s_compare);
        !           476:        else
        !           477:                return NULLIFP;
        !           478: }
        !           479: 
        !           480: AttrV_print (ps,x,format)
        !           481: register PS ps;
        !           482: register AttributeValue x;
        !           483: register int format;
        !           484: {
        !           485: extern int ps_printf ();
        !           486: 
        !           487:        if (format == RDNOUT)
        !           488:            format = READOUT;
        !           489: 
        !           490:        if (x->av_syntax == AV_FILE) 
        !           491:                fileattr_print (ps,x,format);
        !           492:        else if ((format == READOUT) && (syntax_table[x->av_syntax].s_pe_print != NULLCP))
        !           493:                exec_print (ps,x,syntax_table[x->av_syntax].s_pe_print);
        !           494:        else if (syntax_table[x->av_syntax].s_print != NULLIFP) {
        !           495:                if (x->av_struct != NULL)
        !           496:                        (*syntax_table[x->av_syntax].s_print) (ps,x->av_struct,format);
        !           497:        } else if (format == READOUT) {
        !           498:                 vpushquipu (ps);
        !           499:                 vunknown ((PE)x->av_struct);
        !           500:                 vpopquipu ();
        !           501:        } else 
        !           502:                pe_print (ps,(PE)x->av_struct,format);
        !           503: 
        !           504: }

unix.superglobalmegacorp.com

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