papi_status_t ipp_cancel_job(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response) { papi_status_t status; papi_attribute_t **operational = NULL; char *message = NULL; char *queue = NULL; int id = -1; /* Get operational attributes from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* * the operational-attributes-group must contain: * job-uri (or printer-uri/job-id) */ get_printer_id(operational, &queue, &id); if (id < 0) { ipp_set_status(response, PAPI_BAD_REQUEST, "missing job-uri or job-id"); return (PAPI_BAD_REQUEST); } else if (queue == NULL) { ipp_set_status(response, PAPI_BAD_REQUEST, "missing printer-uri or job-uri"); return (PAPI_BAD_REQUEST); } /* * the operational-attributes-group may contain: * message */ (void) papiAttributeListGetString(operational, NULL, "message", &message); status = papiJobCancel(svc, queue, id); if (status != PAPI_OK) { ipp_set_status(response, status, "cancel failed: %s-%d: %s", (queue ? queue : "(null)"), id, ipp_svc_status_mesg(svc, status)); } else if (message != NULL) { /* add unsupported attribute group */ papi_attribute_t **unsupported = NULL; papiAttributeListAddValue(&unsupported, PAPI_ATTR_EXCL, "message", PAPI_COLLECTION, NULL); (void) papiAttributeListAddCollection(response, PAPI_ATTR_REPLACE, "unsupported-attributes-group", unsupported); papiAttributeListFree(unsupported); status = PAPI_OK_SUBST; ipp_set_status(response, status, "unsupported attribute in request"); } return (status); }
papi_status_t ipp_purge_jobs(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response) { papi_status_t status; papi_job_t *jobs = NULL; papi_attribute_t **operational = NULL; char *queue = NULL; /* Get operational attributes from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* * The operational-attributes-group must contain: * printer-uri */ get_printer_id(operational, &queue, NULL); if (queue == NULL) { ipp_set_status(response, status, "printer-uri: %s", papiStatusString(status)); return (PAPI_BAD_REQUEST); } if ((status = papiPrinterPurgeJobs(svc, queue, &jobs)) != PAPI_OK) { ipp_set_status(response, status, "purge failed: %s: %s", (queue ? queue : "(null)"), ipp_svc_status_mesg(svc, status)); } papiJobListFree(jobs); return (status); }
static ipp_handler_t * ipp_operation_handler(papi_attribute_t **request, papi_attribute_t ***response) { int id = 0; int index; papi_attribute_t **ops = NULL; papi_status_t status; char configured = PAPI_FALSE; /* get the operation from the request */ status = papiAttributeListGetInteger(request, NULL, "operation-id", &id); if (status != PAPI_OK) { ipp_set_status(response, PAPI_BAD_ARGUMENT, "no operation specified in request"); return (default_handler); } /* find the operation in the handler table */ index = ipp_operation_id_to_index(id); #ifdef DEBUG if (index == -1) fprintf(stderr, "Operation: 0x%4.4x\n", id); else fprintf(stderr, "Operation: 0x%4.4x(%s)\n", id, handlers[index].name); fflush(stderr); #endif if ((index == -1) || (handlers[index].function == NULL)) { ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED, "operation (0x%4.4x) not implemented by server", id); return (default_handler); } /* find the configured operations */ status = papiAttributeListGetCollection(request, NULL, "operations", &ops); if (status != PAPI_OK) { /* this should not be possible */ ipp_set_status(response, PAPI_INTERNAL_ERROR, "sofware error, no operations configured"); return (default_handler); } /* check if the requested operation is configured */ status = papiAttributeListGetBoolean(ops, NULL, handlers[index].name, &configured); if ((status != PAPI_OK) || (configured != PAPI_TRUE)) { ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED, "operation (%s 0x%4.4x) not enabled on server", handlers[index].name, id); return (default_handler); } return (handlers[index].function); }
static papi_status_t print_service_connect(papi_service_t *svc, papi_attribute_t **request, papi_attribute_t ***response) { papi_status_t status; papi_attribute_t **operational = NULL; char *printer_uri = NULL; char *svc_name = NULL; char *user = NULL; /* Get the operational attributes group from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* get the user name */ (void) papiAttributeListGetString(request, NULL, "default-user", &user); (void) papiAttributeListGetString(operational, NULL, "requesting-user-name", &user); /* get the printer or service name */ (void) papiAttributeListGetString(request, NULL, "default-service", &svc_name); get_printer_id(operational, &svc_name, NULL); status = papiServiceCreate(svc, svc_name, user, NULL, NULL, PAPI_ENCRYPT_NEVER, NULL); if (status != PAPI_OK) { ipp_set_status(response, status, "print service: %s", papiStatusString(status)); return (status); } /* * Trusted Solaris can't be trusting of intermediaries. Pass * the socket connection to the print service to retrieve the * sensativity label off of a multi-level port. */ { int fd = -1; (void) papiAttributeListGetInteger(request, NULL, "peer-socket", &fd); if (fd != -1) papiServiceSetPeer(*svc, fd); } return (status); }
/* * When the PAPI supports papiJobCreate(), papiJobStreamAdd() and * papiJobClose(), this will be much cleaner and more efficient, but in the * meantime, we are using a private, non-standard interface to do this. */ papi_status_t ipp_send_document(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response, ipp_reader_t iread, void *fd) { papi_status_t status; papi_stream_t s = NULL; papi_job_t j = NULL; papi_attribute_t **operational = NULL; papi_attribute_t **job_attributes = NULL; char *queue = NULL; ssize_t rc; int id = -1; char buf[BUFSIZ]; char last = PAPI_FALSE; char *keys[] = { "attributes-natural-language", "attributes-charset", "printer-uri", "job-id", "job-uri", "last-document", NULL }; /* Get operational attributes from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* * the operational-attributes-group must contain: * job-uri (or printer-uri/job-id) * last-document */ get_printer_id(operational, &queue, &id); if (id < 0) { ipp_set_status(response, PAPI_BAD_REQUEST, "missing job-uri or job-id"); return (PAPI_BAD_REQUEST); } else if (queue == NULL) { ipp_set_status(response, PAPI_BAD_REQUEST, "missing printer-uri or job-uri"); return (PAPI_BAD_REQUEST); } status = papiAttributeListGetBoolean(operational, NULL, "last-document", &last); if (status != PAPI_OK) { ipp_set_status(response, status, "last-document: %s", papiStatusString(status)); return (PAPI_BAD_REQUEST); } /* * the operational-attributes-group may contain: * document-name * compression * document-format * document-natural-language * Simply copy the entire contents of the operational-attributes-group * for the PAPI call's possible use. */ split_and_copy_attributes(keys, operational, NULL, &job_attributes); /* copy any job-attributes-group attributes for the PAPI call */ if (papiAttributeListGetCollection(request, NULL, "job-attributes-group", &operational) == PAPI_OK) copy_attributes(&job_attributes, operational); /* create a stream to write the document data on */ status = papiJobStreamAdd(svc, queue, id, &s); papiAttributeListFree(job_attributes); if (status != PAPI_OK) { ipp_set_status(response, status, "job submission: %s", ipp_svc_status_mesg(svc, status)); return (status); } /* copy the document data from the IPP connection to the stream */ while ((status == PAPI_OK) && ((rc = iread(fd, buf, sizeof (buf))) > 0)) status = papiJobStreamWrite(svc, s, buf, rc); if (status != PAPI_OK) { ipp_set_status(response, status, "write job data: %s", ipp_svc_status_mesg(svc, status)); return (status); } /* close the stream */ status = papiJobStreamClose(svc, s, &j); if (status != PAPI_OK) { ipp_set_status(response, status, "close job stream: %s", ipp_svc_status_mesg(svc, status)); papiJobFree(j); /* we shouldn't have a job, but just in case */ return (status); } /* if it's the last document, commit the job */ if (last == PAPI_TRUE) { status = papiJobCommit(svc, queue, id); } /* add the job attributes to the response in a job-attributes-group */ if (j != NULL) { papi_to_ipp_job_group(response, request, PAPI_ATTR_REPLACE, j); papiJobFree(j); } return (status); }
papi_status_t ipp_validate_job(papi_service_t svc, papi_attribute_t **request, papi_attribute_t ***response, ipp_reader_t iread, void *fd) { papi_status_t status; papi_job_t j = NULL; papi_attribute_t **operational = NULL; papi_attribute_t **job_attributes = NULL; char *queue = NULL; char *files[] = { "/etc/syslog.conf", NULL }; ssize_t rc; char buf[BUFSIZ]; char *keys[] = { "attributes-natural-language", "attributes-charset", "printer-uri", NULL }; /* Get operational attributes from the request */ (void) papiAttributeListGetCollection(request, NULL, "operational-attributes-group", &operational); /* * The operational-attributes-group must contain: * printer-uri */ get_printer_id(operational, &queue, NULL); if (queue == NULL) { ipp_set_status(response, status, "printer-uri: %s", papiStatusString(status)); return (PAPI_BAD_REQUEST); } /* * The operational-attributes-group may contain: * job-name * ipp-attribute-fidelity * document-name * compression * document-format * document-natural-language * job-k-octets * job-impressions * job-media-sheets * Simply copy the entire contents of the operational-attributes-group * for the PAPI call's possible use. */ split_and_copy_attributes(keys, operational, NULL, &job_attributes); /* copy any job-attributes-group attributes for the PAPI call */ if (papiAttributeListGetCollection(request, NULL, "job-attributes-group", &operational) == PAPI_OK) copy_attributes(&job_attributes, operational); /* request job validation */ status = papiJobValidate(svc, queue, job_attributes, NULL, files, &j); papiAttributeListFree(job_attributes); if (status != PAPI_OK) { ipp_set_status(response, status, "validating job: %s", ipp_svc_status_mesg(svc, status)); papiJobFree(j); /* we shouldn't have a job, but just in case */ return (status); } /* add the job attributes to the response in a job-attributes-group */ if (j != NULL) { papi_to_ipp_job_group(response, request, PAPI_ATTR_REPLACE, j); papiJobFree(j); } return (status); }