1 /* javazxid.i - SWIG interface file for Java JNI extension for libzxid 2 * Copyright (c) 2007-2009 Symlabs (symlabs@symlabs.com), All Rights Reserved. 3 * Author: Sampo Kellomaki (sampo@iki.fi) 4 * This is confidential unpublished proprietary source code of the author. 5 * NO WARRANTY, not even implied warranties. Contains trade secrets. 6 * Distribution prohibited unless authorized in writing. 7 * Licensed under Apache License 2.0, see file COPYING. 8 * $Id: javazxid.i,v 1.10 2009-11-29 12:23:06 sampo Exp $ 9 * 7.1.2007, created --Sampo 10 * 27.11.2009, tweaked zx_str typemap --Sampo 11 * 12 * See: http://java.sun.com/docs/books/jni/html/objtypes.html 13 * http://www.swig.org/Doc1.3/Java.html 14 */ 15 %module "zxidjni" 16 %{ 17 18 #include "platform.h" 19 #include "errmac.h" 20 #include "zx.h" 21 #include "zxid.h" 22 #include "saml2.h" 23 24 #include "c/zx-const.h" 25 #include "c/zx-data.h" 26 #include "c/zx-ns.h" 27 #include "c/zxidvers.h" 28 29 %} 30 31 /* N.B. Contrary to the documentation the type field in all of the following four maps 32 * must match the original, i.e. struct zx_str*, rather than one of the intermediary 33 * types (errornously documented in SWIG documentation that way). */ 34 %typemap (jni) struct zx_str* "jstring" // Affects zxid_wrap.c 35 %typemap (jtype) struct zx_str* "String" // Affects zxidjniJNI.java 36 %typemap (jstype) struct zx_str* "String" // Affects zxidjni.java 37 %typemap (javaout) struct zx_str* { return $jnicall; } // Affects zxidjni.java body 38 %typemap (javain) struct zx_str* "$javainput" // Affects setter body 39 40 %typemap (out) struct zx_str* { 41 // Unfortunately Java does not provide NewStringUTF() that would explicitly 42 // take length field - they insist on nul termination instead. Sigh. 43 if ($1 && $1->s) { 44 char* tmp = malloc($1->len + 1); 45 if (!tmp) { ERR("Out of memory len=%d", $1->len); return $null; } 46 memcpy(tmp, $1->s, $1->len); 47 tmp[$1->len] = 0; 48 $result = (*jenv)->NewStringUTF(jenv, tmp); 49 free(tmp); 50 // Do not free underlying zx_str because they are usually returned by reference. 51 } else { 52 $result = 0; 53 } 54 } 55 56 %typemap (in) (int len, char* s) %{ 57 // The following jstring casts could probably be avoided with proper use of typemaps 58 $1 = (*jenv)->GetStringUTFLength(jenv, (jstring)$input); 59 $2 = (char*)(*jenv)->GetStringUTFChars(jenv, (jstring)$input, 0); 60 // *** Whether we can free, or not, the obtained string depends 61 // on whether the zxid API will take reference to the string. 62 %} 63 %typemap (freearg) (int len, char* s) "(*jenv)->ReleaseStringUTFChars(jenv, (jstring)$input, $2);" 64 65 %typemap (in) (int len, const char* s) %{ 66 // The following jstring casts could probably be avoided with proper use of typemaps 67 $1 = (*jenv)->GetStringUTFLength(jenv, (jstring)$input); 68 $2 = (char*)(*jenv)->GetStringUTFChars(jenv, (jstring)$input, 0); 69 // *** Whether we can free, or not, the obtained string depends 70 // on whether the zxid API will take reference to the const string. 71 %} 72 %typemap (freearg) (int len, const char* s) "(*jenv)->ReleaseStringUTFChars(jenv, (jstring)$input, $2);" 73 74 //#define ZXID_FIX_SWIGJAVA 1 75 76 %include "zx.h" 77 %include "zxid.h" 78 %include "saml2.h" 79 %include "wsf.h" 80 %include "c/zxidvers.h" 81 %include "c/zx-ns.h" 82 83 /* 84 85 Trying to process all of the below hits a Java class file format limitation 86 "too many constants", manifesting as error message like 87 88 /apps/java/j2sdk1.4.2/bin/javac -J-Xmx128m -g zxid.java zxidjava/*.java 89 zxidjava/zxidjni.java:11: too many constants 90 public class zxidjni implements zxidjniConstants { 91 ^ 92 Note: zxid.java uses or overrides a deprecated API. 93 Note: Recompile with -deprecation for details. 94 1 error 95 make: *** [zxid.class] Error 1 96 97 If you know how to get around that, please let me know. 98 99 %include "c/zx-a-data.h" 100 %include "c/zx-ac-data.h" 101 %include "c/zx-b-data.h" 102 %include "c/zx-b12-data.h" 103 %include "c/zx-const.h" 104 %include "c/zx-data.h" 105 %include "c/zx-di-data.h" 106 %include "c/zx-di12-data.h" 107 %include "c/zx-ds-data.h" 108 %include "c/zx-e-data.h" 109 %include "c/zx-ff12-data.h" 110 %include "c/zx-is-data.h" 111 %include "c/zx-is12-data.h" 112 %include "c/zx-lu-data.h" 113 %include "c/zx-m20-data.h" 114 %include "c/zx-md-data.h" 115 %include "c/zx-sa-data.h" 116 %include "c/zx-sa11-data.h" 117 %include "c/zx-sbf-data.h" 118 %include "c/zx-sec-data.h" 119 %include "c/zx-sec12-data.h" 120 %include "c/zx-sp-data.h" 121 %include "c/zx-sp11-data.h" 122 %include "c/zx-wsse-data.h" 123 %include "c/zx-wsu-data.h" 124 %include "c/zx-xenc-data.h" 125 %include "c/zx-xml-data.h" 126 %include "c/zx-xs-data.h" 127 %include "c/zx-paos-data.h" 128 %include "c/zx-ecp-data.h" 129 %include "c/zx-dap-data.h" 130 %include "c/zx-ps-data.h" 131 %include "c/zx-im-data.h" 132 %include "c/zx-as-data.h" 133 %include "c/zx-dst-data.h" 134 %include "c/zx-subs-data.h" 135 */ 136 137 /* EOF */ 138