]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpinfo.c
2 * "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z 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
*http
, int long_status
, int timeout
);
46 static int show_models(http_t
*http
, int long_status
,
47 const char *device_id
, const char *language
,
48 const char *make_model
, const char *product
);
52 * 'main()' - Parse options and show status information.
56 main(int argc
, /* I - Number of command-line arguments */
57 char *argv
[]) /* I - Command-line arguments */
59 int i
; /* Looping var */
60 http_t
*http
; /* Connection to server */
61 int long_status
; /* Long listing? */
62 const char *device_id
, /* 1284 device ID */
63 *language
, /* Language */
64 *make_model
, /* Make and model */
65 *product
; /* Product */
66 int timeout
; /* Device timeout */
77 timeout
= CUPS_TIMEOUT_DEFAULT
;
79 for (i
= 1; i
< argc
; i
++)
80 if (argv
[i
][0] == '-')
83 case 'E' : /* Encrypt */
85 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
88 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
90 _cupsLangPrintf(stderr
,
91 _("%s: Sorry, no encryption support compiled in!\n"),
96 case 'h' : /* Connect to host */
103 if (argv
[i
][2] != '\0')
104 cupsSetServer(argv
[i
] + 2);
111 _cupsLangPuts(stderr
,
112 _("Error: need hostname after \'-h\' option!\n"));
116 cupsSetServer(argv
[i
]);
120 case 'l' : /* Show long listing */
124 case 'm' : /* Show models */
127 http
= httpConnectEncrypt(cupsServer(), ippPort(),
132 _cupsLangPrintf(stderr
,
133 _("lpinfo: Unable to connect to server: %s\n"),
139 if (show_models(http
, long_status
, device_id
, language
, make_model
,
144 case 'v' : /* Show available devices */
147 http
= httpConnectEncrypt(cupsServer(), ippPort(),
152 _cupsLangPrintf(stderr
,
153 _("lpinfo: Unable to connect to server: %s\n"),
159 if (show_devices(http
, long_status
, timeout
))
163 case '-' : /* --something */
164 if (!strcmp(argv
[i
], "--device-id"))
172 _cupsLangPuts(stderr
,
173 _("lpinfo: Expected 1284 device ID string "
174 "after --device-id!\n"));
178 else if (!strncmp(argv
[i
], "--device-id=", 12) && argv
[i
][12])
180 device_id
= argv
[i
] + 12;
182 else if (!strcmp(argv
[i
], "--language"))
189 _cupsLangPuts(stderr
,
190 _("lpinfo: Expected language after "
195 else if (!strncmp(argv
[i
], "--language=", 11) && argv
[i
][11])
197 language
= argv
[i
] + 11;
199 else if (!strcmp(argv
[i
], "--make-and-model"))
206 _cupsLangPuts(stderr
,
207 _("lpinfo: Expected make and model after "
208 "--make-and-model!\n"));
212 else if (!strncmp(argv
[i
], "--make-and-model=", 17) && argv
[i
][17])
214 make_model
= argv
[i
] + 17;
216 else if (!strcmp(argv
[i
], "--product"))
223 _cupsLangPuts(stderr
,
224 _("lpinfo: Expected product string after "
229 else if (!strncmp(argv
[i
], "--product=", 10) && argv
[i
][10])
231 product
= argv
[i
] + 10;
233 else if (!strcmp(argv
[i
], "--timeout"))
237 timeout
= atoi(argv
[i
]);
240 _cupsLangPuts(stderr
,
241 _("lpinfo: Expected timeout after --timeout!\n"));
245 else if (!strncmp(argv
[i
], "--timeout=", 10) && argv
[i
][10])
247 timeout
= atoi(argv
[i
] + 10);
251 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%s\'!\n"),
258 _cupsLangPrintf(stderr
, _("lpinfo: Unknown option \'%c\'!\n"),
264 _cupsLangPrintf(stderr
, _("lpinfo: Unknown argument \'%s\'!\n"),
274 * 'device_cb()' - Device callback.
279 const char *device_class
, /* I - device-class string */
280 const char *device_id
, /* I - device-id string */
281 const char *device_info
, /* I - device-info string */
282 const char *device_make_and_model
, /* I - device-make-and-model string */
283 const char *device_uri
, /* I - device-uri string */
284 const char *device_location
, /* I - device-location string */
285 void *user_data
) /* I - User data */
287 int *long_status
; /* Show verbose info? */
291 * Display the device...
294 long_status
= (int *)user_data
;
298 _cupsLangPrintf(stdout
,
299 _("Device: uri = %s\n"
302 " make-and-model = %s\n"
305 device_uri
, device_class
, device_info
,
306 device_make_and_model
, device_id
, device_location
);
309 _cupsLangPrintf(stdout
, "%s %s\n", device_class
, device_uri
);
314 * 'show_devices()' - Show available devices.
317 static int /* O - 0 on success, 1 on failure */
318 show_devices(http_t
*http
, /* I - HTTP connection to server */
319 int long_status
, /* I - Long status report? */
320 int timeout
) /* I - Timeout */
322 if (cupsGetDevices(http
, timeout
, CUPS_EXCLUDE_NONE
, device_cb
,
323 &long_status
) != IPP_OK
)
325 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
334 * 'show_models()' - Show available PPDs.
337 static int /* O - 0 on success, 1 on failure */
338 show_models(http_t
*http
, /* I - HTTP connection to server */
339 int long_status
, /* I - Long status report? */
340 const char *device_id
, /* I - 1284 device ID */
341 const char *language
, /* I - Language */
342 const char *make_model
, /* I - Make and model */
343 const char *product
) /* I - Product */
345 ipp_t
*request
, /* IPP Request */
346 *response
; /* IPP Response */
347 ipp_attribute_t
*attr
; /* Current attribute */
348 const char *ppd_device_id
, /* Pointer to ppd-device-id */
349 *ppd_language
, /* Pointer to ppd-natural-language */
350 *ppd_make_model
, /* Pointer to ppd-make-and-model */
351 *ppd_name
; /* Pointer to ppd-name */
358 * Build a CUPS_GET_PPDS request...
361 request
= ippNewRequest(CUPS_GET_PPDS
);
364 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
, "ppd-device-id",
367 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "ppd-language",
370 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
, "ppd-make-and-model",
373 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
, "ppd-product",
377 * Do the request and get back a response...
380 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
383 * Loop through the device list and display them...
386 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
388 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
393 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
396 * Skip leading attributes until we hit a PPD...
399 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
406 * Pull the needed attributes from this PPD...
409 ppd_device_id
= "NONE";
411 ppd_make_model
= NULL
;
414 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
416 if (!strcmp(attr
->name
, "ppd-device-id") &&
417 attr
->value_tag
== IPP_TAG_TEXT
)
418 ppd_device_id
= attr
->values
[0].string
.text
;
419 else if (!strcmp(attr
->name
, "ppd-natural-language") &&
420 attr
->value_tag
== IPP_TAG_LANGUAGE
)
421 ppd_language
= attr
->values
[0].string
.text
;
422 else if (!strcmp(attr
->name
, "ppd-make-and-model") &&
423 attr
->value_tag
== IPP_TAG_TEXT
)
424 ppd_make_model
= attr
->values
[0].string
.text
;
425 else if (!strcmp(attr
->name
, "ppd-name") &&
426 attr
->value_tag
== IPP_TAG_NAME
)
427 ppd_name
= attr
->values
[0].string
.text
;
433 * See if we have everything needed...
436 if (ppd_language
== NULL
|| ppd_make_model
== NULL
|| ppd_name
== NULL
)
445 * Display the device...
450 _cupsLangPrintf(stdout
,
451 _("Model: name = %s\n"
452 " natural_language = %s\n"
453 " make-and-model = %s\n"
454 " device-id = %s\n"),
455 ppd_name
, ppd_language
, ppd_make_model
, ppd_device_id
);
458 _cupsLangPrintf(stdout
, "%s %s\n", ppd_name
, ppd_make_model
);
468 _cupsLangPrintf(stderr
, "lpinfo: %s\n", cupsLastErrorString());
478 * End of "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z mike $".