📄 ipp2.c
字号:
*/static voidadd_job_state_reasons(client_t *con, /* I - Client connection */ job_t *job) /* I - Job info */{ printer_t *dest; /* Destination printer */ LogMessage(L_DEBUG2, "add_job_state_reasons(%p[%d], %d)\n", con, con->http.fd, job ? job->id : 0); switch (job ? job->state->values[0].integer : IPP_JOB_CANCELLED) { case IPP_JOB_PENDING : /* if (job->dtype & CUPS_PRINTER_CLASS) dest = FindClass(job->dest); else*/ dest = FindPrinter(job->dest); if (dest != NULL && dest->state == IPP_PRINTER_STOPPED) ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "printer-stopped"); else ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "none"); break; case IPP_JOB_HELD : if (ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD) != NULL || ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME) != NULL) ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-hold-until-specified"); else ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-incoming"); break; case IPP_JOB_PROCESSING : ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-printing"); break; case IPP_JOB_STOPPED : ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-stopped"); break; case IPP_JOB_CANCELLED : ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-canceled-by-user"); break; case IPP_JOB_ABORTED : ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "aborted-by-system"); break; case IPP_JOB_COMPLETED : ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-completed-successfully"); break; }}#if 0/* * 'add_printer()' - Add a printer to the system. */static voidadd_printer(client_t *con, /* I - Client connection */ ipp_attribute_t *uri) /* I - URI of printer */{ int i; /* Looping var */ char method[HTTP_MAX_URI], /* Method portion of URI */ username[HTTP_MAX_URI], /* Username portion of URI */ host[HTTP_MAX_URI], /* Host portion of URI */ resource[HTTP_MAX_URI]; /* Resource portion of URI */ int port; /* Port portion of URI */ printer_t *printer; /* Printer/class */ ipp_attribute_t *attr; /* Printer attribute */ cups_file_t *fp; /* Script/PPD file */ char line[1024]; /* Line from file... */ char srcfile[1024], /* Source Script/PPD file */ dstfile[1024]; /* Destination Script/PPD file */ int modify; /* Non-zero if we are modifying */ LogMessage(L_DEBUG2, "add_printer(%p[%d], %s)\n", con, con->http.fd, uri->values[0].string.text); /* * Was this operation called from the correct URI? */ if (strncmp(con->uri, "/admin/", 7) != 0) { LogMessage(L_ERROR, "add_printer: admin request on bad resource \'%s\'!", con->uri); send_ipp_error(con, IPP_NOT_AUTHORIZED); return; } /* * Do we have a valid URI? */ httpSeparate(uri->values[0].string.text, method, username, host, &port, resource); if (strncmp(resource, "/printers/", 10) != 0 || strlen(resource) == 10) { /* * No, return an error... */ LogMessage(L_ERROR, "add_printer: bad printer URI \"%s\"!", uri->values[0].string.text); send_ipp_error(con, IPP_BAD_REQUEST); return; } /* * See if the printer already exists; if not, create a new printer... */ if ((printer = FindPrinter(resource + 10)) == NULL) { /* * Printer doesn't exist; see if we have a class of the same name... */ if ((printer = FindClass(resource + 10)) != NULL && !(printer->type & CUPS_PRINTER_REMOTE)) { /* * Yes, return an error... */ LogMessage(L_ERROR, "add_printer: \"%s\" already exists as a class!", resource + 10); send_ipp_error(con, IPP_NOT_POSSIBLE); return; } /* * No, add the printer... */ printer = AddPrinter(resource + 10); modify = 0; } else if (printer->type & CUPS_PRINTER_IMPLICIT) { /* * Rename the implicit printer to "AnyPrinter" or delete it... */ if (ImplicitAnyClasses) { SetStringf(&printer->name, "Any%s", resource + 10); SortPrinters(); } else DeletePrinter(printer, 1); /* * Add the printer as a new local printer... */ printer = AddPrinter(resource + 10); modify = 0; } else if (printer->type & CUPS_PRINTER_REMOTE) { /* * Rename the remote printer to "Printer@server"... */ DeletePrinterFilters(printer); SetStringf(&printer->name, "%s@%s", resource + 10, printer->hostname); SetPrinterAttrs(printer); SortPrinters(); /* * Add the printer as a new local printer... */ printer = AddPrinter(resource + 10); modify = 0; } else modify = 1; /* * Look for attributes and copy them over as needed... */ if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL) SetString(&printer->location, attr->values[0].string.text); if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL) SetString(&printer->info, attr->values[0].string.text); if ((attr = ippFindAttribute(con->request, "device-uri", IPP_TAG_URI)) != NULL) { ipp_attribute_t *device; /* Current device */ int methodlen; /* Length of method string */ /* * Do we have a valid device URI? */ httpSeparate(attr->values[0].string.text, method, username, host, &port, resource); methodlen = strlen(method); if (strcmp(method, "file") == 0) { /* * See if the administrator has enabled file devices... */ if (!FileDevice && strcmp(resource, "/dev/null")) { /* * File devices are disabled and the URL is not file:/dev/null... */ LogMessage(L_ERROR, "add_printer: File device URIs have been disabled! " "To enable, see the FileDevice directive in cupsd.conf."); send_ipp_error(con, IPP_NOT_POSSIBLE); return; } } else { /* * See if the backend is listed as a device... */ for (device = ippFindAttribute(Devices, "device-uri", IPP_TAG_URI); device != NULL; device = ippFindNextAttribute(Devices, "device-uri", IPP_TAG_URI)) if (strncmp(method, device->values[0].string.text, methodlen) == 0 && (device->values[0].string.text[methodlen] == ':' || device->values[0].string.text[methodlen] == '\0')) break; if (device == NULL) { /* * Could not find device in list! */ LogMessage(L_ERROR, "add_printer: bad device-uri attribute \'%s\'!", attr->values[0].string.text); send_ipp_error(con, IPP_NOT_POSSIBLE); return; } } LogMessage(L_INFO, "Setting %s device-uri to \"%s\" (was \"%s\".)", printer->name, cupsdSanitizeURI(attr->values[0].string.text, line, sizeof(line)), cupsdSanitizeURI(printer->device_uri, resource, sizeof(resource))); SetString(&printer->device_uri, attr->values[0].string.text); } if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL) { LogMessage(L_INFO, "Setting %s printer-is-accepting-jobs to %d (was %d.)", printer->name, attr->values[0].boolean, printer->accepting); printer->accepting = attr->values[0].boolean; AddPrinterHistory(printer); } if ((attr = ippFindAttribute(con->request, "printer-state", IPP_TAG_ENUM)) != NULL) { if (attr->values[0].integer != IPP_PRINTER_IDLE && attr->values[0].integer == IPP_PRINTER_STOPPED) { LogMessage(L_ERROR, "Attempt to set %s printer-state to bad value %d!", printer->name, attr->values[0].integer); send_ipp_error(con, IPP_BAD_REQUEST); return; } LogMessage(L_INFO, "Setting %s printer-state to %d (was %d.)", printer->name, attr->values[0].integer, printer->state); SetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0); } if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL) { strlcpy(printer->state_message, attr->values[0].string.text, sizeof(printer->state_message)); AddPrinterHistory(printer); } if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL && !Classification) { SetString(&printer->job_sheets[0], attr->values[0].string.text); if (attr->num_values > 1) SetString(&printer->job_sheets[1], attr->values[1].string.text); else SetString(&printer->job_sheets[1], "none"); } if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed", IPP_TAG_ZERO)) != NULL) { FreePrinterUsers(printer); printer->deny_users = 0; if (attr->value_tag == IPP_TAG_NAME && (attr->num_values > 1 || strcmp(attr->values[0].string.text, "all") != 0)) for (i = 0; i < attr->num_values; i ++) AddPrinterUser(printer, attr->values[i].string.text); } else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied", IPP_TAG_ZERO)) != NULL) { FreePrinterUsers(printer); printer->deny_users = 1; if (attr->value_tag == IPP_TAG_NAME && (attr->num_values > 1 || strcmp(attr->values[0].string.text, "none") != 0)) for (i = 0; i < attr->num_values; i ++) AddPrinterUser(printer, attr->values[i].string.text); } if ((attr = ippFindAttribute(con->request, "job-quota-period", IPP_TAG_INTEGER)) != NULL) { LogMessage(L_DEBUG, "add_printer: Setting job-quota-period to %d...", attr->values[0].integer); FreeQuotas(printer); printer->quota_period = attr->values[0].integer; } if ((attr = ippFindAttribute(con->request, "job-k-limit", IPP_TAG_INTEGER)) != NULL) { LogMessage(L_DEBUG, "add_printer: Setting job-k-limit to %d...", attr->values[0].integer); FreeQuotas(printer); printer->k_limit = attr->values[0].integer; } if ((attr = ippFindAttribute(con->request, "job-page-limit", IPP_TAG_INTEGER)) != NULL) { LogMessage(L_DEBUG, "add_printer: Setting job-page-limit to %d...", attr->values[0].integer); FreeQuotas(printer); printer->page_limit = attr->values[0].integer; } /* * See if we have all required attributes... */ if (!printer->device_uri) SetString(&printer->device_uri, "file:/dev/null"); /* * See if we have an interface script or PPD file attached to the request... */ if (con->filename) { strlcpy(srcfile, con->filename, sizeof(srcfile)); if ((fp = cupsFileOpen(srcfile, "rb")) != NULL) { /* * Yes; get the first line from it... */ line[0] = '\0'; cupsFileGets(fp, line, sizeof(line)); cupsFileClose(fp); /* * Then see what kind of file it is... */ snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot, printer->name); if (strncmp(line, "*PPD-Adobe", 10) == 0) { /* * The new file is a PPD file, so remove any old interface script * that might be lying around... */ unlink(dstfile); } else { /* * This must be an interface script, so move the file over to the * interfaces directory and make it executable... */ if (copy_file(srcfile, dstfile)) { LogMessage(L_ERROR, "add_printer: Unable to copy interface script from %s to %s - %s!", srcfile, dstfile, strerror(errno)); send_ipp_error(con, IPP_INTERNAL_ERROR); return; } else { LogMessage(L_DEBUG, "add_printer: Copied interface script successfully!"); chmod(dstfile, 0755); } } snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, printer->name); if (strncmp(line, "*PPD-Adobe", 10) == 0) { /* * The new file is a PPD file, so move the file over to the * ppd directory and make it readable by all... */ if (copy_file(srcfile, dstfile)) { LogMessage(L_ERROR, "add_printer: Unable to copy PPD file from %s to %s - %s!", srcfile, dstfile, strerror(errno)); send_ipp_error(con, IPP_INTERNAL_ERROR); return; } else { LogMessage(L_DEBUG, "add_printer: Copied PPD file successfully!"); chmod(dstfile, 0644); } } else { /* * This must be an interface script, so remove any old PPD file that * may be lying around... */ unlink(dstfile); } } } else if ((attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL) { if (strcmp(attr->values[0].string.text, "raw") == 0) { /* * Raw driver, remove any existing PPD or interface script files. */ snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot, printer->name); unlink(dstfile); snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, printer->name); unlink(dstfile); } else { /* * PPD model file...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -