]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 4906 2006-01-10 20:53:28Z mike $"
4 * "lpinfo" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and show information.
27 * show_devices() - Show available devices.
28 * show_models() - Show available PPDs.
32 * Include necessary headers...
38 #include <cups/string.h>
39 #include <cups/cups.h>
40 #include <cups/i18n.h>
41 #include <cups/debug.h>
48 static int show_devices(http_t
*, int);
49 static int show_models(http_t
*, int);
53 * 'main()' - Parse options and show status information.
57 main(int argc
, /* I - Number of command-line arguments */
58 char *argv
[]) /* I - Command-line arguments */
60 int i
; /* Looping var */
61 http_t
*http
; /* Connection to server */
62 int long_status
; /* Long listing? */
68 for (i
= 1; i
< argc
; i
++)
69 if (argv
[i
][0] == '-')
72 case 'E' : /* Encrypt */
74 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
77 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
79 _cupsLangPrintf(stderr
, NULL
,
80 _("%s: Sorry, no encryption support compiled in!\n"),
85 case 'l' : /* Show long listing */
89 case 'm' : /* Show models */
92 http
= httpConnectEncrypt(cupsServer(), ippPort(),
97 _cupsLangPrintf(stderr
, NULL
,
98 _("lpinfo: Unable to connect to server: %s\n"),
104 if (show_models(http
, long_status
))
108 case 'v' : /* Show available devices */
111 http
= httpConnectEncrypt(cupsServer(), ippPort(),
116 _cupsLangPrintf(stderr
, NULL
,
117 _("lpinfo: Unable to connect to server: %s\n"),
123 if (show_devices(http
, long_status
))
127 case 'h' : /* Connect to host */
134 if (argv
[i
][2] != '\0')
135 cupsSetServer(argv
[i
] + 2);
142 _cupsLangPuts(stderr
, NULL
,
143 _("Error: need hostname after \'-h\' option!\n"));
147 cupsSetServer(argv
[i
]);
152 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: Unknown option \'%c\'!\n"),
158 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: Unknown argument \'%s\'!\n"),
168 * 'show_devices()' - Show available devices.
171 static int /* O - 0 on success, 1 on failure */
172 show_devices(http_t
*http
, /* I - HTTP connection to server */
173 int long_status
) /* I - Long status report? */
175 ipp_t
*request
, /* IPP Request */
176 *response
; /* IPP Response */
177 ipp_attribute_t
*attr
; /* Current attribute */
178 cups_lang_t
*language
; /* Default language */
179 const char *device_class
, /* Pointer into device-class */
180 *device_info
, /* Pointer into device-info */
181 *device_make
, /* Pointer into device-make-and-model */
182 *device_uri
; /* Pointer into device-uri */
189 * Build a CUPS_GET_DEVICES request, which requires the following
193 * attributes-natural-language
199 request
->request
.op
.operation_id
= CUPS_GET_DEVICES
;
200 request
->request
.op
.request_id
= 1;
202 language
= cupsLangDefault();
204 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
205 "attributes-charset", NULL
, cupsLangEncoding(language
));
207 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
208 "attributes-natural-language", NULL
, language
->language
);
210 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
211 NULL
, "ipp://localhost/printers/");
214 * Do the request and get back a response...
217 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
220 * Loop through the device list and display them...
223 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
225 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: cups-get-devices failed: %s\n"),
226 ippErrorString(response
->request
.status
.status_code
));
231 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
234 * Skip leading attributes until we hit a device...
237 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
244 * Pull the needed attributes from this device...
252 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
254 if (!strcmp(attr
->name
, "device-class") &&
255 attr
->value_tag
== IPP_TAG_KEYWORD
)
256 device_class
= attr
->values
[0].string
.text
;
258 if (!strcmp(attr
->name
, "device-info") &&
259 attr
->value_tag
== IPP_TAG_TEXT
)
260 device_info
= attr
->values
[0].string
.text
;
262 if (!strcmp(attr
->name
, "device-make-and-model") &&
263 attr
->value_tag
== IPP_TAG_TEXT
)
264 device_make
= attr
->values
[0].string
.text
;
266 if (!strcmp(attr
->name
, "device-uri") &&
267 attr
->value_tag
== IPP_TAG_URI
)
268 device_uri
= attr
->values
[0].string
.text
;
274 * See if we have everything needed...
277 if (device_class
== NULL
|| device_info
== NULL
||
278 device_make
== NULL
|| device_uri
== NULL
)
287 * Display the device...
292 _cupsLangPrintf(stdout
, language
,
293 _("Device: uri = %s\n"
296 " make-and-model = %s\n"),
297 device_uri
, device_class
, device_info
, device_make
);
300 _cupsLangPrintf(stdout
, language
, "%s %s\n", device_class
, device_uri
);
310 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: cups-get-devices failed: %s\n"),
311 ippErrorString(cupsLastError()));
320 * 'show_models()' - Show available PPDs.
323 static int /* O - 0 on success, 1 on failure */
324 show_models(http_t
*http
, /* I - HTTP connection to server */
325 int long_status
) /* I - Long status report? */
327 ipp_t
*request
, /* IPP Request */
328 *response
; /* IPP Response */
329 ipp_attribute_t
*attr
; /* Current attribute */
330 cups_lang_t
*language
; /* Default language */
331 const char *ppd_language
, /* Pointer into ppd-natural-language */
332 *ppd_make
, /* Pointer into ppd-make-and-model */
333 *ppd_name
; /* Pointer into ppd-name */
340 * Build a CUPS_GET_PPDS request, which requires the following
344 * attributes-natural-language
350 request
->request
.op
.operation_id
= CUPS_GET_PPDS
;
351 request
->request
.op
.request_id
= 1;
353 language
= cupsLangDefault();
355 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
356 "attributes-charset", NULL
, cupsLangEncoding(language
));
358 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
359 "attributes-natural-language", NULL
, language
->language
);
361 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
362 NULL
, "ipp://localhost/printers/");
365 * Do the request and get back a response...
368 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
371 * Loop through the device list and display them...
374 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
376 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: cups-get-ppds failed: %s\n"),
377 ippErrorString(response
->request
.status
.status_code
));
382 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
385 * Skip leading attributes until we hit a PPD...
388 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
395 * Pull the needed attributes from this PPD...
402 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
404 if (!strcmp(attr
->name
, "ppd-natural-language") &&
405 attr
->value_tag
== IPP_TAG_LANGUAGE
)
406 ppd_language
= attr
->values
[0].string
.text
;
408 if (!strcmp(attr
->name
, "ppd-make-and-model") &&
409 attr
->value_tag
== IPP_TAG_TEXT
)
410 ppd_make
= attr
->values
[0].string
.text
;
412 if (!strcmp(attr
->name
, "ppd-name") &&
413 attr
->value_tag
== IPP_TAG_NAME
)
414 ppd_name
= attr
->values
[0].string
.text
;
420 * See if we have everything needed...
423 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
432 * Display the device...
437 _cupsLangPrintf(stdout
, language
,
438 _("Model: name = %s\n"
439 " natural_language = %s\n"
440 " make-and-model = %s\n"),
441 ppd_name
, ppd_language
, ppd_make
);
444 _cupsLangPrintf(stdout
, language
, "%s %s\n", ppd_name
, ppd_make
);
454 _cupsLangPrintf(stderr
, NULL
, _("lpinfo: cups-get-ppds failed: %s\n"),
455 ippErrorString(cupsLastError()));
465 * End of "$Id: lpinfo.c 4906 2006-01-10 20:53:28Z mike $".