]>
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 * device_cb - Device callback.
19 * show_devices() - Show available devices.
20 * show_models() - Show available PPDs.
24 * Include necessary headers...
30 #include <cups/string.h>
31 #include <cups/cups.h>
32 #include <cups/i18n.h>
33 #include <cups/debug.h>
40 static void device_cb(const char *device_clas
, const char *device_id
,
41 const char *device_info
,
42 const char *device_make_and_model
,
43 const char *device_uri
, void *user_data
);
44 static int show_devices(http_t
*, int);
45 static int show_models(http_t
*, int);
49 * 'main()' - Parse options and show status information.
53 main(int argc
, /* I - Number of command-line arguments */
54 char *argv
[]) /* I - Command-line arguments */
56 int i
; /* Looping var */
57 http_t
*http
; /* Connection to server */
58 int long_status
; /* Long listing? */
66 for (i
= 1; i
< argc
; i
++)
67 if (argv
[i
][0] == '-')
70 case 'E' : /* Encrypt */
72 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
75 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
77 _cupsLangPrintf(stderr
,
78 _("%s: Sorry, no encryption support compiled in!\n"),
83 case 'l' : /* Show long listing */
87 case 'm' : /* Show models */
90 http
= httpConnectEncrypt(cupsServer(), ippPort(),
95 _cupsLangPrintf(stderr
,
96 _("lpinfo: Unable to connect to server: %s\n"),
102 if (show_models(http
, long_status
))
106 case 'v' : /* Show available devices */
109 http
= httpConnectEncrypt(cupsServer(), ippPort(),
114 _cupsLangPrintf(stderr
,
115 _("lpinfo: Unable to connect to server: %s\n"),
121 if (show_devices(http
, long_status
))
125 case 'h' : /* Connect to host */
132 if (argv
[i
][2] != '\0')
133 cupsSetServer(argv
[i
] + 2);
140 _cupsLangPuts(stderr
,
141 _("Error: need hostname after \'-h\' option!\n"));
145 cupsSetServer(argv
[i
]);
150 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
156 _cupsLangPrintf(stderr
, _("lpinfo: Unknown argument \'%s\'!\n"),
166 * 'device_cb()' - Device callback.
171 const char *device_class
, /* I - device-class string */
172 const char *device_id
, /* I - device-id string */
173 const char *device_info
, /* I - device-info string */
174 const char *device_make_and_model
, /* I - device-make-and-model string */
175 const char *device_uri
, /* I - device-uri string */
176 void *user_data
) /* I - User data */
178 int *long_status
; /* Show verbose info? */
182 * Display the device...
185 long_status
= (int *)user_data
;
189 _cupsLangPrintf(stdout
,
190 _("Device: uri = %s\n"
193 " make-and-model = %s\n"
194 " device-id = %s\n"),
195 device_uri
, device_class
, device_info
,
196 device_make_and_model
, device_id
);
199 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
204 * 'show_devices()' - Show available devices.
207 static int /* O - 0 on success, 1 on failure */
208 show_devices(http_t
*http
, /* I - HTTP connection to server */
209 int long_status
) /* I - Long status report? */
211 if (cupsGetDevices(http
, CUPS_TIMEOUT_DEFAULT
, CUPS_EXCLUDE_NONE
, device_cb
,
212 &long_status
) != IPP_OK
)
214 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
223 * 'show_models()' - Show available PPDs.
226 static int /* O - 0 on success, 1 on failure */
227 show_models(http_t
*http
, /* I - HTTP connection to server */
228 int long_status
) /* I - Long status report? */
230 ipp_t
*request
, /* IPP Request */
231 *response
; /* IPP Response */
232 ipp_attribute_t
*attr
; /* Current attribute */
233 const char *ppd_device_id
, /* Pointer to ppd-device-id */
234 *ppd_language
, /* Pointer to ppd-natural-language */
235 *ppd_make
, /* Pointer to ppd-make-and-model */
236 *ppd_name
; /* Pointer to ppd-name */
243 * Build a CUPS_GET_PPDS request, which requires the following
247 * attributes-natural-language
250 request
= ippNewRequest(CUPS_GET_PPDS
);
253 * Do the request and get back a response...
256 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
259 * Loop through the device list and display them...
262 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
264 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
269 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
272 * Skip leading attributes until we hit a PPD...
275 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
282 * Pull the needed attributes from this PPD...
285 ppd_device_id
= "NONE";
290 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
292 if (!strcmp(attr
->name
, "ppd-device-id") &&
293 attr
->value_tag
== IPP_TAG_TEXT
)
294 ppd_device_id
= attr
->values
[0].string
.text
;
295 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
296 attr
->value_tag
== IPP_TAG_LANGUAGE
)
297 ppd_language
= attr
->values
[0].string
.text
;
298 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
299 attr
->value_tag
== IPP_TAG_TEXT
)
300 ppd_make
= attr
->values
[0].string
.text
;
301 else if (!strcmp(attr
->name
, "ppd-name") &&
302 attr
->value_tag
== IPP_TAG_NAME
)
303 ppd_name
= attr
->values
[0].string
.text
;
309 * See if we have everything needed...
312 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
321 * Display the device...
326 _cupsLangPrintf(stdout
,
327 _("Model: name = %s\n"
328 " natural_language = %s\n"
329 " make-and-model = %s\n"
330 " device-id = %s\n"),
331 ppd_name
, ppd_language
, ppd_make
, ppd_device_id
);
334 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make
);
344 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
354 * End of "$Id: lpinfo.c 6649 2007-07-11 21:46:42Z mike $".