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

1.1     ! root        1: /* string.c - printable string handling */
        !             2: 
        !             3: #ifndef lint
        !             4:  static char *rcsid = "$Header: /f/osi/dsap/common/RCS/string.c,v 7.3 90/07/09 14:35:09 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /*
        !             8:  * $Header: /f/osi/dsap/common/RCS/string.c,v 7.3 90/07/09 14:35:09 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       string.c,v $
        !            12:  * Revision 7.3  90/07/09  14:35:09  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.2  90/04/18  08:50:09  mrose
        !            16:  * 6.2
        !            17:  * 
        !            18:  * Revision 7.1  89/12/19  16:19:33  mrose
        !            19:  * sync
        !            20:  * 
        !            21:  * Revision 7.0  89/11/23  21:44:33  mrose
        !            22:  * Release 6.0
        !            23:  * 
        !            24:  */
        !            25: 
        !            26: /*
        !            27:  *                                NOTICE
        !            28:  *
        !            29:  *    Acquisition, use, and distribution of this module and related
        !            30:  *    materials are subject to the restrictions of a license agreement.
        !            31:  *    Consult the Preface in the User's Manual for the full terms of
        !            32:  *    this agreement.
        !            33:  *
        !            34:  */
        !            35: 
        !            36: 
        !            37: /* LINTLIBRARY */
        !            38: 
        !            39: #include "quipu/util.h"
        !            40: #include "quipu/ds_search.h"
        !            41: 
        !            42: extern LLog * log_dsap;
        !            43: extern char  * TidyString2();
        !            44: 
        !            45: #define T61_MARK '$'
        !            46: 
        !            47: static short exct = 0;
        !            48: static char char_failed;
        !            49: soundex_match ();
        !            50: 
        !            51: static PE ia5enc (x)
        !            52: char *x;
        !            53: {
        !            54:        return (ia5s2prim(x,strlen(x)));
        !            55: }
        !            56: 
        !            57: static PE nstrenc (x)
        !            58: char *x;
        !            59: {
        !            60:        return (nums2prim(x,strlen(x)));
        !            61: }
        !            62: 
        !            63: 
        !            64: static PE octenc (x)
        !            65: char *x;
        !            66: {
        !            67:        return (oct2prim(x,strlen(x)));
        !            68: }
        !            69: 
        !            70: static PE strenc (x)
        !            71: char *x;
        !            72: {
        !            73:        if (*x == T61_MARK) {
        !            74:                x++;
        !            75:                return (t61s2prim(x,strlen(x)));
        !            76:        } else
        !            77:                return (prts2prim(x,strlen(x)));
        !            78: }
        !            79: 
        !            80: static char * local_t61 (a)
        !            81: char * a;
        !            82: {
        !            83: char * b;
        !            84: 
        !            85:        if (a == NULLCP)
        !            86:                return (NULLCP);
        !            87: 
        !            88:        b = smalloc (strlen(a) +2);
        !            89:        *b++ = T61_MARK;
        !            90:        (void) strcpy (b,a);
        !            91:        (void) free (a);
        !            92:        return (--b);
        !            93: }
        !            94: 
        !            95: static char * prtsdec (pe)
        !            96: PE pe;
        !            97: {
        !            98: int z;
        !            99: 
        !           100:        if (test_prim_pe (pe,PE_CLASS_UNIV,PE_DEFN_PRTS))
        !           101:                return (TidyString2(prim2str(pe,&z)));
        !           102:        else
        !           103:                return (NULLCP);
        !           104: }
        !           105: 
        !           106: static char * cntydec (pe)
        !           107: PE pe;
        !           108: {
        !           109: char *a;
        !           110: 
        !           111:        if ((a = prtsdec(pe)) == NULLCP)
        !           112:                return (NULLCP);
        !           113: 
        !           114:        if (strlen (a) != 2) {
        !           115:                LLOG (log_dsap,LLOG_EXCEPTIONS, ("Country code size wrong"));
        !           116:                return (NULLCP);
        !           117:        }
        !           118:        return (a);
        !           119: 
        !           120: }
        !           121: 
        !           122: static char * octsdec (pe)
        !           123: PE pe;
        !           124: {
        !           125: int z;
        !           126: 
        !           127:        if (test_prim_pe (pe,PE_CLASS_UNIV,PE_PRIM_OCTS))
        !           128:                return (TidyString2(prim2str(pe,&z)));
        !           129:        else
        !           130:                return (NULLCP);
        !           131: 
        !           132: }
        !           133: 
        !           134: static char * ia5sdec (pe)
        !           135: PE pe;
        !           136: {
        !           137: int z;
        !           138: 
        !           139:        if (test_prim_pe (pe,PE_CLASS_UNIV,PE_DEFN_IA5S))
        !           140:                return (TidyString2(prim2str(pe,&z)));
        !           141:        else
        !           142:                return (NULLCP);
        !           143: }
        !           144: 
        !           145: static char * numsdec (pe)
        !           146: PE pe;
        !           147: {
        !           148: int z;
        !           149:        if (test_prim_pe (pe,PE_CLASS_UNIV,PE_DEFN_NUMS))
        !           150:                return (TidyString2(prim2str(pe,&z)));
        !           151:        else
        !           152:                return (NULLCP);
        !           153: }
        !           154: 
        !           155: 
        !           156: static char * t61dec (pe)
        !           157: PE pe;
        !           158: {
        !           159: int z;
        !           160: 
        !           161:        if (pe->pe_form != PE_FORM_PRIM) {
        !           162:                LLOG (log_dsap,LLOG_EXCEPTIONS,("Primative string expected"));
        !           163:                return NULLCP;
        !           164:        }
        !           165: 
        !           166:        if ( PE_ID (pe -> pe_class, pe -> pe_id) == PE_ID (PE_CLASS_UNIV,PE_DEFN_T61S) ) 
        !           167:                return (local_t61 (TidyString2(prim2str(pe,&z))));
        !           168:        else 
        !           169:                return (prtsdec(pe));
        !           170: }
        !           171: 
        !           172: static char * quotechar (a,b)
        !           173: char a, *b;
        !           174: {
        !           175:        (void) sprintf (b,"\\%02x", a & 0xff);
        !           176:        b += 3;
        !           177:        return (b);
        !           178: }
        !           179: 
        !           180: static char * unquotechar (a,b)
        !           181: char *a, *b;
        !           182: {
        !           183: int val;
        !           184: 
        !           185:        if (*a == '\\') 
        !           186:                *b = '\\';
        !           187:        else {
        !           188:                (void) sscanf (a,"%2x", &val);
        !           189:                *b = val & 0xff;
        !           190:                a++;
        !           191:        }
        !           192:        return (a);
        !           193: }
        !           194: 
        !           195: 
        !           196: static check_print_string (str)
        !           197: char * str;
        !           198: {
        !           199: 
        !           200:     for (; *str != 0; str++) {
        !           201:        if (isalnum (*str))
        !           202:                continue;
        !           203: 
        !           204:        switch (*str) {
        !           205:                case 047:  /* ' */
        !           206:                case '(':
        !           207:                case ')':
        !           208:                case '+':
        !           209:                case '-':
        !           210:                case '.':
        !           211:                case ',':
        !           212:                case '/':
        !           213:                case ':':
        !           214:                case '=':
        !           215:                case '?':
        !           216:                case ' ': continue;
        !           217:                default:  LLOG (log_dsap,LLOG_NOTICE,("character '%c' not in printablestring",*str));
        !           218:                          char_failed = *str;
        !           219:                          return (0);
        !           220:        }
        !           221:     }
        !           222:     return (1);
        !           223: }
        !           224: 
        !           225: 
        !           226: char * octparse (str)
        !           227: char * str;
        !           228: {
        !           229: char buffer [BUFSIZ];
        !           230: register char * ptr=buffer;
        !           231: 
        !           232:         for (; *str != 0; str++)
        !           233:                 if (*str != '\\')
        !           234:                         *ptr++ = *str;
        !           235:                 else {
        !           236:                        str++;
        !           237:                         str = unquotechar (str,ptr);
        !           238:                        ptr++;
        !           239:                }
        !           240:        *ptr = 0;
        !           241:        return (strdup(buffer));
        !           242: }
        !           243: 
        !           244: static char * prtparse_aux (str)
        !           245: char * str;
        !           246: {
        !           247:        if (check_print_string (str))
        !           248:                return (strdup (str));
        !           249:        else 
        !           250:                return (NULLCP);
        !           251: }
        !           252: 
        !           253: char * prtparse (str)
        !           254: char * str;
        !           255: {
        !           256: char * ptr;
        !           257: 
        !           258:        if ((ptr = prtparse_aux(str)) != NULLCP)
        !           259:                return (ptr);
        !           260:        else {
        !           261:                parse_error ("character '%c' not in printablestring",(char *)char_failed);
        !           262:                return (NULLCP);
        !           263:        }
        !           264: }
        !           265: 
        !           266: static char * cntyparse(str)
        !           267: char * str;
        !           268: {
        !           269: char * a;
        !           270: 
        !           271:        if ((a=prtparse(str)) == NULLCP)
        !           272:                return (NULLCP);
        !           273: 
        !           274:        if (strlen (a) != 2) {
        !           275:                parse_error ("country code size wrong",NULLCP); 
        !           276:                return (NULLCP);
        !           277:        }
        !           278: 
        !           279:        return (a);
        !           280: }
        !           281: 
        !           282: static char * t61parse (str)
        !           283: char * str;
        !           284: {
        !           285: extern char t61_flag;
        !           286: char * octparse ();
        !           287: char * res;
        !           288: 
        !           289:        if (t61_flag) {
        !           290:                t61_flag = FALSE;  /* recognised it !!! */
        !           291:                return (local_t61(octparse (str)));   /* need t61 parser */
        !           292:        } else if ((res=prtparse_aux(str)) == NULLCP) {
        !           293:                LLOG (log_dsap,LLOG_NOTICE,("auto-convert to T.61 for '%s' ('%c' not allowed)",str,char_failed));
        !           294:                return (local_t61(octparse (str)));
        !           295:        } else
        !           296:                return (res);
        !           297: }
        !           298: 
        !           299: char * cryptstring (str)
        !           300: char * str;
        !           301: {
        !           302: register char * p;
        !           303:        /* This is a SIMPLE HACK to prevent passwords being revealed */
        !           304:        /* at a glance.  It buys virtually no extra security */
        !           305: 
        !           306: #define CRYPT_MASK 0x23        /* could tailor this */
        !           307: 
        !           308:        for (p=str; *p != 0; p++)
        !           309:                if (*p != CRYPT_MASK)
        !           310:                        *p ^= CRYPT_MASK; 
        !           311: 
        !           312:        return (str);
        !           313: }
        !           314: 
        !           315: char * cryptparse (str)
        !           316: char * str;
        !           317: {
        !           318: extern char crypt_flag;
        !           319: char * octparse ();
        !           320: 
        !           321:        if (crypt_flag) {
        !           322:                crypt_flag = FALSE;  /* recognised it !!! */
        !           323:                return (cryptstring(octparse (str)));   
        !           324:        } else 
        !           325:                return (octparse (str));
        !           326: }
        !           327: 
        !           328: sfree (x)
        !           329: char *x;
        !           330: {
        !           331:        free (x);
        !           332: }
        !           333: 
        !           334: pstrcmp (a,b)
        !           335: char * a, *b;
        !           336: {
        !           337: int c;
        !           338:        if ((c= strcmp (a,b)) == 0)
        !           339:                return (0);
        !           340: 
        !           341:        if ( c > 0)
        !           342:                return (1);
        !           343:        else
        !           344:                return (-1);
        !           345: }
        !           346: 
        !           347: passwdcmp (a,b)
        !           348: char * a, *b;
        !           349: {
        !           350:        if (strcmp (a,b) == 0)
        !           351:                return (0);
        !           352:        else
        !           353:                return (2);
        !           354: 
        !           355: }
        !           356: 
        !           357: telcmp (a, b)
        !           358: char   *a,
        !           359:        *b;
        !           360: {
        !           361:     register char c1,
        !           362:                  c2;
        !           363: 
        !           364:     if (a == NULL)
        !           365:        return (b ? -1 : 0);
        !           366:     else
        !           367:        if (b == NULL)
        !           368:            return 1;
        !           369: 
        !           370:     for (;;) {
        !           371:        while (c1 = *a++)
        !           372:            if (c1 != ' ' && c1 != '-')
        !           373:                break;
        !           374: 
        !           375:        while (c2 = *b++)
        !           376:            if (c2 != ' ' && c2 != '-')
        !           377:                break;
        !           378: 
        !           379:        if (c1 == NULL)
        !           380:            return (c2 ? -1 : 0);
        !           381:        else
        !           382:            if (c2 == NULL)
        !           383:                return 1;
        !           384: 
        !           385:        if (c1 > c2)
        !           386:            return 1;
        !           387:        else
        !           388:            if (c1 < c2)
        !           389:                return -1;
        !           390:     }
        !           391: }
        !           392: 
        !           393: strprint (ps,str,format)
        !           394: PS ps;
        !           395: char * str;
        !           396: int format;
        !           397: {
        !           398:        if (*str == T61_MARK) {
        !           399:                if (format != READOUT)
        !           400:                        ps_print (ps,"{T.61}");
        !           401:                octprint (ps,++str,format);
        !           402:        } else 
        !           403:                ps_print (ps,str);
        !           404: }
        !           405: 
        !           406: cryptprint (ps,str,format)
        !           407: PS ps;
        !           408: char * str;
        !           409: int format;
        !           410: {
        !           411: char * ptr;
        !           412: extern char allow_crypt;
        !           413: 
        !           414:        if (format == READOUT) 
        !           415:                ps_print (ps,"HIDDEN");
        !           416:        else {
        !           417:                if (! allow_crypt) {
        !           418:                        octprint (ps,str,format);
        !           419:                        return;
        !           420:                }
        !           421:                ps_print (ps,"{CRYPT}");
        !           422:                ptr = strdup (str);
        !           423:                octprint (ps,cryptstring(ptr),format);
        !           424:                free ((char *)ptr);
        !           425:        }
        !           426: }
        !           427: 
        !           428: /* ARGSUSED */
        !           429: octprint (ps,str,format)
        !           430: PS ps;
        !           431: char * str;
        !           432: int format;
        !           433: {
        !           434: char buffer [BUFSIZ];
        !           435: register char * ptr=buffer;
        !           436: 
        !           437:        for (; *str != 0; str++) {
        !           438:                if (isprint(*str)) {
        !           439:                        if (format != READOUT)
        !           440:                            switch (*str) {
        !           441:                                case '&': /* used as seperators */
        !           442:                                case '#':
        !           443:                                case '$':
        !           444:                                case '%':
        !           445:                                case '@':
        !           446:                                        ptr = quotechar (*str,ptr);
        !           447:                                        break;
        !           448:                                default:
        !           449:                                        *ptr++ = *str;
        !           450:                                        if (*str == '\\')
        !           451:                                                *ptr++ = *str;
        !           452:                            }
        !           453:                        else 
        !           454:                                *ptr++ = *str;
        !           455:                } else
        !           456:                        ptr = quotechar (*str,ptr);
        !           457:        }
        !           458:        *ptr = 0;
        !           459:        ps_print (ps,buffer);
        !           460: }
        !           461: 
        !           462: 
        !           463: case_exact_match (sntx) 
        !           464: short sntx;
        !           465: {
        !           466:        if ((sntx < exct) || (sntx > (exct + 2)))
        !           467:                return (FALSE);
        !           468:        else
        !           469:                return (TRUE);
        !           470: }
        !           471: 
        !           472: approx_string (sntx)
        !           473: short sntx;
        !           474: {
        !           475:        if ((sntx < exct) || (sntx > (exct + 7)))
        !           476:                return (FALSE);
        !           477:        else
        !           478:                return (TRUE);
        !           479: }
        !           480: 
        !           481: sub_string (sntx)
        !           482: short sntx;
        !           483: {
        !           484:        if ((sntx < exct) || (sntx > (exct + 9)))
        !           485:                return (FALSE);
        !           486:        else
        !           487:                return (TRUE);
        !           488: }
        !           489: 
        !           490: 
        !           491: string_syntaxes ()
        !           492: {
        !           493:        /* Don't change ordering here unless you know 
        !           494:           the side effects !!! */
        !           495: 
        !           496:        /* 1-3 Exact string */
        !           497:        /* 1-7 Approx       */
        !           498: 
        !           499:        exct = add_attribute_syntax ("caseexactstring",
        !           500:                (IFP) strenc,   (IFP) t61dec,
        !           501:                (IFP) t61parse, strprint,
        !           502:                (IFP) strdup,   pstrcmp,
        !           503:                sfree,          NULLCP,
        !           504:                soundex_match,  TRUE);
        !           505: 
        !           506:        (void) add_attribute_syntax ("TelephoneNumber",
        !           507:                (IFP) strenc,   (IFP) prtsdec,
        !           508:                (IFP) prtparse, strprint,
        !           509:                (IFP) strdup,   telcmp,
        !           510:                sfree,          NULLCP,
        !           511:                soundex_match,  TRUE);
        !           512: 
        !           513:        (void) add_attribute_syntax ("printablestring",
        !           514:                (IFP) strenc,   (IFP) prtsdec,
        !           515:                (IFP) prtparse, strprint,
        !           516:                (IFP) strdup,   pstrcmp,
        !           517:                sfree,          NULLCP,
        !           518:                soundex_match,  TRUE);
        !           519: 
        !           520:        (void) add_attribute_syntax ("ia5string",
        !           521:                (IFP) ia5enc,   (IFP) ia5sdec,
        !           522:                (IFP) octparse, octprint,
        !           523:                (IFP) strdup,   pstrcmp,
        !           524:                sfree,          NULLCP,
        !           525:                soundex_match,  TRUE);
        !           526: 
        !           527:        /* 5-8 ignore strings */
        !           528: 
        !           529:        (void) add_attribute_syntax ("countrystring",
        !           530:                (IFP) strenc,   (IFP) cntydec,
        !           531:                (IFP) cntyparse,strprint,
        !           532:                (IFP) strdup,   lexequ,
        !           533:                sfree,          NULLCP,
        !           534:                soundex_match,  TRUE);
        !           535: 
        !           536:        (void) add_attribute_syntax ("DestinationString",
        !           537:                (IFP) strenc,   (IFP) prtsdec,
        !           538:                (IFP) prtparse, strprint,
        !           539:                (IFP) strdup,   lexequ,
        !           540:                sfree,          NULLCP,
        !           541:                soundex_match,  TRUE);
        !           542: 
        !           543:        (void) add_attribute_syntax ("caseignorestring",
        !           544:                (IFP) strenc,   (IFP) t61dec,
        !           545:                (IFP) t61parse, strprint,
        !           546:                (IFP) strdup,   lexequ,
        !           547:                sfree,          NULLCP,
        !           548:                soundex_match,  TRUE);
        !           549: 
        !           550:        (void) add_attribute_syntax ("caseIgnoreIa5string",
        !           551:                (IFP) ia5enc,   (IFP) ia5sdec,
        !           552:                (IFP) octparse, octprint,
        !           553:                (IFP) strdup,   lexequ,
        !           554:                sfree,          NULLCP,
        !           555:                soundex_match,  TRUE);
        !           556: 
        !           557:        /* 1-10 -> substrings */
        !           558:        (void) add_attribute_syntax ("numericstring",
        !           559:                (IFP) nstrenc,  (IFP) numsdec,
        !           560:                (IFP) strdup,   strprint,
        !           561:                (IFP) strdup,   pstrcmp,
        !           562:                sfree,          NULLCP,
        !           563:                NULLIFP,        FALSE);
        !           564: 
        !           565:        (void) add_attribute_syntax ("octetstring",
        !           566:                (IFP) octenc,   (IFP) octsdec,
        !           567:                (IFP) octparse, octprint,
        !           568:                (IFP) strdup,   pstrcmp,
        !           569:                sfree,          NULLCP,
        !           570:                NULLIFP,        TRUE);
        !           571: 
        !           572:        (void) add_attribute_syntax ("password",
        !           573:                (IFP) octenc,   (IFP) octsdec,
        !           574:                (IFP) cryptparse,       cryptprint,
        !           575:                (IFP) strdup,   passwdcmp,
        !           576:                sfree,          NULLCP,
        !           577:                NULLIFP,        TRUE);
        !           578: }
        !           579: 

unix.superglobalmegacorp.com

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