xmlsec-ruby 0.0.2

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.
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+ if pkg_config('xmlsec1-openssl')
3
+ create_makefile('xmlsec')
4
+ else
5
+ puts "xmlsec1 is not installed."
6
+ end
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Simple API to sign a string and return a string using xmlsec
3
+ * All credit for this file goes to John Kemp
4
+ * Unfortunately his site is long gone, but archive.org
5
+ * has preserved it for posterity:
6
+ * http://web.archive.org/web/20060430071452/http://web.mac.com/john.kemp/php-xml-sig.html
7
+ */
8
+
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <assert.h>
12
+
13
+ #include <libxml/tree.h>
14
+ #include <libxml/xmlmemory.h>
15
+ #include <libxml/parser.h>
16
+
17
+ #include <xmlsec/xmlsec.h>
18
+ #include <xmlsec/xmltree.h>
19
+ #include <xmlsec/xmldsig.h>
20
+ #include <xmlsec/xmlenc.h>
21
+ #include <xmlsec/crypto.h>
22
+ #include <xmlsec/bn.h>
23
+
24
+
25
+ int initialize() ;
26
+ void SecShutdown() ;
27
+ static int
28
+ xmlSecAppAddIDAttr(xmlNodePtr node, const xmlChar* attrName, const xmlChar* nodeName, const xmlChar* nsHref) {
29
+ xmlAttrPtr attr, tmpAttr;
30
+ xmlNodePtr cur;
31
+ xmlChar* id;
32
+
33
+ if((node == NULL) || (attrName == NULL) || (nodeName == NULL)) {
34
+ return(-1);
35
+ }
36
+
37
+ /* process children first because it does not matter much but does simplify code */
38
+ cur = xmlSecGetNextElementNode(node->children);
39
+ while(cur != NULL) {
40
+ if(xmlSecAppAddIDAttr(cur, attrName, nodeName, nsHref) < 0) {
41
+ return(-1);
42
+ }
43
+ cur = xmlSecGetNextElementNode(cur->next);
44
+ }
45
+
46
+ /* node name must match */
47
+ if(!xmlStrEqual(node->name, nodeName)) {
48
+ return(0);
49
+ }
50
+
51
+ /* if nsHref is set then it also should match */
52
+ if((nsHref != NULL) && (node->ns != NULL) && (!xmlStrEqual(nsHref, node->ns->href))) {
53
+ return(0);
54
+ }
55
+
56
+ /* the attribute with name equal to attrName should exist */
57
+ for(attr = node->properties; attr != NULL; attr = attr->next) {
58
+ if(xmlStrEqual(attr->name, attrName)) {
59
+ break;
60
+ }
61
+ }
62
+ if(attr == NULL) {
63
+ return(0);
64
+ }
65
+
66
+ /* and this attr should have a value */
67
+ id = xmlNodeListGetString(node->doc, attr->children, 1);
68
+ if(id == NULL) {
69
+ return(0);
70
+ }
71
+
72
+ /* check that we don't have same ID already */
73
+ tmpAttr = xmlGetID(node->doc, id);
74
+ if(tmpAttr == NULL) {
75
+ xmlAddID(NULL, node->doc, id, attr);
76
+ } else if(tmpAttr != attr) {
77
+ fprintf(stderr, "Error: duplicate ID attribute \"%s\"\n", id);
78
+ xmlFree(id);
79
+ return(-1);
80
+ }
81
+ xmlFree(id);
82
+ return(0);
83
+ }
84
+
85
+ /* functions */
86
+ int verify_file(const char* xmlMessage, const char* key) {
87
+ xmlDocPtr doc = NULL;
88
+ xmlNodePtr node = NULL;
89
+ xmlSecDSigCtxPtr dsigCtx = NULL;
90
+ int res = 0;
91
+ initialize();
92
+
93
+ assert(xmlMessage);
94
+ assert(key);
95
+
96
+ doc = xmlParseDoc((xmlChar *) xmlMessage) ;
97
+
98
+ if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
99
+ fprintf(stderr, "Error: unable to parse file \"%s\"\n", xmlMessage);
100
+ goto done;
101
+ }
102
+
103
+ /* find start node */
104
+ node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
105
+ if(node == NULL) {
106
+ fprintf(stdout, "Error: start node not found in \"%s\"\n", xmlMessage);
107
+ goto done;
108
+ }
109
+
110
+ xmlNodePtr cur = xmlSecGetNextElementNode(doc->children);
111
+ while(cur != NULL) {
112
+ if(xmlSecAppAddIDAttr(cur, "ID", "Response", "urn:oasis:names:tc:SAML:2.0:protocol") < 0) {
113
+ fprintf(stderr, "Error: failed to add ID attribute");
114
+ goto done;
115
+ }
116
+ cur = xmlSecGetNextElementNode(cur->next);
117
+ }
118
+
119
+ /* create signature context */
120
+ dsigCtx = xmlSecDSigCtxCreate(NULL);
121
+ if(dsigCtx == NULL) {
122
+ fprintf(stdout,"Error: failed to create signature context\n");
123
+ goto done;
124
+ }
125
+
126
+ /* load public key */
127
+ dsigCtx->signKey = xmlSecCryptoAppKeyLoadMemory(key, strlen(key), xmlSecKeyDataFormatCertPem, NULL, NULL, NULL);
128
+ if(dsigCtx->signKey == NULL) {
129
+ fprintf(stdout,"Error: failed to load public pem key from \"%s\"\n", key);
130
+ goto done;
131
+ }
132
+
133
+ /* set key name to the file name, this is just an example! */
134
+ if(xmlSecKeySetName(dsigCtx->signKey, key) < 0) {
135
+ fprintf(stdout,"Error: failed to set key name for key from \"%s\"\n", key);
136
+ goto done;
137
+ }
138
+
139
+ /* Verify signature */
140
+ if(xmlSecDSigCtxVerify(dsigCtx, node) < 0) {
141
+ fprintf(stdout,"Error: signature verify\n");
142
+ goto done;
143
+ }
144
+
145
+ /* print verification result to stdout */
146
+ if(dsigCtx->status == xmlSecDSigStatusSucceeded) {
147
+ fprintf(stdout, "Signature is OK\n");
148
+ } else {
149
+ fprintf(stdout, "Signature is INVALID\n");
150
+ }
151
+
152
+ /* success */
153
+ res = 1;
154
+
155
+ done:
156
+ /* cleanup */
157
+ if(dsigCtx != NULL) {
158
+ xmlSecDSigCtxDestroy(dsigCtx);
159
+ }
160
+
161
+ SecShutdown() ;
162
+
163
+ return(res);
164
+ }
165
+
166
+ int initialize()
167
+ {
168
+ /* Init libxml and libxslt libraries */
169
+ xmlInitParser();
170
+ LIBXML_TEST_VERSION
171
+ xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
172
+ xmlSubstituteEntitiesDefault(1);
173
+
174
+ /* Init xmlsec library */
175
+ if(xmlSecInit() < 0) {
176
+ fprintf(stdout, "Error: xmlsec initialization failed.\n");
177
+ fflush(stdout) ;
178
+ return(-1);
179
+ }
180
+
181
+ /* Check loaded library version */
182
+ if(xmlSecCheckVersion() != 1) {
183
+ fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n");
184
+ return(-1);
185
+ }
186
+
187
+ /* Load default crypto engine if we are supporting dynamic
188
+ * loading for xmlsec-crypto libraries. Use the crypto library
189
+ * name ("openssl", "nss", etc.) to load corresponding
190
+ * xmlsec-crypto library.
191
+ */
192
+ #ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
193
+ if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) {
194
+ fprintf(stdout, "Error: unable to load default xmlsec-crypto library. Make sure\n"
195
+ "that you have it installed and check shared libraries path\n"
196
+ "(LD_LIBRARY_PATH) envornment variable.\n");
197
+ fflush(stdout) ;
198
+ return(-1);
199
+ }
200
+ #endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
201
+
202
+ /* Init crypto library */
203
+ if(xmlSecCryptoAppInit(NULL) < 0) {
204
+ fprintf(stderr, "Error: crypto initialization failed.\n");
205
+ return(-1);
206
+ }
207
+
208
+ /* Init xmlsec-crypto library */
209
+ if(xmlSecCryptoInit() < 0) {
210
+ fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n");
211
+ return(-1);
212
+ }
213
+ }
214
+
215
+ void SecShutdown()
216
+ {
217
+ /* Shutdown xmlsec-crypto library */
218
+ xmlSecCryptoShutdown();
219
+
220
+ /* Shutdown crypto library */
221
+ xmlSecCryptoAppShutdown();
222
+
223
+ /* Shutdown xmlsec library */
224
+ xmlSecShutdown();
225
+
226
+ /* Shutdown libxslt/libxml */
227
+ #ifndef XMLSEC_NO_XSLT
228
+ xsltCleanupGlobals();
229
+ #endif /* XMLSEC_NO_XSLT */
230
+ xmlCleanupParser();
231
+ return ;
232
+ }
@@ -0,0 +1,1928 @@
1
+ /* ----------------------------------------------------------------------------
2
+ * This file was automatically generated by SWIG (http://www.swig.org).
3
+ * Version 2.0.0
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
+ #define SWIGRUBY
12
+
13
+ /* -----------------------------------------------------------------------------
14
+ * This section contains generic SWIG labels for method/variable
15
+ * declarations/attributes, and other compiler dependent labels.
16
+ * ----------------------------------------------------------------------------- */
17
+
18
+ /* template workaround for compilers that cannot correctly implement the C++ standard */
19
+ #ifndef SWIGTEMPLATEDISAMBIGUATOR
20
+ # if defined(__SUNPRO_CC)
21
+ # if (__SUNPRO_CC <= 0x560)
22
+ # define SWIGTEMPLATEDISAMBIGUATOR template
23
+ # else
24
+ # define SWIGTEMPLATEDISAMBIGUATOR
25
+ # endif
26
+ # else
27
+ # define SWIGTEMPLATEDISAMBIGUATOR
28
+ # endif
29
+ #endif
30
+
31
+ /* inline attribute */
32
+ #ifndef SWIGINLINE
33
+ # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
34
+ # define SWIGINLINE inline
35
+ # else
36
+ # define SWIGINLINE
37
+ # endif
38
+ #endif
39
+
40
+ /* attribute recognised by some compilers to avoid 'unused' warnings */
41
+ #ifndef SWIGUNUSED
42
+ # if defined(__GNUC__)
43
+ # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
44
+ # define SWIGUNUSED __attribute__ ((__unused__))
45
+ # else
46
+ # define SWIGUNUSED
47
+ # endif
48
+ # elif defined(__ICC)
49
+ # define SWIGUNUSED __attribute__ ((__unused__))
50
+ # else
51
+ # define SWIGUNUSED
52
+ # endif
53
+ #endif
54
+
55
+ #ifndef SWIGUNUSEDPARM
56
+ # ifdef __cplusplus
57
+ # define SWIGUNUSEDPARM(p)
58
+ # else
59
+ # define SWIGUNUSEDPARM(p) p SWIGUNUSED
60
+ # endif
61
+ #endif
62
+
63
+ /* internal SWIG method */
64
+ #ifndef SWIGINTERN
65
+ # define SWIGINTERN static SWIGUNUSED
66
+ #endif
67
+
68
+ /* internal inline SWIG method */
69
+ #ifndef SWIGINTERNINLINE
70
+ # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
71
+ #endif
72
+
73
+ /* exporting methods */
74
+ #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
75
+ # ifndef GCC_HASCLASSVISIBILITY
76
+ # define GCC_HASCLASSVISIBILITY
77
+ # endif
78
+ #endif
79
+
80
+ #ifndef SWIGEXPORT
81
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
82
+ # if defined(STATIC_LINKED)
83
+ # define SWIGEXPORT
84
+ # else
85
+ # define SWIGEXPORT __declspec(dllexport)
86
+ # endif
87
+ # else
88
+ # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
89
+ # define SWIGEXPORT __attribute__ ((visibility("default")))
90
+ # else
91
+ # define SWIGEXPORT
92
+ # endif
93
+ # endif
94
+ #endif
95
+
96
+ /* calling conventions for Windows */
97
+ #ifndef SWIGSTDCALL
98
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
99
+ # define SWIGSTDCALL __stdcall
100
+ # else
101
+ # define SWIGSTDCALL
102
+ # endif
103
+ #endif
104
+
105
+ /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
106
+ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
107
+ # define _CRT_SECURE_NO_DEPRECATE
108
+ #endif
109
+
110
+ /* -----------------------------------------------------------------------------
111
+ * This section contains generic SWIG labels for method/variable
112
+ * declarations/attributes, and other compiler dependent labels.
113
+ * ----------------------------------------------------------------------------- */
114
+
115
+ /* template workaround for compilers that cannot correctly implement the C++ standard */
116
+ #ifndef SWIGTEMPLATEDISAMBIGUATOR
117
+ # if defined(__SUNPRO_CC)
118
+ # if (__SUNPRO_CC <= 0x560)
119
+ # define SWIGTEMPLATEDISAMBIGUATOR template
120
+ # else
121
+ # define SWIGTEMPLATEDISAMBIGUATOR
122
+ # endif
123
+ # else
124
+ # define SWIGTEMPLATEDISAMBIGUATOR
125
+ # endif
126
+ #endif
127
+
128
+ /* inline attribute */
129
+ #ifndef SWIGINLINE
130
+ # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
131
+ # define SWIGINLINE inline
132
+ # else
133
+ # define SWIGINLINE
134
+ # endif
135
+ #endif
136
+
137
+ /* attribute recognised by some compilers to avoid 'unused' warnings */
138
+ #ifndef SWIGUNUSED
139
+ # if defined(__GNUC__)
140
+ # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
141
+ # define SWIGUNUSED __attribute__ ((__unused__))
142
+ # else
143
+ # define SWIGUNUSED
144
+ # endif
145
+ # elif defined(__ICC)
146
+ # define SWIGUNUSED __attribute__ ((__unused__))
147
+ # else
148
+ # define SWIGUNUSED
149
+ # endif
150
+ #endif
151
+
152
+ #ifndef SWIGUNUSEDPARM
153
+ # ifdef __cplusplus
154
+ # define SWIGUNUSEDPARM(p)
155
+ # else
156
+ # define SWIGUNUSEDPARM(p) p SWIGUNUSED
157
+ # endif
158
+ #endif
159
+
160
+ /* internal SWIG method */
161
+ #ifndef SWIGINTERN
162
+ # define SWIGINTERN static SWIGUNUSED
163
+ #endif
164
+
165
+ /* internal inline SWIG method */
166
+ #ifndef SWIGINTERNINLINE
167
+ # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
168
+ #endif
169
+
170
+ /* exporting methods */
171
+ #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
172
+ # ifndef GCC_HASCLASSVISIBILITY
173
+ # define GCC_HASCLASSVISIBILITY
174
+ # endif
175
+ #endif
176
+
177
+ #ifndef SWIGEXPORT
178
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
179
+ # if defined(STATIC_LINKED)
180
+ # define SWIGEXPORT
181
+ # else
182
+ # define SWIGEXPORT __declspec(dllexport)
183
+ # endif
184
+ # else
185
+ # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
186
+ # define SWIGEXPORT __attribute__ ((visibility("default")))
187
+ # else
188
+ # define SWIGEXPORT
189
+ # endif
190
+ # endif
191
+ #endif
192
+
193
+ /* calling conventions for Windows */
194
+ #ifndef SWIGSTDCALL
195
+ # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
196
+ # define SWIGSTDCALL __stdcall
197
+ # else
198
+ # define SWIGSTDCALL
199
+ # endif
200
+ #endif
201
+
202
+ /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
203
+ #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
204
+ # define _CRT_SECURE_NO_DEPRECATE
205
+ #endif
206
+
207
+ /* -----------------------------------------------------------------------------
208
+ * swigrun.swg
209
+ *
210
+ * This file contains generic CAPI SWIG runtime support for pointer
211
+ * type checking.
212
+ * ----------------------------------------------------------------------------- */
213
+
214
+ /* This should only be incremented when either the layout of swig_type_info changes,
215
+ or for whatever reason, the runtime changes incompatibly */
216
+ #define SWIG_RUNTIME_VERSION "3"
217
+
218
+ /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
219
+ #ifdef SWIG_TYPE_TABLE
220
+ # define SWIG_QUOTE_STRING(x) #x
221
+ # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
222
+ # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
223
+ #else
224
+ # define SWIG_TYPE_TABLE_NAME
225
+ #endif
226
+
227
+ /*
228
+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
229
+ creating a static or dynamic library from the swig runtime code.
230
+ In 99.9% of the cases, swig just needs to declare them as 'static'.
231
+
232
+ But only do this if is strictly necessary, ie, if you have problems
233
+ with your compiler or so.
234
+ */
235
+
236
+ #ifndef SWIGRUNTIME
237
+ # define SWIGRUNTIME SWIGINTERN
238
+ #endif
239
+
240
+ #ifndef SWIGRUNTIMEINLINE
241
+ # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
242
+ #endif
243
+
244
+ /* Generic buffer size */
245
+ #ifndef SWIG_BUFFER_SIZE
246
+ # define SWIG_BUFFER_SIZE 1024
247
+ #endif
248
+
249
+ /* Flags for pointer conversions */
250
+ #define SWIG_POINTER_DISOWN 0x1
251
+
252
+ /* Flags for new pointer objects */
253
+ #define SWIG_POINTER_OWN 0x1
254
+
255
+
256
+ /*
257
+ Flags/methods for returning states.
258
+
259
+ The swig conversion methods, as ConvertPtr, return and integer
260
+ that tells if the conversion was successful or not. And if not,
261
+ an error code can be returned (see swigerrors.swg for the codes).
262
+
263
+ Use the following macros/flags to set or process the returning
264
+ states.
265
+
266
+ In old swig versions, you usually write code as:
267
+
268
+ if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
269
+ // success code
270
+ } else {
271
+ //fail code
272
+ }
273
+
274
+ Now you can be more explicit as:
275
+
276
+ int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
277
+ if (SWIG_IsOK(res)) {
278
+ // success code
279
+ } else {
280
+ // fail code
281
+ }
282
+
283
+ that seems to be the same, but now you can also do
284
+
285
+ Type *ptr;
286
+ int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
287
+ if (SWIG_IsOK(res)) {
288
+ // success code
289
+ if (SWIG_IsNewObj(res) {
290
+ ...
291
+ delete *ptr;
292
+ } else {
293
+ ...
294
+ }
295
+ } else {
296
+ // fail code
297
+ }
298
+
299
+ I.e., now SWIG_ConvertPtr can return new objects and you can
300
+ identify the case and take care of the deallocation. Of course that
301
+ requires also to SWIG_ConvertPtr to return new result values, as
302
+
303
+ int SWIG_ConvertPtr(obj, ptr,...) {
304
+ if (<obj is ok>) {
305
+ if (<need new object>) {
306
+ *ptr = <ptr to new allocated object>;
307
+ return SWIG_NEWOBJ;
308
+ } else {
309
+ *ptr = <ptr to old object>;
310
+ return SWIG_OLDOBJ;
311
+ }
312
+ } else {
313
+ return SWIG_BADOBJ;
314
+ }
315
+ }
316
+
317
+ Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
318
+ more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
319
+ swig errors code.
320
+
321
+ Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
322
+ allows to return the 'cast rank', for example, if you have this
323
+
324
+ int food(double)
325
+ int fooi(int);
326
+
327
+ and you call
328
+
329
+ food(1) // cast rank '1' (1 -> 1.0)
330
+ fooi(1) // cast rank '0'
331
+
332
+ just use the SWIG_AddCast()/SWIG_CheckState()
333
+
334
+
335
+ */
336
+ #define SWIG_OK (0)
337
+ #define SWIG_ERROR (-1)
338
+ #define SWIG_IsOK(r) (r >= 0)
339
+ #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
340
+
341
+ /* The CastRankLimit says how many bits are used for the cast rank */
342
+ #define SWIG_CASTRANKLIMIT (1 << 8)
343
+ /* The NewMask denotes the object was created (using new/malloc) */
344
+ #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
345
+ /* The TmpMask is for in/out typemaps that use temporal objects */
346
+ #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
347
+ /* Simple returning values */
348
+ #define SWIG_BADOBJ (SWIG_ERROR)
349
+ #define SWIG_OLDOBJ (SWIG_OK)
350
+ #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
351
+ #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
352
+ /* Check, add and del mask methods */
353
+ #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
354
+ #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
355
+ #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
356
+ #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
357
+ #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
358
+ #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
359
+
360
+
361
+ /* Cast-Rank Mode */
362
+ #if defined(SWIG_CASTRANK_MODE)
363
+ # ifndef SWIG_TypeRank
364
+ # define SWIG_TypeRank unsigned long
365
+ # endif
366
+ # ifndef SWIG_MAXCASTRANK /* Default cast allowed */
367
+ # define SWIG_MAXCASTRANK (2)
368
+ # endif
369
+ # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
370
+ # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
371
+ SWIGINTERNINLINE int SWIG_AddCast(int r) {
372
+ return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
373
+ }
374
+ SWIGINTERNINLINE int SWIG_CheckState(int r) {
375
+ return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
376
+ }
377
+ #else /* no cast-rank mode */
378
+ # define SWIG_AddCast
379
+ # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
380
+ #endif
381
+
382
+
383
+
384
+
385
+ #include <string.h>
386
+
387
+ #ifdef __cplusplus
388
+ extern "C" {
389
+ #endif
390
+
391
+ typedef void *(*swig_converter_func)(void *);
392
+ typedef struct swig_type_info *(*swig_dycast_func)(void **);
393
+
394
+ /* Structure to store inforomation on one type */
395
+ typedef struct swig_type_info {
396
+ const char *name; /* mangled name of this type */
397
+ const char *str; /* human readable name of this type */
398
+ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
399
+ struct swig_cast_info *cast; /* linked list of types that can cast into this type */
400
+ void *clientdata; /* language specific type data */
401
+ int owndata; /* flag if the structure owns the clientdata */
402
+ } swig_type_info;
403
+
404
+ /* Structure to store a type and conversion function used for casting */
405
+ typedef struct swig_cast_info {
406
+ swig_type_info *type; /* pointer to type that is equivalent to this type */
407
+ swig_converter_func converter; /* function to cast the void pointers */
408
+ struct swig_cast_info *next; /* pointer to next cast in linked list */
409
+ struct swig_cast_info *prev; /* pointer to the previous cast */
410
+ } swig_cast_info;
411
+
412
+ /* Structure used to store module information
413
+ * Each module generates one structure like this, and the runtime collects
414
+ * all of these structures and stores them in a circularly linked list.*/
415
+ typedef struct swig_module_info {
416
+ swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
417
+ size_t size; /* Number of types in this module */
418
+ struct swig_module_info *next; /* Pointer to next element in circularly linked list */
419
+ swig_type_info **type_initial; /* Array of initially generated type structures */
420
+ swig_cast_info **cast_initial; /* Array of initially generated casting structures */
421
+ void *clientdata; /* Language specific module data */
422
+ } swig_module_info;
423
+
424
+ /*
425
+ Compare two type names skipping the space characters, therefore
426
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
427
+
428
+ Return 0 when the two name types are equivalent, as in
429
+ strncmp, but skipping ' '.
430
+ */
431
+ SWIGRUNTIME int
432
+ SWIG_TypeNameComp(const char *f1, const char *l1,
433
+ const char *f2, const char *l2) {
434
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
435
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
436
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
437
+ if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
438
+ }
439
+ return (l1 - f1) - (l2 - f2);
440
+ }
441
+
442
+ /*
443
+ Check type equivalence in a name list like <name1>|<name2>|...
444
+ Return 0 if not equal, 1 if equal
445
+ */
446
+ SWIGRUNTIME int
447
+ SWIG_TypeEquiv(const char *nb, const char *tb) {
448
+ int equiv = 0;
449
+ const char* te = tb + strlen(tb);
450
+ const char* ne = nb;
451
+ while (!equiv && *ne) {
452
+ for (nb = ne; *ne; ++ne) {
453
+ if (*ne == '|') break;
454
+ }
455
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
456
+ if (*ne) ++ne;
457
+ }
458
+ return equiv;
459
+ }
460
+
461
+ /*
462
+ Check type equivalence in a name list like <name1>|<name2>|...
463
+ Return 0 if equal, -1 if nb < tb, 1 if nb > tb
464
+ */
465
+ SWIGRUNTIME int
466
+ SWIG_TypeCompare(const char *nb, const char *tb) {
467
+ int equiv = 0;
468
+ const char* te = tb + strlen(tb);
469
+ const char* ne = nb;
470
+ while (!equiv && *ne) {
471
+ for (nb = ne; *ne; ++ne) {
472
+ if (*ne == '|') break;
473
+ }
474
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
475
+ if (*ne) ++ne;
476
+ }
477
+ return equiv;
478
+ }
479
+
480
+
481
+ /* think of this as a c++ template<> or a scheme macro */
482
+ #define SWIG_TypeCheck_Template(comparison, ty) \
483
+ if (ty) { \
484
+ swig_cast_info *iter = ty->cast; \
485
+ while (iter) { \
486
+ if (comparison) { \
487
+ if (iter == ty->cast) return iter; \
488
+ /* Move iter to the top of the linked list */ \
489
+ iter->prev->next = iter->next; \
490
+ if (iter->next) \
491
+ iter->next->prev = iter->prev; \
492
+ iter->next = ty->cast; \
493
+ iter->prev = 0; \
494
+ if (ty->cast) ty->cast->prev = iter; \
495
+ ty->cast = iter; \
496
+ return iter; \
497
+ } \
498
+ iter = iter->next; \
499
+ } \
500
+ } \
501
+ return 0
502
+
503
+ /*
504
+ Check the typename
505
+ */
506
+ SWIGRUNTIME swig_cast_info *
507
+ SWIG_TypeCheck(const char *c, swig_type_info *ty) {
508
+ SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
509
+ }
510
+
511
+ /* Same as previous function, except strcmp is replaced with a pointer comparison */
512
+ SWIGRUNTIME swig_cast_info *
513
+ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
514
+ SWIG_TypeCheck_Template(iter->type == from, into);
515
+ }
516
+
517
+ /*
518
+ Cast a pointer up an inheritance hierarchy
519
+ */
520
+ SWIGRUNTIMEINLINE void *
521
+ SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
522
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
523
+ }
524
+
525
+ /*
526
+ Dynamic pointer casting. Down an inheritance hierarchy
527
+ */
528
+ SWIGRUNTIME swig_type_info *
529
+ SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
530
+ swig_type_info *lastty = ty;
531
+ if (!ty || !ty->dcast) return ty;
532
+ while (ty && (ty->dcast)) {
533
+ ty = (*ty->dcast)(ptr);
534
+ if (ty) lastty = ty;
535
+ }
536
+ return lastty;
537
+ }
538
+
539
+ /*
540
+ Return the name associated with this type
541
+ */
542
+ SWIGRUNTIMEINLINE const char *
543
+ SWIG_TypeName(const swig_type_info *ty) {
544
+ return ty->name;
545
+ }
546
+
547
+ /*
548
+ Return the pretty name associated with this type,
549
+ that is an unmangled type name in a form presentable to the user.
550
+ */
551
+ SWIGRUNTIME const char *
552
+ SWIG_TypePrettyName(const swig_type_info *type) {
553
+ /* The "str" field contains the equivalent pretty names of the
554
+ type, separated by vertical-bar characters. We choose
555
+ to print the last name, as it is often (?) the most
556
+ specific. */
557
+ if (!type) return NULL;
558
+ if (type->str != NULL) {
559
+ const char *last_name = type->str;
560
+ const char *s;
561
+ for (s = type->str; *s; s++)
562
+ if (*s == '|') last_name = s+1;
563
+ return last_name;
564
+ }
565
+ else
566
+ return type->name;
567
+ }
568
+
569
+ /*
570
+ Set the clientdata field for a type
571
+ */
572
+ SWIGRUNTIME void
573
+ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
574
+ swig_cast_info *cast = ti->cast;
575
+ /* if (ti->clientdata == clientdata) return; */
576
+ ti->clientdata = clientdata;
577
+
578
+ while (cast) {
579
+ if (!cast->converter) {
580
+ swig_type_info *tc = cast->type;
581
+ if (!tc->clientdata) {
582
+ SWIG_TypeClientData(tc, clientdata);
583
+ }
584
+ }
585
+ cast = cast->next;
586
+ }
587
+ }
588
+ SWIGRUNTIME void
589
+ SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
590
+ SWIG_TypeClientData(ti, clientdata);
591
+ ti->owndata = 1;
592
+ }
593
+
594
+ /*
595
+ Search for a swig_type_info structure only by mangled name
596
+ Search is a O(log #types)
597
+
598
+ We start searching at module start, and finish searching when start == end.
599
+ Note: if start == end at the beginning of the function, we go all the way around
600
+ the circular list.
601
+ */
602
+ SWIGRUNTIME swig_type_info *
603
+ SWIG_MangledTypeQueryModule(swig_module_info *start,
604
+ swig_module_info *end,
605
+ const char *name) {
606
+ swig_module_info *iter = start;
607
+ do {
608
+ if (iter->size) {
609
+ register size_t l = 0;
610
+ register size_t r = iter->size - 1;
611
+ do {
612
+ /* since l+r >= 0, we can (>> 1) instead (/ 2) */
613
+ register size_t i = (l + r) >> 1;
614
+ const char *iname = iter->types[i]->name;
615
+ if (iname) {
616
+ register int compare = strcmp(name, iname);
617
+ if (compare == 0) {
618
+ return iter->types[i];
619
+ } else if (compare < 0) {
620
+ if (i) {
621
+ r = i - 1;
622
+ } else {
623
+ break;
624
+ }
625
+ } else if (compare > 0) {
626
+ l = i + 1;
627
+ }
628
+ } else {
629
+ break; /* should never happen */
630
+ }
631
+ } while (l <= r);
632
+ }
633
+ iter = iter->next;
634
+ } while (iter != end);
635
+ return 0;
636
+ }
637
+
638
+ /*
639
+ Search for a swig_type_info structure for either a mangled name or a human readable name.
640
+ It first searches the mangled names of the types, which is a O(log #types)
641
+ If a type is not found it then searches the human readable names, which is O(#types).
642
+
643
+ We start searching at module start, and finish searching when start == end.
644
+ Note: if start == end at the beginning of the function, we go all the way around
645
+ the circular list.
646
+ */
647
+ SWIGRUNTIME swig_type_info *
648
+ SWIG_TypeQueryModule(swig_module_info *start,
649
+ swig_module_info *end,
650
+ const char *name) {
651
+ /* STEP 1: Search the name field using binary search */
652
+ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
653
+ if (ret) {
654
+ return ret;
655
+ } else {
656
+ /* STEP 2: If the type hasn't been found, do a complete search
657
+ of the str field (the human readable name) */
658
+ swig_module_info *iter = start;
659
+ do {
660
+ register size_t i = 0;
661
+ for (; i < iter->size; ++i) {
662
+ if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
663
+ return iter->types[i];
664
+ }
665
+ iter = iter->next;
666
+ } while (iter != end);
667
+ }
668
+
669
+ /* neither found a match */
670
+ return 0;
671
+ }
672
+
673
+ /*
674
+ Pack binary data into a string
675
+ */
676
+ SWIGRUNTIME char *
677
+ SWIG_PackData(char *c, void *ptr, size_t sz) {
678
+ static const char hex[17] = "0123456789abcdef";
679
+ register const unsigned char *u = (unsigned char *) ptr;
680
+ register const unsigned char *eu = u + sz;
681
+ for (; u != eu; ++u) {
682
+ register unsigned char uu = *u;
683
+ *(c++) = hex[(uu & 0xf0) >> 4];
684
+ *(c++) = hex[uu & 0xf];
685
+ }
686
+ return c;
687
+ }
688
+
689
+ /*
690
+ Unpack binary data from a string
691
+ */
692
+ SWIGRUNTIME const char *
693
+ SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
694
+ register unsigned char *u = (unsigned char *) ptr;
695
+ register const unsigned char *eu = u + sz;
696
+ for (; u != eu; ++u) {
697
+ register char d = *(c++);
698
+ register unsigned char uu;
699
+ if ((d >= '0') && (d <= '9'))
700
+ uu = ((d - '0') << 4);
701
+ else if ((d >= 'a') && (d <= 'f'))
702
+ uu = ((d - ('a'-10)) << 4);
703
+ else
704
+ return (char *) 0;
705
+ d = *(c++);
706
+ if ((d >= '0') && (d <= '9'))
707
+ uu |= (d - '0');
708
+ else if ((d >= 'a') && (d <= 'f'))
709
+ uu |= (d - ('a'-10));
710
+ else
711
+ return (char *) 0;
712
+ *u = uu;
713
+ }
714
+ return c;
715
+ }
716
+
717
+ /*
718
+ Pack 'void *' into a string buffer.
719
+ */
720
+ SWIGRUNTIME char *
721
+ SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
722
+ char *r = buff;
723
+ if ((2*sizeof(void *) + 2) > bsz) return 0;
724
+ *(r++) = '_';
725
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
726
+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
727
+ strcpy(r,name);
728
+ return buff;
729
+ }
730
+
731
+ SWIGRUNTIME const char *
732
+ SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
733
+ if (*c != '_') {
734
+ if (strcmp(c,"NULL") == 0) {
735
+ *ptr = (void *) 0;
736
+ return name;
737
+ } else {
738
+ return 0;
739
+ }
740
+ }
741
+ return SWIG_UnpackData(++c,ptr,sizeof(void *));
742
+ }
743
+
744
+ SWIGRUNTIME char *
745
+ SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
746
+ char *r = buff;
747
+ size_t lname = (name ? strlen(name) : 0);
748
+ if ((2*sz + 2 + lname) > bsz) return 0;
749
+ *(r++) = '_';
750
+ r = SWIG_PackData(r,ptr,sz);
751
+ if (lname) {
752
+ strncpy(r,name,lname+1);
753
+ } else {
754
+ *r = 0;
755
+ }
756
+ return buff;
757
+ }
758
+
759
+ SWIGRUNTIME const char *
760
+ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
761
+ if (*c != '_') {
762
+ if (strcmp(c,"NULL") == 0) {
763
+ memset(ptr,0,sz);
764
+ return name;
765
+ } else {
766
+ return 0;
767
+ }
768
+ }
769
+ return SWIG_UnpackData(++c,ptr,sz);
770
+ }
771
+
772
+ #ifdef __cplusplus
773
+ }
774
+ #endif
775
+
776
+ /* Errors in SWIG */
777
+ #define SWIG_UnknownError -1
778
+ #define SWIG_IOError -2
779
+ #define SWIG_RuntimeError -3
780
+ #define SWIG_IndexError -4
781
+ #define SWIG_TypeError -5
782
+ #define SWIG_DivisionByZero -6
783
+ #define SWIG_OverflowError -7
784
+ #define SWIG_SyntaxError -8
785
+ #define SWIG_ValueError -9
786
+ #define SWIG_SystemError -10
787
+ #define SWIG_AttributeError -11
788
+ #define SWIG_MemoryError -12
789
+ #define SWIG_NullReferenceError -13
790
+
791
+
792
+
793
+ #include <ruby.h>
794
+
795
+ /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
796
+ #ifndef NUM2LL
797
+ #define NUM2LL(x) NUM2LONG((x))
798
+ #endif
799
+ #ifndef LL2NUM
800
+ #define LL2NUM(x) INT2NUM((long) (x))
801
+ #endif
802
+ #ifndef ULL2NUM
803
+ #define ULL2NUM(x) UINT2NUM((unsigned long) (x))
804
+ #endif
805
+
806
+ /* Ruby 1.7 doesn't (yet) define NUM2ULL() */
807
+ #ifndef NUM2ULL
808
+ #ifdef HAVE_LONG_LONG
809
+ #define NUM2ULL(x) rb_num2ull((x))
810
+ #else
811
+ #define NUM2ULL(x) NUM2ULONG(x)
812
+ #endif
813
+ #endif
814
+
815
+ /* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */
816
+ /* Define these for older versions so we can just write code the new way */
817
+ #ifndef RSTRING_LEN
818
+ # define RSTRING_LEN(x) RSTRING(x)->len
819
+ #endif
820
+ #ifndef RSTRING_PTR
821
+ # define RSTRING_PTR(x) RSTRING(x)->ptr
822
+ #endif
823
+ #ifndef RARRAY_LEN
824
+ # define RARRAY_LEN(x) RARRAY(x)->len
825
+ #endif
826
+ #ifndef RARRAY_PTR
827
+ # define RARRAY_PTR(x) RARRAY(x)->ptr
828
+ #endif
829
+
830
+ /*
831
+ * Need to be very careful about how these macros are defined, especially
832
+ * when compiling C++ code or C code with an ANSI C compiler.
833
+ *
834
+ * VALUEFUNC(f) is a macro used to typecast a C function that implements
835
+ * a Ruby method so that it can be passed as an argument to API functions
836
+ * like rb_define_method() and rb_define_singleton_method().
837
+ *
838
+ * VOIDFUNC(f) is a macro used to typecast a C function that implements
839
+ * either the "mark" or "free" stuff for a Ruby Data object, so that it
840
+ * can be passed as an argument to API functions like Data_Wrap_Struct()
841
+ * and Data_Make_Struct().
842
+ */
843
+
844
+ #ifdef __cplusplus
845
+ # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
846
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
847
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
848
+ # define VOIDFUNC(f) ((void (*)()) f)
849
+ # else
850
+ # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
851
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
852
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
853
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
854
+ # else /* These definitions should work for Ruby 1.7+ */
855
+ # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
856
+ # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
857
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
858
+ # endif
859
+ # endif
860
+ #else
861
+ # define VALUEFUNC(f) (f)
862
+ # define VOIDFUNC(f) (f)
863
+ #endif
864
+
865
+ /* Don't use for expressions have side effect */
866
+ #ifndef RB_STRING_VALUE
867
+ #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
868
+ #endif
869
+ #ifndef StringValue
870
+ #define StringValue(s) RB_STRING_VALUE(s)
871
+ #endif
872
+ #ifndef StringValuePtr
873
+ #define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s))
874
+ #endif
875
+ #ifndef StringValueLen
876
+ #define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s))
877
+ #endif
878
+ #ifndef SafeStringValue
879
+ #define SafeStringValue(v) do {\
880
+ StringValue(v);\
881
+ rb_check_safe_str(v);\
882
+ } while (0)
883
+ #endif
884
+
885
+ #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
886
+ #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
887
+ #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
888
+ #endif
889
+
890
+
891
+ /* -----------------------------------------------------------------------------
892
+ * error manipulation
893
+ * ----------------------------------------------------------------------------- */
894
+
895
+
896
+ /* Define some additional error types */
897
+ #define SWIG_ObjectPreviouslyDeletedError -100
898
+
899
+
900
+ /* Define custom exceptions for errors that do not map to existing Ruby
901
+ exceptions. Note this only works for C++ since a global cannot be
902
+ initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
903
+
904
+ SWIGINTERN VALUE
905
+ getNullReferenceError(void) {
906
+ static int init = 0;
907
+ static VALUE rb_eNullReferenceError ;
908
+ if (!init) {
909
+ init = 1;
910
+ rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
911
+ }
912
+ return rb_eNullReferenceError;
913
+ }
914
+
915
+ SWIGINTERN VALUE
916
+ getObjectPreviouslyDeletedError(void) {
917
+ static int init = 0;
918
+ static VALUE rb_eObjectPreviouslyDeleted ;
919
+ if (!init) {
920
+ init = 1;
921
+ rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
922
+ }
923
+ return rb_eObjectPreviouslyDeleted;
924
+ }
925
+
926
+
927
+ SWIGINTERN VALUE
928
+ SWIG_Ruby_ErrorType(int SWIG_code) {
929
+ VALUE type;
930
+ switch (SWIG_code) {
931
+ case SWIG_MemoryError:
932
+ type = rb_eNoMemError;
933
+ break;
934
+ case SWIG_IOError:
935
+ type = rb_eIOError;
936
+ break;
937
+ case SWIG_RuntimeError:
938
+ type = rb_eRuntimeError;
939
+ break;
940
+ case SWIG_IndexError:
941
+ type = rb_eIndexError;
942
+ break;
943
+ case SWIG_TypeError:
944
+ type = rb_eTypeError;
945
+ break;
946
+ case SWIG_DivisionByZero:
947
+ type = rb_eZeroDivError;
948
+ break;
949
+ case SWIG_OverflowError:
950
+ type = rb_eRangeError;
951
+ break;
952
+ case SWIG_SyntaxError:
953
+ type = rb_eSyntaxError;
954
+ break;
955
+ case SWIG_ValueError:
956
+ type = rb_eArgError;
957
+ break;
958
+ case SWIG_SystemError:
959
+ type = rb_eFatal;
960
+ break;
961
+ case SWIG_AttributeError:
962
+ type = rb_eRuntimeError;
963
+ break;
964
+ case SWIG_NullReferenceError:
965
+ type = getNullReferenceError();
966
+ break;
967
+ case SWIG_ObjectPreviouslyDeletedError:
968
+ type = getObjectPreviouslyDeletedError();
969
+ break;
970
+ case SWIG_UnknownError:
971
+ type = rb_eRuntimeError;
972
+ break;
973
+ default:
974
+ type = rb_eRuntimeError;
975
+ }
976
+ return type;
977
+ }
978
+
979
+
980
+
981
+
982
+ /* -----------------------------------------------------------------------------
983
+ * See the LICENSE file for information on copyright, usage and redistribution
984
+ * of SWIG, and the README file for authors - http://www.swig.org/release.html.
985
+ *
986
+ * rubytracking.swg
987
+ *
988
+ * This file contains support for tracking mappings from
989
+ * Ruby objects to C++ objects. This functionality is needed
990
+ * to implement mark functions for Ruby's mark and sweep
991
+ * garbage collector.
992
+ * ----------------------------------------------------------------------------- */
993
+
994
+ #ifdef __cplusplus
995
+ extern "C" {
996
+ #endif
997
+
998
+
999
+ /* Global Ruby hash table to store Trackings from C/C++
1000
+ structs to Ruby Objects. */
1001
+ static VALUE swig_ruby_trackings;
1002
+
1003
+ /* Global variable that stores a reference to the ruby
1004
+ hash table delete function. */
1005
+ static ID swig_ruby_hash_delete = 0;
1006
+
1007
+ /* Setup a Ruby hash table to store Trackings */
1008
+ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
1009
+ /* Create a ruby hash table to store Trackings from C++
1010
+ objects to Ruby objects. Also make sure to tell
1011
+ the garabage collector about the hash table. */
1012
+ swig_ruby_trackings = rb_hash_new();
1013
+ rb_gc_register_address(&swig_ruby_trackings);
1014
+
1015
+ /* Now store a reference to the hash table delete function
1016
+ so that we only have to look it up once.*/
1017
+ swig_ruby_hash_delete = rb_intern("delete");
1018
+ }
1019
+
1020
+ /* Get a Ruby number to reference a pointer */
1021
+ SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) {
1022
+ /* We cast the pointer to an unsigned long
1023
+ and then store a reference to it using
1024
+ a Ruby number object. */
1025
+
1026
+ /* Convert the pointer to a Ruby number */
1027
+ unsigned long value = (unsigned long) ptr;
1028
+ return LONG2NUM(value);
1029
+ }
1030
+
1031
+ /* Get a Ruby number to reference an object */
1032
+ SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) {
1033
+ /* We cast the object to an unsigned long
1034
+ and then store a reference to it using
1035
+ a Ruby number object. */
1036
+
1037
+ /* Convert the Object to a Ruby number */
1038
+ unsigned long value = (unsigned long) object;
1039
+ return LONG2NUM(value);
1040
+ }
1041
+
1042
+ /* Get a Ruby object from a previously stored reference */
1043
+ SWIGRUNTIME VALUE SWIG_RubyReferenceToObject(VALUE reference) {
1044
+ /* The provided Ruby number object is a reference
1045
+ to the Ruby object we want.*/
1046
+
1047
+ /* First convert the Ruby number to a C number */
1048
+ unsigned long value = NUM2LONG(reference);
1049
+ return (VALUE) value;
1050
+ }
1051
+
1052
+ /* Add a Tracking from a C/C++ struct to a Ruby object */
1053
+ SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) {
1054
+ /* In a Ruby hash table we store the pointer and
1055
+ the associated Ruby object. The trick here is
1056
+ that we cannot store the Ruby object directly - if
1057
+ we do then it cannot be garbage collected. So
1058
+ instead we typecast it as a unsigned long and
1059
+ convert it to a Ruby number object.*/
1060
+
1061
+ /* Get a reference to the pointer as a Ruby number */
1062
+ VALUE key = SWIG_RubyPtrToReference(ptr);
1063
+
1064
+ /* Get a reference to the Ruby object as a Ruby number */
1065
+ VALUE value = SWIG_RubyObjectToReference(object);
1066
+
1067
+ /* Store the mapping to the global hash table. */
1068
+ rb_hash_aset(swig_ruby_trackings, key, value);
1069
+ }
1070
+
1071
+ /* Get the Ruby object that owns the specified C/C++ struct */
1072
+ SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) {
1073
+ /* Get a reference to the pointer as a Ruby number */
1074
+ VALUE key = SWIG_RubyPtrToReference(ptr);
1075
+
1076
+ /* Now lookup the value stored in the global hash table */
1077
+ VALUE value = rb_hash_aref(swig_ruby_trackings, key);
1078
+
1079
+ if (value == Qnil) {
1080
+ /* No object exists - return nil. */
1081
+ return Qnil;
1082
+ }
1083
+ else {
1084
+ /* Convert this value to Ruby object */
1085
+ return SWIG_RubyReferenceToObject(value);
1086
+ }
1087
+ }
1088
+
1089
+ /* Remove a Tracking from a C/C++ struct to a Ruby object. It
1090
+ is very important to remove objects once they are destroyed
1091
+ since the same memory address may be reused later to create
1092
+ a new object. */
1093
+ SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
1094
+ /* Get a reference to the pointer as a Ruby number */
1095
+ VALUE key = SWIG_RubyPtrToReference(ptr);
1096
+
1097
+ /* Delete the object from the hash table by calling Ruby's
1098
+ do this we need to call the Hash.delete method.*/
1099
+ rb_funcall(swig_ruby_trackings, swig_ruby_hash_delete, 1, key);
1100
+ }
1101
+
1102
+ /* This is a helper method that unlinks a Ruby object from its
1103
+ underlying C++ object. This is needed if the lifetime of the
1104
+ Ruby object is longer than the C++ object */
1105
+ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
1106
+ VALUE object = SWIG_RubyInstanceFor(ptr);
1107
+
1108
+ if (object != Qnil) {
1109
+ DATA_PTR(object) = 0;
1110
+ }
1111
+ }
1112
+
1113
+
1114
+ #ifdef __cplusplus
1115
+ }
1116
+ #endif
1117
+
1118
+ /* -----------------------------------------------------------------------------
1119
+ * Ruby API portion that goes into the runtime
1120
+ * ----------------------------------------------------------------------------- */
1121
+
1122
+ #ifdef __cplusplus
1123
+ extern "C" {
1124
+ #endif
1125
+
1126
+ SWIGINTERN VALUE
1127
+ SWIG_Ruby_AppendOutput(VALUE target, VALUE o) {
1128
+ if (NIL_P(target)) {
1129
+ target = o;
1130
+ } else {
1131
+ if (TYPE(target) != T_ARRAY) {
1132
+ VALUE o2 = target;
1133
+ target = rb_ary_new();
1134
+ rb_ary_push(target, o2);
1135
+ }
1136
+ rb_ary_push(target, o);
1137
+ }
1138
+ return target;
1139
+ }
1140
+
1141
+ #ifdef __cplusplus
1142
+ }
1143
+ #endif
1144
+
1145
+
1146
+ /* -----------------------------------------------------------------------------
1147
+ * See the LICENSE file for information on copyright, usage and redistribution
1148
+ * of SWIG, and the README file for authors - http://www.swig.org/release.html.
1149
+ *
1150
+ * rubyrun.swg
1151
+ *
1152
+ * This file contains the runtime support for Ruby modules
1153
+ * and includes code for managing global variables and pointer
1154
+ * type checking.
1155
+ * ----------------------------------------------------------------------------- */
1156
+
1157
+ /* For backward compatibility only */
1158
+ #define SWIG_POINTER_EXCEPTION 0
1159
+
1160
+ /* for raw pointers */
1161
+ #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
1162
+ #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own)
1163
+ #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
1164
+ #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own)
1165
+ #define swig_owntype ruby_owntype
1166
+
1167
+ /* for raw packed data */
1168
+ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
1169
+ #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
1170
+
1171
+ /* for class or struct pointers */
1172
+ #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
1173
+ #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
1174
+
1175
+ /* for C or C++ function pointers */
1176
+ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
1177
+ #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
1178
+
1179
+ /* for C++ member pointers, ie, member methods */
1180
+ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty)
1181
+ #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
1182
+
1183
+
1184
+ /* Runtime API */
1185
+
1186
+ #define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule()
1187
+ #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer)
1188
+
1189
+
1190
+ /* Error manipulation */
1191
+
1192
+ #define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
1193
+ #define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), msg)
1194
+ #define SWIG_fail goto fail
1195
+
1196
+
1197
+ /* Ruby-specific SWIG API */
1198
+
1199
+ #define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
1200
+ #define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
1201
+ #define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty)
1202
+ #define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value)
1203
+ #define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty)
1204
+
1205
+
1206
+ /* -----------------------------------------------------------------------------
1207
+ * pointers/data manipulation
1208
+ * ----------------------------------------------------------------------------- */
1209
+
1210
+ #ifdef __cplusplus
1211
+ extern "C" {
1212
+ #if 0
1213
+ } /* cc-mode */
1214
+ #endif
1215
+ #endif
1216
+
1217
+ typedef struct {
1218
+ VALUE klass;
1219
+ VALUE mImpl;
1220
+ void (*mark)(void *);
1221
+ void (*destroy)(void *);
1222
+ int trackObjects;
1223
+ } swig_class;
1224
+
1225
+
1226
+ static VALUE _mSWIG = Qnil;
1227
+ static VALUE _cSWIG_Pointer = Qnil;
1228
+ static VALUE swig_runtime_data_type_pointer = Qnil;
1229
+
1230
+ SWIGRUNTIME VALUE
1231
+ getExceptionClass(void) {
1232
+ static int init = 0;
1233
+ static VALUE rubyExceptionClass ;
1234
+ if (!init) {
1235
+ init = 1;
1236
+ rubyExceptionClass = rb_const_get(_mSWIG, rb_intern("Exception"));
1237
+ }
1238
+ return rubyExceptionClass;
1239
+ }
1240
+
1241
+ /* This code checks to see if the Ruby object being raised as part
1242
+ of an exception inherits from the Ruby class Exception. If so,
1243
+ the object is simply returned. If not, then a new Ruby exception
1244
+ object is created and that will be returned to Ruby.*/
1245
+ SWIGRUNTIME VALUE
1246
+ SWIG_Ruby_ExceptionType(swig_type_info *desc, VALUE obj) {
1247
+ VALUE exceptionClass = getExceptionClass();
1248
+ if (rb_obj_is_kind_of(obj, exceptionClass)) {
1249
+ return obj;
1250
+ } else {
1251
+ return rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj));
1252
+ }
1253
+ }
1254
+
1255
+ /* Initialize Ruby runtime support */
1256
+ SWIGRUNTIME void
1257
+ SWIG_Ruby_InitRuntime(void)
1258
+ {
1259
+ if (_mSWIG == Qnil) {
1260
+ _mSWIG = rb_define_module("SWIG");
1261
+ }
1262
+ }
1263
+
1264
+ /* Define Ruby class for C type */
1265
+ SWIGRUNTIME void
1266
+ SWIG_Ruby_define_class(swig_type_info *type)
1267
+ {
1268
+ VALUE klass;
1269
+ char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
1270
+ sprintf(klass_name, "TYPE%s", type->name);
1271
+ if (NIL_P(_cSWIG_Pointer)) {
1272
+ _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
1273
+ rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
1274
+ }
1275
+ klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
1276
+ free((void *) klass_name);
1277
+ }
1278
+
1279
+ /* Create a new pointer object */
1280
+ SWIGRUNTIME VALUE
1281
+ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
1282
+ {
1283
+ int own = flags & SWIG_POINTER_OWN;
1284
+
1285
+ char *klass_name;
1286
+ swig_class *sklass;
1287
+ VALUE klass;
1288
+ VALUE obj;
1289
+
1290
+ if (!ptr)
1291
+ return Qnil;
1292
+
1293
+ if (type->clientdata) {
1294
+ sklass = (swig_class *) type->clientdata;
1295
+
1296
+ /* Are we tracking this class and have we already returned this Ruby object? */
1297
+ if (sklass->trackObjects) {
1298
+ obj = SWIG_RubyInstanceFor(ptr);
1299
+
1300
+ /* Check the object's type and make sure it has the correct type.
1301
+ It might not in cases where methods do things like
1302
+ downcast methods. */
1303
+ if (obj != Qnil) {
1304
+ VALUE value = rb_iv_get(obj, "__swigtype__");
1305
+ char* type_name = RSTRING_PTR(value);
1306
+
1307
+ if (strcmp(type->name, type_name) == 0) {
1308
+ return obj;
1309
+ }
1310
+ }
1311
+ }
1312
+
1313
+ /* Create a new Ruby object */
1314
+ obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
1315
+
1316
+ /* If tracking is on for this class then track this object. */
1317
+ if (sklass->trackObjects) {
1318
+ SWIG_RubyAddTracking(ptr, obj);
1319
+ }
1320
+ } else {
1321
+ klass_name = (char *) malloc(4 + strlen(type->name) + 1);
1322
+ sprintf(klass_name, "TYPE%s", type->name);
1323
+ klass = rb_const_get(_mSWIG, rb_intern(klass_name));
1324
+ free((void *) klass_name);
1325
+ obj = Data_Wrap_Struct(klass, 0, 0, ptr);
1326
+ }
1327
+ rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
1328
+
1329
+ return obj;
1330
+ }
1331
+
1332
+ /* Create a new class instance (always owned) */
1333
+ SWIGRUNTIME VALUE
1334
+ SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
1335
+ {
1336
+ VALUE obj;
1337
+ swig_class *sklass = (swig_class *) type->clientdata;
1338
+ obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
1339
+ rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
1340
+ return obj;
1341
+ }
1342
+
1343
+ /* Get type mangle from class name */
1344
+ SWIGRUNTIMEINLINE char *
1345
+ SWIG_Ruby_MangleStr(VALUE obj)
1346
+ {
1347
+ VALUE stype = rb_iv_get(obj, "__swigtype__");
1348
+ return StringValuePtr(stype);
1349
+ }
1350
+
1351
+ /* Acquire a pointer value */
1352
+ typedef void (*ruby_owntype)(void*);
1353
+
1354
+ SWIGRUNTIME ruby_owntype
1355
+ SWIG_Ruby_AcquirePtr(VALUE obj, ruby_owntype own) {
1356
+ if (obj) {
1357
+ ruby_owntype oldown = RDATA(obj)->dfree;
1358
+ RDATA(obj)->dfree = own;
1359
+ return oldown;
1360
+ } else {
1361
+ return 0;
1362
+ }
1363
+ }
1364
+
1365
+ /* Convert a pointer value */
1366
+ SWIGRUNTIME int
1367
+ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, ruby_owntype *own)
1368
+ {
1369
+ char *c;
1370
+ swig_cast_info *tc;
1371
+ void *vptr = 0;
1372
+
1373
+ /* Grab the pointer */
1374
+ if (NIL_P(obj)) {
1375
+ *ptr = 0;
1376
+ return SWIG_OK;
1377
+ } else {
1378
+ if (TYPE(obj) != T_DATA) {
1379
+ return SWIG_ERROR;
1380
+ }
1381
+ Data_Get_Struct(obj, void, vptr);
1382
+ }
1383
+
1384
+ if (own) *own = RDATA(obj)->dfree;
1385
+
1386
+ /* Check to see if the input object is giving up ownership
1387
+ of the underlying C struct or C++ object. If so then we
1388
+ need to reset the destructor since the Ruby object no
1389
+ longer owns the underlying C++ object.*/
1390
+ if (flags & SWIG_POINTER_DISOWN) {
1391
+ /* Is tracking on for this class? */
1392
+ int track = 0;
1393
+ if (ty && ty->clientdata) {
1394
+ swig_class *sklass = (swig_class *) ty->clientdata;
1395
+ track = sklass->trackObjects;
1396
+ }
1397
+
1398
+ if (track) {
1399
+ /* We are tracking objects for this class. Thus we change the destructor
1400
+ * to SWIG_RubyRemoveTracking. This allows us to
1401
+ * remove the mapping from the C++ to Ruby object
1402
+ * when the Ruby object is garbage collected. If we don't
1403
+ * do this, then it is possible we will return a reference
1404
+ * to a Ruby object that no longer exists thereby crashing Ruby. */
1405
+ RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
1406
+ } else {
1407
+ RDATA(obj)->dfree = 0;
1408
+ }
1409
+ }
1410
+
1411
+ /* Do type-checking if type info was provided */
1412
+ if (ty) {
1413
+ if (ty->clientdata) {
1414
+ if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
1415
+ if (vptr == 0) {
1416
+ /* The object has already been deleted */
1417
+ return SWIG_ObjectPreviouslyDeletedError;
1418
+ }
1419
+ *ptr = vptr;
1420
+ return SWIG_OK;
1421
+ }
1422
+ }
1423
+ if ((c = SWIG_MangleStr(obj)) == NULL) {
1424
+ return SWIG_ERROR;
1425
+ }
1426
+ tc = SWIG_TypeCheck(c, ty);
1427
+ if (!tc) {
1428
+ return SWIG_ERROR;
1429
+ }
1430
+ *ptr = SWIG_TypeCast(tc, vptr);
1431
+ } else {
1432
+ *ptr = vptr;
1433
+ }
1434
+
1435
+ return SWIG_OK;
1436
+ }
1437
+
1438
+ /* Check convert */
1439
+ SWIGRUNTIMEINLINE int
1440
+ SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
1441
+ {
1442
+ char *c = SWIG_MangleStr(obj);
1443
+ if (!c) return 0;
1444
+ return SWIG_TypeCheck(c,ty) != 0;
1445
+ }
1446
+
1447
+ SWIGRUNTIME VALUE
1448
+ SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
1449
+ char result[1024];
1450
+ char *r = result;
1451
+ if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
1452
+ *(r++) = '_';
1453
+ r = SWIG_PackData(r, ptr, sz);
1454
+ strcpy(r, type->name);
1455
+ return rb_str_new2(result);
1456
+ }
1457
+
1458
+ /* Convert a packed value value */
1459
+ SWIGRUNTIME int
1460
+ SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) {
1461
+ swig_cast_info *tc;
1462
+ const char *c;
1463
+
1464
+ if (TYPE(obj) != T_STRING) goto type_error;
1465
+ c = StringValuePtr(obj);
1466
+ /* Pointer values must start with leading underscore */
1467
+ if (*c != '_') goto type_error;
1468
+ c++;
1469
+ c = SWIG_UnpackData(c, ptr, sz);
1470
+ if (ty) {
1471
+ tc = SWIG_TypeCheck(c, ty);
1472
+ if (!tc) goto type_error;
1473
+ }
1474
+ return SWIG_OK;
1475
+
1476
+ type_error:
1477
+ return SWIG_ERROR;
1478
+ }
1479
+
1480
+ SWIGRUNTIME swig_module_info *
1481
+ SWIG_Ruby_GetModule(void)
1482
+ {
1483
+ VALUE pointer;
1484
+ swig_module_info *ret = 0;
1485
+ VALUE verbose = rb_gv_get("VERBOSE");
1486
+
1487
+ /* temporarily disable warnings, since the pointer check causes warnings with 'ruby -w' */
1488
+ rb_gv_set("VERBOSE", Qfalse);
1489
+
1490
+ /* first check if pointer already created */
1491
+ pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1492
+ if (pointer != Qnil) {
1493
+ Data_Get_Struct(pointer, swig_module_info, ret);
1494
+ }
1495
+
1496
+ /* reinstate warnings */
1497
+ rb_gv_set("VERBOSE", verbose);
1498
+ return ret;
1499
+ }
1500
+
1501
+ SWIGRUNTIME void
1502
+ SWIG_Ruby_SetModule(swig_module_info *pointer)
1503
+ {
1504
+ /* register a new class */
1505
+ VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
1506
+ /* create and store the structure pointer to a global variable */
1507
+ swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
1508
+ rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
1509
+ }
1510
+
1511
+ #ifdef __cplusplus
1512
+ #if 0
1513
+ { /* cc-mode */
1514
+ #endif
1515
+ }
1516
+ #endif
1517
+
1518
+
1519
+
1520
+ #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0)
1521
+
1522
+ #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else
1523
+
1524
+
1525
+
1526
+ /* -------- TYPES TABLE (BEGIN) -------- */
1527
+
1528
+ #define SWIGTYPE_p_char swig_types[0]
1529
+ static swig_type_info *swig_types[2];
1530
+ static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
1531
+ #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
1532
+ #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
1533
+
1534
+ /* -------- TYPES TABLE (END) -------- */
1535
+
1536
+ #define SWIG_init Init_xmlsec
1537
+ #define SWIG_name "Xmlsec"
1538
+
1539
+ static VALUE mXmlsec;
1540
+
1541
+ #define SWIGVERSION 0x020000
1542
+ #define SWIG_VERSION SWIGVERSION
1543
+
1544
+
1545
+ #define SWIG_as_voidptr(a) (void *)((const void *)(a))
1546
+ #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a))
1547
+
1548
+
1549
+ SWIGINTERN swig_type_info*
1550
+ SWIG_pchar_descriptor(void)
1551
+ {
1552
+ static int init = 0;
1553
+ static swig_type_info* info = 0;
1554
+ if (!init) {
1555
+ info = SWIG_TypeQuery("_p_char");
1556
+ init = 1;
1557
+ }
1558
+ return info;
1559
+ }
1560
+
1561
+
1562
+ SWIGINTERN int
1563
+ SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
1564
+ {
1565
+ if (TYPE(obj) == T_STRING) {
1566
+
1567
+
1568
+
1569
+ char *cstr = STR2CSTR(obj);
1570
+
1571
+ size_t size = RSTRING_LEN(obj) + 1;
1572
+ if (cptr) {
1573
+ if (alloc) {
1574
+ if (*alloc == SWIG_NEWOBJ) {
1575
+ *cptr = (char *)memcpy((char *)malloc((size)*sizeof(char)), cstr, sizeof(char)*(size));
1576
+ } else {
1577
+ *cptr = cstr;
1578
+ *alloc = SWIG_OLDOBJ;
1579
+ }
1580
+ }
1581
+ }
1582
+ if (psize) *psize = size;
1583
+ return SWIG_OK;
1584
+ } else {
1585
+ swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
1586
+ if (pchar_descriptor) {
1587
+ void* vptr = 0;
1588
+ if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
1589
+ if (cptr) *cptr = (char *)vptr;
1590
+ if (psize) *psize = vptr ? (strlen((char*)vptr) + 1) : 0;
1591
+ if (alloc) *alloc = SWIG_OLDOBJ;
1592
+ return SWIG_OK;
1593
+ }
1594
+ }
1595
+ }
1596
+ return SWIG_TypeError;
1597
+ }
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+ #include <limits.h>
1604
+ #ifndef LLONG_MIN
1605
+ # define LLONG_MIN LONG_LONG_MIN
1606
+ #endif
1607
+ #ifndef LLONG_MAX
1608
+ # define LLONG_MAX LONG_LONG_MAX
1609
+ #endif
1610
+ #ifndef ULLONG_MAX
1611
+ # define ULLONG_MAX ULONG_LONG_MAX
1612
+ #endif
1613
+
1614
+
1615
+ #define SWIG_From_long LONG2NUM
1616
+
1617
+
1618
+ SWIGINTERNINLINE VALUE
1619
+ SWIG_From_int (int value)
1620
+ {
1621
+ return SWIG_From_long (value);
1622
+ }
1623
+
1624
+ SWIGINTERN VALUE
1625
+ _wrap_verify_file(int argc, VALUE *argv, VALUE self) {
1626
+ char *arg1 = (char *) 0 ;
1627
+ char *arg2 = (char *) 0 ;
1628
+ int res1 ;
1629
+ char *buf1 = 0 ;
1630
+ int alloc1 = 0 ;
1631
+ int res2 ;
1632
+ char *buf2 = 0 ;
1633
+ int alloc2 = 0 ;
1634
+ int result;
1635
+ VALUE vresult = Qnil;
1636
+
1637
+ if ((argc < 2) || (argc > 2)) {
1638
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail;
1639
+ }
1640
+ res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
1641
+ if (!SWIG_IsOK(res1)) {
1642
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "verify_file" "', argument " "1"" of type '" "char const *""'");
1643
+ }
1644
+ arg1 = (char *)(buf1);
1645
+ res2 = SWIG_AsCharPtrAndSize(argv[1], &buf2, NULL, &alloc2);
1646
+ if (!SWIG_IsOK(res2)) {
1647
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "verify_file" "', argument " "2"" of type '" "char const *""'");
1648
+ }
1649
+ arg2 = (char *)(buf2);
1650
+ result = (int)verify_file((char const *)arg1,(char const *)arg2);
1651
+ vresult = SWIG_From_int((int)(result));
1652
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
1653
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
1654
+ return vresult;
1655
+ fail:
1656
+ if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
1657
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
1658
+ return Qnil;
1659
+ }
1660
+
1661
+
1662
+
1663
+ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
1664
+
1665
+ static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
1666
+
1667
+ static swig_type_info *swig_type_initial[] = {
1668
+ &_swigt__p_char,
1669
+ };
1670
+
1671
+ static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
1672
+
1673
+ static swig_cast_info *swig_cast_initial[] = {
1674
+ _swigc__p_char,
1675
+ };
1676
+
1677
+
1678
+ /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
1679
+
1680
+ /* -----------------------------------------------------------------------------
1681
+ * Type initialization:
1682
+ * This problem is tough by the requirement that no dynamic
1683
+ * memory is used. Also, since swig_type_info structures store pointers to
1684
+ * swig_cast_info structures and swig_cast_info structures store pointers back
1685
+ * to swig_type_info structures, we need some lookup code at initialization.
1686
+ * The idea is that swig generates all the structures that are needed.
1687
+ * The runtime then collects these partially filled structures.
1688
+ * The SWIG_InitializeModule function takes these initial arrays out of
1689
+ * swig_module, and does all the lookup, filling in the swig_module.types
1690
+ * array with the correct data and linking the correct swig_cast_info
1691
+ * structures together.
1692
+ *
1693
+ * The generated swig_type_info structures are assigned staticly to an initial
1694
+ * array. We just loop through that array, and handle each type individually.
1695
+ * First we lookup if this type has been already loaded, and if so, use the
1696
+ * loaded structure instead of the generated one. Then we have to fill in the
1697
+ * cast linked list. The cast data is initially stored in something like a
1698
+ * two-dimensional array. Each row corresponds to a type (there are the same
1699
+ * number of rows as there are in the swig_type_initial array). Each entry in
1700
+ * a column is one of the swig_cast_info structures for that type.
1701
+ * The cast_initial array is actually an array of arrays, because each row has
1702
+ * a variable number of columns. So to actually build the cast linked list,
1703
+ * we find the array of casts associated with the type, and loop through it
1704
+ * adding the casts to the list. The one last trick we need to do is making
1705
+ * sure the type pointer in the swig_cast_info struct is correct.
1706
+ *
1707
+ * First off, we lookup the cast->type name to see if it is already loaded.
1708
+ * There are three cases to handle:
1709
+ * 1) If the cast->type has already been loaded AND the type we are adding
1710
+ * casting info to has not been loaded (it is in this module), THEN we
1711
+ * replace the cast->type pointer with the type pointer that has already
1712
+ * been loaded.
1713
+ * 2) If BOTH types (the one we are adding casting info to, and the
1714
+ * cast->type) are loaded, THEN the cast info has already been loaded by
1715
+ * the previous module so we just ignore it.
1716
+ * 3) Finally, if cast->type has not already been loaded, then we add that
1717
+ * swig_cast_info to the linked list (because the cast->type) pointer will
1718
+ * be correct.
1719
+ * ----------------------------------------------------------------------------- */
1720
+
1721
+ #ifdef __cplusplus
1722
+ extern "C" {
1723
+ #if 0
1724
+ } /* c-mode */
1725
+ #endif
1726
+ #endif
1727
+
1728
+ #if 0
1729
+ #define SWIGRUNTIME_DEBUG
1730
+ #endif
1731
+
1732
+
1733
+ SWIGRUNTIME void
1734
+ SWIG_InitializeModule(void *clientdata) {
1735
+ size_t i;
1736
+ swig_module_info *module_head, *iter;
1737
+ int found;
1738
+
1739
+ clientdata = clientdata;
1740
+
1741
+ /* check to see if the circular list has been setup, if not, set it up */
1742
+ if (swig_module.next==0) {
1743
+ /* Initialize the swig_module */
1744
+ swig_module.type_initial = swig_type_initial;
1745
+ swig_module.cast_initial = swig_cast_initial;
1746
+ swig_module.next = &swig_module;
1747
+ }
1748
+
1749
+ /* Try and load any already created modules */
1750
+ module_head = SWIG_GetModule(clientdata);
1751
+ if (!module_head) {
1752
+ /* This is the first module loaded for this interpreter */
1753
+ /* so set the swig module into the interpreter */
1754
+ SWIG_SetModule(clientdata, &swig_module);
1755
+ module_head = &swig_module;
1756
+ } else {
1757
+ /* the interpreter has loaded a SWIG module, but has it loaded this one? */
1758
+ found=0;
1759
+ iter=module_head;
1760
+ do {
1761
+ if (iter==&swig_module) {
1762
+ found=1;
1763
+ break;
1764
+ }
1765
+ iter=iter->next;
1766
+ } while (iter!= module_head);
1767
+
1768
+ /* if the is found in the list, then all is done and we may leave */
1769
+ if (found) return;
1770
+ /* otherwise we must add out module into the list */
1771
+ swig_module.next = module_head->next;
1772
+ module_head->next = &swig_module;
1773
+ }
1774
+
1775
+ /* Now work on filling in swig_module.types */
1776
+ #ifdef SWIGRUNTIME_DEBUG
1777
+ printf("SWIG_InitializeModule: size %d\n", swig_module.size);
1778
+ #endif
1779
+ for (i = 0; i < swig_module.size; ++i) {
1780
+ swig_type_info *type = 0;
1781
+ swig_type_info *ret;
1782
+ swig_cast_info *cast;
1783
+
1784
+ #ifdef SWIGRUNTIME_DEBUG
1785
+ printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
1786
+ #endif
1787
+
1788
+ /* if there is another module already loaded */
1789
+ if (swig_module.next != &swig_module) {
1790
+ type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
1791
+ }
1792
+ if (type) {
1793
+ /* Overwrite clientdata field */
1794
+ #ifdef SWIGRUNTIME_DEBUG
1795
+ printf("SWIG_InitializeModule: found type %s\n", type->name);
1796
+ #endif
1797
+ if (swig_module.type_initial[i]->clientdata) {
1798
+ type->clientdata = swig_module.type_initial[i]->clientdata;
1799
+ #ifdef SWIGRUNTIME_DEBUG
1800
+ printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
1801
+ #endif
1802
+ }
1803
+ } else {
1804
+ type = swig_module.type_initial[i];
1805
+ }
1806
+
1807
+ /* Insert casting types */
1808
+ cast = swig_module.cast_initial[i];
1809
+ while (cast->type) {
1810
+
1811
+ /* Don't need to add information already in the list */
1812
+ ret = 0;
1813
+ #ifdef SWIGRUNTIME_DEBUG
1814
+ printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
1815
+ #endif
1816
+ if (swig_module.next != &swig_module) {
1817
+ ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
1818
+ #ifdef SWIGRUNTIME_DEBUG
1819
+ if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
1820
+ #endif
1821
+ }
1822
+ if (ret) {
1823
+ if (type == swig_module.type_initial[i]) {
1824
+ #ifdef SWIGRUNTIME_DEBUG
1825
+ printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
1826
+ #endif
1827
+ cast->type = ret;
1828
+ ret = 0;
1829
+ } else {
1830
+ /* Check for casting already in the list */
1831
+ swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
1832
+ #ifdef SWIGRUNTIME_DEBUG
1833
+ if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
1834
+ #endif
1835
+ if (!ocast) ret = 0;
1836
+ }
1837
+ }
1838
+
1839
+ if (!ret) {
1840
+ #ifdef SWIGRUNTIME_DEBUG
1841
+ printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
1842
+ #endif
1843
+ if (type->cast) {
1844
+ type->cast->prev = cast;
1845
+ cast->next = type->cast;
1846
+ }
1847
+ type->cast = cast;
1848
+ }
1849
+ cast++;
1850
+ }
1851
+ /* Set entry in modules->types array equal to the type */
1852
+ swig_module.types[i] = type;
1853
+ }
1854
+ swig_module.types[i] = 0;
1855
+
1856
+ #ifdef SWIGRUNTIME_DEBUG
1857
+ printf("**** SWIG_InitializeModule: Cast List ******\n");
1858
+ for (i = 0; i < swig_module.size; ++i) {
1859
+ int j = 0;
1860
+ swig_cast_info *cast = swig_module.cast_initial[i];
1861
+ printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
1862
+ while (cast->type) {
1863
+ printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
1864
+ cast++;
1865
+ ++j;
1866
+ }
1867
+ printf("---- Total casts: %d\n",j);
1868
+ }
1869
+ printf("**** SWIG_InitializeModule: Cast List ******\n");
1870
+ #endif
1871
+ }
1872
+
1873
+ /* This function will propagate the clientdata field of type to
1874
+ * any new swig_type_info structures that have been added into the list
1875
+ * of equivalent types. It is like calling
1876
+ * SWIG_TypeClientData(type, clientdata) a second time.
1877
+ */
1878
+ SWIGRUNTIME void
1879
+ SWIG_PropagateClientData(void) {
1880
+ size_t i;
1881
+ swig_cast_info *equiv;
1882
+ static int init_run = 0;
1883
+
1884
+ if (init_run) return;
1885
+ init_run = 1;
1886
+
1887
+ for (i = 0; i < swig_module.size; i++) {
1888
+ if (swig_module.types[i]->clientdata) {
1889
+ equiv = swig_module.types[i]->cast;
1890
+ while (equiv) {
1891
+ if (!equiv->converter) {
1892
+ if (equiv->type && !equiv->type->clientdata)
1893
+ SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
1894
+ }
1895
+ equiv = equiv->next;
1896
+ }
1897
+ }
1898
+ }
1899
+ }
1900
+
1901
+ #ifdef __cplusplus
1902
+ #if 0
1903
+ { /* c-mode */
1904
+ #endif
1905
+ }
1906
+ #endif
1907
+
1908
+ /*
1909
+
1910
+ */
1911
+ #ifdef __cplusplus
1912
+ extern "C"
1913
+ #endif
1914
+ SWIGEXPORT void Init_xmlsec(void) {
1915
+ size_t i;
1916
+
1917
+ SWIG_InitRuntime();
1918
+ mXmlsec = rb_define_module("Xmlsec");
1919
+
1920
+ SWIG_InitializeModule(0);
1921
+ for (i = 0; i < swig_module.size; i++) {
1922
+ SWIG_define_class(swig_module.types[i]);
1923
+ }
1924
+
1925
+ SWIG_RubyInitializeTrackings();
1926
+ rb_define_module_function(mXmlsec, "verify_file", _wrap_verify_file, -1);
1927
+ }
1928
+