threatstack-agent-ruby 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +6 -0
  4. data/ext/libinjection/extconf.rb +4 -0
  5. data/ext/libinjection/libinjection.h +65 -0
  6. data/ext/libinjection/libinjection.i +13 -0
  7. data/ext/libinjection/libinjection_html5.c +850 -0
  8. data/ext/libinjection/libinjection_html5.h +54 -0
  9. data/ext/libinjection/libinjection_sqli.c +2325 -0
  10. data/ext/libinjection/libinjection_sqli.h +298 -0
  11. data/ext/libinjection/libinjection_sqli_data.h +9654 -0
  12. data/ext/libinjection/libinjection_wrap.c +2393 -0
  13. data/ext/libinjection/libinjection_xss.c +532 -0
  14. data/ext/libinjection/libinjection_xss.h +21 -0
  15. data/lib/constants.rb +110 -0
  16. data/lib/control.rb +61 -0
  17. data/lib/events/event_accumulator.rb +36 -0
  18. data/lib/events/models/attack_event.rb +58 -0
  19. data/lib/events/models/base_event.rb +41 -0
  20. data/lib/events/models/dependency_event.rb +93 -0
  21. data/lib/events/models/environment_event.rb +93 -0
  22. data/lib/events/models/instrumentation_event.rb +46 -0
  23. data/lib/exceptions/request_blocked_error.rb +11 -0
  24. data/lib/instrumentation/common.rb +172 -0
  25. data/lib/instrumentation/instrumenter.rb +144 -0
  26. data/lib/instrumentation/kernel.rb +45 -0
  27. data/lib/instrumentation/rails.rb +61 -0
  28. data/lib/jobs/delayed_job.rb +26 -0
  29. data/lib/jobs/event_submitter.rb +101 -0
  30. data/lib/jobs/job_queue.rb +38 -0
  31. data/lib/jobs/recurrent_job.rb +61 -0
  32. data/lib/threatstack-agent-ruby.rb +7 -0
  33. data/lib/utils/aws_utils.rb +46 -0
  34. data/lib/utils/formatter.rb +47 -0
  35. data/lib/utils/logger.rb +43 -0
  36. data/threatstack-agent-ruby.gemspec +35 -0
  37. metadata +221 -0
