8058316: lookupDefaultPrintService returns null on Solaris 11
Reviewed-by: prr, jdv
--- a/jdk/make/mapfiles/libawt/mapfile-mawt-vers Fri Mar 04 18:42:16 2016 +0300
+++ b/jdk/make/mapfiles/libawt/mapfile-mawt-vers Mon Mar 07 11:54:42 2016 +0530
@@ -200,6 +200,7 @@
Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort;
+ Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes;
--- a/jdk/make/mapfiles/libawt_headless/mapfile-vers Fri Mar 04 18:42:16 2016 +0300
+++ b/jdk/make/mapfiles/libawt_headless/mapfile-vers Mon Mar 07 11:54:42 2016 +0530
@@ -73,6 +73,7 @@
Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort;
+ Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes;
--- a/jdk/make/mapfiles/libawt_xawt/mapfile-vers Fri Mar 04 18:42:16 2016 +0300
+++ b/jdk/make/mapfiles/libawt_xawt/mapfile-vers Mon Mar 07 11:54:42 2016 +0530
@@ -439,6 +439,7 @@
Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort;
+ Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes;
--- a/jdk/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java Fri Mar 04 18:42:16 2016 +0300
+++ b/jdk/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java Mon Mar 07 11:54:42 2016 +0530
@@ -52,6 +52,7 @@
private boolean initialized;
private static native String getCupsServer();
private static native int getCupsPort();
+ private static native String getCupsDefaultPrinter();
private static native boolean canConnect(String server, int port);
private static native boolean initIDs();
// These functions need to be synchronized as
@@ -266,6 +267,15 @@
* Returns 2 values - index 0 is printer name, index 1 is the uri.
*/
static String[] getDefaultPrinter() {
+ // Try to get user/lpoptions-defined printer name from CUPS
+ // if not user-set, then go for server default destination
+ String printerInfo[] = new String[2];
+ printerInfo[0] = getCupsDefaultPrinter();
+
+ if (printerInfo[0] != null) {
+ printerInfo[1] = null;
+ return printerInfo.clone();
+ }
try {
URL url = new URL("http", getServer(), getPort(), "");
final HttpURLConnection urlConnection =
@@ -301,7 +311,7 @@
attCl)) {
HashMap<String, AttributeClass> defaultMap = null;
- String[] printerInfo = new String[2];
+
InputStream is = urlConnection.getInputStream();
HashMap<String, AttributeClass>[] responseMap = IPPPrintService.readIPPResponse(
is);
--- a/jdk/src/java.desktop/unix/native/common/awt/CUPSfuncs.c Fri Mar 04 18:42:16 2016 +0300
+++ b/jdk/src/java.desktop/unix/native/common/awt/CUPSfuncs.c Mon Mar 07 11:54:42 2016 +0530
@@ -43,6 +43,10 @@
typedef http_t* (*fn_httpConnect)(const char *, int);
typedef void (*fn_httpClose)(http_t *);
typedef char* (*fn_cupsGetPPD)(const char *);
+typedef cups_dest_t* (*fn_cupsGetDest)(const char *name,
+ const char *instance, int num_dests, cups_dest_t *dests);
+typedef int (*fn_cupsGetDests)(cups_dest_t **dests);
+typedef void (*fn_cupsFreeDests)(int num_dests, cups_dest_t *dests);
typedef ppd_file_t* (*fn_ppdOpenFile)(const char *);
typedef void (*fn_ppdClose)(ppd_file_t *);
typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *);
@@ -53,6 +57,9 @@
fn_httpConnect j2d_httpConnect;
fn_httpClose j2d_httpClose;
fn_cupsGetPPD j2d_cupsGetPPD;
+fn_cupsGetDest j2d_cupsGetDest;
+fn_cupsGetDests j2d_cupsGetDests;
+fn_cupsFreeDests j2d_cupsFreeDests;
fn_ppdOpenFile j2d_ppdOpenFile;
fn_ppdClose j2d_ppdClose;
fn_ppdFindOption j2d_ppdFindOption;
@@ -106,6 +113,24 @@
return JNI_FALSE;
}
+ j2d_cupsGetDest = (fn_cupsGetDest)dlsym(handle, "cupsGetDest");
+ if (j2d_cupsGetDest == NULL) {
+ dlclose(handle);
+ return JNI_FALSE;
+ }
+
+ j2d_cupsGetDests = (fn_cupsGetDests)dlsym(handle, "cupsGetDests");
+ if (j2d_cupsGetDests == NULL) {
+ dlclose(handle);
+ return JNI_FALSE;
+ }
+
+ j2d_cupsFreeDests = (fn_cupsFreeDests)dlsym(handle, "cupsFreeDests");
+ if (j2d_cupsFreeDests == NULL) {
+ dlclose(handle);
+ return JNI_FALSE;
+ }
+
j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile");
if (j2d_ppdOpenFile == NULL) {
dlclose(handle);
@@ -170,6 +195,30 @@
/*
+ * Gets CUPS default printer name.
+ *
+ */
+JNIEXPORT jstring JNICALL
+Java_sun_print_CUPSPrinter_getCupsDefaultPrinter(JNIEnv *env,
+ jobject printObj)
+{
+ jstring cDefPrinter = NULL;
+ cups_dest_t *dests;
+ char *defaultPrinter = NULL;
+ int num_dests = j2d_cupsGetDests(&dests);
+ int i = 0;
+ cups_dest_t *dest = j2d_cupsGetDest(NULL, NULL, num_dests, dests);
+ if (dest != NULL) {
+ defaultPrinter = dest->name;
+ if (defaultPrinter != NULL) {
+ cDefPrinter = JNU_NewStringPlatform(env, defaultPrinter);
+ }
+ }
+ j2d_cupsFreeDests(num_dests, dests);
+ return cDefPrinter;
+}
+
+/*
* Checks if connection can be made to the server.
*
*/