]> git.meshlink.io Git - catta/commitdiff
add a new structure for configuration AvahiServerConfig
authorLennart Poettering <lennart@poettering.net>
Thu, 19 May 2005 21:49:28 +0000 (21:49 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 May 2005 21:49:28 +0000 (21:49 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@76 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/avahi-test.c
avahi-core/conformance-test.c
avahi-core/core.h
avahi-core/iface.c
avahi-core/server.c
avahi-core/server.h

index e275649053b7bf2fad23cce827c9df61dca57df9..f3ed3cc3197a50de608d07021cd80689b10ea136 100644 (file)
@@ -65,8 +65,8 @@ int main(int argc, char *argv[]) {
     AvahiSubscription *s;
     AvahiKey *k;
     AvahiEntryGroup *g;
-
-    avahi = avahi_server_new(NULL);
+    
+    avahi = avahi_server_new(NULL, NULL);
 
     g = avahi_entry_group_new(avahi, entry_group_callback, NULL);   
     
index 001bff13b05eddf6a28cdde62535846896a7132b..74c38332b00b4fe468d1a7878d1c34dcc918e3eb 100644 (file)
@@ -91,7 +91,7 @@ static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryG
 int main(int argc, char *argv[]) {
     GMainLoop *loop = NULL;
 
-    avahi = avahi_server_new(NULL);
+    avahi = avahi_server_new(NULL, NULL);
     create_service("gurke");
     avahi_server_dump(avahi, stdout);
     
index 98f36b2dcc0fd791d7ebedff95157e4405b5073b..49b09b5aa0f2cb78c74608e66ff0bdbc65e08c95 100644 (file)
@@ -48,9 +48,23 @@ typedef enum {
 
 typedef void (*AvahiEntryGroupCallback) (AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata);
 
-AvahiServer *avahi_server_new(GMainContext *c);
+typedef struct AvahiServerConfig {
+    gboolean register_hinfo;
+    gboolean register_addresses;
+    gboolean use_ipv4;
+    gboolean use_ipv6;
+    gchar *host_name;
+    gchar *domain_name;
+    gboolean check_response_ttl;
+} AvahiServerConfig;
+
+AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc);
 void avahi_server_free(AvahiServer* s);
 
+AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c);
+AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c);
+void avahi_server_config_free(AvahiServerConfig *c);
+    
 const gchar* avahi_server_get_domain(AvahiServer *s);
 const gchar* avahi_server_get_host_name(AvahiServer *s);
 
index 2448678f8b3e87243b93ac0216fd673d4ab4a333..61e5a4a87168f3f2c3efa3f7d14d2e867c9cd009 100644 (file)
@@ -47,7 +47,7 @@ static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a
             a->entry_group = NULL;
         }
     } else {
-        if (!a->entry_group) {
+        if (!a->entry_group && m->server->config.register_addresses) {
             a->entry_group = avahi_entry_group_new(m->server, NULL, NULL);
             avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, AF_UNSPEC, 0, NULL, &a->address); 
             avahi_entry_group_commit(a->entry_group);
index 31cbecce30077599043bac6ccda17020f9c044a1..316952b099119191394b61bd8746b8a1ae58774e 100644 (file)
@@ -626,7 +626,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, struct sockaddr *
 
         if (ttl != 255) {
             g_warning("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol);
-            if (!s->ignore_bad_ttl)
+            if (s->config.check_response_ttl)
                 return;
         }
 
@@ -698,21 +698,22 @@ static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer us
 }
 
 static void add_default_entries(AvahiServer *s) {
-    struct utsname utsname;
     AvahiAddress a;
-    AvahiRecord *r;
     
     g_assert(s);
 
-    return ;
-    
-    /* Fill in HINFO rr */
-    r = avahi_record_new_full(s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO);
-    uname(&utsname);
-    r->data.hinfo.cpu = g_strdup(g_strup(utsname.machine));
-    r->data.hinfo.os = g_strdup(g_strup(utsname.sysname));
-    avahi_server_add(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, r);
-    avahi_record_unref(r);
+    if (s->config.register_hinfo) {
+        struct utsname utsname;
+        AvahiRecord *r;
+        
+        /* Fill in HINFO rr */
+        r = avahi_record_new_full(s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO);
+        uname(&utsname);
+        r->data.hinfo.cpu = g_strdup(g_strup(utsname.machine));
+        r->data.hinfo.os = g_strdup(g_strup(utsname.sysname));
+        avahi_server_add(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, r);
+        avahi_record_unref(r);
+    }
 
     /* Add localhost entries */
     avahi_address_parse("127.0.0.1", AF_INET, &a);
@@ -722,7 +723,7 @@ static void add_default_entries(AvahiServer *s) {
     avahi_server_add_address(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "ip6-localhost", &a);
 }
 
-AvahiServer *avahi_server_new(GMainContext *c) {
+AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc) {
     AvahiServer *s;
     
     static GSourceFuncs source_funcs = {
@@ -736,21 +737,26 @@ AvahiServer *avahi_server_new(GMainContext *c) {
 
     s = g_new(AvahiServer, 1);
 
-    s->ignore_bad_ttl = FALSE;
     s->need_entry_cleanup = s->need_group_cleanup = FALSE;
+
+    if (sc)
+        avahi_server_config_copy(&s->config, sc);
+    else
+        avahi_server_config_init(&s->config);
     
-    s->fd_ipv4 = avahi_open_socket_ipv4();
-    s->fd_ipv6 = -1 /* avahi_open_socket_ipv6() */ ;
+    s->fd_ipv4 = s->config.use_ipv4 ? avahi_open_socket_ipv4() : -1;
+    s->fd_ipv6 = s->config.use_ipv6 ? avahi_open_socket_ipv6() : -1;
     
     if (s->fd_ipv6 < 0 && s->fd_ipv4 < 0) {
-        g_critical("Failed to create IP sockets.\n");
+        g_critical("Selected neither IPv6 nor IPv4 support, aborting.\n");
+        avahi_server_config_free(&s->config);
         g_free(s);
         return NULL;
     }
 
-    if (s->fd_ipv4 < 0)
+    if (s->fd_ipv4 < 0 && s->config.use_ipv4)
         g_message("Failed to create IPv4 socket, proceeding in IPv6 only mode");
-    else if (s->fd_ipv6 < 0)
+    else if (s->fd_ipv6 < 0 && s->config.use_ipv6)
         g_message("Failed to create IPv6 socket, proceeding in IPv4 only mode");
     
     if (c)
@@ -778,6 +784,7 @@ AvahiServer *avahi_server_new(GMainContext *c) {
     s->time_event_queue = avahi_time_event_queue_new(s->context, G_PRIORITY_DEFAULT+10); /* Slightly less priority than the FDs */
     s->monitor = avahi_interface_monitor_new(s);
     avahi_interface_monitor_sync(s->monitor);
+    
     add_default_entries(s);
     
     /* Prepare IO source registration */
@@ -833,6 +840,8 @@ void avahi_server_free(AvahiServer* s) {
     g_source_unref(s->source);
     g_main_context_unref(s->context);
 
+    avahi_server_config_free(&s->config);
+
     g_free(s);
 }
 
@@ -1240,3 +1249,38 @@ const gchar* avahi_server_get_host_name(AvahiServer *s) {
 
     return s->host_name_fqdn;
 }
+
+AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) {
+    g_assert(c);
+
+    memset(c, 0, sizeof(AvahiServerConfig));
+    c->register_hinfo = TRUE;
+    c->register_addresses = TRUE;
+    c->use_ipv6 = TRUE;
+    c->use_ipv4 = TRUE;
+    c->host_name = NULL;
+    c->domain_name = NULL;
+    c->check_response_ttl = TRUE;
+
+    return c;
+}
+
+void avahi_server_config_free(AvahiServerConfig *c) {
+    g_assert(c);
+
+    g_assert(c->host_name);
+    g_assert(c->domain_name);
+    g_free(c);
+}
+
+AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c) {
+    g_assert(ret);
+    g_assert(c);
+
+    *ret = *c;
+
+    ret->host_name = g_strdup(c->host_name);
+    ret->domain_name = g_strdup(c->domain_name);
+
+    return ret;
+}
index 7283b79ad2e452febf72dd85d01340012fba549d..4d0e8a3877e7d52c479358b6949d44d3ded15e3f 100644 (file)
@@ -68,6 +68,8 @@ struct AvahiServer {
     GMainContext *context;
     AvahiInterfaceMonitor *monitor;
 
+    AvahiServerConfig config;
+
     AVAHI_LLIST_HEAD(AvahiEntry, entries);
     GHashTable *entries_by_key;
 
@@ -87,8 +89,6 @@ struct AvahiServer {
     GPollFD pollfd_ipv4, pollfd_ipv6;
     GSource *source;
 
-    gboolean ignore_bad_ttl;
-
     /* Used for assembling responses */
     AvahiRecordList *record_list;
 };