Modifs in smbspool.c
Benoit Astruc
benoit.astruc at free.fr
Tue Apr 13 09:17:07 GMT 2004
Hello,
In order to interop with a Windows software I have to inject some
comments in files (either Poscript or PJL) send by the SMB backend. To
do that I have modify the smbspool.c file (from the source provided on
the Apple site, samba-48, because the programm on which I am working
is under Mac OS X). Now my modified smb backend launch an extern
programm which ask the user some informations and then send those infos
after the initial file juste before the connection was closed.
I have first post it on cups.development
(http://www.cups.org/newsgroups.php?s251+gcups.development+Gcups)
because it's printing considerations, but this file is part of the
Samba Project so I proposed it here (thanks to Lars Mueller for the
address).
This is the result of a diff -u on smbspool.c :
-------------- next part --------------
--- Samba original/samba-48/samba/source/client/smbspool.c Sat Oct 25 01:21:25 2003
+++ samba-48/samba/source/client/smbspool.c Tue Apr 13 10:18:12 2004
@@ -24,6 +23,9 @@
#include "includes.h"
+//path to our binary which say what we add to the printed file
+#define PATH "/usr/libexec/watchdoc/greffon"
+
/*
* Globals...
*/
@@ -37,8 +38,7 @@
static void list_devices(void);
static struct cli_state *smb_connect(const char *, const char *, const char *, const char *, const char *);
-static int smb_print(struct cli_state *, char *, FILE *);
+static int smb_print(struct cli_state *, char */*title*/,char */*login*/,const char */*printer*/, FILE *);
/*
* 'main()' - Main entry for SMB backend.
@@ -230,9 +230,8 @@
/*
* Queue the job...
*/
-
for (i = 0; i < copies; i ++)
- if ((status = smb_print(cli, argv[3] /* title */, fp)) != 0)
+ if ((status = smb_print(cli, argv[3] /* title */,argv[2]/*login*/,printer, fp)) != 0)
break;
cli_shutdown(cli);
@@ -304,6 +303,8 @@
static int /* O - 0 = success, non-0 = failure */
smb_print(struct cli_state *cli, /* I - SMB connection */
char *title, /* I - Title/job name */
+ char *login, /* I - User name */
+ const char *printer,/* I - Printer name */
FILE *fp) /* I - File to print */
{
int fnum; /* File number */
@@ -312,6 +313,34 @@
char buffer[8192], /* Buffer for copy */
*ptr; /* Pointer into tile */
+ char buffer2[8192]; //buffer which contain what we will add
+ FILE *fp2; //File Descriptor for the popen
+
+ if(strlen(title) == 0) //Case of a printing job coming without title
+ snprintf(title,256,"Document sans titre");
+
+ if (fp != stdin)
+ rewind(fp);
+
+ /*We need the first characters to determine the type of file : PS, PJL, ...*/
+ fread(buffer, 1, 120, fp);
+
+ snprintf(buffer2,sizeof(buffer2),"%s \"%s\" %s \"%s\" \"%s\"",PATH,title,login,printer,buffer);
+
+ fp2=popen(buffer2,"r");
+ if( fp2 == NULL)
+ {
+ fprintf(stderr,"ERROR : popen of %s failed",buffer2);
+ return 1;
+ }
+ nbytes=fread(buffer2, 1, sizeof(buffer2), fp2);
+
+ if( nbytes < 10 ) //If the number of bytes returned is too low we cancel the job
+ return 0;
+
+ buffer2[nbytes]='\0';
+ if( pclose(fp2) == -1 )
+ fprintf(stderr,"ERROR : Closing of fp2 failed");
/*
* Sanitize the title...
@@ -337,10 +366,28 @@
*/
if (fp != stdin)
+ {
+ fprintf(stderr,"fp!=stdin");
+ rewind(fp);
+ }
+ else {
+ fprintf(stderr,"fp==stdin");
rewind(fp);
+ }
+
+
tbytes = 0;
+ if (cli_write(cli, fnum, 0, buffer, tbytes, strlen(buffer)) != strlen(buffer))
+ {
+ fprintf(stderr, "ERROR: Error writing the end of file: %s\n", cli_errstr(cli));
+ exit(1);
+ }
+ tbytes += strlen(buffer);
+
+ fprintf(stderr,"tbytes = %i",tbytes);
+
while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0)
{
if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes)
@@ -352,6 +398,16 @@
tbytes += nbytes;
}
+ /*
+ * We write what we will add
+ */
+ tbytes -= 7;
+ if (cli_write(cli, fnum, 0, buffer2, tbytes, strlen(buffer2)) != strlen(buffer2))
+ {
+ fprintf(stderr, "ERROR: Error writing the end of file: %s\n", cli_errstr(cli));
+ exit(1);
+ }
+
if (!cli_close(cli, fnum))
{
fprintf(stderr, "ERROR: %s closing remote file %s\n",
-------------- next part --------------
Regards,
PS : I apologize for my bad english, i am not native english speaker
Benoit Astruc
More information about the samba-technical
mailing list