形式
C
投稿日時
2020-09-01 06:27
公開期間
無期限
  1. /* Any copyright is dedicated to the Public Domain.
  2. * https://creativecommons.org/publicdomain/zero/1.0/ */
  3. /* gcc -lcups cups_test.c -ansi -Wall -Wextra -pedantic -o cups_test */
  4. #include <cups/cups.h>
  5. #include <stdio.h>
  6. static const char *attribs[] = {
  7. "cups-version"
  8. /* Add any further options you want to test here. */
  9. };
  10. #define NUM_ATTRIBS (sizeof(attribs) / sizeof(*attribs))
  11. int main(int argc, char *argv[]){
  12. cups_dest_t *dests;
  13. int num_dests, i, o;
  14. ipp_t *request, *response;
  15. ipp_attribute_t *ipp_attrib;
  16. const char *uri;
  17. (void)argc;
  18. (void)argv;
  19. num_dests = cupsGetDests2(CUPS_HTTP_DEFAULT, &dests);
  20. for(i = 0; i < num_dests; i++){
  21. puts(
  22. "===============================================================================");
  23. fputs("Response from printer: ", stdout);
  24. puts(dests[i].name);
  25. request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
  26. uri = cupsGetOption("printer-uri-supported",
  27. dests[i].num_options,
  28. dests[i].options);
  29. if(!uri){
  30. puts("WARNING: Defaulting to cupsServer for URI");
  31. uri = cupsServer();
  32. }
  33. ippAddString(request,
  34. IPP_TAG_OPERATION,
  35. IPP_TAG_URI,
  36. "printer-uri",
  37. NULL,
  38. uri);
  39. ippAddStrings(request,
  40. IPP_TAG_OPERATION,
  41. IPP_TAG_KEYWORD,
  42. "requested-attributes",
  43. NUM_ATTRIBS,
  44. NULL,
  45. attribs);
  46. /* cupsDoRequest will delete the request ipp_t */
  47. response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
  48. if(cupsLastError() >= IPP_STATUS_ERROR_BAD_REQUEST ||
  49. response == NULL){
  50. fputs("Error in IPP request: ", stdout);
  51. puts(cupsLastErrorString());
  52. }
  53. else{
  54. /* For most attributes there will be only one response.
  55. * Just for completeness though, we can enumerate them all. */
  56. for(ipp_attrib = ippFirstAttribute(response);
  57. ipp_attrib != NULL;
  58. ipp_attrib = ippNextAttribute(response)){
  59. fputs("Beginning ", stdout);
  60. puts(ippGetName(ipp_attrib));
  61. for(o = 0; o < ippGetCount(ipp_attrib); o++){
  62. puts(ippGetString(ipp_attrib, o, NULL));
  63. }
  64. }
  65. ippDelete(response);
  66. }
  67. }
  68. puts(
  69. "===============================================================================");
  70. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト