Lines Matching +full:data +full:- +full:uri +full:- +full:to +full:- +full:buffer
4 * Copyright © 2017-2019 by Apple Inc.
19 #include <cups/string-private.h>
20 #include <cups/thread-private.h>
36 const char *uri, /* Printer URI */ member
48 /* Current printer-state-reasons */
52 /* Current job-state-reasons */
70 static void *monitor_printer(_client_data_t *data);
71 static void *run_client(_client_data_t *data);
78 * 'main()' - Main entry.
81 int /* O - Exit status */
82 main(int argc, /* I - Number of command-line arguments */ in main()
83 char *argv[]) /* I - Command-line arguments */ in main()
87 int num_clients = 0,/* Number of clients to simulate */ in main()
90 char scheme[32], /* URI scheme */ in main()
94 _client_data_t data; /* Client data */ in main() local
98 * Parse command-line options... in main()
104 memset(&data, 0, sizeof(data)); in main()
108 if (argv[i][0] == '-') in main()
114 case 'c' : /* -c num-clients */ in main()
125 puts("Expected client count after '-c'."); in main()
138 case 'd' : /* -d document-format */ in main()
139 if (data.docformat) in main()
149 puts("Expected document format after '-d'."); in main()
154 data.docformat = argv[i]; in main()
157 case 'f' : /* -f print-file */ in main()
158 if (data.docfile) in main()
168 puts("Expected print file after '-f'."); in main()
173 data.docfile = argv[i]; in main()
177 data.grayscale = 1; in main()
181 data.keepfile = 1; in main()
189 printf("Unknown option '-%c'.\n", *opt); in main()
195 else if (data.uri || (strncmp(argv[i], "ipp://", 6) && strncmp(argv[i], "ipps://", 7))) in main()
197 printf("Unknown command-line argument '%s'.\n", argv[i]); in main()
202 data.uri = argv[i]; in main()
209 if (!data.uri) in main()
211 puts("Expected printer URI."); in main()
220 * Connect to the printer... in main()
223 …rateURI(HTTP_URI_CODING_ALL, data.uri, scheme, sizeof(scheme), userpass, sizeof(userpass), hostnam… in main()
225 printf("Bad printer URI '%s'.\n", data.uri); in main()
229 if (!data.port) in main()
230 data.port = IPP_PORT; in main()
233 data.encryption = HTTP_ENCRYPTION_ALWAYS; in main()
235 data.encryption = HTTP_ENCRYPTION_IF_REQUESTED; in main()
241 data.hostname = hostname; in main()
242 data.resource = resource; in main()
253 tid = _cupsThreadCreate((_cups_thread_func_t)run_client, &data); in main()
276 * 'make_raster_file()' - Create a temporary raster file.
279 static const char * /* O - Print filename */
280 make_raster_file(ipp_t *response, /* I - Printer attributes */ in make_raster_file()
281 int grayscale, /* I - Force grayscale? */ in make_raster_file()
282 char *tempname, /* I - Temporary filename buffer */ in make_raster_file()
283 size_t tempsize, /* I - Size of temp file buffer */ in make_raster_file()
284 const char **format) /* O - Print format */ in make_raster_file()
297 unsigned char *line, /* Line of raster data */ in make_raster_file()
331 …"C U U PPPP SSS ----- T EEEE SSS T 0 0 0 1 22 333 … in make_raster_file()
343 if ((attr = ippFindAttribute(response, "document-format-supported", IPP_TAG_MIMETYPE)) == NULL) in make_raster_file()
353 printf("Printer does not support document-format '%s'.\n", *format); in make_raster_file()
359 else if (!strcmp(*format, "image/pwg-raster")) in make_raster_file()
363 printf("Unable to generate document-format '%s'.\n", *format); in make_raster_file()
376 else if (ippContainsString(attr, "image/pwg-raster")) in make_raster_file()
382 *format = "image/pwg-raster"; in make_raster_file()
399 if ((attr = ippFindAttribute(response, "media-ready", IPP_TAG_KEYWORD)) != NULL) in make_raster_file()
412 else if ((attr = ippFindAttribute(response, "media-default", IPP_TAG_KEYWORD)) != NULL) in make_raster_file()
426 …if (mode == CUPS_RASTER_WRITE_APPLE && (attr = ippFindAttribute(response, "urf-supported", IPP_TAG… in make_raster_file()
440 …PS_RASTER_WRITE_PWG && (attr = ippFindAttribute(response, "pwg-raster-document-resolution-supporte… in make_raster_file()
456 …if ((attr = ippFindAttribute(response, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD)) != … in make_raster_file()
481 if (!cupsRasterInitPWGHeader(&header, media, type, xdpi, ydpi, "one-sided", NULL)) in make_raster_file()
483 printf("Unable to initialize raster context: %s\n", cupsRasterErrorString()); in make_raster_file()
500 xrep = (header.cupsWidth - 2 * xoff) / 140; in make_raster_file()
502 yend = header.cupsHeight - yoff; in make_raster_file()
510 …printf("Unable to allocate %u bytes for raster output: %s\n", header.cupsBytesPerLine, strerror(er… in make_raster_file()
516 printf("Unable to create temporary print file: %s\n", strerror(errno)); in make_raster_file()
523 printf("Unable to open raster stream: %s\n", cupsRasterErrorString()); in make_raster_file()
568 for (xcount = xrep; xcount > 0; xcount --) in make_raster_file()
587 for (xcount = xrep; xcount > 0; xcount --, lineptr += 3) in make_raster_file()
597 for (ycount = yrep; ycount > 0 && y < yend; ycount --, y ++) in make_raster_file()
619 * 'monitor_printer()' - Monitor the job and printer states.
622 static void * /* O - Thread exit code */
624 _client_data_t *data) /* I - Client data */ in monitor_printer() argument
626 http_t *http; /* Connection to printer */ in monitor_printer()
637 "job-state", in monitor_printer()
638 "job-state-reasons" in monitor_printer()
642 "printer-state", in monitor_printer()
643 "printer-state-reasons" in monitor_printer()
648 * Open a connection to the printer... in monitor_printer()
651 http = httpConnect2(data->hostname, data->port, NULL, AF_UNSPEC, data->encryption, 1, 0, NULL); in monitor_printer()
663 while (data->job_state < IPP_JSTATE_CANCELED) in monitor_printer()
666 * Reconnect to the printer as needed... in monitor_printer()
679 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, data->uri); in monitor_printer()
680 … ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in monitor_printer()
681 …ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(pa… in monitor_printer()
683 response = cupsDoRequest(http, request, data->resource); in monitor_printer()
685 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) in monitor_printer()
688 if ((attr = ippFindAttribute(response, "printer-state-reasons", IPP_TAG_KEYWORD)) != NULL) in monitor_printer()
691 …if (printer_state != data->printer_state || strcmp(printer_state_reasons, data->printer_state_reas… in monitor_printer()
693 …printf("PRINTER: %s (%s)\n", ippEnumString("printer-state", (int)printer_state), printer_state_rea… in monitor_printer()
695 data->printer_state = printer_state; in monitor_printer()
696 … strlcpy(data->printer_state_reasons, printer_state_reasons, sizeof(data->printer_state_reasons)); in monitor_printer()
701 if (data->job_id > 0) in monitor_printer()
708 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, data->uri); in monitor_printer()
709 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", data->job_id); in monitor_printer()
710 … ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in monitor_printer()
711 …ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(ja… in monitor_printer()
713 response = cupsDoRequest(http, request, data->resource); in monitor_printer()
715 if ((attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM)) != NULL) in monitor_printer()
718 if ((attr = ippFindAttribute(response, "job-state-reasons", IPP_TAG_KEYWORD)) != NULL) in monitor_printer()
721 if (job_state != data->job_state || strcmp(job_state_reasons, data->job_state_reasons)) in monitor_printer()
723 …printf("JOB %d: %s (%s)\n", data->job_id, ippEnumString("job-state", (int)job_state), job_state_re… in monitor_printer()
725 data->job_state = job_state; in monitor_printer()
726 strlcpy(data->job_state_reasons, job_state_reasons, sizeof(data->job_state_reasons)); in monitor_printer()
733 if (data->job_state < IPP_JSTATE_CANCELED) in monitor_printer()
749 printf("FINISHED MONITORING JOB %d\n", data->job_id); in monitor_printer()
756 * 'run_client()' - Run a client thread.
759 static void * /* O - Thread exit code */
761 _client_data_t *data) /* I - Client data */ in run_client() argument
766 _client_data_t ldata; /* Local client data */ in run_client()
767 http_t *http; /* Connection to printer */ in run_client()
774 "media-col-database" in run_client()
778 ldata = *data; in run_client()
787 * Open a connection to the printer... in run_client()
790 http = httpConnect2(data->hostname, data->port, NULL, AF_UNSPEC, data->encryption, 1, 0, NULL); in run_client()
797 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, ldata.uri); in run_client()
798 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in run_client()
799 …ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(pa… in run_client()
830 ldata.docformat = "image/pwg-raster"; in run_client()
834 ldata.docformat = "application/octet-stream"; in run_client()
839 * Tell the printer to auto-detect... in run_client()
842 ldata.docformat = "application/octet-stream"; in run_client()
848 * No file specified, make something to test with... in run_client()
862 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, ldata.uri); in run_client()
863 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in run_client()
870 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL, name); in run_client()
873 show_attributes("Create-Job request", 1, request); in run_client()
878 show_attributes("Create-Job response", 0, response); in run_client()
882 printf("Unable to create print job: %s\n", cupsLastErrorString()); in run_client()
889 if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) == NULL) in run_client()
891 puts("No job-id returned in Create-Job request."); in run_client()
905 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, ldata.uri); in run_client()
906 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", ldata.job_id); in run_client()
907 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); in run_client()
908 …ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, ldata.docforma… in run_client()
909 ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1); in run_client()
912 show_attributes("Send-Document request", 1, request); in run_client()
917 show_attributes("Send-Document response", 0, response); in run_client()
921 printf("Unable to print file: %s\n", cupsLastErrorString()); in run_client()
928 puts("WAITING FOR JOB TO COMPLETE"); in run_client()
947 client_count --; in run_client()
955 * 'show_attributes()' - Show attributes in a request or response.
959 show_attributes(const char *title, /* I - Title */ in show_attributes()
960 int request, /* I - 1 for request, 0 for response */ in show_attributes()
961 ipp_t *ipp) /* I - IPP request/response */ in show_attributes()
969 char buffer[1024]; /* Value */ in show_attributes() local
974 printf(" request-id=%d\n", ippGetRequestId(ipp)); in show_attributes()
976 printf(" status-code=%s\n", ippErrorString(ippGetStatusCode(ipp))); in show_attributes()
989 ippAttributeString(attr, buffer, sizeof(buffer)); in show_attributes()
990 …)=%s\n", name, ippGetCount(attr) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr)), buffer); in show_attributes()
997 * 'show_capabilities()' - Show printer capabilities.
1001 show_capabilities(ipp_t *response) /* I - Printer attributes */ in show_capabilities()
1005 char buffer[1024]; /* Attribute value buffer */ in show_capabilities() local
1006 static const char * const pattrs[] = /* Attributes we want to show */ in show_capabilities()
1008 "copies-default", in show_capabilities()
1009 "copies-supported", in show_capabilities()
1010 "finishings-default", in show_capabilities()
1011 "finishings-ready", in show_capabilities()
1012 "finishings-supported", in show_capabilities()
1013 "media-default", in show_capabilities()
1014 "media-ready", in show_capabilities()
1015 "media-supported", in show_capabilities()
1016 "output-bin-default", in show_capabilities()
1017 "output-bin-supported", in show_capabilities()
1018 "print-color-mode-default", in show_capabilities()
1019 "print-color-mode-supported", in show_capabilities()
1020 "sides-default", in show_capabilities()
1021 "sides-supported", in show_capabilities()
1022 "document-format-default", in show_capabilities()
1023 "document-format-supported", in show_capabilities()
1024 "pwg-raster-document-resolution-supported", in show_capabilities()
1025 "pwg-raster-document-type-supported", in show_capabilities()
1026 "urf-supported" in show_capabilities()
1035 ippAttributeString(attr, buffer, sizeof(buffer)); in show_capabilities()
1036 printf(" %s=%s\n", pattrs[i], buffer); in show_capabilities()
1043 * 'usage()' - Show program usage...
1049 puts("Usage: ./testclient printer-uri [options]"); in usage()
1051 puts(" -c num-clients Simulate multiple clients"); in usage()
1052 puts(" -d document-format Generate the specified format"); in usage()
1053 puts(" -f print-file Print the named file"); in usage()
1054 puts(" -g Force grayscale printing"); in usage()
1055 puts(" -k Keep temporary files"); in usage()
1056 puts(" -v Be more verbose"); in usage()