summaryrefslogtreecommitdiff
path: root/Xprint/attributes.c
diff options
context:
space:
mode:
authorEgbert Eich <eich@suse.de>2004-04-23 19:54:30 +0000
committerEgbert Eich <eich@suse.de>2004-04-23 19:54:30 +0000
commit2fb588620030ad393f8500d60e16144d59e4effe (patch)
tree07262cbe15a40e5aeae54f62751260f83243ab79 /Xprint/attributes.c
parent0664db19bf37f9dd69cca6adff4e238e310c3092 (diff)
Merging XORG-CURRENT into trunk
Diffstat (limited to 'Xprint/attributes.c')
-rw-r--r--Xprint/attributes.c137
1 files changed, 102 insertions, 35 deletions
diff --git a/Xprint/attributes.c b/Xprint/attributes.c
index e1fce8cb3..d02c54e37 100644
--- a/Xprint/attributes.c
+++ b/Xprint/attributes.c
@@ -44,18 +44,15 @@ copyright holders.
** *********************************************************
**
********************************************************************/
-/* $XFree86: xc/programs/Xserver/Xprint/attributes.c,v 1.21 2003/12/19 02:05:38 dawes Exp $ */
-#include <X11/Xproto.h>
+#include <Xproto.h>
#include <string.h>
#include <stdlib.h>
-#include <sys/types.h>
#include <sys/wait.h>
#include <pwd.h>
#if (defined(sun) && defined(SVR4)) || (defined(SCO))
#include <wchar.h>
#endif
-
#include "scrnintstr.h"
#include <X11/extensions/Printstr.h>
@@ -66,11 +63,13 @@ copyright holders.
#include "Xresource.h"
#include "Xrm.c"
+#include "spooler.h"
+
static XrmDatabase CopyDb(XrmDatabase inDb);
extern XrmDatabase XpSpoolerGetServerAttributes(void);
-static unsigned long attrGeneration = 0;
+static int attrGeneration = 0;
typedef struct {
XrmDatabase *pDb;
@@ -137,6 +136,26 @@ static const char XPMODELDIR[] = "/models";
static char NULL_STRING[] = "\0";
/*
+ * XpGetConfigDirBase returns a string containing the path name of the base
+ * where the print server configuration directory is localed.
+ */
+static
+char *XpGetConfigDirBase()
+{
+ char **configDir;
+
+ /*
+ * If the XPCONFIGDIR environment variable is not set, then use the
+ * compile-time constant XPRINTDIR. XPRINTDIR is passed in on the
+ * compile command line, and is defined in $(TOP)/config/cf/Project.tmpl.
+ */
+ if((configDir = getenv("XPCONFIGDIR")) == (char *)NULL)
+ configDir = XPRINTDIR;
+
+ return configDir;
+}
+
+/*
* XpGetConfigDir returns a string containing the path name of the print
* server configuration directory. If the useLocale parameter is False
* the it returns the path to the "/C" directory. If the useLocale
@@ -164,13 +183,7 @@ XpGetConfigDir(Bool useLocale)
}
}
- /*
- * If the XPCONFIGDIR environment variable is not set, then use the
- * compile-time constant XPRINTDIR. XPRINTDIR is passed in on the
- * compile command line, and is defined in $(TOP)/config/cf/Project.tmpl.
- */
- if((configDir = getenv("XPCONFIGDIR")) == (char *)NULL)
- configDir = XPRINTDIR;
+ configDir = XpGetConfigDirBase();
dirName = (char *)xalloc(strlen(configDir) + strlen(XPDIR) +
strlen(langDir) + 1);
@@ -306,7 +319,7 @@ BuildPrinterAttrs(
if(systemAttributes.printers != (XrmDatabase)NULL)
{
- char *fileName;
+ char *dirName, *fileName;
XrmDatabase modelDB = (XrmDatabase)NULL;
XrmName xrm_name[5], xrm_class[2];
XrmRepresentation rep_type;
@@ -606,6 +619,7 @@ XpGetOneAttribute(
{
ContextAttrPtr pCtxtAttrs;
XrmDatabase db = (XrmDatabase)NULL;
+ char *retVal;
XrmName xrm_name[3];
XrmRepresentation rep_type;
XrmValue value;
@@ -669,10 +683,10 @@ XpGetOneAttribute(
*/
void
XpPutOneAttribute(
- XpContextPtr pContext,
- XPAttributes class,
- const char* attributeName,
- const char* value)
+ XpContextPtr pContext,
+ XPAttributes class,
+ const char* attributeName,
+ const char* value)
{
ContextAttrPtr pCtxtAttrs;
XrmDatabase db;
@@ -797,7 +811,7 @@ AppendEntry(
char *s, c;
if (*type != XrmQString)
- return False;
+ return;
for (firstNameSeen = False; *quarks; bindings++, quarks++) {
if (*bindings == XrmBindLoosely) {
@@ -856,6 +870,7 @@ XpGetAttributes(
{
ContextAttrPtr pCtxtAttrs;
XrmDatabase db = (XrmDatabase)NULL;
+ char *retVal;
StringDbStruct enumStruct;
XrmQuark empty = NULLQUARK;
@@ -1064,6 +1079,34 @@ XpSpoolerGetServerAttributes(void)
}
/*
+ * ExecuteCommand takes two pointers - the command to execute,
+ * and the "argv" style NULL-terminated vector of arguments for the command.
+ * We wait for the command to terminate before continuing to ensure that
+ * we don't delete the job file before the spooler has made a copy.
+ */
+static void
+ExecCommand(pCommand, argVector)
+ char *pCommand;
+ char **argVector;
+{
+ pid_t childPid;
+ int status;
+
+ if((childPid = fork()) == 0)
+ {
+ /* return BadAlloc? */
+ if (execv(pCommand, argVector) == -1) {
+ FatalError("unable to exec '%s'", pCommand);
+ }
+ }
+ else
+ {
+ (void) waitpid(childPid, &status, 0);
+ }
+ return;
+}
+
+/*
* SendFileToCommand takes three character pointers - the file name,
* the command to execute,
* and the "argv" style NULL-terminated vector of arguments for the command.
@@ -1119,7 +1162,9 @@ SendFileToCommand(
*/
if(userName)
{
- if(geteuid() == (uid_t)0)
+ uid_t myUid;
+
+ if((myUid = geteuid()) == (uid_t)0)
{
struct passwd *pPasswd;
@@ -1136,6 +1181,8 @@ SendFileToCommand(
}
else
{
+ int res;
+
(void) close(pipefd[0]);
outPipe = fdopen(pipefd[1], "w");
@@ -1155,6 +1202,7 @@ SendFileToCommand(
* store for the supplied print context. The ReplaceAnyString utility
* routine is used to perform the actual replacements.
*/
+extern char *ReplaceAnyString(char *, char *, char *);
static char *
ReplaceAllKeywords(
@@ -1196,6 +1244,10 @@ ReplaceAllKeywords(
else
command = ReplaceAnyString(command, "%options%", "");
+ /* New in xprint.mozdev.org release 007 - replace "%xpconfigdir%" with
+ * location of $XPCONFIGDIR */
+ command = ReplaceAnyString(command, "%xpconfigdir%", XpGetConfigDirBase());
+
return command;
}
@@ -1366,43 +1418,58 @@ VectorizeCommand(
char ***pVector,
XpContextPtr pContext)
{
- char *cmdName;
+ char *cmdName, *curTok;
+ int i, numChars;
if(command == (char *)NULL)
return (char *)NULL;
- (void) GetToken(command, &cmdName);
+ numChars = GetToken(command, &cmdName);
if(cmdName == (char *)NULL)
return (char *)NULL;
- *pVector = BuildArgVector(command, pContext);
+ /* Mangle the command name, too... */
+ cmdName = ReplaceAllKeywords(pContext, cmdName);
+ if(cmdName == (char *)NULL)
+ return (char *)NULL;
+
+ *pVector = BuildArgVector(command, pContext);
+
return cmdName;
}
-#ifdef hpux
-static char DEFAULT_SPOOL_COMMAND[] = "/usr/bin/lp -d %printer-name% -o raw -n %copy-count% -t %job-name% %options%";
-#else
-static char DEFAULT_SPOOL_COMMAND[] = "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%";
-#endif
-
int
-XpSubmitJob(
- char *fileName,
- XpContextPtr pContext)
+XpSubmitJob(fileName, pContext)
+ char *fileName;
+ XpContextPtr pContext;
{
- char **vector, *cmdNam, *command, *userName;
+ char **vector, *cmdNam, *cmdOpt, *command, *userName;
int i;
command = XpGetOneAttribute(pContext, XPPrinterAttr, "xp-spooler-command");
if(command == (char *)NULL || strlen(command) == 0)
- command = strdup(DEFAULT_SPOOL_COMMAND);
+ {
+ if( spooler_type )
+ {
+ command = strdup(spooler_type->spool_command);
+ }
+ else
+ {
+ ErrorF("XpSubmitJob: No default spool command defined.\n");
+ }
+ }
else
+ {
command = strdup(command);
+ }
if(command == (char *)NULL)
+ {
+ ErrorF("XpSubmitJob: No spooler command found, cannot submit job.\n");
return BadAlloc;
-
+ }
+
cmdNam = VectorizeCommand(command, &vector, pContext);
xfree(command);
@@ -1430,7 +1497,6 @@ XpSubmitJob(
FreeVector(vector);
xfree(cmdNam);
- return Success;
}
/*
@@ -1503,6 +1569,7 @@ XpGetTrayMediumFromContext(XpContextPtr pCon,
{
char *defMedium, *defTray;
char *t, *m;
+ char *pS, *pE, *pLast;
defMedium = XpGetOneAttribute( pCon, XPPageAttr,
"default-medium" );