diff options
author | Lennart Poettering <lennart@poettering.net> | 2005-05-06 15:21:41 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2005-05-06 15:21:41 +0000 |
commit | 7dce450bdc23ea306a61e00f914481e29ebcb176 (patch) | |
tree | 694acedcd6728844167c5cde09841058fc20e99e | |
parent | 844f6b5a8213018c3d42b5ef924b61cf3eafcdbb (diff) |
Rename flx_* to avahi_*
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@46 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r-- | address.c | 22 | ||||
-rw-r--r-- | address.h | 28 | ||||
-rw-r--r-- | announce.c | 194 | ||||
-rw-r--r-- | announce.h | 48 | ||||
-rw-r--r-- | cache.c | 146 | ||||
-rw-r--r-- | cache.h | 66 | ||||
-rw-r--r-- | dns-test.c | 32 | ||||
-rw-r--r-- | dns.c | 282 | ||||
-rw-r--r-- | dns.h | 88 | ||||
-rw-r--r-- | domain-test.c | 8 | ||||
-rw-r--r-- | flx.h | 138 | ||||
-rw-r--r-- | iface.c | 214 | ||||
-rw-r--r-- | iface.h | 86 | ||||
-rw-r--r-- | llist.h | 12 | ||||
-rw-r--r-- | main.c | 48 | ||||
-rw-r--r-- | netlink.c | 30 | ||||
-rw-r--r-- | netlink.h | 12 | ||||
-rw-r--r-- | prioq-test.c | 20 | ||||
-rw-r--r-- | prioq.c | 40 | ||||
-rw-r--r-- | prioq.h | 28 | ||||
-rw-r--r-- | psched.c | 308 | ||||
-rw-r--r-- | psched.h | 82 | ||||
-rw-r--r-- | rr.c | 246 | ||||
-rw-r--r-- | rr.h | 82 | ||||
-rw-r--r-- | server.c | 484 | ||||
-rw-r--r-- | server.h | 58 | ||||
-rw-r--r-- | socket.c | 62 | ||||
-rw-r--r-- | socket.h | 22 | ||||
-rw-r--r-- | strlst-test.c | 36 | ||||
-rw-r--r-- | strlst.c | 62 | ||||
-rw-r--r-- | strlst.h | 30 | ||||
-rw-r--r-- | subscribe.c | 70 | ||||
-rw-r--r-- | subscribe.h | 20 | ||||
-rw-r--r-- | timeeventq.c | 58 | ||||
-rw-r--r-- | timeeventq.h | 30 | ||||
-rw-r--r-- | util.c | 36 | ||||
-rw-r--r-- | util.h | 26 |
37 files changed, 1627 insertions, 1627 deletions
@@ -5,7 +5,7 @@ #include "address.h" -guint flx_address_get_size(const flxAddress *a) { +guint avahi_address_get_size(const AvahiAddress *a) { g_assert(a); if (a->family == AF_INET) @@ -16,31 +16,31 @@ guint flx_address_get_size(const flxAddress *a) { return 0; } -gint flx_address_cmp(const flxAddress *a, const flxAddress *b) { +gint avahi_address_cmp(const AvahiAddress *a, const AvahiAddress *b) { g_assert(a); g_assert(b); if (a->family != b->family) return -1; - return memcmp(a->data.data, b->data.data, flx_address_get_size(a)); + return memcmp(a->data.data, b->data.data, avahi_address_get_size(a)); } -gchar *flx_address_snprint(char *s, guint length, const flxAddress *a) { +gchar *avahi_address_snprint(char *s, guint length, const AvahiAddress *a) { g_assert(s); g_assert(length); g_assert(a); return (gchar*) inet_ntop(a->family, a->data.data, s, length); } -gchar* flx_reverse_lookup_name_ipv4(const flxIPv4Address *a) { +gchar* avahi_reverse_lookup_name_ipv4(const AvahiIPv4Address *a) { guint32 n = ntohl(a->address); g_assert(a); return g_strdup_printf("%u.%u.%u.%u.in-addr.arpa", n & 0xFF, (n >> 8) & 0xFF, (n >> 16) & 0xFF, n >> 24); } -static gchar *reverse_lookup_name_ipv6(const flxIPv6Address *a, const gchar *suffix) { +static gchar *reverse_lookup_name_ipv6(const AvahiIPv6Address *a, const gchar *suffix) { return g_strdup_printf("%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%s", a->address[15] & 0xF, @@ -78,15 +78,15 @@ static gchar *reverse_lookup_name_ipv6(const flxIPv6Address *a, const gchar *suf suffix); } -gchar *flx_reverse_lookup_name_ipv6_arpa(const flxIPv6Address *a) { +gchar *avahi_reverse_lookup_name_ipv6_arpa(const AvahiIPv6Address *a) { return reverse_lookup_name_ipv6(a, "ip6.arpa"); } -gchar *flx_reverse_lookup_name_ipv6_int(const flxIPv6Address *a) { +gchar *avahi_reverse_lookup_name_ipv6_int(const AvahiIPv6Address *a) { return reverse_lookup_name_ipv6(a, "ip6.int"); } -flxAddress *flx_address_parse(const char *s, guchar family, flxAddress *ret_addr) { +AvahiAddress *avahi_address_parse(const char *s, guchar family, AvahiAddress *ret_addr) { g_assert(ret_addr); g_assert(s); @@ -98,7 +98,7 @@ flxAddress *flx_address_parse(const char *s, guchar family, flxAddress *ret_addr return ret_addr; } -flxAddress *flx_address_from_sockaddr(const struct sockaddr* sa, flxAddress *ret_addr) { +AvahiAddress *avahi_address_from_sockaddr(const struct sockaddr* sa, AvahiAddress *ret_addr) { g_assert(sa); g_assert(ret_addr); @@ -114,7 +114,7 @@ flxAddress *flx_address_from_sockaddr(const struct sockaddr* sa, flxAddress *ret return ret_addr; } -guint16 flx_port_from_sockaddr(const struct sockaddr* sa) { +guint16 avahi_port_from_sockaddr(const struct sockaddr* sa) { g_assert(sa); g_assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6); @@ -7,34 +7,34 @@ typedef struct { guint32 address; -} flxIPv4Address; +} AvahiIPv4Address; typedef struct { guint8 address[16]; -} flxIPv6Address; +} AvahiIPv6Address; typedef struct { guchar family; union { - flxIPv6Address ipv6; - flxIPv4Address ipv4; + AvahiIPv6Address ipv6; + AvahiIPv4Address ipv4; guint8 data[0]; } data; -} flxAddress; +} AvahiAddress; -guint flx_address_get_size(const flxAddress *a); -gint flx_address_cmp(const flxAddress *a, const flxAddress *b); +guint avahi_address_get_size(const AvahiAddress *a); +gint avahi_address_cmp(const AvahiAddress *a, const AvahiAddress *b); -gchar *flx_address_snprint(char *ret_s, guint length, const flxAddress *a); +gchar *avahi_address_snprint(char *ret_s, guint length, const AvahiAddress *a); -flxAddress *flx_address_parse(const char *s, guchar family, flxAddress *ret_addr); +AvahiAddress *avahi_address_parse(const char *s, guchar family, AvahiAddress *ret_addr); -flxAddress *flx_address_from_sockaddr(const struct sockaddr* sa, flxAddress *ret_addr); -guint16 flx_port_from_sockaddr(const struct sockaddr* sa); +AvahiAddress *avahi_address_from_sockaddr(const struct sockaddr* sa, AvahiAddress *ret_addr); +guint16 avahi_port_from_sockaddr(const struct sockaddr* sa); -gchar* flx_reverse_lookup_name_ipv4(const flxIPv4Address *a); -gchar* flx_reverse_lookup_name_ipv6_arpa(const flxIPv6Address *a); -gchar* flx_reverse_lookup_name_ipv6_int(const flxIPv6Address *a); +gchar* avahi_reverse_lookup_name_ipv4(const AvahiIPv4Address *a); +gchar* avahi_reverse_lookup_name_ipv6_arpa(const AvahiIPv6Address *a); +gchar* avahi_reverse_lookup_name_ipv6_int(const AvahiIPv6Address *a); #endif @@ -1,68 +1,68 @@ #include "announce.h" #include "util.h" -#define FLX_ANNOUNCEMENT_JITTER_MSEC 250 -#define FLX_PROBE_JITTER_MSEC 250 -#define FLX_PROBE_INTERVAL_MSEC 250 +#define AVAHI_ANNOUNCEMENT_JITTER_MSEC 250 +#define AVAHI_PROBE_JITTER_MSEC 250 +#define AVAHI_PROBE_INTERVAL_MSEC 250 -static void remove_announcement(flxServer *s, flxAnnouncement *a) { +static void remove_announcement(AvahiServer *s, AvahiAnnouncement *a) { g_assert(s); g_assert(a); if (a->time_event) - flx_time_event_queue_remove(s->time_event_queue, a->time_event); + avahi_time_event_queue_remove(s->time_event_queue, a->time_event); - FLX_LLIST_REMOVE(flxAnnouncement, by_interface, a->interface->announcements, a); - FLX_LLIST_REMOVE(flxAnnouncement, by_entry, a->entry->announcements, a); + AVAHI_LLIST_REMOVE(AvahiAnnouncement, by_interface, a->interface->announcements, a); + AVAHI_LLIST_REMOVE(AvahiAnnouncement, by_entry, a->entry->announcements, a); g_free(a); } -static void elapse_announce(flxTimeEvent *e, void *userdata); +static void elapse_announce(AvahiTimeEvent *e, void *userdata); -static void set_timeout(flxAnnouncement *a, const GTimeVal *tv) { +static void set_timeout(AvahiAnnouncement *a, const GTimeVal *tv) { g_assert(a); if (!tv) { if (a->time_event) { - flx_time_event_queue_remove(a->server->time_event_queue, a->time_event); + avahi_time_event_queue_remove(a->server->time_event_queue, a->time_event); a->time_event = NULL; } } else { if (a->time_event) - flx_time_event_queue_update(a->server->time_event_queue, a->time_event, tv); + avahi_time_event_queue_update(a->server->time_event_queue, a->time_event, tv); else - a->time_event = flx_time_event_queue_add(a->server->time_event_queue, tv, elapse_announce, a); + a->time_event = avahi_time_event_queue_add(a->server->time_event_queue, tv, elapse_announce, a); } } -static void next_state(flxAnnouncement *a); +static void next_state(AvahiAnnouncement *a); -void flx_entry_group_check_probed(flxEntryGroup *g, gboolean immediately) { - flxEntry *e; +void avahi_entry_group_check_probed(AvahiEntryGroup *g, gboolean immediately) { + AvahiEntry *e; g_assert(g); g_assert(!g->dead); /* Check whether all group members have been probed */ - if (g->state != FLX_ENTRY_GROUP_REGISTERING || g->n_probing > 0) + if (g->state != AVAHI_ENTRY_GROUP_REGISTERING || g->n_probing > 0) return; - flx_entry_group_change_state(g, FLX_ENTRY_GROUP_ESTABLISHED); + avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_ESTABLISHED); if (g->dead) return; for (e = g->entries; e; e = e->entries_next) { - flxAnnouncement *a; + AvahiAnnouncement *a; for (a = e->announcements; a; a = a->by_entry_next) { - if (a->state != FLX_WAITING) + if (a->state != AVAHI_WAITING) continue; - a->state = FLX_ANNOUNCING; + a->state = AVAHI_ANNOUNCING; if (immediately) { /* Shortcut */ @@ -72,32 +72,32 @@ void flx_entry_group_check_probed(flxEntryGroup *g, gboolean immediately) { } else { GTimeVal tv; a->n_iteration = 0; - flx_elapse_time(&tv, 0, FLX_ANNOUNCEMENT_JITTER_MSEC); + avahi_elapse_time(&tv, 0, AVAHI_ANNOUNCEMENT_JITTER_MSEC); set_timeout(a, &tv); } } } } -static void next_state(flxAnnouncement *a) { +static void next_state(AvahiAnnouncement *a) { g_assert(a); /* g_message("%i -- %u", a->state, a->n_iteration); */ - if (a->state == FLX_WAITING) { + if (a->state == AVAHI_WAITING) { g_assert(a->entry->group); - flx_entry_group_check_probed(a->entry->group, TRUE); + avahi_entry_group_check_probed(a->entry->group, TRUE); - } else if (a->state == FLX_PROBING) { + } else if (a->state == AVAHI_PROBING) { if (a->n_iteration >= 4) { /* Probing done */ gchar *t; - g_message("Enough probes for record [%s]", t = flx_record_to_string(a->entry->record)); + g_message("Enough probes for record [%s]", t = avahi_record_to_string(a->entry->record)); g_free(t); if (a->entry->group) { @@ -105,10 +105,10 @@ static void next_state(flxAnnouncement *a) { a->entry->group->n_probing--; } - if (a->entry->group && a->entry->group->state == FLX_ENTRY_GROUP_REGISTERING) - a->state = FLX_WAITING; + if (a->entry->group && a->entry->group->state == AVAHI_ENTRY_GROUP_REGISTERING) + a->state = AVAHI_WAITING; else { - a->state = FLX_ANNOUNCING; + a->state = AVAHI_ANNOUNCING; a->n_iteration = 1; } @@ -117,31 +117,31 @@ static void next_state(flxAnnouncement *a) { } else { GTimeVal tv; - flx_interface_post_probe(a->interface, a->entry->record, FALSE); + avahi_interface_post_probe(a->interface, a->entry->record, FALSE); - flx_elapse_time(&tv, FLX_PROBE_INTERVAL_MSEC, 0); + avahi_elapse_time(&tv, AVAHI_PROBE_INTERVAL_MSEC, 0); set_timeout(a, &tv); a->n_iteration++; } - } else if (a->state == FLX_ANNOUNCING) { + } else if (a->state == AVAHI_ANNOUNCING) { - flx_interface_post_response(a->interface, NULL, a->entry->record, a->entry->flags & FLX_ENTRY_UNIQUE, FALSE); + avahi_interface_post_response(a->interface, NULL, a->entry->record, a->entry->flags & AVAHI_ENTRY_UNIQUE, FALSE); if (++a->n_iteration >= 4) { gchar *t; /* Announcing done */ - g_message("Enough announcements for record [%s]", t = flx_record_to_string(a->entry->record)); + g_message("Enough announcements for record [%s]", t = avahi_record_to_string(a->entry->record)); g_free(t); - a->state = FLX_ESTABLISHED; + a->state = AVAHI_ESTABLISHED; set_timeout(a, NULL); } else { GTimeVal tv; - flx_elapse_time(&tv, a->sec_delay*1000, FLX_ANNOUNCEMENT_JITTER_MSEC); + avahi_elapse_time(&tv, a->sec_delay*1000, AVAHI_ANNOUNCEMENT_JITTER_MSEC); if (a->n_iteration < 10) a->sec_delay *= 2; @@ -151,14 +151,14 @@ static void next_state(flxAnnouncement *a) { } } -static void elapse_announce(flxTimeEvent *e, void *userdata) { +static void elapse_announce(AvahiTimeEvent *e, void *userdata) { g_assert(e); next_state(userdata); } -flxAnnouncement *flx_get_announcement(flxServer *s, flxEntry *e, flxInterface *i) { - flxAnnouncement *a; +AvahiAnnouncement *avahi_get_announcement(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { + AvahiAnnouncement *a; g_assert(s); g_assert(e); @@ -171,8 +171,8 @@ flxAnnouncement *flx_get_announcement(flxServer *s, flxEntry *e, flxInterface *i return NULL; } -static void new_announcement(flxServer *s, flxInterface *i, flxEntry *e) { - flxAnnouncement *a; +static void new_announcement(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) { + AvahiAnnouncement *a; GTimeVal tv; gchar *t; @@ -181,59 +181,59 @@ static void new_announcement(flxServer *s, flxInterface *i, flxEntry *e) { g_assert(e); g_assert(!e->dead); -/* g_message("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = flx_record_to_string(e->record)); */ +/* g_message("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record)); */ /* g_free(t); */ - if (!flx_interface_match(i, e->interface, e->protocol) || !i->announcing || !flx_entry_commited(e)) + if (!avahi_interface_match(i, e->interface, e->protocol) || !i->announcing || !avahi_entry_commited(e)) return; /* We don't want duplicate announcements */ - if (flx_get_announcement(s, e, i)) + if (avahi_get_announcement(s, e, i)) return; - a = g_new(flxAnnouncement, 1); + a = g_new(AvahiAnnouncement, 1); a->server = s; a->interface = i; a->entry = e; - if ((e->flags & FLX_ENTRY_UNIQUE) && !(e->flags & FLX_ENTRY_NOPROBE)) - a->state = FLX_PROBING; - else if (!(e->flags & FLX_ENTRY_NOANNOUNCE)) { + if ((e->flags & AVAHI_ENTRY_UNIQUE) && !(e->flags & AVAHI_ENTRY_NOPROBE)) + a->state = AVAHI_PROBING; + else if (!(e->flags & AVAHI_ENTRY_NOANNOUNCE)) { - if (!e->group || e->group->state == FLX_ENTRY_GROUP_ESTABLISHED) - a->state = FLX_ANNOUNCING; + if (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED) + a->state = AVAHI_ANNOUNCING; else - a->state = FLX_WAITING; + a->state = AVAHI_WAITING; } else - a->state = FLX_ESTABLISHED; + a->state = AVAHI_ESTABLISHED; - g_message("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = flx_record_to_string(e->record), a->state); + g_message("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record), a->state); g_free(t); a->n_iteration = 1; a->sec_delay = 1; a->time_event = NULL; - if (a->state == FLX_PROBING) + if (a->state == AVAHI_PROBING) if (e->group) e->group->n_probing++; - FLX_LLIST_PREPEND(flxAnnouncement, by_interface, i->announcements, a); - FLX_LLIST_PREPEND(flxAnnouncement, by_entry, e->announcements, a); + AVAHI_LLIST_PREPEND(AvahiAnnouncement, by_interface, i->announcements, a); + AVAHI_LLIST_PREPEND(AvahiAnnouncement, by_entry, e->announcements, a); - if (a->state == FLX_PROBING) { - flx_elapse_time(&tv, 0, FLX_PROBE_JITTER_MSEC); + if (a->state == AVAHI_PROBING) { + avahi_elapse_time(&tv, 0, AVAHI_PROBE_JITTER_MSEC); set_timeout(a, &tv); - } else if (a->state == FLX_ANNOUNCING) { - flx_elapse_time(&tv, 0, FLX_ANNOUNCEMENT_JITTER_MSEC); + } else if (a->state == AVAHI_ANNOUNCING) { + avahi_elapse_time(&tv, 0, AVAHI_ANNOUNCEMENT_JITTER_MSEC); set_timeout(a, &tv); } } -void flx_announce_interface(flxServer *s, flxInterface *i) { - flxEntry *e; +void avahi_announce_interface(AvahiServer *s, AvahiInterface *i) { + AvahiEntry *e; g_assert(s); g_assert(i); @@ -246,8 +246,8 @@ void flx_announce_interface(flxServer *s, flxInterface *i) { new_announcement(s, i, e); } -static void announce_walk_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) { - flxEntry *e = userdata; +static void announce_walk_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { + AvahiEntry *e = userdata; g_assert(m); g_assert(i); @@ -257,100 +257,100 @@ static void announce_walk_callback(flxInterfaceMonitor *m, flxInterface *i, gpoi new_announcement(m->server, i, e); } -void flx_announce_entry(flxServer *s, flxEntry *e) { +void avahi_announce_entry(AvahiServer *s, AvahiEntry *e) { g_assert(s); g_assert(e); g_assert(!e->dead); - flx_interface_monitor_walk(s->monitor, e->interface, e->protocol, announce_walk_callback, e); + avahi_interface_monitor_walk(s->monitor, e->interface, e->protocol, announce_walk_callback, e); } -void flx_announce_group(flxServer *s, flxEntryGroup *g) { - flxEntry *e; +void avahi_announce_group(AvahiServer *s, AvahiEntryGroup *g) { + AvahiEntry *e; g_assert(s); g_assert(g); for (e = g->entries; e; e = e->by_group_next) if (!e->dead) - flx_announce_entry(s, e); + avahi_announce_entry(s, e); } -gboolean flx_entry_registered(flxServer *s, flxEntry *e, flxInterface *i) { - flxAnnouncement *a; +gboolean avahi_entry_registered(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { + AvahiAnnouncement *a; g_assert(s); g_assert(e); g_assert(i); g_assert(!e->dead); - if (!(a = flx_get_announcement(s, e, i))) + if (!(a = avahi_get_announcement(s, e, i))) return FALSE; - return a->state == FLX_ANNOUNCING || a->state == FLX_ESTABLISHED; + return a->state == AVAHI_ANNOUNCING || a->state == AVAHI_ESTABLISHED; } -gboolean flx_entry_registering(flxServer *s, flxEntry *e, flxInterface *i) { - flxAnnouncement *a; +gboolean avahi_entry_registering(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { + AvahiAnnouncement *a; g_assert(s); g_assert(e); g_assert(i); g_assert(!e->dead); - if (!(a = flx_get_announcement(s, e, i))) + if (!(a = avahi_get_announcement(s, e, i))) return FALSE; - return a->state == FLX_PROBING || a->state == FLX_WAITING; + return a->state == AVAHI_PROBING || a->state == AVAHI_WAITING; } -static flxRecord *make_goodbye_record(flxRecord *r) { +static AvahiRecord *make_goodbye_record(AvahiRecord *r) { /* gchar *t; */ - flxRecord *g; + AvahiRecord *g; g_assert(r); -/* g_message("Preparing goodbye for record [%s]", t = flx_record_to_string(r)); */ +/* g_message("Preparing goodbye for record [%s]", t = avahi_record_to_string(r)); */ /* g_free(t); */ - g = flx_record_copy(r); + g = avahi_record_copy(r); g_assert(g->ref == 1); g->ttl = 0; return g; } -static void send_goodbye_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) { - flxEntry *e = userdata; - flxRecord *g; +static void send_goodbye_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { + AvahiEntry *e = userdata; + AvahiRecord *g; g_assert(m); g_assert(i); g_assert(e); g_assert(!e->dead); - if (!flx_interface_match(i, e->interface, e->protocol)) + if (!avahi_interface_match(i, e->interface, e->protocol)) return; - if (e->flags & FLX_ENTRY_NOANNOUNCE) + if (e->flags & AVAHI_ENTRY_NOANNOUNCE) return; - if (!flx_entry_registered(m->server, e, i)) + if (!avahi_entry_registered(m->server, e, i)) return; g = make_goodbye_record(e->record); - flx_interface_post_response(i, NULL, g, e->flags & FLX_ENTRY_UNIQUE, TRUE); - flx_record_unref(g); + avahi_interface_post_response(i, NULL, g, e->flags & AVAHI_ENTRY_UNIQUE, TRUE); + avahi_record_unref(g); } -void flx_goodbye_interface(flxServer *s, flxInterface *i, gboolean goodbye) { +void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean goodbye) { g_assert(s); g_assert(i); /* g_message("goodbye interface: %s.%u", i->hardware->name, i->protocol); */ - if (goodbye && flx_interface_relevant(i)) { - flxEntry *e; + if (goodbye && avahi_interface_relevant(i)) { + AvahiEntry *e; for (e = s->entries; e; e = e->entries_next) if (!e->dead) @@ -364,14 +364,14 @@ void flx_goodbye_interface(flxServer *s, flxInterface *i, gboolean goodbye) { } -void flx_goodbye_entry(flxServer *s, flxEntry *e, gboolean goodbye) { +void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean goodbye) { g_assert(s); g_assert(e); /* g_message("goodbye entry: %p", e); */ if (goodbye && !e->dead) - flx_interface_monitor_walk(s->monitor, 0, AF_UNSPEC, send_goodbye_callback, e); + avahi_interface_monitor_walk(s->monitor, 0, AF_UNSPEC, send_goodbye_callback, e); while (e->announcements) remove_announcement(s, e->announcements); @@ -380,8 +380,8 @@ void flx_goodbye_entry(flxServer *s, flxEntry *e, gboolean goodbye) { } -void flx_goodbye_all(flxServer *s, gboolean goodbye) { - flxEntry *e; +void avahi_goodbye_all(AvahiServer *s, gboolean goodbye) { + AvahiEntry *e; g_assert(s); @@ -389,7 +389,7 @@ void flx_goodbye_all(flxServer *s, gboolean goodbye) { for (e = s->entries; e; e = e->entries_next) if (!e->dead) - flx_goodbye_entry(s, e, goodbye); + avahi_goodbye_entry(s, e, goodbye); /* g_message("goodbye all done"); */ @@ -3,7 +3,7 @@ #include <glib.h> -typedef struct _flxAnnouncement flxAnnouncement; +typedef struct _AvahiAnnouncement AvahiAnnouncement; #include "llist.h" #include "iface.h" @@ -11,41 +11,41 @@ typedef struct _flxAnnouncement flxAnnouncement; #include "timeeventq.h" typedef enum { - FLX_PROBING, - FLX_WAITING, /* wait for other records in group */ - FLX_ANNOUNCING, - FLX_ESTABLISHED -} flxAnnouncementState; + AVAHI_PROBING, + AVAHI_WAITING, /* wait for other records in group */ + AVAHI_ANNOUNCING, + AVAHI_ESTABLISHED +} AvahiAnnouncementState; -struct _flxAnnouncement { - flxServer *server; - flxInterface *interface; - flxEntry *entry; +struct _AvahiAnnouncement { + AvahiServer *server; + AvahiInterface *interface; + AvahiEntry *entry; - flxTimeEvent *time_event; + AvahiTimeEvent *time_event; - flxAnnouncementState state; + AvahiAnnouncementState state; guint n_iteration; guint sec_delay; - FLX_LLIST_FIELDS(flxAnnouncement, by_interface); - FLX_LLIST_FIELDS(flxAnnouncement, by_entry); + AVAHI_LLIST_FIELDS(AvahiAnnouncement, by_interface); + AVAHI_LLIST_FIELDS(AvahiAnnouncement, by_entry); }; -void flx_announce_interface(flxServer *s, flxInterface *i); -void flx_announce_entry(flxServer *s, flxEntry *e); -void flx_announce_group(flxServer *s, flxEntryGroup *g); +void avahi_announce_interface(AvahiServer *s, AvahiInterface *i); +void avahi_announce_entry(AvahiServer *s, AvahiEntry *e); +void avahi_announce_group(AvahiServer *s, AvahiEntryGroup *g); -void flx_entry_group_check_probed(flxEntryGroup *g, gboolean immediately); +void avahi_entry_group_check_probed(AvahiEntryGroup *g, gboolean immediately); -gboolean flx_entry_registered(flxServer *s, flxEntry *e, flxInterface *i); -gboolean flx_entry_registering(flxServer *s, flxEntry *e, flxInterface *i); +gboolean avahi_entry_registered(AvahiServer *s, AvahiEntry *e, AvahiInterface *i); +gboolean avahi_entry_registering(AvahiServer *s, AvahiEntry *e, AvahiInterface *i); -void flx_goodbye_interface(flxServer *s, flxInterface *i, gboolean send); -void flx_goodbye_entry(flxServer *s, flxEntry *e, gboolean send); +void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean send); +void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean send); -void flx_goodbye_all(flxServer *s, gboolean send); +void avahi_goodbye_all(AvahiServer *s, gboolean send); -flxAnnouncement *flx_get_announcement(flxServer *s, flxEntry *e, flxInterface *i); +AvahiAnnouncement *avahi_get_announcement(AvahiServer *s, AvahiEntry *e, AvahiInterface *i); #endif @@ -3,8 +3,8 @@ #include "util.h" #include "cache.h" -static void remove_entry(flxCache *c, flxCacheEntry *e) { - flxCacheEntry *t; +static void remove_entry(AvahiCache *c, AvahiCacheEntry *e) { + AvahiCacheEntry *t; g_assert(c); g_assert(e); @@ -13,40 +13,40 @@ static void remove_entry(flxCache *c, flxCacheEntry *e) { /* Remove from hash table */ t = g_hash_table_lookup(c->hash_table, e->record->key); - FLX_LLIST_REMOVE(flxCacheEntry, by_key, t, e); + AVAHI_LLIST_REMOVE(AvahiCacheEntry, by_key, t, e); if (t) g_hash_table_replace(c->hash_table, t->record->key, t); else g_hash_table_remove(c->hash_table, e->record->key); /* Remove from linked list */ - FLX_LLIST_REMOVE(flxCacheEntry, entry, c->entries, e); + AVAHI_LLIST_REMOVE(AvahiCacheEntry, entry, c->entries, e); if (e->time_event) - flx_time_event_queue_remove(c->server->time_event_queue, e->time_event); + avahi_time_event_queue_remove(c->server->time_event_queue, e->time_event); - flx_subscription_notify(c->server, c->interface, e->record, FLX_SUBSCRIPTION_REMOVE); + avahi_subscription_notify(c->server, c->interface, e->record, AVAHI_SUBSCRIPTION_REMOVE); - flx_record_unref(e->record); + avahi_record_unref(e->record); g_free(e); } -flxCache *flx_cache_new(flxServer *server, flxInterface *iface) { - flxCache *c; +AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) { + AvahiCache *c; g_assert(server); - c = g_new(flxCache, 1); + c = g_new(AvahiCache, 1); c->server = server; c->interface = iface; - c->hash_table = g_hash_table_new((GHashFunc) flx_key_hash, (GEqualFunc) flx_key_equal); + c->hash_table = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal); - FLX_LLIST_HEAD_INIT(flxCacheEntry, c->entries); + AVAHI_LLIST_HEAD_INIT(AvahiCacheEntry, c->entries); return c; } -void flx_cache_free(flxCache *c) { +void avahi_cache_free(AvahiCache *c) { g_assert(c); while (c->entries) @@ -57,37 +57,37 @@ void flx_cache_free(flxCache *c) { g_free(c); } -flxCacheEntry *flx_cache_lookup_key(flxCache *c, flxKey *k) { +AvahiCacheEntry *avahi_cache_lookup_key(AvahiCache *c, AvahiKey *k) { g_assert(c); g_assert(k); - g_assert(!flx_key_is_pattern(k)); + g_assert(!avahi_key_is_pattern(k)); return g_hash_table_lookup(c->hash_table, k); } -gpointer flx_cache_walk(flxCache *c, flxKey *pattern, flxCacheWalkCallback cb, gpointer userdata) { +gpointer avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, gpointer userdata) { gpointer ret; g_assert(c); g_assert(pattern); g_assert(cb); - if (flx_key_is_pattern(pattern)) { - flxCacheEntry *e, *n; + if (avahi_key_is_pattern(pattern)) { + AvahiCacheEntry *e, *n; for (e = c->entries; e; e = n) { n = e->entry_next; - if (flx_key_pattern_match(pattern, e->record->key)) + if (avahi_key_pattern_match(pattern, e->record->key)) if ((ret = cb(c, pattern, e, userdata))) return ret; } } else { - flxCacheEntry *e, *n; + AvahiCacheEntry *e, *n; - for (e = flx_cache_lookup_key(c, pattern); e; e = n) { + for (e = avahi_cache_lookup_key(c, pattern); e; e = n) { n = e->by_key_next; if ((ret = cb(c, pattern, e, userdata))) @@ -98,57 +98,57 @@ gpointer flx_cache_walk(flxCache *c, flxKey *pattern, flxCacheWalkCallback cb, g return NULL; } -static gpointer lookup_record_callback(flxCache *c, flxKey *pattern, flxCacheEntry *e, void *userdata) { +static gpointer lookup_record_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void *userdata) { g_assert(c); g_assert(pattern); g_assert(e); - if (flx_record_equal_no_ttl(e->record, userdata)) + if (avahi_record_equal_no_ttl(e->record, userdata)) return e; return NULL; } -flxCacheEntry *flx_cache_lookup_record(flxCache *c, flxRecord *r) { - flxCacheEntry *e; +AvahiCacheEntry *avahi_cache_lookup_record(AvahiCache *c, AvahiRecord *r) { + AvahiCacheEntry *e; g_assert(c); g_assert(r); - return flx_cache_walk(c, r->key, lookup_record_callback, r); + return avahi_cache_walk(c, r->key, lookup_record_callback, r); } -static void next_expiry(flxCache *c, flxCacheEntry *e, guint percent); +static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, guint percent); -static void elapse_func(flxTimeEvent *t, void *userdata) { - flxCacheEntry *e = userdata; +static void elapse_func(AvahiTimeEvent *t, void *userdata) { + AvahiCacheEntry *e = userdata; g_assert(t); g_assert(e); - if (e->state == FLX_CACHE_FINAL) { + if (e->state == AVAHI_CACHE_FINAL) { remove_entry(e->cache, e); g_message("Removing entry from cache due to expiration"); } else { guint percent = 0; switch (e->state) { - case FLX_CACHE_VALID: - e->state = FLX_CACHE_EXPIRY1; + case AVAHI_CACHE_VALID: + e->state = AVAHI_CACHE_EXPIRY1; percent = 85; break; - case FLX_CACHE_EXPIRY1: - e->state = FLX_CACHE_EXPIRY2; + case AVAHI_CACHE_EXPIRY1: + e->state = AVAHI_CACHE_EXPIRY2; percent = 90; break; - case FLX_CACHE_EXPIRY2: - e->state = FLX_CACHE_EXPIRY3; + case AVAHI_CACHE_EXPIRY2: + e->state = AVAHI_CACHE_EXPIRY3; percent = 95; break; - case FLX_CACHE_EXPIRY3: - e->state = FLX_CACHE_FINAL; + case AVAHI_CACHE_EXPIRY3: + e->state = AVAHI_CACHE_FINAL; percent = 100; break; @@ -161,25 +161,25 @@ static void elapse_func(flxTimeEvent *t, void *userdata) { g_message("Requesting cache entry update at %i%%.", percent); /* Request a cache update, if we are subscribed to this entry */ - if (flx_is_subscribed(e->cache->server, e->record->key)) - flx_interface_post_query(e->cache->interface, e->record->key, TRUE); + if (avahi_is_subscribed(e->cache->server, e->record->key)) + avahi_interface_post_query(e->cache->interface, e->record->key, TRUE); /* Check again later */ next_expiry(e->cache, e, percent); } } -static void update_time_event(flxCache *c, flxCacheEntry *e) { +static void update_time_event(AvahiCache *c, AvahiCacheEntry *e) { g_assert(c); g_assert(e); if (e->time_event) - flx_time_event_queue_update(c->server->time_event_queue, e->time_event, &e->expiry); + avahi_time_event_queue_update(c->server->time_event_queue, e->time_event, &e->expiry); else - e->time_event = flx_time_event_queue_add(c->server->time_event_queue, &e->expiry, elapse_func, e); + e->time_event = avahi_time_event_queue_add(c->server->time_event_queue, &e->expiry, elapse_func, e); } -static void next_expiry(flxCache *c, flxCacheEntry *e, guint percent) { +static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, guint percent) { gulong usec; g_assert(c); @@ -197,23 +197,23 @@ static void next_expiry(flxCache *c, flxCacheEntry *e, guint percent) { update_time_event(c, e); } -void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a) { - flxCacheEntry *e, *t; +void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const AvahiAddress *a) { + AvahiCacheEntry *e, *t; gchar *txt; g_assert(c); g_assert(r && r->ref >= 1); - g_message("cache update: %s", (txt = flx_record_to_string(r))); + g_message("cache update: %s", (txt = avahi_record_to_string(r))); g_free(txt); if (r->ttl == 0) { /* This is a goodbye request */ - if ((e = flx_cache_lookup_record(c, r))) { + if ((e = avahi_cache_lookup_record(c, r))) { - e->state = FLX_CACHE_FINAL; + e->state = AVAHI_CACHE_FINAL; g_get_current_time(&e->timestamp); e->expiry = e->timestamp; g_time_val_add(&e->expiry, 1000000); /* 1s */ @@ -224,7 +224,7 @@ void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddre /* This is an update request */ - if ((t = e = flx_cache_lookup_key(c, r->key))) { + if ((t = e = avahi_cache_lookup_key(c, r->key))) { if (unique) { @@ -236,7 +236,7 @@ void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddre /* For non-unique record, look for exactly the same entry */ for (; e; e = e->by_key_next) - if (flx_record_equal_no_ttl(e->record, r)) + if (avahi_record_equal_no_ttl(e->record, r)) break; } } @@ -250,42 +250,42 @@ void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddre g_hash_table_replace(c->hash_table, r->key, e); /* Notify subscribers */ - if (!flx_record_equal_no_ttl(e->record, r)) - flx_subscription_notify(c->server, c->interface, r, FLX_SUBSCRIPTION_CHANGE); + if (!avahi_record_equal_no_ttl(e->record, r)) + avahi_subscription_notify(c->server, c->interface, r, AVAHI_SUBSCRIPTION_CHANGE); /* Update the record */ - flx_record_unref(e->record); - e->record = flx_record_ref(r); + avahi_record_unref(e->record); + e->record = avahi_record_ref(r); } else { /* No entry found, therefore we create a new one */ /* g_message("couldn't find matching cache entry"); */ - e = g_new(flxCacheEntry, 1); + e = g_new(AvahiCacheEntry, 1); e->cache = c; e->time_event = NULL; - e->record = flx_record_ref(r); + e->record = avahi_record_ref(r); /* Append to hash table */ - FLX_LLIST_PREPEND(flxCacheEntry, by_key, t, e); + AVAHI_LLIST_PREPEND(AvahiCacheEntry, by_key, t, e); g_hash_table_replace(c->hash_table, e->record->key, t); /* Append to linked list */ - FLX_LLIST_PREPEND(flxCacheEntry, entry, c->entries, e); + AVAHI_LLIST_PREPEND(AvahiCacheEntry, entry, c->entries, e); /* Notify subscribers */ - flx_subscription_notify(c->server, c->interface, e->record, FLX_SUBSCRIPTION_NEW); + avahi_subscription_notify(c->server, c->interface, e->record, AVAHI_SUBSCRIPTION_NEW); } e->origin = *a; g_get_current_time(&e->timestamp); next_expiry(c, e, 80); - e->state = FLX_CACHE_VALID; + e->state = AVAHI_CACHE_VALID; } } -static gpointer drop_key_callback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata) { +static gpointer drop_key_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, gpointer userdata) { g_assert(c); g_assert(pattern); g_assert(e); @@ -294,34 +294,34 @@ static gpointer drop_key_callback(flxCache *c, flxKey *pattern, flxCacheEntry *e return NULL; } -void flx_cache_drop_key(flxCache *c, flxKey *k) { +void avahi_cache_drop_key(AvahiCache *c, AvahiKey *k) { g_assert(c); g_assert(k); - flx_cache_walk(c, k, drop_key_callback, NULL); + avahi_cache_walk(c, k, drop_key_callback, NULL); } -void flx_cache_drop_record(flxCache *c, flxRecord *r) { - flxCacheEntry *e; +void avahi_cache_drop_record(AvahiCache *c, AvahiRecord *r) { + AvahiCacheEntry *e; g_assert(c); g_assert(r); - if ((e = flx_cache_lookup_record(c, r))) + if ((e = avahi_cache_lookup_record(c, r))) remove_entry(c, e); } static void func(gpointer key, gpointer data, gpointer userdata) { - flxCacheEntry *e = data; - flxKey *k = key; + AvahiCacheEntry *e = data; + AvahiKey *k = key; gchar *t; - t = flx_record_to_string(e->record); + t = avahi_record_to_string(e->record); fprintf((FILE*) userdata, "%s\n", t); g_free(t); } -void flx_cache_dump(flxCache *c, FILE *f) { +void avahi_cache_dump(AvahiCache *c, FILE *f) { g_assert(c); g_assert(f); @@ -329,7 +329,7 @@ void flx_cache_dump(flxCache *c, FILE *f) { g_hash_table_foreach(c->hash_table, func, f); } -gboolean flx_cache_entry_half_ttl(flxCache *c, flxCacheEntry *e) { +gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e) { GTimeVal now; guint age; @@ -338,7 +338,7 @@ gboolean flx_cache_entry_half_ttl(flxCache *c, flxCacheEntry *e) { g_get_current_time(&now); - age = flx_timeval_diff(&now, &e->timestamp)/1000000; + age = avahi_timeval_diff(&now, &e->timestamp)/1000000; g_message("age: %u, ttl/2: %u", age, e->record->ttl); @@ -3,8 +3,8 @@ #include <glib.h> -struct _flxCache; -typedef struct _flxCache flxCache; +struct _AvahiCache; +typedef struct _AvahiCache AvahiCache; #include "prioq.h" #include "server.h" @@ -12,55 +12,55 @@ typedef struct _flxCache flxCache; #include "timeeventq.h" typedef enum { - FLX_CACHE_VALID, - FLX_CACHE_EXPIRY1, - FLX_CACHE_EXPIRY2, - FLX_CACHE_EXPIRY3, - FLX_CACHE_FINAL -} flxCacheEntryState; - -typedef struct flxCacheEntry flxCacheEntry; - -struct flxCacheEntry { - flxCache *cache; - flxRecord *record; + AVAHI_CACHE_VALID, + AVAHI_CACHE_EXPIRY1, + AVAHI_CACHE_EXPIRY2, + AVAHI_CACHE_EXPIRY3, + AVAHI_CACHE_FINAL +} AvahiCacheEntryState; + +typedef struct AvahiCacheEntry AvahiCacheEntry; + +struct AvahiCacheEntry { + AvahiCache *cache; + AvahiRecord *record; GTimeVal timestamp; GTimeVal expiry; - flxAddress origin; + AvahiAddress origin; - flxCacheEntryState state; - flxTimeEvent *time_event; + AvahiCacheEntryState state; + AvahiTimeEvent *time_event; - FLX_LLIST_FIELDS(flxCacheEntry, by_key); - FLX_LLIST_FIELDS(flxCacheEntry, entry); + AVAHI_LLIST_FIELDS(AvahiCacheEntry, by_key); + AVAHI_LLIST_FIELDS(AvahiCacheEntry, entry); }; -struct _flxCache { - flxServer *server; +struct _AvahiCache { + AvahiServer *server; - flxInterface *interface; + AvahiInterface *interface; GHashTable *hash_table; - FLX_LLIST_HEAD(flxCacheEntry, entries); + AVAHI_LLIST_HEAD(AvahiCacheEntry, entries); }; -flxCache *flx_cache_new(flxServer *server, flxInterface *interface); -void flx_cache_free(flxCache *c); +AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *interface); +void avahi_cache_free(AvahiCache *c); -flxCacheEntry *flx_cache_lookup_key(flxCache *c, flxKey *k); -flxCacheEntry *flx_cache_lookup_record(flxCache *c, flxRecord *r); +AvahiCacheEntry *avahi_cache_lookup_key(AvahiCache *c, AvahiKey *k); +AvahiCacheEntry *avahi_cache_lookup_record(AvahiCache *c, AvahiRecord *r); -void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a); +void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const AvahiAddress *a); -void flx_cache_drop_record(flxCache *c, flxRecord *r); +void avahi_cache_drop_record(AvahiCache *c, AvahiRecord *r); -void flx_cache_dump(flxCache *c, FILE *f); +void avahi_cache_dump(AvahiCache *c, FILE *f); -typedef gpointer flxCacheWalkCallback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata); -gpointer flx_cache_walk(flxCache *c, flxKey *pattern, flxCacheWalkCallback cb, gpointer userdata); +typedef gpointer AvahiCacheWalkCallback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, gpointer userdata); +gpointer avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, gpointer userdata); -gboolean flx_cache_entry_half_ttl(flxCache *c, flxCacheEntry *e); +gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e); #endif @@ -3,33 +3,33 @@ int main(int argc, char *argv[]) { gchar t[256], *a, *b, *c, *d; - flxDnsPacket *p; + AvahiDnsPacket *p; - p = flx_dns_packet_new(8000); + p = avahi_dns_packet_new(8000); - flx_dns_packet_append_name(p, a = "hello.hello.hello.de."); - flx_dns_packet_append_name(p, b = "this is a test.hello.de."); - flx_dns_packet_append_name(p, c = "this\\.is\\.a\\.test\\.with\\.dots.hello.de."); - flx_dns_packet_append_name(p, d = "this\\\\is another\\ \\test.hello.de."); + avahi_dns_packet_append_name(p, a = "hello.hello.hello.de."); + avahi_dns_packet_append_name(p, b = "this is a test.hello.de."); + avahi_dns_packet_append_name(p, c = "this\\.is\\.a\\.test\\.with\\.dots.hello.de."); + avahi_dns_packet_append_name(p, d = "this\\\\is another\\ \\test.hello.de."); - flx_hexdump(FLX_DNS_PACKET_DATA(p), p->size); + avahi_hexdump(AVAHI_DNS_PACKET_DATA(p), p->size); - flx_dns_packet_consume_name(p, t, sizeof(t)); + avahi_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); - g_assert(flx_domain_equal(a, t)); + g_assert(avahi_domain_equal(a, t)); - flx_dns_packet_consume_name(p, t, sizeof(t)); + avahi_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); - g_assert(flx_domain_equal(b, t)); + g_assert(avahi_domain_equal(b, t)); - flx_dns_packet_consume_name(p, t, sizeof(t)); + avahi_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); - g_assert(flx_domain_equal(c, t)); + g_assert(avahi_domain_equal(c, t)); - flx_dns_packet_consume_name(p, t, sizeof(t)); + avahi_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); - g_assert(flx_domain_equal(d, t)); + g_assert(avahi_domain_equal(d, t)); - flx_dns_packet_free(p); + avahi_dns_packet_free(p); return 0; } @@ -7,40 +7,40 @@ #include "dns.h" #include "util.h" -flxDnsPacket* flx_dns_packet_new(guint max_size) { - flxDnsPacket *p; +AvahiDnsPacket* avahi_dns_packet_new(guint max_size) { + AvahiDnsPacket *p; if (max_size <= 0) - max_size = FLX_DNS_PACKET_MAX_SIZE; - else if (max_size < FLX_DNS_PACKET_HEADER_SIZE) - max_size = FLX_DNS_PACKET_HEADER_SIZE; + max_size = AVAHI_DNS_PACKET_MAX_SIZE; + else if (max_size < AVAHI_DNS_PACKET_HEADER_SIZE) + max_size = AVAHI_DNS_PACKET_HEADER_SIZE; - p = g_malloc(sizeof(flxDnsPacket) + max_size); - p->size = p->rindex = FLX_DNS_PACKET_HEADER_SIZE; + p = g_malloc(sizeof(AvahiDnsPacket) + max_size); + p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; p->max_size = max_size; p->name_table = NULL; - memset(FLX_DNS_PACKET_DATA(p), 0, p->size); + memset(AVAHI_DNS_PACKET_DATA(p), 0, p->size); return p; } -flxDnsPacket* flx_dns_packet_new_query(guint max_size) { - flxDnsPacket *p; +AvahiDnsPacket* avahi_dns_packet_new_query(guint max_size) { + AvahiDnsPacket *p; - p = flx_dns_packet_new(max_size); - flx_dns_packet_set_field(p, FLX_DNS_FIELD_FLAGS, FLX_DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + p = avahi_dns_packet_new(max_size); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); return p; } -flxDnsPacket* flx_dns_packet_new_response(guint max_size) { - flxDnsPacket *p; +AvahiDnsPacket* avahi_dns_packet_new_response(guint max_size) { + AvahiDnsPacket *p; - p = flx_dns_packet_new(max_size); - flx_dns_packet_set_field(p, FLX_DNS_FIELD_FLAGS, FLX_DNS_FLAGS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + p = avahi_dns_packet_new(max_size); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); return p; } -void flx_dns_packet_free(flxDnsPacket *p) { +void avahi_dns_packet_free(AvahiDnsPacket *p) { g_assert(p); if (p->name_table) @@ -49,22 +49,22 @@ void flx_dns_packet_free(flxDnsPacket *p) { g_free(p); } -void flx_dns_packet_set_field(flxDnsPacket *p, guint index, guint16 v) { +void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint index, guint16 v) { g_assert(p); - g_assert(index < FLX_DNS_PACKET_HEADER_SIZE); + g_assert(index < AVAHI_DNS_PACKET_HEADER_SIZE); - ((guint16*) FLX_DNS_PACKET_DATA(p))[index] = g_htons(v); + ((guint16*) AVAHI_DNS_PACKET_DATA(p))[index] = g_htons(v); } -guint16 flx_dns_packet_get_field(flxDnsPacket *p, guint index) { +guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint index) { g_assert(p); - g_assert(index < FLX_DNS_PACKET_HEADER_SIZE); + g_assert(index < AVAHI_DNS_PACKET_HEADER_SIZE); - return g_ntohs(((guint16*) FLX_DNS_PACKET_DATA(p))[index]); + return g_ntohs(((guint16*) AVAHI_DNS_PACKET_DATA(p))[index]); } /* Read the first label from string *name, unescape "\" and write it to dest */ -gchar *flx_unescape_label(gchar *dest, guint size, const gchar **name) { +gchar *avahi_unescape_label(gchar *dest, guint size, const gchar **name) { guint i = 0; gchar *d; @@ -105,7 +105,7 @@ gchar *flx_unescape_label(gchar *dest, guint size, const gchar **name) { return dest; } -guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { +guint8* avahi_dns_packet_append_name(AvahiDnsPacket *p, const gchar *name) { guint8 *d, *saved_ptr = NULL; guint saved_size; @@ -113,7 +113,7 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { g_assert(name); saved_size = p->size; - saved_ptr = flx_dns_packet_extend(p, 0); + saved_ptr = avahi_dns_packet_extend(p, 0); while (*name) { guint n; @@ -126,14 +126,14 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { if (p->name_table && (prev = g_hash_table_lookup(p->name_table, name))) { guint index; - g_assert(prev >= FLX_DNS_PACKET_DATA(p)); - index = (guint) (prev - FLX_DNS_PACKET_DATA(p)); + g_assert(prev >= AVAHI_DNS_PACKET_DATA(p)); + index = (guint) (prev - AVAHI_DNS_PACKET_DATA(p)); g_assert(index < p->size); if (index < 0x4000) { guint16 *t; - if (!(t = (guint16*) flx_dns_packet_extend(p, sizeof(guint16)))) + if (!(t = (guint16*) avahi_dns_packet_extend(p, sizeof(guint16)))) return NULL; *t = g_htons((0xC000 | index)); @@ -143,19 +143,19 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { pname = name; - if (!(flx_unescape_label(label, sizeof(label), &name))) + if (!(avahi_unescape_label(label, sizeof(label), &name))) goto fail; - if (!(d = flx_dns_packet_append_string(p, label))) + if (!(d = avahi_dns_packet_append_string(p, label))) goto fail; if (!p->name_table) - p->name_table = g_hash_table_new_full((GHashFunc) flx_domain_hash, (GEqualFunc) flx_domain_equal, g_free, NULL); + p->name_table = g_hash_table_new_full((GHashFunc) avahi_domain_hash, (GEqualFunc) avahi_domain_equal, g_free, NULL); g_hash_table_insert(p->name_table, g_strdup(pname), d); } - if (!(d = flx_dns_packet_extend(p, 1))) + if (!(d = avahi_dns_packet_extend(p, 1))) goto fail; *d = 0; @@ -167,22 +167,22 @@ fail: return NULL; } -guint8* flx_dns_packet_append_uint16(flxDnsPacket *p, guint16 v) { +guint8* avahi_dns_packet_append_uint16(AvahiDnsPacket *p, guint16 v) { guint8 *d; g_assert(p); - if (!(d = flx_dns_packet_extend(p, sizeof(guint16)))) + if (!(d = avahi_dns_packet_extend(p, sizeof(guint16)))) return NULL; *((guint16*) d) = g_htons(v); return d; } -guint8 *flx_dns_packet_append_uint32(flxDnsPacket *p, guint32 v) { +guint8 *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, guint32 v) { guint8 *d; g_assert(p); - if (!(d = flx_dns_packet_extend(p, sizeof(guint32)))) + if (!(d = avahi_dns_packet_extend(p, sizeof(guint32)))) return NULL; *((guint32*) d) = g_htonl(v); @@ -190,21 +190,21 @@ guint8 *flx_dns_packet_append_uint32(flxDnsPacket *p, guint32 v) { return d; } -guint8 *flx_dns_packet_append_bytes(flxDnsPacket *p, gconstpointer b, guint l) { +guint8 *avahi_dns_packet_append_bytes(AvahiDnsPacket *p, gconstpointer b, guint l) { guint8* d; g_assert(p); g_assert(b); g_assert(l); - if (!(d = flx_dns_packet_extend(p, l))) + if (!(d = avahi_dns_packet_extend(p, l))) return NULL; memcpy(d, b, l); return d; } -guint8* flx_dns_packet_append_string(flxDnsPacket *p, const gchar *s) { +guint8* avahi_dns_packet_append_string(AvahiDnsPacket *p, const gchar *s) { guint8* d; guint k; @@ -214,7 +214,7 @@ guint8* flx_dns_packet_append_string(flxDnsPacket *p, const gchar *s) { if ((k = strlen(s)) >= 255) k = 255; - if (!(d = flx_dns_packet_extend(p, k+1))) + if (!(d = avahi_dns_packet_extend(p, k+1))) return NULL; *d = (guint8) k; @@ -223,7 +223,7 @@ guint8* flx_dns_packet_append_string(flxDnsPacket *p, const gchar *s) { return d; } -guint8 *flx_dns_packet_extend(flxDnsPacket *p, guint l) { +guint8 *avahi_dns_packet_extend(AvahiDnsPacket *p, guint l) { guint8 *d; g_assert(p); @@ -231,31 +231,31 @@ guint8 *flx_dns_packet_extend(flxDnsPacket *p, guint l) { if (p->size+l > p->max_size) return NULL; - d = FLX_DNS_PACKET_DATA(p) + p->size; + d = AVAHI_DNS_PACKET_DATA(p) + p->size; p->size += l; return d; } -gint flx_dns_packet_check_valid(flxDnsPacket *p) { +gint avahi_dns_packet_check_valid(AvahiDnsPacket *p) { guint16 flags; g_assert(p); if (p->size < 12) return -1; - flags = flx_dns_packet_get_field(p, FLX_DNS_FIELD_FLAGS); + flags = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS); - if (flags & FLX_DNS_FLAG_OPCODE || flags & FLX_DNS_FLAG_RCODE) + if (flags & AVAHI_DNS_FLAG_OPCODE || flags & AVAHI_DNS_FLAG_RCODE) return -1; return 0; } -gint flx_dns_packet_is_query(flxDnsPacket *p) { +gint avahi_dns_packet_is_query(AvahiDnsPacket *p) { g_assert(p); - return !(flx_dns_packet_get_field(p, FLX_DNS_FIELD_FLAGS) & FLX_DNS_FLAG_QR); + return !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_QR); } /* Read a label from a DNS packet, escape "\" and ".", append \0 */ @@ -294,7 +294,7 @@ static gchar *escape_label(guint8* src, guint src_length, gchar **ret_name, guin return r; } -static gint consume_labels(flxDnsPacket *p, guint index, gchar *ret_name, guint l) { +static gint consume_labels(AvahiDnsPacket *p, guint index, gchar *ret_name, guint l) { gint ret = 0; int compressed = 0; int first_label = 1; @@ -306,7 +306,7 @@ static gint consume_labels(flxDnsPacket *p, guint index, gchar *ret_name, guint if (index+1 > p->size) return -1; - n = FLX_DNS_PACKET_DATA(p)[index]; + n = AVAHI_DNS_PACKET_DATA(p)[index]; if (!n) { index++; @@ -337,7 +337,7 @@ static gint consume_labels(flxDnsPacket *p, guint index, gchar *ret_name, guint } else first_label = 0; - if (!(escape_label(FLX_DNS_PACKET_DATA(p) + index, n, &ret_name, &l))) + if (!(escape_label(AVAHI_DNS_PACKET_DATA(p) + index, n, &ret_name, &l))) return -1; index += n; @@ -350,7 +350,7 @@ static gint consume_labels(flxDnsPacket *p, guint index, gchar *ret_name, guint if (index+2 > p->size) return -1; - index = ((guint) (FLX_DNS_PACKET_DATA(p)[index] & ~0xC0)) << 8 | FLX_DNS_PACKET_DATA(p)[index+1]; + index = ((guint) (AVAHI_DNS_PACKET_DATA(p)[index] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[index+1]; if (!compressed) ret += 2; @@ -361,7 +361,7 @@ static gint consume_labels(flxDnsPacket *p, guint index, gchar *ret_name, guint } } -gint flx_dns_packet_consume_name(flxDnsPacket *p, gchar *ret_name, guint l) { +gint avahi_dns_packet_consume_name(AvahiDnsPacket *p, gchar *ret_name, guint l) { gint r; if ((r = consume_labels(p, p->rindex, ret_name, l)) < 0) @@ -371,33 +371,33 @@ gint flx_dns_packet_consume_name(flxDnsPacket *p, gchar *ret_name, guint l) { return 0; } -gint flx_dns_packet_consume_uint16(flxDnsPacket *p, guint16 *ret_v) { +gint avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, guint16 *ret_v) { g_assert(p); g_assert(ret_v); if (p->rindex + sizeof(guint16) > p->size) return -1; - *ret_v = g_ntohs(*((guint16*) (FLX_DNS_PACKET_DATA(p) + p->rindex))); + *ret_v = g_ntohs(*((guint16*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex))); p->rindex += sizeof(guint16); return 0; } -gint flx_dns_packet_consume_uint32(flxDnsPacket *p, guint32 *ret_v) { +gint avahi_dns_packet_consume_uint32(AvahiDnsPacket *p, guint32 *ret_v) { g_assert(p); g_assert(ret_v); if (p->rindex + sizeof(guint32) > p->size) return -1; - *ret_v = g_ntohl(*((guint32*) (FLX_DNS_PACKET_DATA(p) + p->rindex))); + *ret_v = g_ntohl(*((guint32*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex))); p->rindex += sizeof(guint32); return 0; } -gint flx_dns_packet_consume_bytes(flxDnsPacket *p, gpointer ret_data, guint l) { +gint avahi_dns_packet_consume_bytes(AvahiDnsPacket *p, gpointer ret_data, guint l) { g_assert(p); g_assert(ret_data); g_assert(l > 0); @@ -405,13 +405,13 @@ gint flx_dns_packet_consume_bytes(flxDnsPacket *p, gpointer ret_data, guint l) { if (p->rindex + l > p->size) return -1; - memcpy(ret_data, FLX_DNS_PACKET_DATA(p) + p->rindex, l); + memcpy(ret_data, AVAHI_DNS_PACKET_DATA(p) + p->rindex, l); p->rindex += l; return 0; } -gint flx_dns_packet_consume_string(flxDnsPacket *p, gchar *ret_string, guint l) { +gint avahi_dns_packet_consume_string(AvahiDnsPacket *p, gchar *ret_string, guint l) { guint k; g_assert(p); @@ -421,7 +421,7 @@ gint flx_dns_packet_consume_string(flxDnsPacket *p, gchar *ret_string, guint l) if (p->rindex >= p->size) return -1; - k = FLX_DNS_PACKET_DATA(p)[p->rindex]; + k = AVAHI_DNS_PACKET_DATA(p)[p->rindex]; if (p->rindex+1+k > p->size) return -1; @@ -429,7 +429,7 @@ gint flx_dns_packet_consume_string(flxDnsPacket *p, gchar *ret_string, guint l) if (l > k+1) l = k+1; - memcpy(ret_string, FLX_DNS_PACKET_DATA(p)+p->rindex+1, l-1); + memcpy(ret_string, AVAHI_DNS_PACKET_DATA(p)+p->rindex+1, l-1); ret_string[l-1] = 0; @@ -439,16 +439,16 @@ gint flx_dns_packet_consume_string(flxDnsPacket *p, gchar *ret_string, guint l) } -gconstpointer flx_dns_packet_get_rptr(flxDnsPacket *p) { +gconstpointer avahi_dns_packet_get_rptr(AvahiDnsPacket *p) { g_assert(p); if (p->rindex > p->size) return NULL; - return FLX_DNS_PACKET_DATA(p) + p->rindex; + return AVAHI_DNS_PACKET_DATA(p) + p->rindex; } -gint flx_dns_packet_skip(flxDnsPacket *p, guint length) { +gint avahi_dns_packet_skip(AvahiDnsPacket *p, guint length) { g_assert(p); if (p->rindex + length > p->size) @@ -458,13 +458,13 @@ gint flx_dns_packet_skip(flxDnsPacket *p, guint length) { return 0; } -flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_flush) { +AvahiRecord* avahi_dns_packet_consume_record(AvahiDnsPacket *p, gboolean *ret_cache_flush) { gchar name[257], buf[257]; guint16 type, class; guint32 ttl; guint16 rdlength; gconstpointer data; - flxRecord *r = NULL; + AvahiRecord *r = NULL; gconstpointer start; g_assert(p); @@ -472,92 +472,92 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl /* g_message("consume_record()"); */ - if (flx_dns_packet_consume_name(p, name, sizeof(name)) < 0 || - flx_dns_packet_consume_uint16(p, &type) < 0 || - flx_dns_packet_consume_uint16(p, &class) < 0 || - flx_dns_packet_consume_uint32(p, &ttl) < 0 || - flx_dns_packet_consume_uint16(p, &rdlength) < 0 || + if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 || + avahi_dns_packet_consume_uint16(p, &type) < 0 || + avahi_dns_packet_consume_uint16(p, &class) < 0 || + avahi_dns_packet_consume_uint32(p, &ttl) < 0 || + avahi_dns_packet_consume_uint16(p, &rdlength) < 0 || p->rindex + rdlength > p->size) goto fail; /* g_message("name = %s, rdlength = %u", name, rdlength); */ - *ret_cache_flush = !!(class & FLX_DNS_CACHE_FLUSH); - class &= ~FLX_DNS_CACHE_FLUSH; + *ret_cache_flush = !!(class & AVAHI_DNS_CACHE_FLUSH); + class &= ~AVAHI_DNS_CACHE_FLUSH; - start = flx_dns_packet_get_rptr(p); + start = avahi_dns_packet_get_rptr(p); - r = flx_record_new_full(name, class, type); + r = avahi_record_new_full(name, class, type); switch (type) { - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: /* g_message("ptr"); */ - if (flx_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) + if (avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) goto fail; r->data.ptr.name = g_strdup(buf); break; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: /* g_message("srv"); */ - if (flx_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 || - flx_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 || - flx_dns_packet_consume_uint16(p, &r->data.srv.port) < 0 || - flx_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) + if (avahi_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 || + avahi_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 || + avahi_dns_packet_consume_uint16(p, &r->data.srv.port) < 0 || + avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) goto fail; r->data.srv.name = g_strdup(buf); break; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: /* g_message("hinfo"); */ - if (flx_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) + if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) goto fail; r->data.hinfo.cpu = g_strdup(buf); - if (flx_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) + if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) goto fail; r->data.hinfo.os = g_strdup(buf); break; - case FLX_DNS_TYPE_TXT: + case AVAHI_DNS_TYPE_TXT: /* g_message("txt"); */ if (rdlength > 0) { - r->data.txt.string_list = flx_string_list_parse(flx_dns_packet_get_rptr(p), rdlength); + r->data.txt.string_list = avahi_string_list_parse(avahi_dns_packet_get_rptr(p), rdlength); - if (flx_dns_packet_skip(p, rdlength) < 0) + if (avahi_dns_packet_skip(p, rdlength) < 0) goto fail; } else r->data.txt.string_list = NULL; break; - case FLX_DNS_TYPE_A: + case AVAHI_DNS_TYPE_A: /* g_message("A"); */ - if (flx_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(flxIPv4Address)) < 0) + if (avahi_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(AvahiIPv4Address)) < 0) goto fail; break; - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_AAAA: /* g_message("aaaa"); */ - if (flx_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(flxIPv6Address)) < 0) + if (avahi_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(AvahiIPv6Address)) < 0) goto fail; break; @@ -568,19 +568,19 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl if (rdlength > 0) { - r->data.generic.data = g_memdup(flx_dns_packet_get_rptr(p), rdlength); + r->data.generic.data = g_memdup(avahi_dns_packet_get_rptr(p), rdlength); - if (flx_dns_packet_skip(p, rdlength) < 0) + if (avahi_dns_packet_skip(p, rdlength) < 0) goto fail; } break; } -/* g_message("%i == %u ?", (guint8*) flx_dns_packet_get_rptr(p) - (guint8*) start, rdlength); */ +/* g_message("%i == %u ?", (guint8*) avahi_dns_packet_get_rptr(p) - (guint8*) start, rdlength); */ /* Check if we read enough data */ - if ((guint8*) flx_dns_packet_get_rptr(p) - (guint8*) start != rdlength) + if ((guint8*) avahi_dns_packet_get_rptr(p) - (guint8*) start != rdlength) goto fail; r->ttl = ttl; @@ -589,30 +589,30 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl fail: if (r) - flx_record_unref(r); + avahi_record_unref(r); return NULL; } -flxKey* flx_dns_packet_consume_key(flxDnsPacket *p, gboolean *ret_unicast_response) { +AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, gboolean *ret_unicast_response) { gchar name[256]; guint16 type, class; g_assert(p); g_assert(ret_unicast_response); - if (flx_dns_packet_consume_name(p, name, sizeof(name)) < 0 || - flx_dns_packet_consume_uint16(p, &type) < 0 || - flx_dns_packet_consume_uint16(p, &class) < 0) + if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 || + avahi_dns_packet_consume_uint16(p, &type) < 0 || + avahi_dns_packet_consume_uint16(p, &class) < 0) return NULL; - *ret_unicast_response = !!(class & FLX_DNS_UNICAST_RESPONSE); - class &= ~FLX_DNS_UNICAST_RESPONSE; + *ret_unicast_response = !!(class & AVAHI_DNS_UNICAST_RESPONSE); + class &= ~AVAHI_DNS_UNICAST_RESPONSE; - return flx_key_new(name, class, type); + return avahi_key_new(name, class, type); } -guint8* flx_dns_packet_append_key(flxDnsPacket *p, flxKey *k, gboolean unicast_response) { +guint8* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, gboolean unicast_response) { guint8 *t; guint size; @@ -621,9 +621,9 @@ guint8* flx_dns_packet_append_key(flxDnsPacket *p, flxKey *k, gboolean unicast_r size = p->size; - if (!(t = flx_dns_packet_append_name(p, k->name)) || - !flx_dns_packet_append_uint16(p, k->type) || - !flx_dns_packet_append_uint16(p, k->class | (unicast_response ? FLX_DNS_UNICAST_RESPONSE : 0))) { + if (!(t = avahi_dns_packet_append_name(p, k->name)) || + !avahi_dns_packet_append_uint16(p, k->type) || + !avahi_dns_packet_append_uint16(p, k->class | (unicast_response ? AVAHI_DNS_UNICAST_RESPONSE : 0))) { p->size = size; return NULL; } @@ -631,7 +631,7 @@ guint8* flx_dns_packet_append_key(flxDnsPacket *p, flxKey *k, gboolean unicast_r return t; } -guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cache_flush) { +guint8* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, gboolean cache_flush) { guint8 *t, *l, *start; guint size; @@ -640,69 +640,69 @@ guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cac size = p->size; - if (!(t = flx_dns_packet_append_name(p, r->key->name)) || - !flx_dns_packet_append_uint16(p, r->key->type) || - !flx_dns_packet_append_uint16(p, cache_flush ? (r->key->class | FLX_DNS_CACHE_FLUSH) : (r->key->class &~ FLX_DNS_CACHE_FLUSH)) || - !flx_dns_packet_append_uint32(p, r->ttl) || - !(l = flx_dns_packet_append_uint16(p, 0))) + if (!(t = avahi_dns_packet_append_name(p, r->key->name)) || + !avahi_dns_packet_append_uint16(p, r->key->type) || + !avahi_dns_packet_append_uint16(p, cache_flush ? (r->key->class | AVAHI_DNS_CACHE_FLUSH) : (r->key->class &~ AVAHI_DNS_CACHE_FLUSH)) || + !avahi_dns_packet_append_uint32(p, r->ttl) || + !(l = avahi_dns_packet_append_uint16(p, 0))) goto fail; - start = flx_dns_packet_extend(p, 0); + start = avahi_dns_packet_extend(p, 0); switch (r->key->type) { - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME : + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME : - if (!(flx_dns_packet_append_name(p, r->data.ptr.name))) + if (!(avahi_dns_packet_append_name(p, r->data.ptr.name))) goto fail; break; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: - if (!flx_dns_packet_append_uint16(p, r->data.srv.priority) || - !flx_dns_packet_append_uint16(p, r->data.srv.weight) || - !flx_dns_packet_append_uint16(p, r->data.srv.port) || - !flx_dns_packet_append_name(p, r->data.srv.name)) + if (!avahi_dns_packet_append_uint16(p, r->data.srv.priority) || + !avahi_dns_packet_append_uint16(p, r->data.srv.weight) || + !avahi_dns_packet_append_uint16(p, r->data.srv.port) || + !avahi_dns_packet_append_name(p, r->data.srv.name)) goto fail; break; - case FLX_DNS_TYPE_HINFO: - if (!flx_dns_packet_append_string(p, r->data.hinfo.cpu) || - !flx_dns_packet_append_string(p, r->data.hinfo.os)) + case AVAHI_DNS_TYPE_HINFO: + if (!avahi_dns_packet_append_string(p, r->data.hinfo.cpu) || + !avahi_dns_packet_append_string(p, r->data.hinfo.os)) goto fail; break; - case FLX_DNS_TYPE_TXT: { + case AVAHI_DNS_TYPE_TXT: { guint8 *data; guint size; - size = flx_string_list_serialize(r->data.txt.string_list, NULL, 0); + size = avahi_string_list_serialize(r->data.txt.string_list, NULL, 0); /* g_message("appending string: %u %p", size, r->data.txt.string_list); */ - if (!(data = flx_dns_packet_extend(p, size))) + if (!(data = avahi_dns_packet_extend(p, size))) goto fail; - flx_string_list_serialize(r->data.txt.string_list, data, size); + avahi_string_list_serialize(r->data.txt.string_list, data, size); break; } - case FLX_DNS_TYPE_A: + case AVAHI_DNS_TYPE_A: - if (!flx_dns_packet_append_bytes(p, &r->data.a.address, sizeof(r->data.a.address))) + if (!avahi_dns_packet_append_bytes(p, &r->data.a.address, sizeof(r->data.a.address))) goto fail; break; - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_AAAA: - if (!flx_dns_packet_append_bytes(p, &r->data.aaaa.address, sizeof(r->data.aaaa.address))) + if (!avahi_dns_packet_append_bytes(p, &r->data.aaaa.address, sizeof(r->data.aaaa.address))) goto fail; break; @@ -710,7 +710,7 @@ guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cac default: if (r->data.generic.size && - flx_dns_packet_append_bytes(p, r->data.generic.data, r->data.generic.size)) + avahi_dns_packet_append_bytes(p, r->data.generic.data, r->data.generic.size)) goto fail; break; @@ -719,7 +719,7 @@ guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cac - size = flx_dns_packet_extend(p, 0) - start; + size = avahi_dns_packet_extend(p, 0) - start; g_assert(size <= 0xFFFF); /* g_message("appended %u", size); */ @@ -734,13 +734,13 @@ fail: return NULL; } -gboolean flx_dns_packet_is_empty(flxDnsPacket *p) { +gboolean avahi_dns_packet_is_empty(AvahiDnsPacket *p) { g_assert(p); - return p->size <= FLX_DNS_PACKET_HEADER_SIZE; + return p->size <= AVAHI_DNS_PACKET_HEADER_SIZE; } -guint flx_dns_packet_space(flxDnsPacket *p) { +guint avahi_dns_packet_space(AvahiDnsPacket *p) { g_assert(p); g_assert(p->size <= p->max_size); @@ -5,66 +5,66 @@ #include "rr.h" -#define FLX_DNS_PACKET_MAX_SIZE 9000 -#define FLX_DNS_PACKET_HEADER_SIZE 12 +#define AVAHI_DNS_PACKET_MAX_SIZE 9000 +#define AVAHI_DNS_PACKET_HEADER_SIZE 12 -typedef struct _flxDnsPacket { +typedef struct _AvahiDnsPacket { guint size, rindex, max_size; GHashTable *name_table; /* for name compression */ -} flxDnsPacket; +} AvahiDnsPacket; -#define FLX_DNS_PACKET_DATA(p) (((guint8*) p) + sizeof(flxDnsPacket)) +#define AVAHI_DNS_PACKET_DATA(p) (((guint8*) p) + sizeof(AvahiDnsPacket)) -flxDnsPacket* flx_dns_packet_new(guint size); -flxDnsPacket* flx_dns_packet_new_query(guint size); -flxDnsPacket* flx_dns_packet_new_response(guint size); +AvahiDnsPacket* avahi_dns_packet_new(guint size); +AvahiDnsPacket* avahi_dns_packet_new_query(guint size); +AvahiDnsPacket* avahi_dns_packet_new_response(guint size); -void flx_dns_packet_free(flxDnsPacket *p); -void flx_dns_packet_set_field(flxDnsPacket *p, guint index, guint16 v); -guint16 flx_dns_packet_get_field(flxDnsPacket *p, guint index); +void avahi_dns_packet_free(AvahiDnsPacket *p); +void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint index, guint16 v); +guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint index); -guint8 *flx_dns_packet_extend(flxDnsPacket *p, guint l); +guint8 *avahi_dns_packet_extend(AvahiDnsPacket *p, guint l); -guint8 *flx_dns_packet_append_uint16(flxDnsPacket *p, guint16 v); -guint8 *flx_dns_packet_append_uint32(flxDnsPacket *p, guint32 v); -guint8 *flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name); -guint8 *flx_dns_packet_append_bytes(flxDnsPacket *p, gconstpointer, guint l); -guint8* flx_dns_packet_append_key(flxDnsPacket *p, flxKey *k, gboolean unicast_response); -guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cache_flush); -guint8* flx_dns_packet_append_string(flxDnsPacket *p, const gchar *s); +guint8 *avahi_dns_packet_append_uint16(AvahiDnsPacket *p, guint16 v); +guint8 *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, guint32 v); +guint8 *avahi_dns_packet_append_name(AvahiDnsPacket *p, const gchar *name); +guint8 *avahi_dns_packet_append_bytes(AvahiDnsPacket *p, gconstpointer, guint l); +guint8* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, gboolean unicast_response); +guint8* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, gboolean cache_flush); +guint8* avahi_dns_packet_append_string(AvahiDnsPacket *p, const gchar *s); -gint flx_dns_packet_is_query(flxDnsPacket *p); -gint flx_dns_packet_check_valid(flxDnsPacket *p); +gint avahi_dns_packet_is_query(AvahiDnsPacket *p); +gint avahi_dns_packet_check_valid(AvahiDnsPacket *p); -gint flx_dns_packet_consume_uint16(flxDnsPacket *p, guint16 *ret_v); -gint flx_dns_packet_consume_uint32(flxDnsPacket *p, guint32 *ret_v); -gint flx_dns_packet_consume_name(flxDnsPacket *p, gchar *ret_name, guint l); -gint flx_dns_packet_consume_bytes(flxDnsPacket *p, gpointer ret_data, guint l); -flxKey* flx_dns_packet_consume_key(flxDnsPacket *p, gboolean *ret_unicast_response); -flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_flush); -gint flx_dns_packet_consume_string(flxDnsPacket *p, gchar *ret_string, guint l); +gint avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, guint16 *ret_v); +gint avahi_dns_packet_consume_uint32(AvahiDnsPacket *p, guint32 *ret_v); +gint avahi_dns_packet_consume_name(AvahiDnsPacket *p, gchar *ret_name, guint l); +gint avahi_dns_packet_consume_bytes(AvahiDnsPacket *p, gpointer ret_data, guint l); +AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, gboolean *ret_unicast_response); +AvahiRecord* avahi_dns_packet_consume_record(AvahiDnsPacket *p, gboolean *ret_cache_flush); +gint avahi_dns_packet_consume_string(AvahiDnsPacket *p, gchar *ret_string, guint l); -gconstpointer flx_dns_packet_get_rptr(flxDnsPacket *p); +gconstpointer avahi_dns_packet_get_rptr(AvahiDnsPacket *p); -gint flx_dns_packet_skip(flxDnsPacket *p, guint length); +gint avahi_dns_packet_skip(AvahiDnsPacket *p, guint length); -gboolean flx_dns_packet_is_empty(flxDnsPacket *p); -guint flx_dns_packet_space(flxDnsPacket *p); +gboolean avahi_dns_packet_is_empty(AvahiDnsPacket *p); +guint avahi_dns_packet_space(AvahiDnsPacket *p); -#define FLX_DNS_FIELD_ID 0 -#define FLX_DNS_FIELD_FLAGS 1 -#define FLX_DNS_FIELD_QDCOUNT 2 -#define FLX_DNS_FIELD_ANCOUNT 3 -#define FLX_DNS_FIELD_NSCOUNT 4 -#define FLX_DNS_FIELD_ARCOUNT 5 +#define AVAHI_DNS_FIELD_ID 0 +#define AVAHI_DNS_FIELD_FLAGS 1 +#define AVAHI_DNS_FIELD_QDCOUNT 2 +#define AVAHI_DNS_FIELD_ANCOUNT 3 +#define AVAHI_DNS_FIELD_NSCOUNT 4 +#define AVAHI_DNS_FIELD_ARCOUNT 5 -#define FLX_DNS_FLAG_QR (1 << 15) -#define FLX_DNS_FLAG_OPCODE (15 << 11) -#define FLX_DNS_FLAG_RCODE (15) -#define FLX_DNS_FLAG_TC (1 << 9) +#define AVAHI_DNS_FLAG_QR (1 << 15) +#define AVAHI_DNS_FLAG_OPCODE (15 << 11) +#define AVAHI_DNS_FLAG_RCODE (15) +#define AVAHI_DNS_FLAG_TC (1 << 9) -#define FLX_DNS_FLAGS(qr, opcode, aa, tc, rd, ra, z, ad, cd, rcode) \ +#define AVAHI_DNS_FLAGS(qr, opcode, aa, tc, rd, ra, z, ad, cd, rcode) \ (((guint16) !!qr << 15) | \ ((guint16) (opcode & 15) << 11) | \ ((guint16) !!aa << 10) | \ @@ -76,7 +76,7 @@ guint flx_dns_packet_space(flxDnsPacket *p); ((guint16) (rd & 15))) -gchar *flx_unescape_label(gchar *dest, guint size, const gchar **name); +gchar *avahi_unescape_label(gchar *dest, guint size, const gchar **name); #endif diff --git a/domain-test.c b/domain-test.c index ab02943..f3deeac 100644 --- a/domain-test.c +++ b/domain-test.c @@ -3,17 +3,17 @@ int main(int argc, char *argv[]) { gchar *s; - g_message("host name: %s", s = flx_get_host_name()); + g_message("host name: %s", s = avahi_get_host_name()); g_free(s); - g_message("%s", s = flx_normalize_name("foo.foo.")); + g_message("%s", s = avahi_normalize_name("foo.foo.")); g_free(s); - g_message("%s", s = flx_normalize_name("foo.foo.")); + g_message("%s", s = avahi_normalize_name("foo.foo.")); g_free(s); - g_message("%i", flx_domain_equal("\\aaa bbb\\.cccc\\\\.dee.fff.", "aaa\\ bbb\\.cccc\\\\.dee.fff")); + g_message("%i", avahi_domain_equal("\\aaa bbb\\.cccc\\\\.dee.fff.", "aaa\\ bbb\\.cccc\\\\.dee.fff")); return 0; } @@ -1,99 +1,99 @@ -#ifndef fooflxhfoo -#define fooflxhfoo +#ifndef fooAvahihfoo +#define fooAvahihfoo #include <stdio.h> #include <glib.h> -typedef struct _flxServer flxServer; -typedef struct _flxEntry flxEntry; -typedef struct _flxEntryGroup flxEntryGroup; +typedef struct _AvahiServer AvahiServer; +typedef struct _AvahiEntry AvahiEntry; +typedef struct _AvahiEntryGroup AvahiEntryGroup; #include "address.h" #include "rr.h" typedef enum { - FLX_ENTRY_NULL = 0, - FLX_ENTRY_UNIQUE = 1, - FLX_ENTRY_NOPROBE = 2, - FLX_ENTRY_NOANNOUNCE = 4 -} flxEntryFlags; + AVAHI_ENTRY_NULL = 0, + AVAHI_ENTRY_UNIQUE = 1, + AVAHI_ENTRY_NOPROBE = 2, + AVAHI_ENTRY_NOANNOUNCE = 4 +} AvahiEntryFlags; typedef enum { - FLX_ENTRY_GROUP_UNCOMMITED, - FLX_ENTRY_GROUP_REGISTERING, - FLX_ENTRY_GROUP_ESTABLISHED, - FLX_ENTRY_GROUP_COLLISION -} flxEntryGroupState; + AVAHI_ENTRY_GROUP_UNCOMMITED, + AVAHI_ENTRY_GROUP_REGISTERING, + AVAHI_ENTRY_GROUP_ESTABLISHED, + AVAHI_ENTRY_GROUP_COLLISION +} AvahiEntryGroupState; -typedef void (*flxEntryGroupCallback) (flxServer *s, flxEntryGroup *g, flxEntryGroupState state, gpointer userdata); +typedef void (*AvahiEntryGroupCallback) (AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata); -flxServer *flx_server_new(GMainContext *c); -void flx_server_free(flxServer* s); +AvahiServer *avahi_server_new(GMainContext *c); +void avahi_server_free(AvahiServer* s); -const flxRecord *flx_server_iterate(flxServer *s, flxEntryGroup *g, void **state); -void flx_server_dump(flxServer *s, FILE *f); +const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state); +void avahi_server_dump(AvahiServer *s, FILE *f); -flxEntryGroup *flx_entry_group_new(flxServer *s, flxEntryGroupCallback callback, gpointer userdata); -void flx_entry_group_free(flxEntryGroup *g); -void flx_entry_group_commit(flxEntryGroup *g); -flxEntryGroupState flx_entry_group_get_state(flxEntryGroup *g); +AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata); +void avahi_entry_group_free(AvahiEntryGroup *g); +void avahi_entry_group_commit(AvahiEntryGroup *g); +AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g); -void flx_server_add( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, - flxRecord *r); + AvahiEntryFlags flags, + AvahiRecord *r); -void flx_server_add_ptr( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_ptr( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, const gchar *dest); -void flx_server_add_address( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_address( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, - flxAddress *a); + AvahiAddress *a); -void flx_server_add_text( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, ... /* text records, terminated by NULL */); -void flx_server_add_text_va( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text_va( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, va_list va); -void flx_server_add_text_strlst( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text_strlst( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, - flxStringList *strlst); + AvahiStringList *strlst); -void flx_server_add_service( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -103,9 +103,9 @@ void flx_server_add_service( guint16 port, ... /* text records, terminated by NULL */); -void flx_server_add_service_va( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service_va( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -115,9 +115,9 @@ void flx_server_add_service_va( guint16 port, va_list va); -void flx_server_add_service_strlst( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service_strlst( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -125,19 +125,19 @@ void flx_server_add_service_strlst( const gchar *domain, const gchar *host, guint16 port, - flxStringList *strlst); + AvahiStringList *strlst); typedef enum { - FLX_SUBSCRIPTION_NEW, - FLX_SUBSCRIPTION_REMOVE, - FLX_SUBSCRIPTION_CHANGE -} flxSubscriptionEvent; + AVAHI_SUBSCRIPTION_NEW, + AVAHI_SUBSCRIPTION_REMOVE, + AVAHI_SUBSCRIPTION_CHANGE +} AvahiSubscriptionEvent; -typedef struct _flxSubscription flxSubscription; +typedef struct _AvahiSubscription AvahiSubscription; -typedef void (*flxSubscriptionCallback)(flxSubscription *s, flxRecord *record, gint interface, guchar protocol, flxSubscriptionEvent event, gpointer userdata); +typedef void (*AvahiSubscriptionCallback)(AvahiSubscription *s, AvahiRecord *record, gint interface, guchar protocol, AvahiSubscriptionEvent event, gpointer userdata); -flxSubscription *flx_subscription_new(flxServer *s, flxKey *key, gint interface, guchar protocol, flxSubscriptionCallback callback, gpointer userdata); -void flx_subscription_free(flxSubscription *s); +AvahiSubscription *avahi_subscription_new(AvahiServer *s, AvahiKey *key, gint interface, guchar protocol, AvahiSubscriptionCallback callback, gpointer userdata); +void avahi_subscription_free(AvahiSubscription *s); #endif @@ -12,26 +12,26 @@ #include "socket.h" #include "announce.h" -static void update_address_rr(flxInterfaceMonitor *m, flxInterfaceAddress *a, int remove) { +static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, int remove) { g_assert(m); g_assert(a); - if (!flx_interface_address_relevant(a) || remove) { + if (!avahi_interface_address_relevant(a) || remove) { if (a->entry_group) { - flx_entry_group_free(a->entry_group); + avahi_entry_group_free(a->entry_group); a->entry_group = NULL; } } else { if (!a->entry_group) { - a->entry_group = flx_entry_group_new(m->server, NULL, NULL); - flx_server_add_address(m->server, a->entry_group, a->interface->hardware->index, AF_UNSPEC, 0, NULL, &a->address); - flx_entry_group_commit(a->entry_group); + 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); } } } -static void update_interface_rr(flxInterfaceMonitor *m, flxInterface *i, int remove) { - flxInterfaceAddress *a; +static void update_interface_rr(AvahiInterfaceMonitor *m, AvahiInterface *i, int remove) { + AvahiInterfaceAddress *a; g_assert(m); g_assert(i); @@ -39,8 +39,8 @@ static void update_interface_rr(flxInterfaceMonitor *m, flxInterface *i, int rem update_address_rr(m, a, remove); } -static void update_hw_interface_rr(flxInterfaceMonitor *m, flxHwInterface *hw, int remove) { - flxInterface *i; +static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, int remove) { + AvahiInterface *i; g_assert(m); g_assert(hw); @@ -49,27 +49,27 @@ static void update_hw_interface_rr(flxInterfaceMonitor *m, flxHwInterface *hw, i update_interface_rr(m, i, remove); } -static void free_address(flxInterfaceMonitor *m, flxInterfaceAddress *a) { +static void free_address(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a) { g_assert(m); g_assert(a); g_assert(a->interface); - FLX_LLIST_REMOVE(flxInterfaceAddress, address, a->interface->addresses, a); + AVAHI_LLIST_REMOVE(AvahiInterfaceAddress, address, a->interface->addresses, a); if (a->entry_group) - flx_entry_group_free(a->entry_group); + avahi_entry_group_free(a->entry_group); g_free(a); } -static void free_interface(flxInterfaceMonitor *m, flxInterface *i, gboolean send_goodbye) { +static void free_interface(AvahiInterfaceMonitor *m, AvahiInterface *i, gboolean send_goodbye) { g_assert(m); g_assert(i); g_message("removing interface %s.%i", i->hardware->name, i->protocol); - flx_goodbye_interface(m->server, i, send_goodbye); + avahi_goodbye_interface(m->server, i, send_goodbye); g_message("flushing..."); - flx_packet_scheduler_flush_responses(i->scheduler); + avahi_packet_scheduler_flush_responses(i->scheduler); g_message("done"); g_assert(!i->announcements); @@ -77,44 +77,44 @@ static void free_interface(flxInterfaceMonitor *m, flxInterface *i, gboolean sen while (i->addresses) free_address(m, i->addresses); - flx_packet_scheduler_free(i->scheduler); - flx_cache_free(i->cache); + avahi_packet_scheduler_free(i->scheduler); + avahi_cache_free(i->cache); - FLX_LLIST_REMOVE(flxInterface, interface, m->interfaces, i); - FLX_LLIST_REMOVE(flxInterface, by_hardware, i->hardware->interfaces, i); + AVAHI_LLIST_REMOVE(AvahiInterface, interface, m->interfaces, i); + AVAHI_LLIST_REMOVE(AvahiInterface, by_hardware, i->hardware->interfaces, i); g_free(i); } -static void free_hw_interface(flxInterfaceMonitor *m, flxHwInterface *hw, gboolean send_goodbye) { +static void free_hw_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, gboolean send_goodbye) { g_assert(m); g_assert(hw); while (hw->interfaces) free_interface(m, hw->interfaces, send_goodbye); - FLX_LLIST_REMOVE(flxHwInterface, hardware, m->hw_interfaces, hw); + AVAHI_LLIST_REMOVE(AvahiHwInterface, hardware, m->hw_interfaces, hw); g_hash_table_remove(m->hash_table, &hw->index); g_free(hw->name); g_free(hw); } -static flxInterfaceAddress* get_address(flxInterfaceMonitor *m, flxInterface *i, const flxAddress *raddr) { - flxInterfaceAddress *ia; +static AvahiInterfaceAddress* get_address(AvahiInterfaceMonitor *m, AvahiInterface *i, const AvahiAddress *raddr) { + AvahiInterfaceAddress *ia; g_assert(m); g_assert(i); g_assert(raddr); for (ia = i->addresses; ia; ia = ia->address_next) - if (flx_address_cmp(&ia->address, raddr) == 0) + if (avahi_address_cmp(&ia->address, raddr) == 0) return ia; return NULL; } -static int netlink_list_items(flxNetlink *nl, guint16 type, guint *ret_seq) { +static int netlink_list_items(AvahiNetlink *nl, guint16 type, guint *ret_seq) { struct nlmsghdr *n; struct rtgenmsg *gen; guint8 req[1024]; @@ -130,66 +130,66 @@ static int netlink_list_items(flxNetlink *nl, guint16 type, guint *ret_seq) { memset(gen, 0, sizeof(struct rtgenmsg)); gen->rtgen_family = AF_UNSPEC; - return flx_netlink_send(nl, n, ret_seq); + return avahi_netlink_send(nl, n, ret_seq); } -static void new_interface(flxInterfaceMonitor *m, flxHwInterface *hw, guchar protocol) { - flxInterface *i; +static void new_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, guchar protocol) { + AvahiInterface *i; g_assert(m); g_assert(hw); g_assert(protocol != AF_UNSPEC); - i = g_new(flxInterface, 1); + i = g_new(AvahiInterface, 1); i->monitor = m; i->hardware = hw; i->protocol = protocol; i->announcing = FALSE; - FLX_LLIST_HEAD_INIT(flxInterfaceAddress, i->addresses); - FLX_LLIST_HEAD_INIT(flxAnnouncement, i->announcements); + AVAHI_LLIST_HEAD_INIT(AvahiInterfaceAddress, i->addresses); + AVAHI_LLIST_HEAD_INIT(AvahiAnnouncement, i->announcements); - i->cache = flx_cache_new(m->server, i); - i->scheduler = flx_packet_scheduler_new(m->server, i); + i->cache = avahi_cache_new(m->server, i); + i->scheduler = avahi_packet_scheduler_new(m->server, i); - FLX_LLIST_PREPEND(flxInterface, by_hardware, hw->interfaces, i); - FLX_LLIST_PREPEND(flxInterface, interface, m->interfaces, i); + AVAHI_LLIST_PREPEND(AvahiInterface, by_hardware, hw->interfaces, i); + AVAHI_LLIST_PREPEND(AvahiInterface, interface, m->interfaces, i); } -static void check_interface_relevant(flxInterfaceMonitor *m, flxInterface *i) { +static void check_interface_relevant(AvahiInterfaceMonitor *m, AvahiInterface *i) { gboolean b; g_assert(m); g_assert(i); - b = flx_interface_relevant(i); + b = avahi_interface_relevant(i); if (b && !i->announcing) { g_message("New relevant interface %s.%i", i->hardware->name, i->protocol); if (i->protocol == AF_INET) - flx_mdns_mcast_join_ipv4 (i->hardware->index, m->server->fd_ipv4); + avahi_mdns_mcast_join_ipv4 (i->hardware->index, m->server->fd_ipv4); if (i->protocol == AF_INET6) - flx_mdns_mcast_join_ipv6 (i->hardware->index, m->server->fd_ipv6); + avahi_mdns_mcast_join_ipv6 (i->hardware->index, m->server->fd_ipv6); i->announcing = TRUE; - flx_announce_interface(m->server, i); + avahi_announce_interface(m->server, i); } else if (!b && i->announcing) { g_message("Interface %s.%i no longer relevant", i->hardware->name, i->protocol); - flx_goodbye_interface(m->server, i, FALSE); + avahi_goodbye_interface(m->server, i, FALSE); if (i->protocol == AF_INET) - flx_mdns_mcast_leave_ipv4 (i->hardware->index, m->server->fd_ipv4); + avahi_mdns_mcast_leave_ipv4 (i->hardware->index, m->server->fd_ipv4); if (i->protocol == AF_INET6) - flx_mdns_mcast_leave_ipv6 (i->hardware->index, m->server->fd_ipv6); + avahi_mdns_mcast_leave_ipv6 (i->hardware->index, m->server->fd_ipv6); i->announcing = FALSE; } } -static void check_hw_interface_relevant(flxInterfaceMonitor *m, flxHwInterface *hw) { - flxInterface *i; +static void check_hw_interface_relevant(AvahiInterfaceMonitor *m, AvahiHwInterface *hw) { + AvahiInterface *i; g_assert(m); g_assert(hw); @@ -198,8 +198,8 @@ static void check_hw_interface_relevant(flxInterfaceMonitor *m, flxHwInterface * check_interface_relevant(m, i); } -static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { - flxInterfaceMonitor *m = userdata; +static void callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata) { + AvahiInterfaceMonitor *m = userdata; g_assert(m); g_assert(n); @@ -207,7 +207,7 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { if (n->nlmsg_type == RTM_NEWLINK) { struct ifinfomsg *ifinfomsg = NLMSG_DATA(n); - flxHwInterface *hw; + AvahiHwInterface *hw; struct rtattr *a = NULL; size_t l; @@ -215,15 +215,15 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { return; if (!(hw = g_hash_table_lookup(m->hash_table, &ifinfomsg->ifi_index))) { - hw = g_new(flxHwInterface, 1); + hw = g_new(AvahiHwInterface, 1); hw->monitor = m; hw->name = NULL; hw->flags = 0; hw->mtu = 1500; hw->index = ifinfomsg->ifi_index; - FLX_LLIST_HEAD_INIT(flxInterface, hw->interfaces); - FLX_LLIST_PREPEND(flxHwInterface, hardware, m->hw_interfaces, hw); + AVAHI_LLIST_HEAD_INIT(AvahiInterface, hw->interfaces); + AVAHI_LLIST_PREPEND(AvahiHwInterface, hardware, m->hw_interfaces, hw); g_hash_table_insert(m->hash_table, &hw->index, hw); @@ -262,13 +262,13 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { } else if (n->nlmsg_type == RTM_DELLINK) { struct ifinfomsg *ifinfomsg = NLMSG_DATA(n); - flxHwInterface *hw; - flxInterface *i; + AvahiHwInterface *hw; + AvahiInterface *i; if (ifinfomsg->ifi_family != AF_UNSPEC) return; - if (!(hw = flx_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index))) + if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index))) return; update_hw_interface_rr(m, hw, TRUE); @@ -277,16 +277,16 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { } else if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) { struct ifaddrmsg *ifaddrmsg = NLMSG_DATA(n); - flxInterface *i; + AvahiInterface *i; struct rtattr *a = NULL; size_t l; - flxAddress raddr; + AvahiAddress raddr; int raddr_valid = 0; if (ifaddrmsg->ifa_family != AF_INET && ifaddrmsg->ifa_family != AF_INET6) return; - if (!(i = (flxInterface*) flx_interface_monitor_get_interface(m, ifaddrmsg->ifa_index, ifaddrmsg->ifa_family))) + if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, ifaddrmsg->ifa_index, ifaddrmsg->ifa_family))) return; raddr.family = ifaddrmsg->ifa_family; @@ -318,16 +318,16 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { return; if (n->nlmsg_type == RTM_NEWADDR) { - flxInterfaceAddress *addr; + AvahiInterfaceAddress *addr; if (!(addr = get_address(m, i, &raddr))) { - addr = g_new(flxInterfaceAddress, 1); + addr = g_new(AvahiInterfaceAddress, 1); addr->monitor = m; addr->address = raddr; addr->interface = i; addr->entry_group = NULL; - FLX_LLIST_PREPEND(flxInterfaceAddress, address, i->addresses, addr); + AVAHI_LLIST_PREPEND(AvahiInterfaceAddress, address, i->addresses, addr); } addr->flags = ifaddrmsg->ifa_flags; @@ -336,7 +336,7 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { update_address_rr(m, addr, FALSE); check_interface_relevant(m, i); } else { - flxInterfaceAddress *addr; + AvahiInterfaceAddress *addr; if (!(addr = get_address(m, i, &raddr))) return; @@ -369,18 +369,18 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { } } -flxInterfaceMonitor *flx_interface_monitor_new(flxServer *s) { - flxInterfaceMonitor *m = NULL; +AvahiInterfaceMonitor *avahi_interface_monitor_new(AvahiServer *s) { + AvahiInterfaceMonitor *m = NULL; - m = g_new0(flxInterfaceMonitor, 1); + m = g_new0(AvahiInterfaceMonitor, 1); m->server = s; - if (!(m->netlink = flx_netlink_new(s->context, G_PRIORITY_DEFAULT-10, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, callback, m))) + if (!(m->netlink = avahi_netlink_new(s->context, G_PRIORITY_DEFAULT-10, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, callback, m))) goto fail; m->hash_table = g_hash_table_new(g_int_hash, g_int_equal); - FLX_LLIST_HEAD_INIT(flxInterface, m->interfaces); - FLX_LLIST_HEAD_INIT(flxHwInterface, m->hw_interfaces); + AVAHI_LLIST_HEAD_INIT(AvahiInterface, m->interfaces); + AVAHI_LLIST_HEAD_INIT(AvahiHwInterface, m->hw_interfaces); if (netlink_list_items(m->netlink, RTM_GETLINK, &m->query_link_seq) < 0) goto fail; @@ -390,20 +390,20 @@ flxInterfaceMonitor *flx_interface_monitor_new(flxServer *s) { return m; fail: - flx_interface_monitor_free(m); + avahi_interface_monitor_free(m); return NULL; } -void flx_interface_monitor_sync(flxInterfaceMonitor *m) { +void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { g_assert(m); while (m->list != LIST_DONE) { - if (!flx_netlink_work(m->netlink, TRUE)) + if (!avahi_netlink_work(m->netlink, TRUE)) break; } } -void flx_interface_monitor_free(flxInterfaceMonitor *m) { +void avahi_interface_monitor_free(AvahiInterfaceMonitor *m) { g_assert(m); while (m->hw_interfaces) @@ -413,7 +413,7 @@ void flx_interface_monitor_free(flxInterfaceMonitor *m) { if (m->netlink) - flx_netlink_free(m->netlink); + avahi_netlink_free(m->netlink); if (m->hash_table) g_hash_table_destroy(m->hash_table); @@ -422,15 +422,15 @@ void flx_interface_monitor_free(flxInterfaceMonitor *m) { } -flxInterface* flx_interface_monitor_get_interface(flxInterfaceMonitor *m, gint index, guchar protocol) { - flxHwInterface *hw; - flxInterface *i; +AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, gint index, guchar protocol) { + AvahiHwInterface *hw; + AvahiInterface *i; g_assert(m); g_assert(index > 0); g_assert(protocol != AF_UNSPEC); - if (!(hw = flx_interface_monitor_get_hw_interface(m, index))) + if (!(hw = avahi_interface_monitor_get_hw_interface(m, index))) return NULL; for (i = hw->interfaces; i; i = i->by_hardware_next) @@ -440,7 +440,7 @@ flxInterface* flx_interface_monitor_get_interface(flxInterfaceMonitor *m, gint i return NULL; } -flxHwInterface* flx_interface_monitor_get_hw_interface(flxInterfaceMonitor *m, gint index) { +AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, gint index) { g_assert(m); g_assert(index > 0); @@ -448,59 +448,59 @@ flxHwInterface* flx_interface_monitor_get_hw_interface(flxInterfaceMonitor *m, g } -void flx_interface_send_packet(flxInterface *i, flxDnsPacket *p) { +void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p) { g_assert(i); g_assert(p); - if (flx_interface_relevant(i)) { + if (avahi_interface_relevant(i)) { g_message("sending on '%s.%i'", i->hardware->name, i->protocol); if (i->protocol == AF_INET && i->monitor->server->fd_ipv4 >= 0) - flx_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->hardware->index, p); + avahi_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->hardware->index, p); else if (i->protocol == AF_INET6 && i->monitor->server->fd_ipv6 >= 0) - flx_send_dns_packet_ipv6(i->monitor->server->fd_ipv6, i->hardware->index, p); + avahi_send_dns_packet_ipv6(i->monitor->server->fd_ipv6, i->hardware->index, p); } } -void flx_interface_post_query(flxInterface *i, flxKey *key, gboolean immediately) { +void avahi_interface_post_query(AvahiInterface *i, AvahiKey *key, gboolean immediately) { g_assert(i); g_assert(key); - if (flx_interface_relevant(i)) - flx_packet_scheduler_post_query(i->scheduler, key, immediately); + if (avahi_interface_relevant(i)) + avahi_packet_scheduler_post_query(i->scheduler, key, immediately); } -void flx_interface_post_response(flxInterface *i, const flxAddress *a, flxRecord *record, gboolean flush_cache, gboolean immediately) { +void avahi_interface_post_response(AvahiInterface *i, const AvahiAddress *a, AvahiRecord *record, gboolean flush_cache, gboolean immediately) { g_assert(i); g_assert(record); - if (flx_interface_relevant(i)) - flx_packet_scheduler_post_response(i->scheduler, a, record, flush_cache, immediately); + if (avahi_interface_relevant(i)) + avahi_packet_scheduler_post_response(i->scheduler, a, record, flush_cache, immediately); } -void flx_interface_post_probe(flxInterface *i, flxRecord *record, gboolean immediately) { +void avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *record, gboolean immediately) { g_assert(i); g_assert(record); - if (flx_interface_relevant(i)) - flx_packet_scheduler_post_probe(i->scheduler, record, immediately); + if (avahi_interface_relevant(i)) + avahi_packet_scheduler_post_probe(i->scheduler, record, immediately); } -void flx_dump_caches(flxInterfaceMonitor *m, FILE *f) { - flxInterface *i; +void avahi_dump_caches(AvahiInterfaceMonitor *m, FILE *f) { + AvahiInterface *i; g_assert(m); for (i = m->interfaces; i; i = i->interface_next) { - if (flx_interface_relevant(i)) { + if (avahi_interface_relevant(i)) { fprintf(f, "\n;;; INTERFACE %s.%i ;;;\n", i->hardware->name, i->protocol); - flx_cache_dump(i->cache, f); + avahi_cache_dump(i->cache, f); } } fprintf(f, "\n"); } -gboolean flx_interface_relevant(flxInterface *i) { +gboolean avahi_interface_relevant(AvahiInterface *i) { g_assert(i); return @@ -511,14 +511,14 @@ gboolean flx_interface_relevant(flxInterface *i) { i->addresses; } -gboolean flx_interface_address_relevant(flxInterfaceAddress *a) { +gboolean avahi_interface_address_relevant(AvahiInterfaceAddress *a) { g_assert(a); return a->scope == RT_SCOPE_UNIVERSE; } -gboolean flx_interface_match(flxInterface *i, gint index, guchar protocol) { +gboolean avahi_interface_match(AvahiInterface *i, gint index, guchar protocol) { g_assert(i); if (index > 0 && index != i->hardware->index) @@ -531,32 +531,32 @@ gboolean flx_interface_match(flxInterface *i, gint index, guchar protocol) { } -void flx_interface_monitor_walk(flxInterfaceMonitor *m, gint interface, guchar protocol, flxInterfaceMonitorWalkCallback callback, gpointer userdata) { +void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, gint interface, guchar protocol, AvahiInterfaceMonitorWalkCallback callback, gpointer userdata) { g_assert(m); g_assert(callback); if (interface > 0) { if (protocol != AF_UNSPEC) { - flxInterface *i; + AvahiInterface *i; - if ((i = flx_interface_monitor_get_interface(m, interface, protocol))) + if ((i = avahi_interface_monitor_get_interface(m, interface, protocol))) callback(m, i, userdata); } else { - flxHwInterface *hw; - flxInterface *i; + AvahiHwInterface *hw; + AvahiInterface *i; - if ((hw = flx_interface_monitor_get_hw_interface(m, interface))) + if ((hw = avahi_interface_monitor_get_hw_interface(m, interface))) for (i = hw->interfaces; i; i = i->by_hardware_next) - if (flx_interface_match(i, interface, protocol)) + if (avahi_interface_match(i, interface, protocol)) callback(m, i, userdata); } } else { - flxInterface *i; + AvahiInterface *i; for (i = m->interfaces; i; i = i->interface_next) - if (flx_interface_match(i, interface, protocol)) + if (avahi_interface_match(i, interface, protocol)) callback(m, i, userdata); } } @@ -3,10 +3,10 @@ #include <glib.h> -typedef struct _flxInterfaceMonitor flxInterfaceMonitor; -typedef struct _flxInterfaceAddress flxInterfaceAddress; -typedef struct _flxInterface flxInterface; -typedef struct _flxHwInterface flxHwInterface; +typedef struct _AvahiInterfaceMonitor AvahiInterfaceMonitor; +typedef struct _AvahiInterfaceAddress AvahiInterfaceAddress; +typedef struct _AvahiInterface AvahiInterface; +typedef struct _AvahiHwInterface AvahiHwInterface; #include "address.h" #include "server.h" @@ -17,13 +17,13 @@ typedef struct _flxHwInterface flxHwInterface; #include "dns.h" #include "announce.h" -struct _flxInterfaceMonitor { - flxServer *server; - flxNetlink *netlink; +struct _AvahiInterfaceMonitor { + AvahiServer *server; + AvahiNetlink *netlink; GHashTable *hash_table; - FLX_LLIST_HEAD(flxInterface, interfaces); - FLX_LLIST_HEAD(flxHwInterface, hw_interfaces); + AVAHI_LLIST_HEAD(AvahiInterface, interfaces); + AVAHI_LLIST_HEAD(AvahiHwInterface, hw_interfaces); guint query_addr_seq, query_link_seq; @@ -34,69 +34,69 @@ struct _flxInterfaceMonitor { } list; }; -struct _flxHwInterface { - FLX_LLIST_FIELDS(flxHwInterface, hardware); - flxInterfaceMonitor *monitor; +struct _AvahiHwInterface { + AVAHI_LLIST_FIELDS(AvahiHwInterface, hardware); + AvahiInterfaceMonitor *monitor; gchar *name; gint index; guint flags; guint mtu; - FLX_LLIST_HEAD(flxInterface, interfaces); + AVAHI_LLIST_HEAD(AvahiInterface, interfaces); }; -struct _flxInterface { - FLX_LLIST_FIELDS(flxInterface, interface); - FLX_LLIST_FIELDS(flxInterface, by_hardware); - flxInterfaceMonitor *monitor; +struct _AvahiInterface { + AVAHI_LLIST_FIELDS(AvahiInterface, interface); + AVAHI_LLIST_FIELDS(AvahiInterface, by_hardware); + AvahiInterfaceMonitor *monitor; - flxHwInterface *hardware; + AvahiHwInterface *hardware; guchar protocol; gboolean announcing; - flxCache *cache; - flxPacketScheduler *scheduler; + AvahiCache *cache; + AvahiPacketScheduler *scheduler; - FLX_LLIST_HEAD(flxInterfaceAddress, addresses); - FLX_LLIST_HEAD(flxAnnouncement, announcements); + AVAHI_LLIST_HEAD(AvahiInterfaceAddress, addresses); + AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements); }; -struct _flxInterfaceAddress { - FLX_LLIST_FIELDS(flxInterfaceAddress, address); - flxInterfaceMonitor *monitor; +struct _AvahiInterfaceAddress { + AVAHI_LLIST_FIELDS(AvahiInterfaceAddress, address); + AvahiInterfaceMonitor *monitor; guchar flags; guchar scope; - flxAddress address; + AvahiAddress address; - flxEntryGroup *entry_group; - flxInterface *interface; + AvahiEntryGroup *entry_group; + AvahiInterface *interface; }; -flxInterfaceMonitor *flx_interface_monitor_new(flxServer *server); -void flx_interface_monitor_free(flxInterfaceMonitor *m); +AvahiInterfaceMonitor *avahi_interface_monitor_new(AvahiServer *server); +void avahi_interface_monitor_free(AvahiInterfaceMonitor *m); -void flx_interface_monitor_sync(flxInterfaceMonitor *m); +void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m); -flxInterface* flx_interface_monitor_get_interface(flxInterfaceMonitor *m, gint index, guchar protocol); -flxHwInterface* flx_interface_monitor_get_hw_interface(flxInterfaceMonitor *m, gint index); +AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, gint index, guchar protocol); +AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, gint index); -void flx_interface_send_packet(flxInterface *i, flxDnsPacket *p); +void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p); -void flx_interface_post_query(flxInterface *i, flxKey *k, gboolean immediately); -void flx_interface_post_probe(flxInterface *i, flxRecord *p, gboolean immediately); -void flx_interface_post_response(flxInterface *i, const flxAddress *a, flxRecord *record, gboolean flush_cache, gboolean immediately); +void avahi_interface_post_query(AvahiInterface *i, AvahiKey *k, gboolean immediately); +void avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *p, gboolean immediately); +void avahi_interface_post_response(AvahiInterface *i, const AvahiAddress *a, AvahiRecord *record, gboolean flush_cache, gboolean immediately); -void flx_dump_caches(flxInterfaceMonitor *m, FILE *f); +void avahi_dump_caches(AvahiInterfaceMonitor *m, FILE *f); -gboolean flx_interface_relevant(flxInterface *i); -gboolean flx_interface_address_relevant(flxInterfaceAddress *a); +gboolean avahi_interface_relevant(AvahiInterface *i); +gboolean avahi_interface_address_relevant(AvahiInterfaceAddress *a); -gboolean flx_interface_match(flxInterface *i, gint index, guchar protocol); +gboolean avahi_interface_match(AvahiInterface *i, gint index, guchar protocol); -typedef void (*flxInterfaceMonitorWalkCallback)(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata); +typedef void (*AvahiInterfaceMonitorWalkCallback)(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata); -void flx_interface_monitor_walk(flxInterfaceMonitor *m, gint index, guchar protocol, flxInterfaceMonitorWalkCallback callback, gpointer userdata); +void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, gint index, guchar protocol, AvahiInterfaceMonitorWalkCallback callback, gpointer userdata); #endif @@ -7,23 +7,23 @@ /* The head of the linked list. Use this in the structure that shall * contain the head of the linked list */ -#define FLX_LLIST_HEAD(t,name) t *name +#define AVAHI_LLIST_HEAD(t,name) t *name /* The pointers in the linked list's items. Use this in the item structure */ -#define FLX_LLIST_FIELDS(t,name) t *name##_next, *name##_prev +#define AVAHI_LLIST_FIELDS(t,name) t *name##_next, *name##_prev /* Initialize the list's head */ -#define FLX_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0) +#define AVAHI_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0) /* Initialize a list item */ -#define FLX_LLIST_INIT(t,name,item) do { \ +#define AVAHI_LLIST_INIT(t,name,item) do { \ t *_item = (item); \ g_assert(_item); \ _item->name##_prev = _item->name##_next = NULL; \ } while(0) /* Prepend an item to the list */ -#define FLX_LLIST_PREPEND(t,name,head,item) do { \ +#define AVAHI_LLIST_PREPEND(t,name,head,item) do { \ t **_head = &(head), *_item = (item); \ g_assert(_item); \ if ((_item->name##_next = *_head)) \ @@ -33,7 +33,7 @@ } while (0) /* Remove an item from the list */ -#define FLX_LLIST_REMOVE(t,name,head,item) do { \ +#define AVAHI_LLIST_REMOVE(t,name,head,item) do { \ t **_head = &(head), *_item = (item); \ g_assert(_item); \ if (_item->name##_next) \ @@ -3,7 +3,7 @@ #include <arpa/inet.h> #include <stdlib.h> -#include "flx.h" +#include "Avahi.h" static gboolean quit_timeout(gpointer data) { g_main_loop_quit(data); @@ -11,12 +11,12 @@ static gboolean quit_timeout(gpointer data) { } static gboolean dump_timeout(gpointer data) { - flxServer *flx = data; - flx_server_dump(flx, stdout); + AvahiServer *Avahi = data; + avahi_server_dump(Avahi, stdout); return TRUE; } -static void subscription(flxSubscription *s, flxRecord *r, gint interface, guchar protocol, flxSubscriptionEvent event, gpointer userdata) { +static void subscription(AvahiSubscription *s, AvahiRecord *r, gint interface, guchar protocol, AvahiSubscriptionEvent event, gpointer userdata) { gchar *t; g_assert(s); @@ -24,51 +24,51 @@ static void subscription(flxSubscription *s, flxRecord *r, gint interface, gucha g_assert(interface > 0); g_assert(protocol != AF_UNSPEC); - g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = flx_record_to_string(r), interface, protocol, - event == FLX_SUBSCRIPTION_NEW ? "new" : (event == FLX_SUBSCRIPTION_CHANGE ? "changed" : "removed")); + g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = avahi_record_to_string(r), interface, protocol, + event == AVAHI_SUBSCRIPTION_NEW ? "new" : (event == AVAHI_SUBSCRIPTION_CHANGE ? "changed" : "removed")); g_free(t); } -static void entry_group_callback(flxServer *s, flxEntryGroup *g, flxEntryGroupState state, gpointer userdata) { +static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) { g_message("entry group state: %i", state); } int main(int argc, char *argv[]) { - flxServer *flx; + AvahiServer *Avahi; gchar *r; GMainLoop *loop = NULL; - flxSubscription *s; - flxKey *k; - flxEntryGroup *g; + AvahiSubscription *s; + AvahiKey *k; + AvahiEntryGroup *g; - flx = flx_server_new(NULL); + Avahi = avahi_server_new(NULL); -/* g = flx_entry_group_new(flx, entry_group_callback, NULL); */ +/* g = avahi_entry_group_new(Avahi, entry_group_callback, NULL); */ -/* flx_server_add_text(flx, g, 0, AF_UNSPEC, FLX_ENTRY_UNIQUE, NULL, "hallo", NULL); */ -/* flx_server_add_service(flx, g, 0, AF_UNSPEC, "_http._tcp", "gurke", NULL, NULL, 80, "foo", NULL); */ +/* avahi_server_add_text(Avahi, g, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, NULL, "hallo", NULL); */ +/* avahi_server_add_service(Avahi, g, 0, AF_UNSPEC, "_http._tcp", "gurke", NULL, NULL, 80, "foo", NULL); */ -/* flx_entry_group_commit(g); */ +/* avahi_entry_group_commit(g); */ - flx_server_dump(flx, stdout); + avahi_server_dump(Avahi, stdout); -/* k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_ANY); */ -/* s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL); */ -/* flx_key_unref(k); */ +/* k = avahi_key_new("ecstasy.local.", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_ANY); */ +/* s = avahi_subscription_new(Avahi, k, 0, AF_UNSPEC, subscription, NULL); */ +/* avahi_key_unref(k); */ loop = g_main_loop_new(NULL, FALSE); - /* g_timeout_add(1000*20, dump_timeout, flx); */ + /* g_timeout_add(1000*20, dump_timeout, Avahi); */ /* g_timeout_add(1000*30, quit_timeout, loop); */ g_main_loop_run(loop); g_main_loop_unref(loop); -/* flx_subscription_free(s); */ - /* flx_entry_group_free(g); */ - flx_server_free(flx); +/* avahi_subscription_free(s); */ + /* avahi_entry_group_free(g); */ + avahi_server_free(Avahi); return 0; } @@ -4,17 +4,17 @@ #include "netlink.h" -struct _flxNetlink { +struct _AvahiNetlink { GMainContext *context; gint fd; guint seq; GPollFD poll_fd; GSource *source; - void (*callback) (flxNetlink *nl, struct nlmsghdr *n, gpointer userdata); + void (*callback) (AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata); gpointer userdata; }; -gboolean flx_netlink_work(flxNetlink *nl, gboolean block) { +gboolean avahi_netlink_work(AvahiNetlink *nl, gboolean block) { g_assert(nl); for (;;) { @@ -58,29 +58,29 @@ static gboolean prepare_func(GSource *source, gint *timeout) { } static gboolean check_func(GSource *source) { - flxNetlink* nl; + AvahiNetlink* nl; g_assert(source); - nl = *((flxNetlink**) (((guint8*) source) + sizeof(GSource))); + nl = *((AvahiNetlink**) (((guint8*) source) + sizeof(GSource))); g_assert(nl); return nl->poll_fd.revents & (G_IO_IN|G_IO_HUP|G_IO_ERR); } static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer user_data) { - flxNetlink* nl; + AvahiNetlink* nl; g_assert(source); - nl = *((flxNetlink**) (((guint8*) source) + sizeof(GSource))); + nl = *((AvahiNetlink**) (((guint8*) source) + sizeof(GSource))); g_assert(nl); - return flx_netlink_work(nl, FALSE); + return avahi_netlink_work(nl, FALSE); } -flxNetlink *flx_netlink_new(GMainContext *context, gint priority, guint32 groups, void (*cb) (flxNetlink *nl, struct nlmsghdr *n, gpointer userdata), gpointer userdata) { +AvahiNetlink *avahi_netlink_new(GMainContext *context, gint priority, guint32 groups, void (*cb) (AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata), gpointer userdata) { int fd; struct sockaddr_nl addr; - flxNetlink *nl; + AvahiNetlink *nl; static GSourceFuncs source_funcs = { prepare_func, @@ -110,7 +110,7 @@ flxNetlink *flx_netlink_new(GMainContext *context, gint priority, guint32 groups return NULL; } - nl = g_new(flxNetlink, 1); + nl = g_new(AvahiNetlink, 1); nl->context = context; g_main_context_ref(context); nl->fd = fd; @@ -118,8 +118,8 @@ flxNetlink *flx_netlink_new(GMainContext *context, gint priority, guint32 groups nl->callback = cb; nl->userdata = userdata; - nl->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(flxNetlink*)); - *((flxNetlink**) (((guint8*) nl->source) + sizeof(GSource))) = nl; + nl->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(AvahiNetlink*)); + *((AvahiNetlink**) (((guint8*) nl->source) + sizeof(GSource))) = nl; g_source_set_priority(nl->source, priority); @@ -133,7 +133,7 @@ flxNetlink *flx_netlink_new(GMainContext *context, gint priority, guint32 groups return nl; } -void flx_netlink_free(flxNetlink *nl) { +void avahi_netlink_free(AvahiNetlink *nl) { g_assert(nl); g_source_destroy(nl->source); @@ -143,7 +143,7 @@ void flx_netlink_free(flxNetlink *nl) { g_free(nl); } -int flx_netlink_send(flxNetlink *nl, struct nlmsghdr *m, guint *ret_seq) { +int avahi_netlink_send(AvahiNetlink *nl, struct nlmsghdr *m, guint *ret_seq) { g_assert(nl); g_assert(m); @@ -7,14 +7,14 @@ #include <glib.h> -struct _flxNetlink; -typedef struct _flxNetlink flxNetlink; +struct _AvahiNetlink; +typedef struct _AvahiNetlink AvahiNetlink; -flxNetlink *flx_netlink_new(GMainContext *c, gint priority, guint32 groups, void (*cb) (flxNetlink *n, struct nlmsghdr *m, gpointer userdata), gpointer userdata); -void flx_netlink_free(flxNetlink *n); +AvahiNetlink *avahi_netlink_new(GMainContext *c, gint priority, guint32 groups, void (*cb) (AvahiNetlink *n, struct nlmsghdr *m, gpointer userdata), gpointer userdata); +void avahi_netlink_free(AvahiNetlink *n); -int flx_netlink_send(flxNetlink *n, struct nlmsghdr *m, guint *ret_seq); +int avahi_netlink_send(AvahiNetlink *n, struct nlmsghdr *m, guint *ret_seq); -gboolean flx_netlink_work(flxNetlink *n, gboolean block); +gboolean avahi_netlink_work(AvahiNetlink *n, gboolean block); #endif diff --git a/prioq-test.c b/prioq-test.c index d8640c1..53a8383 100644 --- a/prioq-test.c +++ b/prioq-test.c @@ -14,7 +14,7 @@ static int compare_ptr(gconstpointer a, gconstpointer b) { return a < b ? -1 : (a > b ? 1 : 0); } -static void rec(flxPrioQueueNode *n) { +static void rec(AvahiPrioQueueNode *n) { if (!n) return; @@ -52,16 +52,16 @@ static void rec(flxPrioQueueNode *n) { } int main(int argc, char *argv[]) { - flxPrioQueue *q, *q2; + AvahiPrioQueue *q, *q2; gint i, prev; - q = flx_prio_queue_new(compare_int); - q2 = flx_prio_queue_new(compare_ptr); + q = avahi_prio_queue_new(compare_int); + q2 = avahi_prio_queue_new(compare_ptr); srand(time(NULL)); for (i = 0; i < 10000; i++) - flx_prio_queue_put(q2, flx_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF))); + avahi_prio_queue_put(q2, avahi_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF))); while (q2->root) { rec(q->root); @@ -69,10 +69,10 @@ int main(int argc, char *argv[]) { g_assert(q->n_nodes == q2->n_nodes); - printf("%i\n", GPOINTER_TO_INT(((flxPrioQueueNode*)q2->root->data)->data)); + printf("%i\n", GPOINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data)); - flx_prio_queue_remove(q, q2->root->data); - flx_prio_queue_remove(q2, q2->root); + avahi_prio_queue_remove(q, q2->root->data); + avahi_prio_queue_remove(q2, q2->root); } @@ -81,11 +81,11 @@ int main(int argc, char *argv[]) { /* gint v = GPOINTER_TO_INT(q->root->data); */ /* rec(q->root); */ /* printf("%i\n", v); */ -/* flx_prio_queue_remove(q, q->root); */ +/* avahi_prio_queue_remove(q, q->root); */ /* g_assert(v >= prev); */ /* prev = v; */ /* } */ - flx_prio_queue_free(q); + avahi_prio_queue_free(q); return 0; } @@ -1,29 +1,29 @@ #include "prioq.h" -flxPrioQueue* flx_prio_queue_new(gint (*compare) (gconstpointer a, gconstpointer b)) { - flxPrioQueue *q; +AvahiPrioQueue* avahi_prio_queue_new(gint (*compare) (gconstpointer a, gconstpointer b)) { + AvahiPrioQueue *q; g_assert(compare); - q = g_new(flxPrioQueue, 1); + q = g_new(AvahiPrioQueue, 1); q->root = q->last = NULL; q->n_nodes = 0; q->compare = compare; return q; } -void flx_prio_queue_free(flxPrioQueue *q) { +void avahi_prio_queue_free(AvahiPrioQueue *q) { g_assert(q); while (q->last) - flx_prio_queue_remove(q, q->last); + avahi_prio_queue_remove(q, q->last); g_assert(!q->n_nodes); g_free(q); } -static flxPrioQueueNode* get_node_at_xy(flxPrioQueue *q, guint x, guint y) { +static AvahiPrioQueueNode* get_node_at_xy(AvahiPrioQueue *q, guint x, guint y) { guint r; - flxPrioQueueNode *n; + AvahiPrioQueueNode *n; g_assert(q); n = q->root; @@ -44,8 +44,8 @@ static flxPrioQueueNode* get_node_at_xy(flxPrioQueue *q, guint x, guint y) { return n; } -static void exchange_nodes(flxPrioQueue *q, flxPrioQueueNode *a, flxPrioQueueNode *b) { - flxPrioQueueNode *l, *r, *p, *ap, *an, *bp, *bn; +static void exchange_nodes(AvahiPrioQueue *q, AvahiPrioQueueNode *a, AvahiPrioQueueNode *b) { + AvahiPrioQueueNode *l, *r, *p, *ap, *an, *bp, *bn; gint t; g_assert(q); g_assert(a); @@ -128,7 +128,7 @@ static void exchange_nodes(flxPrioQueue *q, flxPrioQueueNode *a, flxPrioQueueNod b->left->parent = b; } } else { - flxPrioQueueNode *apl = NULL, *bpl = NULL; + AvahiPrioQueueNode *apl = NULL, *bpl = NULL; /* Swap parents */ ap = a->parent; @@ -224,7 +224,7 @@ static void exchange_nodes(flxPrioQueue *q, flxPrioQueueNode *a, flxPrioQueueNod } /* Move a node to the correct position */ -void flx_prio_queue_shuffle(flxPrioQueue *q, flxPrioQueueNode *n) { +void avahi_prio_queue_shuffle(AvahiPrioQueue *q, AvahiPrioQueueNode *n) { g_assert(q); g_assert(n); @@ -234,7 +234,7 @@ void flx_prio_queue_shuffle(flxPrioQueue *q, flxPrioQueueNode *n) { /* Move down until the position is OK */ for (;;) { - flxPrioQueueNode *min; + AvahiPrioQueueNode *min; if (!(min = n->left)) { /* No children */ @@ -255,11 +255,11 @@ void flx_prio_queue_shuffle(flxPrioQueue *q, flxPrioQueueNode *n) { } } -flxPrioQueueNode* flx_prio_queue_put(flxPrioQueue *q, gpointer data) { - flxPrioQueueNode *n; +AvahiPrioQueueNode* avahi_prio_queue_put(AvahiPrioQueue *q, gpointer data) { + AvahiPrioQueueNode *n; g_assert(q); - n = g_new(flxPrioQueueNode, 1); + n = g_new(AvahiPrioQueueNode, 1); n->queue = q; n->data = data; @@ -298,20 +298,20 @@ flxPrioQueueNode* flx_prio_queue_put(flxPrioQueue *q, gpointer data) { q->last = n; q->n_nodes++; - flx_prio_queue_shuffle(q, n); + avahi_prio_queue_shuffle(q, n); return n; } -void flx_prio_queue_remove(flxPrioQueue *q, flxPrioQueueNode *n) { +void avahi_prio_queue_remove(AvahiPrioQueue *q, AvahiPrioQueueNode *n) { g_assert(q); g_assert(n); if (n != q->last) { - flxPrioQueueNode *replacement = q->last; + AvahiPrioQueueNode *replacement = q->last; exchange_nodes(q, replacement, n); - flx_prio_queue_remove(q, n); - flx_prio_queue_shuffle(q, replacement); + avahi_prio_queue_remove(q, n); + avahi_prio_queue_shuffle(q, replacement); return; } @@ -3,33 +3,33 @@ #include <glib.h> -struct _flxPrioQueue; -typedef struct _flxPrioQueue flxPrioQueue; +struct _AvahiPrioQueue; +typedef struct _AvahiPrioQueue AvahiPrioQueue; -struct _flxPrioQueueNode; -typedef struct _flxPrioQueueNode flxPrioQueueNode; +struct _AvahiPrioQueueNode; +typedef struct _AvahiPrioQueueNode AvahiPrioQueueNode; -struct _flxPrioQueue { - flxPrioQueueNode *root, *last; +struct _AvahiPrioQueue { + AvahiPrioQueueNode *root, *last; guint n_nodes; gint (*compare) (gconstpointer a, gconstpointer b); }; -struct _flxPrioQueueNode { - flxPrioQueue *queue; +struct _AvahiPrioQueueNode { + AvahiPrioQueue *queue; gpointer data; guint x, y; - flxPrioQueueNode *left, *right, *parent, *next, *prev; + AvahiPrioQueueNode *left, *right, *parent, *next, *prev; }; -flxPrioQueue* flx_prio_queue_new(gint (*compare) (gconstpointer a, gconstpointer b)); -void flx_prio_queue_free(flxPrioQueue *q); +AvahiPrioQueue* avahi_prio_queue_new(gint (*compare) (gconstpointer a, gconstpointer b)); +void avahi_prio_queue_free(AvahiPrioQueue *q); -flxPrioQueueNode* flx_prio_queue_put(flxPrioQueue *q, gpointer data); -void flx_prio_queue_remove(flxPrioQueue *q, flxPrioQueueNode *n); +AvahiPrioQueueNode* avahi_prio_queue_put(AvahiPrioQueue *q, gpointer data); +void avahi_prio_queue_remove(AvahiPrioQueue *q, AvahiPrioQueueNode *n); -void flx_prio_queue_shuffle(flxPrioQueue *q, flxPrioQueueNode *n); +void avahi_prio_queue_shuffle(AvahiPrioQueue *q, AvahiPrioQueueNode *n); #endif @@ -3,72 +3,72 @@ #include "util.h" #include "psched.h" -#define FLX_QUERY_HISTORY_MSEC 100 -#define FLX_QUERY_DEFER_MSEC 100 -#define FLX_RESPONSE_HISTORY_MSEC 700 -#define FLX_RESPONSE_DEFER_MSEC 20 -#define FLX_RESPONSE_JITTER_MSEC 100 -#define FLX_PROBE_DEFER_MSEC 70 +#define AVAHI_QUERY_HISTORY_MSEC 100 +#define AVAHI_QUERY_DEFER_MSEC 100 +#define AVAHI_RESPONSE_HISTORY_MSEC 700 +#define AVAHI_RESPONSE_DEFER_MSEC 20 +#define AVAHI_RESPONSE_JITTER_MSEC 100 +#define AVAHI_PROBE_DEFER_MSEC 70 -flxPacketScheduler *flx_packet_scheduler_new(flxServer *server, flxInterface *i) { - flxPacketScheduler *s; +AvahiPacketScheduler *avahi_packet_scheduler_new(AvahiServer *server, AvahiInterface *i) { + AvahiPacketScheduler *s; g_assert(server); g_assert(i); - s = g_new(flxPacketScheduler, 1); + s = g_new(AvahiPacketScheduler, 1); s->server = server; s->interface = i; - FLX_LLIST_HEAD_INIT(flxQueryJob, s->query_jobs); - FLX_LLIST_HEAD_INIT(flxResponseJob, s->response_jobs); - FLX_LLIST_HEAD_INIT(flxKnownAnswer, s->known_answers); - FLX_LLIST_HEAD_INIT(flxProbeJob, s->probe_jobs); + AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->query_jobs); + AVAHI_LLIST_HEAD_INIT(AvahiResponseJob, s->response_jobs); + AVAHI_LLIST_HEAD_INIT(AvahiKnownAnswer, s->known_answers); + AVAHI_LLIST_HEAD_INIT(AvahiProbeJob, s->probe_jobs); return s; } -static void query_job_free(flxPacketScheduler *s, flxQueryJob *qj) { +static void query_job_free(AvahiPacketScheduler *s, AvahiQueryJob *qj) { g_assert(qj); if (qj->time_event) - flx_time_event_queue_remove(qj->scheduler->server->time_event_queue, qj->time_event); + avahi_time_event_queue_remove(qj->scheduler->server->time_event_queue, qj->time_event); - FLX_LLIST_REMOVE(flxQueryJob, jobs, s->query_jobs, qj); + AVAHI_LLIST_REMOVE(AvahiQueryJob, jobs, s->query_jobs, qj); - flx_key_unref(qj->key); + avahi_key_unref(qj->key); g_free(qj); } -static void response_job_free(flxPacketScheduler *s, flxResponseJob *rj) { +static void response_job_free(AvahiPacketScheduler *s, AvahiResponseJob *rj) { g_assert(rj); if (rj->time_event) - flx_time_event_queue_remove(rj->scheduler->server->time_event_queue, rj->time_event); + avahi_time_event_queue_remove(rj->scheduler->server->time_event_queue, rj->time_event); - FLX_LLIST_REMOVE(flxResponseJob, jobs, s->response_jobs, rj); + AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->response_jobs, rj); - flx_record_unref(rj->record); + avahi_record_unref(rj->record); g_free(rj); } -static void probe_job_free(flxPacketScheduler *s, flxProbeJob *pj) { +static void probe_job_free(AvahiPacketScheduler *s, AvahiProbeJob *pj) { g_assert(pj); if (pj->time_event) - flx_time_event_queue_remove(pj->scheduler->server->time_event_queue, pj->time_event); + avahi_time_event_queue_remove(pj->scheduler->server->time_event_queue, pj->time_event); - FLX_LLIST_REMOVE(flxProbeJob, jobs, s->probe_jobs, pj); + AVAHI_LLIST_REMOVE(AvahiProbeJob, jobs, s->probe_jobs, pj); - flx_record_unref(pj->record); + avahi_record_unref(pj->record); g_free(pj); } -void flx_packet_scheduler_free(flxPacketScheduler *s) { - flxQueryJob *qj; - flxResponseJob *rj; - flxProbeJob *pj; - flxTimeEvent *e; +void avahi_packet_scheduler_free(AvahiPacketScheduler *s) { + AvahiQueryJob *qj; + AvahiResponseJob *rj; + AvahiProbeJob *pj; + AvahiTimeEvent *e; g_assert(s); @@ -84,53 +84,53 @@ void flx_packet_scheduler_free(flxPacketScheduler *s) { g_free(s); } -static gpointer known_answer_walk_callback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata) { - flxPacketScheduler *s = userdata; - flxKnownAnswer *ka; +static gpointer known_answer_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, gpointer userdata) { + AvahiPacketScheduler *s = userdata; + AvahiKnownAnswer *ka; g_assert(c); g_assert(pattern); g_assert(e); g_assert(s); - if (flx_cache_entry_half_ttl(c, e)) + if (avahi_cache_entry_half_ttl(c, e)) return NULL; - ka = g_new0(flxKnownAnswer, 1); + ka = g_new0(AvahiKnownAnswer, 1); ka->scheduler = s; - ka->record = flx_record_ref(e->record); + ka->record = avahi_record_ref(e->record); - FLX_LLIST_PREPEND(flxKnownAnswer, known_answer, s->known_answers, ka); + AVAHI_LLIST_PREPEND(AvahiKnownAnswer, known_answer, s->known_answers, ka); return NULL; } -static guint8* packet_add_query_job(flxPacketScheduler *s, flxDnsPacket *p, flxQueryJob *qj) { +static guint8* packet_add_query_job(AvahiPacketScheduler *s, AvahiDnsPacket *p, AvahiQueryJob *qj) { guint8 *d; g_assert(s); g_assert(p); g_assert(qj); - if ((d = flx_dns_packet_append_key(p, qj->key, FALSE))) { + if ((d = avahi_dns_packet_append_key(p, qj->key, FALSE))) { GTimeVal tv; qj->done = 1; /* Drop query after some time from history */ - flx_elapse_time(&tv, FLX_QUERY_HISTORY_MSEC, 0); - flx_time_event_queue_update(s->server->time_event_queue, qj->time_event, &tv); + avahi_elapse_time(&tv, AVAHI_QUERY_HISTORY_MSEC, 0); + avahi_time_event_queue_update(s->server->time_event_queue, qj->time_event, &tv); g_get_current_time(&qj->delivery); /* Add all matching known answers to the list */ - flx_cache_walk(s->interface->cache, qj->key, known_answer_walk_callback, s); + avahi_cache_walk(s->interface->cache, qj->key, known_answer_walk_callback, s); } return d; } -static void append_known_answers_and_send(flxPacketScheduler *s, flxDnsPacket *p) { - flxKnownAnswer *ka; +static void append_known_answers_and_send(AvahiPacketScheduler *s, AvahiDnsPacket *p) { + AvahiKnownAnswer *ka; guint n; g_assert(s); g_assert(p); @@ -139,35 +139,35 @@ static void append_known_answers_and_send(flxPacketScheduler *s, flxDnsPacket *p while ((ka = s->known_answers)) { - while (!flx_dns_packet_append_record(p, ka->record, FALSE)) { + while (!avahi_dns_packet_append_record(p, ka->record, FALSE)) { - g_assert(!flx_dns_packet_is_empty(p)); + g_assert(!avahi_dns_packet_is_empty(p)); - flx_dns_packet_set_field(p, FLX_DNS_FIELD_FLAGS, flx_dns_packet_get_field(p, FLX_DNS_FIELD_FLAGS) | FLX_DNS_FLAG_TC); - flx_dns_packet_set_field(p, FLX_DNS_FIELD_ANCOUNT, n); - flx_interface_send_packet(s->interface, p); - flx_dns_packet_free(p); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) | AVAHI_DNS_FLAG_TC); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n); + avahi_interface_send_packet(s->interface, p); + avahi_dns_packet_free(p); - p = flx_dns_packet_new_query(s->interface->hardware->mtu - 48); + p = avahi_dns_packet_new_query(s->interface->hardware->mtu - 48); n = 0; } - FLX_LLIST_REMOVE(flxKnownAnswer, known_answer, s->known_answers, ka); - flx_record_unref(ka->record); + AVAHI_LLIST_REMOVE(AvahiKnownAnswer, known_answer, s->known_answers, ka); + avahi_record_unref(ka->record); g_free(ka); n++; } - flx_dns_packet_set_field(p, FLX_DNS_FIELD_ANCOUNT, n); - flx_interface_send_packet(s->interface, p); - flx_dns_packet_free(p); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n); + avahi_interface_send_packet(s->interface, p); + avahi_dns_packet_free(p); } -static void query_elapse(flxTimeEvent *e, gpointer data) { - flxQueryJob *qj = data; - flxPacketScheduler *s; - flxDnsPacket *p; +static void query_elapse(AvahiTimeEvent *e, gpointer data) { + AvahiQueryJob *qj = data; + AvahiPacketScheduler *s; + AvahiDnsPacket *p; guint n; guint8 *d; @@ -182,7 +182,7 @@ static void query_elapse(flxTimeEvent *e, gpointer data) { g_assert(!s->known_answers); - p = flx_dns_packet_new_query(s->interface->hardware->mtu - 48); + p = avahi_dns_packet_new_query(s->interface->hardware->mtu - 48); d = packet_add_query_job(s, p, qj); g_assert(d); n = 1; @@ -199,46 +199,46 @@ static void query_elapse(flxTimeEvent *e, gpointer data) { n++; } - flx_dns_packet_set_field(p, FLX_DNS_FIELD_QDCOUNT, n); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_QDCOUNT, n); /* Now add known answers */ append_known_answers_and_send(s, p); } -flxQueryJob* query_job_new(flxPacketScheduler *s, flxKey *key) { - flxQueryJob *qj; +AvahiQueryJob* query_job_new(AvahiPacketScheduler *s, AvahiKey *key) { + AvahiQueryJob *qj; g_assert(s); g_assert(key); - qj = g_new(flxQueryJob, 1); + qj = g_new(AvahiQueryJob, 1); qj->scheduler = s; - qj->key = flx_key_ref(key); + qj->key = avahi_key_ref(key); qj->done = FALSE; qj->time_event = NULL; - FLX_LLIST_PREPEND(flxQueryJob, jobs, s->query_jobs, qj); + AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->query_jobs, qj); return qj; } -void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key, gboolean immediately) { +void avahi_packet_scheduler_post_query(AvahiPacketScheduler *s, AvahiKey *key, gboolean immediately) { GTimeVal tv; - flxQueryJob *qj; + AvahiQueryJob *qj; g_assert(s); g_assert(key); - flx_elapse_time(&tv, immediately ? 0 : FLX_QUERY_DEFER_MSEC, 0); + avahi_elapse_time(&tv, immediately ? 0 : AVAHI_QUERY_DEFER_MSEC, 0); for (qj = s->query_jobs; qj; qj = qj->jobs_next) { - if (flx_key_equal(qj->key, key)) { + if (avahi_key_equal(qj->key, key)) { - glong d = flx_timeval_diff(&tv, &qj->delivery); + glong d = avahi_timeval_diff(&tv, &qj->delivery); /* Duplicate questions suppression */ - if (d >= 0 && d <= FLX_QUERY_HISTORY_MSEC*1000) { + if (d >= 0 && d <= AVAHI_QUERY_HISTORY_MSEC*1000) { g_message("WARNING! DUPLICATE QUERY SUPPRESSION ACTIVE!"); return; } @@ -251,24 +251,24 @@ void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key, gboolea qj = query_job_new(s, key); qj->delivery = tv; - qj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &qj->delivery, query_elapse, qj); + qj->time_event = avahi_time_event_queue_add(s->server->time_event_queue, &qj->delivery, query_elapse, qj); } -static guint8* packet_add_response_job(flxPacketScheduler *s, flxDnsPacket *p, flxResponseJob *rj) { +static guint8* packet_add_response_job(AvahiPacketScheduler *s, AvahiDnsPacket *p, AvahiResponseJob *rj) { guint8 *d; g_assert(s); g_assert(p); g_assert(rj); - if ((d = flx_dns_packet_append_record(p, rj->record, rj->flush_cache))) { + if ((d = avahi_dns_packet_append_record(p, rj->record, rj->flush_cache))) { GTimeVal tv; rj->done = 1; /* Drop response after some time from history */ - flx_elapse_time(&tv, FLX_RESPONSE_HISTORY_MSEC, 0); - flx_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv); + avahi_elapse_time(&tv, AVAHI_RESPONSE_HISTORY_MSEC, 0); + avahi_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv); g_get_current_time(&rj->delivery); } @@ -276,13 +276,13 @@ static guint8* packet_add_response_job(flxPacketScheduler *s, flxDnsPacket *p, f return d; } -static void send_response_packet(flxPacketScheduler *s, flxResponseJob *rj) { - flxDnsPacket *p; +static void send_response_packet(AvahiPacketScheduler *s, AvahiResponseJob *rj) { + AvahiDnsPacket *p; guint n; g_assert(s); - p = flx_dns_packet_new_response(s->interface->hardware->mtu - 200); + p = avahi_dns_packet_new_response(s->interface->hardware->mtu - 200); n = 0; /* If a job was specified, put it in the packet. */ @@ -305,14 +305,14 @@ static void send_response_packet(flxPacketScheduler *s, flxResponseJob *rj) { n++; } - flx_dns_packet_set_field(p, FLX_DNS_FIELD_ANCOUNT, n); - flx_interface_send_packet(s->interface, p); - flx_dns_packet_free(p); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n); + avahi_interface_send_packet(s->interface, p); + avahi_dns_packet_free(p); } -static void response_elapse(flxTimeEvent *e, gpointer data) { - flxResponseJob *rj = data; - flxPacketScheduler *s; +static void response_elapse(AvahiTimeEvent *e, gpointer data) { + AvahiResponseJob *rj = data; + AvahiPacketScheduler *s; g_assert(rj); s = rj->scheduler; @@ -326,68 +326,68 @@ static void response_elapse(flxTimeEvent *e, gpointer data) { send_response_packet(s, rj); } -static flxResponseJob* look_for_response(flxPacketScheduler *s, flxRecord *record) { - flxResponseJob *rj; +static AvahiResponseJob* look_for_response(AvahiPacketScheduler *s, AvahiRecord *record) { + AvahiResponseJob *rj; g_assert(s); g_assert(record); for (rj = s->response_jobs; rj; rj = rj->jobs_next) - if (flx_record_equal_no_ttl(rj->record, record)) + if (avahi_record_equal_no_ttl(rj->record, record)) return rj; return NULL; } -static flxResponseJob* response_job_new(flxPacketScheduler *s, flxRecord *record) { - flxResponseJob *rj; +static AvahiResponseJob* response_job_new(AvahiPacketScheduler *s, AvahiRecord *record) { + AvahiResponseJob *rj; g_assert(s); g_assert(record); - rj = g_new(flxResponseJob, 1); + rj = g_new(AvahiResponseJob, 1); rj->scheduler = s; - rj->record = flx_record_ref(record); + rj->record = avahi_record_ref(record); rj->done = FALSE; rj->time_event = NULL; rj->address_valid = FALSE; rj->flush_cache = FALSE; - FLX_LLIST_PREPEND(flxResponseJob, jobs, s->response_jobs, rj); + AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->response_jobs, rj); return rj; } -void flx_packet_scheduler_post_response(flxPacketScheduler *s, const flxAddress *a, flxRecord *record, gboolean flush_cache, gboolean immediately) { - flxResponseJob *rj; +void avahi_packet_scheduler_post_response(AvahiPacketScheduler *s, const AvahiAddress *a, AvahiRecord *record, gboolean flush_cache, gboolean immediately) { + AvahiResponseJob *rj; GTimeVal tv; gchar *t; g_assert(s); g_assert(record); - g_assert(!flx_key_is_pattern(record->key)); + g_assert(!avahi_key_is_pattern(record->key)); - flx_elapse_time(&tv, immediately ? 0 : FLX_RESPONSE_DEFER_MSEC, immediately ? 0 : FLX_RESPONSE_JITTER_MSEC); + avahi_elapse_time(&tv, immediately ? 0 : AVAHI_RESPONSE_DEFER_MSEC, immediately ? 0 : AVAHI_RESPONSE_JITTER_MSEC); /* Don't send out duplicates */ if ((rj = look_for_response(s, record))) { glong d; - d = flx_timeval_diff(&tv, &rj->delivery); + d = avahi_timeval_diff(&tv, &rj->delivery); /* If there's already a matching packet in our history or in * the schedule, we do nothing. */ if (!!record->ttl == !!rj->record->ttl && - d >= 0 && d <= FLX_RESPONSE_HISTORY_MSEC*1000) { + d >= 0 && d <= AVAHI_RESPONSE_HISTORY_MSEC*1000) { g_message("WARNING! DUPLICATE RESPONSE SUPPRESSION ACTIVE!"); /* This job is no longer specific to a single querier, so * make sure it isn't suppressed by known answer * suppresion */ - if (rj->address_valid && (!a || flx_address_cmp(a, &rj->address) != 0)) + if (rj->address_valid && (!a || avahi_address_cmp(a, &rj->address) != 0)) rj->address_valid = FALSE; rj->flush_cache = flush_cache; @@ -400,14 +400,14 @@ void flx_packet_scheduler_post_response(flxPacketScheduler *s, const flxAddress response_job_free(s, rj); } -/* g_message("ACCEPTED NEW RESPONSE [%s]", t = flx_record_to_string(record)); */ +/* g_message("ACCEPTED NEW RESPONSE [%s]", t = avahi_record_to_string(record)); */ /* g_free(t); */ /* Create a new job and schedule it */ rj = response_job_new(s, record); rj->flush_cache = flush_cache; rj->delivery = tv; - rj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &rj->delivery, response_elapse, rj); + rj->time_event = avahi_time_event_queue_add(s->server->time_event_queue, &rj->delivery, response_elapse, rj); /* Store the address of the host this messages is intended to, so that we can drop this job in case a truncated message with @@ -417,9 +417,9 @@ void flx_packet_scheduler_post_response(flxPacketScheduler *s, const flxAddress rj->address = *a; } -void flx_packet_scheduler_incoming_query(flxPacketScheduler *s, flxKey *key) { +void avahi_packet_scheduler_incoming_query(AvahiPacketScheduler *s, AvahiKey *key) { GTimeVal tv; - flxQueryJob *qj; + AvahiQueryJob *qj; g_assert(s); g_assert(key); @@ -429,7 +429,7 @@ void flx_packet_scheduler_incoming_query(flxPacketScheduler *s, flxKey *key) { * keyword is "DUPLICATE QUESTION SUPPRESION". */ for (qj = s->query_jobs; qj; qj = qj->jobs_next) - if (flx_key_equal(qj->key, key)) { + if (avahi_key_equal(qj->key, key)) { if (qj->done) return; @@ -445,29 +445,29 @@ mark_done: qj->done = TRUE; /* Drop the query after some time */ - flx_elapse_time(&tv, FLX_QUERY_HISTORY_MSEC, 0); - qj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, query_elapse, qj); + avahi_elapse_time(&tv, AVAHI_QUERY_HISTORY_MSEC, 0); + qj->time_event = avahi_time_event_queue_add(s->server->time_event_queue, &tv, query_elapse, qj); g_get_current_time(&qj->delivery); } -void response_job_set_elapse_time(flxPacketScheduler *s, flxResponseJob *rj, guint msec, guint jitter) { +void response_job_set_elapse_time(AvahiPacketScheduler *s, AvahiResponseJob *rj, guint msec, guint jitter) { GTimeVal tv; g_assert(s); g_assert(rj); - flx_elapse_time(&tv, msec, jitter); + avahi_elapse_time(&tv, msec, jitter); if (rj->time_event) - flx_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv); + avahi_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv); else - rj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, response_elapse, rj); + rj->time_event = avahi_time_event_queue_add(s->server->time_event_queue, &tv, response_elapse, rj); } -void flx_packet_scheduler_incoming_response(flxPacketScheduler *s, flxRecord *record) { - flxResponseJob *rj; +void avahi_packet_scheduler_incoming_response(AvahiPacketScheduler *s, AvahiRecord *record) { + AvahiResponseJob *rj; g_assert(s); g_assert(record); @@ -477,7 +477,7 @@ void flx_packet_scheduler_incoming_response(flxPacketScheduler *s, flxRecord *re * here. The keyword is "DUPLICATE ANSWER SUPPRESION". */ for (rj = s->response_jobs; rj; rj = rj->jobs_next) - if (flx_record_equal_no_ttl(rj->record, record)) { + if (avahi_record_equal_no_ttl(rj->record, record)) { if (rj->done) { @@ -522,13 +522,13 @@ mark_done: rj->done = TRUE; /* Drop response after 500ms from history */ - response_job_set_elapse_time(s, rj, FLX_RESPONSE_HISTORY_MSEC, 0); + response_job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0); g_get_current_time(&rj->delivery); } -void flx_packet_scheduler_incoming_known_answer(flxPacketScheduler *s, flxRecord *record, const flxAddress *a) { - flxResponseJob *rj; +void avahi_packet_scheduler_incoming_known_answer(AvahiPacketScheduler *s, AvahiRecord *record, const AvahiAddress *a) { + AvahiResponseJob *rj; g_assert(s); g_assert(record); @@ -539,9 +539,9 @@ void flx_packet_scheduler_incoming_known_answer(flxPacketScheduler *s, flxRecord g_assert(record->ttl > 0); g_assert(rj->record->ttl/2); - if (flx_record_equal_no_ttl(rj->record, record)) + if (avahi_record_equal_no_ttl(rj->record, record)) if (rj->address_valid) - if (flx_address_cmp(&rj->address, a)) + if (avahi_address_cmp(&rj->address, a)) if (record->ttl >= rj->record->ttl/2) { /* Let's suppress it */ @@ -552,8 +552,8 @@ void flx_packet_scheduler_incoming_known_answer(flxPacketScheduler *s, flxRecord } } -void flx_packet_scheduler_flush_responses(flxPacketScheduler *s) { - flxResponseJob *rj; +void avahi_packet_scheduler_flush_responses(AvahiPacketScheduler *s) { + AvahiResponseJob *rj; g_assert(s); @@ -564,27 +564,27 @@ void flx_packet_scheduler_flush_responses(flxPacketScheduler *s) { send_response_packet(s, rj); } -static flxProbeJob* probe_job_new(flxPacketScheduler *s, flxRecord *record) { - flxProbeJob *pj; +static AvahiProbeJob* probe_job_new(AvahiPacketScheduler *s, AvahiRecord *record) { + AvahiProbeJob *pj; g_assert(s); g_assert(record); - pj = g_new(flxProbeJob, 1); + pj = g_new(AvahiProbeJob, 1); pj->scheduler = s; - pj->record = flx_record_ref(record); + pj->record = avahi_record_ref(record); pj->time_event = NULL; pj->chosen = FALSE; - FLX_LLIST_PREPEND(flxProbeJob, jobs, s->probe_jobs, pj); + AVAHI_LLIST_PREPEND(AvahiProbeJob, jobs, s->probe_jobs, pj); return pj; } -static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, flxProbeJob *pj) { +static guint8* packet_add_probe_query(AvahiPacketScheduler *s, AvahiDnsPacket *p, AvahiProbeJob *pj) { guint size; guint8 *ret; - flxKey *k; + AvahiKey *k; g_assert(s); g_assert(p); @@ -594,16 +594,16 @@ static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, fl /* Estimate the size for this record */ size = - flx_key_get_estimate_size(pj->record->key) + - flx_record_get_estimate_size(pj->record); + avahi_key_get_estimate_size(pj->record->key) + + avahi_record_get_estimate_size(pj->record); /* Too large */ - if (size > flx_dns_packet_space(p)) + if (size > avahi_dns_packet_space(p)) return NULL; /* Create the probe query */ - k = flx_key_new(pj->record->key->name, pj->record->key->class, FLX_DNS_TYPE_ANY); - ret = flx_dns_packet_append_key(p, k, FALSE); + k = avahi_key_new(pj->record->key->name, pj->record->key->class, AVAHI_DNS_TYPE_ANY); + ret = avahi_dns_packet_append_key(p, k, FALSE); g_assert(ret); /* Mark this job for addition to the packet */ @@ -615,38 +615,38 @@ static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, fl continue; /* Does the record match the probe? */ - if (k->class != pj->record->key->class || !flx_domain_equal(k->name, pj->record->key->name)) + if (k->class != pj->record->key->class || !avahi_domain_equal(k->name, pj->record->key->name)) continue; /* This job wouldn't fit in */ - if (flx_record_get_estimate_size(pj->record) > flx_dns_packet_space(p)) + if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p)) break; /* Mark this job for addition to the packet */ pj->chosen = TRUE; } - flx_key_unref(k); + avahi_key_unref(k); return ret; } -static void probe_elapse(flxTimeEvent *e, gpointer data) { - flxProbeJob *pj = data, *next; - flxPacketScheduler *s; - flxDnsPacket *p; +static void probe_elapse(AvahiTimeEvent *e, gpointer data) { + AvahiProbeJob *pj = data, *next; + AvahiPacketScheduler *s; + AvahiDnsPacket *p; guint n; guint8 *d; g_assert(pj); s = pj->scheduler; - p = flx_dns_packet_new_query(s->interface->hardware->mtu - 48); + p = avahi_dns_packet_new_query(s->interface->hardware->mtu - 48); /* Add the import probe */ if (!packet_add_probe_query(s, p, pj)) { g_warning("Record too large! ---"); - flx_dns_packet_free(p); + avahi_dns_packet_free(p); return; } @@ -664,7 +664,7 @@ static void probe_elapse(flxTimeEvent *e, gpointer data) { n++; } - flx_dns_packet_set_field(p, FLX_DNS_FIELD_QDCOUNT, n); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_QDCOUNT, n); n = 0; @@ -676,7 +676,7 @@ static void probe_elapse(flxTimeEvent *e, gpointer data) { if (!pj->chosen) continue; - if (!flx_dns_packet_append_record(p, pj->record, TRUE)) { + if (!avahi_dns_packet_append_record(p, pj->record, TRUE)) { g_warning("Bad probe size estimate!"); /* Unmark all following jobs */ @@ -691,25 +691,25 @@ static void probe_elapse(flxTimeEvent *e, gpointer data) { n ++; } - flx_dns_packet_set_field(p, FLX_DNS_FIELD_NSCOUNT, n); + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_NSCOUNT, n); /* Send it now */ - flx_interface_send_packet(s->interface, p); - flx_dns_packet_free(p); + avahi_interface_send_packet(s->interface, p); + avahi_dns_packet_free(p); } -void flx_packet_scheduler_post_probe(flxPacketScheduler *s, flxRecord *record, gboolean immediately) { - flxProbeJob *pj; +void avahi_packet_scheduler_post_probe(AvahiPacketScheduler *s, AvahiRecord *record, gboolean immediately) { + AvahiProbeJob *pj; GTimeVal tv; g_assert(s); g_assert(record); - g_assert(!flx_key_is_pattern(record->key)); + g_assert(!avahi_key_is_pattern(record->key)); - flx_elapse_time(&tv, immediately ? 0 : FLX_PROBE_DEFER_MSEC, 0); + avahi_elapse_time(&tv, immediately ? 0 : AVAHI_PROBE_DEFER_MSEC, 0); /* Create a new job and schedule it */ pj = probe_job_new(s, record); pj->delivery = tv; - pj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &pj->delivery, probe_elapse, pj); + pj->time_event = avahi_time_event_queue_add(s->server->time_event_queue, &pj->delivery, probe_elapse, pj); } @@ -1,78 +1,78 @@ #ifndef foopschedhfoo #define foopschedhfoo -typedef struct _flxQueryJob flxQueryJob; -typedef struct _flxResponseJob flxResponseJob; -typedef struct _flxPacketScheduler flxPacketScheduler; -typedef struct _flxKnownAnswer flxKnownAnswer; -typedef struct _flxProbeJob flxProbeJob; +typedef struct _AvahiQueryJob AvahiQueryJob; +typedef struct _AvahiResponseJob AvahiResponseJob; +typedef struct _AvahiPacketScheduler AvahiPacketScheduler; +typedef struct _AvahiKnownAnswer AvahiKnownAnswer; +typedef struct _AvahiProbeJob AvahiProbeJob; #include "timeeventq.h" #include "rr.h" #include "llist.h" #include "iface.h" -struct _flxQueryJob { - flxPacketScheduler *scheduler; - flxTimeEvent *time_event; - flxKey *key; +struct _AvahiQueryJob { + AvahiPacketScheduler *scheduler; + AvahiTimeEvent *time_event; + AvahiKey *key; gboolean done; GTimeVal delivery; - FLX_LLIST_FIELDS(flxQueryJob, jobs); + AVAHI_LLIST_FIELDS(AvahiQueryJob, jobs); }; -struct _flxResponseJob { - flxPacketScheduler *scheduler; - flxTimeEvent *time_event; - flxRecord *record; - flxAddress address; +struct _AvahiResponseJob { + AvahiPacketScheduler *scheduler; + AvahiTimeEvent *time_event; + AvahiRecord *record; + AvahiAddress address; gboolean address_valid; gboolean done; GTimeVal delivery; gboolean flush_cache; - FLX_LLIST_FIELDS(flxResponseJob, jobs); + AVAHI_LLIST_FIELDS(AvahiResponseJob, jobs); }; -struct _flxKnownAnswer { - flxPacketScheduler *scheduler; - flxRecord *record; +struct _AvahiKnownAnswer { + AvahiPacketScheduler *scheduler; + AvahiRecord *record; - FLX_LLIST_FIELDS(flxKnownAnswer, known_answer); + AVAHI_LLIST_FIELDS(AvahiKnownAnswer, known_answer); }; -struct _flxProbeJob { - flxPacketScheduler *scheduler; - flxTimeEvent *time_event; - flxRecord *record; +struct _AvahiProbeJob { + AvahiPacketScheduler *scheduler; + AvahiTimeEvent *time_event; + AvahiRecord *record; gboolean chosen; /* Use for packet assembling */ GTimeVal delivery; - FLX_LLIST_FIELDS(flxProbeJob, jobs); + AVAHI_LLIST_FIELDS(AvahiProbeJob, jobs); }; -struct _flxPacketScheduler { - flxServer *server; +struct _AvahiPacketScheduler { + AvahiServer *server; - flxInterface *interface; + AvahiInterface *interface; - FLX_LLIST_HEAD(flxQueryJob, query_jobs); - FLX_LLIST_HEAD(flxResponseJob, response_jobs); - FLX_LLIST_HEAD(flxKnownAnswer, known_answers); - FLX_LLIST_HEAD(flxProbeJob, probe_jobs); + AVAHI_LLIST_HEAD(AvahiQueryJob, query_jobs); + AVAHI_LLIST_HEAD(AvahiResponseJob, response_jobs); + AVAHI_LLIST_HEAD(AvahiKnownAnswer, known_answers); + AVAHI_LLIST_HEAD(AvahiProbeJob, probe_jobs); }; -flxPacketScheduler *flx_packet_scheduler_new(flxServer *server, flxInterface *i); -void flx_packet_scheduler_free(flxPacketScheduler *s); +AvahiPacketScheduler *avahi_packet_scheduler_new(AvahiServer *server, AvahiInterface *i); +void avahi_packet_scheduler_free(AvahiPacketScheduler *s); -void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key, gboolean immediately); -void flx_packet_scheduler_post_response(flxPacketScheduler *s, const flxAddress *a, flxRecord *record, gboolean flush_cache, gboolean immediately); -void flx_packet_scheduler_post_probe(flxPacketScheduler *s, flxRecord *record, gboolean immediately); +void avahi_packet_scheduler_post_query(AvahiPacketScheduler *s, AvahiKey *key, gboolean immediately); +void avahi_packet_scheduler_post_response(AvahiPacketScheduler *s, const AvahiAddress *a, AvahiRecord *record, gboolean flush_cache, gboolean immediately); +void avahi_packet_scheduler_post_probe(AvahiPacketScheduler *s, AvahiRecord *record, gboolean immediately); -void flx_packet_scheduler_incoming_query(flxPacketScheduler *s, flxKey *key); -void flx_packet_scheduler_incoming_response(flxPacketScheduler *s, flxRecord *record); -void flx_packet_scheduler_incoming_known_answer(flxPacketScheduler *s, flxRecord *record, const flxAddress *a); +void avahi_packet_scheduler_incoming_query(AvahiPacketScheduler *s, AvahiKey *key); +void avahi_packet_scheduler_incoming_response(AvahiPacketScheduler *s, AvahiRecord *record); +void avahi_packet_scheduler_incoming_known_answer(AvahiPacketScheduler *s, AvahiRecord *record, const AvahiAddress *a); -void flx_packet_scheduler_flush_responses(flxPacketScheduler *s); +void avahi_packet_scheduler_flush_responses(AvahiPacketScheduler *s); #endif @@ -8,13 +8,13 @@ #include "rr.h" #include "dns.h" -flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type) { - flxKey *k; +AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type) { + AvahiKey *k; g_assert(name); - k = g_new(flxKey, 1); + k = g_new(AvahiKey, 1); k->ref = 1; - k->name = flx_normalize_name(name); + k->name = avahi_normalize_name(name); k->class = class; k->type = type; @@ -23,7 +23,7 @@ flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type) { return k; } -flxKey *flx_key_ref(flxKey *k) { +AvahiKey *avahi_key_ref(AvahiKey *k) { g_assert(k); g_assert(k->ref >= 1); @@ -34,7 +34,7 @@ flxKey *flx_key_ref(flxKey *k) { return k; } -void flx_key_unref(flxKey *k) { +void avahi_key_unref(AvahiKey *k) { g_assert(k); g_assert(k->ref >= 1); @@ -46,36 +46,36 @@ void flx_key_unref(flxKey *k) { } } -flxRecord *flx_record_new(flxKey *k) { - flxRecord *r; +AvahiRecord *avahi_record_new(AvahiKey *k) { + AvahiRecord *r; g_assert(k); - r = g_new(flxRecord, 1); + r = g_new(AvahiRecord, 1); r->ref = 1; - r->key = flx_key_ref(k); + r->key = avahi_key_ref(k); memset(&r->data, 0, sizeof(r->data)); - r->ttl = FLX_DEFAULT_TTL; + r->ttl = AVAHI_DEFAULT_TTL; return r; } -flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type) { - flxRecord *r; - flxKey *k; +AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type) { + AvahiRecord *r; + AvahiKey *k; g_assert(name); - k = flx_key_new(name, class, type); - r = flx_record_new(k); - flx_key_unref(k); + k = avahi_key_new(name, class, type); + r = avahi_record_new(k); + avahi_key_unref(k); return r; } -flxRecord *flx_record_ref(flxRecord *r) { +AvahiRecord *avahi_record_ref(AvahiRecord *r) { g_assert(r); g_assert(r->ref >= 1); @@ -83,71 +83,71 @@ flxRecord *flx_record_ref(flxRecord *r) { return r; } -void flx_record_unref(flxRecord *r) { +void avahi_record_unref(AvahiRecord *r) { g_assert(r); g_assert(r->ref >= 1); if ((--r->ref) <= 0) { switch (r->key->type) { - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: g_free(r->data.srv.name); break; - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: g_free(r->data.ptr.name); break; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: g_free(r->data.hinfo.cpu); g_free(r->data.hinfo.os); break; - case FLX_DNS_TYPE_TXT: - flx_string_list_free(r->data.txt.string_list); + case AVAHI_DNS_TYPE_TXT: + avahi_string_list_free(r->data.txt.string_list); break; - case FLX_DNS_TYPE_A: - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_A: + case AVAHI_DNS_TYPE_AAAA: break; default: g_free(r->data.generic.data); } - flx_key_unref(r->key); + avahi_key_unref(r->key); g_free(r); } } -const gchar *flx_dns_class_to_string(guint16 class) { - if (class & FLX_DNS_CACHE_FLUSH) +const gchar *avahi_dns_class_to_string(guint16 class) { + if (class & AVAHI_DNS_CACHE_FLUSH) return "FLUSH"; - if (class == FLX_DNS_CLASS_IN) + if (class == AVAHI_DNS_CLASS_IN) return "IN"; return NULL; } -const gchar *flx_dns_type_to_string(guint16 type) { +const gchar *avahi_dns_type_to_string(guint16 type) { switch (type) { - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_CNAME: return "CNAME"; - case FLX_DNS_TYPE_A: + case AVAHI_DNS_TYPE_A: return "A"; - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_AAAA: return "AAAA"; - case FLX_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_PTR: return "PTR"; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: return "HINFO"; - case FLX_DNS_TYPE_TXT: + case AVAHI_DNS_TYPE_TXT: return "TXT"; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: return "SRV"; - case FLX_DNS_TYPE_ANY: + case AVAHI_DNS_TYPE_ANY: return "ANY"; default: return NULL; @@ -155,42 +155,42 @@ const gchar *flx_dns_type_to_string(guint16 type) { } -gchar *flx_key_to_string(const flxKey *k) { +gchar *avahi_key_to_string(const AvahiKey *k) { return g_strdup_printf("%s\t%s\t%s", k->name, - flx_dns_class_to_string(k->class), - flx_dns_type_to_string(k->type)); + avahi_dns_class_to_string(k->class), + avahi_dns_type_to_string(k->type)); } -gchar *flx_record_to_string(const flxRecord *r) { +gchar *avahi_record_to_string(const AvahiRecord *r) { gchar *p, *s; char buf[257], *t = NULL, *d = NULL; switch (r->key->type) { - case FLX_DNS_TYPE_A: + case AVAHI_DNS_TYPE_A: inet_ntop(AF_INET, &r->data.a.address.address, t = buf, sizeof(buf)); break; - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_AAAA: inet_ntop(AF_INET6, &r->data.aaaa.address.address, t = buf, sizeof(buf)); break; - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME : + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME : t = r->data.ptr.name; break; - case FLX_DNS_TYPE_TXT: - t = d = flx_string_list_to_string(r->data.txt.string_list); + case AVAHI_DNS_TYPE_TXT: + t = d = avahi_string_list_to_string(r->data.txt.string_list); break; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: snprintf(t = buf, sizeof(buf), "\"%s\" \"%s\"", r->data.hinfo.cpu, r->data.hinfo.os); break; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: snprintf(t = buf, sizeof(buf), "%u %u %u %s", r->data.srv.priority, @@ -201,7 +201,7 @@ gchar *flx_record_to_string(const flxRecord *r) { break; } - p = flx_key_to_string(r->key); + p = avahi_key_to_string(r->key); s = g_strdup_printf("%s %s ; ttl=%u", p, t ? t : "<unparsable>", r->ttl); g_free(p); g_free(d); @@ -209,7 +209,7 @@ gchar *flx_record_to_string(const flxRecord *r) { return s; } -gboolean flx_key_equal(const flxKey *a, const flxKey *b) { +gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) { g_assert(a); g_assert(b); @@ -218,79 +218,79 @@ gboolean flx_key_equal(const flxKey *a, const flxKey *b) { /* g_message("equal: %p %p", a, b); */ - return flx_domain_equal(a->name, b->name) && + return avahi_domain_equal(a->name, b->name) && a->type == b->type && a->class == b->class; } -gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k) { +gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) { g_assert(pattern); g_assert(k); /* g_message("equal: %p %p", a, b); */ - g_assert(!flx_key_is_pattern(k)); + g_assert(!avahi_key_is_pattern(k)); if (pattern == k) return TRUE; - return flx_domain_equal(pattern->name, k->name) && - (pattern->type == k->type || pattern->type == FLX_DNS_TYPE_ANY) && + return avahi_domain_equal(pattern->name, k->name) && + (pattern->type == k->type || pattern->type == AVAHI_DNS_TYPE_ANY) && pattern->class == k->class; } -gboolean flx_key_is_pattern(const flxKey *k) { +gboolean avahi_key_is_pattern(const AvahiKey *k) { g_assert(k); - return k->type == FLX_DNS_TYPE_ANY; + return k->type == AVAHI_DNS_TYPE_ANY; } -guint flx_key_hash(const flxKey *k) { +guint avahi_key_hash(const AvahiKey *k) { g_assert(k); - return flx_domain_hash(k->name) + k->type + k->class; + return avahi_domain_hash(k->name) + k->type + k->class; } -static gboolean rdata_equal(const flxRecord *a, const flxRecord *b) { +static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) { g_assert(a); g_assert(b); g_assert(a->key->type == b->key->type); -/* t = flx_record_to_string(a); */ +/* t = avahi_record_to_string(a); */ /* g_message("comparing %s", t); */ /* g_free(t); */ -/* t = flx_record_to_string(b); */ +/* t = avahi_record_to_string(b); */ /* g_message("and %s", t); */ /* g_free(t); */ switch (a->key->type) { - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: return a->data.srv.priority == b->data.srv.priority && a->data.srv.weight == b->data.srv.weight && a->data.srv.port == b->data.srv.port && - flx_domain_equal(a->data.srv.name, b->data.srv.name); + avahi_domain_equal(a->data.srv.name, b->data.srv.name); - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: - return flx_domain_equal(a->data.ptr.name, b->data.ptr.name); + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: + return avahi_domain_equal(a->data.ptr.name, b->data.ptr.name); - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: return !strcmp(a->data.hinfo.cpu, b->data.hinfo.cpu) && !strcmp(a->data.hinfo.os, b->data.hinfo.os); - case FLX_DNS_TYPE_TXT: - return flx_string_list_equal(a->data.txt.string_list, b->data.txt.string_list); + case AVAHI_DNS_TYPE_TXT: + return avahi_string_list_equal(a->data.txt.string_list, b->data.txt.string_list); - case FLX_DNS_TYPE_A: - return memcmp(&a->data.a.address, &b->data.a.address, sizeof(flxIPv4Address)) == 0; + case AVAHI_DNS_TYPE_A: + return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)) == 0; - case FLX_DNS_TYPE_AAAA: - return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(flxIPv6Address)) == 0; + case AVAHI_DNS_TYPE_AAAA: + return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)) == 0; default: return a->data.generic.size == b->data.generic.size && @@ -299,7 +299,7 @@ static gboolean rdata_equal(const flxRecord *a, const flxRecord *b) { } -gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b) { +gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) { g_assert(a); g_assert(b); @@ -307,46 +307,46 @@ gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b) { return TRUE; return - flx_key_equal(a->key, b->key) && + avahi_key_equal(a->key, b->key) && rdata_equal(a, b); } -flxRecord *flx_record_copy(flxRecord *r) { - flxRecord *copy; +AvahiRecord *avahi_record_copy(AvahiRecord *r) { + AvahiRecord *copy; - copy = g_new(flxRecord, 1); + copy = g_new(AvahiRecord, 1); copy->ref = 1; - copy->key = flx_key_ref(r->key); + copy->key = avahi_key_ref(r->key); copy->ttl = r->ttl; switch (r->key->type) { - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: copy->data.ptr.name = g_strdup(r->data.ptr.name); break; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: copy->data.srv.priority = r->data.srv.priority; copy->data.srv.weight = r->data.srv.weight; copy->data.srv.port = r->data.srv.port; copy->data.srv.name = g_strdup(r->data.srv.name); break; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: copy->data.hinfo.os = g_strdup(r->data.hinfo.os); copy->data.hinfo.cpu = g_strdup(r->data.hinfo.cpu); break; - case FLX_DNS_TYPE_TXT: - copy->data.txt.string_list = flx_string_list_copy(r->data.txt.string_list); + case AVAHI_DNS_TYPE_TXT: + copy->data.txt.string_list = avahi_string_list_copy(r->data.txt.string_list); break; - case FLX_DNS_TYPE_A: + case AVAHI_DNS_TYPE_A: copy->data.a.address = r->data.a.address; break; - case FLX_DNS_TYPE_AAAA: + case AVAHI_DNS_TYPE_AAAA: copy->data.aaaa.address = r->data.aaaa.address; break; @@ -361,42 +361,42 @@ flxRecord *flx_record_copy(flxRecord *r) { } -guint flx_key_get_estimate_size(flxKey *k) { +guint avahi_key_get_estimate_size(AvahiKey *k) { g_assert(k); return strlen(k->name)+1+4; } -guint flx_record_get_estimate_size(flxRecord *r) { +guint avahi_record_get_estimate_size(AvahiRecord *r) { guint n; g_assert(r); - n = flx_key_get_estimate_size(r->key) + 4 + 2; + n = avahi_key_get_estimate_size(r->key) + 4 + 2; switch (r->key->type) { - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: n += strlen(r->data.ptr.name) + 1; break; - case FLX_DNS_TYPE_SRV: + case AVAHI_DNS_TYPE_SRV: n += 6 + strlen(r->data.srv.name) + 1; break; - case FLX_DNS_TYPE_HINFO: + case AVAHI_DNS_TYPE_HINFO: n += strlen(r->data.hinfo.os) + 1 + strlen(r->data.hinfo.cpu) + 1; break; - case FLX_DNS_TYPE_TXT: - n += flx_string_list_serialize(r->data.txt.string_list, NULL, 0); + case AVAHI_DNS_TYPE_TXT: + n += avahi_string_list_serialize(r->data.txt.string_list, NULL, 0); break; - case FLX_DNS_TYPE_A: - n += sizeof(flxIPv4Address); + case AVAHI_DNS_TYPE_A: + n += sizeof(AvahiIPv4Address); break; - case FLX_DNS_TYPE_AAAA: - n += sizeof(flxIPv6Address); + case AVAHI_DNS_TYPE_AAAA: + n += sizeof(AvahiIPv6Address); break; default: @@ -447,8 +447,8 @@ static gint lexicographical_domain_cmp(const gchar *a, const gchar *b) { if (b && !a) return -1; - flx_unescape_label(t1, sizeof(t1), &a); - flx_unescape_label(t2, sizeof(t2), &b); + avahi_unescape_label(t1, sizeof(t1), &a); + avahi_unescape_label(t2, sizeof(t2), &b); al = strlen(t1); bl = strlen(t2); @@ -461,7 +461,7 @@ static gint lexicographical_domain_cmp(const gchar *a, const gchar *b) { } } -gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { +gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) { g_assert(a); g_assert(b); @@ -470,10 +470,10 @@ gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { /* gchar *t; */ -/* g_message("comparing [%s]", t = flx_record_to_string(a)); */ +/* g_message("comparing [%s]", t = avahi_record_to_string(a)); */ /* g_free(t); */ -/* g_message("and [%s]", t = flx_record_to_string(b)); */ +/* g_message("and [%s]", t = avahi_record_to_string(b)); */ /* g_free(t); */ if (a->key->class < b->key->class) @@ -488,11 +488,11 @@ gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { switch (a->key->type) { - case FLX_DNS_TYPE_PTR: - case FLX_DNS_TYPE_CNAME: + case AVAHI_DNS_TYPE_PTR: + case AVAHI_DNS_TYPE_CNAME: return lexicographical_domain_cmp(a->data.ptr.name, b->data.ptr.name); - case FLX_DNS_TYPE_SRV: { + case AVAHI_DNS_TYPE_SRV: { gint r; if ((r = uint16_cmp(a->data.srv.priority, b->data.srv.priority)) == 0 && (r = uint16_cmp(a->data.srv.weight, b->data.srv.weight)) == 0 && @@ -502,7 +502,7 @@ gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { return r; } - case FLX_DNS_TYPE_HINFO: { + case AVAHI_DNS_TYPE_HINFO: { size_t al = strlen(a->data.hinfo.cpu), bl = strlen(b->data.hinfo.cpu); gint r; @@ -524,16 +524,16 @@ gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { } - case FLX_DNS_TYPE_TXT: { + case AVAHI_DNS_TYPE_TXT: { guint8 *ma, *mb; guint asize, bsize; gint r; - ma = g_new(guint8, asize = flx_string_list_serialize(a->data.txt.string_list, NULL, 0)); - mb = g_new(guint8, bsize = flx_string_list_serialize(b->data.txt.string_list, NULL, 0)); - flx_string_list_serialize(a->data.txt.string_list, ma, asize); - flx_string_list_serialize(a->data.txt.string_list, mb, bsize); + ma = g_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0)); + mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0)); + avahi_string_list_serialize(a->data.txt.string_list, ma, asize); + avahi_string_list_serialize(a->data.txt.string_list, mb, bsize); r = lexicographical_memcmp(ma, asize, mb, bsize); g_free(ma); @@ -542,11 +542,11 @@ gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b) { return r; } - case FLX_DNS_TYPE_A: - return memcmp(&a->data.a.address, &b->data.a.address, sizeof(flxIPv4Address)); + case AVAHI_DNS_TYPE_A: + return memcmp(&a->data.a.address, &b->data.a.address, sizeof(AvahiIPv4Address)); - case FLX_DNS_TYPE_AAAA: - return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(flxIPv6Address)); + case AVAHI_DNS_TYPE_AAAA: + return memcmp(&a->data.aaaa.address, &b->data.aaaa.address, sizeof(AvahiIPv6Address)); default: return lexicographical_memcmp(a->data.generic.data, a->data.generic.size, @@ -7,37 +7,37 @@ #include "address.h" enum { - FLX_DNS_TYPE_A = 0x01, - FLX_DNS_TYPE_NS = 0x02, - FLX_DNS_TYPE_CNAME = 0x05, - FLX_DNS_TYPE_SOA = 0x06, - FLX_DNS_TYPE_PTR = 0x0C, - FLX_DNS_TYPE_HINFO = 0x0D, - FLX_DNS_TYPE_MX = 0x0F, - FLX_DNS_TYPE_TXT = 0x10, - FLX_DNS_TYPE_AAAA = 0x1C, - FLX_DNS_TYPE_SRV = 0x21, - FLX_DNS_TYPE_ANY = 0xFF + AVAHI_DNS_TYPE_A = 0x01, + AVAHI_DNS_TYPE_NS = 0x02, + AVAHI_DNS_TYPE_CNAME = 0x05, + AVAHI_DNS_TYPE_SOA = 0x06, + AVAHI_DNS_TYPE_PTR = 0x0C, + AVAHI_DNS_TYPE_HINFO = 0x0D, + AVAHI_DNS_TYPE_MX = 0x0F, + AVAHI_DNS_TYPE_TXT = 0x10, + AVAHI_DNS_TYPE_AAAA = 0x1C, + AVAHI_DNS_TYPE_SRV = 0x21, + AVAHI_DNS_TYPE_ANY = 0xFF }; enum { - FLX_DNS_CLASS_IN = 0x01, - FLX_DNS_CACHE_FLUSH = 0x8000, - FLX_DNS_UNICAST_RESPONSE = 0x8000 + AVAHI_DNS_CLASS_IN = 0x01, + AVAHI_DNS_CACHE_FLUSH = 0x8000, + AVAHI_DNS_UNICAST_RESPONSE = 0x8000 }; -#define FLX_DEFAULT_TTL (120*60) +#define AVAHI_DEFAULT_TTL (120*60) typedef struct { guint ref; gchar *name; guint16 class; guint16 type; -} flxKey; +} AvahiKey; typedef struct { guint ref; - flxKey *key; + AvahiKey *key; guint32 ttl; @@ -64,54 +64,54 @@ typedef struct { } hinfo; struct { - flxStringList *string_list; + AvahiStringList *string_list; } txt; struct { - flxIPv4Address address; + AvahiIPv4Address address; } a; struct { - flxIPv6Address address; + AvahiIPv6Address address; } aaaa; } data; -} flxRecord; +} AvahiRecord; -flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type); -flxKey *flx_key_ref(flxKey *k); -void flx_key_unref(flxKey *k); +AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type); +AvahiKey *avahi_key_ref(AvahiKey *k); +void avahi_key_unref(AvahiKey *k); -gboolean flx_key_equal(const flxKey *a, const flxKey *b); /* Treat FLX_DNS_CLASS_ANY like any other type */ -gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k); /* If pattern.type is FLX_DNS_CLASS_ANY, k.type is ignored */ +gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b); /* Treat AVAHI_DNS_CLASS_ANY like any other type */ +gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k); /* If pattern.type is AVAHI_DNS_CLASS_ANY, k.type is ignored */ -gboolean flx_key_is_pattern(const flxKey *k); +gboolean avahi_key_is_pattern(const AvahiKey *k); -guint flx_key_hash(const flxKey *k); +guint avahi_key_hash(const AvahiKey *k); -flxRecord *flx_record_new(flxKey *k); -flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type); -flxRecord *flx_record_ref(flxRecord *r); -void flx_record_unref(flxRecord *r); +AvahiRecord *avahi_record_new(AvahiKey *k); +AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type); +AvahiRecord *avahi_record_ref(AvahiRecord *r); +void avahi_record_unref(AvahiRecord *r); -const gchar *flx_dns_class_to_string(guint16 class); -const gchar *flx_dns_type_to_string(guint16 type); +const gchar *avahi_dns_class_to_string(guint16 class); +const gchar *avahi_dns_type_to_string(guint16 type); -gchar *flx_key_to_string(const flxKey *k); /* g_free() the result! */ -gchar *flx_record_to_string(const flxRecord *r); /* g_free() the result! */ +gchar *avahi_key_to_string(const AvahiKey *k); /* g_free() the result! */ +gchar *avahi_record_to_string(const AvahiRecord *r); /* g_free() the result! */ -gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b); +gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b); -flxRecord *flx_record_copy(flxRecord *r); +AvahiRecord *avahi_record_copy(AvahiRecord *r); /* returns a maximum estimate for the space that is needed to store * this key in a DNS packet */ -guint flx_key_get_estimate_size(flxKey *k); +guint avahi_key_get_estimate_size(AvahiKey *k); /* ditto */ -guint flx_record_get_estimate_size(flxRecord *r); +guint avahi_record_get_estimate_size(AvahiRecord *r); -gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b); +gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b); #endif @@ -10,20 +10,20 @@ #include "socket.h" #include "subscribe.h" -static void free_entry(flxServer*s, flxEntry *e) { - flxEntry *t; +static void free_entry(AvahiServer*s, AvahiEntry *e) { + AvahiEntry *t; g_assert(s); g_assert(e); - flx_goodbye_entry(s, e, TRUE); + avahi_goodbye_entry(s, e, TRUE); /* Remove from linked list */ - FLX_LLIST_REMOVE(flxEntry, entries, s->entries, e); + AVAHI_LLIST_REMOVE(AvahiEntry, entries, s->entries, e); /* Remove from hash table indexed by name */ t = g_hash_table_lookup(s->entries_by_key, e->record->key); - FLX_LLIST_REMOVE(flxEntry, by_key, t, e); + AVAHI_LLIST_REMOVE(AvahiEntry, by_key, t, e); if (t) g_hash_table_replace(s->entries_by_key, t->record->key, t); else @@ -31,26 +31,26 @@ static void free_entry(flxServer*s, flxEntry *e) { /* Remove from associated group */ if (e->group) - FLX_LLIST_REMOVE(flxEntry, by_group, e->group->entries, e); + AVAHI_LLIST_REMOVE(AvahiEntry, by_group, e->group->entries, e); - flx_record_unref(e->record); + avahi_record_unref(e->record); g_free(e); } -static void free_group(flxServer *s, flxEntryGroup *g) { +static void free_group(AvahiServer *s, AvahiEntryGroup *g) { g_assert(s); g_assert(g); while (g->entries) free_entry(s, g->entries); - FLX_LLIST_REMOVE(flxEntryGroup, groups, s->groups, g); + AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, s->groups, g); g_free(g); } -static void cleanup_dead(flxServer *s) { - flxEntryGroup *g, *ng; - flxEntry *e, *ne; +static void cleanup_dead(AvahiServer *s) { + AvahiEntryGroup *g, *ng; + AvahiEntry *e, *ne; g_assert(s); @@ -77,8 +77,8 @@ static void cleanup_dead(flxServer *s) { } } -static void handle_query_key(flxServer *s, flxKey *k, flxInterface *i, const flxAddress *a, guint16 port, gboolean legacy_unicast, gboolean unicast_response) { - flxEntry *e; +static void handle_query_key(AvahiServer *s, AvahiKey *k, AvahiInterface *i, const AvahiAddress *a, guint16 port, gboolean legacy_unicast, gboolean unicast_response) { + AvahiEntry *e; gchar *txt; g_assert(s); @@ -86,72 +86,72 @@ static void handle_query_key(flxServer *s, flxKey *k, flxInterface *i, const flx g_assert(i); g_assert(a); - g_message("Handling query: %s", txt = flx_key_to_string(k)); + g_message("Handling query: %s", txt = avahi_key_to_string(k)); g_free(txt); - flx_packet_scheduler_incoming_query(i->scheduler, k); + avahi_packet_scheduler_incoming_query(i->scheduler, k); - if (k->type == FLX_DNS_TYPE_ANY) { + if (k->type == AVAHI_DNS_TYPE_ANY) { /* Handle ANY query */ for (e = s->entries; e; e = e->entries_next) - if (!e->dead && flx_key_pattern_match(k, e->record->key) && flx_entry_registered(s, e, i)) - flx_interface_post_response(i, a, e->record, e->flags & FLX_ENTRY_UNIQUE, FALSE); + if (!e->dead && avahi_key_pattern_match(k, e->record->key) && avahi_entry_registered(s, e, i)) + avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, FALSE); } else { /* Handle all other queries */ for (e = g_hash_table_lookup(s->entries_by_key, k); e; e = e->by_key_next) - if (!e->dead && flx_entry_registered(s, e, i)) - flx_interface_post_response(i, a, e->record, e->flags & FLX_ENTRY_UNIQUE, FALSE); + if (!e->dead && avahi_entry_registered(s, e, i)) + avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, FALSE); } } -static void withdraw_entry(flxServer *s, flxEntry *e) { +static void withdraw_entry(AvahiServer *s, AvahiEntry *e) { g_assert(s); g_assert(e); if (e->group) { - flxEntry *k; + AvahiEntry *k; for (k = e->group->entries; k; k = k->by_group_next) { - flx_goodbye_entry(s, k, FALSE); + avahi_goodbye_entry(s, k, FALSE); k->dead = TRUE; } - flx_entry_group_change_state(e->group, FLX_ENTRY_GROUP_COLLISION); + avahi_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION); } else { - flx_goodbye_entry(s, e, FALSE); + avahi_goodbye_entry(s, e, FALSE); e->dead = TRUE; } s->need_entry_cleanup = TRUE; } -static void incoming_probe(flxServer *s, flxRecord *record, flxInterface *i) { - flxEntry *e, *n; +static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface *i) { + AvahiEntry *e, *n; gchar *t; g_assert(s); g_assert(record); g_assert(i); - t = flx_record_to_string(record); + t = avahi_record_to_string(record); /* g_message("PROBE: [%s]", t); */ for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) { n = e->by_key_next; - if (e->dead || flx_record_equal_no_ttl(record, e->record)) + if (e->dead || avahi_record_equal_no_ttl(record, e->record)) continue; - if (flx_entry_registering(s, e, i)) { + if (avahi_entry_registering(s, e, i)) { gint cmp; - if ((cmp = flx_record_lexicographical_compare(record, e->record)) > 0) { + if ((cmp = avahi_record_lexicographical_compare(record, e->record)) > 0) { withdraw_entry(s, e); g_message("Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t); } else if (cmp < 0) @@ -163,7 +163,7 @@ static void incoming_probe(flxServer *s, flxRecord *record, flxInterface *i) { g_free(t); } -static void handle_query(flxServer *s, flxDnsPacket *p, flxInterface *i, const flxAddress *a, guint16 port, gboolean legacy_unicast) { +static void handle_query(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, guint16 port, gboolean legacy_unicast) { guint n; g_assert(s); @@ -172,60 +172,60 @@ static void handle_query(flxServer *s, flxDnsPacket *p, flxInterface *i, const f g_assert(a); /* Handle the questions */ - for (n = flx_dns_packet_get_field(p, FLX_DNS_FIELD_QDCOUNT); n > 0; n --) { - flxKey *key; + for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n --) { + AvahiKey *key; gboolean unicast_response = FALSE; - if (!(key = flx_dns_packet_consume_key(p, &unicast_response))) { + if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) { g_warning("Packet too short (1)"); return; } handle_query_key(s, key, i, a, port, legacy_unicast, unicast_response); - flx_key_unref(key); + avahi_key_unref(key); } /* Known Answer Suppression */ - for (n = flx_dns_packet_get_field(p, FLX_DNS_FIELD_ANCOUNT); n > 0; n --) { - flxRecord *record; + for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) { + AvahiRecord *record; gboolean unique = FALSE; - if (!(record = flx_dns_packet_consume_record(p, &unique))) { + if (!(record = avahi_dns_packet_consume_record(p, &unique))) { g_warning("Packet too short (2)"); return; } - flx_packet_scheduler_incoming_known_answer(i->scheduler, record, a); - flx_record_unref(record); + avahi_packet_scheduler_incoming_known_answer(i->scheduler, record, a); + avahi_record_unref(record); } /* Probe record */ - for (n = flx_dns_packet_get_field(p, FLX_DNS_FIELD_NSCOUNT); n > 0; n --) { - flxRecord *record; + for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT); n > 0; n --) { + AvahiRecord *record; gboolean unique = FALSE; - if (!(record = flx_dns_packet_consume_record(p, &unique))) { + if (!(record = avahi_dns_packet_consume_record(p, &unique))) { g_warning("Packet too short (3)"); return; } - if (record->key->type != FLX_DNS_TYPE_ANY) + if (record->key->type != AVAHI_DNS_TYPE_ANY) incoming_probe(s, record, i); - flx_record_unref(record); + avahi_record_unref(record); } } -static gboolean handle_conflict(flxServer *s, flxInterface *i, flxRecord *record, gboolean unique, const flxAddress *a) { +static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, gboolean unique, const AvahiAddress *a) { gboolean valid = TRUE; - flxEntry *e, *n; + AvahiEntry *e, *n; gchar *t; g_assert(s); g_assert(i); g_assert(record); - t = flx_record_to_string(record); + t = avahi_record_to_string(record); /* g_message("CHECKING FOR CONFLICT: [%s]", t); */ @@ -235,16 +235,16 @@ static gboolean handle_conflict(flxServer *s, flxInterface *i, flxRecord *record if (e->dead) continue; - if (flx_entry_registered(s, e, i)) { + if (avahi_entry_registered(s, e, i)) { - gboolean equal = flx_record_equal_no_ttl(record, e->record); + gboolean equal = avahi_record_equal_no_ttl(record, e->record); /* Check whether there is a unique record conflict */ - if (!equal && ((e->flags & FLX_ENTRY_UNIQUE) || unique)) { + if (!equal && ((e->flags & AVAHI_ENTRY_UNIQUE) || unique)) { gint cmp; /* The lexicographically later data wins. */ - if ((cmp = flx_record_lexicographical_compare(record, e->record)) > 0) { + if ((cmp = avahi_record_lexicographical_compare(record, e->record)) > 0) { g_message("Recieved conflicting record [%s]. Local host lost. Withdrawing.", t); withdraw_entry(s, e); } else if (cmp < 0) { @@ -253,20 +253,20 @@ static gboolean handle_conflict(flxServer *s, flxInterface *i, flxRecord *record g_message("Recieved conflicting record [%s]. Local host won. Refreshing.", t); valid = FALSE; - flx_interface_post_response(i, a, e->record, e->flags & FLX_ENTRY_UNIQUE, TRUE); + avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, TRUE); } /* Check wheter there is a TTL conflict */ } else if (equal && record->ttl <= e->record->ttl/2) { /* Correct the TTL */ valid = FALSE; - flx_interface_post_response(i, a, e->record, e->flags & FLX_ENTRY_UNIQUE, TRUE); + avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, TRUE); g_message("Recieved record with bad TTL [%s]. Refreshing.", t); } - } else if (flx_entry_registering(s, e, i)) { + } else if (avahi_entry_registering(s, e, i)) { - if (!flx_record_equal_no_ttl(record, e->record) && ((e->flags & FLX_ENTRY_UNIQUE) || unique)) { + if (!avahi_record_equal_no_ttl(record, e->record) && ((e->flags & AVAHI_ENTRY_UNIQUE) || unique)) { /* We are currently registering a matching record, but * someone else already claimed it, so let's @@ -283,7 +283,7 @@ static gboolean handle_conflict(flxServer *s, flxInterface *i, flxRecord *record return valid; } -static void handle_response(flxServer *s, flxDnsPacket *p, flxInterface *i, const flxAddress *a) { +static void handle_response(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a) { guint n; g_assert(s); @@ -291,35 +291,35 @@ static void handle_response(flxServer *s, flxDnsPacket *p, flxInterface *i, cons g_assert(i); g_assert(a); - for (n = flx_dns_packet_get_field(p, FLX_DNS_FIELD_ANCOUNT) + - flx_dns_packet_get_field(p, FLX_DNS_FIELD_ARCOUNT); n > 0; n--) { - flxRecord *record; + for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) + + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT); n > 0; n--) { + AvahiRecord *record; gboolean cache_flush = FALSE; gchar *txt; - if (!(record = flx_dns_packet_consume_record(p, &cache_flush))) { + if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) { g_warning("Packet too short (4)"); return; } - if (record->key->type != FLX_DNS_TYPE_ANY) { + if (record->key->type != AVAHI_DNS_TYPE_ANY) { - g_message("Handling response: %s", txt = flx_record_to_string(record)); + g_message("Handling response: %s", txt = avahi_record_to_string(record)); g_free(txt); if (handle_conflict(s, i, record, cache_flush, a)) { - flx_cache_update(i->cache, record, cache_flush, a); - flx_packet_scheduler_incoming_response(i->scheduler, record); + avahi_cache_update(i->cache, record, cache_flush, a); + avahi_packet_scheduler_incoming_response(i->scheduler, record); } } - flx_record_unref(record); + avahi_record_unref(record); } } -static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, gint iface, gint ttl) { - flxInterface *i; - flxAddress a; +static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, struct sockaddr *sa, gint iface, gint ttl) { + AvahiInterface *i; + AvahiAddress a; guint16 port; g_assert(s); @@ -327,7 +327,7 @@ static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, g_assert(sa); g_assert(iface > 0); - if (!(i = flx_interface_monitor_get_interface(s->monitor, iface, sa->sa_family))) { + if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family))) { g_warning("Recieved packet from invalid interface."); return; } @@ -346,28 +346,28 @@ static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, return; } - if (flx_dns_packet_check_valid(p) < 0) { + if (avahi_dns_packet_check_valid(p) < 0) { g_warning("Recieved invalid packet."); return; } - port = flx_port_from_sockaddr(sa); - flx_address_from_sockaddr(sa, &a); + port = avahi_port_from_sockaddr(sa); + avahi_address_from_sockaddr(sa, &a); - if (flx_dns_packet_is_query(p)) { + if (avahi_dns_packet_is_query(p)) { gboolean legacy_unicast = FALSE; - if (flx_dns_packet_get_field(p, FLX_DNS_FIELD_QDCOUNT) == 0 || - flx_dns_packet_get_field(p, FLX_DNS_FIELD_ARCOUNT) != 0) { + if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) == 0 || + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT) != 0) { g_warning("Invalid query packet."); return; } - if (port != FLX_MDNS_PORT) { + if (port != AVAHI_MDNS_PORT) { /* Legacy Unicast */ - if ((flx_dns_packet_get_field(p, FLX_DNS_FIELD_ANCOUNT) != 0 || - flx_dns_packet_get_field(p, FLX_DNS_FIELD_NSCOUNT) != 0)) { + if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 || + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0)) { g_warning("Invalid legacy unicast query packet."); return; } @@ -380,7 +380,7 @@ static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, g_message("Handled query"); } else { - if (port != FLX_MDNS_PORT) { + if (port != AVAHI_MDNS_PORT) { g_warning("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol); return; } @@ -391,9 +391,9 @@ static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, return; } - if (flx_dns_packet_get_field(p, FLX_DNS_FIELD_QDCOUNT) != 0 || - flx_dns_packet_get_field(p, FLX_DNS_FIELD_ANCOUNT) == 0 || - flx_dns_packet_get_field(p, FLX_DNS_FIELD_NSCOUNT) != 0) { + if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) != 0 || + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 || + avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0) { g_warning("Invalid response packet."); return; } @@ -403,26 +403,26 @@ static void dispatch_packet(flxServer *s, flxDnsPacket *p, struct sockaddr *sa, } } -static void work(flxServer *s) { +static void work(AvahiServer *s) { struct sockaddr_in6 sa6; struct sockaddr_in sa; - flxDnsPacket *p; + AvahiDnsPacket *p; gint iface = -1; guint8 ttl; g_assert(s); if (s->pollfd_ipv4.revents & G_IO_IN) { - if ((p = flx_recv_dns_packet_ipv4(s->fd_ipv4, &sa, &iface, &ttl))) { + if ((p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &sa, &iface, &ttl))) { dispatch_packet(s, p, (struct sockaddr*) &sa, iface, ttl); - flx_dns_packet_free(p); + avahi_dns_packet_free(p); } } if (s->pollfd_ipv6.revents & G_IO_IN) { - if ((p = flx_recv_dns_packet_ipv6(s->fd_ipv6, &sa6, &iface, &ttl))) { + if ((p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &sa6, &iface, &ttl))) { dispatch_packet(s, p, (struct sockaddr*) &sa6, iface, ttl); - flx_dns_packet_free(p); + avahi_dns_packet_free(p); } } } @@ -436,20 +436,20 @@ static gboolean prepare_func(GSource *source, gint *timeout) { } static gboolean check_func(GSource *source) { - flxServer* s; + AvahiServer* s; g_assert(source); - s = *((flxServer**) (((guint8*) source) + sizeof(GSource))); + s = *((AvahiServer**) (((guint8*) source) + sizeof(GSource))); g_assert(s); return (s->pollfd_ipv4.revents | s->pollfd_ipv6.revents) & (G_IO_IN | G_IO_HUP | G_IO_ERR); } static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer user_data) { - flxServer* s; + AvahiServer* s; g_assert(source); - s = *((flxServer**) (((guint8*) source) + sizeof(GSource))); + s = *((AvahiServer**) (((guint8*) source) + sizeof(GSource))); g_assert(s); work(s); @@ -458,34 +458,34 @@ static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer us return TRUE; } -static void add_default_entries(flxServer *s) { +static void add_default_entries(AvahiServer *s) { gint length = 0; struct utsname utsname; gchar *hinfo; - flxAddress a; - flxRecord *r; + AvahiAddress a; + AvahiRecord *r; g_assert(s); /* Fill in HINFO rr */ - r = flx_record_new_full(s->hostname, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_HINFO); + r = avahi_record_new_full(s->hostname, 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)); - flx_server_add(s, NULL, 0, AF_UNSPEC, FLX_ENTRY_UNIQUE, r); - flx_record_unref(r); + avahi_server_add(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, r); + avahi_record_unref(r); /* Add localhost entries */ - flx_address_parse("127.0.0.1", AF_INET, &a); - flx_server_add_address(s, NULL, 0, AF_UNSPEC, FLX_ENTRY_UNIQUE|FLX_ENTRY_NOPROBE|FLX_ENTRY_NOANNOUNCE, "localhost", &a); + avahi_address_parse("127.0.0.1", AF_INET, &a); + avahi_server_add_address(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE|AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "localhost", &a); - flx_address_parse("::1", AF_INET6, &a); - flx_server_add_address(s, NULL, 0, AF_UNSPEC, FLX_ENTRY_UNIQUE|FLX_ENTRY_NOPROBE|FLX_ENTRY_NOANNOUNCE, "ip6-localhost", &a); + avahi_address_parse("::1", AF_INET6, &a); + avahi_server_add_address(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE|AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "ip6-localhost", &a); } -flxServer *flx_server_new(GMainContext *c) { +AvahiServer *avahi_server_new(GMainContext *c) { gchar *hn, *e; - flxServer *s; + AvahiServer *s; static GSourceFuncs source_funcs = { prepare_func, @@ -496,13 +496,13 @@ flxServer *flx_server_new(GMainContext *c) { NULL }; - s = g_new(flxServer, 1); + s = g_new(AvahiServer, 1); s->ignore_bad_ttl = FALSE; s->need_entry_cleanup = s->need_group_cleanup = FALSE; - s->fd_ipv4 = flx_open_socket_ipv4(); - s->fd_ipv6 = flx_open_socket_ipv6(); + s->fd_ipv4 = avahi_open_socket_ipv4(); + s->fd_ipv6 = avahi_open_socket_ipv6(); if (s->fd_ipv6 < 0 && s->fd_ipv4 < 0) { g_critical("Failed to create IP sockets.\n"); @@ -520,28 +520,28 @@ flxServer *flx_server_new(GMainContext *c) { else s->context = g_main_context_default(); - FLX_LLIST_HEAD_INIT(flxEntry, s->entries); - s->entries_by_key = g_hash_table_new((GHashFunc) flx_key_hash, (GEqualFunc) flx_key_equal); - FLX_LLIST_HEAD_INIT(flxGroup, s->groups); + AVAHI_LLIST_HEAD_INIT(AvahiEntry, s->entries); + s->entries_by_key = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal); + AVAHI_LLIST_HEAD_INIT(AvahiGroup, s->groups); - FLX_LLIST_HEAD_INIT(flxSubscription, s->subscriptions); - s->subscription_hashtable = g_hash_table_new((GHashFunc) flx_key_hash, (GEqualFunc) flx_key_equal); + AVAHI_LLIST_HEAD_INIT(AvahiSubscription, s->subscriptions); + s->subscription_hashtable = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal); /* Get host name */ - hn = flx_get_host_name(); + hn = avahi_get_host_name(); hn[strcspn(hn, ".")] = 0; s->hostname = g_strdup_printf("%s.local.", hn); g_free(hn); - s->time_event_queue = flx_time_event_queue_new(s->context, G_PRIORITY_DEFAULT+10); /* Slightly less priority than the FDs */ - s->monitor = flx_interface_monitor_new(s); - flx_interface_monitor_sync(s->monitor); + 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 */ - s->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(flxServer*)); - *((flxServer**) (((guint8*) s->source) + sizeof(GSource))) = s; + s->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(AvahiServer*)); + *((AvahiServer**) (((guint8*) s->source) + sizeof(GSource))) = s; memset(&s->pollfd_ipv4, 0, sizeof(s->pollfd_ipv4)); s->pollfd_ipv4.fd = s->fd_ipv4; @@ -558,24 +558,24 @@ flxServer *flx_server_new(GMainContext *c) { return s; } -void flx_server_free(flxServer* s) { +void avahi_server_free(AvahiServer* s) { g_assert(s); while(s->entries) free_entry(s, s->entries); - flx_interface_monitor_free(s->monitor); + avahi_interface_monitor_free(s->monitor); while (s->groups) free_group(s, s->groups); while (s->subscriptions) - flx_subscription_free(s->subscriptions); + avahi_subscription_free(s->subscriptions); g_hash_table_destroy(s->subscription_hashtable); g_hash_table_destroy(s->entries_by_key); - flx_time_event_queue_free(s->time_event_queue); + avahi_time_event_queue_free(s->time_event_queue); if (s->fd_ipv4 >= 0) close(s->fd_ipv4); @@ -591,46 +591,46 @@ void flx_server_free(flxServer* s) { g_free(s); } -void flx_server_add( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, - flxRecord *r) { + AvahiEntryFlags flags, + AvahiRecord *r) { - flxEntry *e, *t; + AvahiEntry *e, *t; g_assert(s); g_assert(r); - g_assert(r->key->type != FLX_DNS_TYPE_ANY); + g_assert(r->key->type != AVAHI_DNS_TYPE_ANY); - e = g_new(flxEntry, 1); + e = g_new(AvahiEntry, 1); e->server = s; - e->record = flx_record_ref(r); + e->record = avahi_record_ref(r); e->group = g; e->interface = interface; e->protocol = protocol; e->flags = flags; e->dead = FALSE; - FLX_LLIST_HEAD_INIT(flxAnnouncement, e->announcements); + AVAHI_LLIST_HEAD_INIT(AvahiAnnouncement, e->announcements); - FLX_LLIST_PREPEND(flxEntry, entries, s->entries, e); + AVAHI_LLIST_PREPEND(AvahiEntry, entries, s->entries, e); /* Insert into hash table indexed by name */ t = g_hash_table_lookup(s->entries_by_key, e->record->key); - FLX_LLIST_PREPEND(flxEntry, by_key, t, e); + AVAHI_LLIST_PREPEND(AvahiEntry, by_key, t, e); g_hash_table_replace(s->entries_by_key, e->record->key, t); /* Insert into group list */ if (g) - FLX_LLIST_PREPEND(flxEntry, by_group, g->entries, e); + AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e); - flx_announce_entry(s, e); + avahi_announce_entry(s, e); } -const flxRecord *flx_server_iterate(flxServer *s, flxEntryGroup *g, void **state) { - flxEntry **e = (flxEntry**) state; +const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state) { + AvahiEntry **e = (AvahiEntry**) state; g_assert(s); g_assert(e); @@ -643,11 +643,11 @@ const flxRecord *flx_server_iterate(flxServer *s, flxEntryGroup *g, void **state if (!*e) return NULL; - return flx_record_ref((*e)->record); + return avahi_record_ref((*e)->record); } -void flx_server_dump(flxServer *s, FILE *f) { - flxEntry *e; +void avahi_server_dump(AvahiServer *s, FILE *f) { + AvahiEntry *e; g_assert(s); g_assert(f); @@ -659,124 +659,124 @@ void flx_server_dump(flxServer *s, FILE *f) { if (e->dead) continue; - t = flx_record_to_string(e->record); + t = avahi_record_to_string(e->record); fprintf(f, "%s ; iface=%i proto=%i\n", t, e->interface, e->protocol); g_free(t); } - flx_dump_caches(s->monitor, f); + avahi_dump_caches(s->monitor, f); } -void flx_server_add_ptr( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_ptr( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, const gchar *dest) { - flxRecord *r; + AvahiRecord *r; g_assert(dest); - r = flx_record_new_full(name ? name : s->hostname, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_PTR); - r->data.ptr.name = flx_normalize_name(dest); - flx_server_add(s, g, interface, protocol, flags, r); - flx_record_unref(r); + r = avahi_record_new_full(name ? name : s->hostname, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR); + r->data.ptr.name = avahi_normalize_name(dest); + avahi_server_add(s, g, interface, protocol, flags, r); + avahi_record_unref(r); } -void flx_server_add_address( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_address( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, - flxAddress *a) { + AvahiAddress *a) { gchar *n = NULL; g_assert(s); g_assert(a); - name = name ? (n = flx_normalize_name(name)) : s->hostname; + name = name ? (n = avahi_normalize_name(name)) : s->hostname; if (a->family == AF_INET) { gchar *reverse; - flxRecord *r; + AvahiRecord *r; - r = flx_record_new_full(name, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_A); + r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A); r->data.a.address = a->data.ipv4; - flx_server_add(s, g, interface, protocol, flags, r); - flx_record_unref(r); + avahi_server_add(s, g, interface, protocol, flags, r); + avahi_record_unref(r); - reverse = flx_reverse_lookup_name_ipv4(&a->data.ipv4); + reverse = avahi_reverse_lookup_name_ipv4(&a->data.ipv4); g_assert(reverse); - flx_server_add_ptr(s, g, interface, protocol, flags, reverse, name); + avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name); g_free(reverse); } else { gchar *reverse; - flxRecord *r; + AvahiRecord *r; - r = flx_record_new_full(name, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_AAAA); + r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA); r->data.aaaa.address = a->data.ipv6; - flx_server_add(s, g, interface, protocol, flags, r); - flx_record_unref(r); + avahi_server_add(s, g, interface, protocol, flags, r); + avahi_record_unref(r); - reverse = flx_reverse_lookup_name_ipv6_arpa(&a->data.ipv6); + reverse = avahi_reverse_lookup_name_ipv6_arpa(&a->data.ipv6); g_assert(reverse); - flx_server_add_ptr(s, g, interface, protocol, flags, reverse, name); + avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name); g_free(reverse); - reverse = flx_reverse_lookup_name_ipv6_int(&a->data.ipv6); + reverse = avahi_reverse_lookup_name_ipv6_int(&a->data.ipv6); g_assert(reverse); - flx_server_add_ptr(s, g, interface, protocol, flags, reverse, name); + avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name); g_free(reverse); } g_free(n); } -void flx_server_add_text_strlst( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text_strlst( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, - flxStringList *strlst) { + AvahiStringList *strlst) { - flxRecord *r; + AvahiRecord *r; g_assert(s); - r = flx_record_new_full(name ? name : s->hostname, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_TXT); + r = avahi_record_new_full(name ? name : s->hostname, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT); r->data.txt.string_list = strlst; - flx_server_add(s, g, interface, protocol, flags, r); - flx_record_unref(r); + avahi_server_add(s, g, interface, protocol, flags, r); + avahi_record_unref(r); } -void flx_server_add_text_va( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text_va( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, va_list va) { g_assert(s); - flx_server_add_text_strlst(s, g, interface, protocol, flags, name, flx_string_list_new_va(va)); + avahi_server_add_text_strlst(s, g, interface, protocol, flags, name, avahi_string_list_new_va(va)); } -void flx_server_add_text( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_text( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, - flxEntryFlags flags, + AvahiEntryFlags flags, const gchar *name, ...) { @@ -785,7 +785,7 @@ void flx_server_add_text( g_assert(s); va_start(va, name); - flx_server_add_text_va(s, g, interface, protocol, flags, name, va); + avahi_server_add_text_va(s, g, interface, protocol, flags, name, va); va_end(va); } @@ -811,9 +811,9 @@ static void escape_service_name(gchar *d, guint size, const gchar *s) { *(d++) = 0; } -void flx_server_add_service_strlst( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service_strlst( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -821,10 +821,10 @@ void flx_server_add_service_strlst( const gchar *domain, const gchar *host, guint16 port, - flxStringList *strlst) { + AvahiStringList *strlst) { gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256]; - flxRecord *r; + AvahiRecord *r; g_assert(s); g_assert(type); @@ -844,25 +844,25 @@ void flx_server_add_service_strlst( snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain); snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain); - flx_server_add_ptr(s, g, interface, protocol, FLX_ENTRY_NULL, ptr_name, svc_name); + avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, ptr_name, svc_name); - r = flx_record_new_full(svc_name, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_SRV); + r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV); r->data.srv.priority = 0; r->data.srv.weight = 0; r->data.srv.port = port; - r->data.srv.name = flx_normalize_name(host); - flx_server_add(s, g, interface, protocol, FLX_ENTRY_UNIQUE, r); - flx_record_unref(r); + r->data.srv.name = avahi_normalize_name(host); + avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r); + avahi_record_unref(r); - flx_server_add_text_strlst(s, g, interface, protocol, FLX_ENTRY_UNIQUE, svc_name, strlst); + avahi_server_add_text_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, svc_name, strlst); snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain); - flx_server_add_ptr(s, g, interface, protocol, FLX_ENTRY_NULL, enum_ptr, ptr_name); + avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, enum_ptr, ptr_name); } -void flx_server_add_service_va( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service_va( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -876,12 +876,12 @@ void flx_server_add_service_va( g_assert(type); g_assert(name); - flx_server_add_service(s, g, interface, protocol, type, name, domain, host, port, flx_string_list_new_va(va)); + avahi_server_add_service(s, g, interface, protocol, type, name, domain, host, port, avahi_string_list_new_va(va)); } -void flx_server_add_service( - flxServer *s, - flxEntryGroup *g, +void avahi_server_add_service( + AvahiServer *s, + AvahiEntryGroup *g, gint interface, guchar protocol, const gchar *type, @@ -898,43 +898,43 @@ void flx_server_add_service( g_assert(name); va_start(va, port); - flx_server_add_service_va(s, g, interface, protocol, type, name, domain, host, port, va); + avahi_server_add_service_va(s, g, interface, protocol, type, name, domain, host, port, va); va_end(va); } -static void post_query_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) { - flxKey *k = userdata; +static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { + AvahiKey *k = userdata; g_assert(m); g_assert(i); g_assert(k); - flx_interface_post_query(i, k, FALSE); + avahi_interface_post_query(i, k, FALSE); } -void flx_server_post_query(flxServer *s, gint interface, guchar protocol, flxKey *key) { +void avahi_server_post_query(AvahiServer *s, gint interface, guchar protocol, AvahiKey *key) { g_assert(s); g_assert(key); - flx_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key); + avahi_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key); } struct tmpdata { - flxRecord *record; + AvahiRecord *record; gboolean flush_cache; }; -static void post_response_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) { +static void post_response_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { struct tmpdata *tmpdata = userdata; g_assert(m); g_assert(i); g_assert(tmpdata); - flx_interface_post_response(i, NULL, tmpdata->record, tmpdata->flush_cache, FALSE); + avahi_interface_post_response(i, NULL, tmpdata->record, tmpdata->flush_cache, FALSE); } -void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flxRecord *record, gboolean flush_cache) { +void avahi_server_post_response(AvahiServer *s, gint interface, guchar protocol, AvahiRecord *record, gboolean flush_cache) { struct tmpdata tmpdata; g_assert(s); @@ -943,10 +943,10 @@ void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flx tmpdata.record = record; tmpdata.flush_cache = flush_cache; - flx_interface_monitor_walk(s->monitor, interface, protocol, post_response_callback, &tmpdata); + avahi_interface_monitor_walk(s->monitor, interface, protocol, post_response_callback, &tmpdata); } -void flx_entry_group_change_state(flxEntryGroup *g, flxEntryGroupState state) { +void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state) { g_assert(g); g->state = state; @@ -957,25 +957,25 @@ void flx_entry_group_change_state(flxEntryGroup *g, flxEntryGroupState state) { } } -flxEntryGroup *flx_entry_group_new(flxServer *s, flxEntryGroupCallback callback, gpointer userdata) { - flxEntryGroup *g; +AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata) { + AvahiEntryGroup *g; g_assert(s); - g = g_new(flxEntryGroup, 1); + g = g_new(AvahiEntryGroup, 1); g->server = s; g->callback = callback; g->userdata = userdata; g->dead = FALSE; - g->state = FLX_ENTRY_GROUP_UNCOMMITED; + g->state = AVAHI_ENTRY_GROUP_UNCOMMITED; g->n_probing = 0; - FLX_LLIST_HEAD_INIT(flxEntry, g->entries); + AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries); - FLX_LLIST_PREPEND(flxEntryGroup, groups, s->groups, g); + AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, s->groups, g); return g; } -void flx_entry_group_free(flxEntryGroup *g) { +void avahi_entry_group_free(AvahiEntryGroup *g) { g_assert(g); g_assert(g->server); @@ -983,30 +983,30 @@ void flx_entry_group_free(flxEntryGroup *g) { g->server->need_group_cleanup = TRUE; } -void flx_entry_group_commit(flxEntryGroup *g) { - flxEntry *e; +void avahi_entry_group_commit(AvahiEntryGroup *g) { + AvahiEntry *e; g_assert(g); g_assert(!g->dead); - if (g->state != FLX_ENTRY_GROUP_UNCOMMITED) + if (g->state != AVAHI_ENTRY_GROUP_UNCOMMITED) return; - flx_entry_group_change_state(g, FLX_ENTRY_GROUP_REGISTERING); - flx_announce_group(g->server, g); - flx_entry_group_check_probed(g, FALSE); + avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING); + avahi_announce_group(g->server, g); + avahi_entry_group_check_probed(g, FALSE); } -gboolean flx_entry_commited(flxEntry *e) { +gboolean avahi_entry_commited(AvahiEntry *e) { g_assert(e); g_assert(!e->dead); return !e->group || - e->group->state == FLX_ENTRY_GROUP_REGISTERING || - e->group->state == FLX_ENTRY_GROUP_ESTABLISHED; + e->group->state == AVAHI_ENTRY_GROUP_REGISTERING || + e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED; } -flxEntryGroupState flx_entry_group_get_state(flxEntryGroup *g) { +AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g) { g_assert(g); g_assert(!g->dead); @@ -1,7 +1,7 @@ -#ifndef fooflxserverhfoo -#define fooflxserverhfoo +#ifndef fooAvahiserverhfoo +#define fooAvahiserverhfoo -#include "flx.h" +#include "Avahi.h" #include "iface.h" #include "prioq.h" #include "llist.h" @@ -9,53 +9,53 @@ #include "announce.h" #include "subscribe.h" -struct _flxEntry { - flxServer *server; - flxEntryGroup *group; +struct _AvahiEntry { + AvahiServer *server; + AvahiEntryGroup *group; gboolean dead; - flxEntryFlags flags; - flxRecord *record; + AvahiEntryFlags flags; + AvahiRecord *record; gint interface; guchar protocol; - FLX_LLIST_FIELDS(flxEntry, entries); - FLX_LLIST_FIELDS(flxEntry, by_key); - FLX_LLIST_FIELDS(flxEntry, by_group); + AVAHI_LLIST_FIELDS(AvahiEntry, entries); + AVAHI_LLIST_FIELDS(AvahiEntry, by_key); + AVAHI_LLIST_FIELDS(AvahiEntry, by_group); - FLX_LLIST_HEAD(flxAnnouncement, announcements); + AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements); }; -struct _flxEntryGroup { - flxServer *server; +struct _AvahiEntryGroup { + AvahiServer *server; gboolean dead; - flxEntryGroupState state; + AvahiEntryGroupState state; gpointer userdata; - flxEntryGroupCallback callback; + AvahiEntryGroupCallback callback; guint n_probing; - FLX_LLIST_FIELDS(flxEntryGroup, groups); - FLX_LLIST_HEAD(flxEntry, entries); + AVAHI_LLIST_FIELDS(AvahiEntryGroup, groups); + AVAHI_LLIST_HEAD(AvahiEntry, entries); }; -struct _flxServer { +struct _AvahiServer { GMainContext *context; - flxInterfaceMonitor *monitor; + AvahiInterfaceMonitor *monitor; - FLX_LLIST_HEAD(flxEntry, entries); + AVAHI_LLIST_HEAD(AvahiEntry, entries); GHashTable *entries_by_key; - FLX_LLIST_HEAD(flxEntryGroup, groups); + AVAHI_LLIST_HEAD(AvahiEntryGroup, groups); - FLX_LLIST_HEAD(flxSubscription, subscriptions); + AVAHI_LLIST_HEAD(AvahiSubscription, subscriptions); GHashTable *subscription_hashtable; gboolean need_entry_cleanup, need_group_cleanup; - flxTimeEventQueue *time_event_queue; + AvahiTimeEventQueue *time_event_queue; gchar *hostname; @@ -67,13 +67,13 @@ struct _flxServer { gboolean ignore_bad_ttl; }; -gboolean flx_server_entry_match_interface(flxEntry *e, flxInterface *i); +gboolean avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i); -void flx_server_post_query(flxServer *s, gint interface, guchar protocol, flxKey *key); -void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flxRecord *record, gboolean flush_cache); +void avahi_server_post_query(AvahiServer *s, gint interface, guchar protocol, AvahiKey *key); +void avahi_server_post_response(AvahiServer *s, gint interface, guchar protocol, AvahiRecord *record, gboolean flush_cache); -void flx_entry_group_change_state(flxEntryGroup *g, flxEntryGroupState state); +void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state); -gboolean flx_entry_commited(flxEntry *e); +gboolean avahi_entry_commited(AvahiEntry *e); #endif @@ -21,7 +21,7 @@ static void mdns_mcast_group_ipv4(struct sockaddr_in *ret_sa) { memset(ret_sa, 0, sizeof(struct sockaddr_in)); ret_sa->sin_family = AF_INET; - ret_sa->sin_port = htons(FLX_MDNS_PORT); + ret_sa->sin_port = htons(AVAHI_MDNS_PORT); inet_pton(AF_INET, "224.0.0.251", &ret_sa->sin_addr); } @@ -32,11 +32,11 @@ static void mdns_mcast_group_ipv6(struct sockaddr_in6 *ret_sa) { memset(ret_sa, 0, sizeof(struct sockaddr_in6)); ret_sa->sin6_family = AF_INET6; - ret_sa->sin6_port = htons(FLX_MDNS_PORT); + ret_sa->sin6_port = htons(AVAHI_MDNS_PORT); inet_pton(AF_INET6, "ff02::fb", &ret_sa->sin6_addr); } -int flx_mdns_mcast_join_ipv4 (int index, int fd) +int avahi_mdns_mcast_join_ipv4 (int index, int fd) { struct ip_mreqn mreq; struct sockaddr_in sa; @@ -55,7 +55,7 @@ int flx_mdns_mcast_join_ipv4 (int index, int fd) return 0; } -int flx_mdns_mcast_join_ipv6 (int index, int fd) +int avahi_mdns_mcast_join_ipv6 (int index, int fd) { struct ipv6_mreq mreq6; struct sockaddr_in6 sa6; @@ -74,7 +74,7 @@ int flx_mdns_mcast_join_ipv6 (int index, int fd) return 0; } -int flx_mdns_mcast_leave_ipv4 (int index, int fd) +int avahi_mdns_mcast_leave_ipv4 (int index, int fd) { struct ip_mreqn mreq; struct sockaddr_in sa; @@ -93,7 +93,7 @@ int flx_mdns_mcast_leave_ipv4 (int index, int fd) return 0; } -int flx_mdns_mcast_leave_ipv6 (int index, int fd) +int avahi_mdns_mcast_leave_ipv6 (int index, int fd) { struct ipv6_mreq mreq6; struct sockaddr_in6 sa6; @@ -112,7 +112,7 @@ int flx_mdns_mcast_leave_ipv6 (int index, int fd) return 0; } -gint flx_open_socket_ipv4(void) { +gint avahi_open_socket_ipv4(void) { struct sockaddr_in sa, local; int fd = -1, ttl, yes; @@ -148,7 +148,7 @@ gint flx_open_socket_ipv4(void) { memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; - local.sin_port = htons(FLX_MDNS_PORT); + local.sin_port = htons(AVAHI_MDNS_PORT); if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) { g_warning("bind() failed: %s\n", strerror(errno)); @@ -167,12 +167,12 @@ gint flx_open_socket_ipv4(void) { goto fail; } - if (flx_set_cloexec(fd) < 0) { + if (avahi_set_cloexec(fd) < 0) { g_warning("FD_CLOEXEC failed: %s\n", strerror(errno)); goto fail; } - if (flx_set_nonblock(fd) < 0) { + if (avahi_set_nonblock(fd) < 0) { g_warning("O_NONBLOCK failed: %s\n", strerror(errno)); goto fail; } @@ -186,7 +186,7 @@ fail: return -1; } -gint flx_open_socket_ipv6(void) { +gint avahi_open_socket_ipv6(void) { struct sockaddr_in6 sa, local; int fd = -1, ttl, yes; @@ -229,7 +229,7 @@ gint flx_open_socket_ipv6(void) { memset(&local, 0, sizeof(local)); local.sin6_family = AF_INET6; - local.sin6_port = htons(FLX_MDNS_PORT); + local.sin6_port = htons(AVAHI_MDNS_PORT); if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) { g_warning("bind() failed: %s\n", strerror(errno)); @@ -248,12 +248,12 @@ gint flx_open_socket_ipv6(void) { goto fail; } - if (flx_set_cloexec(fd) < 0) { + if (avahi_set_cloexec(fd) < 0) { g_warning("FD_CLOEXEC failed: %s\n", strerror(errno)); goto fail; } - if (flx_set_nonblock(fd) < 0) { + if (avahi_set_nonblock(fd) < 0) { g_warning("O_NONBLOCK failed: %s\n", strerror(errno)); goto fail; } @@ -281,14 +281,14 @@ static gint sendmsg_loop(gint fd, struct msghdr *msg, gint flags) { return -1; } - if (flx_wait_for_write(fd) < 0) + if (avahi_wait_for_write(fd) < 0) return -1; } return 0; } -gint flx_send_dns_packet_ipv4(gint fd, gint interface, flxDnsPacket *p) { +gint avahi_send_dns_packet_ipv4(gint fd, gint interface, AvahiDnsPacket *p) { struct sockaddr_in sa; struct msghdr msg; struct iovec io; @@ -299,12 +299,12 @@ gint flx_send_dns_packet_ipv4(gint fd, gint interface, flxDnsPacket *p) { g_assert(fd >= 0); g_assert(p); - g_assert(flx_dns_packet_check_valid(p) >= 0); + g_assert(avahi_dns_packet_check_valid(p) >= 0); mdns_mcast_group_ipv4(&sa); memset(&io, 0, sizeof(io)); - io.iov_base = FLX_DNS_PACKET_DATA(p); + io.iov_base = AVAHI_DNS_PACKET_DATA(p); io.iov_len = p->size; memset(cmsg_data, 0, sizeof(cmsg_data)); @@ -328,7 +328,7 @@ gint flx_send_dns_packet_ipv4(gint fd, gint interface, flxDnsPacket *p) { return sendmsg_loop(fd, &msg, MSG_DONTROUTE); } -gint flx_send_dns_packet_ipv6(gint fd, gint interface, flxDnsPacket *p) { +gint avahi_send_dns_packet_ipv6(gint fd, gint interface, AvahiDnsPacket *p) { struct sockaddr_in6 sa; struct msghdr msg; struct iovec io; @@ -339,12 +339,12 @@ gint flx_send_dns_packet_ipv6(gint fd, gint interface, flxDnsPacket *p) { g_assert(fd >= 0); g_assert(p); - g_assert(flx_dns_packet_check_valid(p) >= 0); + g_assert(avahi_dns_packet_check_valid(p) >= 0); mdns_mcast_group_ipv6(&sa); memset(&io, 0, sizeof(io)); - io.iov_base = FLX_DNS_PACKET_DATA(p); + io.iov_base = AVAHI_DNS_PACKET_DATA(p); io.iov_len = p->size; memset(cmsg_data, 0, sizeof(cmsg_data)); @@ -368,8 +368,8 @@ gint flx_send_dns_packet_ipv6(gint fd, gint interface, flxDnsPacket *p) { return sendmsg_loop(fd, &msg, MSG_DONTROUTE); } -flxDnsPacket* flx_recv_dns_packet_ipv4(gint fd, struct sockaddr_in *ret_sa, gint *ret_iface, guint8* ret_ttl) { - flxDnsPacket *p= NULL; +AvahiDnsPacket* avahi_recv_dns_packet_ipv4(gint fd, struct sockaddr_in *ret_sa, gint *ret_iface, guint8* ret_ttl) { + AvahiDnsPacket *p= NULL; struct msghdr msg; struct iovec io; uint8_t aux[64]; @@ -382,9 +382,9 @@ flxDnsPacket* flx_recv_dns_packet_ipv4(gint fd, struct sockaddr_in *ret_sa, gint g_assert(ret_iface); g_assert(ret_ttl); - p = flx_dns_packet_new(0); + p = avahi_dns_packet_new(0); - io.iov_base = FLX_DNS_PACKET_DATA(p); + io.iov_base = AVAHI_DNS_PACKET_DATA(p); io.iov_len = p->max_size; memset(&msg, 0, sizeof(msg)); @@ -422,13 +422,13 @@ flxDnsPacket* flx_recv_dns_packet_ipv4(gint fd, struct sockaddr_in *ret_sa, gint fail: if (p) - flx_dns_packet_free(p); + avahi_dns_packet_free(p); return NULL; } -flxDnsPacket* flx_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6 *ret_sa, gint *ret_iface, guint8* ret_ttl) { - flxDnsPacket *p = NULL; +AvahiDnsPacket* avahi_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6 *ret_sa, gint *ret_iface, guint8* ret_ttl) { + AvahiDnsPacket *p = NULL; struct msghdr msg; struct iovec io; uint8_t aux[64]; @@ -441,9 +441,9 @@ flxDnsPacket* flx_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6 *ret_sa, gin g_assert(ret_iface); g_assert(ret_ttl); - p = flx_dns_packet_new(0); + p = avahi_dns_packet_new(0); - io.iov_base = FLX_DNS_PACKET_DATA(p); + io.iov_base = AVAHI_DNS_PACKET_DATA(p); io.iov_len = p->max_size; memset(&msg, 0, sizeof(msg)); @@ -481,7 +481,7 @@ flxDnsPacket* flx_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6 *ret_sa, gin fail: if (p) - flx_dns_packet_free(p); + avahi_dns_packet_free(p); return NULL; } @@ -5,23 +5,23 @@ #include "dns.h" -#define FLX_MDNS_PORT 5353 +#define AVAHI_MDNS_PORT 5353 -gint flx_open_socket_ipv4(void); -gint flx_open_socket_ipv6(void); +gint avahi_open_socket_ipv4(void); +gint avahi_open_socket_ipv6(void); -gint flx_send_dns_packet_ipv4(gint fd, gint iface, flxDnsPacket *p); -gint flx_send_dns_packet_ipv6(gint fd, gint iface, flxDnsPacket *p); +gint avahi_send_dns_packet_ipv4(gint fd, gint iface, AvahiDnsPacket *p); +gint avahi_send_dns_packet_ipv6(gint fd, gint iface, AvahiDnsPacket *p); -flxDnsPacket *flx_recv_dns_packet_ipv4(gint fd, struct sockaddr_in*ret_sa, gint *ret_iface, guint8 *ret_ttl); -flxDnsPacket *flx_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6*ret_sa, gint *ret_iface, guint8 *ret_ttl); +AvahiDnsPacket *avahi_recv_dns_packet_ipv4(gint fd, struct sockaddr_in*ret_sa, gint *ret_iface, guint8 *ret_ttl); +AvahiDnsPacket *avahi_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6*ret_sa, gint *ret_iface, guint8 *ret_ttl); -int flx_mdns_mcast_join_ipv4(int index, int fd); -int flx_mdns_mcast_join_ipv6(int index, int fd); +int avahi_mdns_mcast_join_ipv4(int index, int fd); +int avahi_mdns_mcast_join_ipv6(int index, int fd); -int flx_mdns_mcast_leave_ipv4(int index, int fd); -int flx_mdns_mcast_leave_ipv6(int index, int fd); +int avahi_mdns_mcast_leave_ipv4(int index, int fd); +int avahi_mdns_mcast_leave_ipv6(int index, int fd); #endif diff --git a/strlst-test.c b/strlst-test.c index e77eae8..5e28ce2 100644 --- a/strlst-test.c +++ b/strlst-test.c @@ -6,21 +6,21 @@ int main(int argc, char *argv[]) { gchar *t; guint8 data[1024]; - flxStringList *a = NULL, *b; + AvahiStringList *a = NULL, *b; guint size, n; - a = flx_string_list_add(a, "start"); - a = flx_string_list_add(a, "foo"); - a = flx_string_list_add(a, "bar"); - a = flx_string_list_add(a, "quux"); - a = flx_string_list_add_arbitrary(a, "null\0null", 9); - a = flx_string_list_add(a, "end"); + a = avahi_string_list_add(a, "start"); + a = avahi_string_list_add(a, "foo"); + a = avahi_string_list_add(a, "bar"); + a = avahi_string_list_add(a, "quux"); + a = avahi_string_list_add_arbitrary(a, "null\0null", 9); + a = avahi_string_list_add(a, "end"); - t = flx_string_list_to_string(a); + t = avahi_string_list_to_string(a); printf("--%s--\n", t); g_free(t); - size = flx_string_list_serialize(a, data, sizeof(data)); + size = avahi_string_list_serialize(a, data, sizeof(data)); printf("%u\n", size); @@ -33,26 +33,26 @@ int main(int argc, char *argv[]) { printf("\n"); - b = flx_string_list_parse(data, size); + b = avahi_string_list_parse(data, size); - g_assert(flx_string_list_equal(a, b)); + g_assert(avahi_string_list_equal(a, b)); - t = flx_string_list_to_string(b); + t = avahi_string_list_to_string(b); printf("--%s--\n", t); g_free(t); - flx_string_list_free(b); + avahi_string_list_free(b); - b = flx_string_list_copy(a); + b = avahi_string_list_copy(a); - g_assert(flx_string_list_equal(a, b)); + g_assert(avahi_string_list_equal(a, b)); - t = flx_string_list_to_string(b); + t = avahi_string_list_to_string(b); printf("--%s--\n", t); g_free(t); - flx_string_list_free(a); - flx_string_list_free(b); + avahi_string_list_free(a); + avahi_string_list_free(b); return 0; } @@ -3,26 +3,26 @@ #include "strlst.h" -flxStringList *flx_string_list_add_arbitrary(flxStringList *l, const guint8*text, guint size) { - flxStringList *n; +AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const guint8*text, guint size) { + AvahiStringList *n; g_assert(text); - n = g_malloc(sizeof(flxStringList) + size); + n = g_malloc(sizeof(AvahiStringList) + size); n->next = l; memcpy(n->text, text, n->size = size); return n; } -flxStringList *flx_string_list_add(flxStringList *l, const gchar *text) { +AvahiStringList *avahi_string_list_add(AvahiStringList *l, const gchar *text) { g_assert(text); - return flx_string_list_add_arbitrary(l, (const guint8*) text, strlen(text)); + return avahi_string_list_add_arbitrary(l, (const guint8*) text, strlen(text)); } -flxStringList *flx_string_list_parse(gconstpointer data, guint size) { - flxStringList *r = NULL; +AvahiStringList *avahi_string_list_parse(gconstpointer data, guint size) { + AvahiStringList *r = NULL; const guint8 *c; g_assert(data); @@ -34,7 +34,7 @@ flxStringList *flx_string_list_parse(gconstpointer data, guint size) { break; k = *(c++); - r = flx_string_list_add_arbitrary(r, c, k); + r = avahi_string_list_add_arbitrary(r, c, k); c += k; size -= 1 + k; @@ -43,8 +43,8 @@ flxStringList *flx_string_list_parse(gconstpointer data, guint size) { return r; } -void flx_string_list_free(flxStringList *l) { - flxStringList *n; +void avahi_string_list_free(AvahiStringList *l) { + AvahiStringList *n; while (l) { n = l->next; @@ -53,8 +53,8 @@ void flx_string_list_free(flxStringList *l) { } } -static flxStringList* string_list_reverse(flxStringList *l) { - flxStringList *r = NULL, *n; +static AvahiStringList* string_list_reverse(AvahiStringList *l) { + AvahiStringList *r = NULL, *n; while (l) { n = l->next; @@ -66,8 +66,8 @@ static flxStringList* string_list_reverse(flxStringList *l) { return r; } -gchar* flx_string_list_to_string(flxStringList *l) { - flxStringList *n; +gchar* avahi_string_list_to_string(AvahiStringList *l) { + AvahiStringList *n; guint s = 0; gchar *t, *e; @@ -100,12 +100,12 @@ gchar* flx_string_list_to_string(flxStringList *l) { return t; } -guint flx_string_list_serialize(flxStringList *l, gpointer data, guint size) { +guint avahi_string_list_serialize(AvahiStringList *l, gpointer data, guint size) { guint used = 0; if (data) { guint8 *c; - flxStringList *n; + AvahiStringList *n; g_assert(data); @@ -133,7 +133,7 @@ guint flx_string_list_serialize(flxStringList *l, gpointer data, guint size) { l = string_list_reverse(l); } else { - flxStringList *n; + AvahiStringList *n; for (n = l; n; n = n->next) { guint k; @@ -149,7 +149,7 @@ guint flx_string_list_serialize(flxStringList *l, gpointer data, guint size) { return used; } -gboolean flx_string_list_equal(flxStringList *a, flxStringList *b) { +gboolean avahi_string_list_equal(AvahiStringList *a, AvahiStringList *b) { for (;;) { if (!a && !b) @@ -169,50 +169,50 @@ gboolean flx_string_list_equal(flxStringList *a, flxStringList *b) { } } -flxStringList *flx_string_list_add_many(flxStringList *r, ...) { +AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...) { va_list va; va_start(va, r); - r = flx_string_list_add_many_va(r, va); + r = avahi_string_list_add_many_va(r, va); va_end(va); return r; } -flxStringList *flx_string_list_add_many_va(flxStringList *r, va_list va) { +AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va) { const gchar *txt; while ((txt = va_arg(va, const gchar*))) - r = flx_string_list_add(r, txt); + r = avahi_string_list_add(r, txt); return r; } -flxStringList *flx_string_list_new(const gchar *txt, ...) { +AvahiStringList *avahi_string_list_new(const gchar *txt, ...) { va_list va; - flxStringList *r = NULL; + AvahiStringList *r = NULL; if (txt) { - r = flx_string_list_add(r, txt); + r = avahi_string_list_add(r, txt); va_start(va, txt); - r = flx_string_list_add_many_va(r, va); + r = avahi_string_list_add_many_va(r, va); va_end(va); } return r; } -flxStringList *flx_string_list_new_va(va_list va) { - return flx_string_list_add_many_va(NULL, va); +AvahiStringList *avahi_string_list_new_va(va_list va) { + return avahi_string_list_add_many_va(NULL, va); } -flxStringList *flx_string_list_copy(flxStringList *l) { - flxStringList *r = NULL; +AvahiStringList *avahi_string_list_copy(AvahiStringList *l) { + AvahiStringList *r = NULL; for (; l; l = l->next) - r = flx_string_list_add_arbitrary(r, l->text, l->size); + r = avahi_string_list_add_arbitrary(r, l->text, l->size); return string_list_reverse(r); } @@ -3,32 +3,32 @@ #include <glib.h> -typedef struct _flxStringList flxStringList; +typedef struct _AvahiStringList AvahiStringList; -struct _flxStringList { - flxStringList *next; +struct _AvahiStringList { + AvahiStringList *next; guint size; guint8 text[1]; }; -flxStringList *flx_string_list_new(const gchar *txt, ...); -flxStringList *flx_string_list_new_va(va_list va); +AvahiStringList *avahi_string_list_new(const gchar *txt, ...); +AvahiStringList *avahi_string_list_new_va(va_list va); -void flx_string_list_free(flxStringList *l); +void avahi_string_list_free(AvahiStringList *l); -flxStringList *flx_string_list_add(flxStringList *l, const gchar *text); -flxStringList *flx_string_list_add_arbitrary(flxStringList *l, const guint8 *text, guint size); -flxStringList *flx_string_list_add_many(flxStringList *r, ...); -flxStringList *flx_string_list_add_many_va(flxStringList *r, va_list va); +AvahiStringList *avahi_string_list_add(AvahiStringList *l, const gchar *text); +AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const guint8 *text, guint size); +AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...); +AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va); -gchar* flx_string_list_to_string(flxStringList *l); +gchar* avahi_string_list_to_string(AvahiStringList *l); -guint flx_string_list_serialize(flxStringList *l, gpointer data, guint size); -flxStringList *flx_string_list_parse(gconstpointer data, guint size); +guint avahi_string_list_serialize(AvahiStringList *l, gpointer data, guint size); +AvahiStringList *avahi_string_list_parse(gconstpointer data, guint size); -gboolean flx_string_list_equal(flxStringList *a, flxStringList *b); +gboolean avahi_string_list_equal(AvahiStringList *a, AvahiStringList *b); -flxStringList *flx_string_list_copy(flxStringList *l); +AvahiStringList *avahi_string_list_copy(AvahiStringList *l); #endif diff --git a/subscribe.c b/subscribe.c index abd1620..902e966 100644 --- a/subscribe.c +++ b/subscribe.c @@ -1,31 +1,31 @@ #include "subscribe.h" #include "util.h" -static void elapse(flxTimeEvent *e, void *userdata) { - flxSubscription *s = userdata; +static void elapse(AvahiTimeEvent *e, void *userdata) { + AvahiSubscription *s = userdata; GTimeVal tv; gchar *t; g_assert(s); - flx_server_post_query(s->server, s->interface, s->protocol, s->key); + avahi_server_post_query(s->server, s->interface, s->protocol, s->key); if (s->n_query++ <= 8) s->sec_delay *= 2; - g_message("%i. Continuous querying for %s", s->n_query, t = flx_key_to_string(s->key)); + g_message("%i. Continuous querying for %s", s->n_query, t = avahi_key_to_string(s->key)); g_free(t); - flx_elapse_time(&tv, s->sec_delay*1000, 0); - flx_time_event_queue_update(s->server->time_event_queue, s->time_event, &tv); + avahi_elapse_time(&tv, s->sec_delay*1000, 0); + avahi_time_event_queue_update(s->server->time_event_queue, s->time_event, &tv); } struct cbdata { - flxSubscription *subscription; - flxInterface *interface; + AvahiSubscription *subscription; + AvahiInterface *interface; }; -static gpointer scan_cache_callback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata) { +static gpointer scan_cache_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, gpointer userdata) { struct cbdata *cbdata = userdata; g_assert(c); @@ -38,36 +38,36 @@ static gpointer scan_cache_callback(flxCache *c, flxKey *pattern, flxCacheEntry e->record, cbdata->interface->hardware->index, cbdata->interface->protocol, - FLX_SUBSCRIPTION_NEW, + AVAHI_SUBSCRIPTION_NEW, cbdata->subscription->userdata); return NULL; } -static void scan_interface_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) { - flxSubscription *s = userdata; +static void scan_interface_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) { + AvahiSubscription *s = userdata; struct cbdata cbdata = { s, i }; g_assert(m); g_assert(i); g_assert(s); - flx_cache_walk(i->cache, s->key, scan_cache_callback, &cbdata); + avahi_cache_walk(i->cache, s->key, scan_cache_callback, &cbdata); } -flxSubscription *flx_subscription_new(flxServer *server, flxKey *key, gint interface, guchar protocol, flxSubscriptionCallback callback, gpointer userdata) { - flxSubscription *s, *t; +AvahiSubscription *avahi_subscription_new(AvahiServer *server, AvahiKey *key, gint interface, guchar protocol, AvahiSubscriptionCallback callback, gpointer userdata) { + AvahiSubscription *s, *t; GTimeVal tv; g_assert(server); g_assert(key); g_assert(callback); - g_assert(!flx_key_is_pattern(key)); + g_assert(!avahi_key_is_pattern(key)); - s = g_new(flxSubscription, 1); + s = g_new(AvahiSubscription, 1); s->server = server; - s->key = flx_key_ref(key); + s->key = avahi_key_ref(key); s->interface = interface; s->protocol = protocol; s->callback = callback; @@ -75,58 +75,58 @@ flxSubscription *flx_subscription_new(flxServer *server, flxKey *key, gint inter s->n_query = 1; s->sec_delay = 1; - flx_server_post_query(s->server, s->interface, s->protocol, s->key); + avahi_server_post_query(s->server, s->interface, s->protocol, s->key); - flx_elapse_time(&tv, s->sec_delay*1000, 0); - s->time_event = flx_time_event_queue_add(server->time_event_queue, &tv, elapse, s); + avahi_elapse_time(&tv, s->sec_delay*1000, 0); + s->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, elapse, s); - FLX_LLIST_PREPEND(flxSubscription, subscriptions, server->subscriptions, s); + AVAHI_LLIST_PREPEND(AvahiSubscription, subscriptions, server->subscriptions, s); /* Add the new entry to the subscription hash table */ t = g_hash_table_lookup(server->subscription_hashtable, key); - FLX_LLIST_PREPEND(flxSubscription, by_key, t, s); + AVAHI_LLIST_PREPEND(AvahiSubscription, by_key, t, s); g_hash_table_replace(server->subscription_hashtable, key, t); /* Scan the caches */ - flx_interface_monitor_walk(s->server->monitor, s->interface, s->protocol, scan_interface_callback, s); + avahi_interface_monitor_walk(s->server->monitor, s->interface, s->protocol, scan_interface_callback, s); return s; } -void flx_subscription_free(flxSubscription *s) { - flxSubscription *t; +void avahi_subscription_free(AvahiSubscription *s) { + AvahiSubscription *t; g_assert(s); - FLX_LLIST_REMOVE(flxSubscription, subscriptions, s->server->subscriptions, s); + AVAHI_LLIST_REMOVE(AvahiSubscription, subscriptions, s->server->subscriptions, s); t = g_hash_table_lookup(s->server->subscription_hashtable, s->key); - FLX_LLIST_REMOVE(flxSubscription, by_key, t, s); + AVAHI_LLIST_REMOVE(AvahiSubscription, by_key, t, s); if (t) g_hash_table_replace(s->server->subscription_hashtable, t->key, t); else g_hash_table_remove(s->server->subscription_hashtable, s->key); - flx_time_event_queue_remove(s->server->time_event_queue, s->time_event); - flx_key_unref(s->key); + avahi_time_event_queue_remove(s->server->time_event_queue, s->time_event); + avahi_key_unref(s->key); g_free(s); } -void flx_subscription_notify(flxServer *server, flxInterface *i, flxRecord *record, flxSubscriptionEvent event) { - flxSubscription *s; - flxKey *pattern; +void avahi_subscription_notify(AvahiServer *server, AvahiInterface *i, AvahiRecord *record, AvahiSubscriptionEvent event) { + AvahiSubscription *s; + AvahiKey *pattern; g_assert(server); g_assert(record); for (s = g_hash_table_lookup(server->subscription_hashtable, record->key); s; s = s->by_key_next) - if (flx_interface_match(i, s->interface, s->protocol)) + if (avahi_interface_match(i, s->interface, s->protocol)) s->callback(s, record, i->hardware->index, i->protocol, event, s->userdata); } -gboolean flx_is_subscribed(flxServer *server, flxKey *k) { +gboolean avahi_is_subscribed(AvahiServer *server, AvahiKey *k) { g_assert(server); g_assert(k); diff --git a/subscribe.h b/subscribe.h index 2399077..3ea0d8a 100644 --- a/subscribe.h +++ b/subscribe.h @@ -2,30 +2,30 @@ #define foosubscribehfoo #include "llist.h" -#include "flx.h" +#include "Avahi.h" #include "subscribe.h" #include "timeeventq.h" #include "server.h" -struct _flxSubscription { - flxServer *server; - flxKey *key; +struct _AvahiSubscription { + AvahiServer *server; + AvahiKey *key; gint interface; guchar protocol; gint n_query; guint sec_delay; - flxTimeEvent *time_event; + AvahiTimeEvent *time_event; - flxSubscriptionCallback callback; + AvahiSubscriptionCallback callback; gpointer userdata; - FLX_LLIST_FIELDS(flxSubscription, subscriptions); - FLX_LLIST_FIELDS(flxSubscription, by_key); + AVAHI_LLIST_FIELDS(AvahiSubscription, subscriptions); + AVAHI_LLIST_FIELDS(AvahiSubscription, by_key); }; -void flx_subscription_notify(flxServer *s, flxInterface *i, flxRecord *record, flxSubscriptionEvent event); +void avahi_subscription_notify(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, AvahiSubscriptionEvent event); -gboolean flx_is_subscribed(flxServer *s, flxKey *k); +gboolean avahi_is_subscribed(AvahiServer *s, AvahiKey *k); #endif diff --git a/timeeventq.c b/timeeventq.c index 78513aa..fc84157 100644 --- a/timeeventq.c +++ b/timeeventq.c @@ -2,14 +2,14 @@ #include "util.h" static gint compare(gconstpointer _a, gconstpointer _b) { - const flxTimeEvent *a = _a, *b = _b; + const AvahiTimeEvent *a = _a, *b = _b; - return flx_timeval_compare(&a->expiry, &b->expiry); + return avahi_timeval_compare(&a->expiry, &b->expiry); } static gboolean prepare_func(GSource *source, gint *timeout) { - flxTimeEventQueue *q = (flxTimeEventQueue*) source; - flxTimeEvent *e; + AvahiTimeEventQueue *q = (AvahiTimeEventQueue*) source; + AvahiTimeEvent *e; GTimeVal now; g_assert(source); @@ -25,19 +25,19 @@ static gboolean prepare_func(GSource *source, gint *timeout) { g_source_get_current_time(source, &now); - if (flx_timeval_compare(&now, &e->expiry) >= 0) { + if (avahi_timeval_compare(&now, &e->expiry) >= 0) { *timeout = -1; return TRUE; } - *timeout = (gint) (flx_timeval_diff(&e->expiry, &now)/1000); + *timeout = (gint) (avahi_timeval_diff(&e->expiry, &now)/1000); return FALSE; } static gboolean check_func(GSource *source) { - flxTimeEventQueue *q = (flxTimeEventQueue*) source; - flxTimeEvent *e; + AvahiTimeEventQueue *q = (AvahiTimeEventQueue*) source; + AvahiTimeEvent *e; GTimeVal now; g_assert(source); @@ -50,11 +50,11 @@ static gboolean check_func(GSource *source) { g_source_get_current_time(source, &now); - return flx_timeval_compare(&now, &e->expiry) >= 0; + return avahi_timeval_compare(&now, &e->expiry) >= 0; } static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer user_data) { - flxTimeEventQueue *q = (flxTimeEventQueue*) source; + AvahiTimeEventQueue *q = (AvahiTimeEventQueue*) source; GTimeVal now; g_assert(source); @@ -62,9 +62,9 @@ static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer us g_source_get_current_time(source, &now); while (q->prioq->root) { - flxTimeEvent *e = q->prioq->root->data; + AvahiTimeEvent *e = q->prioq->root->data; - if (flx_timeval_compare(&now, &e->expiry) < 0) + if (avahi_timeval_compare(&now, &e->expiry) < 0) break; g_assert(e->callback); @@ -74,8 +74,8 @@ static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer us return TRUE; } -flxTimeEventQueue* flx_time_event_queue_new(GMainContext *context, gint priority) { - flxTimeEventQueue *q; +AvahiTimeEventQueue* avahi_time_event_queue_new(GMainContext *context, gint priority) { + AvahiTimeEventQueue *q; static GSourceFuncs source_funcs = { prepare_func, @@ -86,8 +86,8 @@ flxTimeEventQueue* flx_time_event_queue_new(GMainContext *context, gint priority NULL }; - q = (flxTimeEventQueue*) g_source_new(&source_funcs, sizeof(flxTimeEventQueue)); - q->prioq = flx_prio_queue_new(compare); + q = (AvahiTimeEventQueue*) g_source_new(&source_funcs, sizeof(AvahiTimeEventQueue)); + q->prioq = avahi_prio_queue_new(compare); g_source_set_priority((GSource*) q, priority); @@ -96,62 +96,62 @@ flxTimeEventQueue* flx_time_event_queue_new(GMainContext *context, gint priority return q; } -void flx_time_event_queue_free(flxTimeEventQueue *q) { +void avahi_time_event_queue_free(AvahiTimeEventQueue *q) { g_assert(q); while (q->prioq->root) - flx_time_event_queue_remove(q, q->prioq->root->data); - flx_prio_queue_free(q->prioq); + avahi_time_event_queue_remove(q, q->prioq->root->data); + avahi_prio_queue_free(q->prioq); g_source_destroy(&q->source); g_source_unref(&q->source); } -flxTimeEvent* flx_time_event_queue_add(flxTimeEventQueue *q, const GTimeVal *timeval, void (*callback)(flxTimeEvent *e, void *userdata), void *userdata) { - flxTimeEvent *e; +AvahiTimeEvent* avahi_time_event_queue_add(AvahiTimeEventQueue *q, const GTimeVal *timeval, void (*callback)(AvahiTimeEvent *e, void *userdata), void *userdata) { + AvahiTimeEvent *e; g_assert(q); g_assert(timeval); g_assert(callback); g_assert(userdata); - e = g_new(flxTimeEvent, 1); + e = g_new(AvahiTimeEvent, 1); e->queue = q; e->expiry = *timeval; e->callback = callback; e->userdata = userdata; - e->node = flx_prio_queue_put(q->prioq, e); + e->node = avahi_prio_queue_put(q->prioq, e); return e; } -void flx_time_event_queue_remove(flxTimeEventQueue *q, flxTimeEvent *e) { +void avahi_time_event_queue_remove(AvahiTimeEventQueue *q, AvahiTimeEvent *e) { g_assert(q); g_assert(e); g_assert(e->queue == q); - flx_prio_queue_remove(q->prioq, e->node); + avahi_prio_queue_remove(q->prioq, e->node); g_free(e); } -void flx_time_event_queue_update(flxTimeEventQueue *q, flxTimeEvent *e, const GTimeVal *timeval) { +void avahi_time_event_queue_update(AvahiTimeEventQueue *q, AvahiTimeEvent *e, const GTimeVal *timeval) { g_assert(q); g_assert(e); g_assert(e->queue == q); e->expiry = *timeval; - flx_prio_queue_shuffle(q->prioq, e->node); + avahi_prio_queue_shuffle(q->prioq, e->node); } -flxTimeEvent* flx_time_event_queue_root(flxTimeEventQueue *q) { +AvahiTimeEvent* avahi_time_event_queue_root(AvahiTimeEventQueue *q) { g_assert(q); return q->prioq->root ? q->prioq->root->data : NULL; } -flxTimeEvent* flx_time_event_next(flxTimeEvent *e) { +AvahiTimeEvent* avahi_time_event_next(AvahiTimeEvent *e) { g_assert(e); return e->node->next->data; diff --git a/timeeventq.h b/timeeventq.h index 64abbda..69ff860 100644 --- a/timeeventq.h +++ b/timeeventq.h @@ -1,34 +1,34 @@ #ifndef footimeeventqhfoo #define footimeeventqhfoo -typedef struct _flxTimeEventQueue flxTimeEventQueue; -typedef struct _flxTimeEvent flxTimeEvent; +typedef struct _AvahiTimeEventQueue AvahiTimeEventQueue; +typedef struct _AvahiTimeEvent AvahiTimeEvent; #include "prioq.h" -struct _flxTimeEvent { - flxTimeEventQueue *queue; - flxPrioQueueNode *node; +struct _AvahiTimeEvent { + AvahiTimeEventQueue *queue; + AvahiPrioQueueNode *node; GTimeVal expiry; - void (*callback)(flxTimeEvent *e, void *userdata); + void (*callback)(AvahiTimeEvent *e, void *userdata); void *userdata; }; -struct _flxTimeEventQueue { +struct _AvahiTimeEventQueue { GSource source; - flxPrioQueue *prioq; + AvahiPrioQueue *prioq; }; -flxTimeEventQueue* flx_time_event_queue_new(GMainContext *context, gint priority); -void flx_time_event_queue_free(flxTimeEventQueue *q); +AvahiTimeEventQueue* avahi_time_event_queue_new(GMainContext *context, gint priority); +void avahi_time_event_queue_free(AvahiTimeEventQueue *q); -flxTimeEvent* flx_time_event_queue_add(flxTimeEventQueue *q, const GTimeVal *timeval, void (*callback)(flxTimeEvent *e, void *userdata), void *userdata); -void flx_time_event_queue_remove(flxTimeEventQueue *q, flxTimeEvent *e); +AvahiTimeEvent* avahi_time_event_queue_add(AvahiTimeEventQueue *q, const GTimeVal *timeval, void (*callback)(AvahiTimeEvent *e, void *userdata), void *userdata); +void avahi_time_event_queue_remove(AvahiTimeEventQueue *q, AvahiTimeEvent *e); -void flx_time_event_queue_update(flxTimeEventQueue *q, flxTimeEvent *e, const GTimeVal *timeval); +void avahi_time_event_queue_update(AvahiTimeEventQueue *q, AvahiTimeEvent *e, const GTimeVal *timeval); -flxTimeEvent* flx_time_event_queue_root(flxTimeEventQueue *q); -flxTimeEvent* flx_time_event_next(flxTimeEvent *e); +AvahiTimeEvent* avahi_time_event_queue_root(AvahiTimeEventQueue *q); +AvahiTimeEvent* avahi_time_event_next(AvahiTimeEvent *e); @@ -7,7 +7,7 @@ #include "util.h" -gchar *flx_get_host_name(void) { +gchar *avahi_get_host_name(void) { #ifdef HOST_NAME_MAX char t[HOST_NAME_MAX]; #else @@ -15,10 +15,10 @@ gchar *flx_get_host_name(void) { #endif gethostname(t, sizeof(t)); t[sizeof(t)-1] = 0; - return flx_normalize_name(t); + return avahi_normalize_name(t); } -gchar *flx_normalize_name(const gchar *s) { +gchar *avahi_normalize_name(const gchar *s) { size_t l; g_assert(s); @@ -33,7 +33,7 @@ gchar *flx_normalize_name(const gchar *s) { return g_strdup_printf("%s.", s); } -gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) { +gint avahi_timeval_compare(const GTimeVal *a, const GTimeVal *b) { g_assert(a); g_assert(b); @@ -52,18 +52,18 @@ gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) { return 0; } -glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) { +glong avahi_timeval_diff(const GTimeVal *a, const GTimeVal *b) { g_assert(a); g_assert(b); - if (flx_timeval_compare(a, b) < 0) - return flx_timeval_diff(b, a); + if (avahi_timeval_compare(a, b) < 0) + return avahi_timeval_diff(b, a); return ((glong) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec; } -gint flx_set_cloexec(gint fd) { +gint avahi_set_cloexec(gint fd) { gint n; g_assert(fd >= 0); @@ -77,7 +77,7 @@ gint flx_set_cloexec(gint fd) { return fcntl(fd, F_SETFD, n|FD_CLOEXEC); } -gint flx_set_nonblock(gint fd) { +gint avahi_set_nonblock(gint fd) { gint n; g_assert(fd >= 0); @@ -91,7 +91,7 @@ gint flx_set_nonblock(gint fd) { return fcntl(fd, F_SETFL, n|O_NONBLOCK); } -gint flx_wait_for_write(gint fd) { +gint avahi_wait_for_write(gint fd) { fd_set fds; gint r; @@ -109,7 +109,7 @@ gint flx_wait_for_write(gint fd) { return 0; } -GTimeVal *flx_elapse_time(GTimeVal *tv, guint msec, guint jitter) { +GTimeVal *avahi_elapse_time(GTimeVal *tv, guint msec, guint jitter) { g_assert(tv); g_get_current_time(tv); @@ -123,17 +123,17 @@ GTimeVal *flx_elapse_time(GTimeVal *tv, guint msec, guint jitter) { return tv; } -gint flx_age(const GTimeVal *a) { +gint avahi_age(const GTimeVal *a) { GTimeVal now; g_assert(a); g_get_current_time(&now); - return flx_timeval_diff(&now, a); + return avahi_timeval_diff(&now, a); } -gboolean flx_domain_cmp(const gchar *a, const gchar *b) { +gboolean avahi_domain_cmp(const gchar *a, const gchar *b) { int escaped_a = 0, escaped_b = 0; g_assert(a); g_assert(b); @@ -167,11 +167,11 @@ gboolean flx_domain_cmp(const gchar *a, const gchar *b) { } } -gboolean flx_domain_equal(const gchar *a, const gchar *b) { - return flx_domain_cmp(a, b) == 0; +gboolean avahi_domain_equal(const gchar *a, const gchar *b) { + return avahi_domain_cmp(a, b) == 0; } -guint flx_domain_hash(const gchar *p) { +guint avahi_domain_hash(const gchar *p) { char t[256]; strncpy(t, p, sizeof(t)-1); t[sizeof(t)-1] = 0; @@ -179,7 +179,7 @@ guint flx_domain_hash(const gchar *p) { return g_int_hash(t); } -void flx_hexdump(gconstpointer p, guint size) { +void avahi_hexdump(gconstpointer p, guint size) { const guint8 *c = p; g_assert(p); @@ -3,24 +3,24 @@ #include <glib.h> -gchar *flx_normalize_name(const gchar *s); /* g_free() the result! */ -gchar *flx_get_host_name(void); /* g_free() the result! */ +gchar *avahi_normalize_name(const gchar *s); /* g_free() the result! */ +gchar *avahi_get_host_name(void); /* g_free() the result! */ -gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b); -glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b); +gint avahi_timeval_compare(const GTimeVal *a, const GTimeVal *b); +glong avahi_timeval_diff(const GTimeVal *a, const GTimeVal *b); -gint flx_set_cloexec(gint fd); -gint flx_set_nonblock(gint fd); -gint flx_wait_for_write(gint fd); +gint avahi_set_cloexec(gint fd); +gint avahi_set_nonblock(gint fd); +gint avahi_wait_for_write(gint fd); -GTimeVal *flx_elapse_time(GTimeVal *tv, guint msec, guint jitter); +GTimeVal *avahi_elapse_time(GTimeVal *tv, guint msec, guint jitter); -gint flx_age(const GTimeVal *a); +gint avahi_age(const GTimeVal *a); -guint flx_domain_hash(const gchar *p); -gboolean flx_domain_cmp(const gchar *a, const gchar *b); -gboolean flx_domain_equal(const gchar *a, const gchar *b); +guint avahi_domain_hash(const gchar *p); +gboolean avahi_domain_cmp(const gchar *a, const gchar *b); +gboolean avahi_domain_equal(const gchar *a, const gchar *b); -void flx_hexdump(gconstpointer p, guint size); +void avahi_hexdump(gconstpointer p, guint size); #endif |