papi_status_t class_status_to_attributes(printer_t *p, char *printer, short status, char *reject_reason, long reject_date) { if (p == NULL) return (PAPI_BAD_ARGUMENT); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-reject-reason", reject_reason); papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-reject-date", reject_date); /* add the current system time */ papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, "printer-current-time", time(NULL)); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "printer-up-time", time(NULL)); /* add the status information */ lpsched_printer_status_to_attributes(&p->attributes, status); papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, "printer-state-reasons", "none"); lpsched_printer_defaults(&p->attributes); return (PAPI_OK); }
papi_status_t papiServiceSetEncryption(papi_service_t handle, papi_encryption_t encryption) { service_t *svc = handle; if (svc == NULL) return (PAPI_BAD_ARGUMENT); return (papiAttributeListAddInteger(&svc->attributes, PAPI_ATTR_REPLACE, "encryption", (int)encryption)); }
static papi_status_t ipp_initialize_response(papi_attribute_t **request, papi_attribute_t ***response) { papi_attribute_t **operational = NULL; int i; if ((request == NULL) || (response == NULL)) return (PAPI_BAD_ARGUMENT); /* If the response was initialized, start over */ if (*response != NULL) { papiAttributeListFree(*response); *response = NULL; } /* Add the basic ipp header information to the response */ (void) papiAttributeListGetInteger(request, NULL, "version-major", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "version-major", i); (void) papiAttributeListGetInteger(request, NULL, "version-minor", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "version-minor", i); (void) papiAttributeListGetInteger(request, NULL, "request-id", &i); (void) papiAttributeListAddInteger(response, PAPI_ATTR_REPLACE, "request-id", i); /* Add a default operational attributes group to the response */ (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL, "attributes-charset", "utf-8"); (void) papiAttributeListAddString(&operational, PAPI_ATTR_EXCL, "attributes-natural-language", "en-us"); (void) papiAttributeListAddCollection(response, PAPI_ATTR_REPLACE, "operational-attributes-group", operational); papiAttributeListFree(operational); return (PAPI_OK); }
void lpsched_printer_status_to_attributes(papi_attribute_t ***attrs, unsigned short status) { if (attrs == NULL) return; if (status & (PS_DISABLED|PS_LATER|PS_FAULTED|PS_FORM_FAULT)) { papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, "printer-state", 0x05); /* stopped */ if (status & PS_LATER) papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, "printer-state-reasons", "moving-to-paused"); else if (status & PS_FAULTED) papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, "printer-state-reasons", "none"); else if (status & PS_FORM_FAULT) papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, "printer-state-reasons", "interpreter-resource-unavailable"); else papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, "printer-state-reasons", "paused"); } else if (status & PS_BUSY) { papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, "printer-state", 0x04); /* processing */ papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, "printer-state-reasons", "moving-to-paused"); } else { papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, "printer-state", 0x03); /* idle */ } papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, "printer-is-accepting-jobs", ((status & PS_REJECTED) != PS_REJECTED)); papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, "printer-is-processing-jobs", ((status & PS_DISABLED) != PS_DISABLED)); }
void lpsched_printer_defaults(papi_attribute_t ***attributes) { if (attributes == NULL) return; papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE, "multiple-document-jobs-supported", PAPI_TRUE); papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, "multiple-document-handling-supported", "seperate-documents-colated-copies"); papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, "pdl-override-supported", "not-attempted"); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, "job-priority-supported", 40); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, "job-priority-default", 20); papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE, "copies-supported", 1, 65535); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, "copies-default", 1); papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE, "page-ranges-supported", PAPI_TRUE); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, "number-up-supported", 1); papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, "number-up-default", 1); papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, "job-hold-until-supported", "no-hold"); papiAttributeListAddString(attributes, PAPI_ATTR_APPEND, "job-hold-until-supported", "indefinite"); papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, "job-hold-until-default", "no-hold"); papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, "document-format-default", "application/octet-stream"); }
papi_status_t ipp_process_request(papi_attribute_t **request, papi_attribute_t ***response, ipp_reader_t iread, void *fd) { papi_status_t result = PAPI_OK; ipp_initialize_response(request, response); #ifdef DEBUG fprintf(stderr, "REQUEST:"); papiAttributeListPrint(stderr, request, " %d ", getpid()); fprintf(stderr, "\n"); #endif /* verify that the request is "well-formed" */ if ((result = ipp_validate_request(request, response)) == PAPI_OK) { papi_service_t svc = NULL; ipp_handler_t *handler; result = print_service_connect(&svc, request, response); handler = ipp_operation_handler(request, response); /* process the request */ if ((result == PAPI_OK) && (handler != NULL)) result = (handler)(svc, request, response, iread, fd); #ifdef DEBUG fprintf(stderr, "RESULT: %s\n", papiStatusString(result)); #endif papiServiceDestroy(svc); } (void) papiAttributeListAddInteger(response, PAPI_ATTR_EXCL, "status-code", result); massage_response(request, *response); #ifdef DEBUG fprintf(stderr, "RESPONSE:"); papiAttributeListPrint(stderr, *response, " %d ", getpid()); fprintf(stderr, "\n"); #endif return (result); }
papi_status_t printer_status_to_attributes(printer_t *p, char *printer, char *form, char *character_set, char *disable_reason, char *reject_reason, short status, char *request_id, long disable_date, long reject_date) { if (p == NULL) return (PAPI_BAD_ARGUMENT); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "form-ready", form); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-active-job", request_id); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-mounted-char-set", character_set); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-disable-reason", disable_reason); papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-disable-date", disable_date); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-reject-reason", reject_reason); papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-reject-date", reject_date); /* add the current system time */ papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, "printer-current-time", time(NULL)); /* add the time since last enabled */ papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "printer-up-time", time(NULL)); /* add the status information */ lpsched_printer_status_to_attributes(&p->attributes, status); papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, "printer-state-reasons", "none"); lpsched_printer_defaults(&p->attributes); return (PAPI_OK); }
papi_status_t papiJobStreamClose(papi_service_t handle, papi_stream_t stream, papi_job_t *job) { papi_status_t status = PAPI_OK; service_t *svc = handle; job_stream_t *s = stream; job_t *j = NULL; char *tmp = NULL, *c; if ((svc == NULL) || (stream == NULL) || (job == NULL)) return (PAPI_BAD_ARGUMENT); if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); close(s->fd); lpsched_request_to_job_attributes(s->request, j); if (s->meta_data_file != NULL) { status = lpsched_commit_job(svc, s->meta_data_file, &tmp); if (status != PAPI_OK) { unlink(s->meta_data_file); return (status); } if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, "job-uri", tmp); free(s->meta_data_file); } freerequest(s->request); free(s); return (PAPI_OK); }
void ipp_operations_supported(papi_attribute_t ***list, papi_attribute_t **request) { papi_attribute_t **group = NULL; (void) papiAttributeListGetCollection(request, NULL, "operations", &group); if (group != NULL) { int i; for (i = 0; handlers[i].name != NULL; i++) { char boolean = PAPI_FALSE; (void) papiAttributeListGetBoolean(group, NULL, handlers[i].name, &boolean); if (boolean == PAPI_TRUE) (void) papiAttributeListAddInteger(list, PAPI_ATTR_APPEND, "operations-supported", handlers[i].id); } } }
papi_status_t papiJobCreate(papi_service_t handle, char *printer, papi_attribute_t **job_attributes, papi_job_ticket_t *job_ticket, papi_job_t *job) { papi_status_t status; service_t *svc = handle; job_t *j = NULL; REQUEST *request; char *request_id = NULL; char *c; char *tmp = NULL; char metadata_file[MAXPATHLEN]; if ((svc == NULL) || (printer == NULL) || (job == NULL)) return (PAPI_BAD_ARGUMENT); if (job_ticket != NULL) return (PAPI_JOB_TICKET_NOT_SUPPORTED); if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); /* 1 for the control file (-0) */ status = lpsched_alloc_files(svc, 1, &request_id); if (status != PAPI_OK) return (status); /* convert the attributes to an lpsched REQUEST structure */ request = create_request(svc, (char *)printer, (papi_attribute_t **)job_attributes); if (request == NULL) return (PAPI_TEMPORARY_ERROR); addlist(&request->file_list, DUMMY_FILE); /* add a dummy file */ request->actions |= ACT_HOLD; /* hold the job */ #ifdef LP_USE_PAPI_ATTR /* * store the job attributes in the PAPI job attribute file that was * created by lpsched_alloc_files(), the attributes will then pass * through lpsched and be given to the slow-filters and the printer's * interface script to process them */ snprintf(metadata_file, sizeof (metadata_file), "%s%s-%s", "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, metadata_file); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", metadata_file, strerror(errno)); free(request_id); return (PAPI_DEVICE_ERROR); } #endif /* store the REQUEST on disk */ snprintf(metadata_file, sizeof (metadata_file), "%s-0", request_id); free(request_id); if (putrequest(metadata_file, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), metadata_file, strerror(errno)); return (PAPI_DEVICE_ERROR); } status = lpsched_commit_job(svc, metadata_file, &tmp); if (status != PAPI_OK) { unlink(metadata_file); return (status); } lpsched_request_to_job_attributes(request, j); if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, "job-uri", tmp); return (PAPI_OK); }
papi_status_t papiJobModify(papi_service_t handle, char *printer, int32_t job_id, papi_attribute_t **attributes, papi_job_t *job) { papi_status_t status; job_t *j = NULL; service_t *svc = handle; char *file = NULL; char *dest; REQUEST *r = NULL; char lpfile[BUFSIZ]; if ((svc == NULL) || (printer == NULL) || (job_id < 0) || (attributes == NULL)) return (PAPI_BAD_ARGUMENT); if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); dest = printer_name_from_uri_id(printer, job_id); status = lpsched_start_change(svc, dest, job_id, &file); if (status != PAPI_OK) return (status); if ((r = getrequest(file)) != NULL) { job_attributes_to_lpsched_request(handle, r, (papi_attribute_t **)attributes); #ifdef LP_USE_PAPI_ATTR /* * store the job attributes in the PAPI job attribute file * that was created by the origonal job request. We need to * modify the attributes in the file as per the new attributes */ snprintf(lpfile, sizeof (lpfile), "%s%d-%s", "/var/spool/lp/temp/", job_id, LP_PAPIATTRNAME); status = psm_modifyAttrsFile(attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to modify the attributes file: %s: %s", lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif if (putrequest(file, r) < 0) { detailed_error(svc, gettext("failed to write job: %s: %s"), file, strerror(errno)); freerequest(r); return (PAPI_DEVICE_ERROR); } } else { detailed_error(svc, gettext("failed to read job: %s: %s"), file, strerror(errno)); return (PAPI_DEVICE_ERROR); } status = lpsched_end_change(svc, dest, job_id); lpsched_request_to_job_attributes(r, j); papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, "job-id", job_id); freerequest(r); return (status); }
papi_status_t papiJobSubmit(papi_service_t handle, char *printer, papi_attribute_t **job_attributes, papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { papi_status_t status; service_t *svc = handle; job_t *j; int file_no; char *request_id = NULL; REQUEST *request; int i; char *c; char *tmp = NULL; char lpfile[BUFSIZ]; if ((svc == NULL) || (printer == NULL) || (files == NULL) || (job == NULL)) return (PAPI_BAD_ARGUMENT); if (job_ticket != NULL) return (PAPI_OPERATION_NOT_SUPPORTED); if (files != NULL) for (file_no = 0; files[file_no] != NULL; file_no++) if (access(files[file_no], R_OK) < 0) { detailed_error(svc, gettext("Cannot access file: %s: %s"), files[file_no], strerror(errno)); return (PAPI_BAD_ARGUMENT); } if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); /* file_no + 1 for the control file (-0) */ status = lpsched_alloc_files(svc, file_no + 1, &request_id); if (status != PAPI_OK) return (status); request = create_request(svc, (char *)printer, (papi_attribute_t **)job_attributes); for (i = 0; files[i] != NULL; i++) { papi_status_t status; snprintf(lpfile, sizeof (lpfile), "%s%s-%d", "/var/spool/lp/temp/", request_id, i+1); status = copy_file(files[i], lpfile); if (status != PAPI_OK) { detailed_error(svc, gettext("unable to copy: %s -> %s: %s"), files[i], lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } addlist(&(request->file_list), lpfile); } #ifdef LP_USE_PAPI_ATTR /* * store the job attributes in the PAPI job attribute file that was * created by lpsched_alloc_files(), the attributes will then pass * through lpsched and be given to the slow-filters and the printer's * interface script to process them */ snprintf(lpfile, sizeof (lpfile), "%s%s-%s", "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif /* store the meta-data file */ snprintf(lpfile, sizeof (lpfile), "%s-0", request_id); if (putrequest(lpfile, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } status = lpsched_commit_job(svc, lpfile, &tmp); if (status != PAPI_OK) { unlink(lpfile); freerequest(request); return (status); } lpsched_request_to_job_attributes(request, j); freerequest(request); if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, "job-uri", tmp); return (PAPI_OK); }
static int ipp_handler(request_rec *r) { papi_attribute_t **request = NULL, **response = NULL; IPPListenerConfig *config; papi_status_t status; int ret; /* Really, IPP is all POST requests */ if (r->method_number != M_POST) return (DECLINED); #ifndef APACHE2 /* * An IPP request must have a MIME type of "application/ipp" * (RFC-2910, Section 4, page 19). If it doesn't match this * MIME type, we should decline the request and let someone else * try and handle it. */ if (r->headers_in != NULL) { char *mime_type = (char *)ap_table_get(r->headers_in, "Content-Type"); if ((mime_type == NULL) || (strcasecmp(mime_type, "application/ipp") != 0)) return (DECLINED); } #endif /* CHUNKED_DECHUNK might not work right for IPP? */ if ((ret = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) != OK) return (ret); if (!ap_should_client_block(r)) return (HTTP_INTERNAL_SERVER_ERROR); #ifndef APACHE2 ap_soft_timeout("ipp_module: read/reply request ", r); #endif /* read the IPP request off the network */ status = ipp_read_message(read_data, r, &request, IPP_TYPE_REQUEST); if (status != PAPI_OK) _log_rerror(APLOG_MARK, APLOG_ERR, r, "read failed: %s\n", papiStatusString(status)); #ifdef DEBUG papiAttributeListPrint(stderr, request, "request (%d) ", getpid()); #endif (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL, "originating-host", (char *) #ifdef APACHE2 ap_get_remote_host (r->connection, r->per_dir_config, REMOTE_NAME, NULL)); #else ap_get_remote_host (r->connection, r->per_dir_config, REMOTE_NAME)); #endif (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL, "uri-port", ap_get_server_port(r)); if (r->headers_in != NULL) { char *host = (char *)ap_table_get(r->headers_in, "Host"); if ((host == NULL) || (host[0] == '\0')) host = (char *)ap_get_server_name(r); (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL, "uri-host", host); } (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL, "uri-path", r->uri); config = ap_get_module_config(r->per_dir_config, &ipp_module); if (config != NULL) { (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL, "conformance", config->conformance); (void) papiAttributeListAddCollection(&request, PAPI_ATTR_EXCL, "operations", config->operations); if (config->default_user != NULL) (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL, "default-user", config->default_user); if (config->default_svc != NULL) (void) papiAttributeListAddString(&request, PAPI_ATTR_EXCL, "default-service", config->default_svc); } /* * For Trusted Solaris, pass the fd number of the socket connection * to the backend so the it can be forwarded to the backend print * service to retrieve the sensativity label off of a multi-level * port. */ (void) papiAttributeListAddInteger(&request, PAPI_ATTR_EXCL, "peer-socket", ap_bfileno(r->connection->client, B_RD)); /* process the request */ status = ipp_process_request(request, &response, read_data, r); if (status != PAPI_OK) { errno = 0; _log_rerror(APLOG_MARK, APLOG_ERR, r, "request failed: %s\n", papiStatusString(status)); discard_data(r); } #ifdef DEBUG fprintf(stderr, "processing result: %s\n", papiStatusString(status)); papiAttributeListPrint(stderr, response, "response (%d) ", getpid()); #endif /* * If the client is using chunking and we have not yet received the * final "0" sized chunk, we need to discard any data that may * remain in the post request. */ if ((r->read_chunked != 0) && (ap_table_get(r->headers_in, "Content-Length") == NULL)) discard_data(r); /* write an IPP response back to the network */ r->content_type = "application/ipp"; #ifndef APACHE2 ap_send_http_header(r); #endif status = ipp_write_message(write_data, r, response); if (status != PAPI_OK) _log_rerror(APLOG_MARK, APLOG_ERR, r, "write failed: %s\n", papiStatusString(status)); #ifdef DEBUG fprintf(stderr, "write result: %s\n", papiStatusString(status)); fflush(stderr); #endif papiAttributeListFree(request); papiAttributeListFree(response); #ifndef APACHE2 ap_kill_timeout(r); if (ap_rflush(r) < 0) _log_rerror(APLOG_MARK, APLOG_ERR, r, "flush failed, response may not have been sent"); #endif return (OK); }
static gint gp_transport_papi_construct (GnomePrintTransport *gp_transport) { GPTransportPAPI *transport; char *value; long valint; papi_status_t status; papi_service_t service = NULL; papi_attribute_t **attributes = NULL; transport = GP_TRANSPORT_PAPI (gp_transport); /* gnome_print_config_dump (gp_transport->config); */ /* FIXME: this used to be Settings.Transport.Backend.Printer */ value = (char *)gnome_print_config_get (gp_transport->config, (unsigned char *)"Printer"); if (!value) { g_warning ("Could not find \"Settings.Transport.Backend.Printer\""); return GNOME_PRINT_ERROR_UNKNOWN; } transport->printer = value; status = papiServiceCreate (&service, transport->printer, NULL, NULL, NULL, PAPI_ENCRYPT_NEVER, NULL); if (status != PAPI_OK) { g_warning ("Could not create PAPI service"); return GNOME_PRINT_ERROR_UNKNOWN; } transport->service = service; value = (char *)gnome_print_config_get (gp_transport->config, (unsigned char *)GNOME_PRINT_KEY_NUM_COPIES); errno = 0; valint = strtol ((char *)value, NULL, 10); if (errno == 0) papiAttributeListAddInteger (&attributes, PAPI_ATTR_EXCL, "copies", valint); else papiAttributeListAddInteger (&attributes, PAPI_ATTR_EXCL, "copies", 1); g_free (value); /* * We really ought to pull this value from somewhere. It probably will * be "application/postscript" most of the time, but at least with * "application/octet-stream" (raw data), the queue should do the right * thing. */ papiAttributeListAddString (&attributes, PAPI_ATTR_EXCL, "document-format", "application/octet-stream"); /* * Always print burst pages; GNOME doesn't have an attribute to query * for it. */ papiAttributeListAddString (&attributes, PAPI_ATTR_EXCL, "job-sheets", "standard"); /* * How does PaperSource translate into an IPP attribute? I assume that * this is the input tray, but it's not in gnome-print-config.h. This * is a holdover from the CUPS module, which uses InputSlot. */ /* value = gnome_print_config_get (gp_transport->config, "Settings.Output.PaperSource"); papiAttributeListAddString (&attributes, PAPI_ATTR_EXCL, "???", value); g_free (value); */ /* * lpsched can't deal with bad media values; printing to a remote * printer via lpd will simply fail. */ /* value = (char *)gnome_print_config_get (gp_transport->config, (unsigned char *)GNOME_PRINT_KEY_PAPER_SIZE); papiAttributeListAddString (&attributes, PAPI_ATTR_EXCL, "media", value); g_free (value); */ value = (char *)gnome_print_config_get (gp_transport->config, (unsigned char *)GNOME_PRINT_KEY_DOCUMENT_NAME); if (value != NULL && value[0] != '\0') papiAttributeListAddString (&attributes, PAPI_ATTR_EXCL, "job-name", value); g_free (value); transport->attributes = attributes; return GNOME_PRINT_OK; }
papi_status_t papiJobSubmitByReference(papi_service_t handle, char *printer, papi_attribute_t **job_attributes, papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { service_t *svc = handle; struct stat statbuf; job_t *j; int file_no; short status; char *request_id = NULL; REQUEST *request; char *c; char *tmp = NULL; char lpfile[BUFSIZ]; char **file_list = NULL; if ((svc == NULL) || (printer == NULL) || (files == NULL) || (job == NULL)) return (PAPI_BAD_ARGUMENT); if (job_ticket != NULL) return (PAPI_OPERATION_NOT_SUPPORTED); if (files != NULL) for (file_no = 0; files[file_no] != NULL; file_no++) { if (access(files[file_no], R_OK) < 0) { detailed_error(svc, gettext("Cannot access file: %s: %s"), files[file_no], strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } if (stat(files[file_no], &statbuf) < 0) { detailed_error(svc, gettext("Cannot access file: %s: %s"), files[file_no], strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } if (statbuf.st_size == 0) { detailed_error(svc, gettext("Zero byte (empty) file: %s"), files[file_no]); return (PAPI_BAD_ARGUMENT); } if (files[file_no][0] != '/') { char path[MAXPATHLEN]; if (getcwd(path, sizeof (path)) == NULL) { detailed_error(svc, gettext( "getcwd for file: %s: %s"), files[file_no], strerror(errno)); return (PAPI_DOCUMENT_ACCESS_ERROR); } strlcat(path, "/", sizeof (path)); if (strlcat(path, files[file_no], sizeof (path)) >= sizeof (path)) { detailed_error(svc, gettext( "pathname too long: %s"), files[file_no]); return (PAPI_DOCUMENT_ACCESS_ERROR); } addlist(&file_list, path); } else addlist(&file_list, (char *)files[file_no]); } if ((*job = j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); /* 1 for the control file (-0) */ status = lpsched_alloc_files(svc, 1, &request_id); if (status != PAPI_OK) return (status); request = create_request(svc, (char *)printer, (papi_attribute_t **)job_attributes); request->file_list = file_list; #ifdef LP_USE_PAPI_ATTR /* * store the job attributes in the PAPI job attribute file that was * created by lpsched_alloc_files(), the attributes will then pass * through lpsched and be given to the slow-filters and the printer's * interface script to process them */ snprintf(lpfile, sizeof (lpfile), "%s%s-%s", "/var/spool/lp/temp/", request_id, LP_PAPIATTRNAME); status = psm_copy_attrsToFile(job_attributes, lpfile); if (status != PAPI_OK) { detailed_error(svc, "unable to copy attributes to file: %s: %s", lpfile, strerror(errno)); return (PAPI_DEVICE_ERROR); } #endif /* store the meta-data file */ snprintf(lpfile, sizeof (lpfile), "%s-0", request_id); if (putrequest(lpfile, request) < 0) { detailed_error(svc, gettext("unable to save request: %s: %s"), lpfile, strerror(errno)); freerequest(request); return (PAPI_DEVICE_ERROR); } status = lpsched_commit_job(svc, lpfile, &tmp); if (status != PAPI_OK) { unlink(lpfile); freerequest(request); return (status); } lpsched_request_to_job_attributes(request, j); freerequest(request); if ((c = strrchr(tmp, '-')) != NULL) c++; papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, "job-id", atoi(c)); papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, "job-uri", tmp); return (PAPI_OK); }
int main(int ac, char *av[]) { papi_status_t status; papi_service_t svc = NULL; papi_attribute_t **list = NULL; papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; papi_job_t job = NULL; char prefetch[3]; int prefetch_len = sizeof (prefetch); char *printer = NULL; char b = PAPI_TRUE; int copy = 0; int silent = 0; int dump = 0; int validate = 0; int modify = -1; int c; uid_t ruid; struct passwd *pw; (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); ruid = getuid(); if ((pw = getpwuid(ruid)) != NULL) (void) initgroups(pw->pw_name, pw->pw_gid); (void) setuid(ruid); while ((c = getopt(ac, av, "DEH:P:S:T:cd:f:i:mn:o:pq:rst:Vwy:")) != EOF) switch (c) { case 'H': /* handling */ if (strcasecmp(optarg, "hold") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); else if (strcasecmp(optarg, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", optarg); break; case 'P': { /* page list */ char buf[BUFSIZ]; snprintf(buf, sizeof (buf), "page-ranges=%s", optarg); papiAttributeListFromString(&list, PAPI_ATTR_EXCL, buf); } break; case 'S': /* charset */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "lp-charset", optarg); break; case 'T': /* type */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", lp_type_to_mime_type(optarg)); break; case 'D': /* dump */ dump = 1; break; case 'c': /* copy */ copy = 1; break; case 'd': /* destination */ printer = optarg; break; case 'f': /* form */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "form", optarg); break; case 'i': /* modify job */ if ((get_printer_id(optarg, &printer, &modify) < 0) || (modify < 0)) { fprintf(stderr, gettext("invalid request id: %s\n"), optarg); exit(1); } break; case 'm': /* mail when complete */ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'n': /* copies */ papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", atoi(optarg)); break; case 'o': /* lp "options" */ papiAttributeListFromString(&list, PAPI_ATTR_REPLACE, optarg); break; case 'p': /* Solaris - notification */ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'q': { /* priority */ int i = atoi(optarg); i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) { fprintf(stderr, gettext("UX:lp: ")); fprintf(stderr, gettext("ERROR: ")); fprintf(stderr, gettext("Bad priority" " value \"%s\"."), optarg); fprintf(stderr, gettext("\n ")); fprintf(stderr, gettext("TO FIX")); fprintf(stderr, gettext(": ")); fprintf(stderr, gettext("Use an integer value" " from 0 to 39.")); fprintf(stderr, gettext("\n")); exit(1); } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "job-priority", i); } break; case 'r': /* "raw" mode */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", "application/octet-stream"); papiAttributeListAddString(&list, PAPI_ATTR_APPEND, "stty", "raw"); break; case 's': /* suppress message */ silent = 1; break; case 't': /* title */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-name", optarg); break; case 'V': /* validate */ validate = 1; break; case 'w': papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; case 'y': /* lp "modes" */ papiAttributeListAddString(&list, PAPI_ATTR_APPEND, "lp-modes", optarg); break; case 'E': encryption = PAPI_ENCRYPT_REQUIRED; break; default: usage(av[0]); } /* convert "banner", "nobanner" to "job-sheet" */ if (papiAttributeListGetBoolean(list, NULL, "banner", &b) == PAPI_OK) { (void) papiAttributeListDelete(&list, "banner"); if (b == PAPI_FALSE) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-sheets", "none"); } if ((printer == NULL) && ((printer = getenv("PRINTER")) == NULL) && ((printer = getenv("LPDEST")) == NULL)) printer = DEFAULT_DEST; if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) optind = ac; if (modify == -1) { char *document_format = "text/plain"; if (optind != ac) { /* get the mime type of the file data */ #ifdef MAGIC_MIME magic_t ms = NULL; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } #else if (is_postscript(av[optind]) == 1) document_format = "application/postscript"; #endif } else { if (is_postscript_stream(0, prefetch, &prefetch_len) == 1) document_format = "application/postscript"; } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "document-format", document_format); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-sheets", "standard"); } status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { fprintf(stderr, gettext( "Failed to contact service for %s: %s\n"), printer, verbose_papi_message(svc, status)); exit(1); } if (dump != 0) { printf("requesting attributes:\n"); papiAttributeListPrint(stdout, list, "\t"); printf("\n"); } if (modify != -1) status = papiJobModify(svc, printer, modify, list, &job); else if (optind == ac) /* no file list, use stdin */ status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len, list, &job); else if (validate == 1) /* validate the request can be processed */ status = papiJobValidate(svc, printer, list, NULL, &av[optind], &job); else if (copy == 0) /* reference the files in the job, default */ status = papiJobSubmitByReference(svc, printer, list, NULL, &av[optind], &job); else /* copy the files before return, -c */ status = papiJobSubmit(svc, printer, list, NULL, &av[optind], &job); papiAttributeListFree(list); if (status != PAPI_OK) { fprintf(stderr, gettext("%s: %s\n"), printer, verbose_papi_message(svc, status)); papiJobFree(job); papiServiceDestroy(svc); exit(1); } if (((silent == 0) || (dump != 0)) && ((list = papiJobGetAttributeList(job)) != NULL)) { int32_t id = -1; if (printer == NULL) papiAttributeListGetString(list, NULL, "printer-name", &printer); papiAttributeListGetInteger(list, NULL, "job-id-requested", &id); if (id == -1) { papiAttributeListGetInteger(list, NULL, "job-id", &id); } printf(gettext("request id is %s-%d "), printer, id); if (ac != optind) printf("(%d file(s))\n", ac - optind); else printf("(standard input)\n"); if (dump != 0) { printf("job attributes:\n"); papiAttributeListPrint(stdout, list, "\t"); printf("\n"); } } papiJobFree(job); papiServiceDestroy(svc); return (0); }
papi_status_t lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p, char *dest) { PRINTER *tmp; char buf[BUFSIZ+1]; struct utsname sysname; char **allowed = NULL, **denied = NULL; if ((svc == NULL) || (p == NULL) || (dest == NULL)) return (PAPI_BAD_ARGUMENT); /* get the configuration DB data */ if ((tmp = getprinter(dest)) == NULL) { detailed_error(svc, gettext("unable to read configuration data")); return (PAPI_DEVICE_ERROR); } /* name */ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "printer-name", tmp->name); if (tmp->name != NULL) { char uri[BUFSIZ]; snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s", tmp->name); papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, "printer-uri-supported", uri); } /* banner */ if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL) papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, "job-sheets-supported", "optional"); else if (tmp->banner & BAN_NEVER) papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, "job-sheets-supported", "none"); else if (tmp->banner & BAN_ALWAYS) papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, "job-sheets-supported", "standard"); /* input_types */ if (tmp->input_types != NULL) { int i; for (i = 0; tmp->input_types[i] != NULL; i++) papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_APPEND, "document-format-supported", lp_type_to_mime_type(tmp->input_types[i])); } /* description */ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "printer-info", tmp->description); /* add lpsched specific attributes */ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "device-uri", tmp->device); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-dial-info", tmp->dial_info); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-fault-recovery", tmp->fault_rec); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-interface-script", tmp->interface); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-data-rate", tmp->speed); papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-stty", tmp->stty); papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-login-term", tmp->login); papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-daisy", tmp->daisy); papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-charsets", tmp->char_sets); #ifdef CAN_DO_MODULES papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-modules", tmp->modules); #endif /* CAN_DO_MODULES */ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-options", tmp->options); papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-printer-type", tmp->printer_types); if (tmp->fault_alert.shcmd != NULL) { papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-fault-alert-command", tmp->fault_alert.shcmd); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-fault-alert-threshold", tmp->fault_alert.Q); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-fault-alert-interval", tmp->fault_alert.W); } papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-cpi-value", tmp->cpi.val); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-cpi-unit", tmp->cpi.sc); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-lpi-value", tmp->lpi.val); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-lpi-unit", tmp->lpi.sc); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-plen-value", tmp->plen.val); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-plen-unit", tmp->plen.sc); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-pwid-value", tmp->pwid.val); papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-pwid-unit", tmp->pwid.sc); /* allow/deny list */ load_userprinter_access(dest, &allowed, &denied); papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "requesting-user-name-allowed", allowed); papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, "requesting-user-name-denied", denied); #ifdef LP_USE_PAPI_ATTR if (tmp->ppd != NULL) { int fd; struct stat sbuf; /* construct the two URIs for the printer's PPD file */ if (uname(&sysname) < 0) { /* failed to get systen name */ sysname.nodename[0] = 0; } snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd", sysname.nodename, ETCDIR, tmp->name); papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, "ppd-file-uri", buf); snprintf(buf, sizeof (buf), "file://%s%s", sysname.nodename, tmp->ppd); papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-printer-configure-ppd-uri", buf); papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, "lpsched-ppd-source-path", tmp->ppd); snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name); /* * We don't return error on any of the error conditions, we just * silently return without adding the attribute. */ PPDFileToAttributesList(&p->attributes, buf); } #endif freeprinter(tmp); return (PAPI_OK); }