Skip to content

Commit

Permalink
Merge pull request #218 from V1krant/master
Browse files Browse the repository at this point in the history
cups-browsed: Added AllowResharingRemoteCUPSPrinters and NewBrowsePollQueuesShared configuration directives
  • Loading branch information
tillkamppeter authored Mar 20, 2020
2 parents ca877d0 + b6cbd1f commit 5f75a5b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
35 changes: 32 additions & 3 deletions utils/cups-browsed.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ static unsigned int BrowseInterval = 60;
static unsigned int BrowseTimeout = 300;
static uint16_t BrowsePort = 631;
static browsepoll_t **BrowsePoll = NULL;
static unsigned int NewBrowsePollQueuesShared = 0;
static unsigned int AllowResharingRemoteCUPSPrinters = 0;
static size_t NumBrowsePoll = 0;
static guint update_netifs_sourceid = 0;
static char local_server_str[1024];
Expand Down Expand Up @@ -7897,7 +7899,7 @@ gboolean update_cups_queues(gpointer unused) {
* only if we have CUPS older than 2.2.
* When you have remote queue, clean up and break from the loop.
*/
if (p->netprinter != 0 || !HAVE_CUPS_2_2)
if (p->netprinter != 0 || !HAVE_CUPS_2_2 || AllowResharingRemoteCUPSPrinters)
ippDelete(cupsDoRequest(http, request, "/admin/"));
else {
ippDelete(request);
Expand Down Expand Up @@ -8465,7 +8467,8 @@ gboolean update_cups_queues(gpointer unused) {
if (p->netprinter == 0 &&
strncmp(line, "*%", 2) &&
strncmp(line, "*PPD-Adobe:", 11) &&
ap_remote_queue_id_line_inserted == 0) {
ap_remote_queue_id_line_inserted == 0 &&
!AllowResharingRemoteCUPSPrinters) {
ap_remote_queue_id_line_inserted = 1;
cupsFilePrintf(out, "*APRemoteQueueID: \"\"\n");
}
Expand Down Expand Up @@ -8605,6 +8608,12 @@ gboolean update_cups_queues(gpointer unused) {
num_options = cupsAddOption("printer-is-shared", "true",
num_options, &options);
debug_printf("Setting printer-is-shared bit.\n");
} else if (NewBrowsePollQueuesShared &&
(val = cupsGetOption("printer-to-be-shared", p->num_options,
p->options)) != NULL) {
num_options = cupsAddOption("printer-is-shared", "true",
num_options, &options);
debug_printf("Setting printer-is-shared bit.\n");
} else {
num_options = cupsAddOption("printer-is-shared", "false",
num_options, &options);
Expand All @@ -8617,7 +8626,7 @@ gboolean update_cups_queues(gpointer unused) {
* network printer or if we have remote CUPS queue, do IPP request
* only if we have CUPS older than 2.2.
*/
if (p->netprinter != 0 || !HAVE_CUPS_2_2)
if (p->netprinter != 0 || !HAVE_CUPS_2_2 || AllowResharingRemoteCUPSPrinters)
ippDelete(cupsDoRequest(http, request, "/admin/"));
else
ippDelete(request);
Expand Down Expand Up @@ -10417,12 +10426,18 @@ found_cups_printer (const char *remote_host, const char *uri,
(printer->domain == NULL || printer->domain[0] == '\0' ||
printer->type == NULL || printer->type[0] == '\0')) {
printer->is_legacy = 1;

if (printer->status != STATUS_TO_BE_CREATED) {
printer->timeout = time(NULL) + BrowseTimeout;
debug_printf("starting BrowseTimeout timer for %s (%ds)\n",
printer->queue_name, BrowseTimeout);
}
}

if (printer && NewBrowsePollQueuesShared &&
(HAVE_CUPS_1_6 || (!HAVE_CUPS_1_6 && !printer->is_legacy)))
printer->num_options = cupsAddOption("printer-to-be-shared", "true", printer->num_options, &(printer->options));

}

gboolean
Expand Down Expand Up @@ -11588,6 +11603,20 @@ read_configuration (const char *filename)
else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") ||
!strcasecmp(value, "off") || !strcasecmp(value, "0"))
NewIPPPrinterQueuesShared = 0;
} else if (!strcasecmp(line, "AllowResharingRemoteCUPSPrinters") && value) {
if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") ||
!strcasecmp(value, "on") || !strcasecmp(value, "1"))
AllowResharingRemoteCUPSPrinters = 1;
else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") ||
!strcasecmp(value, "off") || !strcasecmp(value, "0"))
AllowResharingRemoteCUPSPrinters = 0;
} else if (!strcasecmp(line, "NewBrowsePollQueuesShared") && value) {
if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") ||
!strcasecmp(value, "on") || !strcasecmp(value, "1"))
NewBrowsePollQueuesShared = 1;
else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") ||
!strcasecmp(value, "off") || !strcasecmp(value, "0"))
NewBrowsePollQueuesShared = 0;
} else if (!strcasecmp(line, "AutoClustering") && value) {
if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") ||
!strcasecmp(value, "on") || !strcasecmp(value, "1"))
Expand Down
25 changes: 25 additions & 0 deletions utils/cups-browsed.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,31 @@ this timeout if no further broadcast from the server happens.
.fam C
BrowseTimeout 300

.fam T
.fi
The AllowResharingRemoteCUPSPrinters directive determines whether a
print queue pointing to a remote CUPS queue will be re-shared to the
local network or not. Since the queues generated using the BrowsePoll
directive are also pointing to remote queues, they are also shared
automatically if the following option is set. Default is not to share
remote queues.
.PP
.nf
.fam C
AllowResharingRemoteCUPSPrinters Yes

.fam T
.fi
The NewBrowsePollQueuesShared directive determines whether a print
queue for a newly discovered printer (discovered by the BrowsePoll directive)
will be shared to the local network or not. This directive will only work
if AllowResharingRemoteCUPSPrinters is set to yes. Default is
not to share printers discovered using BrowsePoll.
.PP
.nf
.fam C
NewBrowsePollQueuesShared Yes

.fam T
.fi
Set OnlyUnsupportedByCUPS to "Yes" will make cups-browsed not create
Expand Down
17 changes: 16 additions & 1 deletion utils/cups-browsed.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ BrowseRemoteProtocols @BROWSEREMOTEPROTOCOLS@

# BrowseTimeout 300


# Filtering of remote printers by other properties than IP addresses
# of their servers

Expand Down Expand Up @@ -436,6 +435,22 @@ BrowseRemoteProtocols @BROWSEREMOTEPROTOCOLS@
# IPBasedDeviceURIs IPv4
# IPBasedDeviceURIs IPv6

# The AllowResharingRemoteCUPSPrinters directive determines whether a
# print queue pointing to a remote CUPS queue will be re-shared to the
# local network or not. Since the queues generated using the BrowsePoll
# directive are also pointing to remote queues, they are also shared
# automatically if the following option is set. Default is not to share
# remote printers.

# AllowResharingRemoteCUPSPrinters Yes

# The NewBrowsePollQueuesShared directive determines whether a print
# queue for a newly discovered printer (discovered by the BrowsePoll directive)
# will be shared to the local network or not. This directive will only work
# if AllowResharingRemoteCUPSPrinters is set to yes. Default is
# not to share printers discovered using BrowsePoll.

# NewBrowsePollQueuesShared Yes

# Set CreateRemoteRawPrinterQueues to "Yes" to let cups-browsed also
# create local queues pointing to remote raw CUPS queues. Normally,
Expand Down

0 comments on commit 5f75a5b

Please sign in to comment.