Skip to content

Commit

Permalink
cups-browsed: Cleaned up code to determine to which CUPS server to co…
Browse files Browse the repository at this point in the history
…nnect
  • Loading branch information
tillkamppeter committed May 7, 2020
1 parent f9ca9bc commit 1712ee2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ NEWS - OpenPrinting CUPS Filters v1.27.4 - 2020-04-09

CHANGES IN V1.27.5

- cups-browsed: Cleaned up code for determining to which CUPS
server (host/port/domain socket) to connect, so that
connection via DomainSocket cups-browsed.conf directive,
CUPS_SERVER and IPP_PORT environment variables and all
defaults and methods of libcups, including CUPS' client.conf
work.
- gstoraster, rastertopdf: Do not pass NULL to fprintf() (Pull
request #230).
- libcupsfilters: Silence compiler warning (Pull request #229).
Expand Down
35 changes: 19 additions & 16 deletions utils/cups-browsed.c
Original file line number Diff line number Diff line change
Expand Up @@ -12112,43 +12112,46 @@ int main(int argc, char*argv[]) {
if (getenv("IPP_PORT") != NULL) {
snprintf(local_server_str, sizeof(local_server_str) - 1,
"localhost:%s", getenv("IPP_PORT"));
if (strlen(getenv("CUPS_SERVER")) > 1023)
local_server_str[1023] = '\0';
local_server_str[sizeof(local_server_str) - 1] = '\0';
cupsSetServer(local_server_str);
debug_printf("Set port on which CUPS is listening via env variable: IPP_PORT=%s\n",
getenv("IPP_PORT"));
}

/* Point to selected CUPS server or domain socket via the CUPS_SERVER
environment variable or DomainSocket configuration file option.
Default to localhost:631 (and not to CUPS default to override
client.conf files as cups-browsed works only with a local CUPS
daemon, not with remote ones. */
local_server_str[0] = '\0';
if (getenv("CUPS_SERVER") != NULL) {
strncpy(local_server_str, getenv("CUPS_SERVER"),
sizeof(local_server_str) - 1);
if (strlen(getenv("CUPS_SERVER")) > 1023)
local_server_str[1023] = '\0';
local_server_str[sizeof(local_server_str) - 1] = '\0';
cupsSetServer(local_server_str);
debug_printf("Set host/port/domain socket which CUPS is listening via env variable: CUPS_SERVER=%s\n",
getenv("CUPS_SERVER"));
} else {
#ifdef CUPS_DEFAULT_DOMAINSOCKET
if (DomainSocket == NULL)
DomainSocket = strdup(CUPS_DEFAULT_DOMAINSOCKET);
#endif
if (DomainSocket != NULL) {
debug_printf("Set host/port/domain socket on which CUPS is listening via cups-browsed directive DomainSocket: %s\n",
DomainSocket);
struct stat sockinfo; /* Domain socket information */
if (strcasecmp(DomainSocket, "None") != 0 &&
strcasecmp(DomainSocket, "Off") != 0 &&
!stat(DomainSocket, &sockinfo) &&
(sockinfo.st_mode & S_IROTH) != 0 &&
(sockinfo.st_mode & S_IWOTH) != 0)
(sockinfo.st_mode & S_IWOTH) != 0) {
strncpy(local_server_str, DomainSocket,
sizeof(local_server_str) - 1);
else
strncpy(local_server_str, "localhost:631",
sizeof(local_server_str) - 1);
} else
strncpy(local_server_str, "localhost:631", sizeof(local_server_str));
setenv("CUPS_SERVER", local_server_str, 1);
local_server_str[sizeof(local_server_str) - 1] = '\0';
cupsSetServer(local_server_str);
} else
debug_printf("DomainSocket %s not accessible: %s\n",
DomainSocket, strerror(errno));
}
}
cupsSetServer(local_server_str);
if (local_server_str[0])
setenv("CUPS_SERVER", local_server_str, 1);

if (BrowseLocalProtocols & BROWSE_DNSSD) {
debug_printf("Local support for DNSSD not implemented\n");
Expand Down

0 comments on commit 1712ee2

Please sign in to comment.