Browse code

Update to version openjdk-1.8.0.141

Change-Id: I8e823c48e0a7b988d8c57d9ec787abb898ab5b9c
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/3321
Reviewed-by: Sharath George
Tested-by: Sharath George

harishspqr authored on 2017/07/22 11:23:41
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,433 +0,0 @@
1
-+++ b/jdk/src/share/back/invoker.c	Mon Mar 21 11:24:09 2016 +0100
2
-@@ -211,6 +211,47 @@
3
-     return error;
4
- }
5
- 
6
-+/*
7
-+ * Delete global references from the request which got put there before a
8
-+ * invoke request was carried out. See fillInvokeRequest() and invoker invoke*()
9
-+ * impls.
10
-+ */
11
-+static void
12
-+deleteGlobalRefs(JNIEnv *env, InvokeRequest *request)
13
-+{
14
-+    void *cursor;
15
-+    jint argIndex = 0;
16
-+    jvalue *argument = request->arguments;
17
-+    jbyte argumentTag = firstArgumentTypeTag(request->methodSignature, &cursor);
18
-+
19
-+    if (request->clazz != NULL) {
20
-+        tossGlobalRef(env, &(request->clazz));
21
-+    }
22
-+    if (request->instance != NULL) {
23
-+        tossGlobalRef(env, &(request->instance));
24
-+    }
25
-+    /* Delete global argument references */
26
-+    while (argIndex < request->argumentCount) {
27
-+        if ((argumentTag == JDWP_TAG(OBJECT)) ||
28
-+            (argumentTag == JDWP_TAG(ARRAY))) {
29
-+            if (argument->l != NULL) {
30
-+                tossGlobalRef(env, &(argument->l));
31
-+            }
32
-+        }
33
-+        argument++;
34
-+        argIndex++;
35
-+        argumentTag = nextArgumentTypeTag(&cursor);
36
-+    }
37
-+    /* Delete potentially saved return values */
38
-+    if ((request->invokeType == INVOKE_CONSTRUCTOR) ||
39
-+        (returnTypeTag(request->methodSignature) == JDWP_TAG(OBJECT)) ||
40
-+        (returnTypeTag(request->methodSignature) == JDWP_TAG(ARRAY))) {
41
-+        if (request->returnValue.l != NULL) {
42
-+            tossGlobalRef(env, &(request->returnValue.l));
43
-+        }
44
-+    }
45
-+}
46
-+
47
- static jvmtiError
48
- fillInvokeRequest(JNIEnv *env, InvokeRequest *request,
49
-                   jbyte invokeType, jbyte options, jint id,
50
-@@ -736,6 +777,13 @@
51
-         (void)outStream_writeObjectRef(env, &out, exc);
52
-         outStream_sendReply(&out);
53
-     }
54
-+
55
-+    /*
56
-+     * At this time, there's no need to retain global references on
57
-+     * arguments since the reply is processed. No one will deal with
58
-+     * this request ID anymore, so we must call deleteGlobalRefs().
59
-+     */
60
-+    deleteGlobalRefs(env, request);
61
- }
62
- 
63
- jboolean
64
-+++ b/jdk/test/com/sun/jdi/oom/@debuggeeVMOptions	Mon Mar 21 11:24:09 2016 +0100
65
-@@ -0,0 +1,1 @@
66
-+-Xmx40m
67
-\ No newline at end of file
68
-+++ b/jdk/test/com/sun/jdi/oom/OomDebugTest.java	Mon Mar 21 11:24:09 2016 +0100
69
-@@ -0,0 +1,312 @@
70
-+/*
71
-+ * Copyright (c) 2016 Red Hat Inc.
72
-+ *
73
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74
-+ *
75
-+ * This code is free software; you can redistribute it and/or modify it
76
-+ * under the terms of the GNU General Public License version 2 only, as
77
-+ * published by the Free Software Foundation.
78
-+ *
79
-+ * This code is distributed in the hope that it will be useful, but WITHOUT
80
-+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81
-+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
82
-+ * version 2 for more details (a copy is included in the LICENSE file that
83
-+ * accompanied this code).
84
-+ *
85
-+ * You should have received a copy of the GNU General Public License version
86
-+ * 2 along with this work; if not, write to the Free Software Foundation,
87
-+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88
-+ *
89
-+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
90
-+ * or visit www.oracle.com if you need additional information or have any
91
-+ * questions.
92
-+ */
93
-+
94
-+/**
95
-+ *  @test
96
-+ *  @bug 4858370
97
-+ *  @summary JDWP: Memory Leak (global references not deleted after invokeMethod).
98
-+ *
99
-+ *  @author Severin Gehwolf <sgehwolf@redhat.com>
100
-+ *
101
-+ *  @library ..
102
-+ *  @run build TestScaffold VMConnection TargetListener TargetAdapter
103
-+ *  @run compile -g OomDebugTest.java
104
-+ *  @run shell OomDebugTestSetup.sh
105
-+ *  @run main OomDebugTest OomDebugTestTarget test1
106
-+ *  @run main OomDebugTest OomDebugTestTarget test2
107
-+ *  @run main OomDebugTest OomDebugTestTarget test3
108
-+ *  @run main OomDebugTest OomDebugTestTarget test4
109
-+ *  @run main OomDebugTest OomDebugTestTarget test5
110
-+ */
111
-+import java.util.ArrayList;
112
-+import java.util.Collections;
113
-+import java.util.List;
114
-+
115
-+import com.sun.jdi.ArrayReference;
116
-+import com.sun.jdi.ArrayType;
117
-+import com.sun.jdi.ClassType;
118
-+import com.sun.jdi.Field;
119
-+import com.sun.jdi.InvocationException;
120
-+import com.sun.jdi.Method;
121
-+import com.sun.jdi.ObjectReference;
122
-+import com.sun.jdi.ReferenceType;
123
-+import com.sun.jdi.StackFrame;
124
-+import com.sun.jdi.VMOutOfMemoryException;
125
-+import com.sun.jdi.Value;
126
-+import com.sun.jdi.event.BreakpointEvent;
127
-+
128
-+/***************** Target program **********************/
129
-+
130
-+class OomDebugTestTarget {
131
-+
132
-+    OomDebugTestTarget() {
133
-+        System.out.println("DEBUG: invoked constructor");
134
-+    }
135
-+    static class FooCls {
136
-+        @SuppressWarnings("unused")
137
-+        private byte[] bytes = new byte[3000000];
138
-+    };
139
-+
140
-+    FooCls fooCls = new FooCls();
141
-+    byte[] byteArray = new byte[0];
142
-+
143
-+    void testMethod(FooCls foo) {
144
-+        System.out.println("DEBUG: invoked 'void testMethod(FooCls)', foo == " + foo);
145
-+    }
146
-+
147
-+    void testPrimitive(byte[] foo) {
148
-+        System.out.println("DEBUG: invoked 'void testPrimitive(byte[])', foo == " + foo);
149
-+    }
150
-+
151
-+    byte[] testPrimitiveArrRetval() {
152
-+        System.out.println("DEBUG: invoked 'byte[] testPrimitiveArrRetval()'");
153
-+        return new byte[3000000];
154
-+    }
155
-+
156
-+    FooCls testFooClsRetval() {
157
-+        System.out.println("DEBUG: invoked 'FooCls testFooClsRetval()'");
158
-+        return new FooCls();
159
-+    }
160
-+
161
-+    public void entry() {}
162
-+
163
-+    public static void main(String[] args){
164
-+        System.out.println("DEBUG: OomDebugTestTarget.main");
165
-+        new OomDebugTestTarget().entry();
166
-+    }
167
-+}
168
-+
169
-+/***************** Test program ************************/
170
-+
171
-+public class OomDebugTest extends TestScaffold {
172
-+
173
-+    private static final int TOTAL_TESTS = 1;
174
-+    private ReferenceType targetClass;
175
-+    private ObjectReference thisObject;
176
-+    private int failedTests;
177
-+    private final String testMethodName;
178
-+
179
-+    public OomDebugTest(String[] args) {
180
-+        super(args);
181
-+        if (args.length != 2) {
182
-+            throw new RuntimeException("Test failed unexpectedly.");
183
-+        }
184
-+        testMethodName = args[1];
185
-+    }
186
-+
187
-+    @Override
188
-+    protected void runTests() throws Exception {
189
-+        try {
190
-+            /*
191
-+             * Get to the top of entry()
192
-+             * to determine targetClass and mainThread
193
-+             */
194
-+            BreakpointEvent bpe = startTo("OomDebugTestTarget", "entry", "()V");
195
-+            targetClass = bpe.location().declaringType();
196
-+
197
-+            mainThread = bpe.thread();
198
-+
199
-+            StackFrame frame = mainThread.frame(0);
200
-+            thisObject = frame.thisObject();
201
-+            java.lang.reflect.Method m = findTestMethod();
202
-+            m.invoke(this);
203
-+        } catch (NoSuchMethodException e) {
204
-+            e.printStackTrace();
205
-+            failure();
206
-+        } catch (SecurityException e) {
207
-+            e.printStackTrace();
208
-+            failure();
209
-+        }
210
-+    }
211
-+
212
-+    private java.lang.reflect.Method findTestMethod()
213
-+            throws NoSuchMethodException, SecurityException {
214
-+        return OomDebugTest.class.getDeclaredMethod(testMethodName);
215
-+    }
216
-+
217
-+    private void failure() {
218
-+        failedTests++;
219
-+    }
220
-+
221
-+    /*
222
-+     * Test case: Object reference as method parameter.
223
-+     */
224
-+    @SuppressWarnings("unused") // called via reflection
225
-+    private void test1() throws Exception {
226
-+        System.out.println("DEBUG: ------------> Running " + testMethodName);
227
-+        try {
228
-+            Field field = targetClass.fieldByName("fooCls");
229
-+            ClassType clsType = (ClassType)field.type();
230
-+            Method constructor = getConstructorForClass(clsType);
231
-+            for (int i = 0; i < 15; i++) {
232
-+                @SuppressWarnings({ "rawtypes", "unchecked" })
233
-+                ObjectReference objRef = clsType.newInstance(mainThread,
234
-+                                                             constructor,
235
-+                                                             new ArrayList(0),
236
-+                                                             ObjectReference.INVOKE_NONVIRTUAL);
237
-+                invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
238
-+            }
239
-+        } catch (InvocationException e) {
240
-+            handleFailure(e);
241
-+        }
242
-+    }
243
-+
244
-+    /*
245
-+     * Test case: Array reference as method parameter.
246
-+     */
247
-+    @SuppressWarnings("unused") // called via reflection
248
-+    private void test2() throws Exception {
249
-+        System.out.println("DEBUG: ------------> Running " + testMethodName);
250
-+        try {
251
-+            Field field = targetClass.fieldByName("byteArray");
252
-+            ArrayType arrType = (ArrayType)field.type();
253
-+
254
-+            for (int i = 0; i < 15; i++) {
255
-+                ArrayReference byteArrayVal = arrType.newInstance(3000000);
256
-+                invoke("testPrimitive", "([B)V", byteArrayVal);
257
-+            }
258
-+        } catch (VMOutOfMemoryException e) {
259
-+            defaultHandleOOMFailure(e);
260
-+        }
261
-+    }
262
-+
263
-+    /*
264
-+     * Test case: Array reference as return value.
265
-+     */
266
-+    @SuppressWarnings("unused") // called via reflection
267
-+    private void test3() throws Exception {
268
-+        System.out.println("DEBUG: ------------> Running " + testMethodName);
269
-+        try {
270
-+            for (int i = 0; i < 15; i++) {
271
-+                invoke("testPrimitiveArrRetval",
272
-+                       "()[B",
273
-+                       Collections.EMPTY_LIST,
274
-+                       vm().mirrorOfVoid());
275
-+            }
276
-+        } catch (InvocationException e) {
277
-+            handleFailure(e);
278
-+        }
279
-+    }
280
-+
281
-+    /*
282
-+     * Test case: Object reference as return value.
283
-+     */
284
-+    @SuppressWarnings("unused") // called via reflection
285
-+    private void test4() throws Exception {
286
-+        System.out.println("DEBUG: ------------> Running " + testMethodName);
287
-+        try {
288
-+            for (int i = 0; i < 15; i++) {
289
-+                invoke("testFooClsRetval",
290
-+                       "()LOomDebugTestTarget$FooCls;",
291
-+                       Collections.EMPTY_LIST,
292
-+                       vm().mirrorOfVoid());
293
-+            }
294
-+        } catch (InvocationException e) {
295
-+            handleFailure(e);
296
-+        }
297
-+    }
298
-+
299
-+    /*
300
-+     * Test case: Constructor
301
-+     */
302
-+    @SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
303
-+    private void test5() throws Exception {
304
-+        System.out.println("DEBUG: ------------> Running " + testMethodName);
305
-+        try {
306
-+            ClassType type = (ClassType)thisObject.type();
307
-+            for (int i = 0; i < 15; i++) {
308
-+                type.newInstance(mainThread,
309
-+                                 findMethod(targetClass, "<init>", "()V"),
310
-+                                 new ArrayList(0),
311
-+                                 ObjectReference.INVOKE_NONVIRTUAL);
312
-+            }
313
-+        } catch (InvocationException e) {
314
-+            handleFailure(e);
315
-+        }
316
-+    }
317
-+
318
-+    private Method getConstructorForClass(ClassType clsType) {
319
-+        List<Method> methods = clsType.methodsByName("<init>");
320
-+        if (methods.size() != 1) {
321
-+            throw new RuntimeException("FAIL. Expected only one, the default, constructor");
322
-+        }
323
-+        return methods.get(0);
324
-+    }
325
-+
326
-+    private void handleFailure(InvocationException e) {
327
-+        // There is no good way to see the OOME diagnostic message in the target since the
328
-+        // TestScaffold might throw an exception while trying to print the stack trace. I.e
329
-+        // it might get a a VMDisconnectedException before the stack trace printing finishes.
330
-+        System.err.println("FAILURE: InvocationException caused by OOM");
331
-+        defaultHandleOOMFailure(e);
332
-+    }
333
-+
334
-+    private void defaultHandleOOMFailure(Exception e) {
335
-+        e.printStackTrace();
336
-+        failure();
337
-+    }
338
-+
339
-+    @SuppressWarnings({ "rawtypes", "unchecked" })
340
-+    void invoke(String methodName, String methodSig, Value value)
341
-+            throws Exception {
342
-+        List args = new ArrayList(1);
343
-+        args.add(value);
344
-+        invoke(methodName, methodSig, args, value);
345
-+    }
346
-+
347
-+    void invoke(String methodName,
348
-+                String methodSig,
349
-+                @SuppressWarnings("rawtypes") List args,
350
-+                Value value) throws Exception {
351
-+        Method method = findMethod(targetClass, methodName, methodSig);
352
-+        if ( method == null) {
353
-+            failure("FAILED: Can't find method: "
354
-+                    + methodName  + " for class = " + targetClass);
355
-+            return;
356
-+        }
357
-+        invoke(method, args, value);
358
-+    }
359
-+
360
-+    @SuppressWarnings({ "rawtypes", "unchecked" })
361
-+    void invoke(Method method, List args, Value value) throws Exception {
362
-+        thisObject.invokeMethod(mainThread, method, args, 0);
363
-+        System.out.println("DEBUG: Done invoking method via debugger.");
364
-+    }
365
-+
366
-+    Value fieldValue(String fieldName) {
367
-+        Field field = targetClass.fieldByName(fieldName);
368
-+        return thisObject.getValue(field);
369
-+    }
370
-+
371
-+    public static void main(String[] args) throws Exception {
372
-+        OomDebugTest oomTest = new OomDebugTest(args);
373
-+        oomTest.startTests();
374
-+        if (oomTest.failedTests > 0) {
375
-+            throw new RuntimeException(oomTest.failedTests
376
-+                                       + " of " + TOTAL_TESTS + " test(s) failed.");
377
-+        }
378
-+        System.out.println("All " + TOTAL_TESTS + " tests passed.");
379
-+    }
380
-+
381
-+}
382
-+++ b/jdk/test/com/sun/jdi/oom/OomDebugTestSetup.sh	Mon Mar 21 11:24:09 2016 +0100
383
-@@ -0,0 +1,46 @@
384
-+#!/bin/sh
385
-+#
386
-+# Copyright (c) 2016 Red Hat Inc.
387
-+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
388
-+#
389
-+# This code is free software; you can redistribute it and/or modify it
390
-+# under the terms of the GNU General Public License version 2 only, as
391
-+# published by the Free Software Foundation.
392
-+#
393
-+# This code is distributed in the hope that it will be useful, but WITHOUT
394
-+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395
-+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
396
-+# version 2 for more details (a copy is included in the LICENSE file that
397
-+# accompanied this code).
398
-+#
399
-+# You should have received a copy of the GNU General Public License version
400
-+# 2 along with this work; if not, write to the Free Software Foundation,
401
-+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
402
-+#
403
-+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
404
-+# or visit www.oracle.com if you need additional information or have any
405
-+# questions.
406
-+#
407
-+
408
-+
409
-+if [ "${TESTSRC}" = "" ]
410
-+then
411
-+  echo "TESTSRC not set.  Test cannot execute.  Failed."
412
-+  exit 1
413
-+fi
414
-+echo "TESTSRC=${TESTSRC}"
415
-+
416
-+if [ "${TESTJAVA}" = "" ]
417
-+then
418
-+  echo "TESTJAVA not set.  Test cannot execute.  Failed."
419
-+  exit 1
420
-+fi
421
-+echo "TESTJAVA=${TESTJAVA}"
422
-+
423
-+if [ "${TESTCLASSES}" = "" ]
424
-+then
425
-+  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
426
-+  exit 1
427
-+fi
428
-+
429
-+cp ${TESTSRC}/@debuggeeVMOptions ${TESTCLASSES}/
... ...
@@ -2,18 +2,18 @@
2 2
 %global security_hardening none
