print command for the service and inserting the printer name and the
print file name. Return NULL on error, else the passed buffer pointer.
****************************************************************************/
-static char *build_print_command(connection_struct *conn, int snum,
+static char *build_print_command(connection_struct *conn,
char *command,
- char *syscmd, char *filename1)
+ char *syscmd, char *filename)
{
+ int snum = SNUM(conn);
char *tstr;
- pstring filename;
/* get the print command for the service. */
tstr = command;
DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
}
- if (strstr(syscmd,"%s")) {
- pstrcpy(filename,filename1);
-
- string_sub(syscmd, "%s", filename);
- }
-
- string_sub(syscmd, "%f", filename1);
+ pstring_sub(syscmd, "%s", filename);
+ pstring_sub(syscmd, "%f", filename);
/* Does the service have a printername? If not, make a fake
and empty */
tstr = SERVICE(snum);
}
- string_sub(syscmd, "%p", tstr);
+ pstring_sub(syscmd, "%p", tstr);
+
+ standard_sub(conn,syscmd);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
-
return (syscmd);
}
/****************************************************************************
print a file - called on closing the file
****************************************************************************/
-void print_file(connection_struct *conn, int snum, files_struct *file)
+void print_file(connection_struct *conn, files_struct *file)
{
pstring syscmd;
+ int snum = SNUM(conn);
char *tempstr;
*syscmd = 0;
return;
}
- tempstr = build_print_command(conn, snum,
+ tempstr = build_print_command(conn,
PRINTCOMMAND(snum),
syscmd, file->fsp_name);
if (tempstr != NULL) {
return(False);
/* the Job and Total columns must be integer */
- if (!isdigit(*tok[JOBTOK]) || !isdigit(*tok[TOTALTOK])) return(False);
+ if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False);
buf->job = atoi(tok[JOBTOK]);
buf->size = atoi(tok[TOTALTOK]);
break;
}
}
+ /* Ensure null termination. */
+ buf->file[sizeof(buf->file)-1] = '\0';
}
#ifdef PRIOTOK
return(False);
}
- if (!isdigit(*tokarr[LPRNG_JOBTOK]) || !isdigit(*tokarr[LPRNG_TOTALTOK])) {
+ if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
return(False);
}
if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
buf->status = LPQ_PRINTING;
- } else if (isdigit(*tokarr[LPRNG_RANKTOK])) {
+ } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
buf->status = LPQ_QUEUED;
} else {
buf->status = LPQ_PAUSED;
break;
}
}
+ /* Ensure null termination. */
+ buf->file[sizeof(buf->file)-1] = '\0';
}
return(True);
int count=0;
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"standard input","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0;
count<10 &&
}
if (!header_line_ok) return (False); /* incorrect header line */
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"standard input","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
/* we must get 2 tokens */
else if (base_prio) base_prio_reset=False;
/* handle the dash in the job id */
- string_sub(line,"-"," ");
+ pstring_sub(line,"-"," ");
for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
/****************************************************************************
-parse a lpq line
+parse a lpstat line
here is an example of "lpstat -o dcslw" output under sysv
int count=0;
char *p;
- /* handle the dash in the job id */
- string_sub(line,"-"," ");
-
- for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
+ /*
+ * Handle the dash in the job id, but make sure that we skip over
+ * the printer name in case we have a dash in that.
+ * Patch from Dom.Mitchell@palmerharvey.co.uk.
+ */
+
+ /*
+ * Move to the first space.
+ */
+ for (p = line ; !isspace(*p) && *p; p++)
+ ;
+
+ /*
+ * Back up until the last '-' character or
+ * start of line.
+ */
+ for (; (p >= line) && (*p != '-'); p--)
+ ;
+
+ if((p >= line) && (*p == '-'))
+ *p = ' ';
+
+ for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++)
+ ;
/* we must get 7 tokens */
if (count < 7)
return(False);
/* the 2nd and 4th, 6th columns must be integer */
- if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) return(False);
- if (!isdigit((int)*tok[5])) return(False);
+ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))
+ return(False);
+ if (!isdigit((int)*tok[5]))
+ return(False);
/* if the user contains a ! then trim the first part of it */
- if ((p=strchr(tok[2],'!')))
- {
+ if ((p=strchr(tok[2],'!'))) {
fstring tmp;
fstrcpy(tmp,p+1);
fstrcpy(tok[2],tmp);
- }
-
+ }
buf->job = atoi(tok[1]);
buf->size = atoi(tok[3]);
DEBUG(4,("antes [%s]\n", line));
/* handle the case of "-- standard input --" as a filename */
- string_sub(line,"standard input","STDIN");
+ pstring_sub(line,"standard input","STDIN");
DEBUG(4,("despues [%s]\n", line));
- all_string_sub(line,"-- ","\"");
- all_string_sub(line," --","\"");
+ all_string_sub(line,"-- ","\"",0);
+ all_string_sub(line," --","\"",0);
DEBUG(4,("despues 1 [%s]\n", line));
- string_sub(line,"[job #","");
- string_sub(line,"]","");
+ pstring_sub(line,"[job #","");
+ pstring_sub(line,"]","");
DEBUG(4,("despues 2 [%s]\n", line));
int count=0;
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"stdin","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"stdin","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
int count=0;
/* mung all the ":"s to spaces*/
- string_sub(line,":"," ");
+ pstring_sub(line,":"," ");
for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
t->tm_mon = atoi(tok[count+2]+3);
switch (*tok[count+2])
{
- case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]) + 1900; break;
- default: t->tm_year = atoi(tok[count+2]) + 2000; break;
+ case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break;
+ default: t->tm_year = atoi(tok[count+2]); break;
}
t->tm_hour = atoi(tok[count+3]);
/****************************************************************************
get a printer queue
****************************************************************************/
-int get_printqueue(int snum, connection_struct *conn, print_queue_struct **queue,
+int get_printqueue(int snum,
+ connection_struct *conn,print_queue_struct **queue,
print_status_struct *status)
{
char *lpq_command = lp_lpqcommand(snum);
}
pstrcpy(syscmd,lpq_command);
- string_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%p",printername);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ standard_sub(conn,syscmd);
slprintf(outfile,sizeof(outfile)-1, "%s/lpq.%08x",tmpdir(),str_checksum(syscmd));
break;
}
- bzero((char *)&(*queue)[count],sizeof(**queue));
+ memset((char *)&(*queue)[count],'\0',sizeof(**queue));
/* parse it */
if (!parse_lpq_entry(snum,line,
slprintf(jobstr,sizeof(jobstr)-1,"%d",jobid);
pstrcpy(syscmd,lprm_command);
- string_sub(syscmd,"%p",printername);
- string_sub(syscmd,"%j",jobstr);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%j",jobstr);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
slprintf(jobstr,sizeof(jobstr)-1,"%d",jobid);
pstrcpy(syscmd,lpstatus_command);
- string_sub(syscmd,"%p",printername);
- string_sub(syscmd,"%j",jobstr);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%j",jobstr);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
}
pstrcpy(syscmd,queuestatus_command);
- string_sub(syscmd,"%p",printername);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));