return NULL;
}
+AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *b)
+{
+ assert(b);
+ return b->client;
+}
+
int avahi_domain_browser_free (AvahiDomainBrowser *b) {
AvahiClient *client;
int r = AVAHI_OK;
return NULL;
}
+AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *b)
+{
+ assert(b);
+ return b->client;
+}
+
int avahi_service_type_browser_free (AvahiServiceTypeBrowser *b) {
AvahiClient *client;
int r = AVAHI_OK;
return NULL;
}
-
+
+AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *b)
+{
+ assert(b);
+ return b->client;
+}
+
int avahi_service_browser_free (AvahiServiceBrowser *b) {
AvahiClient *client;
int r = AVAHI_OK;
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), domain (%s), data (%s)\n", avahi_domain_browser_get_dbus_path (b), interface, protocol, event, domain, (char*)user_data);
}
+static void
+avahi_service_resolver_callback (AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *a, uint16_t port, AvahiStringList *txt, void *user_data)
+{
+ char addr[64];
+ char *txtr;
+ if (event == AVAHI_RESOLVER_TIMEOUT)
+ {
+ printf ("ServiceResolver timed out\n");
+ return;
+ }
+ avahi_address_snprint (addr, sizeof (addr), a);
+ txtr = avahi_string_list_to_string (txt);
+ printf ("XXX: Callback on ServiceResolver, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), host_name (%s), address (%s), port (%d), txtdata (%s), data(%s)\n", interface, protocol, event, name, type, domain, host_name, addr, port, txtr, (char*)user_data);
+}
+
static void
avahi_service_browser_callback (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, void *user_data)
{
+ AvahiServiceResolver *sr;
+ if (b && name)
+ {
+ sr = avahi_service_resolver_new (avahi_service_browser_get_client (b), interface, protocol, name, type, domain, AF_UNSPEC, avahi_service_resolver_callback, "xxXXxx");
+ }
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), data (%s)\n", avahi_service_browser_get_dbus_path (b), interface, protocol, event, name, type, domain, (char*)user_data);
}
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), type (%s), domain (%s), data (%s)\n", avahi_service_type_browser_get_dbus_path (b), interface, protocol, event, type, domain, (char*)user_data);
}
+static void
+avahi_host_name_resolver_callback (AvahiHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const AvahiAddress *a, void *user_data)
+{
+ char addr[64];
+
+ if (event == AVAHI_RESOLVER_TIMEOUT)
+ {
+ printf ("XXX: Callback on HostNameResolver, timed out.\n");
+ return;
+ }
+ avahi_address_snprint (addr, sizeof (addr), a);
+ printf ("XXX: Callback on HostNameResolver, interface (%d), protocol (%d), event (%d), name (%s), address (%s), data (%s)\n", interface, protocol, event, name, addr, (char*)user_data);
+}
+
static void test_free_domain_browser(AvahiTimeout *timeout, void* userdata)
{
AvahiServiceBrowser *b = userdata;
AvahiDomainBrowser *domain;
AvahiServiceBrowser *sb;
AvahiServiceTypeBrowser *st;
+ AvahiHostNameResolver *hnr;
const char *ret;
int error;
struct timeval tv;
else
printf ("Sucessfully created service browser, path %s\n", avahi_service_browser_get_dbus_path (sb));
+ hnr = avahi_host_name_resolver_new (avahi, AVAHI_IF_UNSPEC, AF_UNSPEC, "hotbox.local", AF_UNSPEC, avahi_host_name_resolver_callback, "omghai4u");
+ if (hnr == NULL)
+ printf ("Failed to create hostname resolver object\n");
+ else
+ printf ("Successfully created hostname resolver object\n");
+
avahi_elapse_time(&tv, 8000, 0);
poll_api->timeout_new(poll_api, &tv, test_entry_group_reset, group);
/** A service resolver object */
typedef struct AvahiServiceResolver AvahiServiceResolver;
+/** A service resolver object */
+typedef struct AvahiHostNameResolver AvahiHostNameResolver;
+
/** States of a client object, a superset of AvahiServerState */
typedef enum {
AVAHI_CLIENT_S_INVALID = AVAHI_SERVER_INVALID,
AvahiStringList *txt,
void *userdata);
+/** The function prototype for the callback of an AvahiHostNameResolver */
+typedef void (*AvahiHostNameResolverCallback) (
+ AvahiHostNameResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const AvahiAddress *a,
+ void *userdata);
+
/** Creates a new client instance */
AvahiClient* avahi_client_new (const AvahiPoll *poll_api, AvahiClientCallback callback, void *userdata, int *error);
AvahiDomainBrowserCallback callback,
void *userdata);
+/** Get the parent client of an AvahiDomainBrowser object */
+AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *);
+
/** Get the D-Bus path of an AvahiDomainBrowser object, for debugging purposes only. */
const char* avahi_domain_browser_get_dbus_path (AvahiDomainBrowser *);
AvahiServiceTypeBrowserCallback callback,
void *userdata);
+/** Get the parent client of an AvahiServiceTypeBrowser object */
+AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *);
+
/** Get the D-Bus path of an AvahiServiceTypeBrowser object, for debugging purposes only. */
const char* avahi_service_type_browser_get_dbus_path(AvahiServiceTypeBrowser *);
/** Get the D-Bus path of an AvahiServiceBrowser object, for debugging purposes only. */
const char* avahi_service_browser_get_dbus_path (AvahiServiceBrowser *);
+/** Get the parent client of an AvahiServiceBrowser object */
+AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *);
+
/* Cleans up and frees an AvahiServiceBrowser object */
int avahi_service_browser_free (AvahiServiceBrowser *);
AvahiServiceResolverCallback callback,
void *userdata);
+/** Get the parent client of an AvahiServiceResolver object */
+AvahiClient* avahi_service_resolver_get_client (AvahiServiceResolver *);
+
/** Free a service resolver object */
int avahi_service_resolver_free(AvahiServiceResolver *r);
/** Block until the resolving is complete */
int avahi_service_resolver_block(AvahiServiceResolver *r);
+/** Create a new hostname resolver object */
+AvahiHostNameResolver * avahi_host_name_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *name,
+ AvahiProtocol aprotocol,
+ AvahiHostNameResolverCallback callback,
+ void *userdata);
+
+/** Get the parent client of an AvahiHostNameResolver object */
+AvahiClient* avahi_host_name_resolver_get_client (AvahiHostNameResolver *);
+
+/** Free a hostname resolver object */
+int avahi_host_name_resolver_free(AvahiHostNameResolver *r);
+
+/** Block until the resolving is complete */
+int avahi_host_name_resolver_block(AvahiHostNameResolver *r);
+
#ifndef DOXYGEN_SHOULD_SKIP_THIS
AVAHI_C_DECL_END
#endif
AVAHI_LLIST_HEAD(AvahiServiceBrowser, service_browsers);
AVAHI_LLIST_HEAD(AvahiServiceTypeBrowser, service_type_browsers);
AVAHI_LLIST_HEAD(AvahiServiceResolver, service_resolvers);
+ AVAHI_LLIST_HEAD(AvahiHostNameResolver, host_name_resolvers);
};
struct AvahiEntryGroup {
AVAHI_LLIST_FIELDS(AvahiServiceResolver, service_resolvers);
};
+struct AvahiHostNameResolver {
+ char *path;
+ DBusPendingCall *call;
+ AvahiClient *client;
+ AvahiHostNameResolverCallback callback;
+ void *userdata;
+ AVAHI_LLIST_FIELDS(AvahiHostNameResolver, host_name_resolvers);
+};
+
int avahi_client_set_errno (AvahiClient *client, int error);
int avahi_client_set_dbus_error(AvahiClient *client, DBusError *error);
#include "client.h"
#include "internal.h"
-static void pending_call_callback(DBusPendingCall *pending, void *userdata) {
+static void
+service_pending_call_callback(DBusPendingCall *pending, void *userdata) {
AvahiServiceResolver *r = userdata;
DBusMessage *message = NULL;
AvahiStringList *strlst = NULL;
dbus_error_free (&error);
}
+static void
+hostname_pending_call_callback(DBusPendingCall *pending, void *userdata) {
+ AvahiHostNameResolver *r = userdata;
+ DBusMessage *message = NULL;
+ DBusError error;
+
+ assert(pending);
+ assert(r);
+
+ dbus_error_init(&error);
+
+ if (!(message = dbus_pending_call_steal_reply(pending)))
+ goto fail;
+
+ if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
+ int32_t interface, protocol, aprotocol;
+ char *name, *address;
+ AvahiAddress a;
+
+ if (!dbus_message_get_args(
+ message, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INT32, &aprotocol,
+ DBUS_TYPE_STRING, &address,
+ DBUS_TYPE_INVALID) ||
+ dbus_error_is_set (&error)) {
+ fprintf(stderr, "Failed to parse resolver event.\n");
+ goto fail;
+ }
+
+ assert(address);
+ if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) {
+ fprintf(stderr, "Failed to parse address\n");
+ goto fail;
+ }
+
+ r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, r->userdata);
+
+ } else {
+
+ assert(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR);
+
+ avahi_client_set_errno(r->client, avahi_error_dbus_to_number(dbus_message_get_error_name(message)));
+
+ r->callback(r, (AvahiIfIndex) 0, (AvahiProtocol) 0, AVAHI_RESOLVER_TIMEOUT, NULL, NULL, r->userdata);
+ }
+
+fail:
+
+ if (message)
+ dbus_message_unref(message);
+
+ dbus_error_free (&error);
+}
+
AvahiServiceResolver * avahi_service_resolver_new(
AvahiClient *client,
AvahiIfIndex interface,
}
if (!dbus_connection_send_with_reply(client->bus, message, &r->call, -1) ||
- !dbus_pending_call_set_notify(r->call, pending_call_callback, r, NULL)) {
+ !dbus_pending_call_set_notify(r->call, service_pending_call_callback, r, NULL)) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
}
+AvahiClient* avahi_service_resolver_get_client (AvahiServiceResolver *r) {
+ AvahiClient *client;
+
+ assert (r);
+
+ return r->client;
+}
+
int avahi_service_resolver_free(AvahiServiceResolver *r) {
AvahiClient *client;
return AVAHI_OK;
}
+AvahiHostNameResolver * avahi_host_name_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *name,
+ AvahiProtocol aprotocol,
+ AvahiHostNameResolverCallback callback,
+ void *userdata) {
+
+ DBusError error;
+ AvahiHostNameResolver *r;
+ DBusMessage *message;
+ int32_t i_interface, i_protocol, i_aprotocol;
+
+ assert(client);
+ assert(name);
+
+ dbus_error_init (&error);
+
+ if (client->state == AVAHI_CLIENT_DISCONNECTED) {
+ avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
+ goto fail;
+ }
+
+ if (!(r = avahi_new(AvahiHostNameResolver, 1))) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ r->client = client;
+ r->callback = callback;
+ r->userdata = userdata;
+ r->call = NULL;
+
+ AVAHI_LLIST_PREPEND(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);
+
+ if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName"))) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ i_interface = interface;
+ i_protocol = protocol;
+ i_aprotocol = aprotocol;
+
+ if (!(dbus_message_append_args(
+ message,
+ DBUS_TYPE_INT32, &i_interface,
+ DBUS_TYPE_INT32, &i_protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INT32, &i_aprotocol,
+ DBUS_TYPE_INVALID))) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ if (!dbus_connection_send_with_reply(client->bus, message, &r->call, -1) ||
+ !dbus_pending_call_set_notify(r->call, hostname_pending_call_callback, r, NULL)) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ dbus_message_unref(message);
+
+ return r;
+
+fail:
+
+ if (dbus_error_is_set(&error)) {
+ avahi_client_set_dbus_error(client, &error);
+ dbus_error_free(&error);
+ }
+
+ if (r)
+ avahi_host_name_resolver_free(r);
+
+ if (message)
+ dbus_message_unref(message);
+
+ return NULL;
+
+}
+
+int avahi_host_name_resolver_free(AvahiHostNameResolver *r) {
+ AvahiClient *client;
+
+ assert(r);
+ client = r->client;
+
+ if (r->call) {
+ dbus_pending_call_cancel(r->call);
+ dbus_pending_call_unref(r->call);
+ }
+
+ AVAHI_LLIST_REMOVE(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);
+
+ avahi_free(r);
+
+ return AVAHI_OK;
+}
+
+AvahiClient* avahi_host_name_resolver_get_client (AvahiHostNameResolver *r) {
+ AvahiClient *client;
+
+ assert (r);
+
+ return r->client;
+}
+
+int avahi_host_name_resolver_block(AvahiHostNameResolver *r) {
+ AvahiClient *client;
+
+ assert(r);
+ client = r->client;
+
+ if (r->call)
+ dbus_pending_call_block(r->call);
+
+ return AVAHI_OK;
+}