]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 7460 2008-04-16 02:19:54Z 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
, const char *device_location
,
45 static int show_devices(http_t
*, int);
46 static int show_models(http_t
*, int);
50 * 'main()' - Parse options and show status information.
54 main(int argc
, /* I - Number of command-line arguments */
55 char *argv
[]) /* I - Command-line arguments */
57 int i
; /* Looping var */
58 http_t
*http
; /* Connection to server */
59 int long_status
; /* Long listing? */
67 for (i
= 1; i
< argc
; i
++)
68 if (argv
[i
][0] == '-')
71 case 'E' : /* Encrypt */
73 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
76 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
78 _cupsLangPrintf(stderr
,
79 _("%s: Sorry, no encryption support compiled in!\n"),
84 case 'l' : /* Show long listing */
88 case 'm' : /* Show models */
91 http
= httpConnectEncrypt(cupsServer(), ippPort(),
96 _cupsLangPrintf(stderr
,
97 _("lpinfo: Unable to connect to server: %s\n"),
103 if (show_models(http
, long_status
))
107 case 'v' : /* Show available devices */
110 http
= httpConnectEncrypt(cupsServer(), ippPort(),
115 _cupsLangPrintf(stderr
,
116 _("lpinfo: Unable to connect to server: %s\n"),
122 if (show_devices(http
, long_status
))
126 case 'h' : /* Connect to host */
133 if (argv
[i
][2] != '\0')
134 cupsSetServer(argv
[i
] + 2);
141 _cupsLangPuts(stderr
,
142 _("Error: need hostname after \'-h\' option!\n"));
146 cupsSetServer(argv
[i
]);
151 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
157 _cupsLangPrintf(stderr
, _("lpinfo: Unknown argument \'%s\'!\n"),
167 * 'device_cb()' - Device callback.
172 const char *device_class
, /* I - device-class string */
173 const char *device_id
, /* I - device-id string */
174 const char *device_info
, /* I - device-info string */
175 const char *device_make_and_model
, /* I - device-make-and-model string */
176 const char *device_uri
, /* I - device-uri string */
177 const char *device_location
, /* I - device-location string */
178 void *user_data
) /* I - User data */
180 int *long_status
; /* Show verbose info? */
184 * Display the device...
187 long_status
= (int *)user_data
;
191 _cupsLangPrintf(stdout
,
192 _("Device: uri = %s\n"
195 " make-and-model = %s\n"
198 device_uri
, device_class
, device_info
,
199 device_make_and_model
, device_id
, device_location
);
202 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
207 * 'show_devices()' - Show available devices.
210 static int /* O - 0 on success, 1 on failure */
211 show_devices(http_t
*http
, /* I - HTTP connection to server */
212 int long_status
) /* I - Long status report? */
214 if (cupsGetDevices(http
, CUPS_TIMEOUT_DEFAULT
, CUPS_EXCLUDE_NONE
, device_cb
,
215 &long_status
) != IPP_OK
)
217 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
226 * 'show_models()' - Show available PPDs.
229 static int /* O - 0 on success, 1 on failure */
230 show_models(http_t
*http
, /* I - HTTP connection to server */
231 int long_status
) /* I - Long status report? */
233 ipp_t
*request
, /* IPP Request */
234 *response
; /* IPP Response */
235 ipp_attribute_t
*attr
; /* Current attribute */
236 const char *ppd_device_id
, /* Pointer to ppd-device-id */
237 *ppd_language
, /* Pointer to ppd-natural-language */
238 *ppd_make
, /* Pointer to ppd-make-and-model */
239 *ppd_name
; /* Pointer to ppd-name */
246 * Build a CUPS_GET_PPDS request, which requires the following
250 * attributes-natural-language
253 request
= ippNewRequest(CUPS_GET_PPDS
);
256 * Do the request and get back a response...
259 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
262 * Loop through the device list and display them...
265 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
267 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
272 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
275 * Skip leading attributes until we hit a PPD...
278 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
285 * Pull the needed attributes from this PPD...
288 ppd_device_id
= "NONE";
293 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
295 if (!strcmp(attr
->name
, "ppd-device-id") &&
296 attr
->value_tag
== IPP_TAG_TEXT
)
297 ppd_device_id
= attr
->values
[0].string
.text
;
298 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
299 attr
->value_tag
== IPP_TAG_LANGUAGE
)
300 ppd_language
= attr
->values
[0].string
.text
;
301 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
302 attr
->value_tag
== IPP_TAG_TEXT
)
303 ppd_make
= attr
->values
[0].string
.text
;
304 else if (!strcmp(attr
->name
, "ppd-name") &&
305 attr
->value_tag
== IPP_TAG_NAME
)
306 ppd_name
= attr
->values
[0].string
.text
;
312 * See if we have everything needed...
315 if (ppd_language
== NULL
|| ppd_make
== NULL
|| ppd_name
== NULL
)
324 * Display the device...
329 _cupsLangPrintf(stdout
,
330 _("Model: name = %s\n"
331 " natural_language = %s\n"
332 " make-and-model = %s\n"
333 " device-id = %s\n"),
334 ppd_name
, ppd_language
, ppd_make
, ppd_device_id
);
337 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make
);
347 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
357 * End of "$Id: lpinfo.c 7460 2008-04-16 02:19:54Z mike $".