37
37
the current job */
38
38
#define CUPS_BROWSED_DEST_PRINTER "cups-browsed-dest-printer"
39
39
40
- static int job_canceled = 0 ;
41
- /* Set to 1 on SIGTERM */
40
+ static int job_canceled = 0 ; /* Set to 1 on SIGTERM */
42
41
43
42
/*
44
43
* Local functions... */
@@ -64,13 +63,10 @@ next_delay(int current, /* I - Current delay value or 0 */
64
63
int * previous ) /* IO - Previous delay value */
65
64
{
66
65
int next ; /* Next delay value */
67
- if (current > 0 )
68
- {
66
+ if (current > 0 ) {
69
67
next = (current + * previous ) % 12 ;
70
68
* previous = next < current ? 0 : current ;
71
- }
72
- else
73
- {
69
+ } else {
74
70
next = 1 ;
75
71
* previous = 0 ;
76
72
}
@@ -82,22 +78,20 @@ next_delay(int current, /* I - Current delay value or 0 */
82
78
*/
83
79
84
80
void /* O - 0 on success, 1 on error */
85
- set_option_in_str (char * buf , /* I - Buffer with option list string */
86
- int buflen , /* I - Length of buffer */
87
- const char * option , /* I - Option to change/add */
88
- const char * value ) /* I - New value for option, NULL
89
- removes option */
81
+ set_option_in_str (char * buf , /* I - Buffer with option list string */
82
+ int buflen , /* I - Length of buffer */
83
+ const char * option , /* I - Option to change/add */
84
+ const char * value ) /* I - New value for option, NULL
85
+ removes option */
90
86
{
91
87
char * p1 , * p2 ;
92
88
93
89
if (!buf || buflen == 0 || !option )
94
90
return ;
95
91
/* Remove any occurrence of option in the string */
96
92
p1 = buf ;
97
- while (* p1 != '\0' && (p2 = strcasestr (p1 , option )) != NULL )
98
- {
99
- if (p2 > buf && * (p2 - 1 ) != ' ' && * (p2 - 1 ) != '\t' )
100
- {
93
+ while (* p1 != '\0' && (p2 = strcasestr (p1 , option )) != NULL ) {
94
+ if (p2 > buf && * (p2 - 1 ) != ' ' && * (p2 - 1 ) != '\t' ) {
101
95
p1 = p2 + 1 ;
102
96
continue ;
103
97
}
@@ -141,10 +135,10 @@ main(int argc, /* I - Number of command-line args */
141
135
char dest_host [1024 ]; /* Destination host */
142
136
ipp_t * request , * response ;
143
137
ipp_attribute_t * attr ;
144
- int bytes ; /* Bytes copied */
138
+ int bytes ; /* Bytes copied */
145
139
char uri [HTTP_MAX_URI ];
146
140
char * argv_nt [7 ];
147
- int outbuflen , filter_pid ,filefd ,exit_status ;
141
+ int outbuflen ,filefd ,exit_status ;
148
142
static const char * pattrs [] =
149
143
{
150
144
"printer-defaults"
@@ -175,10 +169,8 @@ main(int argc, /* I - Number of command-line args */
175
169
* Check command-line...
176
170
*/
177
171
178
- if (argc >= 6 )
179
- {
180
- if ((device_uri = getenv ("DEVICE_URI" )) == NULL )
181
- {
172
+ if (argc >= 6 ) {
173
+ if ((device_uri = getenv ("DEVICE_URI" )) == NULL ) {
182
174
if (!argv || !argv [0 ] || !strchr (argv [0 ], ':' ))
183
175
return (-1 );
184
176
@@ -235,7 +227,8 @@ main(int argc, /* I - Number of command-line args */
235
227
if (ptr1 != NULL )
236
228
break ;
237
229
}
238
- fprintf (stderr , "DEBUG: Read " CUPS_BROWSED_DEST_PRINTER " option: %s\n" , ptr1 );
230
+ fprintf (stderr , "DEBUG: Read " CUPS_BROWSED_DEST_PRINTER " option: %s\n" ,
231
+ ptr1 );
239
232
if (ptr1 == NULL )
240
233
goto failed ;
241
234
/* Destination host is between double quotes, as double quotes are
@@ -289,14 +282,9 @@ main(int argc, /* I - Number of command-line args */
289
282
char buffer [8192 ];
290
283
291
284
fprintf (stderr , "DEBUG: Received destination host name from cups-browsed: printer-uri %s\n" ,
292
- ptr1 );
285
+ ptr1 );
293
286
294
- /* Instead of feeding the job into the IPP backend, we re-print it into
295
- the server's CUPS queue. This way the job gets spooled on the server
296
- and we are not blocked until the job is printed. So a subsequent job
297
- will be immediately processed and sent out to another server */
298
-
299
- /* Parse the command line option and prepare them for the new print
287
+ /* Parse the command line options and prepare them for the new print
300
288
job */
301
289
cupsSetUser (argv [2 ]);
302
290
title = argv [3 ];
@@ -317,114 +305,118 @@ main(int argc, /* I - Number of command-line args */
317
305
else
318
306
fd = 0 ; /* stdin */
319
307
320
- /* Finding the document format in which the pdftoippprinter will convert the pdf
321
- file*/
322
- if ((ptr3 = strchr (ptr1 , ' ' )) != NULL ) {
323
- * ptr3 = '\0' ;
324
- ptr3 ++ ;
325
- }
308
+ /* Finding the document format in which the pdftoippprinter will
309
+ convert the pdf file */
310
+ if ((ptr3 = strchr (ptr1 , ' ' )) != NULL ) {
311
+ * ptr3 = '\0' ;
312
+ ptr3 ++ ;
313
+ }
326
314
327
- /* Finding the resolution requested for the job*/
328
- if ((ptr4 = strchr (ptr3 , ' ' )) != NULL ) {
329
- * ptr4 = '\0' ;
330
- ptr4 ++ ;
331
- }
315
+ /* Finding the resolution requested for the job*/
316
+ if ((ptr4 = strchr (ptr3 , ' ' )) != NULL ) {
317
+ * ptr4 = '\0' ;
318
+ ptr4 ++ ;
319
+ }
332
320
333
- strncpy (printer_uri ,ptr1 ,sizeof (printer_uri ));
334
- strncpy (document_format ,ptr3 ,sizeof (document_format ));
335
- strncpy (resolution ,ptr4 ,sizeof (resolution ));
336
-
337
- fprintf (stderr ,"DEBUG: Recieved job for the printer with the destination uri - %s, Final-document format for the printer - %s and requested resolution - %s\n" ,
338
- printer_uri ,document_format ,resolution );
339
-
340
- /* We need to send modified arguments to the IPP backend */
341
- if (argc == 6 ){
342
- /** Copy stdin to a temp file...*/
343
- if ((fd = cupsTempFd (tempfile , sizeof (tempfile ))) < 0 ){
344
- fprintf (stderr ,"Debug: Can't Read PDF file.\n" );
345
- return CUPS_BACKEND_FAILED ;
346
- }
347
- fprintf (stderr , "Debug: implicitclass - copying to temp print file \"%s\"\n" ,
348
- tempfile );
349
- while ((bytes = fread (buffer , 1 , sizeof (buffer ), stdin )) > 0 )
350
- bytes = write (fd , buffer , bytes );
351
- close (fd );
352
- filename = tempfile ;
353
- }
354
- else {
355
- /** Use the filename on the command-line...*/
356
- filename = argv [6 ];
357
- tempfile [0 ] = '\0' ;
321
+ strncpy (printer_uri , ptr1 , sizeof (printer_uri ));
322
+ strncpy (document_format , ptr3 , sizeof (document_format ));
323
+ strncpy (resolution , ptr4 , sizeof (resolution ));
324
+
325
+ fprintf (stderr ,"DEBUG: Received job for the printer with the destination uri - %s, Final-document format for the printer - %s and requested resolution - %s\n" ,
326
+ printer_uri , document_format , resolution );
327
+
328
+ /* We need to send modified arguments to the IPP backend */
329
+ if (argc == 6 ) {
330
+ /* Copy stdin to a temp file...*/
331
+ if ((fd = cupsTempFd (tempfile , sizeof (tempfile ))) < 0 ){
332
+ fprintf (stderr ,"Debug: Can't Read PDF file.\n" );
333
+ return CUPS_BACKEND_FAILED ;
358
334
}
335
+ fprintf (stderr , "Debug: implicitclass - copying to temp print file \"%s\"\n" ,
336
+ tempfile );
337
+ while ((bytes = fread (buffer , 1 , sizeof (buffer ), stdin )) > 0 )
338
+ bytes = write (fd , buffer , bytes );
339
+ close (fd );
340
+ filename = tempfile ;
341
+ } else {
342
+ /** Use the filename on the command-line...*/
343
+ filename = argv [6 ];
344
+ tempfile [0 ] = '\0' ;
345
+ }
359
346
360
- /*Copying the argument to a new char** which will be sent to the filter and
361
- the ipp backend*/
362
- for (i = 0 ; i < 5 ; i ++ )
363
- argv_nt [i ] = argv [i ];
364
-
365
- /* Few new options will be added to the argv[5]*/
366
- outbuflen = strlen (argv [5 ]) + 256 ;
367
- argv_nt [5 ] = calloc (outbuflen , sizeof (char ));
368
- strcpy (argv_nt [5 ], (const char * )argv [5 ]);
369
-
370
- /* Filter pdftoippprinter.c will read the input from this file*/
371
- argv_nt [6 ] = filename ;
372
-
373
- set_option_in_str (argv_nt [5 ], outbuflen , "output-format" , document_format );
374
- set_option_in_str (argv_nt [5 ], outbuflen , "Resolution" ,resolution );
375
- setenv ("DEVICE_URI" ,printer_uri , 1 );
376
-
377
- filefd = cupsTempFd (tempfile_filter , sizeof (tempfile_filter ));
378
- /* The output of the last filter in pdftoippprinter will be written to
379
- this file. We could have sent the output directly to the backend, but having
380
- this temperory file will help us find whether the filter worked correctly and
381
- what was the document-format of the filtered output.*/
382
- close (1 );
383
- dup (filefd );
384
- /* Calling pdftoippprinter.c filter*/
385
- apply_filters (7 ,argv_nt );
386
-
387
- close (filefd );
388
-
389
- /*We will send the filtered output of the pdftoippprinter.c to the IPP Backend*/
390
- argv_nt [6 ] = tempfile_filter ;
391
- fprintf (stderr , "DEBUG: The filtered output of pdftoippprinter is written to file %s\n" ,
392
- tempfile_filter );
393
-
394
- /*Setting the final content type to the best pdl supported by the printer.*/
395
- if (!strcmp (document_format ,"pdf" ))
396
- setenv ("FINAL_CONTENT_TYPE" , "application/pdf" , 1 );
397
- else if (!strcmp (document_format ,"raster" ))
398
- setenv ("FINAL_CONTENT_TYPE" , "image/pwg-raster" , 1 );
399
- else if (!strcmp (document_format ,"apple-raster" ))
400
- setenv ("FINAL_CONTENT_TYPE" , "image/urf" , 1 );
401
- else if (!strcmp (document_format ,"pclm" ))
402
- setenv ("FINAL_CONTENT_TYPE" , "application/PCLm" , 1 );
403
- else if (!strcmp (document_format ,"pclxl" ))
404
- setenv ("FINAL_CONTENT_TYPE" , "application/vnd.hp-pclxl" , 1 );
405
- else if (!strcmp (document_format ,"pcl" ))
406
- setenv ("FINAL_CONTENT_TYPE" , "application/pcl" , 1 );
407
-
408
- ippDelete (response );
409
- /* The implicitclass backend will send the job directly to the ipp backend*/
410
- pid_t pid = fork ();
411
- if ( pid == 0 ) {
412
- fprintf (stderr , "DEBUG: Started IPP Backend with pid: %d\n" ,getpid ());
413
- execv ("/usr/lib/cups/backend/ipp" ,argv_nt );
414
- }else {
415
- int status ;
416
- waitpid (pid , & status , 0 );
417
- if (WIFEXITED (status )){
418
- exit_status = WEXITSTATUS (status );
419
- fprintf (stderr , "DEBUG: The IPP Backend exited with the status %d\n" ,
420
- exit_status );
421
- }
422
- return exit_status ;
423
- }
424
- }
347
+ /* Copying the argument to a new char** which will be sent to the filter
348
+ and the ipp backend*/
349
+ for (i = 0 ; i < 5 ; i ++ )
350
+ argv_nt [i ] = argv [i ];
351
+
352
+ /* Few new options will be added to the argv[5]*/
353
+ outbuflen = strlen (argv [5 ]) + 256 ;
354
+ argv_nt [5 ] = calloc (outbuflen , sizeof (char ));
355
+ strcpy (argv_nt [5 ], (const char * )argv [5 ]);
356
+
357
+ /* Filter pdftoippprinter.c will read the input from this file*/
358
+ argv_nt [6 ] = filename ;
359
+ set_option_in_str (argv_nt [5 ], outbuflen , "output-format" ,
360
+ document_format );
361
+ set_option_in_str (argv_nt [5 ], outbuflen , "Resolution" ,resolution );
362
+ setenv ("DEVICE_URI" ,printer_uri , 1 );
363
+
364
+ filefd = cupsTempFd (tempfile_filter , sizeof (tempfile_filter ));
365
+
366
+ /* The output of the last filter in pdftoippprinter will be
367
+ written to this file. We could have sent the output directly
368
+ to the backend, but having this temperory file will help us
369
+ find whether the filter worked correctly and what was the
370
+ document-format of the filtered output.*/
371
+ close (1 );
372
+ /*dup(filefd);*/
373
+
374
+ /* Calling pdftoippprinter.c filter*/
375
+ apply_filters (7 ,argv_nt );
376
+
377
+ close (filefd );
378
+
379
+ /* We will send the filtered output of the pdftoippprinter.c to
380
+ the IPP Backend*/
381
+ argv_nt [6 ] = tempfile_filter ;
382
+ fprintf (stderr , "DEBUG: The filtered output of pdftoippprinter is written to file %s\n" ,
383
+ tempfile_filter );
384
+
385
+ /* Setting the final content type to the best pdl supported by
386
+ the printer.*/
387
+ if (!strcmp (document_format ,"pdf" ))
388
+ setenv ("FINAL_CONTENT_TYPE" , "application/pdf" , 1 );
389
+ else if (!strcmp (document_format ,"raster" ))
390
+ setenv ("FINAL_CONTENT_TYPE" , "image/pwg-raster" , 1 );
391
+ else if (!strcmp (document_format ,"apple-raster" ))
392
+ setenv ("FINAL_CONTENT_TYPE" , "image/urf" , 1 );
393
+ else if (!strcmp (document_format ,"pclm" ))
394
+ setenv ("FINAL_CONTENT_TYPE" , "application/PCLm" , 1 );
395
+ else if (!strcmp (document_format ,"pclxl" ))
396
+ setenv ("FINAL_CONTENT_TYPE" , "application/vnd.hp-pclxl" , 1 );
397
+ else if (!strcmp (document_format ,"pcl" ))
398
+ setenv ("FINAL_CONTENT_TYPE" , "application/pcl" , 1 );
399
+
400
+ ippDelete (response );
401
+
402
+ /* The implicitclass backend will send the job directly to the
403
+ ipp backend*/
404
+ pid_t pid = fork ();
405
+ if ( pid == 0 ) {
406
+ fprintf (stderr , "DEBUG: Started IPP Backend with pid: %d\n" ,getpid ());
407
+ execv ("/usr/lib/cups/backend/ipp" ,argv_nt );
408
+ } else {
409
+ int status ;
410
+ waitpid (pid , & status , 0 );
411
+ if (WIFEXITED (status )) {
412
+ exit_status = WEXITSTATUS (status );
413
+ fprintf (stderr , "DEBUG: The IPP Backend exited with the status %d\n" ,
414
+ exit_status );
425
415
}
426
- else if (argc != 1 )
427
- {
416
+ return exit_status ;
417
+ }
418
+ }
419
+ } else if (argc != 1 ) {
428
420
fprintf (stderr ,
429
421
"Usage: %s job-id user title copies options [file]" ,
430
422
argv [0 ]);
@@ -453,4 +445,3 @@ sigterm_handler(int sig) /* I - Signal number (unused) */
453
445
else
454
446
job_canceled = 1 ;
455
447
}
456
-
0 commit comments