papi_status_t papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) { service_t *svc = handle; papi_status_t result = PAPI_OK_SUBST; short more; long status; char *dest; char *req_id; if ((handle == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); dest = printer_name_from_uri_id(name, -1); more = snd_msg(svc, S_CANCEL, dest, "", ""); free(dest); if (more < 0) return (PAPI_SERVICE_UNAVAILABLE); do { if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0) return (PAPI_SERVICE_UNAVAILABLE); switch (status) { case MOK: papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, "canceled-jobs", req_id); break; case M2LATE: case MUNKNOWN: case MNOINFO: papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, "cancel-failed", req_id); result = PAPI_DEVICE_ERROR; break; case MNOPERM: papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, "cancel-failed", req_id); result = PAPI_NOT_AUTHORIZED; break; default: detailed_error(svc, gettext("cancel failed, bad status (%d)\n"), status); return (PAPI_DEVICE_ERROR); } } while (more == MOKMORE); return (result); }
static REQUEST * create_request(papi_service_t svc, char *printer, papi_attribute_t **attributes) { REQUEST *r; if ((r = calloc(1, sizeof (*r))) != NULL) { char *hostname = NULL; r->priority = -1; r->destination = printer_name_from_uri_id(printer, -1); papiAttributeListGetString(attributes, NULL, "job-originating-host-name", &hostname); if (hostname == NULL) { char host[BUFSIZ]; if (gethostname(host, sizeof (host)) == 0) papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, "job-originating-host-name", host); } job_attributes_to_lpsched_request(svc, r, attributes); } return (r); }
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 papiJobValidate(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; papi_attribute_t **attributes = NULL; int i; papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, "job-hold-until", "indefinite"); for (i = 0; job_attributes[i]; i++) list_append(&attributes, job_attributes[i]); status = papiJobSubmitByReference(handle, printer, (papi_attribute_t **)attributes, job_ticket, files, job); if (status == PAPI_OK) { int id = papiJobGetId(*job); if (id != -1) papiJobCancel(handle, printer, id); } attributes[1] = NULL; /* after attr[0], they are in another list */ papiAttributeListFree(attributes); return (status); }
papi_status_t papiPrinterListJobs(papi_service_t handle, char *name, char **requested_attrs, int type_mask, int max_num_jobs, papi_job_t **jobs) { papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; void *iter = NULL; if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, OPID_GET_JOBS); ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; for (status = papiAttributeListGetCollection(response, &iter, "job-attributes-group", &op); status == PAPI_OK; status = papiAttributeListGetCollection(response, &iter, NULL, &op)) { job_t *j = NULL; if ((j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); copy_attributes(&j->attributes, op); op = NULL; list_append(jobs, j); } papiAttributeListFree(response); return (result); }
static papi_status_t _printer_enable_disable_pause_resume_delete(papi_service_t handle, char *name, char *message, uint16_t type) { papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, type); ipp_initialize_operational_attributes(svc, &op, name, -1); switch (type) { case OPID_DISABLE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-message-from-operator", message); break; case OPID_PAUSE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-state-message", message); break; default: /* a message value is of no use */ break; } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); papiAttributeListFree(response); return (result); }
/* * This puts the class information in only. It could create a hybrid * printer object to return, but that is problematic at best. */ papi_status_t lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p, char *dest) { CLASS *tmp; if ((svc == NULL) || (p == NULL)) return (PAPI_BAD_ARGUMENT); /* get the configuration DB data */ if ((tmp = getclass(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); } if (tmp->members != NULL) { char **members = tmp->members; int i; for (i = 0; members[i] != NULL; i++) papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, "member-names", members[i]); } freeclass(tmp); return (PAPI_OK); }
papi_status_t papiAttributeListAddLPString(papi_attribute_t ***list, int flags, char *name, char *value) { papi_status_t result = PAPI_BAD_ARGUMENT; if ((list != NULL) && (name != NULL) && (value != NULL) && (value[0] != NULL)) result = papiAttributeListAddString(list, flags, name, value); return (result); }
papi_status_t papiServiceSetPassword(papi_service_t handle, char *password) { service_t *svc = handle; if (svc == NULL) return (PAPI_BAD_ARGUMENT); return (papiAttributeListAddString(&svc->attributes, PAPI_ATTR_REPLACE, "password", password)); }
papi_status_t papiServiceSetUserName(papi_service_t handle, char *user_name) { service_t *svc = handle; if (svc == NULL) return (PAPI_BAD_ARGUMENT); return (papiAttributeListAddString(&svc->attributes, PAPI_ATTR_REPLACE, "user-name", user_name)); }
papi_status_t papiPrintersList(papi_service_t handle, char **requested_attrs, papi_filter_t *filter, papi_printer_t **printers) { papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; void *iter = NULL; if ((svc == NULL) || (printers == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, DEFAULT_DEST)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, OPID_CUPS_GET_PRINTERS); ipp_initialize_operational_attributes(svc, &op, NULL, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; for (status = papiAttributeListGetCollection(response, &iter, "printer-attributes-group", &op); status == PAPI_OK; status = papiAttributeListGetCollection(response, &iter, NULL, &op)) { printer_t *p = NULL; if ((p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); copy_attributes(&p->attributes, op); op = NULL; list_append(printers, p); } papiAttributeListFree(response); return (result); }
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)); }
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); }
papi_status_t papiPrinterQuery(papi_service_t handle, char *name, char **requested_attrs, papi_attribute_t **job_attributes, papi_printer_t *printer) { papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; printer_t *p = NULL; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; if ((svc == NULL) || (name == NULL) || (printer == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); ipp_initialize_request(svc, &request, OPID_GET_PRINTER_ATTRIBUTES); ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; papiAttributeListGetCollection(response, NULL, "printer-attributes-group", &op); copy_attributes(&p->attributes, op); papiAttributeListFree(response); return (result); }
papi_status_t papiAttributeListAddLPStrings(papi_attribute_t ***list, int flags, char *name, char **values) { papi_status_t result = PAPI_OK; int i, flgs = flags; if ((list == NULL) || (name == NULL) || (values == NULL)) result = PAPI_BAD_ARGUMENT; for (i = 0; ((result == PAPI_OK) && (values[i] != NULL)); i++, flgs = PAPI_ATTR_APPEND) result = papiAttributeListAddString(list, flgs, name, values[i]); 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 papiServiceCreate(papi_service_t *handle, char *service_name, char *user_name, char *password, int (*authCB)(papi_service_t svc, void *app_data), papi_encryption_t encryption, void *app_data) { service_t *svc = NULL; char *path = Lp_FIFO; if (handle == NULL) return (PAPI_BAD_ARGUMENT); if ((*handle = svc = calloc(1, sizeof (*svc))) == NULL) return (PAPI_TEMPORARY_ERROR); svc->md = mconnect(path, 0, 0); if (svc->md == NULL) { detailed_error(svc, gettext("can't connect to spooler for %s: %s"), (service_name ? service_name : ""), strerror(errno)); return (PAPI_SERVICE_UNAVAILABLE); } svc->msgbuf_size = MSGMAX; if ((svc->msgbuf = calloc(1, svc->msgbuf_size)) == NULL) return (PAPI_TEMPORARY_ERROR); if (service_name != NULL) papiAttributeListAddString(&svc->attributes, PAPI_ATTR_EXCL, "service-name", service_name); (void) papiServiceSetUserName(svc, user_name); (void) papiServiceSetPassword(svc, password); (void) papiServiceSetAuthCB(svc, authCB); (void) papiServiceSetAppData(svc, app_data); (void) papiServiceSetEncryption(svc, encryption); 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 detailed_error(service_t *svc, char *fmt, ...) { if ((svc != NULL) && (fmt != NULL)) { va_list ap; size_t size; char *message = alloca(BUFSIZ); va_start(ap, fmt); /* * fill in the message. If the buffer is too small, allocate * one that is large enough and fill it in. */ if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ) if ((message = alloca(size)) != NULL) vsnprintf(message, size, fmt, ap); va_end(ap); papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, "detailed-status-message", message); } }
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 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); }
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); }
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); }
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; }
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); }
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 PPDFileToAttributesList(papi_attribute_t ***attributes, char *filename) { papi_status_t status = PAPI_OK; FILE *fp; char line[256]; char capability[256]; char def[256]; char supported[256]; char *current_group_name = NULL; int ui = 0; if ((fp = fopen(filename, "r")) == NULL) return (PAPI_NOT_POSSIBLE); while ((status == PAPI_OK) && (fgets(line, sizeof (line), fp) != NULL)) { char *key = NULL, *value = NULL, *text = NULL; /* we want *key...: "value" */ if (line[0] != '*') continue; if (strchr(line, ':') == NULL) continue; if ((text = strrchr(line, '\n')) != NULL) *text = NULL; process_line(line, &key, &value, &text); if ((strcasecmp(key, "PageSize") == 0) || (strcasecmp(key, "InputSlot") == 0)) key = "media"; if (strcasecmp(key, "OpenGroup") == 0) { if (value == NULL) value = "unknown"; current_group_name = strdup(value); } else if (strcasecmp(key, "OpenUI") == 0) { if ((strcasecmp(value, "PageSize") == 0) || (strcasecmp(value, "InputSlot") == 0)) value = "media"; snprintf(capability, sizeof (capability), "%s", value); snprintf(def, sizeof (def), "%s-default", value); snprintf(supported, sizeof (supported), "%s-supported", value); ui = 1; } else if (strcasecmp(key, "CloseGroup") == 0) { /* do nothing */ } else if (strcasecmp(key, "CloseUI") == 0) { ui = 0; /* do nothing */ } else if (strcasecmp(key, "Manufacturer") == 0) { status = papiAttributeListAddString(attributes, PAPI_ATTR_EXCL, "printer-make", value); } else if (strcasecmp(key, "ModelName") == 0) { status = papiAttributeListAddString(attributes, PAPI_ATTR_EXCL, "printer-model", value); } else if (strcasecmp(key, "ShortNickName") == 0) { status = papiAttributeListAddString(attributes, PAPI_ATTR_EXCL, "printer-make-and-model", value); } else if ((strncasecmp(key, "Default", 7) == 0) && ui) { status = papiAttributeListAddString(attributes, PAPI_ATTR_EXCL, def, value); } else if ((strcasecmp(key, capability) == 0) && ui) { status = papiAttributeListAddString(attributes, PAPI_ATTR_APPEND, supported, value); } } fclose(fp); return (status); }
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); }