@@ -0,0 +1,2393 @@
1
+ /* ----------------------------------------------------------------------------
2
+ * This file was automatically generated by SWIG (http://www.swig.org).
3
+ * Version 4.0.1
4
+ *
5
+ * This file is not intended to be easily readable and contains a number of
6
+ * coding conventions designed to improve portability and efficiency. Do not make
7
+ * changes to this file unless you know what you are doing--modify the SWIG
8
+ * interface file instead.
9
+ * ----------------------------------------------------------------------------- */
10
+
11
+
12
+ #ifndef SWIGRUBY
13
+ #define SWIGRUBY
14
+ #endif
15
+
16
+
17
+ /* -----------------------------------------------------------------------------
18
+ * This section contains generic SWIG labels for method/variable
19
+ * declarations/attributes, and other compiler dependent labels.
20
+ * ----------------------------------------------------------------------------- */
21
+
22
+ /* template workaround for compilers that cannot correctly implement the C++ standard */
23
+ #ifndef SWIGTEMPLATEDISAMBIGUATOR
24
+ # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
25
+ # define SWIGTEMPLATEDISAMBIGUATOR template
26
+ # elif defined(__HP_aCC)
27
+ /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
28
+ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
29
+ # define SWIGTEMPLATEDISAMBIGUATOR template
30
+ # else
31
+ # define SWIGTEMPLATEDISAMBIGUATOR
32
+ # endif
33
+ #endif
34
+
35
+ /* inline attribute */
36
+ #ifndef SWIGINLINE
37
+ # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
38
+ # define SWIGINLINE inline
39
+ # else
40
+ # define SWIGINLINE
41
+ # endif
42
+ #endif
43
+
44
+ /* attribute recognised by some compilers to avoid 'unused' warnings */
45
+ #ifndef SWIGUNUSED
46
+ # if defined(__GNUC__)
47
+ # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
48
+ # define SWIGUNUSED __attribute__ ((__unused__))
49
+ # else
50
+ # define SWIGUNUSED
51
+ # endif
52
+ # elif defined(__ICC)
53
+ # define SWIGUNUSED __attribute__ ((__unused__))
54
+ # else
55
+ # define SWIGUNUSED
56
+ # endif
57
+ #endif
58
+
59
+ #ifndef SWIG_MSC_UNSUPPRESS_4505
60
+ # if defined(_MSC_VER)
61
+ # pragma warning(disable : 4505) /* unreferenced local function has been removed */
62
+ # endif
63
+ #endif
64
+
65
+ #ifndef SWIGUNUSEDPARM
66
+ # ifdef __cplusplus
67
+ # define SWIGUNUSEDPARM(p)
68
+ # else
69
+ # define SWIGUNUSEDPARM(p) p SWIGUNUSED
70
+ # endif
71
+ #endif
72
+
73
+ /* internal SWIG method */
74
+ #ifndef SWIGINTERN
75
+ # define SWIGINTERN static SWIGUNUSED
76
+ #endif
77
+
78
+ /* internal inline SWIG method */
79
+ #ifndef SWIGINTERNINLINE
80
+ # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
81
+ #endif
82
+
83
+ /* exporting methods */
84
+ #if defined(__GNUC__)
85
+ # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
86
+ # ifndef GCC_HASCLASSVISIBILITY
87
+ # define GCC_HASCLASSVISIBILITY
88
+ # endif
89
+ # endif
90
+ #endif
91
+
92
+ #ifndef SWIGEXPORT
93
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
94
+ # if defined(STATIC_LINKED)
95
+ # define SWIGEXPORT
96
+ # else
97
+ # define SWIGEXPORT __declspec(dllexport)
98
+ # endif
99
+ # else
100
+ # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
101
+ # define SWIGEXPORT __attribute__ ((visibility("default")))
102
+ # else
103
+ # define SWIGEXPORT
104
+ # endif
105
+ # endif
106
+ #endif
107
+
108
+ /* calling conventions for Windows */
109
+ #ifndef SWIGSTDCALL
110
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
111
+ # define SWIGSTDCALL __stdcall
112
+ # else
113
+ # define SWIGSTDCALL
114
+ # endif
115
+ #endif
116
+
117
+ /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
118
+ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
119
+ # define _CRT_SECURE_NO_DEPRECATE
120
+ #endif
121
+
122
+ /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
123
+ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
124
+ # define _SCL_SECURE_NO_DEPRECATE
125
+ #endif
126
+
127
+ /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
128
+ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
129
+ # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
130
+ #endif
131
+
132
+ /* Intel's compiler complains if a variable which was never initialised is
133
+ * cast to void, which is a common idiom which we use to indicate that we
134
+ * are aware a variable isn't used. So we just silence that warning.
135
+ * See: https://github.com/swig/swig/issues/192 for more discussion.
136
+ */
137
+ #ifdef __INTEL_COMPILER
138
+ # pragma warning disable 592
139
+ #endif
140
+
141
+ /* -----------------------------------------------------------------------------
142
+ * This section contains generic SWIG labels for method/variable
143
+ * declarations/attributes, and other compiler dependent labels.
144
+ * ----------------------------------------------------------------------------- */
145
+
146
+ /* template workaround for compilers that cannot correctly implement the C++ standard */
147
+ #ifndef SWIGTEMPLATEDISAMBIGUATOR
148
+ # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
149
+ # define SWIGTEMPLATEDISAMBIGUATOR template
150
+ # elif defined(__HP_aCC)
151
+ /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
152
+ /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
153
+ # define SWIGTEMPLATEDISAMBIGUATOR template
154
+ # else
155
+ # define SWIGTEMPLATEDISAMBIGUATOR
156
+ # endif
157
+ #endif
158
+
159
+ /* inline attribute */
160
+ #ifndef SWIGINLINE
161
+ # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
162
+ # define SWIGINLINE inline
163
+ # else
164
+ # define SWIGINLINE
165
+ # endif
166
+ #endif
167
+
168
+ /* attribute recognised by some compilers to avoid 'unused' warnings */
169
+ #ifndef SWIGUNUSED
170
+ # if defined(__GNUC__)
171
+ # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
172
+ # define SWIGUNUSED __attribute__ ((__unused__))
173
+ # else
174
+ # define SWIGUNUSED
175
+ # endif
176
+ # elif defined(__ICC)
177
+ # define SWIGUNUSED __attribute__ ((__unused__))
178
+ # else
179
+ # define SWIGUNUSED
180
+ # endif
181
+ #endif
182
+
183
+ #ifndef SWIG_MSC_UNSUPPRESS_4505
184
+ # if defined(_MSC_VER)
185
+ # pragma warning(disable : 4505) /* unreferenced local function has been removed */
186
+ # endif
187
+ #endif
188
+
189
+ #ifndef SWIGUNUSEDPARM
190
+ # ifdef __cplusplus
191
+ # define SWIGUNUSEDPARM(p)
192
+ # else
193
+ # define SWIGUNUSEDPARM(p) p SWIGUNUSED
194
+ # endif
195
+ #endif
196
+
197
+ /* internal SWIG method */
198
+ #ifndef SWIGINTERN
199
+ # define SWIGINTERN static SWIGUNUSED
200
+ #endif
201
+
202
+ /* internal inline SWIG method */
203
+ #ifndef SWIGINTERNINLINE
204
+ # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
205
+ #endif
206
+
207
+ /* exporting methods */
208
+ #if defined(__GNUC__)
209
+ # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
210
+ # ifndef GCC_HASCLASSVISIBILITY
211
+ # define GCC_HASCLASSVISIBILITY
212
+ # endif
213
+ # endif
214
+ #endif
215
+
216
+ #ifndef SWIGEXPORT
217
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
218
+ # if defined(STATIC_LINKED)
219
+ # define SWIGEXPORT
220
+ # else
221
+ # define SWIGEXPORT __declspec(dllexport)
222
+ # endif
223
+ # else
224
+ # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
225
+ # define SWIGEXPORT __attribute__ ((visibility("default")))
226
+ # else
227
+ # define SWIGEXPORT
228
+ # endif
229
+ # endif
230
+ #endif
231
+
232
+ /* calling conventions for Windows */
233
+ #ifndef SWIGSTDCALL
234
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
235
+ # define SWIGSTDCALL __stdcall
236
+ # else
237
+ # define SWIGSTDCALL
238
+ # endif
239
+ #endif
240
+
241
+ /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
242
+ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
243
+ # define _CRT_SECURE_NO_DEPRECATE
244
+ #endif
245
+
246
+ /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
247
+ #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
248
+ # define _SCL_SECURE_NO_DEPRECATE
249
+ #endif
250
+
251
+ /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
252
+ #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
253
+ # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
254
+ #endif
255
+
256
+ /* Intel's compiler complains if a variable which was never initialised is
257
+ * cast to void, which is a common idiom which we use to indicate that we
258
+ * are aware a variable isn't used. So we just silence that warning.
259
+ * See: https://github.com/swig/swig/issues/192 for more discussion.
260
+ */
261
+ #ifdef __INTEL_COMPILER
262
+ # pragma warning disable 592
263
+ #endif
264
+
265
+ /* -----------------------------------------------------------------------------
266
+ * swigrun.swg
267
+ *
268
+ * This file contains generic C API SWIG runtime support for pointer
269
+ * type checking.
270
+ * ----------------------------------------------------------------------------- */
271
+
272
+ /* This should only be incremented when either the layout of swig_type_info changes,
273
+ or for whatever reason, the runtime changes incompatibly */
274
+ #define SWIG_RUNTIME_VERSION "4"
275
+
276
+ /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
277
+ #ifdef SWIG_TYPE_TABLE
278
+ # define SWIG_QUOTE_STRING(x) #x
279
+ # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
280
+ # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
281
+ #else
282
+ # define SWIG_TYPE_TABLE_NAME
283
+ #endif
284
+
285
+ /*
286
+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
287
+ creating a static or dynamic library from the SWIG runtime code.
288
+ In 99.9% of the cases, SWIG just needs to declare them as 'static'.
289
+
290
+ But only do this if strictly necessary, ie, if you have problems
291
+ with your compiler or suchlike.
292
+ */
293
+
294
+ #ifndef SWIGRUNTIME
295
+ # define SWIGRUNTIME SWIGINTERN
296
+ #endif
297
+
298
+ #ifndef SWIGRUNTIMEINLINE
299
+ # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
300
+ #endif
301
+
302
+ /* Generic buffer size */
303
+ #ifndef SWIG_BUFFER_SIZE
304
+ # define SWIG_BUFFER_SIZE 1024
305
+ #endif
306
+
307
+ /* Flags for pointer conversions */
308
+ #define SWIG_POINTER_DISOWN 0x1
309
+ #define SWIG_CAST_NEW_MEMORY 0x2
310
+ #define SWIG_POINTER_NO_NULL 0x4
311
+
312
+ /* Flags for new pointer objects */
313
+ #define SWIG_POINTER_OWN 0x1
314
+
315
+
316
+ /*
317
+ Flags/methods for returning states.
318
+
319
+ The SWIG conversion methods, as ConvertPtr, return an integer
320
+ that tells if the conversion was successful or not. And if not,
321
+ an error code can be returned (see swigerrors.swg for the codes).
322
+
323
+ Use the following macros/flags to set or process the returning
324
+ states.
325
+
326
+ In old versions of SWIG, code such as the following was usually written:
327
+
328
+ if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
329
+ // success code
330
+ } else {
331
+ //fail code
332
+ }
333
+
334
+ Now you can be more explicit:
335
+
336
+ int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
337
+ if (SWIG_IsOK(res)) {
338
+ // success code
339
+ } else {
340
+ // fail code
341
+ }
342
+
343
+ which is the same really, but now you can also do
344
+
345
+ Type *ptr;
346
+ int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
347
+ if (SWIG_IsOK(res)) {
348
+ // success code
349
+ if (SWIG_IsNewObj(res) {
350
+ ...
351
+ delete *ptr;
352
+ } else {
353
+ ...
354
+ }
355
+ } else {
356
+ // fail code
357
+ }
358
+
359
+ I.e., now SWIG_ConvertPtr can return new objects and you can
360
+ identify the case and take care of the deallocation. Of course that
361
+ also requires SWIG_ConvertPtr to return new result values, such as
362
+
363
+ int SWIG_ConvertPtr(obj, ptr,...) {
364
+ if (<obj is ok>) {
365
+ if (<need new object>) {
366
+ *ptr = <ptr to new allocated object>;
367
+ return SWIG_NEWOBJ;
368
+ } else {
369
+ *ptr = <ptr to old object>;
370
+ return SWIG_OLDOBJ;
371
+ }
372
+ } else {
373
+ return SWIG_BADOBJ;
374
+ }
375
+ }
376
+
377
+ Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
378
+ more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
379
+ SWIG errors code.
380
+
381
+ Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
382
+ allows to return the 'cast rank', for example, if you have this
383
+
384
+ int food(double)
385
+ int fooi(int);
386
+
387
+ and you call
388
+
389
+ food(1) // cast rank '1' (1 -> 1.0)
390
+ fooi(1) // cast rank '0'
391
+
392
+ just use the SWIG_AddCast()/SWIG_CheckState()
393
+ */
394
+
395
+ #define SWIG_OK (0)
396
+ #define SWIG_ERROR (-1)
397
+ #define SWIG_IsOK(r) (r >= 0)
398
+ #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
399
+
400
+ /* The CastRankLimit says how many bits are used for the cast rank */
401
+ #define SWIG_CASTRANKLIMIT (1 << 8)
402
+ /* The NewMask denotes the object was created (using new/malloc) */
403
+ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
404
+ /* The TmpMask is for in/out typemaps that use temporal objects */
405
+ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
406
+ /* Simple returning values */
407
+ #define SWIG_BADOBJ (SWIG_ERROR)
408
+ #define SWIG_OLDOBJ (SWIG_OK)
409
+ #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
410
+ #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
411
+ /* Check, add and del mask methods */
412
+ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
413
+ #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
414
+ #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
415
+ #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
416
+ #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
417
+ #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
418
+
419
+ /* Cast-Rank Mode */
420
+ #if defined(SWIG_CASTRANK_MODE)
421
+ # ifndef SWIG_TypeRank
422
+ # define SWIG_TypeRank unsigned long
423
+ # endif
424
+ # ifndef SWIG_MAXCASTRANK /* Default cast allowed */
425
+ # define SWIG_MAXCASTRANK (2)
426
+ # endif
427
+ # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
428
+ # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
429
+ SWIGINTERNINLINE int SWIG_AddCast(int r) {
430
+ return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
431
+ }
432
+ SWIGINTERNINLINE int SWIG_CheckState(int r) {
433
+ return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
434
+ }
435
+ #else /* no cast-rank mode */
436
+ # define SWIG_AddCast(r) (r)
437
+ # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
438
+ #endif
439
+
440
+
441
+ #include <string.h>
442
+
443
+ #ifdef __cplusplus
444
+ extern "C" {
445
+ #endif
446
+
447
+ typedef void *(*swig_converter_func)(void *, int *);
448
+ typedef struct swig_type_info *(*swig_dycast_func)(void **);
449
+
450
+ /* Structure to store information on one type */
451
+ typedef struct swig_type_info {
452
+ const char *name; /* mangled name of this type */
453
+ const char *str; /* human readable name of this type */
454
+ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
455
+ struct swig_cast_info *cast; /* linked list of types that can cast into this type */
456
+ void *clientdata; /* language specific type data */
457
+ int owndata; /* flag if the structure owns the clientdata */
458
+ } swig_type_info;
459
+
460
+ /* Structure to store a type and conversion function used for casting */
461
+ typedef struct swig_cast_info {
462
+ swig_type_info *type; /* pointer to type that is equivalent to this type */
463
+ swig_converter_func converter; /* function to cast the void pointers */
464
+ struct swig_cast_info *next; /* pointer to next cast in linked list */
465
+ struct swig_cast_info *prev; /* pointer to the previous cast */
466
+ } swig_cast_info;
467
+
468
+ /* Structure used to store module information
469
+ * Each module generates one structure like this, and the runtime collects
470
+ * all of these structures and stores them in a circularly linked list.*/
471
+ typedef struct swig_module_info {
472
+ swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
473
+ size_t size; /* Number of types in this module */
474
+ struct swig_module_info *next; /* Pointer to next element in circularly linked list */
475
+ swig_type_info **type_initial; /* Array of initially generated type structures */
476
+ swig_cast_info **cast_initial; /* Array of initially generated casting structures */
477
+ void *clientdata; /* Language specific module data */
478
+ } swig_module_info;
479
+
480
+ /*
481
+ Compare two type names skipping the space characters, therefore
482
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
483
+
484
+ Return 0 when the two name types are equivalent, as in
485
+ strncmp, but skipping ' '.
486
+ */
487
+ SWIGRUNTIME int
488
+ SWIG_TypeNameComp(const char *f1, const char *l1,
489
+ const char *f2, const char *l2) {
490
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
491
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
492
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
493
+ if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
494
+ }
495
+ return (int)((l1 - f1) - (l2 - f2));
496
+ }
497
+
498
+ /*
499
+ Check type equivalence in a name list like <name1>|<name2>|...
500
+ Return 0 if equal, -1 if nb < tb, 1 if nb > tb
501
+ */
502
+ SWIGRUNTIME int
503
+ SWIG_TypeCmp(const char *nb, const char *tb) {
504
+ int equiv = 1;
505
+ const char* te = tb + strlen(tb);
506
+ const char* ne = nb;
507
+ while (equiv != 0 && *ne) {
508
+ for (nb = ne; *ne; ++ne) {
509
+ if (*ne == '|') break;
510
+ }
511
+ equiv = SWIG_TypeNameComp(nb, ne, tb, te);
512
+ if (*ne) ++ne;
513
+ }
514
+ return equiv;
515
+ }
516
+
517
+ /*
518
+ Check type equivalence in a name list like <name1>|<name2>|...
519
+ Return 0 if not equal, 1 if equal
520
+ */
521
+ SWIGRUNTIME int
522
+ SWIG_TypeEquiv(const char *nb, const char *tb) {
523
+ return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
524
+ }
525
+
526
+ /*
527
+ Check the typename
528
+ */
529
+ SWIGRUNTIME swig_cast_info *
530
+ SWIG_TypeCheck(const char *c, swig_type_info *ty) {
531
+ if (ty) {
532
+ swig_cast_info *iter = ty->cast;
533
+ while (iter) {
534
+ if (strcmp(iter->type->name, c) == 0) {
535
+ if (iter == ty->cast)
536
+ return iter;
537
+ /* Move iter to the top of the linked list */
538
+ iter->prev->next = iter->next;
539
+ if (iter->next)
540
+ iter->next->prev = iter->prev;
541
+ iter->next = ty->cast;
542
+ iter->prev = 0;
543
+ if (ty->cast) ty->cast->prev = iter;
544
+ ty->cast = iter;
545
+ return iter;
546
+ }
547
+ iter = iter->next;
548
+ }
549
+ }
550
+ return 0;
551
+ }
552
+
553
+ /*
554
+ Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
555
+ */
556
+ SWIGRUNTIME swig_cast_info *
557
+ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) {
558
+ if (ty) {
559
+ swig_cast_info *iter = ty->cast;
560
+ while (iter) {
561
+ if (iter->type == from) {
562
+ if (iter == ty->cast)
563
+ return iter;
564
+ /* Move iter to the top of the linked list */
565
+ iter->prev->next = iter->next;
566
+ if (iter->next)
567
+ iter->next->prev = iter->prev;
568
+ iter->next = ty->cast;
569
+ iter->prev = 0;
570
+ if (ty->cast) ty->cast->prev = iter;
571
+ ty->cast = iter;
572
+ return iter;
573
+ }
574
+ iter = iter->next;
575
+ }
576
+ }
577
+ return 0;
578
+ }
579
+
580
+ /*
581
+ Cast a pointer up an inheritance hierarchy
582
+ */
583
+ SWIGRUNTIMEINLINE void *
584
+ SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
585
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
586
+ }
587
+
588
+ /*
589
+ Dynamic pointer casting. Down an inheritance hierarchy
590
+ */
591
+ SWIGRUNTIME swig_type_info *
592
+ SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
593
+ swig_type_info *lastty = ty;
594
+ if (!ty || !ty->dcast) return ty;
595
+ while (ty && (ty->dcast)) {
596
+ ty = (*ty->dcast)(ptr);
597
+ if (ty) lastty = ty;
598
+ }
599
+ return lastty;
600
+ }
601
+
602
+ /*
603
+ Return the name associated with this type
604
+ */
605
+ SWIGRUNTIMEINLINE const char *
606
+ SWIG_TypeName(const swig_type_info *ty) {
607
+ return ty->name;
608
+ }
609
+
610
+ /*
611
+ Return the pretty name associated with this type,
612
+ that is an unmangled type name in a form presentable to the user.
613
+ */
614
+ SWIGRUNTIME const char *
615
+ SWIG_TypePrettyName(const swig_type_info *type) {
616
+ /* The "str" field contains the equivalent pretty names of the
617
+ type, separated by vertical-bar characters. We choose
618
+ to print the last name, as it is often (?) the most
619
+ specific. */
620
+ if (!type) return NULL;
621
+ if (type->str != NULL) {
622
+ const char *last_name = type->str;
623
+ const char *s;
624
+ for (s = type->str; *s; s++)
625
+ if (*s == '|') last_name = s+1;
626
+ return last_name;
627
+ }
628
+ else
629
+ return type->name;
630
+ }
631
+
632
+ /*
633
+ Set the clientdata field for a type
634
+ */
635
+ SWIGRUNTIME void
636
+ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
637
+ swig_cast_info *cast = ti->cast;
638
+ /* if (ti->clientdata == clientdata) return; */
639
+ ti->clientdata = clientdata;
640
+
641
+ while (cast) {
642
+ if (!cast->converter) {
643
+ swig_type_info *tc = cast->type;
644
+ if (!tc->clientdata) {
645
+ SWIG_TypeClientData(tc, clientdata);
646
+ }
647
+ }
648
+ cast = cast->next;
649
+ }
650
+ }
651
+ SWIGRUNTIME void
652
+ SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
653
+ SWIG_TypeClientData(ti, clientdata);
654
+ ti->owndata = 1;
655
+ }
656
+
657
+ /*
658
+ Search for a swig_type_info structure only by mangled name
659
+ Search is a O(log #types)
660
+
661
+ We start searching at module start, and finish searching when start == end.
662
+ Note: if start == end at the beginning of the function, we go all the way around
663
+ the circular list.
664
+ */
665
+ SWIGRUNTIME swig_type_info *
666
+ SWIG_MangledTypeQueryModule(swig_module_info *start,
667
+ swig_module_info *end,
668
+ const char *name) {
669
+ swig_module_info *iter = start;
670
+ do {
671
+ if (iter->size) {
672
+ size_t l = 0;
673
+ size_t r = iter->size - 1;
674
+ do {
675
+ /* since l+r >= 0, we can (>> 1) instead (/ 2) */
676
+ size_t i = (l + r) >> 1;
677
+ const char *iname = iter->types[i]->name;
678
+ if (iname) {
679
+ int compare = strcmp(name, iname);
680
+ if (compare == 0) {
681
+ return iter->types[i];
682
+ } else if (compare < 0) {
683
+ if (i) {
684
+ r = i - 1;
685
+ } else {
686
+ break;
687
+ }
688
+ } else if (compare > 0) {
689
+ l = i + 1;
690
+ }
691
+ } else {
692
+ break; /* should never happen */
693
+ }
694
+ } while (l <= r);
695
+ }
696
+ iter = iter->next;
697
+ } while (iter != end);
698
+ return 0;
699
+ }
700
+
701
+ /*
702
+ Search for a swig_type_info structure for either a mangled name or a human readable name.
703
+ It first searches the mangled names of the types, which is a O(log #types)
704
+ If a type is not found it then searches the human readable names, which is O(#types).
705
+
706
+ We start searching at module start, and finish searching when start == end.
707
+ Note: if start == end at the beginning of the function, we go all the way around
708
+ the circular list.
709
+ */
710
+ SWIGRUNTIME swig_type_info *
711
+ SWIG_TypeQueryModule(swig_module_info *start,
712
+ swig_module_info *end,
713
+ const char *name) {
714
+ /* STEP 1: Search the name field using binary search */
715
+ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
716
+ if (ret) {
717
+ return ret;
718
+ } else {
719
+ /* STEP 2: If the type hasn't been found, do a complete search
720
+ of the str field (the human readable name) */
721
+ swig_module_info *iter = start;
722
+ do {
723
+ size_t i = 0;
724
+ for (; i < iter->size; ++i) {
725
+ if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
726
+ return iter->types[i];
727
+ }
728
+ iter = iter->next;
729
+ } while (iter != end);
730
+ }
731
+
732
+ /* neither found a match */
733
+ return 0;
734
+ }
735
+
736
+ /*
737
+ Pack binary data into a string
738
+ */
739
+ SWIGRUNTIME char *
740
+ SWIG_PackData(char *c, void *ptr, size_t sz) {
741
+ static const char hex[17] = "0123456789abcdef";
742
+ const unsigned char *u = (unsigned char *) ptr;
743
+ const unsigned char *eu = u + sz;
744
+ for (; u != eu; ++u) {
745
+ unsigned char uu = *u;
746
+ *(c++) = hex[(uu & 0xf0) >> 4];
747
+ *(c++) = hex[uu & 0xf];
748
+ }
749
+ return c;
750
+ }
751
+
752
+ /*
753
+ Unpack binary data from a string
754
+ */
755
+ SWIGRUNTIME const char *
756
+ SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
757
+ unsigned char *u = (unsigned char *) ptr;
758
+ const unsigned char *eu = u + sz;
759
+ for (; u != eu; ++u) {
760
+ char d = *(c++);
761
+ unsigned char uu;
762
+ if ((d >= '0') && (d <= '9'))
763
+ uu = (unsigned char)((d - '0') << 4);
764
+ else if ((d >= 'a') && (d <= 'f'))
765
+ uu = (unsigned char)((d - ('a'-10)) << 4);
766
+ else
767
+ return (char *) 0;
768
+ d = *(c++);
769
+ if ((d >= '0') && (d <= '9'))
770
+ uu |= (unsigned char)(d - '0');
771
+ else if ((d >= 'a') && (d <= 'f'))
772
+ uu |= (unsigned char)(d - ('a'-10));
773
+ else
774
+ return (char *) 0;
775
+ *u = uu;
776
+ }
777
+ return c;
778
+ }
779
+
780
+ /*
781
+ Pack 'void *' into a string buffer.
782
+ */
783
+ SWIGRUNTIME char *
784
+ SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
785
+ char *r = buff;
786
+ if ((2*sizeof(void *) + 2) > bsz) return 0;
787
+ *(r++) = '_';
788
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
789
+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
790
+ strcpy(r,name);
791
+ return buff;
792
+ }
793
+
794
+ SWIGRUNTIME const char *
795
+ SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
796
+ if (*c != '_') {
797
+ if (strcmp(c,"NULL") == 0) {
798
+ *ptr = (void *) 0;
799
+ return name;
800
+ } else {
801
+ return 0;
802
+ }
803
+ }
804
+ return SWIG_UnpackData(++c,ptr,sizeof(void *));
805
+ }
806
+
807
+ SWIGRUNTIME char *
808
+ SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
809
+ char *r = buff;
810
+ size_t lname = (name ? strlen(name) : 0);
811
+ if ((2*sz + 2 + lname) > bsz) return 0;
812
+ *(r++) = '_';
813
+ r = SWIG_PackData(r,ptr,sz);
814
+ if (lname) {
815
+ strncpy(r,name,lname+1);
816
+ } else {
817
+ *r = 0;
818
+ }
819
+ return buff;
820
+ }
821
+
822
+ SWIGRUNTIME const char *
823
+ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
824
+ if (*c != '_') {
825
+ if (strcmp(c,"NULL") == 0) {
826
+ memset(ptr,0,sz);
827
+ return name;
828
+ } else {
829
+ return 0;
830
+ }
831
+ }
832
+ return SWIG_UnpackData(++c,ptr,sz);
833
+ }
834
+
835
+ #ifdef __cplusplus
836
+ }
837
+ #endif
838
+
839
+ /* Errors in SWIG */
840
+ #define SWIG_UnknownError -1
841
+ #define SWIG_IOError -2
842
+ #define SWIG_RuntimeError -3
843
+ #define SWIG_IndexError -4
844
+ #define SWIG_TypeError -5
845
+ #define SWIG_DivisionByZero -6
846
+ #define SWIG_OverflowError -7
847
+ #define SWIG_SyntaxError -8
848
+ #define SWIG_ValueError -9
849
+ #define SWIG_SystemError -10
850
+ #define SWIG_AttributeError -11
851
+ #define SWIG_MemoryError -12
852
+ #define SWIG_NullReferenceError -13
853
+
854
+
855
+
856
+ #include <ruby.h>
857
+
858
+ /* Ruby 1.9.1 has a "memoisation optimisation" when compiling with GCC which
859
+ * breaks using rb_intern as an lvalue, as SWIG does. We work around this
860
+ * issue for now by disabling this.
861
+ * https://sourceforge.net/tracker/?func=detail&aid=2859614&group_id=1645&atid=101645
862
+ */
863
+ #ifdef rb_intern
864
+ # undef rb_intern
865
+ #endif
866
+
867
+ /* Remove global macros defined in Ruby's win32.h */
868
+ #ifdef write
869
+ # undef write
870
+ #endif
871
+ #ifdef read
872
+ # undef read
873
+ #endif
874
+ #ifdef bind
875
+ # undef bind
876
+ #endif
877
+ #ifdef close
878
+ # undef close
879
+ #endif
880
+ #ifdef connect
881
+ # undef connect
882
+ #endif
883
+
884
+
885
+ /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
886
+ #ifndef NUM2LL
887
+ #define NUM2LL(x) NUM2LONG((x))
888
+ #endif
889
+ #ifndef LL2NUM
890
+ #define LL2NUM(x) INT2NUM((long) (x))
891
+ #endif
892
+ #ifndef ULL2NUM
893
+ #define ULL2NUM(x) UINT2NUM((unsigned long) (x))
894
+ #endif
895
+
896
+ /* Ruby 1.7 doesn't (yet) define NUM2ULL() */
897
+ #ifndef NUM2ULL
898
+ #ifdef HAVE_LONG_LONG
899
+ #define NUM2ULL(x) rb_num2ull((x))
900
+ #else
901
+ #define NUM2ULL(x) NUM2ULONG(x)
902
+ #endif
903
+ #endif
904
+
905
+ /* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */
906
+ /* Define these for older versions so we can just write code the new way */
907
+ #ifndef RSTRING_LEN
908
+ # define RSTRING_LEN(x) RSTRING(x)->len
909
+ #endif
910
+ #ifndef RSTRING_PTR
911
+ # define RSTRING_PTR(x) RSTRING(x)->ptr
912
+ #endif
913
+ #ifndef RSTRING_END
914
+ # define RSTRING_END(x) (RSTRING_PTR(x) + RSTRING_LEN(x))
915
+ #endif
916
+ #ifndef RARRAY_LEN
917
+ # define RARRAY_LEN(x) RARRAY(x)->len
918
+ #endif
919
+ #ifndef RARRAY_PTR
920
+ # define RARRAY_PTR(x) RARRAY(x)->ptr
921
+ #endif
922
+ #ifndef RFLOAT_VALUE
923
+ # define RFLOAT_VALUE(x) RFLOAT(x)->value
924
+ #endif
925
+ #ifndef DOUBLE2NUM
926
+ # define DOUBLE2NUM(x) rb_float_new(x)
927
+ #endif
928
+ #ifndef RHASH_TBL
929
+ # define RHASH_TBL(x) (RHASH(x)->tbl)
930
+ #endif
931
+ #ifndef RHASH_ITER_LEV
932
+ # define RHASH_ITER_LEV(x) (RHASH(x)->iter_lev)
933
+ #endif
934
+ #ifndef RHASH_IFNONE
935
+ # define RHASH_IFNONE(x) (RHASH(x)->ifnone)
936
+ #endif
937
+ #ifndef RHASH_SIZE
938
+ # define RHASH_SIZE(x) (RHASH(x)->tbl->num_entries)
939
+ #endif
940
+ #ifndef RHASH_EMPTY_P
941
+ # define RHASH_EMPTY_P(x) (RHASH_SIZE(x) == 0)
942
+ #endif
943
+ #ifndef RSTRUCT_LEN
944
+ # define RSTRUCT_LEN(x) RSTRUCT(x)->len
945
+ #endif
946
+ #ifndef RSTRUCT_PTR
947
+ # define RSTRUCT_PTR(x) RSTRUCT(x)->ptr
948
+ #endif
949
+ #ifndef RTYPEDDATA_P
950
+ # define RTYPEDDATA_P(x) (TYPE(x) != T_DATA)
951
+ #endif
952
+
953
+
954
+
955
+ /*
956
+ * Need to be very careful about how these macros are defined, especially
957
+ * when compiling C++ code or C code with an ANSI C compiler.
958
+ *
959
+ * VALUEFUNC(f) is a macro used to typecast a C function that implements
960
+ * a Ruby method so that it can be passed as an argument to API functions
961
+ * like rb_define_method() and rb_define_singleton_method().
962
+ *
963
+ * VOIDFUNC(f) is a macro used to typecast a C function that implements
964
+ * either the "mark" or "free" stuff for a Ruby Data object, so that it
965
+ * can be passed as an argument to API functions like Data_Wrap_Struct()
966
+ * and Data_Make_Struct().
967
+ */
968
+
969
+ #ifdef __cplusplus
970
+ # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
971
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
972
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
973
+ # define VOIDFUNC(f) ((void (*)()) f)
974
+ # else
975
+ # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
976
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
977
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
978
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
979
+ # else /* These definitions should work for Ruby 1.7+ */
980
+ # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
981
+ # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
982
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
983
+ # endif
984
+ # endif
985
+ #else
986
+ # define VALUEFUNC(f) (f)
987
+ # define VOIDFUNC(f) (f)
988
+ #endif
989
+
990
+ /* Don't use for expressions have side effect */
991
+ #ifndef RB_STRING_VALUE
992
+ #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
993
+ #endif
994
+ #ifndef StringValue
995
+ #define StringValue(s) RB_STRING_VALUE(s)
996
+ #endif
997
+ #ifndef StringValuePtr
998
+ #define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s))
999
+ #endif
1000
+ #ifndef StringValueLen
1001
+ #define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s))
1002
+ #endif
1003
+ #ifndef SafeStringValue
1004
+ #define SafeStringValue(v) do {\
1005
+ StringValue(v);\
1006
+ rb_check_safe_str(v);\
1007
+ } while (0)
1008
+ #endif
1009
+
1010
+ #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
1011
+ #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
1012
+ #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
1013
+ #endif
1014
+
1015
+ static VALUE _mSWIG = Qnil;
1016
+
1017
+ /* -----------------------------------------------------------------------------
1018
+ * error manipulation
1019
+ * ----------------------------------------------------------------------------- */
1020
+
1021
+
1022
+ /* Define some additional error types */
1023
+ #define SWIG_ObjectPreviouslyDeletedError -100
1024
+
1025
+
1026
+ /* Define custom exceptions for errors that do not map to existing Ruby
1027
+ exceptions. Note this only works for C++ since a global cannot be
1028
+ initialized by a function in C. For C, fallback to rb_eRuntimeError.*/
1029
+
1030
+ SWIGINTERN VALUE
1031
+ getNullReferenceError(void) {
1032
+ static int init = 0;
1033
+ static VALUE rb_eNullReferenceError ;
1034
+ if (!init) {
1035
+ init = 1;
1036
+ rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
1037
+ }
1038
+ return rb_eNullReferenceError;
1039
+ }
1040
+
1041
+ SWIGINTERN VALUE
1042
+ getObjectPreviouslyDeletedError(void) {
1043
+ static int init = 0;
1044
+ static VALUE rb_eObjectPreviouslyDeleted ;
1045
+ if (!init) {
1046
+ init = 1;
1047
+ rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
1048
+ }
1049
+ return rb_eObjectPreviouslyDeleted;
1050
+ }
1051
+
1052
+
1053
+ SWIGINTERN VALUE
1054
+ SWIG_Ruby_ErrorType(int SWIG_code) {
1055
+ VALUE type;
1056
+ switch (SWIG_code) {
1057
+ case SWIG_MemoryError:
1058
+ type = rb_eNoMemError;
1059
+ break;
1060
+ case SWIG_IOError:
1061
+ type = rb_eIOError;
1062
+ break;
1063
+ case SWIG_RuntimeError:
1064
+ type = rb_eRuntimeError;
1065
+ break;
1066
+ case SWIG_IndexError:
1067
+ type = rb_eIndexError;
1068
+ break;
1069
+ case SWIG_TypeError:
1070
+ type = rb_eTypeError;
1071
+ break;
1072
+ case SWIG_DivisionByZero:
1073
+ type = rb_eZeroDivError;
1074
+ break;
1075
+ case SWIG_OverflowError:
1076
+ type = rb_eRangeError;
1077
+ break;
1078
+ case SWIG_SyntaxError:
1079
+ type = rb_eSyntaxError;
1080
+ break;
1081
+ case SWIG_ValueError:
1082
+ type = rb_eArgError;
1083
+ break;
1084
+ case SWIG_SystemError:
1085
+ type = rb_eFatal;
1086
+ break;
1087
+ case SWIG_AttributeError:
1088
+ type = rb_eRuntimeError;
1089
+ break;
1090
+ case SWIG_NullReferenceError:
1091
+ type = getNullReferenceError();
1092
+ break;
1093
+ case SWIG_ObjectPreviouslyDeletedError:
1094
+ type = getObjectPreviouslyDeletedError();
1095
+ break;
1096
+ case SWIG_UnknownError:
1097
+ type = rb_eRuntimeError;
1098
+ break;
1099
+ default:
1100
+ type = rb_eRuntimeError;
1101
+ }
1102
+ return type;
1103
+ }
1104
+
1105
+
1106
+ /* This function is called when a user inputs a wrong argument to
1107
+ a method.
1108
+ */
1109
+ SWIGINTERN
1110
+ const char* Ruby_Format_TypeError( const char* msg,
1111
+ const char* type,
1112
+ const char* name,
1113
+ const int argn,
1114
+ VALUE input )
1115
+ {
1116
+ char buf[128];
1117
+ VALUE str;
1118
+ VALUE asStr;
1119
+ if ( msg && *msg )
1120
+ {
1121
+ str = rb_str_new2(msg);
1122
+ }
1123
+ else
1124
+ {
1125
+ str = rb_str_new(NULL, 0);
1126
+ }
1127
+
1128
+ str = rb_str_cat2( str, "Expected argument " );
1129
+ sprintf( buf, "%d of type ", argn-1 );
1130
+ str = rb_str_cat2( str, buf );
1131
+ str = rb_str_cat2( str, type );
1132
+ str = rb_str_cat2( str, ", but got " );
1133
+ str = rb_str_cat2( str, rb_obj_classname(input) );
1134
+ str = rb_str_cat2( str, " " );
1135
+ asStr = rb_inspect(input);
1136
+ if ( RSTRING_LEN(asStr) > 30 )
1137
+ {
1138
+ str = rb_str_cat( str, StringValuePtr(asStr), 30 );
1139
+ str = rb_str_cat2( str, "..." );
1140
+ }
1141
+ else
1142
+ {
1143
+ str = rb_str_append( str, asStr );
1144
+ }
1145
+
1146
+ if ( name )
1147
+ {
1148
+ str = rb_str_cat2( str, "\n\tin SWIG method '" );
1149
+ str = rb_str_cat2( str, name );
1150
+ str = rb_str_cat2( str, "'" );
1151
+ }
1152
+
1153
+ return StringValuePtr( str );
1154
+ }
1155
+
1156
+ /* This function is called when an overloaded method fails */
1157
+ SWIGINTERN
1158
+ void Ruby_Format_OverloadedError(
1159
+ const int argc,
1160
+ const int maxargs,
1161
+ const char* method,
1162
+ const char* prototypes
1163
+ )
1164
+ {
1165
+ const char* msg = "Wrong # of arguments";
1166
+ if ( argc <= maxargs ) msg = "Wrong arguments";
1167
+ rb_raise(rb_eArgError,"%s for overloaded method '%s'.\n"
1168
+ "Possible C/C++ prototypes are:\n%s",
1169
+ msg, method, prototypes);
1170
+ }
1171
+
1172
+ /* -----------------------------------------------------------------------------
1173
+ * rubytracking.swg
1174
+ *
1175
+ * This file contains support for tracking mappings from
1176
+ * Ruby objects to C++ objects. This functionality is needed
1177
+ * to implement mark functions for Ruby's mark and sweep
1178
+ * garbage collector.
1179
+ * ----------------------------------------------------------------------------- */
1180
+
1181
+ #ifdef __cplusplus
1182
+ extern "C" {
1183
+ #endif
1184
+
1185
+ #if !defined(ST_DATA_T_DEFINED)
1186
+ /* Needs to be explicitly included for Ruby 1.8 and earlier */
1187
+ #include <st.h>
1188
+ #endif
1189
+
1190
+ /* Ruby 1.8 actually assumes the first case. */
1191
+ #if SIZEOF_VOIDP == SIZEOF_LONG
1192
+ # define SWIG2NUM(v) LONG2NUM((unsigned long)v)
1193
+ # define NUM2SWIG(x) (unsigned long)NUM2LONG(x)
1194
+ #elif SIZEOF_VOIDP == SIZEOF_LONG_LONG
1195
+ # define SWIG2NUM(v) LL2NUM((unsigned long long)v)
1196
+ # define NUM2SWIG(x) (unsigned long long)NUM2LL(x)
1197
+ #else
1198
+ # error sizeof(void*) is not the same as long or long long
1199
+ #endif
1200
+
1201
+ /* Global hash table to store Trackings from C/C++
1202
+ structs to Ruby Objects.
1203
+ */
1204
+ static st_table* swig_ruby_trackings = NULL;
1205
+
1206
+ static VALUE swig_ruby_trackings_count(ANYARGS) {
1207
+ return SWIG2NUM(swig_ruby_trackings->num_entries);
1208
+ }
1209
+
1210
+
1211
+ /* Setup a hash table to store Trackings */
1212
+ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
1213
+ /* Create a hash table to store Trackings from C++
1214
+ objects to Ruby objects. */
1215
+
1216
+ /* Try to see if some other .so has already created a
1217
+ tracking hash table, which we keep hidden in an instance var
1218
+ in the SWIG module.
1219
+ This is done to allow multiple DSOs to share the same
1220
+ tracking table.
1221
+ */
1222
+ VALUE trackings_value = Qnil;
1223
+ /* change the variable name so that we can mix modules
1224
+ compiled with older SWIG's - this used to be called "@__trackings__" */
1225
+ ID trackings_id = rb_intern( "@__safetrackings__" );
1226
+ VALUE verbose = rb_gv_get("VERBOSE");
1227
+ rb_gv_set("VERBOSE", Qfalse);
1228
+ trackings_value = rb_ivar_get( _mSWIG, trackings_id );
1229
+ rb_gv_set("VERBOSE", verbose);
1230
+
1231
+ /* The trick here is that we have to store the hash table
1232
+ pointer in a Ruby variable. We do not want Ruby's GC to
1233
+ treat this pointer as a Ruby object, so we convert it to
1234
+ a Ruby numeric value. */
1235
+ if (trackings_value == Qnil) {
1236
+ /* No, it hasn't. Create one ourselves */
1237
+ swig_ruby_trackings = st_init_numtable();
1238
+ rb_ivar_set( _mSWIG, trackings_id, SWIG2NUM(swig_ruby_trackings) );
1239
+ } else {
1240
+ swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value);
1241
+ }
1242
+
1243
+ rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL);
1244
+ }
1245
+
1246
+ /* Add a Tracking from a C/C++ struct to a Ruby object */
1247
+ SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) {
1248
+ /* Store the mapping to the global hash table. */
1249
+ st_insert(swig_ruby_trackings, (st_data_t)ptr, object);
1250
+ }
1251
+
1252
+ /* Get the Ruby object that owns the specified C/C++ struct */
1253
+ SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) {
1254
+ /* Now lookup the value stored in the global hash table */
1255
+ VALUE value;
1256
+
1257
+ if (st_lookup(swig_ruby_trackings, (st_data_t)ptr, &value)) {
1258
+ return value;
1259
+ } else {
1260
+ return Qnil;
1261
+ }
1262
+ }
1263
+
1264
+ /* Remove a Tracking from a C/C++ struct to a Ruby object. It
1265
+ is very important to remove objects once they are destroyed
1266
+ since the same memory address may be reused later to create
1267
+ a new object. */
1268
+ SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
1269
+ /* Delete the object from the hash table */
1270
+ st_delete(swig_ruby_trackings, (st_data_t *)&ptr, NULL);
1271
+ }
1272
+
1273
+ /* This is a helper method that unlinks a Ruby object from its
1274
+ underlying C++ object. This is needed if the lifetime of the
1275
+ Ruby object is longer than the C++ object. */
1276
+ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
1277
+ VALUE object = SWIG_RubyInstanceFor(ptr);
1278
+
1279
+ if (object != Qnil) {
1280
+ // object might have the T_ZOMBIE type, but that's just
1281
+ // because the GC has flagged it as such for a deferred
1282
+ // destruction. Until then, it's still a T_DATA object.
1283
+ DATA_PTR(object) = 0;
1284
+ }
1285
+ }
1286
+
1287
+ /* This is a helper method that iterates over all the trackings
1288
+ passing the C++ object pointer and its related Ruby object
1289
+ to the passed callback function. */
1290
+
1291
+ /* Proxy method to abstract the internal trackings datatype */
1292
+ static int swig_ruby_internal_iterate_callback(void* ptr, VALUE obj, void(*meth)(void* ptr, VALUE obj)) {
1293
+ (*meth)(ptr, obj);
1294
+ return ST_CONTINUE;
1295
+ }
1296
+
1297
+ SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) {
1298
+ st_foreach(swig_ruby_trackings, (int (*)(ANYARGS))&swig_ruby_internal_iterate_callback, (st_data_t)meth);
1299
+ }
1300
+
1301
+ #ifdef __cplusplus
1302
+ }
1303
+ #endif
1304
+
1305
+ /* -----------------------------------------------------------------------------
1306
+ * Ruby API portion that goes into the runtime
1307
+ * ----------------------------------------------------------------------------- */
1308
+
1309
+ #ifdef __cplusplus
1310
+ extern "C" {
1311
+ #endif
1312
+
1313
+ SWIGINTERN VALUE
1314
+ SWIG_Ruby_AppendOutput(VALUE target, VALUE o) {
1315
+ if (NIL_P(target)) {
1316
+ target = o;
1317
+ } else {
1318
+ if (TYPE(target) != T_ARRAY) {
1319
+ VALUE o2 = target;
1320
+ target = rb_ary_new();
1321
+ rb_ary_push(target, o2);
1322
+ }
1323
+ rb_ary_push(target, o);
1324
+ }
1325
+ return target;
1326
+ }
1327
+
1328
+ /* For ruby1.8.4 and earlier. */
1329
+ #ifndef RUBY_INIT_STACK
1330
+ RUBY_EXTERN void Init_stack(VALUE* addr);
1331
+ # define RUBY_INIT_STACK \
1332
+ VALUE variable_in_this_stack_frame; \
1333
+ Init_stack(&variable_in_this_stack_frame);
1334
+ #endif
1335
+
1336
+
1337
+ #ifdef __cplusplus
1338
+ }
1339
+ #endif
1340
+
1341
+
1342
+ /* -----------------------------------------------------------------------------
1343
+ * rubyrun.swg
1344
+ *
1345
+ * This file contains the runtime support for Ruby modules
1346
+ * and includes code for managing global variables and pointer
1347
+ * type checking.
1348
+ * ----------------------------------------------------------------------------- */
1349
+
1350
+ /* For backward compatibility only */
1351
+ #define SWIG_POINTER_EXCEPTION 0
1352
+
1353
+ /* for raw pointers */
1354
+ #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
1355
+ #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own)
1356
+ #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
1357
+ #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own)
1358
+ #define swig_owntype swig_ruby_owntype
1359
+
1360
+ /* for raw packed data */
1361
+ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
1362
+ #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
1363
+
1364
+ /* for class or struct pointers */
1365
+ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
1366
+ #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
1367
+
1368
+ /* for C or C++ function pointers */
1369
+ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
1370
+ #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
1371
+
1372
+ /* for C++ member pointers, ie, member methods */
1373
+ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty)
1374
+ #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
1375
+
1376
+
1377
+ /* Runtime API */
1378
+
1379
+ #define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule(clientdata)
1380
+ #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer)
1381
+
1382
+
1383
+ /* Error manipulation */
1384
+
1385
+ #define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
1386
+ #define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), "%s", msg)
1387
+ #define SWIG_fail goto fail
1388
+
1389
+
1390
+ /* Ruby-specific SWIG API */
1391
+
1392
+ #define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
1393
+ #define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
1394
+ #define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty)
1395
+ #define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value)
1396
+ #define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty)
1397
+
1398
+ #include "assert.h"
1399
+
1400
+ /* -----------------------------------------------------------------------------
1401
+ * pointers/data manipulation
1402
+ * ----------------------------------------------------------------------------- */
1403
+
1404
+ #ifdef __cplusplus
1405
+ extern "C" {
1406
+ #endif
1407
+
1408
+ typedef struct {
1409
+ VALUE klass;
1410
+ VALUE mImpl;
1411
+ void (*mark)(void *);
1412
+ void (*destroy)(void *);
1413
+ int trackObjects;
1414
+ } swig_class;
1415
+
1416
+
1417
+ /* Global pointer used to keep some internal SWIG stuff */
1418
+ static VALUE _cSWIG_Pointer = Qnil;
1419
+ static VALUE swig_runtime_data_type_pointer = Qnil;
1420
+
1421
+ /* Global IDs used to keep some internal SWIG stuff */
1422
+ static ID swig_arity_id = 0;
1423
+ static ID swig_call_id = 0;
1424
+
1425
+ /*
1426
+ If your swig extension is to be run within an embedded ruby and has
1427
+ director callbacks, you should set -DRUBY_EMBEDDED during compilation.
1428
+ This will reset ruby's stack frame on each entry point from the main
1429
+ program the first time a virtual director function is invoked (in a
1430
+ non-recursive way).
1431
+ If this is not done, you run the risk of Ruby trashing the stack.
1432
+ */
1433
+
1434
+ #ifdef RUBY_EMBEDDED
1435
+
1436
+ # define SWIG_INIT_STACK \
1437
+ if ( !swig_virtual_calls ) { RUBY_INIT_STACK } \
1438
+ ++swig_virtual_calls;
1439
+ # define SWIG_RELEASE_STACK --swig_virtual_calls;
1440
+ # define Ruby_DirectorTypeMismatchException(x) \
1441
+ rb_raise( rb_eTypeError, "%s", x ); return c_result;
1442
+
1443
+ static unsigned int swig_virtual_calls = 0;
1444
+
1445
+ #else /* normal non-embedded extension */
1446
+
1447
+ # define SWIG_INIT_STACK
1448
+ # define SWIG_RELEASE_STACK
1449
+ # define Ruby_DirectorTypeMismatchException(x) \
1450
+ throw Swig::DirectorTypeMismatchException( x );
1451
+
1452
+ #endif /* RUBY_EMBEDDED */
1453
+
1454
+
1455
+ SWIGRUNTIME VALUE
1456
+ getExceptionClass(void) {
1457
+ static int init = 0;
1458
+ static VALUE rubyExceptionClass ;
1459
+ if (!init) {
1460
+ init = 1;
1461
+ rubyExceptionClass = rb_const_get(_mSWIG, rb_intern("Exception"));
1462
+ }
1463
+ return rubyExceptionClass;
1464
+ }
1465
+
1466
+ /* This code checks to see if the Ruby object being raised as part
1467
+ of an exception inherits from the Ruby class Exception. If so,
1468
+ the object is simply returned. If not, then a new Ruby exception
1469
+ object is created and that will be returned to Ruby.*/
1470
+ SWIGRUNTIME VALUE
1471
+ SWIG_Ruby_ExceptionType(swig_type_info *desc, VALUE obj) {
1472
+ VALUE exceptionClass = getExceptionClass();
1473
+ if (rb_obj_is_kind_of(obj, exceptionClass)) {
1474
+ return obj;
1475
+ } else {
1476
+ return rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj));
1477
+ }
1478
+ }
1479
+
1480
+ /* Initialize Ruby runtime support */
1481
+ SWIGRUNTIME void
1482
+ SWIG_Ruby_InitRuntime(void)
1483
+ {
1484
+ if (_mSWIG == Qnil) {
1485
+ _mSWIG = rb_define_module("SWIG");
1486
+ swig_call_id = rb_intern("call");
1487
+ swig_arity_id = rb_intern("arity");
1488
+ }
1489
+ }
1490
+
1491
+ /* Define Ruby class for C type */
1492
+ SWIGRUNTIME void
1493
+ SWIG_Ruby_define_class(swig_type_info *type)
1494
+ {
1495
+ char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
1496
+ sprintf(klass_name, "TYPE%s", type->name);
1497
+ if (NIL_P(_cSWIG_Pointer)) {
1498
+ _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
1499
+ rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
1500
+ }
1501
+ rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
1502
+ free((void *) klass_name);
1503
+ }
1504
+
1505
+ /* Create a new pointer object */
1506
+ SWIGRUNTIME VALUE
1507
+ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
1508
+ {
1509
+ int own = flags & SWIG_POINTER_OWN;
1510
+ int track;
1511
+ char *klass_name;
1512
+ swig_class *sklass;
1513
+ VALUE klass;
1514
+ VALUE obj;
1515
+
1516
+ if (!ptr)
1517
+ return Qnil;
1518
+
1519
+ assert(type);
1520
+ if (type->clientdata) {
1521
+ sklass = (swig_class *) type->clientdata;
1522
+
1523
+ /* Are we tracking this class and have we already returned this Ruby object? */
1524
+ track = sklass->trackObjects;
1525
+ if (track) {
1526
+ obj = SWIG_RubyInstanceFor(ptr);
1527
+
1528
+ /* Check the object's type and make sure it has the correct type.
1529
+ It might not in cases where methods do things like
1530
+ downcast methods. */
1531
+ if (obj != Qnil) {
1532
+ VALUE value = rb_iv_get(obj, "@__swigtype__");
1533
+ const char* type_name = RSTRING_PTR(value);
1534
+
1535
+ if (strcmp(type->name, type_name) == 0) {
1536
+ return obj;
1537
+ }
1538
+ }
1539
+ }
1540
+
1541
+ /* Create a new Ruby object */
1542
+ obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark),
1543
+ ( own ? VOIDFUNC(sklass->destroy) :
1544
+ (track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 )
1545
+ ), ptr);
1546
+
1547
+ /* If tracking is on for this class then track this object. */
1548
+ if (track) {
1549
+ SWIG_RubyAddTracking(ptr, obj);
1550
+ }
1551
+ } else {
1552
+ klass_name = (char *) malloc(4 + strlen(type->name) + 1);
1553
+ sprintf(klass_name, "TYPE%s", type->name);
1554
+ klass = rb_const_get(_mSWIG, rb_intern(klass_name));
1555
+ free((void *) klass_name);
1556
+ obj = Data_Wrap_Struct(klass, 0, 0, ptr);
1557
+ }
1558
+ rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name));
1559
+
1560
+ return obj;
1561
+ }
1562
+
1563
+ /* Create a new class instance (always owned) */
1564
+ SWIGRUNTIME VALUE
1565
+ SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
1566
+ {
1567
+ VALUE obj;
1568
+ swig_class *sklass = (swig_class *) type->clientdata;
1569
+ obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
1570
+ rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name));
1571
+ return obj;
1572
+ }
1573
+
1574
+ /* Get type mangle from class name */
1575
+ SWIGRUNTIMEINLINE char *
1576
+ SWIG_Ruby_MangleStr(VALUE obj)
1577
+ {
1578
+ VALUE stype = rb_iv_get(obj, "@__swigtype__");
1579
+ return StringValuePtr(stype);
1580
+ }
1581
+
1582
+ /* Acquire a pointer value */
1583
+ typedef struct {
1584
+ void (*datafree)(void *);
1585
+ int own;
1586
+ } swig_ruby_owntype;
1587
+
1588
+ SWIGRUNTIME swig_ruby_owntype
1589
+ SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) {
1590
+ swig_ruby_owntype oldown = {0, 0};
1591
+ if (TYPE(obj) == T_DATA && !RTYPEDDATA_P(obj)) {
1592
+ oldown.datafree = RDATA(obj)->dfree;
1593
+ RDATA(obj)->dfree = own.datafree;
1594
+ }
1595
+ return oldown;
1596
+ }
1597
+
1598
+ /* Convert a pointer value */
1599
+ SWIGRUNTIME int
1600
+ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, swig_ruby_owntype *own)
1601
+ {
1602
+ char *c;
1603
+ swig_cast_info *tc;
1604
+ void *vptr = 0;
1605
+
1606
+ /* Grab the pointer */
1607
+ if (NIL_P(obj)) {
1608
+ if (ptr)
1609
+ *ptr = 0;
1610
+ return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
1611
+ } else {
1612
+ if (TYPE(obj) != T_DATA || (TYPE(obj) == T_DATA && RTYPEDDATA_P(obj))) {
1613
+ return SWIG_ERROR;
1614
+ }
1615
+ Data_Get_Struct(obj, void, vptr);
1616
+ }
1617
+
1618
+ if (own) {
1619
+ own->datafree = RDATA(obj)->dfree;
1620
+ own->own = 0;
1621
+ }
1622
+
1623
+ /* Check to see if the input object is giving up ownership
1624
+ of the underlying C struct or C++ object. If so then we
1625
+ need to reset the destructor since the Ruby object no
1626
+ longer owns the underlying C++ object.*/
1627
+ if (flags & SWIG_POINTER_DISOWN) {
1628
+ /* Is tracking on for this class? */
1629
+ int track = 0;
1630
+ if (ty && ty->clientdata) {
1631
+ swig_class *sklass = (swig_class *) ty->clientdata;
1632
+ track = sklass->trackObjects;
1633
+ }
1634
+
1635
+ if (track) {
1636
+ /* We are tracking objects for this class. Thus we change the destructor
1637
+ * to SWIG_RubyRemoveTracking. This allows us to
1638
+ * remove the mapping from the C++ to Ruby object
1639
+ * when the Ruby object is garbage collected. If we don't
1640
+ * do this, then it is possible we will return a reference
1641
+ * to a Ruby object that no longer exists thereby crashing Ruby. */
1642
+ RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
1643
+ } else {
1644
+ RDATA(obj)->dfree = 0;
1645
+ }
1646
+ }
1647
+
1648
+ /* Do type-checking if type info was provided */
1649
+ if (ty) {
1650
+ if (ty->clientdata) {
1651
+ if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
1652
+ if (vptr == 0) {
1653
+ /* The object has already been deleted */
1654
+ return SWIG_ObjectPreviouslyDeletedError;
1655
+ }
1656
+ }
1657
+ }
1658
+ if ((c = SWIG_MangleStr(obj)) == NULL) {
1659
+ return SWIG_ERROR;
1660
+ }
1661
+ tc = SWIG_TypeCheck(c, ty);
1662
+ if (!tc) {
1663
+ return SWIG_ERROR;
1664
+ } else {
1665
+ if (ptr) {
1666
+ if (tc->type == ty) {
1667
+ *ptr = vptr;
1668
+ } else {
1669
+ int newmemory = 0;
1670
+ *ptr = SWIG_TypeCast(tc, vptr, &newmemory);
1671
+ if (newmemory == SWIG_CAST_NEW_MEMORY) {
1672
+ assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
1673
+ if (own)
1674
+ own->own = own->own | SWIG_CAST_NEW_MEMORY;
1675
+ }
1676
+ }
1677
+ }
1678
+ }
1679
+ } else {
1680
+ if (ptr)
1681
+ *ptr = vptr;
1682
+ }
1683
+
1684
+ return SWIG_OK;
1685
+ }
1686
+
1687
+ /* Check convert */
1688
+ SWIGRUNTIMEINLINE int
1689
+ SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
1690
+ {
1691
+ char *c = SWIG_MangleStr(obj);
1692
+ if (!c) return 0;
1693
+ return SWIG_TypeCheck(c,ty) != 0;
1694
+ }
1695
+
1696
+ SWIGRUNTIME VALUE
1697
+ SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
1698
+ char result[1024];
1699
+ char *r = result;
1700
+ if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
1701
+ *(r++) = '_';
1702
+ r = SWIG_PackData(r, ptr, sz);
1703
+ strcpy(r, type->name);
1704
+ return rb_str_new2(result);
1705
+ }
1706
+
1707
+ /* Convert a packed pointer value */
1708
+ SWIGRUNTIME int
1709
+ SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) {
1710
+ swig_cast_info *tc;
1711
+ const char *c;
1712
+
1713
+ if (TYPE(obj) != T_STRING) goto type_error;
1714
+ c = StringValuePtr(obj);
1715
+ /* Pointer values must start with leading underscore */
1716
+ if (*c != '_') goto type_error;
1717
+ c++;
1718
+ c = SWIG_UnpackData(c, ptr, sz);
1719
+ if (ty) {
1720
+ tc = SWIG_TypeCheck(c, ty);
1721
+ if (!tc) goto type_error;
1722
+ }
1723
+ return SWIG_OK;
1724
+
1725
+ type_error:
1726
+ return SWIG_ERROR;
1727
+ }
1728
+
1729
+ SWIGRUNTIME swig_module_info *
1730
+ SWIG_Ruby_GetModule(void *SWIGUNUSEDPARM(clientdata))
1731
+ {
1732
+ VALUE pointer;
1733
+ swig_module_info *ret = 0;
1734
+ VALUE verbose = rb_gv_get("VERBOSE");
1735
+
1736
+ /* temporarily disable warnings, since the pointer check causes warnings with 'ruby -w' */
1737
+ rb_gv_set("VERBOSE", Qfalse);
1738
+
1739
+ /* first check if pointer already created */
1740
+ pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1741
+ if (pointer != Qnil) {
1742
+ Data_Get_Struct(pointer, swig_module_info, ret);
1743
+ }
1744
+
1745
+ /* reinstate warnings */
1746
+ rb_gv_set("VERBOSE", verbose);
1747
+ return ret;
1748
+ }
1749
+
1750
+ SWIGRUNTIME void
1751
+ SWIG_Ruby_SetModule(swig_module_info *pointer)
1752
+ {
1753
+ /* register a new class */
1754
+ VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
1755
+ /* create and store the structure pointer to a global variable */
1756
+ swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
1757
+ rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
1758
+ }
1759
+
1760
+ /* This function can be used to check whether a proc or method or similarly
1761
+ callable function has been passed. Usually used in a %typecheck, like:
1762
+
1763
+ %typecheck(c_callback_t, precedence=SWIG_TYPECHECK_POINTER) {
1764
+ $result = SWIG_Ruby_isCallable( $input );
1765
+ }
1766
+ */
1767
+ SWIGINTERN
1768
+ int SWIG_Ruby_isCallable( VALUE proc )
1769
+ {
1770
+ if ( rb_respond_to( proc, swig_call_id ) )
1771
+ return 1;
1772
+ return 0;
1773
+ }
1774
+
1775
+ /* This function can be used to check the arity (number of arguments)
1776
+ a proc or method can take. Usually used in a %typecheck.
1777
+ Valid arities will be that equal to minimal or those < 0
1778
+ which indicate a variable number of parameters at the end.
1779
+ */
1780
+ SWIGINTERN
1781
+ int SWIG_Ruby_arity( VALUE proc, int minimal )
1782
+ {
1783
+ if ( rb_respond_to( proc, swig_arity_id ) )
1784
+ {
1785
+ VALUE num = rb_funcall( proc, swig_arity_id, 0 );
1786
+ int arity = NUM2INT(num);
1787
+ if ( arity < 0 && (arity+1) < -minimal ) return 1;
1788
+ if ( arity == minimal ) return 1;
1789
+ return 1;
1790
+ }
1791
+ return 0;
1792
+ }
1793
+
1794
+
1795
+ #ifdef __cplusplus
1796
+ }
1797
+ #endif
1798
+
1799
+
1800
+
1801
+ #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0)
1802
+
1803
+ #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else
1804
+
1805
+
1806
+
1807
+ /* -------- TYPES TABLE (BEGIN) -------- */
1808
+
1809
+ #define SWIGTYPE_p_char swig_types[0]
1810
+ static swig_type_info *swig_types[2];
1811
+ static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
1812
+ #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
1813
+ #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
1814
+
1815
+ /* -------- TYPES TABLE (END) -------- */
1816
+
1817
+ #define SWIG_init Init_libinjection
1818
+ #define SWIG_name "Libinjection"
1819
+
1820
+ static VALUE mLibinjection;
1821
+
1822
+ #define SWIG_RUBY_THREAD_BEGIN_BLOCK
1823
+ #define SWIG_RUBY_THREAD_END_BLOCK
1824
+
1825
+
1826
+ #define SWIGVERSION 0x040001
1827
+ #define SWIG_VERSION SWIGVERSION
1828
+
1829
+
1830
+ #define SWIG_as_voidptr(a) (void *)((const void *)(a))
1831
+ #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a))
1832
+
1833
+
1834
+ #include "libinjection.h"
1835
+ #include "libinjection_sqli.h"
1836
+ #include "libinjection_xss.h"
1837
+
1838
+
1839
+ SWIGINTERN swig_type_info*
1840
+ SWIG_pchar_descriptor(void)
1841
+ {
1842
+ static int init = 0;
1843
+ static swig_type_info* info = 0;
1844
+ if (!init) {
1845
+ info = SWIG_TypeQuery("_p_char");
1846
+ init = 1;
1847
+ }
1848
+ return info;
1849
+ }
1850
+
1851
+
1852
+ SWIGINTERNINLINE VALUE
1853
+ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
1854
+ {
1855
+ if (carray) {
1856
+ if (size > LONG_MAX) {
1857
+ swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
1858
+ return pchar_descriptor ?
1859
+ SWIG_NewPointerObj((char *)(carray), pchar_descriptor, 0) : Qnil;
1860
+ } else {
1861
+ return rb_str_new(carray, (long)(size));
1862
+ }
1863
+ } else {
1864
+ return Qnil;
1865
+ }
1866
+ }
1867
+
1868
+
1869
+ SWIGINTERNINLINE VALUE
1870
+ SWIG_FromCharPtr(const char *cptr)
1871
+ {
1872
+ return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0));
1873
+ }
1874
+
1875
+
1876
+ SWIGINTERN int
1877
+ SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
1878
+ {
1879
+ if (TYPE(obj) == T_STRING) {
1880
+ char *cstr = StringValuePtr(obj);
1881
+ size_t size = RSTRING_LEN(obj) + 1;
1882
+ if (cptr) {
1883
+ if (alloc) {
1884
+ if (*alloc == SWIG_NEWOBJ) {
1885
+ *cptr = (char *)memcpy(malloc((size)*sizeof(char)), cstr, sizeof(char)*(size));
1886
+ } else {
1887
+ *cptr = cstr;
1888
+ *alloc = SWIG_OLDOBJ;
1889
+ }
1890
+ }
1891
+ }
1892
+ if (psize) *psize = size;
1893
+ return SWIG_OK;
1894
+ } else {
1895
+ swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
1896
+ if (pchar_descriptor) {
1897
+ void* vptr = 0;
1898
+ if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
1899
+ if (cptr) *cptr = (char *)vptr;
1900
+ if (psize) *psize = vptr ? (strlen((char*)vptr) + 1) : 0;
1901
+ if (alloc) *alloc = SWIG_OLDOBJ;
1902
+ return SWIG_OK;
1903
+ }
1904
+ }
1905
+ }
1906
+ return SWIG_TypeError;
1907
+ }
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+ SWIGINTERN VALUE
1914
+ SWIG_ruby_failed(void)
1915
+ {
1916
+ return Qnil;
1917
+ }
1918
+
1919
+
1920
+ /*@SWIG:/usr/local/share/swig/4.0.1/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
1921
+ SWIGINTERN VALUE SWIG_AUX_NUM2ULONG(VALUE *args)
1922
+ {
1923
+ VALUE obj = args[0];
1924
+ VALUE type = TYPE(obj);
1925
+ unsigned long *res = (unsigned long *)(args[1]);
1926
+ *res = type == T_FIXNUM ? NUM2ULONG(obj) : rb_big2ulong(obj);
1927
+ return obj;
1928
+ }
1929
+ /*@SWIG@*/
1930
+
1931
+ SWIGINTERN int
1932
+ SWIG_AsVal_unsigned_SS_long (VALUE obj, unsigned long *val)
1933
+ {
1934
+ VALUE type = TYPE(obj);
1935
+ if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
1936
+ unsigned long v;
1937
+ VALUE a[2];
1938
+ a[0] = obj;
1939
+ a[1] = (VALUE)(&v);
1940
+ if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
1941
+ if (val) *val = v;
1942
+ return SWIG_OK;
1943
+ }
1944
+ }
1945
+ return SWIG_TypeError;
1946
+ }
1947
+
1948
+
1949
+ #include <limits.h>
1950
+ #if !defined(SWIG_NO_LLONG_MAX)
1951
+ # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
1952
+ # define LLONG_MAX __LONG_LONG_MAX__
1953
+ # define LLONG_MIN (-LLONG_MAX - 1LL)
1954
+ # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
1955
+ # endif
1956
+ #endif
1957
+
1958
+
1959
+ #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE)
1960
+ # define SWIG_LONG_LONG_AVAILABLE
1961
+ #endif
1962
+
1963
+
1964
+ #ifdef SWIG_LONG_LONG_AVAILABLE
1965
+ /*@SWIG:/usr/local/share/swig/4.0.1/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
1966
+ SWIGINTERN VALUE SWIG_AUX_NUM2ULL(VALUE *args)
1967
+ {
1968
+ VALUE obj = args[0];
1969
+ VALUE type = TYPE(obj);
1970
+ long long *res = (long long *)(args[1]);
1971
+ *res = type == T_FIXNUM ? NUM2ULL(obj) : rb_big2ull(obj);
1972
+ return obj;
1973
+ }
1974
+ /*@SWIG@*/
1975
+
1976
+ SWIGINTERN int
1977
+ SWIG_AsVal_unsigned_SS_long_SS_long (VALUE obj, unsigned long long *val)
1978
+ {
1979
+ VALUE type = TYPE(obj);
1980
+ if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
1981
+ unsigned long long v;
1982
+ VALUE a[2];
1983
+ a[0] = obj;
1984
+ a[1] = (VALUE)(&v);
1985
+ if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
1986
+ if (val) *val = v;
1987
+ return SWIG_OK;
1988
+ }
1989
+ }
1990
+ return SWIG_TypeError;
1991
+ }
1992
+ #endif
1993
+
1994
+
1995
+ SWIGINTERNINLINE int
1996
+ SWIG_AsVal_size_t (VALUE obj, size_t *val)
1997
+ {
1998
+ int res = SWIG_TypeError;
1999
+ #ifdef SWIG_LONG_LONG_AVAILABLE
2000
+ if (sizeof(size_t) <= sizeof(unsigned long)) {
2001
+ #endif
2002
+ unsigned long v;
2003
+ res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0);
2004
+ if (SWIG_IsOK(res) && val) *val = (size_t)(v);
2005
+ #ifdef SWIG_LONG_LONG_AVAILABLE
2006
+ } else if (sizeof(size_t) <= sizeof(unsigned long long)) {
2007
+ unsigned long long v;
2008
+ res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0);
2009
+ if (SWIG_IsOK(res) && val) *val = (size_t)(v);
2010
+ }
2011
+ #endif
2012
+ return res;
2013
+ }
2014
+
2015
+
2016
+ #define SWIG_From_long LONG2NUM
2017
+
2018
+
2019
+ SWIGINTERNINLINE VALUE
2020
+ SWIG_From_int (int value)
2021
+ {
2022
+ return SWIG_From_long (value);
2023
+ }
2024
+
2025
+ SWIGINTERN VALUE
2026
+ _wrap_libinjection_version(int argc, VALUE *argv, VALUE self) {
2027
+ char *result = 0 ;
2028
+ VALUE vresult = Qnil;
2029
+
2030
+ if ((argc < 0) || (argc > 0)) {
2031
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
2032
+ }
2033
+ result = (char *)libinjection_version();
2034
+ vresult = SWIG_FromCharPtr((const char *)result);
2035
+ return vresult;
2036
+ fail:
2037
+ return Qnil;
2038
+ }
2039
+
2040
+
2041
+ SWIGINTERN VALUE
2042
+ _wrap_libinjection_sqli(int argc, VALUE *argv, VALUE self) {
2043
+ char *arg1 = (char *) 0 ;
2044
+ size_t arg2 ;
2045
+ char *arg3 ;
2046
+ int res1 ;
2047
+ char *buf1 = 0 ;
2048
+ int alloc1 = 0 ;
2049
+ size_t val2 ;
2050
+ int ecode2 = 0 ;
2051
+ int res3 ;
2052
+ char *buf3 = 0 ;
2053
+ int alloc3 = 0 ;
2054
+ int result;
2055
+ VALUE vresult = Qnil;
2056
+
2057
+ if ((argc < 3) || (argc > 3)) {
2058
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail;
2059
+ }
2060
+ res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
2061
+ if (!SWIG_IsOK(res1)) {
2062
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","libinjection_sqli", 1, argv[0] ));
2063
+ }
2064
+ arg1 = (char *)(buf1);
2065
+ ecode2 = SWIG_AsVal_size_t(argv[1], &val2);
2066
+ if (!SWIG_IsOK(ecode2)) {
2067
+ SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "size_t","libinjection_sqli", 2, argv[1] ));
2068
+ }
2069
+ arg2 = (size_t)(val2);
2070
+ res3 = SWIG_AsCharPtrAndSize(argv[2], &buf3, NULL, &alloc3);
2071
+ if (!SWIG_IsOK(res3)) {
2072
+ SWIG_exception_fail(SWIG_ArgError(res3), Ruby_Format_TypeError( "", "char []","libinjection_sqli", 3, argv[2] ));
2073
+ }
2074
+ arg3 = (char *)(buf3);
2075
+ result = (int)libinjection_sqli((char const *)arg1,arg2,arg3);
2076
+ vresult = SWIG_From_int((int)(result));
2077
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
2078
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
2079
+ return vresult;
2080
+ fail:
2081
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
2082
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
2083
+ return Qnil;
2084
+ }
2085
+
2086
+
2087
+ SWIGINTERN VALUE
2088
+ _wrap_libinjection_xss(int argc, VALUE *argv, VALUE self) {
2089
+ char *arg1 = (char *) 0 ;
2090
+ size_t arg2 ;
2091
+ int res1 ;
2092
+ char *buf1 = 0 ;
2093
+ int alloc1 = 0 ;
2094
+ size_t val2 ;
2095
+ int ecode2 = 0 ;
2096
+ int result;
2097
+ VALUE vresult = Qnil;
2098
+
2099
+ if ((argc < 2) || (argc > 2)) {
2100
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail;
2101
+ }
2102
+ res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
2103
+ if (!SWIG_IsOK(res1)) {
2104
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","libinjection_xss", 1, argv[0] ));
2105
+ }
2106
+ arg1 = (char *)(buf1);
2107
+ ecode2 = SWIG_AsVal_size_t(argv[1], &val2);
2108
+ if (!SWIG_IsOK(ecode2)) {
2109
+ SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "size_t","libinjection_xss", 2, argv[1] ));
2110
+ }
2111
+ arg2 = (size_t)(val2);
2112
+ result = (int)libinjection_xss((char const *)arg1,arg2);
2113
+ vresult = SWIG_From_int((int)(result));
2114
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
2115
+ return vresult;
2116
+ fail:
2117
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
2118
+ return Qnil;
2119
+ }
2120
+
2121
+
2122
+
2123
+ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
2124
+
2125
+ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
2126
+
2127
+ static swig_type_info *swig_type_initial[] = {
2128
+ &_swigt__p_char,
2129
+ };
2130
+
2131
+ static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
2132
+
2133
+ static swig_cast_info *swig_cast_initial[] = {
2134
+ _swigc__p_char,
2135
+ };
2136
+
2137
+
2138
+ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
2139
+
2140
+ /* -----------------------------------------------------------------------------
2141
+ * Type initialization:
2142
+ * This problem is tough by the requirement that no dynamic
2143
+ * memory is used. Also, since swig_type_info structures store pointers to
2144
+ * swig_cast_info structures and swig_cast_info structures store pointers back
2145
+ * to swig_type_info structures, we need some lookup code at initialization.
2146
+ * The idea is that swig generates all the structures that are needed.
2147
+ * The runtime then collects these partially filled structures.
2148
+ * The SWIG_InitializeModule function takes these initial arrays out of
2149
+ * swig_module, and does all the lookup, filling in the swig_module.types
2150
+ * array with the correct data and linking the correct swig_cast_info
2151
+ * structures together.
2152
+ *
2153
+ * The generated swig_type_info structures are assigned statically to an initial
2154
+ * array. We just loop through that array, and handle each type individually.
2155
+ * First we lookup if this type has been already loaded, and if so, use the
2156
+ * loaded structure instead of the generated one. Then we have to fill in the
2157
+ * cast linked list. The cast data is initially stored in something like a
2158
+ * two-dimensional array. Each row corresponds to a type (there are the same
2159
+ * number of rows as there are in the swig_type_initial array). Each entry in
2160
+ * a column is one of the swig_cast_info structures for that type.
2161
+ * The cast_initial array is actually an array of arrays, because each row has
2162
+ * a variable number of columns. So to actually build the cast linked list,
2163
+ * we find the array of casts associated with the type, and loop through it
2164
+ * adding the casts to the list. The one last trick we need to do is making
2165
+ * sure the type pointer in the swig_cast_info struct is correct.
2166
+ *
2167
+ * First off, we lookup the cast->type name to see if it is already loaded.
2168
+ * There are three cases to handle:
2169
+ * 1) If the cast->type has already been loaded AND the type we are adding
2170
+ * casting info to has not been loaded (it is in this module), THEN we
2171
+ * replace the cast->type pointer with the type pointer that has already
2172
+ * been loaded.
2173
+ * 2) If BOTH types (the one we are adding casting info to, and the
2174
+ * cast->type) are loaded, THEN the cast info has already been loaded by
2175
+ * the previous module so we just ignore it.
2176
+ * 3) Finally, if cast->type has not already been loaded, then we add that
2177
+ * swig_cast_info to the linked list (because the cast->type) pointer will
2178
+ * be correct.
2179
+ * ----------------------------------------------------------------------------- */
2180
+
2181
+ #ifdef __cplusplus
2182
+ extern "C" {
2183
+ #if 0
2184
+ } /* c-mode */
2185
+ #endif
2186
+ #endif
2187
+
2188
+ #if 0
2189
+ #define SWIGRUNTIME_DEBUG
2190
+ #endif
2191
+
2192
+
2193
+ SWIGRUNTIME void
2194
+ SWIG_InitializeModule(void *clientdata) {
2195
+ size_t i;
2196
+ swig_module_info *module_head, *iter;
2197
+ int init;
2198
+
2199
+ /* check to see if the circular list has been setup, if not, set it up */
2200
+ if (swig_module.next==0) {
2201
+ /* Initialize the swig_module */
2202
+ swig_module.type_initial = swig_type_initial;
2203
+ swig_module.cast_initial = swig_cast_initial;
2204
+ swig_module.next = &swig_module;
2205
+ init = 1;
2206
+ } else {
2207
+ init = 0;
2208
+ }
2209
+
2210
+ /* Try and load any already created modules */
2211
+ module_head = SWIG_GetModule(clientdata);
2212
+ if (!module_head) {
2213
+ /* This is the first module loaded for this interpreter */
2214
+ /* so set the swig module into the interpreter */
2215
+ SWIG_SetModule(clientdata, &swig_module);
2216
+ } else {
2217
+ /* the interpreter has loaded a SWIG module, but has it loaded this one? */
2218
+ iter=module_head;
2219
+ do {
2220
+ if (iter==&swig_module) {
2221
+ /* Our module is already in the list, so there's nothing more to do. */
2222
+ return;
2223
+ }
2224
+ iter=iter->next;
2225
+ } while (iter!= module_head);
2226
+
2227
+ /* otherwise we must add our module into the list */
2228
+ swig_module.next = module_head->next;
2229
+ module_head->next = &swig_module;
2230
+ }
2231
+
2232
+ /* When multiple interpreters are used, a module could have already been initialized in
2233
+ a different interpreter, but not yet have a pointer in this interpreter.
2234
+ In this case, we do not want to continue adding types... everything should be
2235
+ set up already */
2236
+ if (init == 0) return;
2237
+
2238
+ /* Now work on filling in swig_module.types */
2239
+ #ifdef SWIGRUNTIME_DEBUG
2240
+ printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
2241
+ #endif
2242
+ for (i = 0; i < swig_module.size; ++i) {
2243
+ swig_type_info *type = 0;
2244
+ swig_type_info *ret;
2245
+ swig_cast_info *cast;
2246
+
2247
+ #ifdef SWIGRUNTIME_DEBUG
2248
+ printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
2249
+ #endif
2250
+
2251
+ /* if there is another module already loaded */
2252
+ if (swig_module.next != &swig_module) {
2253
+ type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
2254
+ }
2255
+ if (type) {
2256
+ /* Overwrite clientdata field */
2257
+ #ifdef SWIGRUNTIME_DEBUG
2258
+ printf("SWIG_InitializeModule: found type %s\n", type->name);
2259
+ #endif
2260
+ if (swig_module.type_initial[i]->clientdata) {
2261
+ type->clientdata = swig_module.type_initial[i]->clientdata;
2262
+ #ifdef SWIGRUNTIME_DEBUG
2263
+ printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
2264
+ #endif
2265
+ }
2266
+ } else {
2267
+ type = swig_module.type_initial[i];
2268
+ }
2269
+
2270
+ /* Insert casting types */
2271
+ cast = swig_module.cast_initial[i];
2272
+ while (cast->type) {
2273
+
2274
+ /* Don't need to add information already in the list */
2275
+ ret = 0;
2276
+ #ifdef SWIGRUNTIME_DEBUG
2277
+ printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
2278
+ #endif
2279
+ if (swig_module.next != &swig_module) {
2280
+ ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
2281
+ #ifdef SWIGRUNTIME_DEBUG
2282
+ if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
2283
+ #endif
2284
+ }
2285
+ if (ret) {
2286
+ if (type == swig_module.type_initial[i]) {
2287
+ #ifdef SWIGRUNTIME_DEBUG
2288
+ printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
2289
+ #endif
2290
+ cast->type = ret;
2291
+ ret = 0;
2292
+ } else {
2293
+ /* Check for casting already in the list */
2294
+ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
2295
+ #ifdef SWIGRUNTIME_DEBUG
2296
+ if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
2297
+ #endif
2298
+ if (!ocast) ret = 0;
2299
+ }
2300
+ }
2301
+
2302
+ if (!ret) {
2303
+ #ifdef SWIGRUNTIME_DEBUG
2304
+ printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
2305
+ #endif
2306
+ if (type->cast) {
2307
+ type->cast->prev = cast;
2308
+ cast->next = type->cast;
2309
+ }
2310
+ type->cast = cast;
2311
+ }
2312
+ cast++;
2313
+ }
2314
+ /* Set entry in modules->types array equal to the type */
2315
+ swig_module.types[i] = type;
2316
+ }
2317
+ swig_module.types[i] = 0;
2318
+
2319
+ #ifdef SWIGRUNTIME_DEBUG
2320
+ printf("**** SWIG_InitializeModule: Cast List ******\n");
2321
+ for (i = 0; i < swig_module.size; ++i) {
2322
+ int j = 0;
2323
+ swig_cast_info *cast = swig_module.cast_initial[i];
2324
+ printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
2325
+ while (cast->type) {
2326
+ printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
2327
+ cast++;
2328
+ ++j;
2329
+ }
2330
+ printf("---- Total casts: %d\n",j);
2331
+ }
2332
+ printf("**** SWIG_InitializeModule: Cast List ******\n");
2333
+ #endif
2334
+ }
2335
+
2336
+ /* This function will propagate the clientdata field of type to
2337
+ * any new swig_type_info structures that have been added into the list
2338
+ * of equivalent types. It is like calling
2339
+ * SWIG_TypeClientData(type, clientdata) a second time.
2340
+ */
2341
+ SWIGRUNTIME void
2342
+ SWIG_PropagateClientData(void) {
2343
+ size_t i;
2344
+ swig_cast_info *equiv;
2345
+ static int init_run = 0;
2346
+
2347
+ if (init_run) return;
2348
+ init_run = 1;
2349
+
2350
+ for (i = 0; i < swig_module.size; i++) {
2351
+ if (swig_module.types[i]->clientdata) {
2352
+ equiv = swig_module.types[i]->cast;
2353
+ while (equiv) {
2354
+ if (!equiv->converter) {
2355
+ if (equiv->type && !equiv->type->clientdata)
2356
+ SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
2357
+ }
2358
+ equiv = equiv->next;
2359
+ }
2360
+ }
2361
+ }
2362
+ }
2363
+
2364
+ #ifdef __cplusplus
2365
+ #if 0
2366
+ { /* c-mode */
2367
+ #endif
2368
+ }
2369
+ #endif
2370
+
2371
+ /*
2372
+
2373
+ */
2374
+ #ifdef __cplusplus
2375
+ extern "C"
2376
+ #endif
2377
+ SWIGEXPORT void Init_libinjection(void) {
2378
+ size_t i;
2379
+
2380
+ SWIG_InitRuntime();
2381
+ mLibinjection = rb_define_module("Libinjection");
2382
+
2383
+ SWIG_InitializeModule(0);
2384
+ for (i = 0; i < swig_module.size; i++) {
2385
+ SWIG_define_class(swig_module.types[i]);
2386
+ }
2387
+
2388
+ SWIG_RubyInitializeTrackings();
2389
+ rb_define_module_function(mLibinjection, "libinjection_version", _wrap_libinjection_version, -1);
2390
+ rb_define_module_function(mLibinjection, "libinjection_sqli", _wrap_libinjection_sqli, -1);
2391
+ rb_define_module_function(mLibinjection, "libinjection_xss", _wrap_libinjection_xss, -1);
2392
+ }
2393
+