for the issue that GetPrinterList does not return printer descriptions on Solaris. The patch implements a framework which allows the printer enumerator scripts to pass additional printer attributes to the information pool (currently only "xp-printerattr.descriptor" is implemented).
This commit is contained in:
parent
884908a63c
commit
ad6b9644a3
|
@ -2,11 +2,12 @@
|
||||||
/*
|
/*
|
||||||
(c) Copyright 1996 Hewlett-Packard Company
|
(c) Copyright 1996 Hewlett-Packard Company
|
||||||
(c) Copyright 1996 International Business Machines Corp.
|
(c) Copyright 1996 International Business Machines Corp.
|
||||||
(c) Copyright 1996 Sun Microsystems, Inc.
|
(c) Copyright 1996-2004 Sun Microsystems, Inc.
|
||||||
(c) Copyright 1996 Novell, Inc.
|
(c) Copyright 1996 Novell, Inc.
|
||||||
(c) Copyright 1996 Digital Equipment Corp.
|
(c) Copyright 1996 Digital Equipment Corp.
|
||||||
(c) Copyright 1996 Fujitsu Limited
|
(c) Copyright 1996 Fujitsu Limited
|
||||||
(c) Copyright 1996 Hitachi, Ltd.
|
(c) Copyright 1996 Hitachi, Ltd.
|
||||||
|
(c) Copyright 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -245,6 +246,7 @@ typedef struct _printerDbEntry {
|
||||||
char *qualifier;
|
char *qualifier;
|
||||||
int screenNum;
|
int screenNum;
|
||||||
char *driverName;
|
char *driverName;
|
||||||
|
char *desc;
|
||||||
} PrinterDbEntry, *PrinterDbPtr;
|
} PrinterDbEntry, *PrinterDbPtr;
|
||||||
|
|
||||||
static PrinterDbPtr printerDb = (PrinterDbPtr)NULL;
|
static PrinterDbPtr printerDb = (PrinterDbPtr)NULL;
|
||||||
|
@ -456,6 +458,8 @@ FreePrinterDb(void)
|
||||||
pNextEntry = pCurEntry->next;
|
pNextEntry = pCurEntry->next;
|
||||||
if(pCurEntry->name != (char *)NULL)
|
if(pCurEntry->name != (char *)NULL)
|
||||||
xfree(pCurEntry->name);
|
xfree(pCurEntry->name);
|
||||||
|
if(pCurEntry->desc != (char *)NULL)
|
||||||
|
xfree(pCurEntry->desc);
|
||||||
/*
|
/*
|
||||||
* We don't free the driver name, because it's expected to simply
|
* We don't free the driver name, because it's expected to simply
|
||||||
* be a pointer into the xrm database.
|
* be a pointer into the xrm database.
|
||||||
|
@ -472,12 +476,13 @@ FreePrinterDb(void)
|
||||||
* XXX AddPrinterDbName needs to check for (and not add) duplicate names.
|
* XXX AddPrinterDbName needs to check for (and not add) duplicate names.
|
||||||
*/
|
*/
|
||||||
static Bool
|
static Bool
|
||||||
AddPrinterDbName(char *name)
|
AddPrinterDbName(char *name, char *desc)
|
||||||
{
|
{
|
||||||
PrinterDbPtr pEntry = (PrinterDbPtr)xalloc(sizeof(PrinterDbEntry));
|
PrinterDbPtr pEntry = (PrinterDbPtr)xalloc(sizeof(PrinterDbEntry));
|
||||||
|
|
||||||
if(pEntry == (PrinterDbPtr)NULL) return FALSE;
|
if(pEntry == (PrinterDbPtr)NULL) return FALSE;
|
||||||
pEntry->name = strdup(name);
|
pEntry->name = (name != NULL) ? strdup(name) : NULL;
|
||||||
|
pEntry->desc = (desc != NULL) ? strdup(desc) : NULL;
|
||||||
pEntry->qualifier = (char *)NULL;
|
pEntry->qualifier = (char *)NULL;
|
||||||
|
|
||||||
if(printerDb == (PrinterDbPtr)NULL)
|
if(printerDb == (PrinterDbPtr)NULL)
|
||||||
|
@ -499,13 +504,35 @@ AugmentPrinterDb(const char *command)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char name[256];
|
char name[256];
|
||||||
int num_printers = 0; /* Number of printers we found */
|
int num_printers = 0; /* Number of printers we found */
|
||||||
|
size_t namelen;
|
||||||
|
char *desc = NULL;
|
||||||
|
|
||||||
fp = popen(command, "r");
|
fp = popen(command, "r");
|
||||||
/* XXX is a 256 character limit overly restrictive for printer names? */
|
/* XXX is a 256 character limit overly restrictive for printer names? */
|
||||||
while(fgets(name, 256, fp) != (char *)NULL && strlen(name))
|
while(fgets(name, 256, fp) != (char *)NULL && (namelen=strlen(name)))
|
||||||
{
|
{
|
||||||
name[strlen(name) - 1] = (char)'\0'; /* strip the \n */
|
char *option = name;
|
||||||
AddPrinterDbName(name);
|
|
||||||
|
name[namelen-1] = (char)'\0'; /* strip the \n */
|
||||||
|
|
||||||
|
#define XP_DESCRIPTOR "xp-printerattr.descriptor="
|
||||||
|
#define XP_DESCRIPTOR_LEN (sizeof(XP_DESCRIPTOR)-1)
|
||||||
|
while (option = strchr(option, '\t')) {
|
||||||
|
option++; /* Skip the '\t' */
|
||||||
|
if (!strncmp(option, XP_DESCRIPTOR, XP_DESCRIPTOR_LEN)) {
|
||||||
|
*(option-1) = '\0'; /* Kill the '\t' (only if we found a valid option) */
|
||||||
|
option += XP_DESCRIPTOR_LEN;
|
||||||
|
if (*option != '\0') {
|
||||||
|
desc = option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Unknown option */
|
||||||
|
ErrorF("AugmentPrinterDb: Unknown option '%s'\n", option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AddPrinterDbName(name, desc);
|
||||||
num_printers++;
|
num_printers++;
|
||||||
}
|
}
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
|
@ -645,6 +672,29 @@ StoreDriverNames(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* StoreDescriptors - queries the attribute store for the descriptor.
|
||||||
|
* if the descriptor is not in the attribute database, then the descriptor
|
||||||
|
* from the printerDb is store in the attribute store for the printer.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
StoreDescriptors()
|
||||||
|
{
|
||||||
|
PrinterDbPtr pEntry;
|
||||||
|
|
||||||
|
for(pEntry = printerDb; pEntry != (PrinterDbPtr)NULL;
|
||||||
|
pEntry = pEntry->next)
|
||||||
|
{
|
||||||
|
if (pEntry->desc != NULL)
|
||||||
|
{
|
||||||
|
XpAddPrinterAttribute(pEntry->name,
|
||||||
|
(pEntry->qualifier != (char *)NULL)?
|
||||||
|
pEntry->qualifier : pEntry->name,
|
||||||
|
"*descriptor", pEntry->desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
MbStrchr(
|
MbStrchr(
|
||||||
char *str,
|
char *str,
|
||||||
|
@ -766,7 +816,7 @@ BuildPrinterDb(void)
|
||||||
{
|
{
|
||||||
if(ptr = MbStrchr(tok, '\012'))
|
if(ptr = MbStrchr(tok, '\012'))
|
||||||
*ptr = (char)'\0';
|
*ptr = (char)'\0';
|
||||||
AddPrinterDbName(tok);
|
AddPrinterDbName(tok, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strcmp(tok, "Map") == 0)
|
else if(strcmp(tok, "Map") == 0)
|
||||||
|
@ -855,6 +905,7 @@ BuildPrinterDb(void)
|
||||||
* in the printerDb
|
* in the printerDb
|
||||||
*/
|
*/
|
||||||
StoreDriverNames();
|
StoreDriverNames();
|
||||||
|
StoreDescriptors();
|
||||||
|
|
||||||
if(freeConfigFileName)
|
if(freeConfigFileName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
/* $Xorg: spooler.c,v 1.1 2003/09/14 1:19:56 gisburn Exp $ */
|
/* $Xorg: spooler.c,v 1.1 2003/09/14 1:19:56 gisburn Exp $ */
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
|
Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
|
||||||
|
Copyright (c) 2004 Sun Microsystems, Inc.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -117,7 +118,15 @@ copyright holders.
|
||||||
\
|
\
|
||||||
"[ \"${WHICH_LPSTAT}\" != \"\" ] && (LANG=C lpstat -v | ${NAWK} ' $2 == \"for\" { x = match($3, /:/); print substr($3, 1, x-1) }')\n" \
|
"[ \"${WHICH_LPSTAT}\" != \"\" ] && (LANG=C lpstat -v | ${NAWK} ' $2 == \"for\" { x = match($3, /:/); print substr($3, 1, x-1) }')\n" \
|
||||||
") | egrep -v -i \" |^all$\" | sort | uniq"
|
") | egrep -v -i \" |^all$\" | sort | uniq"
|
||||||
|
|
||||||
|
#define LIST_QUEUES_SOLARIS "LANG=C lpget -k description " \
|
||||||
|
"`lpstat -v " \
|
||||||
|
"| nawk '$2 == \"for\" { x = match($3, /:/); print substr($3, 1,x-1) }' " \
|
||||||
|
"| sort -u` " \
|
||||||
|
"| nawk -F: ' NF == 2 { name=$1 } " \
|
||||||
|
" NF == 1 { sub(\"^.*description\\( - undefined|=\\)\",\"\"); " \
|
||||||
|
" printf \"%sxp-printerattr.descriptor=%s\\n\", name, $1 } '"
|
||||||
|
|
||||||
#define LIST_QUEUES_OTHER \
|
#define LIST_QUEUES_OTHER \
|
||||||
"LANG=C lpstat -v | " \
|
"LANG=C lpstat -v | " \
|
||||||
"nawk '" \
|
"nawk '" \
|
||||||
|
@ -126,11 +135,12 @@ copyright holders.
|
||||||
" x = match($3, /:/); " \
|
" x = match($3, /:/); " \
|
||||||
" print substr($3, 1, x-1)" \
|
" print substr($3, 1, x-1)" \
|
||||||
" }' | sort | uniq"
|
" }' | sort | uniq"
|
||||||
|
|
||||||
#define DEFAULT_SPOOL_COMMAND_HPUX "/usr/bin/lp -d %printer-name% -o raw -n %copy-count% -t %job-name% %options%"
|
#define DEFAULT_SPOOL_COMMAND_HPUX "/usr/bin/lp -d %printer-name% -o raw -n %copy-count% -t %job-name% %options%"
|
||||||
#define DEFAULT_SPOOL_COMMAND_BSD "/usr/bin/lpr -P %printer-name% -#%copy-count% -T %job-name% %options%"
|
#define DEFAULT_SPOOL_COMMAND_BSD "/usr/bin/lpr -P %printer-name% -#%copy-count% -T %job-name% %options%"
|
||||||
#define DEFAULT_SPOOL_COMMAND_SYSV "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
|
#define DEFAULT_SPOOL_COMMAND_SYSV "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
|
||||||
#define DEFAULT_SPOOL_COMMAND_OTHER "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
|
#define DEFAULT_SPOOL_COMMAND_SOLARIS "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
|
||||||
|
#define DEFAULT_SPOOL_COMMAND_OTHER "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
|
||||||
|
|
||||||
|
|
||||||
/* List of spooler types and the commands used to enumerate
|
/* List of spooler types and the commands used to enumerate
|
||||||
|
@ -138,21 +148,21 @@ copyright holders.
|
||||||
XpSpoolerType xpstm[] =
|
XpSpoolerType xpstm[] =
|
||||||
{
|
{
|
||||||
/* OS-specific spoolers */
|
/* OS-specific spoolers */
|
||||||
{ "aix", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
|
{ "aix", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
|
||||||
{ "aix4", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
|
{ "aix4", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
|
||||||
{ "bsd", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
|
{ "bsd", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
|
||||||
{ "osf", LIST_QUEUES_OSF, DEFAULT_SPOOL_COMMAND_OTHER },
|
{ "osf", LIST_QUEUES_OSF, DEFAULT_SPOOL_COMMAND_OTHER },
|
||||||
{ "solaris", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
|
{ "solaris", LIST_QUEUES_SOLARIS, DEFAULT_SPOOL_COMMAND_SOLARIS },
|
||||||
{ "sysv", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
|
{ "sysv", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
|
||||||
{ "uxp", LIST_QUEUES_UXP, DEFAULT_SPOOL_COMMAND_OTHER },
|
{ "uxp", LIST_QUEUES_UXP, DEFAULT_SPOOL_COMMAND_OTHER },
|
||||||
/* crossplatform spoolers */
|
/* crossplatform spoolers */
|
||||||
{ "cups", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
|
{ "cups", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
|
||||||
{ "lprng", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
|
{ "lprng", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
|
||||||
/* misc */
|
/* misc */
|
||||||
{ "other", LIST_QUEUES_OTHER, DEFAULT_SPOOL_COMMAND_OTHER },
|
{ "other", LIST_QUEUES_OTHER, DEFAULT_SPOOL_COMMAND_OTHER },
|
||||||
{ "none", NULL, NULL },
|
{ "none", NULL, NULL },
|
||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Used by Init.c and attributes.c */
|
/* Used by Init.c and attributes.c */
|
||||||
XpSpoolerTypePtr spooler_type = NULL;
|
XpSpoolerTypePtr spooler_type = NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user