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

« back to all changes in this revision

Viewing changes to perl/OID/OID.xs

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- C -*- */
 
2
#include "EXTERN.h"
 
3
#include "perl.h"
 
4
#include "XSUB.h"
 
5
 
 
6
#include <net-snmp/net-snmp-config.h>
 
7
#include <net-snmp/net-snmp-includes.h>
 
8
 
 
9
/* pulled from Dave's, yet-to-be-used, net-snmp library rewrite.
 
10
   autocompatibility for the future? */
 
11
 
 
12
typedef struct netsnmp_oid_s {
 
13
    oid                 *name;
 
14
    unsigned int         len;
 
15
    oid                  namebuf[ MAX_OID_LEN ];
 
16
} netsnmp_oid;
 
17
 
 
18
static int
 
19
not_here(char *s)
 
20
{
 
21
    croak("%s not implemented on this architecture", s);
 
22
    return -1;
 
23
}
 
24
 
 
25
static double
 
26
constant(char *name, int len, int arg)
 
27
{
 
28
    errno = EINVAL;
 
29
    return 0;
 
30
}
 
31
 
 
32
netsnmp_oid *
 
33
nso_newarrayptr(oid *name, size_t name_len) 
 
34
{
 
35
    netsnmp_oid *RETVAL;
 
36
    RETVAL = SNMP_MALLOC_TYPEDEF(netsnmp_oid);
 
37
    RETVAL->name = RETVAL->namebuf;
 
38
    RETVAL->len = name_len;
 
39
    memcpy(RETVAL->name, name, name_len * sizeof(oid));
 
40
    return RETVAL;
 
41
}
 
42
 
 
43
MODULE = NetSNMP::OID           PACKAGE = NetSNMP::OID          PREFIX=nso_
 
44
 
 
45
netsnmp_oid *
 
46
nso_newptr(initstring)
 
47
    char *initstring
 
48
    CODE:
 
49
        RETVAL = SNMP_MALLOC_TYPEDEF(netsnmp_oid);
 
50
        RETVAL->name = RETVAL->namebuf;
 
51
        RETVAL->len = sizeof(RETVAL->namebuf)/sizeof(RETVAL->namebuf[0]);
 
52
        if (!snmp_parse_oid(initstring, (oid *) RETVAL->name, &RETVAL->len)) {
 
53
            snmp_log(LOG_ERR, "Can't parse: %s\n", initstring);
 
54
            RETVAL->len = 0;
 
55
            RETVAL = NULL;
 
56
        }
 
57
    OUTPUT:
 
58
        RETVAL
 
59
 
 
60
double
 
61
constant(sv,arg)
 
62
    PREINIT:
 
63
        STRLEN          len;
 
64
    INPUT:
 
65
        SV *            sv
 
66
        char *          s = SvPV(sv, len);
 
67
        int             arg
 
68
    CODE:
 
69
        RETVAL = constant(s,len,arg);
 
70
    OUTPUT:
 
71
        RETVAL
 
72
 
 
73
int
 
74
_snmp_oid_compare(oid1, oid2)
 
75
    netsnmp_oid *oid1;
 
76
    netsnmp_oid *oid2;
 
77
    CODE:
 
78
        RETVAL = snmp_oid_compare((oid *) oid1->name, oid1->len,
 
79
                                  (oid *) oid2->name, oid2->len);
 
80
    OUTPUT:
 
81
        RETVAL
 
82
 
 
83
MODULE = NetSNMP::OID  PACKAGE = netsnmp_oidPtr  PREFIX = nsop_
 
84
 
 
85
void
 
86
nsop_DESTROY(oid1)
 
87
        netsnmp_oid *oid1
 
88
    CODE:
 
89
        free(oid1);
 
90
        
 
91
char *
 
92
nsop_to_string(oid1)
 
93
        netsnmp_oid *oid1
 
94
    PREINIT:
 
95
        static char mystr[SNMP_MAXBUF];
 
96
    CODE:
 
97
        {
 
98
            if (oid1->len == 0)
 
99
                snprintf(mystr, sizeof(mystr), "Illegal OID");
 
100
            else
 
101
                snprint_objid(mystr, sizeof(mystr),
 
102
                              (oid *) oid1->name, oid1->len);
 
103
            RETVAL = mystr;
 
104
        }
 
105
                
 
106
    OUTPUT:
 
107
        RETVAL
 
108
 
 
109
void
 
110
nsop_to_array(oid1)
 
111
    netsnmp_oid *oid1;
 
112
    PREINIT:
 
113
        int i;
 
114
 
 
115
    PPCODE:
 
116
        EXTEND(SP, oid1->len);
 
117
        for(i=0; i < oid1->len; i++) {
 
118
            PUSHs(sv_2mortal(newSVnv(oid1->name[i])));
 
119
        }
 
120
 
 
121
void
 
122
nsop_append(oid1, string)
 
123
    netsnmp_oid *oid1;
 
124
    char *string;
 
125
    PREINIT:
 
126
    oid name[MAX_OID_LEN];
 
127
    size_t name_len = MAX_OID_LEN;
 
128
    int i;
 
129
    CODE: 
 
130
    {
 
131
        if (!snmp_parse_oid(string, (oid *) name, &name_len)) {
 
132
            /* XXX */
 
133
        }
 
134
        if (oid1->len + name_len > MAX_OID_LEN) {
 
135
            /* XXX: illegal */
 
136
        }
 
137
        for(i = 0; i < (int)name_len; i++) {
 
138
            oid1->name[i+oid1->len] = name[i];
 
139
        }
 
140
        oid1->len += name_len;
 
141
    }
 
142
 
 
143
void
 
144
nsop_append_oid(oid1, oid2)
 
145
    netsnmp_oid *oid1;
 
146
    netsnmp_oid *oid2;
 
147
    PREINIT:
 
148
    int i;
 
149
    CODE: 
 
150
    {
 
151
        if (oid1->len + oid2->len > MAX_OID_LEN) {
 
152
            /* XXX: illegal */
 
153
        }
 
154
        for(i = 0; i < (int)oid2->len; i++) {
 
155
            oid1->name[i+oid1->len] = oid2->name[i];
 
156
        }
 
157
        oid1->len += oid2->len;
 
158
    }
 
159
 
 
160
int
 
161
nsop_length(oid1)
 
162
    netsnmp_oid *oid1;
 
163
    CODE: 
 
164
    {
 
165
        RETVAL = oid1->len;
 
166
    }
 
167
    OUTPUT:
 
168
    RETVAL
 
169
    
 
170
netsnmp_oid *
 
171
nsop_clone(oid1)
 
172
    netsnmp_oid *oid1;
 
173
    PREINIT:
 
174
    netsnmp_oid *oid2;
 
175
    CODE:
 
176
    {
 
177
        oid2 = nso_newarrayptr(oid1->name, oid1->len);
 
178
        RETVAL = oid2;
 
179
    }
 
180
OUTPUT:
 
181
    RETVAL
 
182