]> git.ipfire.org Git - thirdparty/cups.git/blame - cgi-bin/printers.c
Added templates, CGI variable code, and updated printers CGI to use
[thirdparty/cups.git] / cgi-bin / printers.c
CommitLineData
c4adf588 1/*
13c1a6d9 2 * "$Id: printers.c,v 1.14 2000/02/01 02:52:23 mike Exp $"
c4adf588 3 *
4 * Printer status CGI for the Common UNIX Printing System (CUPS).
5 *
13c1a6d9 6 * Copyright 1997-2000 by Easy Software Products.
c4adf588 7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
13c1a6d9 26 * main() - Main entry for CGI.
c4adf588 27 */
28
29/*
30 * Include necessary headers...
31 */
32
13c1a6d9 33#include "ipp-var.h"
c4adf588 34
35
36/*
37 * 'main()' - Main entry for CGI.
38 */
39
40int /* O - Exit status */
41main(int argc, /* I - Number of command-line arguments */
42 char *argv[]) /* I - Command-line arguments */
43{
44 cups_lang_t *language; /* Language information */
45 char *printer; /* Printer name */
46 http_t *http; /* Connection to the server */
13c1a6d9 47 ipp_t *request, /* IPP request */
48 *response; /* IPP response */
49 ipp_attribute_t *attr; /* IPP attribute */
50 char uri[HTTP_MAX_URI];
51 /* Printer URI */
52
c4adf588 53
13c1a6d9 54 setbuf(stdout, NULL);
c4adf588 55
56 /*
57 * Get the request language...
58 */
59
da376774 60 language = cupsLangDefault();
c4adf588 61
62 /*
63 * Connect to the HTTP server...
64 */
65
2bc54909 66 http = httpConnect("localhost", ippPort());
c4adf588 67
68 /*
69 * Tell the client to expect HTML...
70 */
71
72 printf("Content-Type: text/html;charset=%s\n\n", cupsLangEncoding(language));
73
74 /*
75 * See if we need to show a list of printers or the status of a
76 * single printer...
77 */
78
79 printer = argv[0];
80 if (strcmp(printer, "/") == 0 || strcmp(printer, "printers.cgi") == 0)
13c1a6d9 81 {
c4adf588 82 printer = NULL;
13c1a6d9 83 cgiSetVariable("TITLE", "Printers");
84 }
c4adf588 85 else
13c1a6d9 86 cgiSetVariable("TITLE", printer);
c4adf588 87
88 /*
13c1a6d9 89 * Get the printer info...
c4adf588 90 */
91
92 request = ippNew();
93
580af8cf 94 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
95 "attributes-charset", NULL, cupsLangEncoding(language));
c4adf588 96
580af8cf 97 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
98 "attributes-natural-language", NULL, language->language);
c4adf588 99
13c1a6d9 100 if (printer == NULL)
c4adf588 101 {
102 /*
13c1a6d9 103 * Build a CUPS_GET_PRINTERS request, which requires the following
104 * attributes:
105 *
106 * attributes-charset
107 * attributes-natural-language
c4adf588 108 */
109
13c1a6d9 110 request->request.op.operation_id = CUPS_GET_PRINTERS;
111 request->request.op.request_id = 1;
580af8cf 112 }
580af8cf 113 else
580af8cf 114 {
c4adf588 115 /*
13c1a6d9 116 * Build a IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
580af8cf 117 * attributes:
118 *
119 * attributes-charset
120 * attributes-natural-language
121 * printer-uri
c4adf588 122 */
123
13c1a6d9 124 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
580af8cf 125 request->request.op.request_id = 1;
126
13c1a6d9 127 snprintf(uri, sizeof(uri), "ipp://%s/printers/%s", getenv("SERVER_NAME"),
128 printer);
129 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
130 uri);
580af8cf 131 }
580af8cf 132
13c1a6d9 133 /*
134 * Do the request and get back a response...
135 */
580af8cf 136
13c1a6d9 137 if ((response = cupsDoRequest(http, request, "/")) != NULL)
580af8cf 138 {
13c1a6d9 139 ippSetCGIVars(response);
140 ippDelete(response);
141 }
c4adf588 142
13c1a6d9 143 /*
144 * Write the report...
145 */
c4adf588 146
13c1a6d9 147 cgiCopyTemplateFile(stdout, TEMPLATES "/header.tmpl");
148 cgiCopyTemplateFile(stdout, TEMPLATES "/printers.tmpl");
149 cgiCopyTemplateFile(stdout, TEMPLATES "/trailer.tmpl");
c4adf588 150
13c1a6d9 151 /*
152 * Close the HTTP server connection...
153 */
c4adf588 154
13c1a6d9 155 httpClose(http);
156 cupsLangFree(language);
580af8cf 157
13c1a6d9 158 /*
159 * Return with no errors...
160 */
580af8cf 161
13c1a6d9 162 return (0);
c4adf588 163}
164
165
166/*
13c1a6d9 167 * End of "$Id: printers.c,v 1.14 2000/02/01 02:52:23 mike Exp $".
c4adf588 168 */