提交 9d72a242 编写于 作者: P psadhukhan

8058316: lookupDefaultPrintService returns null on Solaris 11

Reviewed-by: prr, jdv
上级 2e3ff1bd
...@@ -201,6 +201,7 @@ SUNWprivate_1.1 { ...@@ -201,6 +201,7 @@ SUNWprivate_1.1 {
Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort; Java_sun_print_CUPSPrinter_getCupsPort;
Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes; Java_sun_print_CUPSPrinter_getPageSizes;
......
...@@ -73,6 +73,7 @@ SUNWprivate_1.1 { ...@@ -73,6 +73,7 @@ SUNWprivate_1.1 {
Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort; Java_sun_print_CUPSPrinter_getCupsPort;
Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes; Java_sun_print_CUPSPrinter_getPageSizes;
......
...@@ -439,6 +439,7 @@ SUNWprivate_1.1 { ...@@ -439,6 +439,7 @@ SUNWprivate_1.1 {
Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_initIDs;
Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsServer;
Java_sun_print_CUPSPrinter_getCupsPort; Java_sun_print_CUPSPrinter_getCupsPort;
Java_sun_print_CUPSPrinter_getCupsDefaultPrinter;
Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_canConnect;
Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getMedia;
Java_sun_print_CUPSPrinter_getPageSizes; Java_sun_print_CUPSPrinter_getPageSizes;
......
...@@ -51,6 +51,7 @@ public class CUPSPrinter { ...@@ -51,6 +51,7 @@ public class CUPSPrinter {
private boolean initialized; private boolean initialized;
private static native String getCupsServer(); private static native String getCupsServer();
private static native int getCupsPort(); private static native int getCupsPort();
private static native String getCupsDefaultPrinter();
private static native boolean canConnect(String server, int port); private static native boolean canConnect(String server, int port);
private static native boolean initIDs(); private static native boolean initIDs();
// These functions need to be synchronized as // These functions need to be synchronized as
...@@ -250,6 +251,15 @@ public class CUPSPrinter { ...@@ -250,6 +251,15 @@ public class CUPSPrinter {
* Returns 2 values - index 0 is printer name, index 1 is the uri. * Returns 2 values - index 0 is printer name, index 1 is the uri.
*/ */
static String[] getDefaultPrinter() { 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 { try {
URL url = new URL("http", getServer(), getPort(), ""); URL url = new URL("http", getServer(), getPort(), "");
final HttpURLConnection urlConnection = final HttpURLConnection urlConnection =
...@@ -285,7 +295,7 @@ public class CUPSPrinter { ...@@ -285,7 +295,7 @@ public class CUPSPrinter {
attCl)) { attCl)) {
HashMap defaultMap = null; HashMap defaultMap = null;
String[] printerInfo = new String[2];
InputStream is = urlConnection.getInputStream(); InputStream is = urlConnection.getInputStream();
HashMap[] responseMap = IPPPrintService.readIPPResponse( HashMap[] responseMap = IPPPrintService.readIPPResponse(
is); is);
......
...@@ -43,6 +43,10 @@ typedef int (*fn_ippPort)(void); ...@@ -43,6 +43,10 @@ typedef int (*fn_ippPort)(void);
typedef http_t* (*fn_httpConnect)(const char *, int); typedef http_t* (*fn_httpConnect)(const char *, int);
typedef void (*fn_httpClose)(http_t *); typedef void (*fn_httpClose)(http_t *);
typedef char* (*fn_cupsGetPPD)(const char *); 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 ppd_file_t* (*fn_ppdOpenFile)(const char *);
typedef void (*fn_ppdClose)(ppd_file_t *); typedef void (*fn_ppdClose)(ppd_file_t *);
typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *); typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *);
...@@ -53,6 +57,9 @@ fn_ippPort j2d_ippPort; ...@@ -53,6 +57,9 @@ fn_ippPort j2d_ippPort;
fn_httpConnect j2d_httpConnect; fn_httpConnect j2d_httpConnect;
fn_httpClose j2d_httpClose; fn_httpClose j2d_httpClose;
fn_cupsGetPPD j2d_cupsGetPPD; fn_cupsGetPPD j2d_cupsGetPPD;
fn_cupsGetDest j2d_cupsGetDest;
fn_cupsGetDests j2d_cupsGetDests;
fn_cupsFreeDests j2d_cupsFreeDests;
fn_ppdOpenFile j2d_ppdOpenFile; fn_ppdOpenFile j2d_ppdOpenFile;
fn_ppdClose j2d_ppdClose; fn_ppdClose j2d_ppdClose;
fn_ppdFindOption j2d_ppdFindOption; fn_ppdFindOption j2d_ppdFindOption;
...@@ -106,6 +113,24 @@ Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env, ...@@ -106,6 +113,24 @@ Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env,
return JNI_FALSE; 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"); j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile");
if (j2d_ppdOpenFile == NULL) { if (j2d_ppdOpenFile == NULL) {
dlclose(handle); dlclose(handle);
...@@ -169,6 +194,30 @@ Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env, ...@@ -169,6 +194,30 @@ Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env,
} }
/*
* 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. * Checks if connection can be made to the server.
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册