summaryrefslogtreecommitdiffstats
path: root/avahi-core/resolve-address.c
diff options
context:
space:
mode:
Diffstat (limited to 'avahi-core/resolve-address.c')
-rw-r--r--avahi-core/resolve-address.c85
1 files changed, 54 insertions, 31 deletions
diff --git a/avahi-core/resolve-address.c b/avahi-core/resolve-address.c
index 6bd7cf2..e210285 100644
--- a/avahi-core/resolve-address.c
+++ b/avahi-core/resolve-address.c
@@ -24,6 +24,8 @@
#endif
#include <avahi-common/timeval.h>
+#include <avahi-common/malloc.h>
+
#include "browse.h"
struct AvahiAddressResolver {
@@ -33,7 +35,7 @@ struct AvahiAddressResolver {
AvahiRecordBrowser *record_browser;
AvahiAddressResolverCallback callback;
- gpointer userdata;
+ void* userdata;
AvahiTimeEvent *time_event;
@@ -41,30 +43,30 @@ struct AvahiAddressResolver {
};
static void finish(AvahiAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, AvahiRecord *record) {
- g_assert(r);
+ assert(r);
avahi_record_browser_free(r->record_browser);
r->record_browser = NULL;
if (r->time_event) {
- avahi_time_event_queue_remove(r->server->time_event_queue, r->time_event);
+ avahi_time_event_free(r->time_event);
r->time_event = NULL;
}
r->callback(r, interface, protocol, event, &r->address, record ? record->data.ptr.name : NULL, r->userdata);
}
-static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, void* userdata) {
AvahiAddressResolver *r = userdata;
- g_assert(rr);
- g_assert(record);
- g_assert(r);
+ assert(rr);
+ assert(record);
+ assert(r);
if (!(event == AVAHI_BROWSER_NEW))
return;
- g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
+ assert(record->key->type == AVAHI_DNS_TYPE_PTR);
finish(r, interface, protocol, AVAHI_RESOLVER_FOUND, record);
}
@@ -72,42 +74,63 @@ static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interfac
static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
AvahiAddressResolver *r = userdata;
- g_assert(e);
- g_assert(r);
+ assert(e);
+ assert(r);
finish(r, -1, AVAHI_PROTO_UNSPEC, AVAHI_RESOLVER_TIMEOUT, NULL);
}
-AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *address, AvahiAddressResolverCallback callback, gpointer userdata) {
+AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *address, AvahiAddressResolverCallback callback, void* userdata) {
AvahiAddressResolver *r;
AvahiKey *k;
- gchar *n;
+ char *n;
struct timeval tv;
- g_assert(server);
- g_assert(address);
- g_assert(callback);
+ assert(server);
+ assert(address);
+ assert(callback);
+
+ assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
+
+ if (address->family == AVAHI_PROTO_INET)
+ n = avahi_reverse_lookup_name_ipv4(&address->data.ipv4);
+ else
+ n = avahi_reverse_lookup_name_ipv6_arpa(&address->data.ipv6);
+
+ if (!n) {
+ avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
+ return NULL;
+ }
+
+ k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
+ avahi_free(n);
- g_assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
+ if (!k) {
+ avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
+ return NULL;
+ }
- r = g_new(AvahiAddressResolver, 1);
+ if (!(r = avahi_new(AvahiAddressResolver, 1))) {
+ avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
+ avahi_key_unref(k);
+ return NULL;
+ }
+
r->server = server;
r->address = *address;
r->callback = callback;
r->userdata = userdata;
- avahi_elapse_time(&tv, 1000, 0);
- r->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, time_event_callback, r);
-
+ r->record_browser = NULL;
AVAHI_LLIST_PREPEND(AvahiAddressResolver, resolver, server->address_resolvers, r);
-
- if (address->family == AVAHI_PROTO_INET)
- n = avahi_reverse_lookup_name_ipv4(&address->data.ipv4);
- else
- n = avahi_reverse_lookup_name_ipv6_arpa(&address->data.ipv6);
-
- k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
- g_free(n);
+
+ avahi_elapse_time(&tv, 1000, 0);
+ if (!(r->time_event = avahi_time_event_new(server->time_event_queue, &tv, time_event_callback, r))) {
+ avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
+ avahi_address_resolver_free(r);
+ avahi_key_unref(k);
+ return NULL;
+ }
r->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, r);
avahi_key_unref(k);
@@ -121,7 +144,7 @@ AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, AvahiIfInd
}
void avahi_address_resolver_free(AvahiAddressResolver *r) {
- g_assert(r);
+ assert(r);
AVAHI_LLIST_REMOVE(AvahiAddressResolver, resolver, r->server->address_resolvers, r);
@@ -129,7 +152,7 @@ void avahi_address_resolver_free(AvahiAddressResolver *r) {
avahi_record_browser_free(r->record_browser);
if (r->time_event)
- avahi_time_event_queue_remove(r->server->time_event_queue, r->time_event);
+ avahi_time_event_free(r->time_event);
- g_free(r);
+ avahi_free(r);
}