|
|
9829b01 |
diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c
|
|
|
9829b01 |
index 99b8e7b..2688eff 100644
|
|
|
9829b01 |
--- a/cgi-bin/admin.c
|
|
|
9829b01 |
+++ b/cgi-bin/admin.c
|
|
|
9829b01 |
@@ -1643,7 +1643,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
|
|
|
9829b01 |
else
|
|
|
9829b01 |
local_protocols[0] = '\0';
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
if (cgiGetVariable("BROWSE_LOCAL_DNSSD"))
|
|
|
9829b01 |
{
|
|
|
9829b01 |
if (local_protocols[0])
|
|
|
9829b01 |
@@ -1651,7 +1651,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
|
|
|
9829b01 |
else
|
|
|
9829b01 |
strcat(local_protocols, "dnssd");
|
|
|
9829b01 |
}
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_LDAP
|
|
|
9829b01 |
if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
|
|
|
9829b01 |
@@ -2718,9 +2718,9 @@ do_menu(http_t *http) /* I - HTTP connection */
|
|
|
9829b01 |
#endif /* HAVE_GSSAPI */
|
|
|
9829b01 |
cgiSetVariable("KERBEROS", "");
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
cgiSetVariable("HAVE_DNSSD", "1");
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_LDAP
|
|
|
9829b01 |
cgiSetVariable("HAVE_LDAP", "1");
|
|
|
9829b01 |
diff --git a/scheduler/client.c b/scheduler/client.c
|
|
|
9829b01 |
index e4c9b01..984dcc5 100644
|
|
|
9829b01 |
--- a/scheduler/client.c
|
|
|
9829b01 |
+++ b/scheduler/client.c
|
|
|
9829b01 |
@@ -4987,7 +4987,7 @@ valid_host(cupsd_client_t *con) /* I - Client connection */
|
|
|
9829b01 |
!strncmp(host, "[::1]:", 6));
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Check if the hostname is something.local (Bonjour); if so, allow it.
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -4996,7 +4996,7 @@ valid_host(cupsd_client_t *con) /* I - Client connection */
|
|
|
9829b01 |
(!_cups_strcasecmp(end, ".local") || !_cups_strncasecmp(end, ".local:", 7) ||
|
|
|
9829b01 |
!_cups_strcasecmp(end, ".local.") || !_cups_strncasecmp(end, ".local.:", 8)))
|
|
|
9829b01 |
return (1);
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Check if the hostname is an IP address...
|
|
|
9829b01 |
diff --git a/scheduler/conf.c b/scheduler/conf.c
|
|
|
e462076 |
index badc630..c1edd39 100644
|
|
|
9829b01 |
--- a/scheduler/conf.c
|
|
|
9829b01 |
+++ b/scheduler/conf.c
|
|
|
e462076 |
@@ -648,7 +648,7 @@ cupsdReadConfiguration(void)
|
|
|
e462076 |
Browsing = CUPS_DEFAULT_BROWSING;
|
|
|
e462076 |
DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED;
|
|
|
e462076 |
|
|
|
e462076 |
-#ifdef HAVE_DNSSD
|
|
|
e462076 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
cupsdSetString(&DNSSDRegType, "_ipp._tcp,_cups");
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c
|
|
|
e462076 |
index eb3c862..48dcef9 100644
|
|
|
9829b01 |
--- a/scheduler/dirsvc.c
|
|
|
9829b01 |
+++ b/scheduler/dirsvc.c
|
|
|
9829b01 |
@@ -27,6 +27,7 @@
|
|
|
9829b01 |
* ldap_connect() - Start new LDAP connection
|
|
|
9829b01 |
* ldap_reconnect() - Reconnect to LDAP Server
|
|
|
9829b01 |
* ldap_disconnect() - Disconnect from LDAP Server
|
|
|
9829b01 |
+ * cupsdStartAvahiClient() - Start an Avahi client if needed
|
|
|
9829b01 |
* cupsdStartBrowsing() - Start sending and receiving broadcast
|
|
|
9829b01 |
* information.
|
|
|
9829b01 |
* cupsdStartPolling() - Start polling servers as needed.
|
|
|
9829b01 |
@@ -45,6 +46,8 @@
|
|
|
9829b01 |
* printer.
|
|
|
9829b01 |
* dnssdPackTxtRecord() - Pack an array of key/value pairs into the TXT
|
|
|
9829b01 |
* record format.
|
|
|
9829b01 |
+ * avahiPackTxtRecord() - Pack an array of key/value pairs into an
|
|
|
9829b01 |
+ * AvahiStringList.
|
|
|
9829b01 |
* dnssdRegisterCallback() - DNSServiceRegister callback.
|
|
|
9829b01 |
* dnssdRegisterPrinter() - Start sending broadcast information for a
|
|
|
9829b01 |
* printer or update the broadcast contents.
|
|
|
9829b01 |
@@ -83,6 +86,7 @@
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
#include "cupsd.h"
|
|
|
9829b01 |
+#include <assert.h>
|
|
|
9829b01 |
#include <grp.h>
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_DNSSD
|
|
|
9829b01 |
@@ -97,6 +101,17 @@
|
|
|
9829b01 |
# endif /* HAVE_SYSTEMCONFIGURATION */
|
|
|
9829b01 |
# endif /* __APPLE__ */
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+# include <avahi-common/domain.h>
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+typedef char *cupsd_txt_record_t;
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+typedef AvahiStringList *cupsd_txt_record_t;
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
@@ -159,27 +174,39 @@ static void update_polling(void);
|
|
|
9829b01 |
static void update_smb(int onoff);
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
+static cupsd_txt_record_t dnssdBuildTxtRecord(int *txt_len, cupsd_printer_t *p,
|
|
|
9829b01 |
+ int for_lpd);
|
|
|
9829b01 |
+static int dnssdComparePrinters(cupsd_printer_t *a, cupsd_printer_t *b);
|
|
|
9829b01 |
+static void dnssdDeregisterPrinter(cupsd_printer_t *p);
|
|
|
9829b01 |
+static void dnssdRegisterPrinter(cupsd_printer_t *p);
|
|
|
9829b01 |
+static void dnssdStop(void);
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
#ifdef HAVE_DNSSD
|
|
|
9829b01 |
# ifdef HAVE_COREFOUNDATION
|
|
|
9829b01 |
static void dnssdAddAlias(const void *key, const void *value,
|
|
|
9829b01 |
void *context);
|
|
|
9829b01 |
# endif /* HAVE_COREFOUNDATION */
|
|
|
9829b01 |
-static char *dnssdBuildTxtRecord(int *txt_len, cupsd_printer_t *p,
|
|
|
9829b01 |
- int for_lpd);
|
|
|
9829b01 |
-static int dnssdComparePrinters(cupsd_printer_t *a, cupsd_printer_t *b);
|
|
|
9829b01 |
-static void dnssdDeregisterPrinter(cupsd_printer_t *p);
|
|
|
9829b01 |
-static char *dnssdPackTxtRecord(int *txt_len, char *keyvalue[][2],
|
|
|
9829b01 |
- int count);
|
|
|
9829b01 |
static void dnssdRegisterCallback(DNSServiceRef sdRef,
|
|
|
9829b01 |
DNSServiceFlags flags,
|
|
|
9829b01 |
DNSServiceErrorType errorCode,
|
|
|
9829b01 |
const char *name, const char *regtype,
|
|
|
9829b01 |
const char *domain, void *context);
|
|
|
9829b01 |
-static void dnssdRegisterPrinter(cupsd_printer_t *p);
|
|
|
9829b01 |
-static void dnssdStop(void);
|
|
|
9829b01 |
static void dnssdUpdate(void);
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+static AvahiStringList *avahiPackTxtRecord(char *keyvalue[][2],
|
|
|
9829b01 |
+ int count);
|
|
|
9829b01 |
+static void avahi_entry_group_cb (AvahiEntryGroup *group,
|
|
|
9829b01 |
+ AvahiEntryGroupState state,
|
|
|
9829b01 |
+ void *userdata);
|
|
|
9829b01 |
+static void avahi_client_cb (AvahiClient *client,
|
|
|
9829b01 |
+ AvahiClientState state,
|
|
|
9829b01 |
+ void *userdata);
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
#ifdef HAVE_LDAP
|
|
|
9829b01 |
static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
|
|
|
9829b01 |
{
|
|
|
9829b01 |
@@ -283,10 +310,10 @@ cupsdDeregisterPrinter(
|
|
|
9829b01 |
ldap_dereg_printer(p);
|
|
|
9829b01 |
#endif /* HAVE_LDAP */
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
- if (removeit && (BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
+ if (removeit && (BrowseLocalProtocols & BROWSE_DNSSD))
|
|
|
9829b01 |
dnssdDeregisterPrinter(p);
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -702,10 +729,10 @@ cupsdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
|
|
|
9829b01 |
slpRegisterPrinter(p); */
|
|
|
9829b01 |
#endif /* HAVE_LIBSLP */
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
- if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
+ if ((BrowseLocalProtocols & BROWSE_DNSSD))
|
|
|
9829b01 |
dnssdRegisterPrinter(p);
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -1419,6 +1446,27 @@ ldap_disconnect(LDAP *ld) /* I - LDAP handle */
|
|
|
9829b01 |
#endif /* HAVE_LDAP */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+/*
|
|
|
9829b01 |
+ * 'cupsdStartAvahiClient()' - Start an Avahi client if needed
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+void
|
|
|
9829b01 |
+cupsdStartAvahiClient(void)
|
|
|
9829b01 |
+{
|
|
|
9829b01 |
+ if (!AvahiCupsClient && !AvahiCupsClientConnecting)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ if (!AvahiCupsPollHandle)
|
|
|
9829b01 |
+ AvahiCupsPollHandle = avahi_cups_poll_new ();
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (AvahiCupsPollHandle)
|
|
|
9829b01 |
+ avahi_client_new (avahi_cups_poll_get (AvahiCupsPollHandle),
|
|
|
9829b01 |
+ AVAHI_CLIENT_NO_FAIL, avahi_client_cb, NULL, NULL);
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+}
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -1542,13 +1590,16 @@ cupsdStartBrowsing(void)
|
|
|
9829b01 |
else
|
|
|
9829b01 |
BrowseSocket = -1;
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_DNSSD)
|
|
|
9829b01 |
{
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
DNSServiceErrorType error; /* Error from service creation */
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
cupsd_listener_t *lis; /* Current listening socket */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* First create a "master" connection for all registrations...
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -1573,6 +1624,7 @@ cupsdStartBrowsing(void)
|
|
|
9829b01 |
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
|
|
9829b01 |
|
|
|
9829b01 |
cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Then get the port we use for registrations. If we are not listening
|
|
|
9829b01 |
@@ -1606,9 +1658,16 @@ cupsdStartBrowsing(void)
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
cupsdUpdateDNSSDName();
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ cupsdStartAvahiClient ();
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
}
|
|
|
9829b01 |
- }
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_LIBSLP
|
|
|
9829b01 |
if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
|
|
|
9829b01 |
@@ -1834,10 +1893,10 @@ cupsdStopBrowsing(void)
|
|
|
9829b01 |
BrowseSocket = -1;
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
- if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
+ if ((BrowseLocalProtocols & BROWSE_DNSSD))
|
|
|
9829b01 |
dnssdStop();
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_LIBSLP
|
|
|
9829b01 |
if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
|
|
|
9829b01 |
@@ -1902,7 +1961,7 @@ cupsdStopPolling(void)
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'cupsdUpdateDNSSDName()' - Update the computer name we use for browsing...
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -1910,8 +1969,14 @@ cupsdStopPolling(void)
|
|
|
9829b01 |
void
|
|
|
9829b01 |
cupsdUpdateDNSSDName(void)
|
|
|
9829b01 |
{
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
DNSServiceErrorType error; /* Error from service creation */
|
|
|
9829b01 |
char webif[1024]; /* Web interface share name */
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ int ret; /* Error from service creation */
|
|
|
9829b01 |
+ char webif[AVAHI_LABEL_MAX]; /* Web interface share name */
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
# ifdef HAVE_SYSTEMCONFIGURATION
|
|
|
9829b01 |
SCDynamicStoreRef sc; /* Context for dynamic store */
|
|
|
9829b01 |
CFDictionaryRef btmm; /* Back-to-My-Mac domains */
|
|
|
9829b01 |
@@ -2042,6 +2107,7 @@ cupsdUpdateDNSSDName(void)
|
|
|
9829b01 |
else
|
|
|
9829b01 |
strlcpy(webif, "CUPS Web Interface", sizeof(webif));
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
if (WebIFRef)
|
|
|
9829b01 |
DNSServiceRefDeallocate(WebIFRef);
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -2054,9 +2120,45 @@ cupsdUpdateDNSSDName(void)
|
|
|
9829b01 |
NULL)) != kDNSServiceErr_NoError)
|
|
|
9829b01 |
cupsdLogMessage(CUPSD_LOG_ERROR,
|
|
|
9829b01 |
"DNS-SD web interface registration failed: %d", error);
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ if (!AvahiCupsClient)
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Client not yet running.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+ return;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (AvahiWebIFGroup)
|
|
|
9829b01 |
+ avahi_entry_group_reset (AvahiWebIFGroup);
|
|
|
9829b01 |
+ else
|
|
|
9829b01 |
+ AvahiWebIFGroup = avahi_entry_group_new (AvahiCupsClient,
|
|
|
9829b01 |
+ avahi_entry_group_cb,
|
|
|
9829b01 |
+ NULL);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (AvahiWebIFGroup)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ ret = avahi_entry_group_add_service (AvahiWebIFGroup,
|
|
|
9829b01 |
+ AVAHI_IF_UNSPEC,
|
|
|
9829b01 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
9829b01 |
+ 0, /* flags */
|
|
|
9829b01 |
+ webif, /* name */
|
|
|
9829b01 |
+ "_http._tcp", /* type */
|
|
|
9829b01 |
+ NULL, /* domain */
|
|
|
9829b01 |
+ NULL, /* host */
|
|
|
9829b01 |
+ DNSSDPort, /* port */
|
|
|
9829b01 |
+ "path=/", NULL);
|
|
|
9829b01 |
+ if (ret == 0)
|
|
|
9829b01 |
+ ret = avahi_entry_group_commit (AvahiWebIFGroup);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (ret != 0)
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_ERROR,
|
|
|
9829b01 |
+ "Avahi web interface registration failed: %d", ret);
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
}
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifdef HAVE_LDAP
|
|
|
9829b01 |
@@ -2334,13 +2436,15 @@ dnssdAddAlias(const void *key, /* I - Key */
|
|
|
9829b01 |
"Bad Back to My Mac domain in dynamic store!");
|
|
|
9829b01 |
}
|
|
|
9829b01 |
# endif /* HAVE_COREFOUNDATION */
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'dnssdBuildTxtRecord()' - Build a TXT record from printer info.
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
-static char * /* O - TXT record */
|
|
|
9829b01 |
+static cupsd_txt_record_t /* O - TXT record */
|
|
|
9829b01 |
dnssdBuildTxtRecord(
|
|
|
9829b01 |
int *txt_len, /* O - TXT record length */
|
|
|
9829b01 |
cupsd_printer_t *p, /* I - Printer information */
|
|
|
9829b01 |
@@ -2379,7 +2483,12 @@ dnssdBuildTxtRecord(
|
|
|
9829b01 |
keyvalue[i ][0] = "ty";
|
|
|
9829b01 |
keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
|
|
|
9829b01 |
|
|
|
9829b01 |
- snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.", DNSSDHostName);
|
|
|
9829b01 |
+ snprintf(admin_hostname, sizeof(admin_hostname),
|
|
|
9829b01 |
+ "%s.local"
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+ "." /* terminating dot no good for Avahi */
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+ , DNSSDHostName);
|
|
|
9829b01 |
httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
|
|
|
9829b01 |
"http", NULL, admin_hostname, DNSSDPort, "/%s/%s",
|
|
|
9829b01 |
(p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
|
|
|
9829b01 |
@@ -2462,7 +2571,12 @@ dnssdBuildTxtRecord(
|
|
|
9829b01 |
* Then pack them into a proper txt record...
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
return (dnssdPackTxtRecord(txt_len, keyvalue, i));
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ return (avahiPackTxtRecord(keyvalue, i));
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -2474,7 +2588,16 @@ static int /* O - Result of comparison */
|
|
|
9829b01 |
dnssdComparePrinters(cupsd_printer_t *a,/* I - First printer */
|
|
|
9829b01 |
cupsd_printer_t *b)/* I - Second printer */
|
|
|
9829b01 |
{
|
|
|
9829b01 |
- return (_cups_strcasecmp(a->reg_name, b->reg_name));
|
|
|
9829b01 |
+ if (!a->reg_name)
|
|
|
9829b01 |
+ if (!b->reg_name)
|
|
|
9829b01 |
+ return 0;
|
|
|
9829b01 |
+ else
|
|
|
9829b01 |
+ return -1;
|
|
|
9829b01 |
+ else
|
|
|
9829b01 |
+ if (!b->reg_name)
|
|
|
9829b01 |
+ return 1;
|
|
|
9829b01 |
+ else
|
|
|
9829b01 |
+ return (_cups_strcasecmp(a->reg_name, b->reg_name));
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -2489,6 +2612,10 @@ dnssdDeregisterPrinter(
|
|
|
9829b01 |
{
|
|
|
9829b01 |
cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+ if (!DNSSDRef)
|
|
|
9829b01 |
+ return;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Closing the socket deregisters the service
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -2524,6 +2651,24 @@ dnssdDeregisterPrinter(
|
|
|
9829b01 |
free(p->printer_txt);
|
|
|
9829b01 |
p->printer_txt = NULL;
|
|
|
9829b01 |
}
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ if (p->avahi_group)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ avahi_entry_group_reset (p->avahi_group);
|
|
|
9829b01 |
+ avahi_entry_group_free (p->avahi_group);
|
|
|
9829b01 |
+ p->avahi_group = NULL;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (p->ipp_txt)
|
|
|
9829b01 |
+ avahi_string_list_free (p->ipp_txt);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (p->printer_txt)
|
|
|
9829b01 |
+ avahi_string_list_free (p->printer_txt);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ p->ipp_txt = p->printer_txt = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Remove the printer from the array of DNS-SD printers, then clear the
|
|
|
9829b01 |
@@ -2533,8 +2678,10 @@ dnssdDeregisterPrinter(
|
|
|
9829b01 |
cupsArrayRemove(DNSSDPrinters, p);
|
|
|
9829b01 |
cupsdClearString(&p->reg_name);
|
|
|
9829b01 |
}
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'dnssdPackTxtRecord()' - Pack an array of key/value pairs into the
|
|
|
9829b01 |
* TXT record format.
|
|
|
9829b01 |
@@ -2644,8 +2791,10 @@ dnssdRegisterCallback(
|
|
|
9829b01 |
LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
|
|
|
9829b01 |
}
|
|
|
9829b01 |
}
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'dnssdRegisterPrinter()' - Start sending broadcast information for a printer
|
|
|
9829b01 |
* or update the broadcast contents.
|
|
|
e462076 |
@@ -2654,20 +2803,40 @@ dnssdRegisterCallback(
|
|
|
9829b01 |
static void
|
|
|
9829b01 |
dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
|
|
|
9829b01 |
{
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
DNSServiceErrorType se; /* dnssd errors */
|
|
|
9829b01 |
char *ipp_txt, /* IPP TXT record buffer */
|
|
|
9829b01 |
*printer_txt, /* LPD TXT record buffer */
|
|
|
9829b01 |
- name[1024], /* Service name */
|
|
|
9829b01 |
- *nameptr; /* Pointer into name */
|
|
|
9829b01 |
+ name[1024]; /* Service name */
|
|
|
9829b01 |
int ipp_len, /* IPP TXT record length */
|
|
|
9829b01 |
printer_len, /* LPD TXT record length */
|
|
|
9829b01 |
printer_port; /* LPD port number */
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ int ret; /* Error code */
|
|
|
9829b01 |
+ AvahiStringList *ipp_txt, /* IPP TXT record */
|
|
|
9829b01 |
+ *printer_txt; /* LPD TXT record */
|
|
|
e462076 |
+ char name[AVAHI_LABEL_MAX], /* Service name */
|
|
|
e462076 |
+ fullsubtype[AVAHI_LABEL_MAX]; /* Full subtype */
|
|
|
9829b01 |
+ char *regtype_copy, /* Writeable copy of reg type */
|
|
|
e462076 |
+ *subtype, /* Current service sub type */
|
|
|
e462076 |
+ *nextsubtype; /* Next service sub type */
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+ char *nameptr; /* Pointer into name */
|
|
|
9829b01 |
const char *regtype; /* Registration type */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+ if (!DNSSDRef)
|
|
|
9829b01 |
+ return;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterPrinter(%s) %s", p->name,
|
|
|
9829b01 |
!p->ipp_ref ? "new" : "update");
|
|
|
9829b01 |
-
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterPrinter(%s) %s", p->name,
|
|
|
9829b01 |
+ !p->avahi_group ? "new" : "update");
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* If per-printer sharing was just disabled make sure we're not
|
|
|
9829b01 |
* registered before returning.
|
|
|
e462076 |
@@ -2686,12 +2855,36 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
|
|
|
9829b01 |
if (p->info && strlen(p->info) > 0)
|
|
|
9829b01 |
{
|
|
|
9829b01 |
if (DNSSDComputerName)
|
|
|
9829b01 |
- snprintf(name, sizeof(name), "%s @ %s", p->info, DNSSDComputerName);
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Make sure there is room for at least 15 characters of
|
|
|
9829b01 |
+ * DNSSDComputerName.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ assert(sizeof(name) >= 15 + 4);
|
|
|
9829b01 |
+ nameptr = name + strlcpy(name, p->info,
|
|
|
9829b01 |
+ sizeof(name) - 4 -
|
|
|
9829b01 |
+ strnlen(DNSSDComputerName, 15));
|
|
|
9829b01 |
+ nameptr += strlcpy(nameptr, " @ ", sizeof(name) - (nameptr - name));
|
|
|
9829b01 |
+ strlcpy(nameptr, DNSSDComputerName, sizeof(name) - (nameptr - name));
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
else
|
|
|
9829b01 |
strlcpy(name, p->info, sizeof(name));
|
|
|
9829b01 |
}
|
|
|
9829b01 |
else if (DNSSDComputerName)
|
|
|
9829b01 |
- snprintf(name, sizeof(name), "%s @ %s", p->name, DNSSDComputerName);
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Make sure there is room for at least 15 characters of
|
|
|
9829b01 |
+ * DNSSDComputerName.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ assert(sizeof(name) >= 15 + 4);
|
|
|
9829b01 |
+ nameptr = name + strlcpy(name, p->info,
|
|
|
9829b01 |
+ sizeof(name) - 4 -
|
|
|
9829b01 |
+ strnlen(DNSSDComputerName, 15));
|
|
|
9829b01 |
+ nameptr += strlcpy(nameptr, " @ ", sizeof(name) - (nameptr - name));
|
|
|
9829b01 |
+ strlcpy(nameptr, DNSSDComputerName, sizeof(name) - (nameptr - name));
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
else
|
|
|
9829b01 |
strlcpy(name, p->name, sizeof(name));
|
|
|
9829b01 |
|
|
|
e462076 |
@@ -2712,6 +2905,7 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
|
|
|
9829b01 |
* Register IPP and (optionally) LPD...
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
ipp_len = 0; /* anti-compiler-warning-code */
|
|
|
9829b01 |
ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
|
|
|
9829b01 |
|
|
|
e462076 |
@@ -2884,6 +3078,209 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
|
|
|
9829b01 |
|
|
|
9829b01 |
if (printer_txt)
|
|
|
9829b01 |
free(printer_txt);
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ if (!AvahiCupsClient)
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Client not running yet. The client callback will call us again later.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+ return;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ ipp_txt = dnssdBuildTxtRecord(NULL, p, 0);
|
|
|
9829b01 |
+ printer_txt = dnssdBuildTxtRecord(NULL, p, 1);
|
|
|
9829b01 |
+ regtype = (p->type & CUPS_PRINTER_FAX) ? "_fax-ipp._tcp" : DNSSDRegType;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (p->avahi_group && p->ipp_txt && ipp_txt &&
|
|
|
9829b01 |
+ !avahi_string_list_equal (p->ipp_txt, ipp_txt))
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Update the existing registration...
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ avahi_string_list_free (p->ipp_txt);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (p->printer_txt)
|
|
|
9829b01 |
+ avahi_string_list_free (p->printer_txt);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ /*
|
|
|
e462076 |
+ * Update the service group entry.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
e462076 |
+ regtype_copy = strdup (regtype);
|
|
|
e462076 |
+ subtype = strchr (regtype_copy, ',');
|
|
|
e462076 |
+ if (subtype)
|
|
|
e462076 |
+ *subtype = '\0';
|
|
|
e462076 |
+
|
|
|
e462076 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG,
|
|
|
e462076 |
+ "Updating TXT record for %s (%s)", name, regtype_copy);
|
|
|
e462076 |
+ ret = avahi_entry_group_update_service_txt_strlst (p->avahi_group,
|
|
|
e462076 |
+ AVAHI_IF_UNSPEC,
|
|
|
e462076 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
e462076 |
+ 0, name,
|
|
|
e462076 |
+ regtype_copy,
|
|
|
e462076 |
+ NULL, ipp_txt);
|
|
|
e462076 |
+ free (regtype_copy);
|
|
|
9829b01 |
+
|
|
|
e462076 |
+ if (ret < 0)
|
|
|
e462076 |
+ goto update_failed;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ p->ipp_txt = ipp_txt;
|
|
|
9829b01 |
+ ipp_txt = NULL;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (BrowseLocalProtocols & BROWSE_LPD)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ ret = avahi_entry_group_update_service_txt_strlst (p->avahi_group,
|
|
|
9829b01 |
+ AVAHI_IF_UNSPEC,
|
|
|
9829b01 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
9829b01 |
+ 0, name,
|
|
|
9829b01 |
+ "_printer._tcp", NULL,
|
|
|
9829b01 |
+ printer_txt);
|
|
|
9829b01 |
+ if (ret < 0)
|
|
|
9829b01 |
+ goto update_failed;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ p->printer_txt = printer_txt;
|
|
|
9829b01 |
+ printer_txt = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ ret = avahi_entry_group_commit (p->avahi_group);
|
|
|
9829b01 |
+ if (ret < 0)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ update_failed:
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_ERROR,
|
|
|
9829b01 |
+ "Failed to update TXT record for %s: %d",
|
|
|
9829b01 |
+ name, ret);
|
|
|
9829b01 |
+ avahi_entry_group_reset (p->avahi_group);
|
|
|
9829b01 |
+ avahi_entry_group_free (p->avahi_group);
|
|
|
9829b01 |
+ p->avahi_group = NULL;
|
|
|
9829b01 |
+ ipp_txt = p->ipp_txt;
|
|
|
9829b01 |
+ p->ipp_txt = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (!p->avahi_group)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Initial registration. Use the _fax subtype for fax queues...
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ p->avahi_group = avahi_entry_group_new (AvahiCupsClient,
|
|
|
9829b01 |
+ avahi_entry_group_cb,
|
|
|
9829b01 |
+ p);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
|
|
|
9829b01 |
+ "Registering Avahi printer %s with name \"%s\" and "
|
|
|
9829b01 |
+ "type \"%s\"", p->name, name, regtype);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (!p->avahi_group)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ ret = 0;
|
|
|
9829b01 |
+ goto add_failed;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Add each service type (DNSSDRegType may contain several,
|
|
|
9829b01 |
+ * separated by commas).
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
e462076 |
+ subtype = regtype_copy = strdup (regtype);
|
|
|
e462076 |
+ while (subtype && *subtype)
|
|
|
9829b01 |
+ {
|
|
|
e462076 |
+ nextsubtype = strchr (subtype, ',');
|
|
|
e462076 |
+ if (nextsubtype)
|
|
|
e462076 |
+ *nextsubtype++ = '\0';
|
|
|
9829b01 |
+
|
|
|
e462076 |
+ if (subtype == regtype_copy)
|
|
|
e462076 |
+ {
|
|
|
e462076 |
+ /*
|
|
|
e462076 |
+ * Main type entry.
|
|
|
e462076 |
+ */
|
|
|
e462076 |
+
|
|
|
e462076 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG,
|
|
|
e462076 |
+ "Adding TXT record for %s (%s)", name, regtype_copy);
|
|
|
e462076 |
+ ret = avahi_entry_group_add_service_strlst (p->avahi_group,
|
|
|
e462076 |
+ AVAHI_IF_UNSPEC,
|
|
|
e462076 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
e462076 |
+ 0, name, regtype_copy,
|
|
|
e462076 |
+ NULL, NULL,
|
|
|
e462076 |
+ DNSSDPort,
|
|
|
e462076 |
+ ipp_txt);
|
|
|
e462076 |
+ }
|
|
|
e462076 |
+ else
|
|
|
e462076 |
+ {
|
|
|
e462076 |
+ /*
|
|
|
e462076 |
+ * Sub-type entry.
|
|
|
e462076 |
+ */
|
|
|
e462076 |
+
|
|
|
e462076 |
+ snprintf (fullsubtype, sizeof(fullsubtype),
|
|
|
e462076 |
+ "%s._sub.%s", subtype, regtype_copy);
|
|
|
e462076 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG,
|
|
|
e462076 |
+ "Adding TXT record for %s (%s)", name, fullsubtype);
|
|
|
e462076 |
+ ret = avahi_entry_group_add_service_subtype (p->avahi_group,
|
|
|
e462076 |
+ AVAHI_IF_UNSPEC,
|
|
|
e462076 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
e462076 |
+ 0, name,
|
|
|
e462076 |
+ regtype_copy,
|
|
|
e462076 |
+ NULL, fullsubtype);
|
|
|
e462076 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (ret < 0)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ free (regtype_copy);
|
|
|
9829b01 |
+ goto add_failed;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
e462076 |
+ subtype = nextsubtype;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ free (regtype_copy);
|
|
|
9829b01 |
+ p->ipp_txt = ipp_txt;
|
|
|
9829b01 |
+ ipp_txt = NULL;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (BrowseLocalProtocols & BROWSE_LPD)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
|
|
|
9829b01 |
+ "Registering Avahi printer %s with name \"%s\" and "
|
|
|
9829b01 |
+ "type \"_printer._tcp\"", p->name, name);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ ret = avahi_entry_group_add_service_strlst (p->avahi_group,
|
|
|
9829b01 |
+ AVAHI_IF_UNSPEC,
|
|
|
9829b01 |
+ AVAHI_PROTO_UNSPEC,
|
|
|
9829b01 |
+ 0, name,
|
|
|
9829b01 |
+ "_printer._tcp", NULL, NULL,
|
|
|
9829b01 |
+ 515,
|
|
|
9829b01 |
+ printer_txt);
|
|
|
9829b01 |
+ if (ret < 0)
|
|
|
9829b01 |
+ goto add_failed;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ p->printer_txt = printer_txt;
|
|
|
9829b01 |
+ printer_txt = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ ret = avahi_entry_group_commit (p->avahi_group);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (ret < 0)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ add_failed:
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_ERROR,
|
|
|
9829b01 |
+ "Failed to add Avahi entry for %s: %d",
|
|
|
9829b01 |
+ name, ret);
|
|
|
9829b01 |
+ if (p->avahi_group)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ avahi_entry_group_reset (p->avahi_group);
|
|
|
9829b01 |
+ avahi_entry_group_free (p->avahi_group);
|
|
|
9829b01 |
+ p->avahi_group = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+ ipp_txt = p->ipp_txt;
|
|
|
9829b01 |
+ p->ipp_txt = NULL;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (ipp_txt)
|
|
|
9829b01 |
+ avahi_string_list_free (ipp_txt);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (printer_txt)
|
|
|
9829b01 |
+ avahi_string_list_free (printer_txt);
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
e462076 |
@@ -2896,6 +3293,10 @@ dnssdStop(void)
|
|
|
9829b01 |
{
|
|
|
9829b01 |
cupsd_printer_t *p; /* Current printer */
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+ if (!DNSSDRef)
|
|
|
9829b01 |
+ return;
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* De-register the individual printers
|
|
|
e462076 |
@@ -2906,6 +3307,7 @@ dnssdStop(void)
|
|
|
9829b01 |
p = (cupsd_printer_t *)cupsArrayNext(Printers))
|
|
|
9829b01 |
dnssdDeregisterPrinter(p);
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Shutdown the rest of the service refs...
|
|
|
9829b01 |
*/
|
|
|
e462076 |
@@ -2926,14 +3328,17 @@ dnssdStop(void)
|
|
|
9829b01 |
|
|
|
9829b01 |
DNSServiceRefDeallocate(DNSSDRef);
|
|
|
9829b01 |
DNSSDRef = NULL;
|
|
|
9829b01 |
+#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
cupsArrayDelete(DNSSDPrinters);
|
|
|
9829b01 |
DNSSDPrinters = NULL;
|
|
|
9829b01 |
|
|
|
9829b01 |
DNSSDPort = 0;
|
|
|
9829b01 |
}
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'dnssdUpdate()' - Handle DNS-SD queries.
|
|
|
9829b01 |
*/
|
|
|
e462076 |
@@ -2955,6 +3360,147 @@ dnssdUpdate(void)
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+/*
|
|
|
9829b01 |
+ * 'avahiPackTxtRecord()' - Pack an array of key/value pairs into an
|
|
|
9829b01 |
+ * AvahiStringList.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+static AvahiStringList * /* O - new string list */
|
|
|
9829b01 |
+avahiPackTxtRecord(char *keyvalue[][2], /* I - Table of key value pairs */
|
|
|
9829b01 |
+ int count) /* I - Number of items in table */
|
|
|
9829b01 |
+{
|
|
|
9829b01 |
+ AvahiStringList *strlst = NULL;
|
|
|
9829b01 |
+ char **elements;
|
|
|
9829b01 |
+ size_t len;
|
|
|
9829b01 |
+ int i = 0;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ elements = malloc ((1 + count) * sizeof (char *));
|
|
|
9829b01 |
+ if (!elements)
|
|
|
9829b01 |
+ goto cleanup;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ for (i = 0; i < count; i++)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ len = (1 + strlen (keyvalue[i][0]) +
|
|
|
9829b01 |
+ (keyvalue[i][1] ? 1 + strlen (keyvalue[i][1]) : 1));
|
|
|
9829b01 |
+ elements[i] = malloc (len * sizeof (char));
|
|
|
9829b01 |
+ if (!elements[i])
|
|
|
9829b01 |
+ goto cleanup;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ snprintf (elements[i], len, "%s=%s", keyvalue[i][0], keyvalue[i][1]);
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ strlst = avahi_string_list_new_from_array ((const char **) elements, count);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+cleanup:
|
|
|
9829b01 |
+ while (--i >= 0)
|
|
|
9829b01 |
+ free (elements[i]);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ free (elements);
|
|
|
9829b01 |
+ return (strlst);
|
|
|
9829b01 |
+}
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+/*
|
|
|
9829b01 |
+ * 'avahi_entry_group_cb()' - Avahi entry group callback function.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+static void
|
|
|
9829b01 |
+avahi_entry_group_cb (AvahiEntryGroup *group,
|
|
|
9829b01 |
+ AvahiEntryGroupState state,
|
|
|
9829b01 |
+ void *userdata)
|
|
|
9829b01 |
+{
|
|
|
9829b01 |
+ char *name;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if (userdata)
|
|
|
9829b01 |
+ name = ((cupsd_printer_t *) userdata)->reg_name;
|
|
|
9829b01 |
+ else
|
|
|
9829b01 |
+ name = "CUPS web interface";
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ switch (state)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ case AVAHI_ENTRY_GROUP_UNCOMMITED:
|
|
|
9829b01 |
+ case AVAHI_ENTRY_GROUP_REGISTERING:
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ case AVAHI_ENTRY_GROUP_ESTABLISHED:
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG,
|
|
|
9829b01 |
+ "Avahi entry group established for %s", name);
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ default:
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG,
|
|
|
9829b01 |
+ "Avahi entry group %s has state %d",
|
|
|
9829b01 |
+ name, state);
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+}
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+/*
|
|
|
9829b01 |
+ * 'avahi_client_cb()' - Avahi client callback function.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+static void
|
|
|
9829b01 |
+avahi_client_cb (AvahiClient *client,
|
|
|
9829b01 |
+ AvahiClientState state,
|
|
|
9829b01 |
+ void *userdata)
|
|
|
9829b01 |
+{
|
|
|
9829b01 |
+ cupsd_printer_t *printer;
|
|
|
9829b01 |
+ switch (state)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ case AVAHI_CLIENT_S_RUNNING:
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Avahi client started successfully.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+ AvahiCupsClient = client;
|
|
|
9829b01 |
+ AvahiCupsClientConnecting = 0;
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client started");
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ cupsdUpdateDNSSDName ();
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
|
|
|
9829b01 |
+ printer;
|
|
|
9829b01 |
+ printer = (cupsd_printer_t *)cupsArrayNext(Printers))
|
|
|
9829b01 |
+ if (Browsing && (BrowseLocalProtocols & BROWSE_DNSSD) &&
|
|
|
9829b01 |
+ (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
|
|
|
9829b01 |
+ CUPS_PRINTER_SCANNER))) && printer->shared)
|
|
|
9829b01 |
+ dnssdRegisterPrinter (printer);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ case AVAHI_CLIENT_CONNECTING:
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * No Avahi daemon, client is waiting.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+ AvahiCupsClientConnecting = 1;
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client connecting");
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ case AVAHI_CLIENT_FAILURE:
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Avahi client failed, close it to allow a clean restart.
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_ERROR,
|
|
|
9829b01 |
+ "Avahi client failed, "
|
|
|
9829b01 |
+ "closing client to allow a clean restart");
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
|
|
|
9829b01 |
+ printer;
|
|
|
9829b01 |
+ printer = (cupsd_printer_t *)cupsArrayNext(Printers))
|
|
|
9829b01 |
+ dnssdDeregisterPrinter (printer);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ avahi_client_free(client);
|
|
|
9829b01 |
+ AvahiCupsClientConnecting = 0;
|
|
|
9829b01 |
+ AvahiCupsClient = NULL;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ break;
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ default:
|
|
|
9829b01 |
+ cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client state: %d", state);
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
+}
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* 'get_auth_info_required()' - Get the auth-info-required value to advertise.
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
diff --git a/scheduler/dirsvc.h b/scheduler/dirsvc.h
|
|
|
9829b01 |
index 99079bd..d53a179 100644
|
|
|
9829b01 |
--- a/scheduler/dirsvc.h
|
|
|
9829b01 |
+++ b/scheduler/dirsvc.h
|
|
|
9829b01 |
@@ -31,6 +31,10 @@
|
|
|
9829b01 |
# endif /* HAVE_LDAP_SSL_H */
|
|
|
9829b01 |
#endif /* HAVE_LDAP */
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+# include <avahi-client/publish.h>
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
/*
|
|
|
9829b01 |
* Browse protocols...
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
@@ -131,19 +135,22 @@ VAR int PollPipe VALUE(0);
|
|
|
9829b01 |
VAR cupsd_statbuf_t *PollStatusBuffer VALUE(NULL);
|
|
|
9829b01 |
/* Status buffer for pollers */
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
VAR char *DNSSDComputerName VALUE(NULL),
|
|
|
9829b01 |
/* Computer/server name */
|
|
|
9829b01 |
*DNSSDHostName VALUE(NULL),
|
|
|
9829b01 |
/* Hostname */
|
|
|
9829b01 |
*DNSSDRegType VALUE(NULL);
|
|
|
9829b01 |
/* Bonjour registration type */
|
|
|
9829b01 |
-VAR cups_array_t *DNSSDAlias VALUE(NULL);
|
|
|
9829b01 |
- /* List of dynamic ServerAlias's */
|
|
|
9829b01 |
VAR int DNSSDPort VALUE(0);
|
|
|
9829b01 |
/* Port number to register */
|
|
|
9829b01 |
VAR cups_array_t *DNSSDPrinters VALUE(NULL);
|
|
|
9829b01 |
/* Printers we have registered */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+VAR cups_array_t *DNSSDAlias VALUE(NULL);
|
|
|
9829b01 |
+ /* List of dynamic ServerAlias's */
|
|
|
9829b01 |
VAR DNSServiceRef DNSSDRef VALUE(NULL),
|
|
|
9829b01 |
/* Master DNS-SD service reference */
|
|
|
9829b01 |
WebIFRef VALUE(NULL),
|
|
|
9829b01 |
@@ -152,6 +159,17 @@ VAR DNSServiceRef DNSSDRef VALUE(NULL),
|
|
|
9829b01 |
/* Remote printer browse reference */
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+VAR AvahiCupsPoll *AvahiCupsPollHandle VALUE(NULL);
|
|
|
9829b01 |
+ /* AvahiCupsPoll object */
|
|
|
9829b01 |
+VAR AvahiClient *AvahiCupsClient VALUE(NULL);
|
|
|
9829b01 |
+ /* AvahiClient object */
|
|
|
9829b01 |
+VAR int AvahiCupsClientConnecting VALUE(0);
|
|
|
9829b01 |
+ /* Is AvahiClient object connecting? */
|
|
|
9829b01 |
+VAR AvahiEntryGroup *AvahiWebIFGroup VALUE(NULL);
|
|
|
9829b01 |
+ /* Web interface entry group */
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
#ifdef HAVE_LIBSLP
|
|
|
9829b01 |
VAR SLPHandle BrowseSLPHandle VALUE(NULL);
|
|
|
9829b01 |
/* SLP API handle */
|
|
|
9829b01 |
@@ -195,13 +213,14 @@ extern void cupsdRegisterPrinter(cupsd_printer_t *p);
|
|
|
9829b01 |
extern void cupsdRestartPolling(void);
|
|
|
9829b01 |
extern void cupsdSaveRemoteCache(void);
|
|
|
9829b01 |
extern void cupsdSendBrowseList(void);
|
|
|
9829b01 |
+extern void cupsdStartAvahiClient(void);
|
|
|
9829b01 |
extern void cupsdStartBrowsing(void);
|
|
|
9829b01 |
extern void cupsdStartPolling(void);
|
|
|
9829b01 |
extern void cupsdStopBrowsing(void);
|
|
|
9829b01 |
extern void cupsdStopPolling(void);
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
extern void cupsdUpdateDNSSDName(void);
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
#ifdef HAVE_LDAP
|
|
|
9829b01 |
extern void cupsdUpdateLDAPBrowse(void);
|
|
|
9829b01 |
#endif /* HAVE_LDAP */
|
|
|
9829b01 |
diff --git a/scheduler/ipp.c b/scheduler/ipp.c
|
|
|
9829b01 |
index a048baa..9a3ab11 100644
|
|
|
9829b01 |
--- a/scheduler/ipp.c
|
|
|
9829b01 |
+++ b/scheduler/ipp.c
|
|
|
9829b01 |
@@ -6087,7 +6087,7 @@ copy_printer_attrs(
|
|
|
9829b01 |
ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
|
|
|
9829b01 |
ippTimeToDate(curtime));
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
|
|
|
9829b01 |
{
|
|
|
9829b01 |
if (printer->reg_name)
|
|
|
9829b01 |
@@ -6097,7 +6097,7 @@ copy_printer_attrs(
|
|
|
9829b01 |
ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
|
|
|
9829b01 |
"printer-dns-sd-name", 0);
|
|
|
9829b01 |
}
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
if (!ra || cupsArrayFind(ra, "printer-error-policy"))
|
|
|
9829b01 |
ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
|
|
|
9829b01 |
diff --git a/scheduler/main.c b/scheduler/main.c
|
|
|
9829b01 |
index 1e60572..6c210e6 100644
|
|
|
9829b01 |
--- a/scheduler/main.c
|
|
|
9829b01 |
+++ b/scheduler/main.c
|
|
|
9829b01 |
@@ -120,6 +120,10 @@ main(int argc, /* I - Number of command-line args */
|
|
|
9829b01 |
cupsd_listener_t *lis; /* Current listener */
|
|
|
9829b01 |
time_t current_time, /* Current time */
|
|
|
9829b01 |
activity, /* Client activity timer */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ avahi_client_time, /* Time for next Avahi client
|
|
|
9829b01 |
+ check */
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
browse_time, /* Next browse send time */
|
|
|
9829b01 |
senddoc_time, /* Send-Document time */
|
|
|
9829b01 |
expire_time, /* Subscription expire time */
|
|
|
9829b01 |
@@ -662,6 +666,9 @@ main(int argc, /* I - Number of command-line args */
|
|
|
9829b01 |
*/
|
|
|
9829b01 |
|
|
|
9829b01 |
current_time = time(NULL);
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ avahi_client_time = current_time;
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
browse_time = current_time;
|
|
|
9829b01 |
event_time = current_time;
|
|
|
9829b01 |
expire_time = current_time;
|
|
|
9829b01 |
@@ -884,6 +891,16 @@ main(int argc, /* I - Number of command-line args */
|
|
|
9829b01 |
tmo = cupsdNextTimeout (&tmo_delay);
|
|
|
9829b01 |
if (tmo && tmo_delay == 0)
|
|
|
9829b01 |
cupsdRunTimeout (tmo);
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ /*
|
|
|
9829b01 |
+ * Try to restart the Avahi client every 10 seconds if needed...
|
|
|
9829b01 |
+ */
|
|
|
9829b01 |
+
|
|
|
9829b01 |
+ if ((current_time - avahi_client_time) >= 10)
|
|
|
9829b01 |
+ {
|
|
|
9829b01 |
+ avahi_client_time = current_time;
|
|
|
9829b01 |
+ cupsdStartAvahiClient();
|
|
|
9829b01 |
+ }
|
|
|
9829b01 |
#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
|
|
|
9829b01 |
#ifndef __APPLE__
|
|
|
9829b01 |
diff --git a/scheduler/printers.c b/scheduler/printers.c
|
|
|
9829b01 |
index 4686c4c..fac7bbc 100644
|
|
|
9829b01 |
--- a/scheduler/printers.c
|
|
|
9829b01 |
+++ b/scheduler/printers.c
|
|
|
9829b01 |
@@ -883,9 +883,9 @@ cupsdDeletePrinter(
|
|
|
9829b01 |
cupsdClearString(&p->alert);
|
|
|
9829b01 |
cupsdClearString(&p->alert_description);
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
cupsdClearString(&p->pdl);
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
|
|
|
9829b01 |
cupsArrayDelete(p->filetypes);
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -3765,7 +3765,7 @@ add_printer_formats(cupsd_printer_t *p) /* I - Printer */
|
|
|
9829b01 |
attr->values[i].string.text = _cupsStrAlloc(mimetype);
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
{
|
|
|
9829b01 |
char pdl[1024]; /* Buffer to build pdl list */
|
|
|
9829b01 |
mime_filter_t *filter; /* MIME filter looping var */
|
|
|
9829b01 |
@@ -3821,7 +3821,7 @@ add_printer_formats(cupsd_printer_t *p) /* I - Printer */
|
|
|
9829b01 |
|
|
|
9829b01 |
cupsdSetString(&p->pdl, pdl);
|
|
|
9829b01 |
}
|
|
|
9829b01 |
-#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
}
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
diff --git a/scheduler/printers.h b/scheduler/printers.h
|
|
|
9829b01 |
index 1751578..fb04651 100644
|
|
|
9829b01 |
--- a/scheduler/printers.h
|
|
|
9829b01 |
+++ b/scheduler/printers.h
|
|
|
9829b01 |
@@ -16,6 +16,9 @@
|
|
|
9829b01 |
#ifdef HAVE_DNSSD
|
|
|
9829b01 |
# include <dns_sd.h>
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+# include "avahi.h"
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
#include <cups/pwg-private.h>
|
|
|
9829b01 |
|
|
|
9829b01 |
|
|
|
9829b01 |
@@ -95,16 +98,23 @@ struct cupsd_printer_s
|
|
|
9829b01 |
time_t marker_time; /* Last time marker attributes were updated */
|
|
|
9829b01 |
_ppd_cache_t *pc; /* PPD cache and mapping data */
|
|
|
9829b01 |
|
|
|
9829b01 |
-#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
|
|
|
9829b01 |
char *reg_name, /* Name used for service registration */
|
|
|
9829b01 |
- *pdl, /* pdl value for TXT record */
|
|
|
9829b01 |
- *ipp_txt, /* IPP TXT record contents */
|
|
|
9829b01 |
+ *pdl; /* pdl value for TXT record */
|
|
|
9829b01 |
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
|
|
|
9829b01 |
+#ifdef HAVE_DNSSD
|
|
|
9829b01 |
+ char *ipp_txt, /* IPP TXT record contents */
|
|
|
9829b01 |
*printer_txt; /* LPD TXT record contents */
|
|
|
9829b01 |
int ipp_len, /* IPP TXT record length */
|
|
|
9829b01 |
printer_len; /* LPD TXT record length */
|
|
|
9829b01 |
DNSServiceRef ipp_ref, /* Reference for _ipp._tcp,_cups */
|
|
|
9829b01 |
printer_ref; /* Reference for _printer._tcp */
|
|
|
9829b01 |
#endif /* HAVE_DNSSD */
|
|
|
9829b01 |
+#ifdef HAVE_AVAHI
|
|
|
9829b01 |
+ AvahiStringList *ipp_txt, /* IPP TXT record */
|
|
|
9829b01 |
+ *printer_txt; /* LPD TXT record */
|
|
|
9829b01 |
+ AvahiEntryGroup *avahi_group; /* Avahi entry group */
|
|
|
9829b01 |
+#endif /* HAVE_AVAHI */
|
|
|
9829b01 |
};
|
|
|
9829b01 |
|
|
|
9829b01 |
|