Annotation of 43BSDReno/contrib/isode-beta/snmp/values.c, revision 1.1.1.1

1.1       root        1: /* values.c - encode values */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/snmp/RCS/values.c,v 7.3 90/07/09 14:49:51 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/snmp/RCS/values.c,v 7.3 90/07/09 14:49:51 mrose Exp $
                      9:  *
                     10:  * Contributed by NYSERNet Inc.  This work was partially supported by the
                     11:  * U.S. Defense Advanced Research Projects Agency and the Rome Air Development
                     12:  * Center of the U.S. Air Force Systems Command under contract number
                     13:  * F30602-88-C-0016.
                     14:  *
                     15:  *
                     16:  * $Log:       values.c,v $
                     17:  * Revision 7.3  90/07/09  14:49:51  mrose
                     18:  * sync
                     19:  * 
                     20:  * Revision 7.2  90/04/18  08:52:12  mrose
                     21:  * oid_normalize
                     22:  * 
                     23:  * Revision 7.1  90/02/19  15:39:11  mrose
                     24:  * one more time
                     25:  * 
                     26:  * Revision 7.0  90/02/17  10:36:50  mrose
                     27:  * *** empty log message ***
                     28:  * 
                     29:  */
                     30: 
                     31: /*
                     32:  *                               NOTICE
                     33:  *
                     34:  *    Acquisition, use, and distribution of this module and related
                     35:  *    materials are subject to the restrictions of a license agreement.
                     36:  *    Consult the Preface in the User's Manual for the full terms of
                     37:  *    this agreement.
                     38:  *
                     39:  */
                     40: 
                     41: 
                     42: #include <stdio.h>
                     43: #include "SNMP-types.h"
                     44: #include "objects.h"
                     45: #include "logger.h"
                     46:            
                     47: /*  */
                     48: 
                     49: #define        ADVISE  if (o_advise) (*o_advise)
                     50: 
                     51: IFP    o_advise = NULLIFP;
                     52: 
                     53: /*  */
                     54: 
                     55: int    o_generic (oi, v, offset)
                     56: OI     oi;
                     57: register struct type_SNMP_VarBind *v;
                     58: int    offset;
                     59: {
                     60:     register OID    oid = oi -> oi_name;
                     61:     register OT            ot = oi -> oi_type;
                     62:     register OS            os = ot -> ot_syntax;
                     63: 
                     64:     switch (offset) {
                     65:        case type_SNMP_PDUs_get__request:
                     66:            if (oid -> oid_nelem != ot -> ot_name -> oid_nelem + 1
                     67:                    || oid -> oid_elements[oid -> oid_nelem - 1] != 0)
                     68:                return int_SNMP_error__status_noSuchName;
                     69:            break;
                     70: 
                     71:        case type_SNMP_PDUs_get__next__request:
                     72:            if (oid -> oid_nelem == ot -> ot_name -> oid_nelem) {
                     73:                OID     new;
                     74: 
                     75:                if ((new = oid_extend (oid, 1)) == NULLOID)
                     76:                    return int_SNMP_error__status_genErr;
                     77:                new -> oid_elements[new -> oid_nelem - 1] = 0;
                     78: 
                     79:                if (v -> name)
                     80:                    free_SNMP_ObjectName (v -> name);
                     81:                v -> name = new;
                     82:            }
                     83:            else
                     84:                return NOTOK;
                     85:            break;
                     86: 
                     87:        default:
                     88:            return int_SNMP_error__status_genErr;
                     89:     }
                     90:        
                     91:     if (os == NULLOS) {
                     92:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                     93:                "no syntax defined for object \"%s\"", ot -> ot_text);
                     94: 
                     95:        return (offset == type_SNMP_PDUs_get__next__request ? NOTOK
                     96:                : int_SNMP_error__status_genErr);
                     97:     }
                     98:     if (ot -> ot_info == NULL) {
                     99:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    100:                "no value defined for object \"%s\"", ot -> ot_text);
                    101: 
                    102:        return (offset == type_SNMP_PDUs_get__next__request ? NOTOK
                    103:                : int_SNMP_error__status_noSuchName);
                    104:     }
                    105: 
                    106:     if (v -> value)
                    107:        free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
                    108:     if ((*os -> os_encode) (ot -> ot_info, &v -> value) == NOTOK) {
                    109:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    110:                "encoding error for variable \"%s\"",
                    111:                oid2ode (oi -> oi_name));
                    112: 
                    113:        return int_SNMP_error__status_genErr;
                    114:     }
                    115: 
                    116:     return int_SNMP_error__status_noError;
                    117: }
                    118:            
                    119: /*  */
                    120: 
                    121: int    o_number (oi, v, number)
                    122: OI     oi;
                    123: register struct type_SNMP_VarBind *v;
                    124: integer        number;
                    125: {
                    126:     int            result;
                    127:     register OT            ot = oi -> oi_type;
                    128:     register OS            os = ot -> ot_syntax;
                    129: 
                    130:     if (os == NULLOS) {
                    131:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    132:                "no syntax defined for object \"%s\"", ot -> ot_text);
                    133: 
                    134:        return int_SNMP_error__status_genErr;
                    135:     }
                    136: 
                    137:     if (v -> value)
                    138:        free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
                    139:     result = (*os -> os_encode) (&number, &v -> value);
                    140: 
                    141:     if (result == NOTOK) {
                    142:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    143:                "encoding error for variable \"%s\"",
                    144:                oid2ode (oi -> oi_name));
                    145: 
                    146:        return int_SNMP_error__status_genErr;
                    147:     }
                    148: 
                    149:     return int_SNMP_error__status_noError;
                    150: }
                    151:            
                    152: /*  */
                    153: 
                    154: int    o_string (oi, v, base, len)
                    155: OI     oi;
                    156: register struct type_SNMP_VarBind *v;
                    157: char   *base;
                    158: int    len;
                    159: {
                    160:     int            result;
                    161:     struct qbuf *value;
                    162:     register OT            ot = oi -> oi_type;
                    163:     register OS            os = ot -> ot_syntax;
                    164: 
                    165:     if (os == NULLOS) {
                    166:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    167:                "no syntax defined for object \"%s\"", ot -> ot_text);
                    168: 
                    169:        return int_SNMP_error__status_genErr;
                    170:     }
                    171: 
                    172:     if ((value = str2qb (base, len, 1)) == NULL) {
                    173:        ADVISE (LLOG_EXCEPTIONS, NULLCP, "out of memory");
                    174:        return int_SNMP_error__status_genErr;
                    175:     }
                    176: 
                    177:     if (v -> value)
                    178:        free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
                    179:     result = (*os -> os_encode) (value, &v -> value);
                    180:     qb_free (value);
                    181: 
                    182:     if (result == NOTOK) {
                    183:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    184:                "encoding error for variable \"%s\"",
                    185:                oid2ode (oi -> oi_name));
                    186: 
                    187:        return int_SNMP_error__status_genErr;
                    188:     }
                    189: 
                    190:     return int_SNMP_error__status_noError;
                    191: }
                    192: 
                    193: /*  */
                    194: 
                    195: int    o_qbstring (oi, v, value)
                    196: OI     oi;
                    197: register struct type_SNMP_VarBind *v;
                    198: struct qbuf *value;
                    199: {
                    200:     int            result;
                    201:     register OT            ot = oi -> oi_type;
                    202:     register OS            os = ot -> ot_syntax;
                    203: 
                    204:     if (os == NULLOS) {
                    205:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    206:                "no syntax defined for object \"%s\"", ot -> ot_text);
                    207: 
                    208:        return int_SNMP_error__status_genErr;
                    209:     }
                    210: 
                    211:     if (v -> value)
                    212:        free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
                    213:     result = (*os -> os_encode) (value, &v -> value);
                    214: 
                    215:     if (result == NOTOK) {
                    216:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    217:                "encoding error for variable \"%s\"",
                    218:                oid2ode (oi -> oi_name));
                    219: 
                    220:        return int_SNMP_error__status_genErr;
                    221:     }
                    222: 
                    223:     return int_SNMP_error__status_noError;
                    224: }
                    225: 
                    226: /*  */
                    227: 
                    228: int    o_specific (oi, v, value)
                    229: OI     oi;
                    230: register struct type_SNMP_VarBind *v;
                    231: caddr_t        value;
                    232: {
                    233:     int            result;
                    234:     register OT            ot = oi -> oi_type;
                    235:     register OS            os = ot -> ot_syntax;
                    236: 
                    237:     if (os == NULLOS) {
                    238:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    239:                "no syntax defined for object \"%s\"", ot -> ot_text);
                    240: 
                    241:        return int_SNMP_error__status_genErr;
                    242:     }
                    243: 
                    244:     if (v -> value)
                    245:        free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
                    246:     result = (*os -> os_encode) (value, &v -> value);
                    247: 
                    248:     if (result == NOTOK) {
                    249:        ADVISE (LLOG_EXCEPTIONS, NULLCP,
                    250:                "encoding error for variable \"%s\"",
                    251:                oid2ode (oi -> oi_name));
                    252: 
                    253:        return int_SNMP_error__status_genErr;
                    254:     }
                    255: 
                    256:     return int_SNMP_error__status_noError;
                    257: }
                    258: 
                    259: /*  */
                    260: 
                    261: int    mediaddr2oid (ip, addr, len, islen)
                    262: register unsigned int *ip;
                    263: register u_char *addr;
                    264: int    len,
                    265:        islen;
                    266: {
                    267:     register int   i;
                    268: 
                    269:     if (islen)
                    270:        *ip++ = len & 0xff;
                    271: 
                    272:     for (i = len; i > 0; i--)
                    273:        *ip++ = *addr++ & 0xff;
                    274: 
                    275:     return (len + (islen ? 1 : 0));
                    276: }
                    277: 
                    278: /*  */
                    279: 
                    280: OID    oid_extend (q, howmuch)
                    281: register OID   q;
                    282: int    howmuch;
                    283: {
                    284:     register unsigned int   i,
                    285:                           *ip,
                    286:                           *jp;
                    287:     OID            oid;
                    288: 
                    289:     if (q == NULLOID)
                    290:        return NULLOID;
                    291:     if ((i = q -> oid_nelem) < 1)
                    292:        return NULLOID;
                    293:     if ((oid = (OID) malloc (sizeof *oid)) == NULLOID)
                    294:        return NULLOID;
                    295: 
                    296:     if ((ip = (unsigned int *)
                    297:                    calloc ((unsigned) (i + howmuch + 1), sizeof *ip))
                    298:                == NULL) {
                    299:        free ((char *) oid);
                    300:        return NULLOID;
                    301:     }
                    302: 
                    303:     oid -> oid_elements = ip, oid -> oid_nelem = i + howmuch;
                    304: 
                    305:     for (i = 0, jp = q -> oid_elements; i < oid -> oid_nelem; i++, jp++)
                    306:        *ip++ = *jp;
                    307: 
                    308:     return oid;
                    309: }
                    310: 
                    311: /*  */
                    312: 
                    313: OID    oid_normalize (q, howmuch, bigvalue)
                    314: register OID   q;
                    315: int    howmuch,
                    316:        bigvalue;
                    317: {
                    318:     register int       i;
                    319:     register unsigned int   *ip,
                    320:                            *jp;
                    321:     OID            oid;
                    322: 
                    323:     if ((oid = oid_extend (q, howmuch)) == NULL)
                    324:        return NULLOID;
                    325: 
                    326:     for (jp = (ip = oid -> oid_elements + q -> oid_nelem) - 1;
                    327:             jp >= oid -> oid_elements;
                    328:             jp--)
                    329:        if (*jp > 0) {
                    330:            *jp -= 1;
                    331:            break;
                    332:        }
                    333:     for (i = howmuch; i > 0; i--)
                    334:        *ip++ = (unsigned int) bigvalue;
                    335: 
                    336:     return oid;
                    337: }

unix.superglobalmegacorp.com

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