3 3
 Summary:	OpenJDK
4 4
 Name:		openjdk8
5
-Version:	1.8.0.131
6
-Release:	4%{?dist}
5
+Version:	1.8.0.141
6
+Release:	1%{?dist}
7 7
 License:	GNU GPL
8 8
 URL:		https://openjdk.java.net
9 9
 Group:		Development/Tools
10 10
 Vendor:		VMware, Inc.
11 11
 Distribution:   Photon
12
-Source0:	http://www.java.net/download/openjdk/jdk8/promoted/b131/openjdk-%{version}.tar.bz2
13
-%define sha1 openjdk=ae01c24fe5247d5aa246a60c0272ba92188a7d55
12
+Source0:	http://www.java.net/download/openjdk/jdk8/promoted/b131/openjdk-%{version}.tar.gz
13
+%define sha1 openjdk=e74417bc0bfcdb8f6b30a63bb26dbf35515ec562
14 14
 Patch0:		Awt_build_headless_only.patch
15
-Patch1:		Fix-memory-leak.patch
16
-Patch2:		check-system-ca-certs.patch
15
+Patch1:		check-system-ca-certs.patch
16
+Patch2:         remove-cups.patch
17 17
 BuildRequires:  pcre-devel
18 18
 BuildRequires:	which
19 19
 BuildRequires:	zip
