ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-SNMP-XS/XS.xs
(Generate patch)

Comparing Net-SNMP-XS/XS.xs (file contents):
Revision 1.2 by root, Wed Apr 8 10:39:32 2009 UTC vs.
Revision 1.3 by root, Wed Apr 8 13:54:42 2009 UTC

23 23
24#define ASN_LONG_LEN 0x80 24#define ASN_LONG_LEN 0x80
25#define ASN_EXTENSION_ID 0x1f 25#define ASN_EXTENSION_ID 0x1f
26#define ASN_BIT8 0x80 26#define ASN_BIT8 0x80
27 27
28//#define BENCHMARK 28#define BENCHMARK
29 29
30static SV *msg; 30static SV *msg;
31static int errflag; 31static int errflag;
32static U8 *buf, *cur; 32static U8 *buf, *cur;
33static STRLEN len, rem; 33static STRLEN len, rem;
34
35static SV *
36x_get_cv (SV *cb_sv)
37{
38 HV *st;
39 GV *gvp;
40 CV *cv = sv_2cv (cb_sv, &st, &gvp, 0);
41
42 if (!cv)
43 croak ("CODE reference expected");
44
45 return (SV *)cv;
46}
34 47
35static void 48static void
36error (const char *msg) 49error (const char *msg)
37{ 50{
38 errflag = 1; 51 errflag = 1;
134 } 147 }
135 148
136 return res; 149 return res;
137} 150}
138 151
152static AV *av_type;
153
139MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::XS 154MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::XS
155
156PROTOTYPES: ENABLE
157
158BOOT:
159 av_type = newAV ();
160
161void
162set_type (int type, SV *cv)
163 CODE:
164 av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv)));
140 165
141void 166void
142set_msg (SV *msg_, SV *buf_) 167set_msg (SV *msg_, SV *buf_)
143 CODE: 168 CODE:
144 errflag = 0; 169 errflag = 0;
199 RETVAL 224 RETVAL
200 225
201U32 226U32
202_process_length (SV *self, ...) 227_process_length (SV *self, ...)
203 ALIAS: 228 ALIAS:
204 _process_sequence = 1 229 _process_sequence = 0
205 CODE: 230 CODE:
206 RETVAL = process_length (); 231 RETVAL = process_length ();
207 OUTPUT: 232 OUTPUT:
208 RETVAL 233 RETVAL
209 234
306 RETVAL = newSVpvf ("%d.%d.%d.%d", data [0], data [1], data [2], data [3]); 331 RETVAL = newSVpvf ("%d.%d.%d.%d", data [0], data [1], data [2], data [3]);
307} 332}
308 OUTPUT: 333 OUTPUT:
309 RETVAL 334 RETVAL
310 335
336SV *
337process (SV *self, SV *expected = 0, SV *found = 0)
338 PPCODE:
339{
340 U8 type = get8 ();
341
342 if (expected && SvOK (expected) && type != SvIV (expected))
343 {
344 error ("Expected a different type than found");
345 XSRETURN_UNDEF;
346 }
347
348 if (type > AvFILLp (av_type) || !SvTYPE (AvARRAY (av_type)[type]) == SVt_PVCV)
349 {
350 sv_dump (AvARRAY (av_type)[type]);//D
351 error ("Unknown ASN.1 type");
352 XSRETURN_UNDEF;
353 }
354
355 if (found)
356 sv_setiv (found, type);
357
358 SV *res;
359
360 {
361 dSP;
362 PUSHMARK (SP);
363 EXTEND (SP, 2);
364 PUSHs (self);
365 PUSHs (expected);
366 PUTBACK;
367 int count = call_sv (AvARRAY (av_type)[type], G_SCALAR);
368 SPAGAIN;
369 res = count ? TOPs : &PL_sv_undef;
370 }
371
372 XPUSHs (res);
373}
374

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines