Skip to content

Commit

Permalink
Save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 1, 2024
1 parent bf0b130 commit 9293865
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 18 deletions.
57 changes: 56 additions & 1 deletion pappl/printer-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,28 @@ papplPrinterGetURI(
}


//
// 'papplPrinterGetUUID()' - Get the UUID associated with a printer.
//

const char * // O - UUID string
papplPrinterGetUUID(
pappl_printer_t *printer) // I - Printer
{
const char *uuid = NULL; // UUID string


if (printer)
{
_papplRWLockRead(printer);
uuid = ippGetString(ippFindAttribute(printer->attrs, "printer-uuid", IPP_TAG_URI), 0, NULL);
_papplRWUnlock(printer);
}

return (uuid);
}


//
// 'papplPrinterHoldNewJobs()' - Hold new jobs for printing.
//
Expand Down Expand Up @@ -1774,7 +1796,24 @@ papplPrinterSetProxy(

_papplRWLockWrite(printer);

// TODO: Start/stop proxy?
if (printer->proxy_active)
{
// Terminate proxy thread...
printer->proxy_terminate = true;

while (printer->proxy_active)
{
_papplRWUnlock(printer);

sleep(1);

_papplRWLockWrite(printer);
}

printer->proxy_terminate = false;
}

// Update the proxy information...
free(printer->proxy_name);
free(printer->proxy_uri);
free(printer->proxy_uuid);
Expand All @@ -1786,6 +1825,22 @@ papplPrinterSetProxy(
_papplRWUnlock(printer);

_papplSystemConfigChanged(printer->system);

// If the system is running, start the proxy...
if (printer->system->is_running && printer->proxy_name)
{
cups_thread_t tid; // Thread ID

if ((tid = cupsThreadCreate((void *(*)(void *))_papplPrinterRunProxy, printer)) == CUPS_THREAD_INVALID)
{
// Unable to create listener thread...
papplLogPrinter(printer, PAPPL_LOGLEVEL_ERROR, "Unable to create proxy thread: %s", strerror(errno));
}
else
{
cupsThreadDetach(tid);
}
}
}


Expand Down
31 changes: 25 additions & 6 deletions pappl/printer-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,38 @@ _papplPrinterConnectProxy(
pappl_printer_t *printer) // I - Printer
{
http_t *http = NULL; // Connection to server
char resource[1024]; // Resource path
char uri[1024], // Proxy URI
resource[1024]; // Resource path
char *creds, // Public key and certificate, if any
*key; // Private key, if any
// char *token; // OAuth 2.0 access token, if any
// time_t token_expires; // Access token expiration date/time


// TODO: Add client credentials support using proxy_uuid as common name
_papplRWLockWrite(printer);
// Copy the Infrastructure Printer URI...
_papplRWLockRead(printer);
cupsCopyString(uri, printer->proxy_uri, sizeof(uri));

// Get any client credentials using the proxy UUID...
creds = cupsCopyCredentials(/*path*/NULL, printer->proxy_uuid);
key = cupsCopyCredentials(/*path*/NULL, printer->proxy_uuid);
_papplRWUnlock(printer);

cupsSetClientCredentials(creds, key);

if ((http = httpConnectURI(printer->proxy_uri, /*host*/NULL, /*hsize*/0, /*port*/NULL, resource, sizeof(resource), /*blocking*/true, /*msec*/30000, /*cancel*/NULL, /*require_ca*/false)) == NULL)
// Connect to the Infrastructure Printer...
if ((http = httpConnectURI(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());
else if (!printer->proxy_resource)
printer->proxy_resource = strdup(resource);
return (NULL);
}

_papplRWLockWrite(printer);
if (!printer->proxy_resource)
printer->proxy_resource = strdup(resource);
_papplRWUnlock(printer);

// TODO: Set OAuth bearer (access) token, if present...
return (http);
}

Expand Down
1 change: 1 addition & 0 deletions pappl/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ 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 const char *papplPrinterGetUUID(pappl_printer_t *printer) _PAPPL_PUBLIC;

extern bool papplPrinterHoldNewJobs(pappl_printer_t *printer) _PAPPL_PUBLIC;
extern void papplPrinterHTMLFooter(pappl_client_t *client) _PAPPL_PUBLIC;
Expand Down
4 changes: 2 additions & 2 deletions pappl/system-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2602,10 +2602,10 @@ papplSystemSetPrinterDrivers(
// /* Return requested printer */
// return (requested_printer);
// }
// else if (papplSystemGetNumberOfPrinter(papplClientGetSystem(client)) < 32)
// else if (papplSystemGetNumberOfPrinters(papplClientGetSystem(client)) < 32)
// {
// /* Return new printer */
// return (papplPrinterCreateInfra(papplClientGetSystem(system), /*printer_id*/0, /*printer_name*/device_uuid, /*num_device_uuids*/1, &device_uuid));
// return (papplPrinterCreateInfra(papplClientGetSystem(client), /*printer_id*/0, /*printer_name*/device_uuid, /*num_device_uuids*/1, &device_uuid));
// }
// else
// {
Expand Down
17 changes: 17 additions & 0 deletions pappl/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ papplSystemRun(pappl_system_t *system) // I - System
cupsThreadDetach(tid);
}
}

if (printer->proxy_uri)
{
cups_thread_t tid; // Thread ID

papplLogPrinter(printer, PAPPL_LOGLEVEL_INFO, "Starting proxy thread for '%s'.", printer->proxy_uri);

if ((tid = cupsThreadCreate((void *(*)(void *))_papplPrinterRunProxy, printer)) == CUPS_THREAD_INVALID)
{
// Unable to create listener thread...
papplLogPrinter(printer, PAPPL_LOGLEVEL_ERROR, "Unable to create proxy thread: %s", strerror(errno));
}
else
{
cupsThreadDetach(tid);
}
}
}

// Start the USB gadget as needed...
Expand Down
4 changes: 2 additions & 2 deletions testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ test: testpappl
$(MKDIR) testpappl.output
echo "./testhttpmon"
./testhttpmon 2>test.log
echo "./testpappl -c -l testpappl.log -L debug -o testpappl.output -t api,client,pwg-raster,client-10x1000,idle-shutdown"
./testpappl -c -l testpappl.log -L debug -o testpappl.output -t api,client,pwg-raster,client-10x1000,idle-shutdown 2>test.log
echo "./testpappl -c -l testpappl.log -L debug -o testpappl.output -t api,client,pwg-raster,infra,client-10x1000,idle-shutdown"
./testpappl -c -l testpappl.log -L debug -o testpappl.output -t api,client,pwg-raster,infra,client-10x1000,idle-shutdown 2>test.log


# HTTP monitor unit test
Expand Down
Loading

0 comments on commit 9293865

Please sign in to comment.