]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 5926 2006-09-05 20:45: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? */
70 for (i
= 1; i
< argc
; i
++)
71 if (argv
[i
][0] == '-')
74 case 'E' : /* Encrypt */
76 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
79 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
81 _cupsLangPrintf(stderr
,
82 _("%s: Sorry, no encryption support compiled in!\n"),
87 case 'l' : /* Show long listing */
91 case 'm' : /* Show models */
94 http
= httpConnectEncrypt(cupsServer(), ippPort(),
99 _cupsLangPrintf(stderr
,
100 _("lpinfo: Unable to connect to server: %s\n"),
106 if (show_models(http
, long_status
))
110 case 'v' : /* Show available devices */
113 http
= httpConnectEncrypt(cupsServer(), ippPort(),
118 _cupsLangPrintf(stderr
,
119 _("lpinfo: Unable to connect to server: %s\n"),
125 if (show_devices(http
, long_status
))
129 case 'h' : /* Connect to host */
136 if (argv
[i
][2] != '\0')
137 cupsSetServer(argv
[i
] + 2);
144 _cupsLangPuts(stderr
,
145 _("Error: need hostname after \'-h\' option!\n"));
149 cupsSetServer(argv
[i
]);
154 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
160 _cupsLangPrintf(stderr
, _("lpinfo: Unknown argument \'%s\'!\n"),
170 * 'show_devices()' - Show available devices.
173 static int /* O - 0 on success, 1 on failure */
174 show_devices(http_t
*http
, /* I - HTTP connection to server */
175 int long_status
) /* I - Long status report? */
177 ipp_t
*request
, /* IPP Request */
178 *response
; /* IPP Response */
179 ipp_attribute_t
*attr
; /* Current attribute */
180 const char *device_class
, /* Pointer to device-class */
181 *device_id
, /* Pointer to device-id */
182 *device_info
, /* Pointer to device-info */
183 *device_make
, /* Pointer to device-make-and-model */
184 *device_uri
; /* Pointer to device-uri */
191 * Build a CUPS_GET_DEVICES request, which requires the following
195 * attributes-natural-language
198 request
= ippNewRequest(CUPS_GET_DEVICES
);
201 * Do the request and get back a response...
204 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
207 * Loop through the device list and display them...
210 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
212 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
217 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
220 * Skip leading attributes until we hit a device...
223 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
230 * Pull the needed attributes from this device...
239 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
241 if (!strcmp(attr
->name
, "device-class") &&
242 attr
->value_tag
== IPP_TAG_KEYWORD
)
243 device_class
= attr
->values
[0].string
.text
;
244 else if (!strcmp(attr
->name
, "device-info") &&
245 attr
->value_tag
== IPP_TAG_TEXT
)
246 device_info
= attr
->values
[0].string
.text
;
247 else if (!strcmp(attr
->name
, "device-make-and-model") &&
248 attr
->value_tag
== IPP_TAG_TEXT
)
249 device_make
= attr
->values
[0].string
.text
;
250 else if (!strcmp(attr
->name
, "device-uri") &&
251 attr
->value_tag
== IPP_TAG_URI
)
252 device_uri
= attr
->values
[0].string
.text
;
253 else if (!strcmp(attr
->name
, "device-id") &&
254 attr
->value_tag
== IPP_TAG_TEXT
)
255 device_id
= attr
->values
[0].string
.text
;
261 * See if we have everything needed...
264 if (device_class
== NULL
|| device_info
== NULL
||
265 device_make
== NULL
|| device_uri
== NULL
)
274 * Display the device...
279 _cupsLangPrintf(stdout
,
280 _("Device: uri = %s\n"
283 " make-and-model = %s\n"
284 " device-id = %s\n"),
285 device_uri
, device_class
, device_info
, device_make
,
289 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
299 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
308 * 'show_models()' - Show available PPDs.
311 static int /* O - 0 on success, 1 on failure */
312 show_models(http_t
*http
, /* I - HTTP connection to server */
313 int long_status
) /* I - Long status report? */
315 ipp_t
*request
, /* IPP Request */
316 *response
; /* IPP Response */
317 ipp_attribute_t
*attr
; /* Current attribute */
318 const char *ppd_device_id
, /* Pointer to ppd-device-id */
319 *ppd_language
, /* Pointer to ppd-natural-language */
320 *ppd_make
, /* Pointer to ppd-make-and-model */
321 *ppd_name
; /* Pointer to ppd-name */
328 * Build a CUPS_GET_PPDS request, which requires the following
332 * attributes-natural-language
335 request
= ippNewRequest(CUPS_GET_PPDS
);
338 * Do the request and get back a response...
341 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
344 * Loop through the device list and display them...
347 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
349 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
354 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
357 * Skip leading attributes until we hit a PPD...
360 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
367 * Pull the needed attributes from this PPD...
370 ppd_device_id
= "NONE";
375 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
377 if (!strcmp(attr
->name
, "ppd-device-id") &&
378 attr
->value_tag
== IPP_TAG_TEXT
)
379 ppd_device_id
= attr
->values
[0].string
.text
;
380 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
381 attr
->value_tag
== IPP_TAG_LANGUAGE
)
382 ppd_language
= attr
->values
[0].string
.text
;
383 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
384 attr
->value_tag
== IPP_TAG_TEXT
)
385 ppd_make
= attr
->values
[0].string
.text
;
386 else if (!strcmp(attr
->name
, "ppd-name") &&
387 attr
->value_tag
== IPP_TAG_NAME
)
388 ppd_name
= attr
->values
[0].string
.text
;
394 * See if we have everything needed...
397 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
406 * Display the device...
411 _cupsLangPrintf(stdout
,
412 _("Model: name = %s\n"
413 " natural_language = %s\n"
414 " make-and-model = %s\n"
415 " device-id = %s\n"),
416 ppd_name
, ppd_language
, ppd_make
, ppd_device_id
);
419 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make
);
429 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
439 * End of "$Id: lpinfo.c 5926 2006-09-05 20:45:47Z mike $".