diff options
author | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2009-02-17 19:24:29 +0000 |
---|---|---|
committer | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2009-02-17 19:24:29 +0000 |
commit | f0ab5bff8ab3f7b00619675b806b1f01294a3f6a (patch) | |
tree | 2c9d51f5a4af79a28e10dc990e323efaddb5c555 /scheduler | |
parent | bf3816c7edd01247b850a12e52856819190b66fd (diff) |
Merge changes from CUPS 1.4svn-r8362.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@1228 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'scheduler')
-rw-r--r-- | scheduler/client.c | 5 | ||||
-rw-r--r-- | scheduler/cups-driverd.cxx | 218 | ||||
-rw-r--r-- | scheduler/cupsfilter.c | 4 | ||||
-rw-r--r-- | scheduler/dirsvc.c | 93 | ||||
-rw-r--r-- | scheduler/ipp.c | 14 | ||||
-rw-r--r-- | scheduler/job.c | 147 | ||||
-rw-r--r-- | scheduler/printers.c | 2 | ||||
-rw-r--r-- | scheduler/statbuf.c | 14 | ||||
-rw-r--r-- | scheduler/subscriptions.c | 5 |
9 files changed, 333 insertions, 169 deletions
diff --git a/scheduler/client.c b/scheduler/client.c index 1e2f55d8d..758c47196 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -2697,8 +2697,13 @@ cupsdUpdateCGI(void) while ((ptr = cupsdStatBufUpdate(CGIStatusBuffer, &loglevel, message, sizeof(message))) != NULL) + { + if (loglevel == CUPSD_LOG_INFO) + cupsdLogMessage(CUPSD_LOG_INFO, "%s", message); + if (!strchr(CGIStatusBuffer->buffer, '\n')) break; + } if (ptr == NULL && !CGIStatusBuffer->bufused) { diff --git a/scheduler/cups-driverd.cxx b/scheduler/cups-driverd.cxx index 4cc80c706..0b1a83ee4 100644 --- a/scheduler/cups-driverd.cxx +++ b/scheduler/cups-driverd.cxx @@ -26,11 +26,13 @@ * compare_matches() - Compare PPD match scores for sorting. * compare_names() - Compare PPD filenames for sorting. * compare_ppds() - Compare PPD file make and model names for sorting. + * dump_ppds_dat() - Dump the contents of the ppds.dat file. * free_array() - Free an array of strings. * list_ppds() - List PPD files. * load_ppds() - Load PPD files recursively. * load_drv() - Load the PPDs from a driver information file. * load_drivers() - Load driver-generated PPD files. + * load_ppds_dat() - Load the ppds.dat file. * regex_device_id() - Compile a regular expression based on the 1284 device * ID. * regex_string() - Construct a regular expression to compare a simple @@ -136,6 +138,7 @@ static int compare_names(const ppd_info_t *p0, const ppd_info_t *p1); static int compare_ppds(const ppd_info_t *p0, const ppd_info_t *p1); +static int dump_ppds_dat(void); static void free_array(cups_array_t *a); static int list_ppds(int request_id, int limit, const char *opt); static int load_drivers(cups_array_t *include, @@ -143,6 +146,8 @@ static int load_drivers(cups_array_t *include, static int load_drv(const char *filename, const char *name, cups_file_t *fp, time_t mtime, off_t size); static int load_ppds(const char *d, const char *p, int descend); +static void load_ppds_dat(char *filename, size_t filesize, + int verbose); static regex_t *regex_device_id(const char *device_id); static regex_t *regex_string(const char *s); @@ -165,6 +170,8 @@ main(int argc, /* I - Number of command-line args */ if (argc == 3 && !strcmp(argv[1], "cat")) return (cat_ppd(argv[2], 0)); + else if (argc == 2 && !strcmp(argv[1], "dump")) + return (dump_ppds_dat()); else if (argc == 4 && !strcmp(argv[1], "get")) return (cat_ppd(argv[3], atoi(argv[2]))); else if (argc == 5 && !strcmp(argv[1], "list")) @@ -172,6 +179,7 @@ main(int argc, /* I - Number of command-line args */ else { fputs("Usage: cups-driverd cat ppd-name\n", stderr); + fputs("Usage: cups-driverd dump\n", stderr); fputs("Usage: cups-driverd get request_id ppd-name\n", stderr); fputs("Usage: cups-driverd list request_id limit options\n", stderr); return (1); @@ -341,7 +349,7 @@ cat_drv(const char *name, /* I - PPD name */ ppdcCatalog *catalog; // Message catalog in .drv file - fprintf(stderr, "DEBUG: [cups-driverd] %d locales defined in \"%s\"...\n", + fprintf(stderr, "DEBUG2: [cups-driverd] %d locales defined in \"%s\"...\n", src->po_files->count, filename); locales = new ppdcArray(); @@ -349,7 +357,7 @@ cat_drv(const char *name, /* I - PPD name */ catalog; catalog = (ppdcCatalog *)src->po_files->next()) { - fprintf(stderr, "DEBUG: [cups-driverd] Adding locale \"%s\"...\n", + fprintf(stderr, "DEBUG2: [cups-driverd] Adding locale \"%s\"...\n", catalog->locale->value); locales->add(catalog->locale); } @@ -711,6 +719,41 @@ compare_ppds(const ppd_info_t *p0, /* I - First PPD file */ /* + * 'dump_ppds_dat()' - Dump the contents of the ppds.dat file. + */ + +static int /* O - Exit status */ +dump_ppds_dat(void) +{ + char filename[1024]; /* ppds.dat filename */ + ppd_info_t *ppd; /* Current PPD */ + + + /* + * See if we a PPD database file... + */ + + load_ppds_dat(filename, sizeof(filename), 0); + + puts("mtime,size,model_number,type,filename,name,languages0,products0," + "psversions0,make,make_and_model,device_id,scheme"); + for (ppd = (ppd_info_t *)cupsArrayFirst(PPDsByName); + ppd; + ppd = (ppd_info_t *)cupsArrayNext(PPDsByName)) + printf("%d,%ld,%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"," + "\"%s\",\"%s\"\n", + (int)ppd->record.mtime, (long)ppd->record.size, + ppd->record.model_number, ppd->record.type, ppd->record.filename, + ppd->record.name, ppd->record.languages[0], ppd->record.products[0], + ppd->record.psversions[0], ppd->record.make, + ppd->record.make_and_model, ppd->record.device_id, + ppd->record.scheme); + + return (0); +} + + +/* * 'free_array()' - Free an array of strings. */ @@ -742,10 +785,8 @@ list_ppds(int request_id, /* I - Request ID */ int count; /* Number of PPDs to send */ ppd_info_t *ppd; /* Current PPD file */ cups_file_t *fp; /* ppds.dat file */ - struct stat fileinfo; /* ppds.dat information */ char filename[1024], /* ppds.dat filename */ model[1024]; /* Model directory */ - const char *cups_cachedir; /* CUPS_CACHEDIR environment variable */ const char *cups_datadir; /* CUPS_DATADIR environment variable */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ @@ -788,64 +829,8 @@ list_ppds(int request_id, /* I - Request ID */ * See if we a PPD database file... */ - PPDsByName = cupsArrayNew((cups_array_func_t)compare_names, NULL); - PPDsByMakeModel = cupsArrayNew((cups_array_func_t)compare_ppds, NULL); - ChangedPPD = 0; - - if ((cups_cachedir = getenv("CUPS_CACHEDIR")) == NULL) - cups_cachedir = CUPS_CACHEDIR; - - snprintf(filename, sizeof(filename), "%s/ppds.dat", cups_cachedir); - if ((fp = cupsFileOpen(filename, "r")) != NULL) - { - /* - * See if we have the right sync word... - */ - - unsigned ppdsync; /* Sync word */ - int num_ppds; /* Number of PPDs */ - + load_ppds_dat(filename, sizeof(filename), 1); - if (cupsFileRead(fp, (char *)&ppdsync, sizeof(ppdsync)) - == sizeof(ppdsync) && - ppdsync == PPD_SYNC && - !stat(filename, &fileinfo) && - ((fileinfo.st_size - sizeof(ppdsync)) % sizeof(ppd_rec_t)) == 0 && - (num_ppds = (fileinfo.st_size - sizeof(ppdsync)) / - sizeof(ppd_rec_t)) > 0) - { - /* - * We have a ppds.dat file, so read it! - */ - - for (; num_ppds > 0; num_ppds --) - { - if ((ppd = (ppd_info_t *)calloc(1, sizeof(ppd_info_t))) == NULL) - { - fputs("ERROR: [cups-driverd] Unable to allocate memory for PPD!\n", - stderr); - exit(1); - } - - if (cupsFileRead(fp, (char *)&(ppd->record), sizeof(ppd_rec_t)) > 0) - { - cupsArrayAdd(PPDsByName, ppd); - cupsArrayAdd(PPDsByMakeModel, ppd); - } - else - { - free(ppd); - break; - } - } - - fprintf(stderr, "INFO: [cups-driverd] Read \"%s\", %d PPDs...\n", - filename, cupsArrayCount(PPDsByName)); - } - - cupsFileClose(fp); - } - /* * Load all PPDs in the specified directory and below... */ @@ -902,12 +887,16 @@ list_ppds(int request_id, /* I - Request ID */ cupsArrayRemove(PPDsByName, ppd); cupsArrayRemove(PPDsByMakeModel, ppd); free(ppd); + + ChangedPPD = 1; } /* * Write the new ppds.dat file... */ + fprintf(stderr, "DEBUG: [cups-driverd] ChangedPPD=%d\n", ChangedPPD); + if (ChangedPPD) { if ((fp = cupsFileOpen(filename, "w")) != NULL) @@ -944,10 +933,6 @@ list_ppds(int request_id, /* I - Request ID */ include = cupsdCreateStringsArray(cupsGetOption("include-schemes", num_options, options)); - for (i = 0; i < num_options; i ++) - fprintf(stderr, "DEBUG: [cups-driverd] %s=%s\n", options[i].name, - options[i].value); - load_drivers(include, exclude); /* @@ -1007,7 +992,7 @@ list_ppds(int request_id, /* I - Request ID */ type = 0; for (i = 0; i < num_options; i ++) - fprintf(stderr, "DEBUG: [cups-driverd] %s=\"%s\"\n", options[i].name, + fprintf(stderr, "DEBUG2: [cups-driverd] %s=\"%s\"\n", options[i].name, options[i].value); if (!requested || cupsArrayFind(requested, (void *)"all") != NULL) @@ -1044,7 +1029,14 @@ list_ppds(int request_id, /* I - Request ID */ (void *)"ppd-type") != NULL; } - puts("Content-Type: application/ipp\n"); + /* + * Send the content type header to the scheduler; request_id can only be + * 0 when run manually since the scheduler enforces the IPP requirement for + * a request ID from 1 to 2^31-1... + */ + + if (request_id > 0) + puts("Content-Type: application/ipp\n"); sent_header = 0; @@ -1167,7 +1159,7 @@ list_ppds(int request_id, /* I - Request ID */ if (ppd->matches) { - fprintf(stderr, "DEBUG: [cups-driverd] %s matches with score %d!\n", + fprintf(stderr, "DEBUG2: [cups-driverd] %s matches with score %d!\n", ppd->record.name, ppd->matches); cupsArrayAdd(matches, ppd); } @@ -1226,7 +1218,7 @@ list_ppds(int request_id, /* I - Request ID */ "en-US"); } - fprintf(stderr, "DEBUG: [cups-driverd] Sending %s (%s)...\n", + fprintf(stderr, "DEBUG2: [cups-driverd] Sending %s (%s)...\n", ppd->record.name, ppd->record.make_and_model); count --; @@ -1757,7 +1749,7 @@ load_ppds(const char *d, /* I - Actual directory */ * Add new PPD file... */ - fprintf(stderr, "DEBUG: [cups-driverd] Adding ppd \"%s\"...\n", name); + fprintf(stderr, "DEBUG2: [cups-driverd] Adding ppd \"%s\"...\n", name); ppd = add_ppd(name, name, lang_version, manufacturer, make_model, device_id, (char *)cupsArrayFirst(products), @@ -1777,7 +1769,7 @@ load_ppds(const char *d, /* I - Actual directory */ * Update existing record... */ - fprintf(stderr, "DEBUG: [cups-driverd] Updating ppd \"%s\"...\n", name); + fprintf(stderr, "DEBUG2: [cups-driverd] Updating ppd \"%s\"...\n", name); memset(ppd, 0, sizeof(ppd_info_t)); @@ -1885,6 +1877,7 @@ load_drv(const char *filename, /* I - Actual filename */ add_ppd(filename, filename, "", "", "", "", "", "", mtime, size, 0, PPD_TYPE_DRV, "drv"); + ChangedPPD = 1; /* * Then the drivers in the file... @@ -2153,8 +2146,8 @@ load_drivers(cups_array_t *include, /* I - Drivers to include */ type = PPD_TYPE_UNKNOWN; } - ppd = add_ppd("", name, languages, make, make_and_model, device_id, - product, psversion, 0, 0, 0, type, scheme); + ppd = add_ppd(filename, name, languages, make, make_and_model, + device_id, product, psversion, 0, 0, 0, type, scheme); if (!ppd) { @@ -2179,7 +2172,7 @@ load_drivers(cups_array_t *include, /* I - Drivers to include */ } } - fprintf(stderr, "DEBUG: [cups-driverd] Added dynamic PPD \"%s\"...\n", + fprintf(stderr, "DEBUG2: [cups-driverd] Added dynamic PPD \"%s\"...\n", name); } } @@ -2198,6 +2191,83 @@ load_drivers(cups_array_t *include, /* I - Drivers to include */ /* + * 'load_ppds_dat()' - Load the ppds.dat file. + */ + +static void +load_ppds_dat(char *filename, /* I - Filename buffer */ + size_t filesize, /* I - Size of filename buffer */ + int verbose) /* I - Be verbose? */ +{ + ppd_info_t *ppd; /* Current PPD file */ + cups_file_t *fp; /* ppds.dat file */ + struct stat fileinfo; /* ppds.dat information */ + const char *cups_cachedir; /* CUPS_CACHEDIR environment variable */ + + + PPDsByName = cupsArrayNew((cups_array_func_t)compare_names, NULL); + PPDsByMakeModel = cupsArrayNew((cups_array_func_t)compare_ppds, NULL); + ChangedPPD = 0; + + if ((cups_cachedir = getenv("CUPS_CACHEDIR")) == NULL) + cups_cachedir = CUPS_CACHEDIR; + + snprintf(filename, filesize, "%s/ppds.dat", cups_cachedir); + if ((fp = cupsFileOpen(filename, "r")) != NULL) + { + /* + * See if we have the right sync word... + */ + + unsigned ppdsync; /* Sync word */ + int num_ppds; /* Number of PPDs */ + + + if (cupsFileRead(fp, (char *)&ppdsync, sizeof(ppdsync)) + == sizeof(ppdsync) && + ppdsync == PPD_SYNC && + !stat(filename, &fileinfo) && + ((fileinfo.st_size - sizeof(ppdsync)) % sizeof(ppd_rec_t)) == 0 && + (num_ppds = (fileinfo.st_size - sizeof(ppdsync)) / + sizeof(ppd_rec_t)) > 0) + { + /* + * We have a ppds.dat file, so read it! + */ + + for (; num_ppds > 0; num_ppds --) + { + if ((ppd = (ppd_info_t *)calloc(1, sizeof(ppd_info_t))) == NULL) + { + if (verbose) + fputs("ERROR: [cups-driverd] Unable to allocate memory for PPD!\n", + stderr); + exit(1); + } + + if (cupsFileRead(fp, (char *)&(ppd->record), sizeof(ppd_rec_t)) > 0) + { + cupsArrayAdd(PPDsByName, ppd); + cupsArrayAdd(PPDsByMakeModel, ppd); + } + else + { + free(ppd); + break; + } + } + + if (verbose) + fprintf(stderr, "INFO: [cups-driverd] Read \"%s\", %d PPDs...\n", + filename, cupsArrayCount(PPDsByName)); + } + + cupsFileClose(fp); + } +} + + +/* * 'regex_device_id()' - Compile a regular expression based on the 1284 device * ID. */ diff --git a/scheduler/cupsfilter.c b/scheduler/cupsfilter.c index 9685857c0..d3c30210a 100644 --- a/scheduler/cupsfilter.c +++ b/scheduler/cupsfilter.c @@ -1085,9 +1085,7 @@ get_job_file(const char *job) /* I - Job ID */ if ((tempfd = cupsTempFd(TempFile, sizeof(TempFile))) == -1) { - _cupsLangPrintf(stderr, - _("cupsfilter: Unable to create temporary file: %s\n"), - strerror(errno)); + _cupsLangPrintError(_("ERROR: Unable to create temporary file")); httpClose(http); exit(1); } diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index d876c5ac4..f41fb451b 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -47,6 +47,7 @@ * dnssdRegisterCallback() - DNSServiceRegister callback. * dnssdRegisterPrinter() - Start sending broadcast information for a * printer or update the broadcast contents. + * dnssdStop() - Stop all DNS-SD registrations. * dnssdUpdate() - Handle DNS-SD queries. * get_hostconfig() - Get an /etc/hostconfig service setting. * is_local_queue() - Determine whether the URI points at a local @@ -166,6 +167,7 @@ static void dnssdRegisterCallback(DNSServiceRef sdRef, const char *name, const char *regtype, const char *domain, void *context); static void dnssdRegisterPrinter(cupsd_printer_t *p); +static void dnssdStop(void); static void dnssdUpdate(void); #endif /* HAVE_DNSSD */ @@ -1816,29 +1818,7 @@ cupsdStopBrowsing(void) #ifdef HAVE_DNSSD if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef) - { - if (WebIFRef) - { - DNSServiceRefDeallocate(WebIFRef); - WebIFRef = NULL; - } - - if (RemoteRef) - { - DNSServiceRefDeallocate(RemoteRef); - RemoteRef = NULL; - } - - cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDRef)); - - DNSServiceRefDeallocate(DNSSDRef); - DNSSDRef = NULL; - - cupsArrayDelete(DNSSDPrinters); - DNSSDPrinters = NULL; - - DNSSDPort = 0; - } + dnssdStop(); #endif /* HAVE_DNSSD */ #ifdef HAVE_LIBSLP @@ -2812,6 +2792,53 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */ /* + * 'dnssdStop()' - Stop all DNS-SD registrations. + */ + +static void +dnssdStop(void) +{ + cupsd_printer_t *p; /* Current printer */ + + + /* + * De-register the individual printers + */ + + for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); + p; + p = (cupsd_printer_t *)cupsArrayNext(Printers)) + dnssdDeregisterPrinter(p); + + /* + * Shutdown the rest of the service refs... + */ + + if (WebIFRef) + { + DNSServiceRefDeallocate(WebIFRef); + WebIFRef = NULL; + } + + if (RemoteRef) + { + DNSServiceRefDeallocate(RemoteRef); + RemoteRef = NULL; + } + + cupsdRemoveSelect(DNSServiceRefSockFD(DNSSDRef)); + + DNSServiceRefDeallocate(DNSSDRef); + DNSSDRef = NULL; + + cupsArrayDelete(DNSSDPrinters); + DNSSDPrinters = NULL; + + DNSSDPort = 0; +} + + +/* * 'dnssdUpdate()' - Handle DNS-SD queries. */ @@ -2822,9 +2849,12 @@ dnssdUpdate(void) if ((sdErr = DNSServiceProcessResult(DNSSDRef)) != kDNSServiceErr_NoError) + { cupsdLogMessage(CUPSD_LOG_ERROR, "DNS Service Discovery registration error %d!", sdErr); + dnssdStop(); + } } #endif /* HAVE_DNSSD */ @@ -3509,6 +3539,18 @@ process_implicit_classes(void) else len = strlen(p->name); + if (len >= sizeof(name)) + { + /* + * If the printer name length somehow is greater than we normally allow, + * skip this printer... + */ + + len = 0; + cupsArrayRestore(Printers); + continue; + } + strncpy(name, p->name, len); name[len] = '\0'; offset = 0; @@ -5253,8 +5295,13 @@ update_polling(void) while ((ptr = cupsdStatBufUpdate(PollStatusBuffer, &loglevel, message, sizeof(message))) != NULL) + { + if (loglevel == CUPSD_LOG_INFO) + cupsdLogMessage(CUPSD_LOG_INFO, "%s", message); + if (!strchr(PollStatusBuffer->buffer, '\n')) break; + } if (ptr == NULL && !PollStatusBuffer->bufused) { diff --git a/scheduler/ipp.c b/scheduler/ipp.c index 783920c6e..82e7a7eca 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -299,6 +299,20 @@ cupsdProcessIPPRequest( con->request->request.any.version[0], con->request->request.any.version[1]); } + else if (con->request->request.any.request_id < 1) + { + /* + * Return an error, since request IDs must be between 1 and 2^31-1 + */ + + cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, + "%04X %s Bad request ID %d", + IPP_BAD_REQUEST, con->http.hostname, + con->request->request.any.request_id); + + send_ipp_status(con, IPP_BAD_REQUEST, _("Bad request ID %d!"), + con->request->request.any.request_id); + } else if (!con->request->attrs) { cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, diff --git a/scheduler/job.c b/scheduler/job.c index 752de5e5e..ee83e4c74 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -161,7 +161,8 @@ cupsdCancelJob(cupsd_job_t *job, /* I - Job to cancel */ * Stop any processes that are working on the current job... */ - printer = job->printer; + if ((printer = job->printer) == NULL) + printer = cupsdFindDest(job->dest); if (job->state_value == IPP_JOB_PROCESSING) cupsdStopJob(job, 0); @@ -622,7 +623,8 @@ cupsdFinishJob(cupsd_job_t *job) /* I - Job */ job->status_buffer = NULL; } - printer = job->printer; + if ((printer = job->printer) == NULL) + printer = cupsdFindDest(job->dest); update_job_attrs(job, 0); @@ -741,7 +743,7 @@ cupsdFinishJob(cupsd_job_t *job) /* I - Job */ set_hold_until(job, time(NULL) + JobRetryInterval); - cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, + cupsdAddEvent(CUPSD_EVENT_JOB_STATE, printer, job, "Job held due to fax errors; please consult " "the error_log file for details."); cupsdSetPrinterState(printer, IPP_PRINTER_IDLE, 0); @@ -3664,8 +3666,31 @@ update_job(cupsd_job_t *job) /* I - Job to check */ *ptr; /* Pointer update... */ int loglevel, /* Log level for message */ event = 0; /* Events? */ + cupsd_printer_t *printer; /* Printer for job */ + static const char * const levels[] = /* Log levels */ + { + "NONE", + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARN", + "NOTICE", + "INFO", + "DEBUG", + "DEBUG2" + }; + /* + * Get the printer associated with this job; if the printer is stopped for + * any reason then job->printer will be reset to NULL, so make sure we have + * a valid pointer... + */ + + if ((printer = job->printer) == NULL) + printer = cupsdFindDest(job->dest); + while ((ptr = cupsdStatBufUpdate(job->status_buffer, &loglevel, message, sizeof(message))) != NULL) { @@ -3698,9 +3723,9 @@ update_job(cupsd_job_t *job) /* I - Job to check */ job->sheets->values[0].integer += copies; - if (job->printer->page_limit) + if (printer->page_limit) { - cupsd_quota_t *q = cupsdUpdateQuota(job->printer, job->username, + cupsd_quota_t *q = cupsdUpdateQuota(printer, job->username, copies, 0); #ifdef __APPLE__ @@ -3713,8 +3738,8 @@ update_job(cupsd_job_t *job) /* I - Job to check */ cupsdLogJob(job, CUPSD_LOG_INFO, "Canceled because pages exceed user %s " "quota limit on printer %s (%s).", - job->username, job->printer->name, - job->printer->info); + job->username, printer->name, + printer->info); cupsdCancelJob(job, 1, IPP_JOB_CANCELED); return; @@ -3728,7 +3753,7 @@ update_job(cupsd_job_t *job) /* I - Job to check */ cupsdLogPage(job, message); if (job->sheets) - cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, job->printer, job, + cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, printer, job, "Printed %d page(s).", job->sheets->values[0].integer); } else if (loglevel == CUPSD_LOG_STATE) @@ -3737,13 +3762,13 @@ update_job(cupsd_job_t *job) /* I - Job to check */ if (!strcmp(message, "paused")) { - cupsdStopPrinter(job->printer, 1); + cupsdStopPrinter(printer, 1); return; } else { - cupsdSetPrinterReasons(job->printer, message); - cupsdAddPrinterHistory(job->printer); + cupsdSetPrinterReasons(printer, message); + cupsdAddPrinterHistory(printer); event |= CUPSD_EVENT_PRINTER_STATE; } @@ -3767,10 +3792,10 @@ update_job(cupsd_job_t *job) /* I - Job to check */ if ((attr = cupsGetOption("auth-info-required", num_attrs, attrs)) != NULL) { - cupsdSetAuthInfoRequired(job->printer, attr, NULL); - cupsdSetPrinterAttrs(job->printer); + cupsdSetAuthInfoRequired(printer, attr, NULL); + cupsdSetPrinterAttrs(printer); - if (job->printer->type & CUPS_PRINTER_DISCOVERED) + if (printer->type & CUPS_PRINTER_DISCOVERED) cupsdMarkDirty(CUPSD_DIRTY_REMOTE); else cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); @@ -3787,7 +3812,7 @@ update_job(cupsd_job_t *job) /* I - Job to check */ job->progress = progress; if (job->sheets) - cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, job->printer, job, + cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, printer, job, "Printing page %d, %d%%", job->sheets->values[0].integer, job->progress); } @@ -3795,69 +3820,69 @@ update_job(cupsd_job_t *job) /* I - Job to check */ if ((attr = cupsGetOption("printer-alert", num_attrs, attrs)) != NULL) { - cupsdSetString(&job->printer->alert, attr); + cupsdSetString(&printer->alert, attr); event |= CUPSD_EVENT_PRINTER_STATE; } if ((attr = cupsGetOption("printer-alert-description", num_attrs, attrs)) != NULL) { - cupsdSetString(&job->printer->alert_description, attr); + cupsdSetString(&printer->alert_description, attr); event |= CUPSD_EVENT_PRINTER_STATE; } if ((attr = cupsGetOption("marker-colors", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-colors", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-colors", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-levels", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-levels", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-levels", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-low-levels", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-low-levels", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-low-levels", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-high-levels", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-high-levels", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-high-levels", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-message", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-message", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-message", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-names", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-names", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-names", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } if ((attr = cupsGetOption("marker-types", num_attrs, attrs)) != NULL) { - cupsdSetPrinterAttr(job->printer, "marker-types", (char *)attr); - job->printer->marker_time = time(NULL); + cupsdSetPrinterAttr(printer, "marker-types", (char *)attr); + printer->marker_time = time(NULL); event |= CUPSD_EVENT_PRINTER_STATE; cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); } @@ -3878,8 +3903,8 @@ update_job(cupsd_job_t *job) /* I - Job to check */ num_keywords = cupsParseOptions(message, 0, &keywords); - if (cupsdUpdatePrinterPPD(job->printer, num_keywords, keywords)) - cupsdSetPrinterAttrs(job->printer); + if (cupsdUpdatePrinterPPD(printer, num_keywords, keywords)) + cupsdSetPrinterAttrs(printer); cupsFreeOptions(num_keywords, keywords); } @@ -3892,24 +3917,22 @@ update_job(cupsd_job_t *job) /* I - Job to check */ if (*ptr) { - cupsdSetPrinterReasons(job->printer, - "+com.apple.print.recoverable-warning"); - cupsdSetString(&job->printer->recoverable, ptr); - cupsdAddPrinterHistory(job->printer); + cupsdSetPrinterReasons(printer, "+com.apple.print.recoverable-warning"); + cupsdSetString(&(printer->recoverable), ptr); + cupsdAddPrinterHistory(printer); event |= CUPSD_EVENT_PRINTER_STATE; } } else if (!strncmp(message, "recovered:", 10)) { - cupsdSetPrinterReasons(job->printer, - "-com.apple.print.recoverable-warning"); + cupsdSetPrinterReasons(printer, "-com.apple.print.recoverable-warning"); ptr = message + 10; while (isspace(*ptr & 255)) ptr ++; - cupsdSetString(&job->printer->recoverable, ptr); - cupsdAddPrinterHistory(job->printer); + cupsdSetString(&(printer->recoverable), ptr); + cupsdAddPrinterHistory(printer); event |= CUPSD_EVENT_PRINTER_STATE; } #endif /* __APPLE__ */ @@ -3919,9 +3942,9 @@ update_job(cupsd_job_t *job) /* I - Job to check */ if (loglevel < CUPSD_LOG_DEBUG) { - strlcpy(job->printer->state_message, message, - sizeof(job->printer->state_message)); - cupsdAddPrinterHistory(job->printer); + strlcpy(printer->state_message, message, + sizeof(printer->state_message)); + cupsdAddPrinterHistory(printer); event |= CUPSD_EVENT_PRINTER_STATE; @@ -3935,6 +3958,12 @@ update_job(cupsd_job_t *job) /* I - Job to check */ job->status_level = loglevel; update_job_attrs(job, 1); + + cupsdLogJob(job, CUPSD_LOG_DEBUG, + "Set job-printer-state-message to \"%s\", " + "current level=%s", + job->printer_message->values[0].string.text, + levels[job->status_level]); } } } @@ -3944,11 +3973,11 @@ update_job(cupsd_job_t *job) /* I - Job to check */ } if (event & CUPSD_EVENT_PRINTER_STATE) - cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, job->printer, NULL, - (job->printer->type & CUPS_PRINTER_CLASS) ? + cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL, + (printer->type & CUPS_PRINTER_CLASS) ? "Class \"%s\" state changed." : "Printer \"%s\" state changed.", - job->printer->name); + printer->name); if (ptr == NULL && !job->status_buffer->bufused) { @@ -3983,11 +4012,10 @@ update_job_attrs(cupsd_job_t *job, /* I - Job to update */ int do_message)/* I - 1 = update job-printer-state message */ { int i; /* Looping var */ + cupsd_printer_t *printer; /* Printer for job */ int num_reasons; /* Actual number of reasons */ const char * const *reasons; /* Reasons */ - static const char *none = "none", /* "none" */ - *paused = "paused"; - /* "paused" */ + static const char *none = "none"; /* "none" reason */ /* @@ -4009,35 +4037,34 @@ update_job_attrs(cupsd_job_t *job, /* I - Job to update */ "job-printer-state-reasons", IPP_TAG_KEYWORD); - /* - * If the job isn't printing, return now... - */ + if ((printer = job->printer) == NULL) + printer = cupsdFindDest(job->dest); - if (!job->printer) + if (!printer) return; /* * Otherwise copy the printer-state-message value... */ - if (job->printer->state_message[0] && + if (printer->state_message[0] && (do_message || !job->printer_message->values[0].string.text[0])) cupsdSetString(&(job->printer_message->values[0].string.text), - job->printer->state_message); + printer->state_message); /* * ... and the printer-state-reasons value... */ - if (job->printer->num_reasons == 0) + if (printer->num_reasons == 0) { num_reasons = 1; - reasons = job->printer->state == IPP_PRINTER_STOPPED ? &paused : &none; + reasons = &none; } else { - num_reasons = job->printer->num_reasons; - reasons = (const char * const *)job->printer->reasons; + num_reasons = printer->num_reasons; + reasons = (const char * const *)printer->reasons; } if (!job->printer_reasons || job->printer_reasons->num_values != num_reasons) diff --git a/scheduler/printers.c b/scheduler/printers.c index b6d7bce61..003210aa4 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -119,7 +119,7 @@ cupsdAddPrinter(const char *name) /* I - Name of printer */ cupsdSetString(&p->hostname, ServerName); cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name); - cupsdSetDeviceURI(p, "file:/dev/null"); + cupsdSetDeviceURI(p, "file:///dev/null"); p->state = IPP_PRINTER_STOPPED; p->state_time = time(NULL); diff --git a/scheduler/statbuf.c b/scheduler/statbuf.c index c4959cfbe..925b60169 100644 --- a/scheduler/statbuf.c +++ b/scheduler/statbuf.c @@ -4,7 +4,7 @@ * Status buffer routines for the Common UNIX Printing System (CUPS) * scheduler. * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2009 by Apple Inc. * Copyright 1997-2006 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -118,13 +118,11 @@ cupsdStatBufNew(int fd, /* I - File descriptor of pipe */ */ char * /* O - Line from buffer, "", or NULL */ -cupsdStatBufUpdate(cupsd_statbuf_t *sb, /* I - Status buffer */ - int *loglevel, - /* O - Log level */ - char *line, - /* I - Line buffer */ - int linelen) - /* I - Size of line buffer */ +cupsdStatBufUpdate( + cupsd_statbuf_t *sb, /* I - Status buffer */ + int *loglevel, /* O - Log level */ + char *line, /* I - Line buffer */ + int linelen) /* I - Size of line buffer */ { int bytes; /* Number of bytes read */ char *lineptr, /* Pointer to end of line in buffer */ diff --git a/scheduler/subscriptions.c b/scheduler/subscriptions.c index 2247d12de..4412c33d7 100644 --- a/scheduler/subscriptions.c +++ b/scheduler/subscriptions.c @@ -1664,8 +1664,13 @@ cupsd_update_notifier(void) while (cupsdStatBufUpdate(NotifierStatusBuffer, &loglevel, message, sizeof(message))) + { + if (loglevel == CUPSD_LOG_INFO) + cupsdLogMessage(CUPSD_LOG_INFO, "%s", message); + if (!strchr(NotifierStatusBuffer->buffer, '\n')) break; + } } |