]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 6649 2007-07-11 21:46:42Z mike $"
4 * "lpinfo" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Parse options and show information.
18 * show_devices() - Show available devices.
19 * show_models() - Show available PPDs.
23 * Include necessary headers...
29 #include <cups/string.h>
30 #include <cups/cups.h>
31 #include <cups/i18n.h>
32 #include <cups/debug.h>
39 static int show_devices(http_t
*, int);
40 static int show_models(http_t
*, int);
44 * 'main()' - Parse options and show status information.
48 main(int argc
, /* I - Number of command-line arguments */
49 char *argv
[]) /* I - Command-line arguments */
51 int i
; /* Looping var */
52 http_t
*http
; /* Connection to server */
53 int long_status
; /* Long listing? */
61 for (i
= 1; i
< argc
; i
++)
62 if (argv
[i
][0] == '-')
65 case 'E' : /* Encrypt */
67 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
70 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
72 _cupsLangPrintf(stderr
,
73 _("%s: Sorry, no encryption support compiled in!\n"),
78 case 'l' : /* Show long listing */
82 case 'm' : /* Show models */
85 http
= httpConnectEncrypt(cupsServer(), ippPort(),
90 _cupsLangPrintf(stderr
,
91 _("lpinfo: Unable to connect to server: %s\n"),
97 if (show_models(http
, long_status
))
101 case 'v' : /* Show available devices */
104 http
= httpConnectEncrypt(cupsServer(), ippPort(),
109 _cupsLangPrintf(stderr
,
110 _("lpinfo: Unable to connect to server: %s\n"),
116 if (show_devices(http
, long_status
))
120 case 'h' : /* Connect to host */
127 if (argv
[i
][2] != '\0')
128 cupsSetServer(argv
[i
] + 2);
135 _cupsLangPuts(stderr
,
136 _("Error: need hostname after \'-h\' option!\n"));
140 cupsSetServer(argv
[i
]);
145 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
151 _cupsLangPrintf(stderr
, _("lpinfo: Unknown argument \'%s\'!\n"),
161 * 'show_devices()' - Show available devices.
164 static int /* O - 0 on success, 1 on failure */
165 show_devices(http_t
*http
, /* I - HTTP connection to server */
166 int long_status
) /* I - Long status report? */
168 ipp_t
*request
, /* IPP Request */
169 *response
; /* IPP Response */
170 ipp_attribute_t
*attr
; /* Current attribute */
171 const char *device_class
, /* Pointer to device-class */
172 *device_id
, /* Pointer to device-id */
173 *device_info
, /* Pointer to device-info */
174 *device_make
, /* Pointer to device-make-and-model */
175 *device_uri
; /* Pointer to device-uri */
182 * Build a CUPS_GET_DEVICES request, which requires the following
186 * attributes-natural-language
189 request
= ippNewRequest(CUPS_GET_DEVICES
);
192 * Do the request and get back a response...
195 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
198 * Loop through the device list and display them...
201 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
203 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
208 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
211 * Skip leading attributes until we hit a device...
214 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
221 * Pull the needed attributes from this device...
230 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
232 if (!strcmp(attr
->name
, "device-class") &&
233 attr
->value_tag
== IPP_TAG_KEYWORD
)
234 device_class
= attr
->values
[0].string
.text
;
235 else if (!strcmp(attr
->name
, "device-info") &&
236 attr
->value_tag
== IPP_TAG_TEXT
)
237 device_info
= attr
->values
[0].string
.text
;
238 else if (!strcmp(attr
->name
, "device-make-and-model") &&
239 attr
->value_tag
== IPP_TAG_TEXT
)
240 device_make
= attr
->values
[0].string
.text
;
241 else if (!strcmp(attr
->name
, "device-uri") &&
242 attr
->value_tag
== IPP_TAG_URI
)
243 device_uri
= attr
->values
[0].string
.text
;
244 else if (!strcmp(attr
->name
, "device-id") &&
245 attr
->value_tag
== IPP_TAG_TEXT
)
246 device_id
= attr
->values
[0].string
.text
;
252 * See if we have everything needed...
255 if (device_class
== NULL
|| device_info
== NULL
||
256 device_make
== NULL
|| device_uri
== NULL
)
265 * Display the device...
270 _cupsLangPrintf(stdout
,
271 _("Device: uri = %s\n"
274 " make-and-model = %s\n"
275 " device-id = %s\n"),
276 device_uri
, device_class
, device_info
, device_make
,
280 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
290 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
299 * 'show_models()' - Show available PPDs.
302 static int /* O - 0 on success, 1 on failure */
303 show_models(http_t
*http
, /* I - HTTP connection to server */
304 int long_status
) /* I - Long status report? */
306 ipp_t
*request
, /* IPP Request */
307 *response
; /* IPP Response */
308 ipp_attribute_t
*attr
; /* Current attribute */
309 const char *ppd_device_id
, /* Pointer to ppd-device-id */
310 *ppd_language
, /* Pointer to ppd-natural-language */
311 *ppd_make
, /* Pointer to ppd-make-and-model */
312 *ppd_name
; /* Pointer to ppd-name */
319 * Build a CUPS_GET_PPDS request, which requires the following
323 * attributes-natural-language
326 request
= ippNewRequest(CUPS_GET_PPDS
);
329 * Do the request and get back a response...
332 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
335 * Loop through the device list and display them...
338 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
340 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
345 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
348 * Skip leading attributes until we hit a PPD...
351 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
358 * Pull the needed attributes from this PPD...
361 ppd_device_id
= "NONE";
366 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
368 if (!strcmp(attr
->name
, "ppd-device-id") &&
369 attr
->value_tag
== IPP_TAG_TEXT
)
370 ppd_device_id
= attr
->values
[0].string
.text
;
371 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
372 attr
->value_tag
== IPP_TAG_LANGUAGE
)
373 ppd_language
= attr
->values
[0].string
.text
;
374 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
375 attr
->value_tag
== IPP_TAG_TEXT
)
376 ppd_make
= attr
->values
[0].string
.text
;
377 else if (!strcmp(attr
->name
, "ppd-name") &&
378 attr
->value_tag
== IPP_TAG_NAME
)
379 ppd_name
= attr
->values
[0].string
.text
;
385 * See if we have everything needed...
388 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
397 * Display the device...
402 _cupsLangPrintf(stdout
,
403 _("Model: name = %s\n"
404 " natural_language = %s\n"
405 " make-and-model = %s\n"
406 " device-id = %s\n"),
407 ppd_name
, ppd_language
, ppd_make
, ppd_device_id
);
410 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make
);
420 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
430 * End of "$Id: lpinfo.c 6649 2007-07-11 21:46:42Z mike $".