... ...
@@ -64,7 +64,7 @@ Requires:       %{name} = %{version}-%{release}
64 64
 This package provides the runtime library class sources.
65 65
 
66 66
 %prep -p exit
67
-%setup -q -n openjdk
67
+%setup -qn openjdk-1.8.0-141
68 68
 %patch0 -p1
69 69
 %patch1 -p1
70 70
 %patch2 -p1
... ...
@@ -233,6 +233,8 @@ rm -rf %{buildroot}/*
233 233
 %{_libdir}/jvm/OpenJDK-%{version}/src.zip
234 234
 
235 235
 %changelog
236
+*   Fri Jul 21 2017 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.8.0.141-1
237
+-   Upgraded to version 1.8.0.141-1
236 238
 *   Thu Jul 6 2017 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.8.0.131-4
237 239
 -   Build AWT libraries as well.
238 240
 *   Thu Jun 29 2017 Divya Thaluru <dthaluru@vmware.com> 1.8.0.131-3
239 241
new file mode 100644
... ...
@@ -0,0 +1,449 @@
0
+diff -Naur openjdk-1.8.0-141/jdk/src/solaris/native/sun/awt/CUPSfuncs.c openjdk-1.8.0.141/jdk/src/solaris/native/sun/awt/CUPSfuncs.c
1
+--- a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c	2017-07-21 15:17:04.000000000 -0700
2
+@@ -1,445 +0,0 @@
3
+-/*
4
+- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
5
+- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
+- *
7
+- * This code is free software; you can redistribute it and/or modify it
8
+- * under the terms of the GNU General Public License version 2 only, as
9
+- * published by the Free Software Foundation.  Oracle designates this
10
+- * particular file as subject to the "Classpath" exception as provided
11
+- * by Oracle in the LICENSE file that accompanied this code.
12
+- *
13
+- * This code is distributed in the hope that it will be useful, but WITHOUT
14
+- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16
+- * version 2 for more details (a copy is included in the LICENSE file that
17
+- * accompanied this code).
18
+- *
19
+- * You should have received a copy of the GNU General Public License version
20
+- * 2 along with this work; if not, write to the Free Software Foundation,
21
+- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22
+- *
23
+- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24
+- * or visit www.oracle.com if you need additional information or have any
25
+- * questions.
26
+- */
27
+-
28
+-#include <jni.h>
29
+-#include <jni_util.h>
30
+-#include <jvm_md.h>
31
+-#include <dlfcn.h>
32
+-#include <cups/cups.h>
33
+-#include <cups/ppd.h>
34
+-
35
+-//#define CUPS_DEBUG
36
+-
37
+-#ifdef CUPS_DEBUG
38
+-#define DPRINTF(x, y) fprintf(stderr, x, y);
39
+-#else
40
+-#define DPRINTF(x, y)
41
+-#endif
42
+-
43
+-typedef const char* (*fn_cupsServer)(void);
44
+-typedef int (*fn_ippPort)(void);
45
+-typedef http_t* (*fn_httpConnect)(const char *, int);
46
+-typedef void (*fn_httpClose)(http_t *);
47
+-typedef char* (*fn_cupsGetPPD)(const char *);
48
+-typedef cups_dest_t* (*fn_cupsGetDest)(const char *name,
49
+-    const char *instance, int num_dests, cups_dest_t *dests);
50
+-typedef int (*fn_cupsGetDests)(cups_dest_t **dests);
51
+-typedef void (*fn_cupsFreeDests)(int num_dests, cups_dest_t *dests);
52
+-typedef ppd_file_t* (*fn_ppdOpenFile)(const char *);
53
+-typedef void (*fn_ppdClose)(ppd_file_t *);
54
+-typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *);
55
+-typedef ppd_size_t* (*fn_ppdPageSize)(ppd_file_t *, char *);
56
+-
57
+-fn_cupsServer j2d_cupsServer;
58
+-fn_ippPort j2d_ippPort;
59
+-fn_httpConnect j2d_httpConnect;
60
+-fn_httpClose j2d_httpClose;
61
+-fn_cupsGetPPD j2d_cupsGetPPD;
62
+-fn_cupsGetDest j2d_cupsGetDest;
63
+-fn_cupsGetDests j2d_cupsGetDests;
64
+-fn_cupsFreeDests j2d_cupsFreeDests;
65
+-fn_ppdOpenFile j2d_ppdOpenFile;
66
+-fn_ppdClose j2d_ppdClose;
67
+-fn_ppdFindOption j2d_ppdFindOption;
68
+-fn_ppdPageSize j2d_ppdPageSize;
69
+-
70
+-
71
+-/*
72
+- * Initialize library functions.
73
+- * // REMIND : move tab , add dlClose before return
74
+- */
75
+-JNIEXPORT jboolean JNICALL
76
+-Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env,
77
+-                                         jobject printObj) {
78
+-  void *handle = dlopen(VERSIONED_JNI_LIB_NAME("cups", "2"),
79
+-                        RTLD_LAZY | RTLD_GLOBAL);
80
+-
81
+-  if (handle == NULL) {
82
+-    handle = dlopen(JNI_LIB_NAME("cups"), RTLD_LAZY | RTLD_GLOBAL);
83
+-    if (handle == NULL) {
84
+-      return JNI_FALSE;
85
+-    }
86
+-  }
87
+-
88
+-  j2d_cupsServer = (fn_cupsServer)dlsym(handle, "cupsServer");
89
+-  if (j2d_cupsServer == NULL) {
90
+-    dlclose(handle);
91
+-    return JNI_FALSE;
92
+-  }
93
+-
94
+-  j2d_ippPort = (fn_ippPort)dlsym(handle, "ippPort");
95
+-  if (j2d_ippPort == NULL) {
96
+-    dlclose(handle);
97
+-    return JNI_FALSE;
98
+-  }
99
+-
100
+-  j2d_httpConnect = (fn_httpConnect)dlsym(handle, "httpConnect");
101
+-  if (j2d_httpConnect == NULL) {
102
+-    dlclose(handle);
103
+-    return JNI_FALSE;
104
+-  }
105
+-
106
+-  j2d_httpClose = (fn_httpClose)dlsym(handle, "httpClose");
107
+-  if (j2d_httpClose == NULL) {
108
+-    dlclose(handle);
109
+-    return JNI_FALSE;
110
+-  }
111
+-
112
+-  j2d_cupsGetPPD = (fn_cupsGetPPD)dlsym(handle, "cupsGetPPD");
113
+-  if (j2d_cupsGetPPD == NULL) {
114
+-    dlclose(handle);
115
+-    return JNI_FALSE;
116
+-  }
117
+-
118
+-  j2d_cupsGetDest = (fn_cupsGetDest)dlsym(handle, "cupsGetDest");
119
+-  if (j2d_cupsGetDest == NULL) {
120
+-    dlclose(handle);
121
+-    return JNI_FALSE;
122
+-  }
123
+-
124
+-  j2d_cupsGetDests = (fn_cupsGetDests)dlsym(handle, "cupsGetDests");
125
+-  if (j2d_cupsGetDests == NULL) {
126
+-    dlclose(handle);
127
+-    return JNI_FALSE;
128
+-  }
129
+-
130
+-  j2d_cupsFreeDests = (fn_cupsFreeDests)dlsym(handle, "cupsFreeDests");
131
+-  if (j2d_cupsFreeDests == NULL) {
132
+-    dlclose(handle);
133
+-    return JNI_FALSE;
134
+-  }
135
+-
136
+-  j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile");
137
+-  if (j2d_ppdOpenFile == NULL) {
138
+-    dlclose(handle);
139
+-    return JNI_FALSE;
140
+-
141
+-  }
142
+-
143
+-  j2d_ppdClose = (fn_ppdClose)dlsym(handle, "ppdClose");
144
+-  if (j2d_ppdClose == NULL) {
145
+-    dlclose(handle);
146
+-    return JNI_FALSE;
147
+-
148
+-  }
149
+-
150
+-  j2d_ppdFindOption = (fn_ppdFindOption)dlsym(handle, "ppdFindOption");
151
+-  if (j2d_ppdFindOption == NULL) {
152
+-    dlclose(handle);
153
+-    return JNI_FALSE;
154
+-  }
155
+-
156
+-  j2d_ppdPageSize = (fn_ppdPageSize)dlsym(handle, "ppdPageSize");
157
+-  if (j2d_ppdPageSize == NULL) {
158
+-    dlclose(handle);
159
+-    return JNI_FALSE;
160
+-  }
161
+-
162
+-  return JNI_TRUE;
163
+-}
164
+-
165
+-/*
166
+- * Gets CUPS server name.
167
+- *
168
+- */
169
+-JNIEXPORT jstring JNICALL
170
+-Java_sun_print_CUPSPrinter_getCupsServer(JNIEnv *env,
171
+-                                         jobject printObj)
172
+-{
173
+-    jstring cServer = NULL;
174
+-    const char* server = j2d_cupsServer();
175
+-    if (server != NULL) {
176
+-        // Is this a local domain socket?
177
+-        if (strncmp(server, "/", 1) == 0) {
178
+-            cServer = JNU_NewStringPlatform(env, "localhost");
179
+-        } else {
180
+-            cServer = JNU_NewStringPlatform(env, server);
181
+-        }
182
+-    }
183
+-    return cServer;
184
+-}
185
+-
186
+-/*
187
+- * Gets CUPS port name.
188
+- *
189
+- */
190
+-JNIEXPORT jint JNICALL
191
+-Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env,
192
+-                                         jobject printObj)
193
+-{
194
+-    int port = j2d_ippPort();
195
+-    return (jint) port;
196
+-}
197
+-
198
+-
199
+-/*
200
+- * Gets CUPS default printer name.
201
+- *
202
+- */
203
+-JNIEXPORT jstring JNICALL
204
+-Java_sun_print_CUPSPrinter_getCupsDefaultPrinter(JNIEnv *env,
205
+-                                                  jobject printObj)
206
+-{
207
+-    jstring cDefPrinter = NULL;
208
+-    cups_dest_t *dests;
209
+-    char *defaultPrinter = NULL;
210
+-    int num_dests = j2d_cupsGetDests(&dests);
211
+-    int i = 0;
212
+-    cups_dest_t *dest = j2d_cupsGetDest(NULL, NULL, num_dests, dests);
213
+-    if (dest != NULL) {
214
+-        defaultPrinter = dest->name;
215
+-        if (defaultPrinter != NULL) {
216
+-            cDefPrinter = JNU_NewStringPlatform(env, defaultPrinter);
217
+-        }
218
+-    }
219
+-    j2d_cupsFreeDests(num_dests, dests);
220
+-    return cDefPrinter;
221
+-}
222
+-
223
+-/*
224
+- * Checks if connection can be made to the server.
225
+- *
226
+- */
227
+-JNIEXPORT jboolean JNICALL
228
+-Java_sun_print_CUPSPrinter_canConnect(JNIEnv *env,
229
+-                                      jobject printObj,
230
+-                                      jstring server,
231
+-                                      jint port)
232
+-{
233
+-    const char *serverName;
234
+-    serverName = (*env)->GetStringUTFChars(env, server, NULL);
235
+-    if (serverName != NULL) {
236
+-        http_t *http = j2d_httpConnect(serverName, (int)port);
237
+-        (*env)->ReleaseStringUTFChars(env, server, serverName);
238
+-        if (http != NULL) {
239
+-            j2d_httpClose(http);
240
+-            return JNI_TRUE;
241
+-        }
242
+-    }
243
+-    return JNI_FALSE;
244
+-}
245
+-
246
+-
247
+-/*
248
+- * Returns list of media: pages + trays
249
+- */
250
+-JNIEXPORT jobjectArray JNICALL
251
+-Java_sun_print_CUPSPrinter_getMedia(JNIEnv *env,
252
+-                                         jobject printObj,
253
+-                                         jstring printer)
254
+-{
255
+-    ppd_file_t *ppd;
256
+-    ppd_option_t *optionTray, *optionPage;
257
+-    ppd_choice_t *choice;
258
+-    const char *name;
259
+-    const char *filename;
260
+-    int i, nTrays=0, nPages=0, nTotal=0;
261
+-    jstring utf_str;
262
+-    jclass cls;
263
+-    jobjectArray nameArray = NULL;
264
+-
265
+-    name = (*env)->GetStringUTFChars(env, printer, NULL);
266
+-    if (name == NULL) {
267
+-        (*env)->ExceptionClear(env);
268
+-        JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
269
+-        return NULL;
270
+-    }
271
+-
272
+-    // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
273
+-    // unlink() must be caled to remove the file when finished using it.
274
+-    filename = j2d_cupsGetPPD(name);
275
+-    (*env)->ReleaseStringUTFChars(env, printer, name);
276
+-    CHECK_NULL_RETURN(filename, NULL);
277
+-
278
+-    cls = (*env)->FindClass(env, "java/lang/String");
279
+-    CHECK_NULL_RETURN(cls, NULL);
280
+-
281
+-    if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
282
+-        unlink(filename);
283
+-        DPRINTF("CUPSfuncs::unable to open PPD  %s\n", filename);
284
+-        return NULL;
285
+-    }
286
+-
287
+-    optionPage = j2d_ppdFindOption(ppd, "PageSize");
288
+-    if (optionPage != NULL) {
289
+-        nPages = optionPage->num_choices;
290
+-    }
291
+-
292
+-    optionTray = j2d_ppdFindOption(ppd, "InputSlot");
293
+-    if (optionTray != NULL) {
294
+-        nTrays = optionTray->num_choices;
295
+-    }
296
+-
297
+-    if ((nTotal = (nPages+nTrays) *2) > 0) {
298
+-        nameArray = (*env)->NewObjectArray(env, nTotal, cls, NULL);
299
+-        if (nameArray == NULL) {
300
+-            unlink(filename);
301
+-            j2d_ppdClose(ppd);
302
+-            DPRINTF("CUPSfuncs::bad alloc new array\n", "")
303
+-            (*env)->ExceptionClear(env);
304
+-            JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
305
+-            return NULL;
306
+-        }
307
+-
308
+-        for (i = 0; optionPage!=NULL && i<nPages; i++) {
309
+-            choice = (optionPage->choices)+i;
310
+-            utf_str = JNU_NewStringPlatform(env, choice->text);
311
+-            if (utf_str == NULL) {
312
+-                unlink(filename);
313
+-                j2d_ppdClose(ppd);
314
+-                DPRINTF("CUPSfuncs::bad alloc new string ->text\n", "")
315
+-                JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
316
+-                return NULL;
317
+-            }
318
+-            (*env)->SetObjectArrayElement(env, nameArray, i*2, utf_str);
319
+-            (*env)->DeleteLocalRef(env, utf_str);
320
+-            utf_str = JNU_NewStringPlatform(env, choice->choice);
321
+-            if (utf_str == NULL) {
322
+-                unlink(filename);
323
+-                j2d_ppdClose(ppd);
324
+-                DPRINTF("CUPSfuncs::bad alloc new string ->choice\n", "")
325
+-                JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
326
+-                return NULL;
327
+-            }
328
+-            (*env)->SetObjectArrayElement(env, nameArray, i*2+1, utf_str);
329
+-            (*env)->DeleteLocalRef(env, utf_str);
330
+-        }
331
+-
332
+-        for (i = 0; optionTray!=NULL && i<nTrays; i++) {
333
+-            choice = (optionTray->choices)+i;
334
+-            utf_str = JNU_NewStringPlatform(env, choice->text);
335
+-            if (utf_str == NULL) {
336
+-                unlink(filename);
337
+-                j2d_ppdClose(ppd);
338
+-                DPRINTF("CUPSfuncs::bad alloc new string text\n", "")
339
+-                JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
340
+-                return NULL;
341
+-            }
342
+-            (*env)->SetObjectArrayElement(env, nameArray,
343
+-                                          (nPages+i)*2, utf_str);
344
+-            (*env)->DeleteLocalRef(env, utf_str);
345
+-            utf_str = JNU_NewStringPlatform(env, choice->choice);
346
+-            if (utf_str == NULL) {
347
+-                unlink(filename);
348
+-                j2d_ppdClose(ppd);
349
+-                DPRINTF("CUPSfuncs::bad alloc new string choice\n", "")
350
+-                JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
351
+-                return NULL;
352
+-            }
353
+-            (*env)->SetObjectArrayElement(env, nameArray,
354
+-                                          (nPages+i)*2+1, utf_str);
355
+-            (*env)->DeleteLocalRef(env, utf_str);
356
+-        }
357
+-    }
358
+-    j2d_ppdClose(ppd);
359
+-    unlink(filename);
360
+-    return nameArray;
361
+-}
362
+-
363
+-
364
+-/*
365
+- * Returns list of page sizes and imageable area.
366
+- */
367
+-JNIEXPORT jfloatArray JNICALL
368
+-Java_sun_print_CUPSPrinter_getPageSizes(JNIEnv *env,
369
+-                                         jobject printObj,
370
+-                                         jstring printer)
371
+-{
372
+-    ppd_file_t *ppd;
373
+-    ppd_option_t *option;
374
+-    ppd_choice_t *choice;
375
+-    ppd_size_t *size;
376
+-
377
+-    const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
378
+-    if (name == NULL) {
379
+-        (*env)->ExceptionClear(env);
380
+-        JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
381
+-        return NULL;
382
+-    }
383
+-    const char *filename;
384
+-    int i;
385
+-    jobjectArray sizeArray = NULL;
386
+-    jfloat *dims;
387
+-
388
+-    // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
389
+-    // unlink() must be called to remove the file after using it.
390
+-    filename = j2d_cupsGetPPD(name);
391
+-    (*env)->ReleaseStringUTFChars(env, printer, name);
392
+-    CHECK_NULL_RETURN(filename, NULL);
393
+-    if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
394
+-        unlink(filename);
395
+-        DPRINTF("unable to open PPD  %s\n", filename)
396
+-        return NULL;
397
+-    }
398
+-    option = j2d_ppdFindOption(ppd, "PageSize");
399
+-    if (option != NULL && option->num_choices > 0) {
400
+-        // create array of dimensions - (num_choices * 6)
401
+-        //to cover length & height
402
+-        DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices)
403
+-        // +1 is for storing the default media index
404
+-        sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1);
405
+-        if (sizeArray == NULL) {
406
+-            unlink(filename);
407
+-            j2d_ppdClose(ppd);
408
+-            DPRINTF("CUPSfuncs::bad alloc new float array\n", "")
409
+-            (*env)->ExceptionClear(env);
410
+-            JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
411
+-            return NULL;
412
+-        }
413
+-
414
+-        dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL);
415
+-        if (dims == NULL) {
416
+-            unlink(filename);
417
+-            j2d_ppdClose(ppd);
418
+-            (*env)->ExceptionClear(env);
419
+-            JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
420
+-            return NULL;
421
+-        }
422
+-        for (i = 0; i<option->num_choices; i++) {
423
+-            choice = (option->choices)+i;
424
+-            // get the index of the default page
425
+-            if (!strcmp(choice->choice, option->defchoice)) {
426
+-                dims[option->num_choices*6] = (float)i;
427
+-            }
428
+-            size = j2d_ppdPageSize(ppd, choice->choice);
429
+-            if (size != NULL) {
430
+-                // paper width and height
431
+-                dims[i*6] = size->width;
432
+-                dims[(i*6)+1] = size->length;
433
+-                // paper printable area
434
+-                dims[(i*6)+2] = size->left;
435
+-                dims[(i*6)+3] = size->top;
436
+-                dims[(i*6)+4] = size->right;
437
+-                dims[(i*6)+5] = size->bottom;
438
+-            }
439
+-        }
440
+-
441
+-        (*env)->ReleaseFloatArrayElements(env, sizeArray, dims, 0);
442
+-    }
443
+-
444
+-    j2d_ppdClose(ppd);
445
+-    unlink(filename);
446
+-    return sizeArray;
447
+-}