ipp_status_t cupsCancelDestJob(http_t *http, /* I - Connection to destination */ cups_dest_t *dest, /* I - Destination */ int job_id) /* I - Job ID */ { cups_dinfo_t *info; /* Destination information */ if ((info = cupsCopyDestInfo(http, dest)) != NULL) { ipp_t *request; /* Cancel-Job request */ request = ippNewRequest(IPP_OP_CANCEL_JOB); ippSetVersion(request, info->version / 10, info->version % 10); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, info->uri); ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", job_id); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser()); ippDelete(cupsDoRequest(http, request, info->resource)); cupsFreeDestInfo(info); } return (cupsLastError()); }
destination_implObj::cups_dinfo_t_wrapper ::cups_dinfo_t_wrapper(http_t *http, cups_dest_t *dest) : info{cupsCopyDestInfo(http, dest)} { if (!info) throw EXCEPTION(libmsg(_("Print destination not available."))); }
GList *dt_get_papers(const dt_printer_info_t *printer) { const char *printer_name = printer->name; GList *result = NULL; #if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 if (cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL && cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL) #endif { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); int cancel = 0; // important char resource[1024]; if (dest) { http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource, sizeof(resource), NULL, (void *)NULL); if (hcon) { cups_size_t size; cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest); const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT); for (int k=0; k<count; k++) { if (cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size)) { if (size.width!=0 && size.length!=0 && !paper_exists(result, size.media)) { pwg_media_t *med = pwgMediaForPWG (size.media); char common_name[MAX_NAME] = { 0 }; if (med->ppd) g_strlcpy(common_name, med->ppd, sizeof(common_name)); else g_strlcpy(common_name, size.media, sizeof(common_name)); dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size.media, sizeof(paper->name)); g_strlcpy(paper->common_name, common_name, sizeof(paper->common_name)); paper->width = (double)size.width / 100.0; paper->height = (double)size.length / 100.0; result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } } } cupsFreeDestInfo(info); httpClose(hcon); } else dt_print(DT_DEBUG_PRINT, "[print] cannot connect to printer %s (cancel=%d)\n", printer_name, cancel); } cupsFreeDests(num_dests, dests); } #endif // check now PPD page sizes const char *PPDFile = cupsGetPPD(printer_name); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppd_size_t *size = ppd->sizes; for (int k=0; k<ppd->num_sizes; k++) { if (size->width!=0 && size->length!=0 && !paper_exists(result, size->name)) { dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size->name, MAX_NAME); g_strlcpy(paper->common_name, size->name, MAX_NAME); paper->width = (double)dt_pdf_point_to_mm(size->width); paper->height = (double)dt_pdf_point_to_mm(size->length); result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } size++; } ppdClose(ppd); g_unlink(PPDFile); } result = g_list_sort_with_data (result, (GCompareDataFunc)sort_papers, NULL); return result; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { http_t *http; /* Connection to destination */ cups_dest_t *dest = NULL; /* Destination */ cups_dinfo_t *dinfo; /* Destination info */ if (argc < 2) usage(NULL); if (!strcmp(argv[1], "--enum")) { int i; /* Looping var */ cups_ptype_t type = 0, /* Printer type filter */ mask = 0; /* Printer type mask */ for (i = 2; i < argc; i ++) { if (!strcmp(argv[i], "grayscale")) { type |= CUPS_PRINTER_BW; mask |= CUPS_PRINTER_BW; } else if (!strcmp(argv[i], "color")) { type |= CUPS_PRINTER_COLOR; mask |= CUPS_PRINTER_COLOR; } else if (!strcmp(argv[i], "duplex")) { type |= CUPS_PRINTER_DUPLEX; mask |= CUPS_PRINTER_DUPLEX; } else if (!strcmp(argv[i], "staple")) { type |= CUPS_PRINTER_STAPLE; mask |= CUPS_PRINTER_STAPLE; } else if (!strcmp(argv[i], "small")) { type |= CUPS_PRINTER_SMALL; mask |= CUPS_PRINTER_SMALL; } else if (!strcmp(argv[i], "medium")) { type |= CUPS_PRINTER_MEDIUM; mask |= CUPS_PRINTER_MEDIUM; } else if (!strcmp(argv[i], "large")) { type |= CUPS_PRINTER_LARGE; mask |= CUPS_PRINTER_LARGE; } else usage(argv[i]); } cupsEnumDests(CUPS_DEST_FLAGS_NONE, 5000, NULL, type, mask, enum_cb, NULL); return (0); } else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7)) dest = cupsGetDestWithURI(NULL, argv[1]); else dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[1], NULL); if (!dest) { printf("testdest: Unable to get destination \"%s\": %s\n", argv[1], cupsLastErrorString()); return (1); } if ((http = cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE, 30000, NULL, NULL, 0, NULL, NULL)) == NULL) { printf("testdest: Unable to connect to destination \"%s\": %s\n", argv[1], cupsLastErrorString()); return (1); } if ((dinfo = cupsCopyDestInfo(http, dest)) == NULL) { printf("testdest: Unable to get information for destination \"%s\": %s\n", argv[1], cupsLastErrorString()); return (1); } if (argc == 2 || (!strcmp(argv[2], "supported") && argc < 6)) { if (argc > 3) show_supported(http, dest, dinfo, argv[3], argv[4]); else if (argc > 2) show_supported(http, dest, dinfo, argv[3], NULL); else show_supported(http, dest, dinfo, NULL, NULL); } else if (!strcmp(argv[2], "conflicts") && argc > 3) { int i, /* Looping var */ num_options = 0;/* Number of options */ cups_option_t *options = NULL;/* Options */ for (i = 3; i < argc; i ++) num_options = cupsParseOptions(argv[i], num_options, &options); show_conflicts(http, dest, dinfo, num_options, options); } else if (!strcmp(argv[2], "default") && argc == 4) { show_default(http, dest, dinfo, argv[3]); } else if (!strcmp(argv[2], "localize") && argc < 6) { if (argc > 3) localize(http, dest, dinfo, argv[3], argv[4]); else if (argc > 2) localize(http, dest, dinfo, argv[3], NULL); else localize(http, dest, dinfo, NULL, NULL); } else if (!strcmp(argv[2], "media")) { int i; /* Looping var */ const char *name = NULL; /* Media name, if any */ unsigned flags = CUPS_MEDIA_FLAGS_DEFAULT; /* Media selection flags */ for (i = 3; i < argc; i ++) { if (!strcmp(argv[i], "borderless")) flags = CUPS_MEDIA_FLAGS_BORDERLESS; else if (!strcmp(argv[i], "duplex")) flags = CUPS_MEDIA_FLAGS_DUPLEX; else if (!strcmp(argv[i], "exact")) flags = CUPS_MEDIA_FLAGS_EXACT; else if (!strcmp(argv[i], "ready")) flags = CUPS_MEDIA_FLAGS_READY; else if (name) usage(argv[i]); else name = argv[i]; } show_media(http, dest, dinfo, flags, name); } else if (!strcmp(argv[2], "print") && argc > 3) { int i, /* Looping var */ num_options = 0;/* Number of options */ cups_option_t *options = NULL;/* Options */ for (i = 4; i < argc; i ++) num_options = cupsParseOptions(argv[i], num_options, &options); print_file(http, dest, dinfo, argv[3], num_options, options); } else usage(argv[2]); return (0); }