|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "stdlib.h" |
|
20 #include "nativesecureconnection.h" |
|
21 #include "com_nokia_mj_impl_ssl_SecureConnectionImpl.h" |
|
22 |
|
23 using namespace java; |
|
24 |
|
25 JNIEXPORT jint JNICALL |
|
26 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1createNativePeer |
|
27 (JNIEnv* aJni, jobject /*peer*/, jstring aName, jint aMode, jstring aHost, jint aPort) |
|
28 { |
|
29 const char* host = aJni->GetStringUTFChars(aHost, 0); |
|
30 const char* name = aJni->GetStringUTFChars(aName, 0); |
|
31 |
|
32 NativeSecureConnection* secSockConn = new NativeSecureConnection(name, aMode, host, aPort); |
|
33 |
|
34 aJni->ReleaseStringUTFChars(aHost, host); |
|
35 aJni->ReleaseStringUTFChars(aName, name); |
|
36 return reinterpret_cast<jint>(secSockConn); |
|
37 } |
|
38 |
|
39 JNIEXPORT jint JNICALL |
|
40 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1doHandshake |
|
41 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jint aSocket, jint aType, jint aApn, jintArray aReturnValue) |
|
42 { |
|
43 int err1 = 0; |
|
44 int err2 = 0 ; |
|
45 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
46 int ret = secSockConn->doHandshake(aSocket,aType, aApn, &err1,&err2); |
|
47 LOG1(ESOCKET, EInfo,"SecureConnectionJNI-dohandshake err= %d",err1); |
|
48 LOG1(ESOCKET, EInfo,"SecureConnectionJNI-validate err= %d",err2); |
|
49 //int *temp = &err; |
|
50 aJni->SetIntArrayRegion(aReturnValue,0,1,&err1); |
|
51 aJni->SetIntArrayRegion(aReturnValue,1,1,&err2); |
|
52 return ret; |
|
53 } |
|
54 |
|
55 JNIEXPORT jint JNICALL |
|
56 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getport |
|
57 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
58 { |
|
59 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
60 |
|
61 // getPort method of NativeSocketConnection is called |
|
62 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection class |
|
63 return secSockConn->getPort(); |
|
64 } |
|
65 |
|
66 JNIEXPORT jint JNICALL |
|
67 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getLocalPort |
|
68 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
69 { |
|
70 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
71 |
|
72 // getLocalPort method of NativeSocketConnection is called |
|
73 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection class |
|
74 return secSockConn->getLocalPort(); |
|
75 } |
|
76 |
|
77 JNIEXPORT jint JNICALL |
|
78 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getSocketOption |
|
79 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle, int aOption) |
|
80 { |
|
81 |
|
82 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
83 |
|
84 // getSocketOption method of NativeSocketConnection is called |
|
85 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection |
|
86 return secSockConn->getSocketOption(aOption); |
|
87 } |
|
88 |
|
89 JNIEXPORT int JNICALL |
|
90 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1setSocketOption |
|
91 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle, jint aOption, jint aValue) |
|
92 { |
|
93 |
|
94 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
95 |
|
96 // setSocketOption method of NativeSocketConnection is called |
|
97 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection |
|
98 return secSockConn->setSocketOption(aOption, aValue); |
|
99 |
|
100 } |
|
101 |
|
102 JNIEXPORT jint JNICALL |
|
103 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getLocalAddress |
|
104 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jobjectArray address) |
|
105 { |
|
106 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
107 char * addr = new char[256]; |
|
108 |
|
109 // getLocalAddress method of NativeSocketConnection is called |
|
110 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection |
|
111 jint retValue = secSockConn->getLocalAddress(addr); |
|
112 jstring jnistring = aJni->NewStringUTF(addr); |
|
113 aJni->SetObjectArrayElement(address,0,jnistring); |
|
114 aJni->DeleteLocalRef(jnistring); |
|
115 delete[] addr; |
|
116 return retValue; |
|
117 } |
|
118 |
|
119 JNIEXPORT jint JNICALL |
|
120 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getAddress |
|
121 (JNIEnv *aJni, jobject /*peer*/, jint aNativePeerHandle, jobjectArray address) |
|
122 { |
|
123 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
124 char * addr = new char[256]; |
|
125 |
|
126 // getAddress method of NativeSocketConnection is called |
|
127 // As NativeSecureConnection class derives socket behaviour from NativeSocketConnection |
|
128 jint retValue = secSockConn->getAddress(addr); |
|
129 jstring jnistring = aJni->NewStringUTF(addr); |
|
130 aJni->SetObjectArrayElement(address,0,jnistring); |
|
131 aJni->DeleteLocalRef(jnistring); |
|
132 delete[] addr; |
|
133 return retValue; |
|
134 |
|
135 } |
|
136 |
|
137 JNIEXPORT jint JNICALL |
|
138 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1close |
|
139 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
140 { |
|
141 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
142 return secSockConn->secureSocketClose(); |
|
143 } |
|
144 |
|
145 JNIEXPORT jint JNICALL |
|
146 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1getSecurityInfo |
|
147 (JNIEnv* aJni,jobject /*peer*/, jint aNativePeerHandle, jobjectArray aStringResultArray) |
|
148 { |
|
149 NativeSecureConnection* secSockConn = reinterpret_cast<NativeSecureConnection*>(aNativePeerHandle); |
|
150 ILOG(ESOCKET, "++SecureConnectionJNI "); |
|
151 char **result = secSockConn->getSecurityInfo(); |
|
152 jstring jniString; |
|
153 |
|
154 for (int i=0; i<9; i++) |
|
155 { |
|
156 ILOG1(ESOCKET, "SecureConnectionJNI result[i]= %s",result[i]); |
|
157 jniString = aJni->NewStringUTF(result[i]); |
|
158 aJni->SetObjectArrayElement(aStringResultArray, i, jniString); |
|
159 |
|
160 } |
|
161 aJni->DeleteLocalRef(jniString); |
|
162 return 1; |
|
163 } |
|
164 |
|
165 JNIEXPORT void JNICALL |
|
166 Java_com_nokia_mj_impl_ssl_SecureConnectionImpl__1dispose |
|
167 (JNIEnv* /*aJni*/, jobject /*peer*/, jint aNativePeerHandle) |
|
168 { |
|
169 NativeSocketConnection* nativeConn = reinterpret_cast<NativeSocketConnection*>(aNativePeerHandle); |
|
170 delete nativeConn; |
|
171 } |