Closed michaelrsweet closed 12 years ago
CUPS.org User: mike
The changes still need to conform to the CUPS coding standards (mainly comments are missing), and I'd rather make the code HAVE_AVAHI or HAVE_DNSSD (but only one gets defined). We can worry about adding configure options to choose which implementation to use at the end - some Linux distros come with mDNSResponder instead of Avahi.
I think you are going to have serious problems implementing Avahi in the scheduler since it is so tightly coupled to glib (or that's how it looked when I investigated adding "native" Avahi support last year), and the lack of documentation on the low-level interfaces that don't depend on glib (which is probably what you'll need to use) won't help either.
Finally, the source changes will be large enough we'll probably need a copyright assignment or at least a licensing to Apple to keep the CUPS sources (legally) clean.
Moving to -feature for now; if we end up with a complete implementation before 1.4.0 is released and have any legal issues resolved, it can go in 1.4.x, otherwise probably 1.5.x.
CUPS.org User: martin.pitt.canonical
Please note that this
causes the test suite to fail when being run without a running system D-BUS instance:
FAIL: 20 error messages, expected 18. [...] E [25/Aug/2009:16:17:48.540155 +0000] [CGI] Unable to create avahi client: No such file or directory E [25/Aug/2009:16:17:48.540492 +0000] [cups-deviced] PID 22335 (dnssd) stopped with status 1!
This is usually the case when calling "make check" during package build on build servers. It's usually a great idea to enable the tests during package build to catch regressions on particular architectures or from underlying libraries, so I wouldn't like to lose this feature. Perhaps this can be toned down to a mere printf() to stdout (for debugging), and exit cleanly?
CUPS.org User: martin.pitt.canonical
Just for the records, this is what avahi_client_new() tries:
connect(5, {sa_family=AF_FILE, path="/var/run/dbus/system_bus_socket"}, 33) = -1 ENOENT (No such file or directory)
Slightly altering the code snippet to
keeps the test suite happy. Would this be acceptable?
CUPS.org User: twaugh.redhat
It's the avahi equivalent of this:
if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErr_NoError) { perror("ERROR: Unable to create service connection"); return (1); }
So if one has to change, the other also has to change.
CUPS.org User: Spudd86
might I suggest using pkg-config to detect avahi rather than AC_CHECK_HEADER
so you do like this instead:
PKG_CHECK_MODULES([AVAHI], [avahi-client]) AC_SUBST(AVAHI_CFLAGS) AC_SUBST(AVAHI_LIBS)
(with changes to make stuff work... but that's the idea)
CUPS.org User: twaugh.redhat
Note that the current version of the patch is here:
http://cvs.fedoraproject.org/viewvc/devel/cups/cups-avahi.patch?view=markup
and that further work is required for Avahi support in the scheduler.
CUPS.org User: twaugh.redhat
Having implemented native Avahi support for branch-1.4, I've now split it up into separate functional pieces and have begun re-basing them to trunk.
There are 5 in total but I have not yet re-based the last of them. I'll attach the first 4 here.
CUPS.org User: twaugh.redhat
I've updated patch number 4 in the sequence (Avahi poll API implementation) to fix a resource leak during an error condition. Problem spotted using static code analysis.
CUPS.org User: mike
Pushing out pending licensing...
CUPS.org User: anybody
Has this been included in CUPS 1.5 ?
A presentation from April 2010 mentioned "Bonjour support: Full support for Avahi" as one of the changes for CUPS v1.5 (Source: https://www.linuxfoundation.org/sites/main/files/cups-openprinting-april-10.pdf), however upon release of the new version I couldn't really identify something in the changelog that made it clear to me whether this has been included or not.
Basically what I want to do is use AirPrint in Gentoo, and since Gentoo doesn't ship an Avahi-patched-CUPS-1.4 (like Ubuntu does) i'm stuck on the very old 1.3.x release... I was hoping that a "reintegration" of AVAHI would be part of CUPS 1.5 and would allow me to upgrade. Was I wrong about this?
CUPS.org User: mike
No, current CUPS 1.5 does NOT have Avahi support. We are waiting on legal issues to incorporate the code changes.
CUPS.org User: twaugh.redhat
Current patch set, with license updated, attached.
CUPS.org User: twaugh.redhat
Current patch set attached.
CUPS.org User: stoatwblr
FWIW these patches don't get used when compiling cups 1.5 on rhel6
I assumed it's the avahi-client reference in dnssd.m4 that's causing it but converting that to avahi-libs doesn't work either.
CUPS.org User: twaugh.redhat
Note that you need to run these commands after applying the patches:
aclocal -I config-scripts autoconf -I config-scripts
CUPS.org User: stoatwblr
Slightly further now - it's checking for avahi and then decides "no"
CUPS.org User: twaugh.redhat
Did you supply '--enable-avahi' to configure? For a working Avahi-patched CUPS build, take a look at how it is done in e.g. Fedora.
CUPS.org User: andyrtr
Can you please rebase the patch set for 1.5.1 release? thanks.
CUPS.org User: stoatwblr
Yes I did use the --enable-avahi flags. Will look more closely at the Fedora builds. Thanks.
CUPS.org User: stoatwblr
Tim: More RHELisms, I'm afraid:
/usr/share/aclocal/aalib.m4:12: warning: underquoted definition of AM_PATH_AALIB /usr/share/aclocal/aalib.m4:12: run info '(automake)Extending aclocal' /usr/share/aclocal/aalib.m4:12: or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
Also, would you mind looking at what's needed to rebase to 1.5.2?
CUPS.org User: twaugh.redhat
stoatwblr: I'm not sure what you mean. The warnings you are seeing are from a mistake in the aalib m4 macros -- they have no bearing on CUPS or Avahi, and are not responsible for any issues you may be seeing.
I've merged upstream cups changes into my patch set, for which a git repository can be obtained as follows: git clone http://twaugh.fedorapeople.org/cups-avahi.git
The separate parts of the Avahi support are available as patches here: http://twaugh.fedorapeople.org/cups-avahi/
Michael, is there any possibility that these patches will be merged into the CUPS source soon? I also have patches for trunk (although they are missing the needed libcups changes).. but I think Avahi support was targeted for 1.5 in any case.
CUPS.org User: mike
OK, so I've started integrating this but the changes do not conform to the CUPS coding standards and break the existing mDNSResponder code...
CUPS.org User: mike
OK, I'm just getting back to this to finish up the work. I think there is a serious issue with the dnssd implementation as it is doing a RESOLVE to get the TXT record. That is really not a good idea as it forces most devices to their full power state.
What we want to use here is a QUERY to get the TXT record, which means using avahi_record_browser_new to get the TXT record type.
Geez the Avahi documentation is awful...
CUPS.org User: mike
Oh, and another side-effect of how this is currently implemented is that we will flood the network with resolves, which is also not good (will fail in many cases and is not nice since it can cause a DoS of the network...)
CUPS.org User: mike
The _httpResolveURI changes also needed to be re-worked. There was no timeout after 90 seconds, no initial lookup for the service in the .local domain, and no reporting of offline/online status. I am also concerned about the use of the IP address in the resolved URI since that is often a VPN address for wide-area Bonjour. Will do some more testing to see if the glibc NSS stuff is working in recent Linux distros, since that is what we really want (so the hostname information is preserved in HTTP requests...)
CUPS.org User: mike
OK, the resolve issue was caused by Fedora's default firewall settings (disables mDNS completely... sigh...)
CUPS.org User: mike
OK, resolution and discovery are now working properly. Working on the registration code now...
FWIW, Avahi has a bad bug in avahi_simple_poll_iterate where the timeout value is not used: http://avahi.org/ticket/364
I've worked around the bug in question by implementing a custom poll function that uses the desired timeout...
CUPS.org User: mike
OK, I've re-worked all of the DNS-SD functionality in cupsd; I have a few more things to change to properly support Avahi, but we are really close now...
CUPS.org User: mike
OK, trunk now has mostly complete Avahi support in r10417. The one remaining task is to add browsing to the new cupsEnumDests() API.
The implementation in the scheduler is significantly different than provided, using the avahi_threaded_poll() path to avoid introducing the whole timeout interface and more complications.
CUPS.org User: twaugh.redhat
Thanks!
CUPS.org User: andyrtr
New 1.5.3 release requires the cups-avahi-2-backend.patch rebased and maybe more changes. Can you please have a look?
Hunk #6 FAILED at 131. Hunk #7 FAILED at 145.
Thanks. -Andy ArchLinux
CUPS.org User: mike
This is complete as of r10470.
"cups-avahi-backend.patch":
diff --git a/backend/dnssd.c b/backend/dnssd.c index ec32bba..a5d7a1b 100644 --- a/backend/dnssd.c +++ b/backend/dnssd.c @@ -20,7 +20,8 @@
@@ -30,7 +31,18 @@
-#include
/* @@ -49,7 +61,11 @@ typedef enum
typedef struct { +#ifdef HAVE_AVAHI
+#ifdef HAVE_AVAHI +/*
const char *replyDomain);
static void unquote(char _dst, const char src, size_t dstsize); +static int device_type(const char regtype); + + +#ifdef HAVE_AVAHI +static AvahiSimplePoll simple_poll = NULL; +static int avahi_gotcallback; +#endif / HAVE_AVAHI /
/ @@ -122,6 +176,10 @@ main(int argc, /* I - Number of command-line args / struct timeval timeout; / Timeout for select() _/ cups_array_t devices; / Device array / cups_devicet *device; / Current device */ +#ifdef HAVE_AVAHI
int error; +#endif /* HAVE_AVAHI */
/ @@ -161,6 +219,48 @@ main(int argc, /* I - Number of command-line args /
+#ifdef HAVE_AVAHI
avahi_browse_callback, devices);
+#else if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErrNoError) { perror("ERROR: Unable to create service connection"); @@ -212,6 +312,7 @@ main(int argc, /* I - Number of command-line args / riousbprint_ref = main_ref; DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0, "_riousbprint._tcp", NULL, browsecallback, devices); +#endif / !HAVE_AVAHI */
/*
for (;;) {
@@ -238,11 +351,19 @@ main(int argc, /* I - Number of command-line args */ } else {
+#ifndef HAVEAVAHI DNSServiceErrorType status; /* DNS query status / +#endif /_ !HAVEAVAHI / cups_devicet *best; / Best matching device _/ char deviceuri[1024]; / Device URI / int count; / Number of queries / @@ -255,6 +376,7 @@ main(int argc, / I - Number of command-line args _/ best = NULL, count = 0; device; device = (cups_device_t )cupsArrayNext(devices)) +#ifndef HAVEAVAHI if (!device->ref && !device->sent) { / @@ -283,23 +405,36 @@ main(int argc, /* I - Number of command-line args / count ++; } }
if (!device->sent) { +#ifndef HAVE_AVAHI /*
DNSServiceRefDeallocate(device->ref); device->ref = 0; +#endif /* !HAVE_AVAHI */
if (!best) best = device; else if (strcasecmp(best->name, device->name) || strcasecmp(best->domain, device->domain)) { +#ifdef HAVE_AVAHI
best->name);
+#else httpAssembleURI(HTTP_URI_CODING_ALL, device_uri, sizeof(device_uri), schemes[best->type], NULL, best->fullName, 0, best->cups_shared ? "/cups" : "/"); +#endif /* HAVE_AVAHI */
cupsBackendReport("network", device_uri, best->make_and_model,
best->name, NULL, NULL);
@@ -319,9 +454,17 @@ main(int argc, /* I - Number of command-line args */
if (best) {
best->cups_shared ? "/cups" : "/");
+#endif /* HAVE_AVAHI */
cupsBackendReport("network", device_uri, best->make_and_model, best->name, NULL, NULL); @@ -332,6 +475,164 @@ main(int argc, /* I - Number of command-line args */ }
+#ifdef HAVE_AVAHI +static void +avahi_client_callback(
}
+}
+
+#else /* !HAVEAVAHI /
/_
/ @@ -518,18 +820,7 @@ get_device(cups_array_t devices, / I - Device array /
key.name = (char *)serviceName;
key.type = device_type (regtype);
for (device = cupsArrayFind(devices, &key); device; @@ -559,13 +850,20 @@ get_device(cups_array_t devices, / I - Device array */
+#ifdef HAVE_AVAHI
device->fullName = strdup(fullName); +#else DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain); device->fullName = strdup(fullName); +#endif /* !HAVE_AVAHI */
return (device); }
+#ifndef HAVE_AVAHI /*
'querycallback()' - Process query data. / @@ -584,12 +882,21 @@ query_callback( uint32t ttl, / I - Time-to-live / void *context) / I - Devices array */ {
fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, " "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", " @@ -610,7 +917,6 @@ query_callback(
devices = (cups_array_t *)context; key.name = name;
unquote(name, fullName, sizeof(name)); @@ -635,88 +941,111 @@ query_callback( else key.type = CUPS_DEVICE_RIOUSBPRINT;
const void *value; /* Pointer to value */
*ptr;
value = TXTRecordGetValuePtr(rdlen, rdata, "priority", &valueLen);
if (value && valueLen)
if ((value = TXTRecordGetValuePtr(rdlen, rdata, "usb_MFG",
if ((value = TXTRecordGetValuePtr(rdlen, rdata, "usb_MDL",
memcpy(model, value + 1, valueLen - 2);
model[product_len] = '\0';
}
if (!strcasecmp(model, "GPL Ghostscript") || !strcasecmp(model, "GNU Ghostscript") || !strcasecmp(model, "ESP Ghostscript")) {
model[ty_len] = '\0';
if ((ptr = strchr(model, ',')) != NULL)
*ptr = '\0';
@@ -742,7 +1071,7 @@ query_callback(
if ((device->type == CUPS_DEVICE_IPP || device->type == CUPS_DEVICE_PRINTER) &&
printer_type)
{ /*
@@ -797,6 +1125,35 @@ unquote(char dst, / I - Destination buffer */ }
+static int +device_type (const char *regtype) +{ +#ifdef HAVE_AVAHI
]) fi
AC_SUBST(DNSSDLIBS) diff --git a/config.h.in b/config.h.in index e657b09..84df2a3 100644 --- a/config.h.in +++ b/config.h.in @@ -344,6 +344,13 @@
/*
"0001-New-enable-avahi-configure-option.patch":
From d948ecde8d30db6fbf5688d9caf2592c7c09577d Mon Sep 17 00:00:00 2001 From: Tim Waugh twaugh@redhat.com Date: Tue, 4 Jan 2011 15:26:26 +0000 Subject: [PATCH 1/4] New --enable-avahi configure option.
config-scripts/cups-dnssd.m4 | 15 +++++++++++++++ config.h.in | 7 +++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/config-scripts/cups-dnssd.m4 b/config-scripts/cups-dnssd.m4 index 0f582fc..48fb7ab 100644 --- a/config-scripts/cups-dnssd.m4 +++ b/config-scripts/cups-dnssd.m4 @@ -27,6 +27,21 @@ AC_ARG_WITH(dnssd-includes, [ --with-dnssd-includes set directory for DNS Ser DNSSDLIBS="" DNSSD_BACKEND=""
+AC_ARG_ENABLE(avahi, [ --enable-avahi turn on DNS Service Discovery support, default=no],
$PKGCONFIG --cflags avahi-client
"$PKGCONFIG --libs avahi-client
" fi])
+ if test x$enable_dnssd != xno; then AC_CHECK_HEADER(dns_sd.h, [ case "$uname" in diff --git a/config.h.in b/config.h.in index ed3df38..4e2301c 100644 --- a/config.h.in +++ b/config.h.in @@ -365,6 +365,13 @@
/*
1.7.3.4
"0002-Avahi-support-in-the-dnssd-backend.patch":
From 5e72ac0b42633facc875ab46d1601b59aed60d13 Mon Sep 17 00:00:00 2001 From: Tim Waugh twaugh@redhat.com Date: Wed, 29 Jul 2009 13:45:35 +0100 Subject: [PATCH 2/4] Avahi support in the dnssd backend.
backend/dnssd.c | 580 +++++++++++++++++++++++++++++++++++++++++++------- cups/http-support.c | 191 +++++++++++++++++- 2 files changed, 687 insertions(+), 84 deletions(-)
diff --git a/backend/dnssd.c b/backend/dnssd.c index 57ecc6c..8e08271 100644 --- a/backend/dnssd.c +++ b/backend/dnssd.c @@ -15,14 +15,21 @@ *
unquote() - Unquote a name string. */ @@ -33,7 +40,18 @@
-#include
/* @@ -52,7 +70,12 @@ typedef enum
typedef struct { +#ifdef HAVEDNSSD DNSServiceRef ref; /* Service reference for resolve / +#endif /_ HAVE_DNSSD */ +#ifdef HAVE_AVAHI
+typedef struct +{
AvahiStringList txt; +#endif / HAVE_DNSSD */ +} cups_txt_records_t; +
/*
+#ifdef HAVE_DNSSD static void browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, @@ -92,12 +130,6 @@ static void browse_local_callback(DNSServiceRef sdRef, const char _regtype, const char replyDomain, void context); -static int compare_devices(cups_device_t a, cups_device_t b); -static void exec_backend(char _argv); -static cups_device_t get_device(cups_array_t *devices,
+#ifdef HAVE_AVAHI +static AvahiSimplePoll _simple_poll = NULL; +static int avahi_gotcallback; +#endif / HAVEAVAHI / + + +/_
return 0; +} +
/*
struct sigaction action; / Actions for POSIX signals /
@@ -195,6 +342,49 @@ main(int argc, /_ I - Number of command-line args */
+#ifdef HAVE_AVAHI
avahi_browse_callback, devices);
+#endif /* HAVEAVAHI / +#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErrNoError) { perror("ERROR: Unable to create service connection"); @@ -246,6 +436,7 @@ main(int argc, / I - Number of command-line args _/ riousbprint_ref = main_ref; DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0, "_riousbprint._tcp", NULL, browsecallback, devices); +#endif / HAVE_DNSSD */
/*
while (!job_canceled) {
@@ -272,11 +466,35 @@ main(int argc, /* I - Number of command-line args */ } else {
+#ifdef HAVEDNSSD DNSServiceErrorType status; /* DNS query status / +#endif /_ HAVEDNSSD / cups_devicet *best; / Best matching device _/ char deviceuri[1024]; / Device URI / int count; / Number of queries / @@ -286,6 +504,7 @@ main(int argc, / I - Number of command-line args _/ best = NULL, count = 0; device; device = (cups_device_t )cupsArrayNext(devices)) +#ifdef HAVEDNSSD if (!device->ref && !device->sent) { / @@ -314,14 +533,23 @@ main(int argc, /* I - Number of command-line args / count ++; } }
if (!device->sent) { +#ifdef HAVE_DNSSD /*
DNSServiceRefDeallocate(device->ref); device->ref = 0; +#endif /* HAVE_DNSSD */
if (!best) best = device; @@ -369,6 +597,7 @@ main(int argc, /* I - Number of command-line args */ }
+#ifdef HAVE_DNSSD /*
'browsecallback()' - Browse devices. / @@ -457,6 +686,7 @@ browse_localcallback( device->fullName); device->sent = 1; } +#endif / HAVE_DNSSD */
/ @@ -531,6 +761,37 @@ exec_backend(char argv) / I - Command-line arguments */
/*
+static int +device_type (const char *regtype) +{ +#ifdef HAVE_AVAHI
+/*
@@ -551,18 +812,7 @@ get_device(cups_array_t devices, / I - Device array / /
key.type = device_type (regtype);
for (device = cupsArrayFind(devices, &key); device; @@ -582,8 +832,14 @@ get_device(cups_array_t devices, / I - Device array */ free(device->domain); device->domain = strdup(replyDomain);
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, device->name, regtype, replyDomain); +#else /* HAVE_AVAHI */
device->resolved = 0; +#endif /* HAVE_AVAHI */
cupsArrayAdd(devices, device);
@@ -610,13 +869,20 @@ get_device(cups_array_t devices, / I - Device array */
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain); +#else /* HAVE_AVAHI */
serviceName, regtype, replyDomain);
+#endif /* HAVE_DNSSD */ + device->fullName = strdup(fullName);
return (device); }
+#ifdef HAVE_DNSSD /*
'querycallback()' - Process query data. / @@ -640,7 +906,7 @@ querycallback( *ptr; / Pointer into string _/ cups_devicet dkey, / Search key */
fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, " "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", " @@ -674,84 +940,232 @@ querycallback( if ((ptr = strstr(name, ".")) != NULL) *ptr = '\0';
const uint8_t *data, /* Pointer into data */
device_id[2048]; /* 1284 device ID */
device_id[0] = '\0'; make_and_model[0] = '\0';
strcpy(model, "Unknown");
for (data = rdata, dataend = data + rdlen;
goto next;
break;
}
if (device->device_id) @@ -855,11 +1273,9 @@ query_callback( } }
/*
resolve_callback() - Build a device URI for the given service name.
/* @@ -59,6 +63,11 @@
+#ifdef HAVEAVAHI +# include <avahi-client/client.h> +# include <avahi-client/lookup.h> +# include <avahi-common/simple-watch.h> +#endif / HAVE_AVAHI */
/* @@ -125,6 +134,24 @@ static void DNSSD_API resolve_callback(DNSServiceRef sdRef, void _context);
+#ifdef HAVE_AVAHI +static void avahi_resolve_uri_client_cb(AvahiClient *client,
void *context);
+#endif /* HAVE_AVAHI */
/*
if (strstr(hostname, "._tcp")) { +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
@@ -1395,6 +1425,17 @@ _httpResolveURI( fd_set inputset; / Input set for select() / struct timeval stimeout; / Timeout value for select() _/
+#else /_ HAVE_AVAHI */
} user_data; +#endif /* HAVE_DNSSD */ +
if (logit) fprintf(stderr, "DEBUG: Resolving \"%s\"...\n", hostname); @@ -1431,8 +1472,13 @@ _httpResolveURI( if (domain) *domain++ = '\0';
+#ifdef HAVE_DNSSD uribuf.buffer = resolved_uri; uribuf.bufsize = resolved_size; +#else
user_data.uribuf.bufsize = resolved_size; +#endif
resolved_uri[0] = '\0';
@@ -1447,6 +1493,7 @@ _httpResolveURI(
uri = NULL;
+#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError) { localref = ref; @@ -1545,6 +1592,36 @@ _httpResolveURI(
DNSServiceRefDeallocate(ref);
}
+#else /* HAVE_AVAHI */
} +#endif /* HAVE_DNSSD */
if (logit) { @@ -1556,13 +1633,13 @@ _httpResolveURI( fputs("STATE: -connecting-to-device,offline-report\n", stderr); }
-#else +#else /* HAVE_DNSSD || HAVEAVAHI / /_ * No DNS-SD support... */
uri = NULL;
-#endif /* HAVEDNSSD / +#endif /_ HAVE_DNSSD || HAVE_AVAHI */
if (logit && !uri)
_cupsLangPrintFilter(stderr, "ERROR", _("Unable to find printer."));
@@ -1768,6 +1845,116 @@ resolve_callback(
+#ifdef HAVE_AVAHI +/*
"0003-Timed-callback-support-needed-for-Avahi.patch":
From cf80621258dfff7dad567ddb34ac042e9c59ade6 Mon Sep 17 00:00:00 2001 From: Tim Waugh twaugh@redhat.com Date: Tue, 21 Dec 2010 17:25:24 +0000 Subject: [PATCH 3/4] Timed callback support, needed for Avahi.
scheduler/Makefile | 3 +- scheduler/cupsd.h | 26 +++++++ scheduler/main.c | 39 ++++++++++ scheduler/timeout.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 262 insertions(+), 1 deletions(-) create mode 100644 scheduler/timeout.c
diff --git a/scheduler/Makefile b/scheduler/Makefile index 0decf8f..688d564 100644 --- a/scheduler/Makefile +++ b/scheduler/Makefile @@ -39,7 +39,8 @@ CUPSDOBJS = \ server.o \ statbuf.o \ subscriptions.o \
timeout.o
LIBOBJS = \ filter.o \ mime.o \ diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index d151015..5af3821 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -139,6 +139,15 @@ extern const char *cups_hstrerror(int);
typedef void (cupsd_selfunc_t)(void data);
+#ifdef HAVE_AVAHI +/*
_/ + +typedef struct _cupsd_timeout_s cupsd_timeout_t; +typedef void (_cupsd_timeoutfunc_t)(cupsd_timeout_t timeout, void *data); +#endif / HAVE_AVAHI */ +
/*
+#ifdef HAVE_AVAHI +VAR cups_array_t Timeouts; / Timed callbacks for main loop / +#endif / HAVE_AVAHI */ + +
/*
+#ifdef HAVE_AVAHI +extern void cupsdInitTimeouts(void); +extern cupsd_timeout_t cupsdAddTimeout (const struct timeval tv,
diff --git a/scheduler/main.c b/scheduler/main.c index a19409e..798561d 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -153,6 +153,10 @@ main(int argc, /* I - Number of command-line args _/ int launchd_idleexit; / Idle exit on select timeout? _/
+#ifdef HAVE_AVAHI
long tmodelay; /* Time before it must be called / +#endif /_ HAVE_AVAHI */
@@ -532,6 +536,14 @@ main(int argc, /* I - Number of command-line args */
httpInitialize();
+#ifdef HAVE_AVAHI
cupsdInitTimeouts(); +#endif /* HAVE_AVAHI */ + cupsdStartServer();
/ @@ -871,6 +883,16 @@ main(int argc, /\ I - Number of command-line args _/ }
+#ifdef HAVE_AVAHI
/_
long tmodelay; /* Seconds before calling it / +#endif /_ HAVE_AVAHI */
/ @@ -1958,6 +1984,19 @@ select_timeout(int fds) /\ I - Number of descriptors returned _/ }
+#ifdef HAVE_AVAHI
1.7.3.4
"0004-Avahi-poll-API-implementation.patch":
From 6e0fe12e81d7f88b2d07924d6d1aed42d62bb89d Mon Sep 17 00:00:00 2001 From: Tim Waugh twaugh@redhat.com Date: Tue, 4 Jan 2011 16:12:00 +0000 Subject: [PATCH 4/4] Avahi poll API implementation.
scheduler/Makefile | 1 + scheduler/avahi.c | 443 ++++++++++++++++++++++++++++++++++++++++++++++++++++ scheduler/avahi.h | 49 ++++++ 3 files changed, 493 insertions(+), 0 deletions(-) create mode 100644 scheduler/avahi.c create mode 100644 scheduler/avahi.h
diff --git a/scheduler/Makefile b/scheduler/Makefile index 688d564..56e7df3 100644 --- a/scheduler/Makefile +++ b/scheduler/Makefile @@ -17,6 +17,7 @@ include ../Makedefs
CUPSDOBJS = \ auth.o \
1.7.3.4
"0004-Avahi-poll-API-implementation_v2.patch":
From 3aeafd44e8e0d5208e2ebdc65a2051942d766674 Mon Sep 17 00:00:00 2001 From: Tim Waugh twaugh@redhat.com Date: Tue, 4 Jan 2011 16:12:00 +0000 Subject: [PATCH 4/4] Avahi poll API implementation.
scheduler/Makefile | 1 + scheduler/avahi.c | 445 ++++++++++++++++++++++++++++++++++++++++++++++++++++ scheduler/avahi.h | 49 ++++++ 3 files changed, 495 insertions(+), 0 deletions(-) create mode 100644 scheduler/avahi.c create mode 100644 scheduler/avahi.h
diff --git a/scheduler/Makefile b/scheduler/Makefile index 81f8bab..b9a0149 100644 --- a/scheduler/Makefile +++ b/scheduler/Makefile @@ -17,6 +17,7 @@ include ../Makedefs
CUPSDOBJS = \ auth.o \
1.7.4
"cups-1-avahi-config.patch":
diff --git a/config-scripts/cups-dnssd.m4 b/config-scripts/cups-dnssd.m4 index 66a400b..5b17603 100644 --- a/config-scripts/cups-dnssd.m4 +++ b/config-scripts/cups-dnssd.m4 @@ -23,6 +23,21 @@ AC_ARG_WITH(dnssd-includes, [ --with-dnssd-includes set directory for DNS Ser DNSSDLIBS="" DNSSD_BACKEND=""
+AC_ARG_ENABLE(avahi, [ --enable-avahi turn on DNS Service Discovery support, default=no],
$PKGCONFIG --cflags avahi-client
"$PKGCONFIG --libs avahi-client
" fi])
+ if test x$enable_dnssd != xno; then AC_CHECK_HEADER(dns_sd.h, [ case "$uname" in diff --git a/config.h.in b/config.h.in index 8d4cd42..6182be8 100644 --- a/config.h.in +++ b/config.h.in @@ -390,6 +390,13 @@
/*
"cups-2-avahi-backend.patch":
diff --git a/backend/dnssd.c b/backend/dnssd.c index d1392ed..a35a9cc 100644 --- a/backend/dnssd.c +++ b/backend/dnssd.c @@ -15,14 +15,21 @@ *
unquote() - Unquote a name string. */ @@ -33,7 +40,18 @@
-#include
/* @@ -53,7 +71,12 @@ typedef enum
typedef struct { +#ifdef HAVEDNSSD DNSServiceRef ref; /* Service reference for resolve / +#endif /_ HAVE_DNSSD */ +#ifdef HAVE_AVAHI
+typedef struct +{
AvahiStringList txt; +#endif / HAVE_DNSSD */ +} cups_txt_records_t; +
/*
+#ifdef HAVE_DNSSD static void browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, @@ -93,12 +131,6 @@ static void browse_local_callback(DNSServiceRef sdRef, const char _regtype, const char replyDomain, void context); -static int compare_devices(cups_device_t a, cups_device_t b); -static void exec_backend(char _argv); -static cups_device_t get_device(cups_array_t *devices,
+#ifdef HAVE_AVAHI +static AvahiSimplePoll _simple_poll = NULL; +static int avahi_gotcallback; +#endif / HAVEAVAHI / + + +/_
return 0; +} +
/*
struct sigaction action; / Actions for POSIX signals /
@@ -198,6 +345,49 @@ main(int argc, /_ I - Number of command-line args */
+#ifdef HAVE_AVAHI
avahi_browse_callback, devices);
+#endif /* HAVEAVAHI / +#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErrNoError) { perror("ERROR: Unable to create service connection"); @@ -258,6 +448,7 @@ main(int argc, / I - Number of command-line args _/ riousbprint_ref = main_ref; DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0, "_riousbprint._tcp", NULL, browsecallback, devices); +#endif / HAVE_DNSSD */
/*
while (!job_canceled) {
@@ -284,11 +478,35 @@ main(int argc, /* I - Number of command-line args */ } else {
+#ifdef HAVEDNSSD DNSServiceErrorType status; /* DNS query status / +#endif /_ HAVEDNSSD / cups_devicet *best; / Best matching device _/ char deviceuri[1024]; / Device URI / int count; / Number of queries / @@ -302,6 +520,7 @@ main(int argc, / I - Number of command-line args */ if (device->sent) sent ++;
+#ifdef HAVE_DNSSD if (device->ref) count ++;
@@ -333,14 +552,23 @@ main(int argc, /* I - Number of command-line args */ count ++; } }
if (!device->sent) { +#ifdef HAVE_DNSSD /*
DNSServiceRefDeallocate(device->ref); device->ref = 0; +#endif /* HAVE_DNSSD */
if (!best) best = device; @@ -401,6 +629,7 @@ main(int argc, /* I - Number of command-line args */ }
+#ifdef HAVE_DNSSD /*
'browsecallback()' - Browse devices. / @@ -489,6 +718,7 @@ browse_localcallback( device->fullName); device->sent = 1; } +#endif / HAVE_DNSSD */
/ @@ -569,6 +799,41 @@ exec_backend(char argv) / I - Command-line arguments */
/*
+static int +device_type (const char *regtype) +{ +#ifdef HAVE_AVAHI
+/*
@@ -589,20 +854,7 @@ get_device(cups_array_t devices, / I - Device array / /
key.type = device_type (regtype);
for (device = cupsArrayFind(devices, &key); device; @@ -622,8 +874,14 @@ get_device(cups_array_t devices, / I - Device array */ free(device->domain); device->domain = strdup(replyDomain);
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, device->name, regtype, replyDomain); +#else /* HAVE_AVAHI */
device->resolved = 0; +#endif /* HAVE_AVAHI */
cupsArrayAdd(devices, device);
@@ -650,13 +911,20 @@ get_device(cups_array_t devices, / I - Device array */
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain); +#else /* HAVE_AVAHI */
serviceName, regtype, replyDomain);
+#endif /* HAVE_DNSSD */ + device->fullName = strdup(fullName);
return (device); }
+#ifdef HAVE_DNSSD /*
'querycallback()' - Process query data. / @@ -680,7 +948,7 @@ querycallback( *ptr; / Pointer into string _/ cups_devicet dkey, / Search key */
fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, " "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", " @@ -714,94 +982,233 @@ querycallback( if ((ptr = strstr(name, ".")) != NULL) *ptr = '\0';
const uint8_t *data, /* Pointer into data */
device_id[2048]; /* 1284 device ID */
device_id[0] = '\0'; make_and_model[0] = '\0';
strcpy(model, "Unknown");
for (data = rdata, dataend = data + rdlen;
datalen = *data++;
goto next;
if (!datalen || (data + datalen) >= dataend)
break;
}
if (device->device_id) @@ -905,11 +1316,9 @@ query_callback( } }
/*
http_resolve_cb() - Build a device URI for the given service name.
/* @@ -60,6 +64,11 @@
+#ifdef HAVEAVAHI +# include <avahi-client/client.h> +# include <avahi-client/lookup.h> +# include <avahi-common/simple-watch.h> +#endif / HAVE_AVAHI */
/* @@ -127,6 +136,24 @@ static void DNSSD_API http_resolve_cb(DNSServiceRef sdRef, void _context);
+#ifdef HAVE_AVAHI +static void avahi_resolve_uri_client_cb(AvahiClient *client,
void *context);
+#endif /* HAVE_AVAHI */
/*
if (strstr(hostname, "._tcp")) { +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
@@ -1449,6 +1479,17 @@ _httpResolveURI( fd_set inputset; / Input set for select() / struct timeval stimeout; / Timeout value for select() _/
+#else /_ HAVE_AVAHI */
} user_data; +#endif /* HAVE_DNSSD */ +
if (options & _HTTP_RESOLVE_STDERR) fprintf(stderr, "DEBUG: Resolving \"%s\"...\n", hostname); @@ -1485,9 +1526,16 @@ _httpResolveURI( if (domain) *domain++ = '\0';
+#ifdef HAVE_DNSSD uribuf.buffer = resolved_uri; uribuf.bufsize = resolved_size; uribuf.options = options; +#else
user_data.uribuf.options = options; +#endif + resolved_uri[0] = '\0';
DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", " @@ -1501,6 +1549,7 @@ _httpResolveURI(
uri = NULL;
+#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError) { localref = ref; @@ -1608,6 +1657,36 @@ _httpResolveURI(
DNSServiceRefDeallocate(ref);
}
+#else /* HAVE_AVAHI */
} +#endif /* HAVE_DNSSD */
if (options & _HTTP_RESOLVE_STDERR) { @@ -1619,13 +1698,13 @@ _httpResolveURI( fputs("STATE: -connecting-to-device,offline-report\n", stderr); }
-#else +#else /* HAVE_DNSSD || HAVEAVAHI / /_ * No DNS-SD support... */
uri = NULL;
-#endif /* HAVEDNSSD / +#endif /_ HAVE_DNSSD || HAVE_AVAHI */
if ((options & _HTTP_RESOLVE_STDERR) && !uri)
_cupsLangPrintFilter(stderr, "ERROR", _("Unable to find printer."));
@@ -1895,6 +1974,116 @@ http_resolve_cb(
+#ifdef HAVE_AVAHI +/*
"cups-3-timeouts.patch":
diff --git a/scheduler/Makefile b/scheduler/Makefile index 3c7da8e..7b4d05b 100644 --- a/scheduler/Makefile +++ b/scheduler/Makefile @@ -39,7 +39,8 @@ CUPSDOBJS = \ server.o \ statbuf.o \ subscriptions.o \
timeout.o
LIBOBJS = \ filter.o \ mime.o \ diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index 5d7229d..3ddb173 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -140,6 +140,15 @@ extern const char *cups_hstrerror(int);
typedef void (cupsd_selfunc_t)(void data);
+#ifdef HAVE_AVAHI +/*
_/ + +typedef struct _cupsd_timeout_s cupsd_timeout_t; +typedef void (_cupsd_timeoutfunc_t)(cupsd_timeout_t timeout, void *data); +#endif / HAVE_AVAHI */ +
/*
+#ifdef HAVE_AVAHI +VAR cups_array_t Timeouts; / Timed callbacks for main loop / +#endif / HAVE_AVAHI */ + +
/*
+#ifdef HAVE_AVAHI +extern void cupsdInitTimeouts(void); +extern cupsd_timeout_t cupsdAddTimeout (const struct timeval tv,
const struct timeval *tv);
+extern void cupsdRemoveTimeout (cupsd_timeout_t timeout); +#endif / HAVE_AVAHI / + +extern int cupsdRemoveFile(const char filename); +
/*
+#ifdef HAVE_AVAHI
long tmodelay; /* Time before it must be called / +#endif /_ HAVE_AVAHI */
@@ -525,6 +529,14 @@ main(int argc, /* I - Number of command-line args */
httpInitialize();
+#ifdef HAVE_AVAHI
cupsdInitTimeouts(); +#endif /* HAVE_AVAHI */ + cupsdStartServer();
/ @@ -864,6 +876,16 @@ main(int argc, /\ I - Number of command-line args _/ }
+#ifdef HAVE_AVAHI
/_
long tmodelay; /* Seconds before calling it / +#endif /_ HAVE_AVAHI */
/ @@ -1819,6 +1845,19 @@ select_timeout(int fds) /\ I - Number of descriptors returned _/ }
+#ifdef HAVE_AVAHI
"cups-4-avahi-poll.patch":
diff --git a/scheduler/Makefile b/scheduler/Makefile index 7b4d05b..63b5123 100644 --- a/scheduler/Makefile +++ b/scheduler/Makefile @@ -17,6 +17,7 @@ include ../Makedefs
CUPSDOBJS = \ auth.o \
"cups-5-avahi-services.patch":
diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c index 99b8e7b..2688eff 100644 --- a/cgi-bin/admin.c +++ b/cgi-bin/admin.c @@ -1643,7 +1643,7 @@ do_config_server(http_t http) / I - HTTP connection */ else local_protocols[0] = '\0';
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if (cgiGetVariable("BROWSE_LOCAL_DNSSD")) { if (local_protocols[0]) @@ -1651,7 +1651,7 @@ do_config_server(http_t http) / I - HTTP connection _/ else strcat(localprotocols, "dnssd"); } -#endif / HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
@@ -2718,9 +2718,9 @@ do_menu(http_t http) / I - HTTP connection _/
cgiSetVariable("KERBEROS", "");
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cgiSetVariable("HAVE_DNSSD", "1"); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
cgiSetVariable("HAVE_LDAP", "1"); diff --git a/scheduler/client.c b/scheduler/client.c index d5a5111..12ed881 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -4985,7 +4985,7 @@ valid_host(cupsd_client_t con) / I - Client connection */ !strncmp(host, "[::1]:", 6)); }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
Check if the hostname is something.local (Bonjour); if so, allow it. _/ @@ -4994,7 +4994,7 @@ valid_host(cupsd_clientt *con) / I - Client connection _/ (!_cups_strcasecmp(end, ".local") || !_cups_strncasecmp(end, ".local:", 7) || !_cups_strcasecmp(end, ".local.") || !_cupsstrncasecmp(end, ".local.:", 8))) return (1); -#endif / HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
/*
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cupsdSetString(&DNSSDRegType, "_ipp._tcp,_cups");
diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index eb3c862..48dcef9 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -27,6 +27,7 @@
printer or update the broadcast contents.
@@ -83,6 +86,7 @@ */
+#include
@@ -97,6 +101,17 @@
+#ifdef HAVEAVAHI +# include <avahi-common/domain.h> +#endif / HAVEAVAHI / + + +#ifdef HAVE_DNSSD +typedef char cupsd_txt_recordt; +#endif / HAVEDNSSD / +#ifdef HAVE_AVAHI +typedef AvahiStringList cupsd_txt_recordt; +#endif / HAVE_AVAHI */
/* @@ -159,27 +174,39 @@ static void update_polling(void); static void update_smb(int onoff);
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) +static cupsd_txt_record_t dnssdBuildTxtRecord(int txt_len, cupsd_printer_t p,
static void dnssdAddAlias(const void key, const void value, void *context);
-static char dnssdBuildTxtRecord(int txt_len, cupsd_printer_t *p,
+#ifdef HAVE_AVAHI +static AvahiStringList avahiPackTxtRecord(char keyvalue[][2],
static const char * const ldapattrs[] =/ CUPS LDAP attributes _/ { @@ -283,10 +310,10 @@ cupsdDeregisterPrinter( ldap_dereg_printer(p);
-#ifdef HAVE_DNSSD
@@ -702,10 +729,10 @@ cupsdRegisterPrinter(cupsd_printer_t p)/ I - Printer _/ slpRegisterPrinter(p); */
-#ifdef HAVE_DNSSD
@@ -1419,6 +1446,27 @@ ldap_disconnect(LDAP ld) / I - LDAP handle _/
+#ifdef HAVE_AVAHI +/*
/*
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_DNSSD) { +#ifdef HAVEDNSSD DNSServiceErrorType error; /* Error from service creation / +#endif /_ HAVEDNSSD / cupsd_listenert *lis; / Current listening socket */
+#ifdef HAVE_DNSSD / * First create a "master" connection for all registrations... / @@ -1573,6 +1624,7 @@ cupsdStartBrowsing(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
+#endif /* HAVE_DNSSD */
/*
* Then get the port we use for registrations. If we are not listening
@@ -1606,9 +1658,16 @@ cupsdStartBrowsing(void) */
cupsdUpdateDNSSDName();
+ +#ifdef HAVE_AVAHI
} +#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) @@ -1834,10 +1893,10 @@ cupsdStopBrowsing(void) BrowseSocket = -1; }
-#ifdef HAVE_DNSSD
if ((BrowseLocalProtocols & BROWSE_DNSSD)) dnssdStop(); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) && @@ -1902,7 +1961,7 @@ cupsdStopPolling(void) }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
SCDynamicStoreRef sc; / Context for dynamic store / CFDictionaryRef btmm; /_ Back-to-My-Mac domains */ @@ -2042,6 +2107,7 @@ cupsdUpdateDNSSDName(void) else strlcpy(webif, "CUPS Web Interface", sizeof(webif));
+#ifdef HAVE_DNSSD if (WebIFRef) DNSServiceRefDeallocate(WebIFRef);
@@ -2054,9 +2120,45 @@ cupsdUpdateDNSSDName(void) NULL)) != kDNSServiceErr_NoError) cupsdLogMessage(CUPSD_LOG_ERROR, "DNS-SD web interface registration failed: %d", error); +#endif /* HAVE_DNSSD */ + +#ifdef HAVE_AVAHI
} +#endif /* HAVEAVAHI / } } -#endif /_ HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
@@ -2334,13 +2436,15 @@ dnssdAddAlias(const void key, / I - Key */ "Bad Back to My Mac domain in dynamic store!"); }
+#endif /* HAVE_DNSSD */
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
-static char * /* O - TXT record _/ +static cupsd_txt_recordt / O - TXT record _/ dnssdBuildTxtRecord( int txtlen, / O - TXT record length _/ cupsd_printer_t p, /_ I - Printer information */ @@ -2379,7 +2483,12 @@ dnssdBuildTxtRecord( keyvalue[i ][0] = "ty"; keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
+#ifdef HAVE_DNSSD return (dnssdPackTxtRecord(txt_len, keyvalue, i)); +#endif /* HAVE_DNSSD */ +#ifdef HAVE_AVAHI
@@ -2474,7 +2588,16 @@ static int /* O - Result of comparison _/ dnssdComparePrinters(cupsd_printert *a,/ I - First printer _/ cupsd_printert *b)/ I - Second printer */ {
@@ -2489,6 +2612,10 @@ dnssdDeregisterPrinter( { cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
+#ifdef HAVE_DNSSD
+#ifdef HAVE_AVAHI
} +#endif /* HAVE_AVAHI */
/*
+#ifdef HAVE_DNSSD /*
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
+#ifdef HAVE_DNSSD
+#endif /* HAVE_DNSSD */ +#ifdef HAVE_AVAHI
@@ -2712,6 +2905,7 @@ dnssdRegisterPrinter(cupsd_printer_t p)/ I - Printer */
+#ifdef HAVE_DNSSD ipp_len = 0; /* anti-compiler-warning-code */ ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
@@ -2884,6 +3078,209 @@ dnssdRegisterPrinter(cupsd_printer_t p)/ I - Printer */
if (printer_txt) free(printer_txt); +#endif /* HAVE_DNSSD */ +#ifdef HAVE_AVAHI
@@ -2896,6 +3293,10 @@ dnssdStop(void) { cupsd_printer_t p; / Current printer */
+#ifdef HAVE_DNSSD
return; +#endif /* HAVE_DNSSD */
/*
+#ifdef HAVE_DNSSD /*
Shutdown the rest of the service refs... */ @@ -2926,14 +3328,17 @@ dnssdStop(void)
DNSServiceRefDeallocate(DNSSDRef); DNSSDRef = NULL; +#endif /* HAVE_DNSSD */
cupsArrayDelete(DNSSDPrinters); DNSSDPrinters = NULL;
DNSSDPort = 0; } +#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
+#ifdef HAVE_DNSSD /*
+#ifdef HAVE_AVAHI +/*
+#ifdef HAVE_AVAHI +# include <avahi-client/publish.h> +#endif /* HAVEAVAHI / + /_
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) VAR char DNSSDComputerName VALUE(NULL), / Computer/server name / *DNSSDHostName VALUE(NULL), / Hostname / *DNSSDRegType VALUE(NULL); / Bonjour registration type / -VAR cups_array_t DNSSDAlias VALUE(NULL);
+#ifdef HAVE_AVAHI +VAR AvahiCupsPoll *AvahiCupsPollHandle VALUE(NULL);
VAR SLPHandle BrowseSLPHandle VALUE(NULL); / SLP API handle / @@ -195,13 +213,14 @@ extern void cupsdRegisterPrinter(cupsd_printer_t *p); extern void cupsdRestartPolling(void); extern void cupsdSaveRemoteCache(void); extern void cupsdSendBrowseList(void); +extern void cupsdStartAvahiClient(void); extern void cupsdStartBrowsing(void); extern void cupsdStartPolling(void); extern void cupsdStopBrowsing(void); extern void cupsdStopPolling(void); -#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVEAVAHI) extern void cupsdUpdateDNSSDName(void); -#endif / HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVEAVAHI) /
extern void cupsdUpdateLDAPBrowse(void);
diff --git a/scheduler/ipp.c b/scheduler/ipp.c index a048baa..9a3ab11 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -6087,7 +6087,7 @@ copy_printer_attrs( ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time", ippTimeToDate(curtime));
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if (!ra || cupsArrayFind(ra, "printer-dns-sd-name")) { if (printer->reg_name) @@ -6097,7 +6097,7 @@ copy_printer_attrs( ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, "printer-dns-sd-name", 0); } -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (!ra || cupsArrayFind(ra, "printer-error-policy")) ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAGNAME, diff --git a/scheduler/main.c b/scheduler/main.c index 1e60572..6c210e6 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -120,6 +120,10 @@ main(int argc, /* I - Number of command-line args / cupsd_listenert *lis; / Current listener _/ time_t currenttime, / Current time / activity, / Client activity timer */ +#ifdef HAVE_AVAHI
check */
+#endif /* HAVEAVAHI / browsetime, / Next browse send time _/ senddoctime, / Send-Document time _/ expiretime, / Subscription expire time / @@ -662,6 +666,9 @@ main(int argc, / I - Number of command-line args / /
current_time = time(NULL); +#ifdef HAVE_AVAHI
}
diff --git a/scheduler/printers.c b/scheduler/printers.c index 4686c4c..fac7bbc 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -883,9 +883,9 @@ cupsdDeletePrinter( cupsdClearString(&p->alert); cupsdClearString(&p->alert_description);
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cupsdClearString(&p->pdl); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
cupsArrayDelete(p->filetypes);
@@ -3765,7 +3765,7 @@ add_printer_formats(cupsd_printer_t p) / I - Printer */ attr->values[i].string.text = _cupsStrAlloc(mimetype); }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVEAVAHI) { char pdl[1024]; /* Buffer to build pdl list / mime_filtert *filter; / MIME filter looping var _/ @@ -3821,7 +3821,7 @@ add_printer_formats(cupsd_printert *p) / I - Printer */
cupsdSetString(&p->pdl, pdl);
} -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */ }
diff --git a/scheduler/printers.h b/scheduler/printers.h index 1751578..fb04651 100644 --- a/scheduler/printers.h +++ b/scheduler/printers.h @@ -16,6 +16,9 @@
+#ifdef HAVEAVAHI +# include "avahi.h" +#endif / HAVE_AVAHI */
@@ -95,16 +98,23 @@ struct cupsd_printer_s time_t markertime; /* Last time marker attributes were updated / _ppd_cachet *pc; / PPD cache and mapping data */
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) char _regname, / Name used for service registration */
+#ifdef HAVE_AVAHI
"cups-avahi-1-config.patch":
diff -up cups-1.5.0/config.h.in.avahi-1-config cups-1.5.0/config.h.in --- cups-1.5.0/config.h.in.avahi-1-config 2011-06-16 21:12:16.000000000 +0100 +++ cups-1.5.0/config.h.in 2011-08-05 15:04:09.535759988 +0100 @@ -390,6 +390,13 @@
/*
diff -up cups-1.5.0/config-scripts/cups-dnssd.m4.avahi-1-config cups-1.5.0/config-scripts/cups-dnssd.m4 --- cups-1.5.0/config-scripts/cups-dnssd.m4.avahi-1-config 2011-05-12 06:21:56.000000000 +0100 +++ cups-1.5.0/config-scripts/cups-dnssd.m4 2011-08-05 15:04:09.525760307 +0100 @@ -23,6 +23,21 @@ AC_ARG_WITH(dnssd-includes, [ --with-dn DNSSDLIBS="" DNSSD_BACKEND=""
+AC_ARG_ENABLE(avahi, [ --enable-avahi turn on DNS Service Discovery support, default=no],
$PKGCONFIG --cflags avahi-client
"$PKGCONFIG --libs avahi-client
""cups-avahi-2-backend.patch":
diff -up cups-1.5.0/backend/dnssd.c.avahi-2-backend cups-1.5.0/backend/dnssd.c --- cups-1.5.0/backend/dnssd.c.avahi-2-backend 2011-08-05 15:04:46.182591844 +0100 +++ cups-1.5.0/backend/dnssd.c 2011-08-05 15:05:13.868710181 +0100 @@ -15,14 +15,21 @@ *
unquote() - Unquote a name string. */ @@ -33,7 +40,18 @@
-#include
/* @@ -53,7 +71,12 @@ typedef enum
typedef struct { +#ifdef HAVEDNSSD DNSServiceRef ref; /* Service reference for resolve / +#endif /_ HAVE_DNSSD */ +#ifdef HAVE_AVAHI
+typedef struct +{
AvahiStringList txt; +#endif / HAVE_DNSSD */ +} cups_txt_records_t; +
/*
+#ifdef HAVE_DNSSD static void browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, @@ -93,12 +131,6 @@ static void browse_local_callback(DNSSe const char _regtype, const char replyDomain, void context); -static int compare_devices(cups_device_t a, cups_device_t b); -static void exec_backend(char _argv); -static cups_device_t get_device(cups_array_t *devices,
+#ifdef HAVE_AVAHI +static AvahiSimplePoll _simple_poll = NULL; +static int avahi_gotcallback; +#endif / HAVEAVAHI / + + +/_
return 0; +} +
/*
struct sigaction action; / Actions for POSIX signals /
@@ -198,6 +345,49 @@ main(int argc, /_ I - Number of comm
+#ifdef HAVE_AVAHI
avahi_browse_callback, devices);
+#endif /* HAVEAVAHI / +#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&main_ref) != kDNSServiceErrNoError) { perror("ERROR: Unable to create service connection"); @@ -258,6 +448,7 @@ main(int argc, / I - Number of comm riousbprint_ref = main_ref; DNSServiceBrowse(&riousbprint_ref, kDNSServiceFlagsShareConnection, 0, "_riousbprint._tcp", NULL, browse_callback, devices); +#endif /* HAVE_DNSSD */
/*
while (!job_canceled) {
@@ -284,11 +478,35 @@ main(int argc, /* I - Number of comm } else {
+#ifdef HAVEDNSSD DNSServiceErrorType status; /* DNS query status / +#endif /_ HAVEDNSSD / cups_devicet *best; / Best matching device _/ char deviceuri[1024]; / Device URI / int count; / Number of queries / @@ -302,6 +520,7 @@ main(int argc, / I - Number of comm if (device->sent) sent ++;
+#ifdef HAVE_DNSSD if (device->ref) count ++;
@@ -333,14 +552,23 @@ main(int argc, /* I - Number of comm count ++; } }
if (!device->sent) { +#ifdef HAVE_DNSSD /*
DNSServiceRefDeallocate(device->ref); device->ref = 0; +#endif /* HAVE_DNSSD */
if (!best) best = device; @@ -401,6 +629,7 @@ main(int argc, /* I - Number of comm }
+#ifdef HAVE_DNSSD /*
'browsecallback()' - Browse devices. / @@ -489,6 +718,7 @@ browse_localcallback( device->fullName); device->sent = 1; } +#endif / HAVE_DNSSD */
/ @@ -569,6 +799,41 @@ exec_backend(char argv) / I - Comman
/*
+static int +device_type (const char *regtype) +{ +#ifdef HAVE_AVAHI
+/*
@@ -589,20 +854,7 @@ get_device(cups_array_t devices, / I - */
key.type = device_type (regtype);
for (device = cupsArrayFind(devices, &key); device; @@ -622,8 +874,14 @@ get_device(cups_array_t devices, / I - free(device->domain); device->domain = strdup(replyDomain);
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, device->name, regtype, replyDomain); +#else /* HAVE_AVAHI */
device->resolved = 0; +#endif /* HAVE_AVAHI */
cupsArrayAdd(devices, device);
@@ -650,13 +911,20 @@ get_device(cups_array_t devices, / I -
+#ifdef HAVE_DNSSD DNSServiceConstructFullName(fullName, serviceName, regtype, replyDomain); +#else /* HAVE_AVAHI */
serviceName, regtype, replyDomain);
+#endif /* HAVE_DNSSD */ + device->fullName = strdup(fullName);
return (device); }
+#ifdef HAVE_DNSSD /*
'querycallback()' - Process query data. / @@ -680,7 +948,7 @@ querycallback( *ptr; / Pointer into string _/ cups_devicet dkey, / Search key */
fprintf(stderr, "DEBUG2: query_callback(sdRef=%p, flags=%x, " "interfaceIndex=%d, errorCode=%d, fullName=\"%s\", " @@ -714,94 +982,233 @@ querycallback( if ((ptr = strstr(name, ".")) != NULL) *ptr = '\0';
const uint8_t *data, /* Pointer into data */
device_id[2048]; /* 1284 device ID */
device_id[0] = '\0'; make_and_model[0] = '\0';
strcpy(model, "Unknown");
for (data = rdata, dataend = data + rdlen;
goto next;
fprintf(stderr, "DEBUG2: query_callback: \"%s=%s\".\n",
break;
}
if (device->device_id) @@ -912,11 +1323,9 @@ query_callback( } }
/*
http_resolve_cb() - Build a device URI for the given service name.
/* @@ -60,6 +64,11 @@
+#ifdef HAVEAVAHI +# include <avahi-client/client.h> +# include <avahi-client/lookup.h> +# include <avahi-common/simple-watch.h> +#endif / HAVE_AVAHI */
/* @@ -127,6 +136,24 @@ static void DNSSD_API http_resolve_cb(DN void _context);
+#ifdef HAVE_AVAHI +static void avahi_resolve_uri_client_cb(AvahiClient *client,
void *context);
+#endif /* HAVE_AVAHI */
/*
if (strstr(hostname, "._tcp")) { +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
@@ -1449,6 +1479,17 @@ _httpResolveURI( fd_set inputset; / Input set for select() / struct timeval stimeout; / Timeout value for select() _/
+#else /_ HAVE_AVAHI */
} user_data; +#endif /* HAVE_DNSSD */ +
if (options & _HTTP_RESOLVE_STDERR) fprintf(stderr, "DEBUG: Resolving \"%s\"...\n", hostname); @@ -1485,9 +1526,16 @@ _httpResolveURI( if (domain) *domain++ = '\0';
+#ifdef HAVE_DNSSD uribuf.buffer = resolved_uri; uribuf.bufsize = resolved_size; uribuf.options = options; +#else
user_data.uribuf.options = options; +#endif + resolved_uri[0] = '\0';
DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", " @@ -1501,6 +1549,7 @@ _httpResolveURI(
uri = NULL;
+#ifdef HAVE_DNSSD if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError) { localref = ref; @@ -1608,6 +1657,36 @@ _httpResolveURI(
DNSServiceRefDeallocate(ref);
}
+#else /* HAVE_AVAHI */
} +#endif /* HAVE_DNSSD */
if (options & _HTTP_RESOLVE_STDERR) { @@ -1619,13 +1698,13 @@ _httpResolveURI( fputs("STATE: -connecting-to-device,offline-report\n", stderr); }
-#else +#else /* HAVE_DNSSD || HAVEAVAHI / /_ * No DNS-SD support... */
uri = NULL;
-#endif /* HAVEDNSSD / +#endif /_ HAVE_DNSSD || HAVE_AVAHI */
if ((options & _HTTP_RESOLVE_STDERR) && !uri)
_cupsLangPrintFilter(stderr, "ERROR", _("Unable to find printer."));
@@ -1895,6 +1974,116 @@ http_resolve_cb(
+#ifdef HAVE_AVAHI +/*
"cups-avahi-3-timeouts.patch":
diff -up cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts cups-1.5.0/scheduler/cupsd.h --- cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts 2011-05-11 23:17:34.000000000 +0100 +++ cups-1.5.0/scheduler/cupsd.h 2011-10-07 13:20:41.522867324 +0100 @@ -140,6 +140,15 @@ extern const char *cups_hstrerror(int);
typedef void (cupsd_selfunc_t)(void data);
+#ifdef HAVE_AVAHI +/*
_/ + +typedef struct _cupsd_timeout_s cupsd_timeout_t; +typedef void (_cupsd_timeoutfunc_t)(cupsd_timeout_t timeout, void *data); +#endif / HAVE_AVAHI */ +
/*
+#ifdef HAVE_AVAHI +VAR cups_array_t Timeouts; / Timed callbacks for main loop / +#endif / HAVE_AVAHI */ + +
/*
+#ifdef HAVE_AVAHI +extern void cupsdInitTimeouts(void); +extern cupsd_timeout_t cupsdAddTimeout (const struct timeval tv,
const struct timeval *tv);
+extern void cupsdRemoveTimeout (cupsd_timeout_t timeout); +#endif / HAVE_AVAHI / + +extern int cupsdRemoveFile(const char filename); +
/*
+#ifdef HAVE_AVAHI
long tmodelay; /* Time before it must be called / +#endif /_ HAVE_AVAHI */
@@ -535,6 +539,14 @@ main(int argc, /* I - Number of comm
httpInitialize();
+#ifdef HAVE_AVAHI
cupsdInitTimeouts(); +#endif /* HAVE_AVAHI */ + cupsdStartServer();
/ @@ -874,6 +886,16 @@ main(int argc, /\ I - Number of comm }
+#ifdef HAVE_AVAHI
/_
long tmodelay; /* Seconds before calling it / +#endif /_ HAVE_AVAHI */
/ @@ -1829,6 +1855,19 @@ select_timeout(int fds) /\ I - Number }
+#ifdef HAVE_AVAHI
"cups-avahi-4-poll.patch":
diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c --- cups-1.5.0/scheduler/avahi.c.avahi-4-poll 2011-10-11 10:56:50.102288037 +0100 +++ cups-1.5.0/scheduler/avahi.c 2011-10-11 10:56:50.102288037 +0100 @@ -0,0 +1,441 @@ +/*
*/ diff -up cups-1.5.0/scheduler/Makefile.avahi-4-poll cups-1.5.0/scheduler/Makefile --- cups-1.5.0/scheduler/Makefile.avahi-4-poll 2011-10-11 10:56:45.868365861 +0100 +++ cups-1.5.0/scheduler/Makefile 2011-10-11 10:56:50.101288055 +0100 @@ -17,6 +17,7 @@ include ../Makedefs
CUPSDOBJS = \ auth.o \
"cups-avahi-5-services.patch":
diff -up cups-1.5.0/cgi-bin/admin.c.avahi-5-services cups-1.5.0/cgi-bin/admin.c --- cups-1.5.0/cgi-bin/admin.c.avahi-5-services 2011-05-20 04:49:49.000000000 +0100 +++ cups-1.5.0/cgi-bin/admin.c 2011-10-19 11:53:32.123177998 +0100 @@ -1643,7 +1643,7 @@ do_config_server(http_t http) / I - H else local_protocols[0] = '\0';
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if (cgiGetVariable("BROWSE_LOCAL_DNSSD")) { if (local_protocols[0]) @@ -1651,7 +1651,7 @@ do_config_server(http_t http) / I - H else strcat(local_protocols, "dnssd"); } -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
@@ -2718,9 +2718,9 @@ do_menu(http_t http) / I - HTTP conn
cgiSetVariable("KERBEROS", "");
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cgiSetVariable("HAVE_DNSSD", "1"); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
cgiSetVariable("HAVE_LDAP", "1"); diff -up cups-1.5.0/scheduler/client.c.avahi-5-services cups-1.5.0/scheduler/client.c --- cups-1.5.0/scheduler/client.c.avahi-5-services 2011-06-10 22:16:18.000000000 +0100 +++ cups-1.5.0/scheduler/client.c 2011-10-19 11:53:32.127177926 +0100 @@ -4987,7 +4987,7 @@ valid_host(cupsd_client_t con) / I - !strncmp(host, "[::1]:", 6)); }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
Check if the hostname is something.local (Bonjour); if so, allow it. _/ @@ -4996,7 +4996,7 @@ valid_host(cupsd_clientt *con) / I - (!_cups_strcasecmp(end, ".local") || !_cups_strncasecmp(end, ".local:", 7) || !_cups_strcasecmp(end, ".local.") || !_cups_strncasecmp(end, ".local.:", 8))) return (1); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
/*
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cupsdSetString(&DNSSDRegType, "_ipp._tcp,_cups");
diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dirsvc.c --- cups-1.5.0/scheduler/dirsvc.c.avahi-5-services 2011-10-19 11:53:32.011180075 +0100 +++ cups-1.5.0/scheduler/dirsvc.c 2011-10-19 11:53:58.916681461 +0100 @@ -27,6 +27,7 @@
printer or update the broadcast contents.
@@ -83,6 +85,7 @@ */
+#include
@@ -97,6 +100,17 @@
+#ifdef HAVEAVAHI +# include <avahi-common/domain.h> +#endif / HAVEAVAHI / + + +#ifdef HAVE_DNSSD +typedef char cupsd_txt_recordt; +#endif / HAVEDNSSD / +#ifdef HAVE_AVAHI +typedef AvahiStringList cupsd_txt_recordt; +#endif / HAVE_AVAHI */
/* @@ -159,27 +173,38 @@ static void update_polling(void); static void update_smb(int onoff);
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) +static cupsd_txt_record_t dnssdBuildTxtRecord(int txt_len, cupsd_printer_t p,
static void dnssdAddAlias(const void key, const void value, void *context);
-static char dnssdBuildTxtRecord(int txt_len, cupsd_printer_t *p,
+#ifdef HAVE_AVAHI +static AvahiStringList avahiPackTxtRecord(char keyvalue[][2],
static const char * const ldapattrs[] =/ CUPS LDAP attributes _/ { @@ -283,10 +308,10 @@ cupsdDeregisterPrinter( ldap_dereg_printer(p);
-#ifdef HAVE_DNSSD
@@ -702,10 +727,10 @@ cupsdRegisterPrinter(cupsd_printer_t _p) slpRegisterPrinter(p); */
-#ifdef HAVE_DNSSD
@@ -1419,6 +1444,36 @@ ldap_disconnect(LDAP ld) / I - LDAP h
+#ifdef HAVE_AVAHI +/*
/*
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_DNSSD) { +#ifdef HAVEDNSSD DNSServiceErrorType error; /* Error from service creation / +#endif /_ HAVEDNSSD / cupsd_listenert *lis; / Current listening socket */
+#ifdef HAVE_DNSSD / * First create a "master" connection for all registrations... / @@ -1573,6 +1631,7 @@ cupsdStartBrowsing(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
+#endif /* HAVE_DNSSD */
/*
* Then get the port we use for registrations. If we are not listening
@@ -1598,17 +1657,23 @@ cupsdStartBrowsing(void) */
if (BrowseRemoteProtocols & BROWSE_DNSSD)
DNSSDPrinters = cupsArrayNew(NULL, NULL);
/*
cupsdUpdateDNSSDName(); + +#ifdef HAVE_AVAHI
} +#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) @@ -1834,10 +1899,10 @@ cupsdStopBrowsing(void) BrowseSocket = -1; }
-#ifdef HAVE_DNSSD
if ((BrowseLocalProtocols & BROWSE_DNSSD)) dnssdStop(); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) && @@ -1902,7 +1967,7 @@ cupsdStopPolling(void) }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
SCDynamicStoreRef sc; / Context for dynamic store / CFDictionaryRef btmm; /_ Back-to-My-Mac domains */ @@ -2042,6 +2113,7 @@ cupsdUpdateDNSSDName(void) else strlcpy(webif, "CUPS Web Interface", sizeof(webif));
+#ifdef HAVE_DNSSD if (WebIFRef) DNSServiceRefDeallocate(WebIFRef);
@@ -2054,9 +2126,45 @@ cupsdUpdateDNSSDName(void) NULL)) != kDNSServiceErr_NoError) cupsdLogMessage(CUPSD_LOG_ERROR, "DNS-SD web interface registration failed: %d", error); +#endif /* HAVE_DNSSD */ + +#ifdef HAVE_AVAHI
} +#endif /* HAVEAVAHI / } } -#endif /_ HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
@@ -2334,13 +2442,15 @@ dnssdAddAlias(const void key, / I - K "Bad Back to My Mac domain in dynamic store!"); }
+#endif /* HAVE_DNSSD */
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
-static char * /* O - TXT record _/ +static cupsd_txt_recordt / O - TXT record _/ dnssdBuildTxtRecord( int txtlen, / O - TXT record length _/ cupsd_printer_t p, /_ I - Printer information */ @@ -2379,7 +2489,12 @@ dnssdBuildTxtRecord( keyvalue[i ][0] = "ty"; keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
+#ifdef HAVE_DNSSD return (dnssdPackTxtRecord(txt_len, keyvalue, i));
-/*
-static int /* O - Result of comparison _/ -dnssdComparePrinters(cupsd_printert *a,/ I - First printer */
@@ -2489,6 +2597,10 @@ dnssdDeregisterPrinter( { cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
+#ifdef HAVE_DNSSD
+#ifdef HAVE_AVAHI
} +#endif /* HAVE_AVAHI */
/*
+#ifdef HAVE_DNSSD /*
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) /*
+#ifdef HAVE_DNSSD
+#endif /* HAVE_DNSSD */ +#ifdef HAVE_AVAHI
@@ -2712,6 +2890,7 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
+#ifdef HAVE_DNSSD ipp_len = 0; /* anti-compiler-warning-code */ ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
@@ -2884,6 +3063,209 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
if (printer_txt) free(printer_txt); +#endif /* HAVE_DNSSD */ +#ifdef HAVE_AVAHI
@@ -2896,6 +3278,10 @@ dnssdStop(void) { cupsd_printer_t p; / Current printer */
+#ifdef HAVE_DNSSD
return; +#endif /* HAVE_DNSSD */
/*
+#ifdef HAVE_DNSSD /*
Shutdown the rest of the service refs... */ @@ -2926,14 +3313,17 @@ dnssdStop(void)
DNSServiceRefDeallocate(DNSSDRef); DNSSDRef = NULL; +#endif /* HAVE_DNSSD */
cupsArrayDelete(DNSSDPrinters); DNSSDPrinters = NULL;
DNSSDPort = 0; } +#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
+#ifdef HAVE_DNSSD /*
+#ifdef HAVE_AVAHI +/*
+#ifdef HAVE_AVAHI +# include <avahi-client/publish.h> +#endif /* HAVEAVAHI / + /_
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) VAR char DNSSDComputerName VALUE(NULL), / Computer/server name / *DNSSDHostName VALUE(NULL), / Hostname / *DNSSDRegType VALUE(NULL); / Bonjour registration type / -VAR cups_array_t DNSSDAlias VALUE(NULL);
+#ifdef HAVE_AVAHI +VAR AvahiCupsPoll *AvahiCupsPollHandle VALUE(NULL);
VAR SLPHandle BrowseSLPHandle VALUE(NULL); / SLP API handle / @@ -195,13 +213,14 @@ extern void cupsdRegisterPrinter(cupsd_p extern void cupsdRestartPolling(void); extern void cupsdSaveRemoteCache(void); extern void cupsdSendBrowseList(void); +extern void cupsdStartAvahiClient(void); extern void cupsdStartBrowsing(void); extern void cupsdStartPolling(void); extern void cupsdStopBrowsing(void); extern void cupsdStopPolling(void); -#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVEAVAHI) extern void cupsdUpdateDNSSDName(void); -#endif / HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVEAVAHI) /
extern void cupsdUpdateLDAPBrowse(void);
diff -up cups-1.5.0/scheduler/ipp.c.avahi-5-services cups-1.5.0/scheduler/ipp.c --- cups-1.5.0/scheduler/ipp.c.avahi-5-services 2011-10-19 11:53:31.978180686 +0100 +++ cups-1.5.0/scheduler/ipp.c 2011-10-19 11:53:32.147177555 +0100 @@ -6096,7 +6096,7 @@ copy_printer_attrs( ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time", ippTimeToDate(curtime));
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) if (!ra || cupsArrayFind(ra, "printer-dns-sd-name")) { if (printer->reg_name) @@ -6106,7 +6106,7 @@ copy_printer_attrs( ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, "printer-dns-sd-name", 0); } -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
if (!ra || cupsArrayFind(ra, "printer-error-policy")) ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, diff -up cups-1.5.0/scheduler/main.c.avahi-5-services cups-1.5.0/scheduler/main.c --- cups-1.5.0/scheduler/main.c.avahi-5-services 2011-10-19 11:53:32.101178406 +0100 +++ cups-1.5.0/scheduler/main.c 2011-10-19 11:53:32.151177479 +0100 @@ -120,6 +120,10 @@ main(int argc, /* I - Number of comm cupsd_listener_t lis; / Current listener _/ time_t currenttime, / Current time / activity, / Client activity timer */ +#ifdef HAVE_AVAHI
check */
+#endif /* HAVEAVAHI / browsetime, / Next browse send time _/ senddoctime, / Send-Document time _/ expiretime, / Subscription expire time / @@ -672,6 +676,9 @@ main(int argc, / I - Number of comm */
current_time = time(NULL); +#ifdef HAVE_AVAHI
}
diff -up cups-1.5.0/scheduler/printers.c.avahi-5-services cups-1.5.0/scheduler/printers.c --- cups-1.5.0/scheduler/printers.c.avahi-5-services 2011-10-19 11:53:31.916181835 +0100 +++ cups-1.5.0/scheduler/printers.c 2011-10-19 11:53:32.156177388 +0100 @@ -883,9 +883,9 @@ cupsdDeletePrinter( cupsdClearString(&p->alert); cupsdClearString(&p->alert_description);
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cupsdClearString(&p->pdl); -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
cupsArrayDelete(p->filetypes);
@@ -3787,7 +3787,7 @@ add_printer_formats(cupsd_printer_t *p) attr->values[i].string.text = _cupsStrAlloc(mimetype); }
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVEAVAHI) { char pdl[1024]; /* Buffer to build pdl list / mime_filtert *filter; / MIME filter looping var / @@ -3843,7 +3843,7 @@ add_printer_formats(cupsd_printer_t p)
cupsdSetString(&p->pdl, pdl);
} -#endif /* HAVEDNSSD / +#endif /_ defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */ }
diff -up cups-1.5.0/scheduler/printers.h.avahi-5-services cups-1.5.0/scheduler/printers.h --- cups-1.5.0/scheduler/printers.h.avahi-5-services 2011-03-18 18:42:46.000000000 +0000 +++ cups-1.5.0/scheduler/printers.h 2011-10-19 11:53:32.157177369 +0100 @@ -16,6 +16,9 @@
+#ifdef HAVEAVAHI +# include "avahi.h" +#endif / HAVE_AVAHI */
@@ -95,16 +98,23 @@ struct cupsd_printer_s time_t markertime; /* Last time marker attributes were updated / _ppd_cachet *pc; / PPD cache and mapping data */
-#ifdef HAVE_DNSSD +#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) char _regname, / Name used for service registration */
+#ifdef HAVE_AVAHI
Version: 1.6-feature CUPS.org User: twaugh.redhat
I'm in the process of adding support for Avahi, an implementation of mDNS/DNS-SD.
It is not yet complete, but seems to be working for at least the dnssd backend.
I'm attaching a patch for review, to see if I'm heading in the right direction before continuing on with the scheduler.