~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to snmplib/parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Jochen Friedrich
  • Date: 2010-06-10 18:02:54 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100610180254-6ezvupl2clicwdqf
ImportĀ upstreamĀ versionĀ 5.4.3~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
528
528
 
529
529
static int      current_module = 0;
530
530
static int      max_module = 0;
 
531
static int      first_err_module = 1;
531
532
static char    *last_err_module = 0;    /* no repeats on "Cannot find module..." */
532
533
 
533
534
static void     tree_from_node(struct tree *tp, struct node *np);
774
775
static void
775
776
print_module_not_found(const char *cp)
776
777
{
 
778
    if (first_err_module) {
 
779
        snmp_log(LOG_ERR, "MIB search path: %s\n",
 
780
                           netsnmp_get_mib_directory());
 
781
        first_err_module = 0;
 
782
    }
777
783
    if (!last_err_module || strcmp(cp, last_err_module))
778
784
        print_error("Cannot find module", cp, CONTINUE);
779
785
    if (last_err_module)
912
918
    free((char *) np);
913
919
}
914
920
 
 
921
static void
 
922
print_range_value(FILE * fp, int type, struct range_list * rp)
 
923
{
 
924
    switch (type) {
 
925
    case TYPE_INTEGER:
 
926
    case TYPE_INTEGER32:
 
927
        if (rp->low == rp->high)
 
928
            fprintf(fp, "%d", rp->low);
 
929
        else
 
930
            fprintf(fp, "%d..%d", rp->low, rp->high);
 
931
        break;
 
932
    case TYPE_UNSIGNED32:
 
933
    case TYPE_OCTETSTR:
 
934
    case TYPE_GAUGE:
 
935
    case TYPE_UINTEGER:
 
936
        if (rp->low == rp->high)
 
937
            fprintf(fp, "%u", (unsigned)rp->low);
 
938
        else
 
939
            fprintf(fp, "%u..%u", (unsigned)rp->low, (unsigned)rp->high);
 
940
        break;
 
941
    default:
 
942
        /* No other range types allowed */
 
943
        break;
 
944
    }
 
945
}
 
946
 
915
947
#ifdef TEST
916
948
static void
917
949
print_nodes(FILE * fp, struct node *root)
935
967
            }
936
968
        }
937
969
        if (np->ranges) {
938
 
            fprintf(fp, "  Ranges: \n");
 
970
            fprintf(fp, "  Ranges: ");
939
971
            for (rp = np->ranges; rp; rp = rp->next) {
940
 
                fprintf(fp, "    %d..%d\n", rp->low, rp->high);
 
972
                fprintf(fp, "\n    ");
 
973
                print_range_value(fp, np->type, rp);
941
974
            }
 
975
            fprintf(fp, "\n");
942
976
        }
943
977
        if (np->indexes) {
944
978
            fprintf(fp, "  Indexes: \n");
2169
2203
            nexttype = get_token(fp, nexttoken, MAXTOKEN);
2170
2204
        else
2171
2205
            taken = 0;
2172
 
        high = low = strtol(nexttoken, NULL, 10);
 
2206
        high = low = strtoul(nexttoken, NULL, 10);
2173
2207
        nexttype = get_token(fp, nexttoken, MAXTOKEN);
2174
2208
        if (nexttype == RANGE) {
2175
2209
            nexttype = get_token(fp, nexttoken, MAXTOKEN);
2176
2210
            errno = 0;
2177
 
            high = strtol(nexttoken, NULL, 10);
 
2211
            high = strtoul(nexttoken, NULL, 10);
2178
2212
            if ( errno == ERANGE ) {
2179
2213
                if (netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, 
2180
2214
                                       NETSNMP_DS_LIB_MIB_WARNINGS))
2937
2971
    strcpy(np->parent, np->next->parent);
2938
2972
    strcat(np->parent, "#");
2939
2973
    np->next->label = strdup(np->parent);
 
2974
    np->type = TRAPTYPE;
2940
2975
    return np;
2941
2976
}
2942
2977
 
2952
2987
    struct node    *np = alloc_node(current_module);
2953
2988
    char            nexttoken[MAXTOKEN];
2954
2989
 
 
2990
    if (!np)
 
2991
        return 0;
 
2992
 
2955
2993
    type = get_token(fp, token, maxtoken);
2956
2994
    nexttype = get_token(fp, nexttoken, MAXTOKEN);
2957
2995
    switch (type) {
4191
4229
parse(FILE * fp, struct node *root)
4192
4230
{
4193
4231
    char            token[MAXTOKEN];
4194
 
    char            name[MAXTOKEN];
 
4232
    char            name[MAXTOKEN+1];
4195
4233
    int             type = LABEL;
4196
4234
    int             lasttype = LABEL;
4197
4235
 
4283
4321
        case ENDOFFILE:
4284
4322
            continue;
4285
4323
        default:
4286
 
            strcpy(name, token);
 
4324
            strncpy(name, token, sizeof(name));
 
4325
            name[sizeof(name)-1] = '\0';
4287
4326
            type = get_token(fp, token, MAXTOKEN);
4288
4327
            nnp = NULL;
4289
4328
            if (type == MACRO) {
4300
4339
                print_error(name, "is a reserved word", lasttype);
4301
4340
            continue;           /* see if we can parse the rest of the file */
4302
4341
        }
4303
 
        strcpy(name, token);
 
4342
        strncpy(name, token, sizeof(name));
 
4343
        name[sizeof(name)-1] = '\0';
4304
4344
        type = get_token(fp, token, MAXTOKEN);
4305
4345
        nnp = NULL;
4306
4346
 
5332
5372
            while (rp) {
5333
5373
                if (rp != tp->ranges)
5334
5374
                    fprintf(f, " | ");
5335
 
                if (rp->low == rp->high)
5336
 
                    fprintf(f, "%d", rp->low);
5337
 
                else
5338
 
                    fprintf(f, "%d..%d", rp->low, rp->high);
 
5375
                print_range_value(f, tp->type, rp);
5339
5376
                rp = rp->next;
5340
5377
            }
5341
5378
            fprintf(f, "\n");