2 * "$Id: classes.c,v 1.7 1999/09/27 17:14:25 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 - " CUPS_SVERSION
"</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\">");
107 puts("<AREA SHAPE=\"RECT\" COORDS=\"10,10,76,30\" HREF=\"printers\" ALT=\"Current Printer Status\">");
108 puts("<AREA SHAPE=\"RECT\" COORDS=\"88,10,158,30\" HREF=\"classes\" ALT=\"Current Printer Classes Status\">");
109 puts("<AREA SHAPE=\"RECT\" COORDS=\"170,10,210,30\" HREF=\"jobs\" ALT=\"Current Jobs Status\">");
110 puts("<AREA SHAPE=\"RECT\" COORDS=\"222,10,354,30\" HREF=\"documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
111 puts("<AREA SHAPE=\"RECT\" COORDS=\"366,10,442,30\" HREF=\"http://www.easysw.com/printpro/software.html\" ALT=\"Download the Current ESP Print Pro Software\">");
112 puts("<AREA SHAPE=\"RECT\" COORDS=\"454,10,530,30\" HREF=\"http://www.easysw.com/printpro/support.html\" ALT=\"Get Tech Support for Current ESP Print Pro\">");
114 puts("<AREA SHAPE=\"RECT\" COORDS=\"10,10,85,30\" HREF=\"/printers\" ALT=\"Current Printer Status\">");
115 puts("<AREA SHAPE=\"RECT\" COORDS=\"95,10,175,30\" HREF=\"/classes\" ALT=\"Current Printer Classes Status\">");
116 puts("<AREA SHAPE=\"RECT\" COORDS=\"185,10,235,30\" HREF=\"/jobs\" ALT=\"Current Jobs Status\">");
117 puts("<AREA SHAPE=\"RECT\" COORDS=\"245,10,395,30\" HREF=\"/documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
118 puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.cups.org\" ALT=\"Download the Current CUPS Software\">");
119 #endif /* ESPPRINTPRO */
123 puts("<P ALIGN=CENTER>");
124 puts("<A HREF=\"http://www.easysw.com\" ALT=\"Easy Software Products Home Page\">");
125 puts("<IMG SRC=\"/images/logo.gif\" WIDTH=\"71\" HEIGHT=\"40\" BORDER=0 ALT=\"Easy Software Products Home Page\"></A>");
126 puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"540\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
128 printf("<H1>%s on %s</H1>\n", name
== NULL
? "Classes" : name
,
129 getenv("SERVER_NAME"));
133 puts("<TABLE WIDTH=\"90%\" BORDER=\"1\">");
135 puts("<TH>Name</TH>");
136 puts("<TH WIDTH=\"50%\">Status</TH>");
137 puts("<TH WIDTH=\"25%\">Jobs</TH>");
141 * Show the information...
145 show_class_list(http
, language
);
147 show_class_info(http
, language
, name
);
150 * Write a standard trailer...
158 puts("<P>The Common UNIX Printing System, CUPS, and the CUPS logo are the");
159 puts("trademark property of <A HREF=\"http://www.easysw.com\">Easy Software");
160 puts("Products</A>. CUPS is copyright 1997-1999 by Easy Software Products,");
161 puts("All Rights Reserved.");
167 * Close the HTTP server connection...
171 cupsLangFree(language
);
174 * Return with no errors...
182 * 'show_class_list()' - Show a list of classes...
186 show_class_list(http_t
*http
, /* I - HTTP connection */
187 cups_lang_t
*language
)/* I - Client's language */
189 ipp_t
*request
, /* IPP request */
190 *response
; /* IPP response */
191 ipp_attribute_t
*attr
; /* IPP attribute */
195 * Build a CUPS_GET_CLASSES request, which requires the following
199 * attributes-natural-language
204 request
->request
.op
.operation_id
= CUPS_GET_CLASSES
;
205 request
->request
.op
.request_id
= 1;
208 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
209 "attributes-charset", NULL
, cupsLangEncoding(language
));
211 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
212 "attributes-natural-language", NULL
, language
->language
);
215 * Do the request and get back a response...
218 if ((response
= cupsDoRequest(http
, request
, "/classes/")) != NULL
)
221 * Loop through the classes returned in the list and display
225 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
228 * Skip leading attributes until we hit a job...
231 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
238 * Show the class status for each class...
241 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
243 if (strcmp(attr
->name
, "printer-name") == 0 &&
244 attr
->value_tag
== IPP_TAG_NAME
)
245 show_class_info(http
, language
, attr
->values
[0].string
.text
);
260 * 'show_class_info()' - Show class information.
264 show_class_info(http_t
*http
,
265 cups_lang_t
*language
,
268 ipp_t
*request
, /* IPP request */
269 *response
, /* IPP response */
270 *jobs
; /* IPP Get Jobs response */
271 int jobcount
; /* Number of jobs */
272 ipp_attribute_t
*attr
; /* IPP attribute */
273 char *message
; /* Printer state message */
274 int accepting
; /* Accepting requests? */
275 ipp_pstate_t pstate
; /* Printer state */
276 char uri
[HTTP_MAX_URI
];/* Printer URI */
280 * Build a IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
284 * attributes-natural-language
290 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
291 request
->request
.op
.request_id
= 1;
293 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
294 "attributes-charset", NULL
, cupsLangEncoding(language
));
296 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
297 "attributes-natural-language", NULL
, language
->language
);
299 sprintf(uri
, "ipp://localhost/classes/%s", name
);
301 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, uri
);
304 * Do the request and get back a response...
307 if ((response
= cupsDoRequest(http
, request
, uri
+ 15)) == NULL
)
309 puts("<P>Unable to communicate with CUPS server!");
313 if (response
->request
.status
.status_code
== IPP_NOT_FOUND
)
315 puts("<P>Class does not exist.");
321 * Grab the needed class attributes...
324 if ((attr
= ippFindAttribute(response
, "printer-state", IPP_TAG_ENUM
)) != NULL
)
325 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
327 pstate
= IPP_PRINTER_IDLE
;
329 if ((attr
= ippFindAttribute(response
, "printer-state-message", IPP_TAG_TEXT
)) != NULL
)
330 message
= attr
->values
[0].string
.text
;
334 if ((attr
= ippFindAttribute(response
, "printer-is-accepting-jobs",
335 IPP_TAG_BOOLEAN
)) != NULL
)
336 accepting
= attr
->values
[0].boolean
;
340 if ((attr
= ippFindAttribute(response
, "printer-uri-supported", IPP_TAG_URI
)) != NULL
)
342 strcpy(uri
, "http:");
343 strcpy(uri
+ 5, strchr(attr
->values
[0].string
.text
, '/'));
347 * Display the class entry...
352 printf("<TD VALIGN=TOP><A HREF=\"%s\">%s</A></TD>\n", uri
, name
);
354 puts("<TD VALIGN=TOP><IMG SRC=\"/images/classes.gif\" ALIGN=\"LEFT\">");
356 printf("%s: %s, %s<BR>\n",
357 cupsLangString(language
, CUPS_MSG_PRINTER_STATE
),
358 cupsLangString(language
, pstate
== IPP_PRINTER_IDLE
? CUPS_MSG_IDLE
:
359 pstate
== IPP_PRINTER_PROCESSING
?
360 CUPS_MSG_PROCESSING
: CUPS_MSG_STOPPED
),
361 cupsLangString(language
, accepting
? CUPS_MSG_ACCEPTING_JOBS
:
362 CUPS_MSG_NOT_ACCEPTING_JOBS
));
365 printf("<BR CLEAR=ALL><I>\"%s\"</I>\n", message
);
366 else if (!accepting
|| pstate
== IPP_PRINTER_STOPPED
)
367 puts("<BR CLEAR=ALL><I>\"Reason Unknown\"</I>");
372 * Show a list of jobs as needed...
375 if (pstate
!= IPP_PRINTER_IDLE
)
378 * Build an IPP_GET_JOBS request, which requires the following
382 * attributes-natural-language
388 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
389 request
->request
.op
.request_id
= 1;
391 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
392 "attributes-charset", NULL
,
393 cupsLangEncoding(language
));
395 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
396 "attributes-natural-language", NULL
,
399 sprintf(uri
, "ipp://localhost/printers/%s", name
);
400 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
401 "printer-uri", NULL
, uri
);
403 jobs
= cupsDoRequest(http
, request
, uri
+ 15);
408 puts("<TD VALIGN=\"TOP\">");
413 char *username
; /* Pointer to job-originating-user-name */
414 int jobid
, /* job-id */
415 size
; /* job-k-octets */
418 for (attr
= jobs
->attrs
; attr
!= NULL
; attr
= attr
->next
)
421 * Skip leading attributes until we hit a job...
424 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
431 * Pull the needed attributes from this job...
438 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
440 if (strcmp(attr
->name
, "job-id") == 0 &&
441 attr
->value_tag
== IPP_TAG_INTEGER
)
442 jobid
= attr
->values
[0].integer
;
444 if (strcmp(attr
->name
, "job-k-octets") == 0 &&
445 attr
->value_tag
== IPP_TAG_INTEGER
)
446 size
= attr
->values
[0].integer
;
448 if (strcmp(attr
->name
, "job-originating-user-name") == 0 &&
449 attr
->value_tag
== IPP_TAG_NAME
)
450 username
= attr
->values
[0].string
.text
;
456 * Display the job if it matches the current class...
459 if (username
!= NULL
)
462 printf("<A HREF=\"/jobs/%d\">%s-%d %s %dk</A><BR>\n", jobid
, name
,
463 jobid
, username
, size
);
483 * End of "$Id: classes.c,v 1.7 1999/09/27 17:14:25 mike Exp $".