2 * Support code for the Common UNIX Printing System ("CUPS")
4 * Copyright 1999 by Easy Software Products
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <cups/cups.h>
26 #include <cups/language.h>
28 extern int DEBUGLEVEL
;
32 * 'cups_printer_fn()' - Call a function for every printer known to the
36 void cups_printer_fn(void (*fn
)(char *, char *))
38 http_t
*http
; /* HTTP connection to server */
39 ipp_t
*request
, /* IPP Request */
40 *response
; /* IPP Response */
41 ipp_attribute_t
*attr
; /* Current attribute */
42 cups_lang_t
*language
; /* Default language */
43 char *name
, /* printer-name attribute */
44 *make_model
; /* make_model attribute */
48 * Try to connect to the server...
51 if ((http
= httpConnect(cupsServer(), ippPort())) == NULL
)
55 * Build a CUPS_GET_PRINTERS request, which requires the following
59 * attributes-natural-language
64 request
->request
.op
.operation_id
= CUPS_GET_PRINTERS
;
65 request
->request
.op
.request_id
= 1;
67 language
= cupsLangDefault();
69 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
70 "attributes-charset", NULL
, cupsLangEncoding(language
));
72 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
73 "attributes-natural-language", NULL
, language
->language
);
76 * Do the request and get back a response...
79 if ((response
= cupsDoRequest(http
, request
, "/")) == NULL
)
85 for (attr
= response
->attrs
; attr
!= NULL
;)
88 * Skip leading attributes until we hit a printer...
91 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
98 * Pull the needed attributes from this printer...
104 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
106 if (strcmp(attr
->name
, "printer-name") == 0 &&
107 attr
->value_tag
== IPP_TAG_NAME
)
108 name
= attr
->values
[0].string
.text
;
110 if (strcmp(attr
->name
, "printer-make-and-model") == 0 &&
111 attr
->value_tag
== IPP_TAG_TEXT
)
112 make_model
= attr
->values
[0].string
.text
;
118 * See if we have everything needed...
124 (*fn
)(name
, make_model
);
133 * provide the equivalent of pcap_printername_ok() for SVID/XPG4 conforming
136 int cups_printername_ok(char *name
)
138 http_t
*http
; /* HTTP connection to server */
139 ipp_t
*request
, /* IPP Request */
140 *response
; /* IPP Response */
141 ipp_attribute_t
*attr
; /* Current attribute */
142 cups_lang_t
*language
; /* Default language */
143 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
146 * Try to connect to the server...
149 if ((http
= httpConnect(cupsServer(), ippPort())) == NULL
)
153 * Build a IPP_GET_PRINTER_ATTRS request, which requires the following
157 * attributes-natural-language
163 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
164 request
->request
.op
.request_id
= 1;
166 language
= cupsLangDefault();
168 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
169 "attributes-charset", NULL
, cupsLangEncoding(language
));
171 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
172 "attributes-natural-language", NULL
, language
->language
);
174 snprintf(uri
, sizeof(uri
), "ipp://localhost/printers/%s", name
);
176 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
177 "printer-uri", NULL
, uri
);
180 * Do the request and get back a response...
183 if ((response
= cupsDoRequest(http
, request
, "/")) == NULL
)
191 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
)
204 /* this keeps fussy compilers happy */
205 void print_cups_dummy(void) {}
206 #endif /* HAVE_LIBCUPS */