]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/jobs.c
2 * "$Id: jobs.c,v 1.10 1999/11/04 14:57:57 mike Exp $"
4 * Job status CGI for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-1999 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for CGI.
27 * show_job_list() - Show a list of jobs...
28 * show_job_info() - Show job information.
32 * Include necessary headers...
38 #include <cups/cups.h>
39 #include <cups/language.h>
40 #include <cups/debug.h>
48 static void show_job_list ( http_t
* http
, cups_lang_t
* language
);
49 static void show_job_info ( http_t
* http
, cups_lang_t
* language
,
54 * 'main()' - Main entry for CGI.
57 int /* O - Exit status */
58 main ( int argc
, /* I - Number of command-line arguments */
59 char * argv
[]) /* I - Command-line arguments */
61 cups_lang_t
* language
; /* Language information */
62 char * job
; /* Job name */
63 http_t
* http
; /* Connection to the server */
67 * Get the request language...
70 language
= cupsLangDefault ();
73 * Connect to the HTTP server...
76 http
= httpConnect ( "localhost" , ippPort ());
79 * Tell the client to expect HTML...
82 printf ( "Content-Type: text/html;charset=%s \n\n " , cupsLangEncoding ( language
));
85 * See if we need to show a list of jobs or the status of a
90 if ( strcmp ( job
, "/" ) == 0 || strcmp ( job
, "jobs.cgi" ) == 0 )
94 * Print the standard header...
100 puts ( "<META HTTP-EQUIV= \" Refresh \" CONTENT= \" 10 \" >" );
102 puts ( "<META HTTP-EQUIV= \" Refresh \" CONTENT= \" 30 \" >" );
103 printf ( "<TITLE>%s on %s - " CUPS_SVERSION
"</TITLE> \n " ,
104 job
== NULL
? "Jobs" : job
, getenv ( "SERVER_NAME" ));
105 puts ( "<LINK REL=STYLESHEET TYPE= \" text/css \" HREF= \" /cups.css \" >" );
106 puts ( "<MAP NAME= \" navbar \" >" );
108 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 10,10,76,30 \" HREF= \" /printers \" ALT= \" Current Printer Status \" >" );
109 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 88,10,158,30 \" HREF= \" /classes \" ALT= \" Current Printer Classes Status \" >" );
110 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 170,10,210,30 \" HREF= \" jobs \" ALT= \" Current Jobs Status \" >" );
111 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 222,10,354,30 \" HREF= \" /documentation.html \" ALT= \" Read CUPS Documentation On-Line \" >" );
112 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 366,10,442,30 \" HREF= \" http://www.easysw.com/software.html \" ALT= \" Download the Current ESP Print Pro Software \" >" );
113 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 454,10,530,30 \" HREF= \" http://www.easysw.com/support.html \" ALT= \" Get Tech Support for Current ESP Print Pro \" >" );
115 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 10,10,85,30 \" HREF= \" /printers \" ALT= \" Current Printer Status \" >" );
116 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 95,10,175,30 \" HREF= \" /classes \" ALT= \" Current Printer Classes Status \" >" );
117 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 185,10,235,30 \" HREF= \" /jobs \" ALT= \" Current Jobs Status \" >" );
118 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 245,10,395,30 \" HREF= \" /documentation.html \" ALT= \" Read CUPS Documentation On-Line \" >" );
119 puts ( "<AREA SHAPE= \" RECT \" COORDS= \" 405,10,490,30 \" HREF= \" http://www.cups.org \" ALT= \" Download the Current CUPS Software \" >" );
120 #endif /* ESPPRINTPRO */
124 puts ( "<P ALIGN=CENTER>" );
125 puts ( "<A HREF= \" http://www.easysw.com \" ALT= \" Easy Software Products Home Page \" >" );
126 puts ( "<IMG SRC= \" /images/logo.gif \" WIDTH= \" 71 \" HEIGHT= \" 40 \" BORDER=0 ALT= \" Easy Software Products Home Page \" ></A>" );
127 puts ( "<IMG SRC= \" /images/navbar.gif \" WIDTH= \" 540 \" HEIGHT= \" 40 \" USEMAP= \" #navbar \" BORDER=0>" );
132 * Show the information...
136 show_job_list ( http
, language
);
138 show_job_info ( http
, language
, job
);
141 * Write a standard trailer...
146 puts ( "<P>The Common UNIX Printing System, CUPS, and the CUPS logo are the" );
147 puts ( "trademark property of <A HREF= \" http://www.easysw.com \" >Easy Software" );
148 puts ( "Products</A>. CUPS is copyright 1997-1999 by Easy Software Products," );
149 puts ( "All Rights Reserved." );
155 * Close the HTTP server connection...
159 cupsLangFree ( language
);
162 * Return with no errors...
170 * 'show_job_list()' - Show a list of jobs...
174 show_job_list ( http_t
* http
, /* I - HTTP connection */
175 cups_lang_t
* language
) /* I - Client's language */
177 ipp_t
* request
, /* IPP request */
178 * response
; /* IPP response */
179 ipp_attribute_t
* attr
; /* IPP attribute */
180 char * job_uri
, /* job-uri */
181 * printer_uri
, /* job-printer-uri */
182 * job_name
, /* job-name */
183 * job_user
; /* job-originating-user-name */
184 int job_id
, /* job-id */
185 job_priority
, /* job-priority */
186 job_k_octets
, /* job-k-octets */
188 ipp_jstate_t job_state
; /* job-state */
191 printf ( "<H1>Jobs on %s</H1> \n " , getenv ( "SERVER_NAME" ));
194 * Build an IPP_GET_JOBS request, which requires the following
198 * attributes-natural-language
204 request
-> request
. op
. operation_id
= IPP_GET_JOBS
;
205 request
-> request
. op
. request_id
= 1 ;
207 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
208 "attributes-charset" , NULL
, cupsLangEncoding ( language
));
210 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
211 "attributes-natural-language" , NULL
, language
-> language
);
213 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri" ,
214 NULL
, "ipp://localhost/jobs/" );
217 * Do the request and get back a response...
220 if (( response
= cupsDoRequest ( http
, request
, "/" )) != NULL
)
223 * Do a table for the jobs...
227 puts ( "<TABLE WIDTH= \" 90% \" BORDER= \" 1 \" >" );
229 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_PRINT_JOBS
));
230 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_JOB_STATE
));
231 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_JOB_NAME
));
232 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_USER_NAME
));
233 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_PRIORITY
));
234 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_COPIES
));
235 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_FILE_SIZE
));
239 * Loop through the jobs returned in the list and display
243 for ( attr
= response
-> attrs
; attr
!= NULL
; attr
= attr
-> next
)
246 * Skip leading attributes until we hit a job...
249 while ( attr
!= NULL
&& attr
-> group_tag
!= IPP_TAG_JOB
)
256 * Show the job status for each job...
261 job_name
= "unknown" ;
262 job_user
= "unknown" ;
267 job_state
= IPP_JOB_PENDING
;
269 while ( attr
!= NULL
&& attr
-> group_tag
== IPP_TAG_JOB
)
271 if ( strcmp ( attr
-> name
, "job-uri" ) == 0 &&
272 attr
-> value_tag
== IPP_TAG_URI
)
273 job_uri
= attr
-> values
[ 0 ]. string
. text
;
275 if ( strcmp ( attr
-> name
, "job-printer-uri" ) == 0 &&
276 attr
-> value_tag
== IPP_TAG_URI
)
277 printer_uri
= attr
-> values
[ 0 ]. string
. text
;
279 if ( strcmp ( attr
-> name
, "job-name" ) == 0 &&
280 attr
-> value_tag
== IPP_TAG_NAME
)
281 job_name
= attr
-> values
[ 0 ]. string
. text
;
283 if ( strcmp ( attr
-> name
, "job-originating-user-name" ) == 0 &&
284 attr
-> value_tag
== IPP_TAG_NAME
)
285 job_user
= attr
-> values
[ 0 ]. string
. text
;
287 if ( strcmp ( attr
-> name
, "job-id" ) == 0 &&
288 attr
-> value_tag
== IPP_TAG_INTEGER
)
289 job_id
= attr
-> values
[ 0 ]. integer
;
291 if ( strcmp ( attr
-> name
, "job-priority" ) == 0 &&
292 attr
-> value_tag
== IPP_TAG_INTEGER
)
293 job_priority
= attr
-> values
[ 0 ]. integer
;
295 if ( strcmp ( attr
-> name
, "job-k-octets" ) == 0 &&
296 attr
-> value_tag
== IPP_TAG_INTEGER
)
297 job_k_octets
= attr
-> values
[ 0 ]. integer
;
299 if ( strcmp ( attr
-> name
, "copies" ) == 0 &&
300 attr
-> value_tag
== IPP_TAG_INTEGER
)
301 copies
= attr
-> values
[ 0 ]. integer
;
303 if ( strcmp ( attr
-> name
, "job-state" ) == 0 &&
304 attr
-> value_tag
== IPP_TAG_ENUM
)
305 job_state
= ( ipp_jstate_t
) attr
-> values
[ 0 ]. integer
;
311 * See if we have everything needed...
314 if ( job_id
&& job_uri
!= NULL
&& printer_uri
!= NULL
)
317 printf ( "<TD><A HREF= \" http://%s:%s/jobs/%d \" >%s-%d</A></TD> \n " ,
318 getenv ( "SERVER_NAME" ), getenv ( "SERVER_PORT" ), job_id
,
319 strrchr ( printer_uri
, '/' ) + 1 , job_id
);
320 printf ( "<TD>%s</TD> \n " , job_state
== IPP_JOB_PROCESSING
?
321 cupsLangString ( language
, CUPS_MSG_PROCESSING
) :
322 cupsLangString ( language
, CUPS_MSG_PENDING
));
323 printf ( "<TD>%s</TD> \n " , job_name
);
324 printf ( "<TD>%s</TD> \n " , job_user
);
325 printf ( "<TD>%d</TD> \n " , job_priority
);
326 printf ( "<TD>%d</TD> \n " , copies
);
327 printf ( "<TD>%dk</TD> \n " , job_k_octets
);
341 puts ( "<P>No jobs found." );
346 * 'show_job_info()' - Show job information.
350 show_job_info ( http_t
* http
, /* I - Server connection */
351 cups_lang_t
* language
, /* I - Language */
352 char * name
) /* I - Job "name" */
354 int i
; /* Looping var */
355 ipp_t
* request
, /* IPP request */
356 * response
; /* IPP response */
357 ipp_attribute_t
* attr
; /* IPP attribute */
358 char uri
[ HTTP_MAX_URI
]; /* Real URI */
359 char * job_uri
, /* job-uri */
360 * printer_uri
, /* job-printer-uri */
361 * job_name
, /* job-name */
362 * job_user
; /* job-originating-user-name */
363 int job_id
, /* job-id */
364 job_priority
, /* job-priority */
365 job_k_octets
; /* job-k-octets */
366 ipp_jstate_t job_state
; /* job-state */
370 * Build an IPP_GET_JOB_ATTRIBUTES request, which requires the following
374 * attributes-natural-language
380 request
-> request
. op
. operation_id
= IPP_GET_JOB_ATTRIBUTES
;
381 request
-> request
. op
. request_id
= 1 ;
383 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
384 "attributes-charset" , NULL
, cupsLangEncoding ( language
));
386 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
387 "attributes-natural-language" , NULL
, language
-> language
);
389 snprintf ( uri
, sizeof ( uri
), "ipp://localhost/jobs/%s" , name
);
390 ippAddString ( request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri" , NULL
, uri
);
393 * Do the request and get back a response...
396 if (( response
= cupsDoRequest ( http
, request
, "/" )) == NULL
)
398 puts ( "<P>Unable to communicate with CUPS server!" );
402 if ( response
-> request
. status
. status_code
== IPP_NOT_FOUND
)
404 puts ( "<P>Job does not exist or has completed." );
410 * Get the job status for this job...
413 if (( attr
= ippFindAttribute ( response
, "job-uri" , IPP_TAG_URI
)) != NULL
)
414 job_uri
= attr
-> values
[ 0 ]. string
. text
;
417 puts ( "<P>Missing job-uri attribute!" );
422 if (( attr
= ippFindAttribute ( response
, "job-printer-uri" , IPP_TAG_URI
)) != NULL
)
423 printer_uri
= attr
-> values
[ 0 ]. string
. text
;
426 puts ( "<P>Missing job-printer-uri attribute!" );
431 if (( attr
= ippFindAttribute ( response
, "job-name" , IPP_TAG_NAME
)) != NULL
)
432 job_name
= attr
-> values
[ 0 ]. string
. text
;
434 job_name
= "unknown" ;
436 if (( attr
= ippFindAttribute ( response
, "job-originating-user-name" ,
437 IPP_TAG_NAME
)) != NULL
)
438 job_user
= attr
-> values
[ 0 ]. string
. text
;
440 job_user
= "unknown" ;
442 if (( attr
= ippFindAttribute ( response
, "job-id" , IPP_TAG_INTEGER
)) != NULL
)
443 job_id
= attr
-> values
[ 0 ]. integer
;
446 puts ( "<P>Missing job-id attribute!" );
451 if (( attr
= ippFindAttribute ( response
, "job-priority" , IPP_TAG_INTEGER
)) != NULL
)
452 job_priority
= attr
-> values
[ 0 ]. integer
;
456 if (( attr
= ippFindAttribute ( response
, "job-k-octets" , IPP_TAG_INTEGER
)) != NULL
)
457 job_k_octets
= attr
-> values
[ 0 ]. integer
;
461 if (( attr
= ippFindAttribute ( response
, "job-state" , IPP_TAG_ENUM
)) != NULL
)
462 job_state
= ( ipp_jstate_t
) attr
-> values
[ 0 ]. integer
;
464 job_state
= IPP_JOB_PENDING
;
467 * Do a table for the job...
470 printf ( "<H1><A HREF= \" http://%s:%s/printers/%s \" >%s-%d</A></H1> \n " ,
471 getenv ( "SERVER_NAME" ), getenv ( "SERVER_PORT" ),
472 strrchr ( printer_uri
, '/' ) + 1 , strrchr ( printer_uri
, '/' ) + 1 , job_id
);
475 puts ( "<TABLE WIDTH= \" 90% \" BORDER= \" 1 \" >" );
478 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_JOB_STATE
));
479 printf ( "<TD>%s</TD> \n " , job_state
== IPP_JOB_PROCESSING
?
480 cupsLangString ( language
, CUPS_MSG_PROCESSING
) :
481 cupsLangString ( language
, CUPS_MSG_PENDING
));
485 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_JOB_NAME
));
486 printf ( "<TD>%s</TD> \n " , job_name
);
490 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_USER_NAME
));
491 printf ( "<TD>%s</TD> \n " , job_user
);
495 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_PRIORITY
));
496 printf ( "<TD>%d</TD> \n " , job_priority
);
500 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_FILE_SIZE
));
501 printf ( "<TD>%dk</TD> \n " , job_k_octets
);
504 puts ( "<TR VALIGN= \" TOP \" >" );
505 printf ( "<TH>%s</TH> \n " , cupsLangString ( language
, CUPS_MSG_OPTIONS
));
508 for ( attr
= response
-> attrs
; attr
!= NULL
; attr
= attr
-> next
)
510 if ( attr
-> group_tag
!= IPP_TAG_JOB
)
513 if ( strcmp ( attr
-> name
, "job-uri" ) == 0 ||
514 strcmp ( attr
-> name
, "job-printer-uri" ) == 0 ||
515 strcmp ( attr
-> name
, "job-name" ) == 0 ||
516 strcmp ( attr
-> name
, "job-originating-user-name" ) == 0 ||
517 strcmp ( attr
-> name
, "job-id" ) == 0 ||
518 strcmp ( attr
-> name
, "job-priority" ) == 0 ||
519 strcmp ( attr
-> name
, "job-k-octets" ) == 0 ||
520 strcmp ( attr
-> name
, "job-state" ) == 0 )
523 if ( attr
-> value_tag
!= IPP_TAG_BOOLEAN
)
524 printf ( "%s=" , attr
-> name
);
526 for ( i
= 0 ; i
< attr
-> num_values
; i
++)
531 switch ( attr
-> value_tag
)
533 case IPP_TAG_INTEGER
:
535 printf ( "%d" , attr
-> values
[ i
]. integer
);
538 case IPP_TAG_BOOLEAN
:
539 if (! attr
-> values
[ i
]. boolean
)
542 case IPP_TAG_NOVALUE
:
543 fputs ( attr
-> name
, stdout
);
547 printf ( "%d-%d" , attr
-> values
[ i
]. range
. lower
,
548 attr
-> values
[ i
]. range
. upper
);
551 case IPP_TAG_RESOLUTION
:
552 printf ( "%dx%d%s" , attr
-> values
[ i
]. resolution
. xres
,
553 attr
-> values
[ i
]. resolution
. yres
,
554 attr
-> values
[ i
]. resolution
. units
== IPP_RES_PER_INCH
?
558 case IPP_TAG_STRING
:
561 case IPP_TAG_KEYWORD
:
562 case IPP_TAG_CHARSET
:
563 case IPP_TAG_LANGUAGE
:
564 case IPP_TAG_MIMETYPE
:
566 printf ( " \" %s \" " , attr
-> values
[ i
]. string
. text
);
576 puts ( "</TABLE></CENTER>" );
583 * End of "$Id: jobs.c,v 1.10 1999/11/04 14:57:57 mike Exp $".