Skip to content

Commit

Permalink
Save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Jul 10, 2024
1 parent f5cb8a1 commit acfcdb7
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
38 changes: 38 additions & 0 deletions pappl/printer-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,44 @@ papplPrinterGetSystem(
}


//
// 'papplPrinterGetURI()' - Get the URI for the printer.
//
// This function returns the "printer-uri" value to use for the printer.
// Access over the loopback interface uses the "ipp" URI scheme while all others
// use the "ipps" URI scheme.
//
// The provided buffer should be at least 512 bytes in size to allow for the
// maximum length host and printer names.
//

char * // O - Printer URI
papplPrinterGetURI(
pappl_printer_t *printer, // I - Printer
char *buffer, // I - URI buffer
size_t bufsize) // I - Size of URI buffer
{
char hostname[256]; // URI hostname


// Range check input...
if (buffer)
*buffer = '\0';

if (!printer || !buffer || bufsize < 32)
return (NULL);

// Get the hostname for the system...
if (!papplSystemGetHostName(printer->system, hostname, sizeof(hostname)))
return (NULL);

// Format the printer's URI and return it...
httpAssembleURI(HTTP_URI_CODING_ALL, buffer, bufsize, !strcmp(hostname, "localhost") ? "ipp" : "ipps", /*userpass*/NULL, hostname, printer->system->port, printer->resource);

return (buffer);
}


//
// 'papplPrinterHoldNewJobs()' - Hold new jobs for printing.
//
Expand Down
3 changes: 2 additions & 1 deletion pappl/printer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ struct _pappl_printer_s // Printer data
pappl_pr_usb_cb_t usb_cb; // USB processing callback, if any
void *usb_cbdata; // USB processing callback data, if any

bool proxy_active; // Proxy active?
bool proxy_active, // Proxy active?
proxy_terminate; // Terminate proxy?
char *proxy_name, // Proxy common_name value
*proxy_uri, // Proxy printer-uri value
*proxy_uuid; // Proxy output-device-uuid value
Expand Down
33 changes: 31 additions & 2 deletions pappl/printer-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,45 @@ void * // O - Thread exit status
_papplPrinterRunProxy(
pappl_printer_t *printer) // I - Printer
{
http_t *http = NULL; // Connection to server
char resource[1024]; // Resource path
ipp_t *request, // IPP request
*response; // IPP response
ipp_attribute_t *attr; // Current IPP attribute
int sub_id = 0, // Event subscription ID
seq_number = 0; // Event sequence number
bool update_jobs = true; // Do an Update-Active-Jobs request?
time_t update_time = 0; // Next update time


papplLogPrinter(printer, PAPPL_LOGLEVEL_DEBUG, "Running proxy thread.");

// Update the list of current proxy jobs...
_papplRWLockWrite(printer);
printer->proxy_active = true;
update_proxy_jobs(printer);
_papplRWUnlock(printer);

while (!papplPrinterIsDeleted(printer) && papplSystemIsRunning(printer->system))
while (!printer->proxy_terminate && !papplPrinterIsDeleted(printer) && papplSystemIsRunning(printer->system))
{
// TODO: Get notifications...
// See if we have anything to do...
if (sub_id > 0 && !update_jobs && (time(NULL) - update_time) < 5)
{
// Nothing to do, sleep for 1 second and then continue...
sleep(1);
continue;
}

// Connect to the infrastructure printer...
if (!http && (http = httpConnectURI(printer->proxy_uri, /*host*/NULL, /*hsize*/0, /*port*/NULL, resource, sizeof(resource), /*blocking*/true, /*msec*/30000, /*cancel*/NULL, /*require_ca*/false)) == NULL)
{
papplLogPrinter(printer, PAPPL_LOGLEVEL_ERROR, "Unable to connect to infrastructure printer '%s': %s", printer->proxy_uri, cupsGetErrorString());
sleep(1);
continue;
}



sleep(1);
}

Expand Down
1 change: 1 addition & 0 deletions pappl/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ extern pappl_preason_t papplPrinterGetReasons(pappl_printer_t *printer) _PAPPL_P
extern ipp_pstate_t papplPrinterGetState(pappl_printer_t *printer) _PAPPL_PUBLIC;
extern size_t papplPrinterGetSupplies(pappl_printer_t *printer, size_t max_supplies, pappl_supply_t *supplies) _PAPPL_PUBLIC;
extern pappl_system_t *papplPrinterGetSystem(pappl_printer_t *printer) _PAPPL_PUBLIC;
extern char *papplPrinterGetURI(pappl_printer_t *printer, char *buffer, size_t bufsize) _PAPPL_PUBLIC;

extern bool papplPrinterHoldNewJobs(pappl_printer_t *printer) _PAPPL_PUBLIC;
extern void papplPrinterHTMLFooter(pappl_client_t *client) _PAPPL_PUBLIC;
Expand Down

0 comments on commit acfcdb7

Please sign in to comment.