char * /* O - Name of PPD file or @code NULL@ on error */ cupsGetServerPPD(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ const char *name) /* I - Name of PPD file ("ppd-name") */ { int fd; /* PPD file descriptor */ ipp_t *request; /* IPP request */ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ /* * Range check input... */ if (!name) { _cupsSetError(IPP_INTERNAL_ERROR, _("No PPD name"), 1); return (NULL); } if (!http) if ((http = _cupsConnect()) == NULL) return (NULL); /* * Get a temp file... */ if ((fd = cupsTempFd(cg->ppd_filename, sizeof(cg->ppd_filename))) < 0) { /* * Can't open file; close the server connection and return NULL... */ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0); return (NULL); } /* * Get the PPD file... */ request = ippNewRequest(CUPS_GET_PPD); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name", NULL, name); ippDelete(cupsDoIORequest(http, request, "/", -1, fd)); close(fd); if (cupsLastError() != IPP_OK) { unlink(cg->ppd_filename); return (NULL); } else return (cg->ppd_filename); }
ipp_t * /* O - Response data */ cupsDoRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ ipp_t *request, /* I - IPP request */ const char *resource) /* I - HTTP resource for POST */ { DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")", (void *)http, (void *)request, request ? ippOpString(request->request.op.operation_id) : "?", resource)); return (cupsDoIORequest(http, request, resource, -1, -1)); }
ipp_t * /* O - Response data */ cupsDoFileRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ ipp_t *request, /* I - IPP request */ const char *resource, /* I - HTTP resource for POST */ const char *filename) /* I - File to send or @code NULL@ for none */ { ipp_t *response; /* IPP response data */ int infile; /* Input file */ DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", " "filename=\"%s\")", http, request, request ? ippOpString(request->request.op.operation_id) : "?", resource, filename)); if (filename) { if ((infile = open(filename, O_RDONLY | O_BINARY)) < 0) { /* * Can't get file information! */ _cupsSetError(errno == ENOENT ? IPP_STATUS_ERROR_NOT_FOUND : IPP_STATUS_ERROR_NOT_AUTHORIZED, NULL, 0); ippDelete(request); return (NULL); } } else infile = -1; response = cupsDoIORequest(http, request, resource, infile, -1); if (infile >= 0) close(infile); return (response); }
static void get_job_file(const char *job) /* I - Job ID */ { long jobid, /* Job ID */ docnum; /* Document number */ const char *jobptr; /* Pointer into job ID string */ char uri[1024]; /* job-uri */ http_t *http; /* Connection to server */ ipp_t *request; /* Request data */ int tempfd; /* Temporary file */ /* * Get the job ID and document number, if any... */ if ((jobptr = strrchr(job, '-')) != NULL) jobptr ++; else jobptr = job; jobid = strtol(jobptr, (char **)&jobptr, 10); if (*jobptr == ',') docnum = strtol(jobptr + 1, NULL, 10); else docnum = 1; if (jobid < 1 || jobid > INT_MAX) { _cupsLangPrintf(stderr, _("cupsfilter: Invalid job ID %d."), (int)jobid); exit(1); } if (docnum < 1 || docnum > INT_MAX) { _cupsLangPrintf(stderr, _("cupsfilter: Invalid document number %d."), (int)docnum); exit(1); } /* * Ask the server for the document file... */ if ((http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption())) == NULL) { _cupsLangPrintf(stderr, _("%s: Unable to connect to server."), "cupsfilter"); exit(1); } request = ippNewRequest(CUPS_GET_DOCUMENT); snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", (int)jobid); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "document-number", (int)docnum); if ((tempfd = cupsTempFd(TempFile, sizeof(TempFile))) == -1) { _cupsLangPrintError("ERROR", _("Unable to create temporary file")); httpClose(http); exit(1); } signal(SIGTERM, sighandler); ippDelete(cupsDoIORequest(http, request, "/", -1, tempfd)); close(tempfd); httpClose(http); if (cupsLastError() != IPP_OK) { _cupsLangPrintf(stderr, _("cupsfilter: Unable to get job file - %s"), cupsLastErrorString()); unlink(TempFile); exit(1); } }