michaelrsweet / pappl

PAPPL - Printer Application Framework
https://www.msweet.org/pappl
Apache License 2.0
310 stars 50 forks source link

The printer(s) cannot be loaded from the state file again after restart pappl #298

Closed tangyanli closed 1 year ago

tangyanli commented 1 year ago

Describe the bug The printer(s) cannot be loaded from the state file again after restart pappl

To Reproduce Steps to reproduce the behavior:

  1. Build and run legacy-printer-app
  2. And several printers on the web page
  3. Shutdown the legacy-printer-app
  4. Run the legacy-printer-app again, the pappl cannot load the printers from the state file again.

Expected behavior The pappl can load the printers from the state file again.

System Information:

Additional context In the papplSystemSaveState() file, 6 options are saved for a printer.

num_options = cupsAddIntegerOption("id", printer->printer_id, num_options, &options);
num_options = cupsAddOption("name", printer->name, num_options, &options);
num_options = cupsAddOption("did", printer->device_id ? printer->device_id : "", num_options, &options);
num_options = cupsAddOption("uri", printer->device_uri, num_options, &options);
num_options = cupsAddOption("driver", printer->driver_name, num_options, &options);

if (system->options & PAPPL_SOPTIONS_MULTI_QUEUE)
    num_options = cupsAddIntegerOption("state", (int)printer->state, num_options, &options);

But in the papplSystemLoadState(), the printer is skipped when it's option number is not equal to 5.

if ((num_options = cupsParseOptions(value, 0, &options)) != 5 ||
    (printer_id = cupsGetOption("id", num_options, options)) == NULL ||  strtol(printer_id, NULL, 10) <= 0 || 
    (printer_name = cupsGetOption("name", num_options, options)) == NULL || 
    (device_id = cupsGetOption("did", num_options, options)) == NULL || 
    (device_uri = cupsGetOption("uri", num_options, options)) == NULL || 
    (driver_name = cupsGetOption("driver", num_options, options)) == NULL)
    {
     papplLog(system, PAPPL_LOGLEVEL_ERROR, "Bad printer definition on line %d of '%s'.", linenum, filename);
    break;
    }
michaelrsweet commented 1 year ago

[master dc8e97b] Fix loading of previous state (Issue #298)

[v1.4.x 3a3c1e9] Fix loading of previous state (Issue #298)