Logo Search packages:      
Sourcecode: avahi version File versions

AvahiServiceResolver* avahi_service_resolver_new ( AvahiClient client,
AvahiIfIndex  interface,
AvahiProtocol  protocol,
const char *  name,
const char *  type,
const char *  domain,
AvahiProtocol  aprotocol,
AvahiLookupFlags  flags,
AvahiServiceResolverCallback  callback,
void *  userdata 
)

Create a new service resolver object. Please make sure to pass all the service data you received via avahi_service_browser_new()'s callback function, especially interface and protocol. The protocol argument specifies the protocol (IPv4 or IPv6) to use as transport for the queries which are sent out by this resolver. The aprotocol argument specifies the adress family (IPv4 or IPv6) of the address of the service we are looking for. Generally, on "protocol" you should only pass what was supplied to you as parameter to your AvahiServiceBrowserCallback. In "aprotocol" you should pass what your application code can deal with when connecting to the service. Or, more technically speaking: protocol specifies if the mDNS queries should be sent as UDP/IPv4 resp. UDP/IPv6 packets. aprotocol specifies whether the query is for a A resp. AAAA resource record.

Parameters:
interface  Pass the interface argument you recieved in AvahiServiceBrowserCallback here.
protocol  Pass the protocol argument you recieved in AvahiServiceBrowserCallback here.
name  Pass the name argument you recieved in AvahiServiceBrowserCallback here.
type  Pass the type argument you recieved in AvahiServiceBrowserCallback here.
domain  Pass the domain argument you recieved in AvahiServiceBrowserCallback here.
aprotocol  The desired address family of the service address to resolve. AVAHI_PROTO_UNSPEC if your application can deal with both IPv4 and IPv6

Definition at line 181 of file resolver.c.

References AVAHI_ERR_BAD_STATE, AVAHI_ERR_DBUS_ERROR, AVAHI_ERR_NO_MEMORY, AVAHI_LLIST_PREPEND, avahi_new, avahi_service_resolver_free(), and avahi_service_resolver_new().

Referenced by avahi_service_resolver_new().

                    {

    DBusError error;
    AvahiServiceResolver *r = NULL;
    DBusMessage *message = NULL, *reply = NULL;
    int32_t i_interface, i_protocol, i_aprotocol;
    uint32_t u_flags;
    char *path;
    
    assert(client);
    assert(type);

    if (!domain)
        domain = "";

    if (!name)
        name = "";
    
    dbus_error_init (&error);

    if (!avahi_client_is_connected(client)) {
        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
        goto fail;
    }

    if (!(r = avahi_new(AvahiServiceResolver, 1))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    r->client = client;
    r->callback = callback;
    r->userdata = userdata;
    r->path = NULL;
    r->name = r->type = r->domain = NULL;
    r->interface = interface;
    r->protocol = protocol;
    
    AVAHI_LLIST_PREPEND(AvahiServiceResolver, service_resolvers, client->service_resolvers, r);

    if (name && name[0])
        if (!(r->name = avahi_strdup(name))) {
            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
            goto fail;
        }

    if (!(r->type = avahi_strdup(type))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    if (domain && domain[0])
        if (!(r->domain = avahi_strdup(domain))) {
            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
            goto fail;
        }
    
    
    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    i_interface = (int32_t) interface;
    i_protocol = (int32_t) protocol;
    i_aprotocol = (int32_t) aprotocol;
    u_flags = (uint32_t) flags;

    if (!(dbus_message_append_args(
              message,
              DBUS_TYPE_INT32, &i_interface,
              DBUS_TYPE_INT32, &i_protocol,
              DBUS_TYPE_STRING, &name,
              DBUS_TYPE_STRING, &type,
              DBUS_TYPE_STRING, &domain,
              DBUS_TYPE_INT32, &i_aprotocol,
              DBUS_TYPE_UINT32, &u_flags,
              DBUS_TYPE_INVALID))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
        dbus_error_is_set(&error)) {
        avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

    if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
        dbus_error_is_set(&error) ||
        !path) {
        avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

    if (!(r->path = avahi_strdup(path))) {

        /* FIXME: We don't remove the object on the server side */

        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }
        

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return r;
    
fail:

    if (dbus_error_is_set(&error)) {
        avahi_client_set_dbus_error(client, &error);
        dbus_error_free(&error);
    }

    if (r)
        avahi_service_resolver_free(r);
    
    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);
    
    return NULL;

}


Generated by  Doxygen 1.6.0   Back to index