2 * "$Id: classes.c,v 1.1 1999/06/21 18:45:23 mike Exp $"
4 * Class 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_class_list() - Show a list of classes...
28 * show_class_info() - Show class information.
32 * Include necessary headers...
38 #include <cups/cups.h>
39 #include <cups/language.h>
40 #include <cups/debug.h>
47 static void show_class_list(http_t
*http
, cups_lang_t
*language
);
48 static void show_class_info(http_t
*http
, cups_lang_t
*language
,
53 * 'main()' - Main entry for CGI.
56 int /* O - Exit status */
57 main(int argc
, /* I - Number of command-line arguments */
58 char *argv
[]) /* I - Command-line arguments */
60 cups_lang_t
*language
; /* Language information */
61 char *name
; /* Class name */
62 http_t
*http
; /* Connection to the server */
66 * Get the request language...
69 language
= cupsLangDefault();
72 * Connect to the HTTP server...
75 http
= httpConnect("localhost", ippPort());
78 * Tell the client to expect HTML...
81 printf("Content-Type: text/html;charset=%s\n\n", cupsLangEncoding(language
));
84 * See if we need to show a list of classes or the status of a
89 if (strcmp(name
, "/") == 0 || strcmp(name
, "classes.cgi") == 0)
93 * Print the standard header...
99 puts("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">");
101 puts("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"30\">");
102 printf("<TITLE>%s on %s - Common UNIX Printing System</TITLE>\n",
103 name
== NULL
? "Classes" : name
, getenv("SERVER_NAME"));
104 puts("<LINK REL=STYLESHEET TYPE=\"text/css\" HREF=\"/cups.css\">");
105 puts("<MAP NAME=\"navbar\">");
106 puts("<AREA SHAPE=\"RECT\" COORDS=\"10,10,100,35\" HREF=\"/printers\" ALT=\"Current Printer Status\">");
107 puts("<AREA SHAPE=\"RECT\" COORDS=\"115,10,205,35\" HREF=\"/classes\" ALT=\"Current Printer Classes Status\">");
108 puts("<AREA SHAPE=\"RECT\" COORDS=\"220,10,280,35\" HREF=\"/jobs\" ALT=\"Current Jobs Status\">");
109 puts("<AREA SHAPE=\"RECT\" COORDS=\"295,10,470,35\" HREF=\"/documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
110 puts("<AREA SHAPE=\"RECT\" COORDS=\"485,10,590,35\" HREF=\"http://www.cups.org\" ALT=\"Download the Current CUPS Software\">");
114 puts("<P ALIGN=CENTER>");
115 puts("<A HREF=\"http://www.easysw.com\" ALT=\"Easy Software Products Home Page\">");
116 puts("<IMG SRC=\"/images/logo.gif\" WIDTH=\"71\" HEIGHT=\"40\" BORDER=0 ALT=\"Easy Software Products Home Page\"></A>");
117 puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"540\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
119 printf("<H1>%s on %s</H1>\n", name
== NULL
? "Classes" : name
,
120 getenv("SERVER_NAME"));
124 puts("<TABLE WIDTH=\"90%\" BORDER=\"1\">");
126 puts("<TH>Name</TH>");
127 puts("<TH WIDTH=\"50%\">Status</TH>");
128 puts("<TH WIDTH=\"25%\">Jobs</TH>");
132 * Show the information...
136 show_class_list(http
, language
);
138 show_class_info(http
, language
, name
);
141 * Write a standard trailer...
149 puts("<P>The Common UNIX Printing System, CUPS, and the CUPS logo are the");
150 puts("trademark property of <A HREF=\"http://www.easysw.com\">Easy Software");
151 puts("Products</A>. CUPS is copyright 1997-1999 by Easy Software Products,");
152 puts("All Rights Reserved.");
158 * Close the HTTP server connection...
162 cupsLangFree(language
);
165 * Return with no errors...
173 * 'show_class_list()' - Show a list of classes...
177 show_class_list(http_t
*http
, /* I - HTTP connection */
178 cups_lang_t
*language
)/* I - Client's language */
180 ipp_t
*request
, /* IPP request */
181 *response
; /* IPP response */
182 ipp_attribute_t
*attr
; /* IPP attribute */
186 * Build a CUPS_GET_CLASSES request, which requires the following
190 * attributes-natural-language
195 request
->request
.op
.operation_id
= CUPS_GET_CLASSES
;
196 request
->request
.op
.request_id
= 1;
199 attr
= ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
200 "attributes-charset", NULL
, cupsLangEncoding(language
));
202 attr
= ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
203 "attributes-natural-language", NULL
, language
->language
);
206 * Do the request and get back a response...
209 if ((response
= cupsDoRequest(http
, request
, "/classes/")) != NULL
)
212 * Loop through the classes returned in the list and display
216 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
219 * Skip leading attributes until we hit a job...
222 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
229 * Show the class status for each class...
232 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
234 if (strcmp(attr
->name
, "printer-name") == 0 &&
235 attr
->value_tag
== IPP_TAG_NAME
)
236 show_class_info(http
, language
, attr
->values
[0].string
.text
);
251 * 'show_class_info()' - Show class information.
255 show_class_info(http_t
*http
,
256 cups_lang_t
*language
,
259 ipp_t
*request
, /* IPP request */
260 *response
, /* IPP response */
261 *jobs
; /* IPP Get Jobs response */
262 int jobcount
; /* Number of jobs */
263 ipp_attribute_t
*attr
; /* IPP attribute */
264 char *message
; /* Printer state message */
265 int accepting
; /* Accepting requests? */
266 ipp_pstate_t pstate
; /* Printer state */
267 char uri
[HTTP_MAX_URI
];/* Printer URI */
271 * Build a IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
275 * attributes-natural-language
281 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
282 request
->request
.op
.request_id
= 1;
284 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
285 "attributes-charset", NULL
, cupsLangEncoding(language
));
287 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
288 "attributes-natural-language", NULL
, language
->language
);
290 sprintf(uri
, "ipp://localhost/classes/%s", name
);
292 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "class-uri", NULL
, uri
);
295 * Do the request and get back a response...
298 if ((response
= cupsDoRequest(http
, request
, uri
+ 15)) != NULL
)
301 * Grab the needed class attributes...
304 if ((attr
= ippFindAttribute(response
, "class-state", IPP_TAG_ENUM
)) != NULL
)
305 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
307 pstate
= IPP_PRINTER_IDLE
;
309 if ((attr
= ippFindAttribute(response
, "class-state-message", IPP_TAG_TEXT
)) != NULL
)
310 message
= attr
->values
[0].string
.text
;
314 if ((attr
= ippFindAttribute(response
, "class-is-accepting-jobs",
315 IPP_TAG_BOOLEAN
)) != NULL
)
316 accepting
= attr
->values
[0].boolean
;
320 if ((attr
= ippFindAttribute(response
, "printer-uri", IPP_TAG_URI
)) != NULL
)
321 strcpy(uri
, attr
->values
[0].string
.text
);
324 * Display the class entry...
329 printf("<TD VALIGN=TOP><A HREF=\"/classes/%s\">%s</A></TD>\n", name
, name
);
331 puts("<TD VALIGN=TOP><IMG SRC=\"/images/classes.gif\" ALIGN=\"LEFT\">");
333 printf("%s: %s, %s<BR>\n",
334 cupsLangString(language
, CUPS_MSG_PRINTER_STATE
),
335 cupsLangString(language
, pstate
== IPP_PRINTER_IDLE
? CUPS_MSG_IDLE
:
336 pstate
== IPP_PRINTER_PROCESSING
?
337 CUPS_MSG_PROCESSING
: CUPS_MSG_STOPPED
),
338 cupsLangString(language
, accepting
? CUPS_MSG_ACCEPTING_JOBS
:
339 CUPS_MSG_NOT_ACCEPTING_JOBS
));
342 printf("<BR CLEAR=ALL><I>\"%s\"</I>\n", message
);
343 else if (!accepting
|| pstate
== IPP_PRINTER_STOPPED
)
344 puts("<BR CLEAR=ALL><I>\"Reason Unknown\"</I>");
349 * Show a list of jobs as needed...
352 if (pstate
!= IPP_PRINTER_IDLE
)
355 * Build an IPP_GET_JOBS request, which requires the following
359 * attributes-natural-language
365 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
366 request
->request
.op
.request_id
= 1;
368 attr
= ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
369 "attributes-charset", NULL
,
370 cupsLangEncoding(language
));
372 attr
= ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
373 "attributes-natural-language", NULL
,
376 attr
= ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
377 "class-uri", NULL
, uri
);
379 jobs
= cupsDoRequest(http
, request
, uri
+ 15);
384 puts("<TD VALIGN=\"TOP\">");
389 char *username
; /* Pointer to job-originating-user-name */
390 int jobid
, /* job-id */
391 size
; /* job-k-octets */
394 for (attr
= jobs
->attrs
; attr
!= NULL
; attr
= attr
->next
)
397 * Skip leading attributes until we hit a job...
400 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
407 * Pull the needed attributes from this job...
414 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
416 if (strcmp(attr
->name
, "job-id") == 0 &&
417 attr
->value_tag
== IPP_TAG_INTEGER
)
418 jobid
= attr
->values
[0].integer
;
420 if (strcmp(attr
->name
, "job-k-octets") == 0 &&
421 attr
->value_tag
== IPP_TAG_INTEGER
)
422 size
= attr
->values
[0].integer
;
424 if (strcmp(attr
->name
, "job-originating-user-name") == 0 &&
425 attr
->value_tag
== IPP_TAG_NAME
)
426 username
= attr
->values
[0].string
.text
;
432 * Display the job if it matches the current class...
435 if (username
!= NULL
)
438 printf("<A HREF=\"/jobs/%d\">%s-%d %s %dk</A><BR>\n", jobid
, name
,
439 jobid
, username
, size
);
460 * End of "$Id: classes.c,v 1.1 1999/06/21 18:45:23 mike Exp $".