]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 4925 2006-01-13 02:52:47Z 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
,
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
,
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
,
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
,
143 _("Error: need hostname after \'-h\' option!\n"));
147 cupsSetServer(argv
[i
]);
152 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
158 _cupsLangPrintf(stderr
, _("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 const char *device_class
, /* Pointer to device-class */
179 *device_id
, /* Pointer to device-id */
180 *device_info
, /* Pointer to device-info */
181 *device_make
, /* Pointer to device-make-and-model */
182 *device_uri
; /* Pointer to device-uri */
189 * Build a CUPS_GET_DEVICES request, which requires the following
193 * attributes-natural-language
196 request
= ippNewRequest(CUPS_GET_DEVICES
);
199 * Do the request and get back a response...
202 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
205 * Loop through the device list and display them...
208 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
210 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
215 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
218 * Skip leading attributes until we hit a device...
221 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
228 * Pull the needed attributes from this device...
237 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
239 if (!strcmp(attr
->name
, "device-class") &&
240 attr
->value_tag
== IPP_TAG_KEYWORD
)
241 device_class
= attr
->values
[0].string
.text
;
242 else if (!strcmp(attr
->name
, "device-info") &&
243 attr
->value_tag
== IPP_TAG_TEXT
)
244 device_info
= attr
->values
[0].string
.text
;
245 else if (!strcmp(attr
->name
, "device-make-and-model") &&
246 attr
->value_tag
== IPP_TAG_TEXT
)
247 device_make
= attr
->values
[0].string
.text
;
248 else if (!strcmp(attr
->name
, "device-uri") &&
249 attr
->value_tag
== IPP_TAG_URI
)
250 device_uri
= attr
->values
[0].string
.text
;
251 else if (!strcmp(attr
->name
, "device-id") &&
252 attr
->value_tag
== IPP_TAG_TEXT
)
253 device_id
= attr
->values
[0].string
.text
;
259 * See if we have everything needed...
262 if (device_class
== NULL
|| device_info
== NULL
||
263 device_make
== NULL
|| device_uri
== NULL
)
272 * Display the device...
277 _cupsLangPrintf(stdout
,
278 _("Device: uri = %s\n"
281 " make-and-model = %s\n"
282 " device-id = %s\n"),
283 device_uri
, device_class
, device_info
, device_make
,
287 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
297 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
306 * 'show_models()' - Show available PPDs.
309 static int /* O - 0 on success, 1 on failure */
310 show_models(http_t
*http
, /* I - HTTP connection to server */
311 int long_status
) /* I - Long status report? */
313 ipp_t
*request
, /* IPP Request */
314 *response
; /* IPP Response */
315 ipp_attribute_t
*attr
; /* Current attribute */
316 const char *ppd_device_id
, /* Pointer to ppd-device-id */
317 *ppd_language
, /* Pointer to ppd-natural-language */
318 *ppd_make
, /* Pointer to ppd-make-and-model */
319 *ppd_name
; /* Pointer to ppd-name */
326 * Build a CUPS_GET_PPDS request, which requires the following
330 * attributes-natural-language
333 request
= ippNewRequest(CUPS_GET_PPDS
);
336 * Do the request and get back a response...
339 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
342 * Loop through the device list and display them...
345 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
347 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
352 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
355 * Skip leading attributes until we hit a PPD...
358 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
365 * Pull the needed attributes from this PPD...
368 ppd_device_id
= "NONE";
373 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
375 if (!strcmp(attr
->name
, "ppd-device-id") &&
376 attr
->value_tag
== IPP_TAG_TEXT
)
377 ppd_device_id
= attr
->values
[0].string
.text
;
378 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
379 attr
->value_tag
== IPP_TAG_LANGUAGE
)
380 ppd_language
= attr
->values
[0].string
.text
;
381 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
382 attr
->value_tag
== IPP_TAG_TEXT
)
383 ppd_make
= attr
->values
[0].string
.text
;
384 else if (!strcmp(attr
->name
, "ppd-name") &&
385 attr
->value_tag
== IPP_TAG_NAME
)
386 ppd_name
= attr
->values
[0].string
.text
;
392 * See if we have everything needed...
395 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
404 * Display the device...
409 _cupsLangPrintf(stdout
,
410 _("Model: name = %s\n"
411 " natural_language = %s\n"
412 " make-and-model = %s\n"
413 " device-id = %s\n"),
414 ppd_name
, ppd_language
, ppd_make
, ppd_device_id
);
417 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make
);
427 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
437 * End of "$Id: lpinfo.c 4925 2006-01-13 02:52:47Z mike $".