コード例 #1
0
ファイル: browser.c プロジェクト: Antares84/asuswrt-merlin
int avahi_domain_browser_free (AvahiDomainBrowser *b) {
    AvahiClient *client;
    int r = AVAHI_OK;

    assert(b);
    assert(b->ref >= 1);

    if (--(b->ref) >= 1)
        return AVAHI_OK;

    client = b->client;

    if (b->path && avahi_client_is_connected(b->client))
        r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free");

    AVAHI_LLIST_REMOVE(AvahiDomainBrowser, domain_browsers, client->domain_browsers, b);

    if (b->defer_timeout)
        b->client->poll_api->timeout_free(b->defer_timeout);

    avahi_string_list_free(b->static_browse_domains);
    avahi_free(b->path);
    avahi_free(b);

    return r;
}
コード例 #2
0
ファイル: client.c プロジェクト: EBone/Faust
int avahi_client_set_host_name(AvahiClient* client, const char *name) {
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;

    assert(client);

    if (!avahi_client_is_connected(client))
        return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);

    dbus_error_init (&error);

    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "SetHostName"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
        avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error);

    if (!reply || dbus_error_is_set (&error))
        goto fail;

    if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
        dbus_error_is_set (&error))
        goto fail;

    dbus_message_unref(message);
    dbus_message_unref(reply);

    avahi_free(client->host_name);
    client->host_name = NULL;
    avahi_free(client->host_name_fqdn);
    client->host_name_fqdn = NULL;

    return 0;

fail:

    if (message)
        dbus_message_unref(message);
    if (reply)
        dbus_message_unref(reply);

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

    return client->error;
}
コード例 #3
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
int avahi_entry_group_reset(AvahiEntryGroup *group) {
    int ret;
    assert(group);

    if (!group->path || !avahi_client_is_connected(group->client))
        return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);

    if ((ret = entry_group_simple_method_call(group, "Reset")) < 0)
        return ret;

    group->state_valid = 0;
    return ret;
}
コード例 #4
0
ファイル: client.c プロジェクト: EBone/Faust
const char* avahi_client_get_version_string(AvahiClient *client) {
    assert(client);

    if (!avahi_client_is_connected(client)) {
        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
        return NULL;
    }

    if (!client->version_string)
        client->version_string = avahi_client_get_string_reply_and_block(client, "GetVersionString", NULL);

    return client->version_string;
}
コード例 #5
0
ファイル: client.c プロジェクト: EBone/Faust
const char* avahi_client_get_domain_name(AvahiClient *client) {
    assert(client);

    if (!avahi_client_is_connected(client)) {
        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
        return NULL;
    }

    if (!client->domain_name)
        client->domain_name = avahi_client_get_string_reply_and_block(client, "GetDomainName", NULL);

    return client->domain_name;
}
コード例 #6
0
ファイル: client.c プロジェクト: EBone/Faust
const char* avahi_client_get_host_name_fqdn (AvahiClient *client) {
    assert(client);

    if (!avahi_client_is_connected(client)) {
        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
        return NULL;
    }

    if (!client->host_name_fqdn)
        client->host_name_fqdn = avahi_client_get_string_reply_and_block(client, "GetHostNameFqdn", NULL);

    return client->host_name_fqdn;
}
コード例 #7
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
int avahi_entry_group_is_empty (AvahiEntryGroup *group) {
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;
    int r = AVAHI_OK;
    int b;
    AvahiClient *client;

    assert(group);
    client = group->client;

    if (!group->path || !avahi_client_is_connected(group->client))
        return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);

    dbus_error_init(&error);

    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty"))) {
        r = 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)) {
        r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

    if (!dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID) ||
        dbus_error_is_set (&error)) {
        r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return !!b;

fail:
    if (dbus_error_is_set(&error)) {
        r = avahi_client_set_dbus_error(client, &error);
        dbus_error_free(&error);
    }

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return r;
}
コード例 #8
0
ファイル: client.c プロジェクト: EBone/Faust
uint32_t avahi_client_get_local_service_cookie(AvahiClient *client) {
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;
    assert(client);

    if (!avahi_client_is_connected(client)) {
        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
        return AVAHI_SERVICE_COOKIE_INVALID;
    }

    if (client->local_service_cookie_valid)
        return client->local_service_cookie;

    dbus_error_init (&error);

    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetLocalServiceCookie"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);

    if (!reply || dbus_error_is_set (&error))
        goto fail;

    if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &client->local_service_cookie, DBUS_TYPE_INVALID) ||
        dbus_error_is_set (&error))
        goto fail;

    dbus_message_unref(message);
    dbus_message_unref(reply);

    client->local_service_cookie_valid = 1;
    return client->local_service_cookie;

fail:

    if (message)
        dbus_message_unref(message);
    if (reply)
        dbus_message_unref(reply);

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

    return AVAHI_SERVICE_COOKIE_INVALID;
}
コード例 #9
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
int avahi_entry_group_free(AvahiEntryGroup *group) {
    AvahiClient *client = group->client;
    int r = AVAHI_OK;

    assert(group);

    if (group->path && avahi_client_is_connected(client))
        r = entry_group_simple_method_call(group, "Free");

    AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, client->groups, group);

    avahi_free(group->path);
    avahi_free(group);

    return r;
}
コード例 #10
0
ファイル: browser.c プロジェクト: Antares84/asuswrt-merlin
int avahi_record_browser_free (AvahiRecordBrowser *b) {
    AvahiClient *client;
    int r = AVAHI_OK;

    assert(b);
    client = b->client;

    if (b->path && avahi_client_is_connected(b->client))
        r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Free");

    AVAHI_LLIST_REMOVE(AvahiRecordBrowser, record_browsers, b->client->record_browsers, b);

    avahi_free(b->path);
    avahi_free(b->name);
    avahi_free(b);
    return r;
}
コード例 #11
0
ファイル: browser.c プロジェクト: Antares84/asuswrt-merlin
int avahi_service_type_browser_free (AvahiServiceTypeBrowser *b) {
    AvahiClient *client;
    int r = AVAHI_OK;

    assert(b);
    client = b->client;

    if (b->path && avahi_client_is_connected(b->client))
        r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free");

    AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);

    avahi_free(b->path);
    avahi_free(b->domain);
    avahi_free(b);
    return r;
}
コード例 #12
0
int avahi_address_resolver_free(AvahiAddressResolver *r) {
    AvahiClient *client;
    int ret = AVAHI_OK;

    assert(r);
    client = r->client;

    if (r->path && avahi_client_is_connected(client))
        ret = avahi_client_simple_method_call(client, r->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Free");

    AVAHI_LLIST_REMOVE(AvahiAddressResolver, address_resolvers, client->address_resolvers, r);

    avahi_free(r->path);
    avahi_free(r);

    return ret;
}
コード例 #13
0
int avahi_host_name_resolver_free(AvahiHostNameResolver *r) {
    int ret = AVAHI_OK;
    AvahiClient *client;

    assert(r);
    client = r->client;

    if (r->path && avahi_client_is_connected(client))
        ret = avahi_client_simple_method_call(client, r->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Free");

    AVAHI_LLIST_REMOVE(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);

    avahi_free(r->path);
    avahi_free(r->host_name);
    avahi_free(r);

    return ret;
}
コード例 #14
0
int avahi_service_resolver_free(AvahiServiceResolver *r) {
    AvahiClient *client;
    int ret = AVAHI_OK;

    assert(r);
    client = r->client;

    if (r->path && avahi_client_is_connected(client))
        ret = avahi_client_simple_method_call(client, r->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Free");

    AVAHI_LLIST_REMOVE(AvahiServiceResolver, service_resolvers, client->service_resolvers, r);

    avahi_free(r->path);
    avahi_free(r->name);
    avahi_free(r->type);
    avahi_free(r->domain);
    avahi_free(r);

    return ret;
}
コード例 #15
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
int avahi_entry_group_update_service_txt_strlst(
    AvahiEntryGroup *group,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    AvahiPublishFlags flags,
    const char *name,
    const char *type,
    const char *domain,
    AvahiStringList *txt) {

    DBusMessage *message = NULL, *reply = NULL;
    int r = AVAHI_OK;
    DBusError error;
    AvahiClient *client;
    int32_t i_interface, i_protocol;
    uint32_t u_flags;

    assert(group);
    assert(name);
    assert(type);

    client = group->client;

    if (!group->path || !avahi_client_is_connected(group->client))
        return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);

    if (!domain)
        domain = "";

    dbus_error_init(&error);

    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt"))) {
        r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

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

    if (!dbus_message_append_args(
            message,
            DBUS_TYPE_INT32, &i_interface,
            DBUS_TYPE_INT32, &i_protocol,
            DBUS_TYPE_UINT32, &u_flags,
            DBUS_TYPE_STRING, &name,
            DBUS_TYPE_STRING, &type,
            DBUS_TYPE_STRING, &domain,
            DBUS_TYPE_INVALID) ||
        append_string_list(message, txt) < 0) {
        r = avahi_client_set_errno(group->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)) {
        r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

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

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return AVAHI_OK;

fail:

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

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return r;
}
コード例 #16
0
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) {

    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;

}
コード例 #17
0
ファイル: client.c プロジェクト: EBone/Faust
static DBusHandlerResult filter_func(DBusConnection *bus, DBusMessage *message, void *userdata) {
    AvahiClient *client = (AvahiClient *)userdata;
    DBusError error;

    assert(bus);
    assert(message);

    dbus_error_init(&error);

/*     fprintf(stderr, "dbus: interface=%s, path=%s, member=%s\n", */
/*             dbus_message_get_interface (message), */
/*             dbus_message_get_path (message), */
/*             dbus_message_get_member (message)); */

    if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {

        /* The DBUS server died or kicked us */
        avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED);
        goto fail;

    } else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameAcquired")) {

        /* Ignore this message */

    } else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
        char *name, *old, *newname;

        if (!dbus_message_get_args(
                  message, &error,
                  DBUS_TYPE_STRING, &name,
                  DBUS_TYPE_STRING, &old,
                  DBUS_TYPE_STRING, &newname,
                  DBUS_TYPE_INVALID) || dbus_error_is_set(&error)) {

            fprintf(stderr, "WARNING: Failed to parse NameOwnerChanged signal: %s\n", error.message);
            avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
            goto fail;
        }

        if (strcmp(name, AVAHI_DBUS_NAME) == 0) {

            if (old[0] &&
                avahi_client_is_connected(client)) {

                /* Regardless if the server lost its name or
                 * if the name was transfered: our services are no longer
                 * available, so we disconnect ourselves */
                avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED);
                goto fail;

            } else if (client->state == AVAHI_CLIENT_CONNECTING && (!old || *old == 0)) {
                int ret;

                /* Server appeared */

                if ((ret = init_server(client, NULL)) < 0) {
                    avahi_client_set_errno(client, ret);
                    goto fail;
                }
            }
        }

    } else if (!avahi_client_is_connected(client)) {

        /* Ignore messages we get in unconnected state */

    } else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_SERVER, "StateChanged")) {
        int32_t state;
        char *e = NULL;
        int c;

        if (!dbus_message_get_args(
                  message, &error,
                  DBUS_TYPE_INT32, &state,
                  DBUS_TYPE_STRING, &e,
                  DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) {

            fprintf(stderr, "WARNING: Failed to parse Server.StateChanged signal: %s\n", error.message);
            avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
            goto fail;
        }

        if ((c = avahi_error_dbus_to_number(e)) != AVAHI_OK)
            avahi_client_set_errno(client, c);

        client_set_state(client, (AvahiClientState) state);

    } else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged")) {
        const char *path;
        AvahiEntryGroup *g;
        path = dbus_message_get_path(message);

        for (g = client->groups; g; g = g->groups_next){
            if (strcmp(g->path, path) == 0)
                break;
		}

        if (g) {
            int32_t state;
            char *e;
            int c;

            if (!dbus_message_get_args(
                      message, &error,
                      DBUS_TYPE_INT32, &state,
                      DBUS_TYPE_STRING, &e,
                      DBUS_TYPE_INVALID) ||
                dbus_error_is_set(&error)) {

                fprintf(stderr, "WARNING: Failed to parse EntryGroup.StateChanged signal: %s\n", error.message);
                avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
                goto fail;
            }

            if ((c = avahi_error_dbus_to_number(e)) != AVAHI_OK)
                avahi_client_set_errno(client, c);

            avahi_entry_group_set_state(g, (AvahiEntryGroupState)state);
        }

        return avahi_domain_browser_event(client, AVAHI_BROWSER_NEW, message);
	}
    else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "ItemRemove"))
        return avahi_domain_browser_event(client, AVAHI_BROWSER_REMOVE, message);
    else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "CacheExhausted"))
        return avahi_domain_browser_event(client, AVAHI_BROWSER_CACHE_EXHAUSTED, message);
    else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "AllForNow"))
        return avahi_domain_browser_event(client, AVAHI_BROWSER_ALL_FOR_NOW, message);
    else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Failure"))
        return avahi_domain_browser_event(client, AVAHI_BROWSER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemNew"))
        return avahi_service_type_browser_event (client, AVAHI_BROWSER_NEW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemRemove"))
        return avahi_service_type_browser_event (client, AVAHI_BROWSER_REMOVE, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "CacheExhausted"))
        return avahi_service_type_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "AllForNow"))
        return avahi_service_type_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Failure"))
        return avahi_service_type_browser_event (client, AVAHI_BROWSER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "ItemNew"))
        return avahi_service_browser_event (client, AVAHI_BROWSER_NEW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "ItemRemove"))
        return avahi_service_browser_event (client, AVAHI_BROWSER_REMOVE, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "CacheExhausted"))
        return avahi_service_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "AllForNow"))
        return avahi_service_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Failure"))
        return avahi_service_browser_event (client, AVAHI_BROWSER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Found"))
        return avahi_service_resolver_event (client, AVAHI_RESOLVER_FOUND, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Failure"))
        return avahi_service_resolver_event (client, AVAHI_RESOLVER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Found"))
        return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FOUND, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Failure"))
        return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Found"))
        return avahi_address_resolver_event (client, AVAHI_RESOLVER_FOUND, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Failure"))
        return avahi_address_resolver_event (client, AVAHI_RESOLVER_FAILURE, message);

    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "ItemNew"))
        return avahi_record_browser_event (client, AVAHI_BROWSER_NEW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "ItemRemove"))
        return avahi_record_browser_event (client, AVAHI_BROWSER_REMOVE, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "CacheExhausted"))
        return avahi_record_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "AllForNow"))
        return avahi_record_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message);
    else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Failure"))
        return avahi_record_browser_event (client, AVAHI_BROWSER_FAILURE, message);

    else {

        fprintf(stderr, "WARNING: Unhandled message: interface=%s, path=%s, member=%s\n",
               dbus_message_get_interface(message),
               dbus_message_get_path(message),
               dbus_message_get_member(message));

        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }

    return DBUS_HANDLER_RESULT_HANDLED;

fail:

    if (dbus_error_is_set(&error)) {
        avahi_client_set_errno(client, avahi_error_dbus_to_number(error.name));
        dbus_error_free(&error);
    }

    client_set_state(client, AVAHI_CLIENT_FAILURE);

    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
コード例 #18
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
AvahiEntryGroup* avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCallback callback, void *userdata) {
    AvahiEntryGroup *group = NULL;
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;
    char *path;
    int state;

    assert(client);

    dbus_error_init (&error);

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

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

    group->client = client;
    group->callback = callback;
    group->userdata = userdata;
    group->state_valid = 0;
    group->path = NULL;
    AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, client->groups, group);

    if (!(message = dbus_message_new_method_call(
              AVAHI_DBUS_NAME,
              AVAHI_DBUS_PATH_SERVER,
              AVAHI_DBUS_INTERFACE_SERVER,
              "EntryGroupNew"))) {
        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)) {
        avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

    if (!(group->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;
    }

    if ((state = retrieve_state(group)) < 0) {
        avahi_client_set_errno(client, state);
        goto fail;
    }

    avahi_entry_group_set_state(group, (AvahiEntryGroupState) state);

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return group;

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

    if (group)
        avahi_entry_group_free(group);

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return NULL;
}
コード例 #19
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
/** Add an arbitrary record */
int avahi_entry_group_add_record(
    AvahiEntryGroup *group,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    AvahiPublishFlags flags,
    const char *name,
    uint16_t clazz,
    uint16_t type,
    uint32_t ttl,
    const void *rdata,
    size_t size) {

    DBusMessage *message = NULL, *reply = NULL;
    int r = AVAHI_OK;
    DBusError error;
    AvahiClient *client;
    int32_t i_interface, i_protocol;
    uint32_t u_flags;

    assert(name);

    client = group->client;

    if (!group->path || !avahi_client_is_connected(group->client))
        return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);

    dbus_error_init(&error);

    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddRecord"))) {
        r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

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

    if (!dbus_message_append_args(
            message,
            DBUS_TYPE_INT32, &i_interface,
            DBUS_TYPE_INT32, &i_protocol,
            DBUS_TYPE_UINT32, &u_flags,
            DBUS_TYPE_STRING, &name,
            DBUS_TYPE_UINT16, &clazz,
            DBUS_TYPE_UINT16, &type,
            DBUS_TYPE_UINT32, &ttl,
            DBUS_TYPE_INVALID) || append_rdata(message, rdata, size) < 0) {
        r = avahi_client_set_errno(group->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)) {
        r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

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

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return AVAHI_OK;

fail:

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

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return r;
}
コード例 #20
0
ファイル: entrygroup.c プロジェクト: EBone/Faust
/** Add a host/address pair */
int avahi_entry_group_add_address(
    AvahiEntryGroup *group,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    AvahiPublishFlags flags,
    const char *name,
    const AvahiAddress *a) {

    DBusMessage *message = NULL, *reply = NULL;
    int r = AVAHI_OK;
    DBusError error;
    AvahiClient *client;
    int32_t i_interface, i_protocol;
    uint32_t u_flags;
    char s_address[AVAHI_ADDRESS_STR_MAX];
    char *p_address = s_address;

    assert(name);

    client = group->client;

    if (!group->path || !avahi_client_is_connected(group->client))
        return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);

    dbus_error_init(&error);

    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress"))) {
        r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

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

    if (!avahi_address_snprint (s_address, sizeof (s_address), a))
    {
        r = avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
        goto fail;
    }

    if (!dbus_message_append_args(
            message,
            DBUS_TYPE_INT32, &i_interface,
            DBUS_TYPE_INT32, &i_protocol,
            DBUS_TYPE_UINT32, &u_flags,
            DBUS_TYPE_STRING, &name,
            DBUS_TYPE_STRING, &p_address,
            DBUS_TYPE_INVALID)) {
        r = avahi_client_set_errno(group->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)) {
        r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
        goto fail;
    }

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

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return AVAHI_OK;

fail:

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

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return r;
}
コード例 #21
0
AvahiAddressResolver * avahi_address_resolver_new(
    AvahiClient *client,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    const AvahiAddress *a,
    AvahiLookupFlags flags, 
    AvahiAddressResolverCallback callback,
    void *userdata) {

    DBusError error;
    AvahiAddressResolver *r = NULL;
    DBusMessage *message = NULL, *reply = NULL;
    int32_t i_interface, i_protocol;
    uint32_t u_flags;
    char *path;
    char addr[AVAHI_ADDRESS_STR_MAX], *address = addr;

    assert(client);
    assert(a);

    dbus_error_init (&error);

    if (!avahi_address_snprint (addr, sizeof(addr), a)) {
        avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
        return NULL;
    }

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

    if (!(r = avahi_new(AvahiAddressResolver, 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->interface = interface;
    r->protocol = protocol;
    r->address = *a;
    
    AVAHI_LLIST_PREPEND(AvahiAddressResolver, address_resolvers, client->address_resolvers, r);

    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "AddressResolverNew"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

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

    if (!(dbus_message_append_args(
              message,
              DBUS_TYPE_INT32, &i_interface,
              DBUS_TYPE_INT32, &i_protocol,
              DBUS_TYPE_STRING, &address,
              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_address_resolver_free(r);
    
    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return NULL;

}
コード例 #22
0
ファイル: browser.c プロジェクト: Antares84/asuswrt-merlin
AvahiDomainBrowser* avahi_domain_browser_new(
    AvahiClient *client,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    const char *domain,
    AvahiDomainBrowserType btype,
    AvahiLookupFlags flags,
    AvahiDomainBrowserCallback callback,
    void *userdata) {

    AvahiDomainBrowser *db = NULL;
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;
    char *path;
    int32_t i_interface, i_protocol, bt;
    uint32_t u_flags;

    assert(client);
    assert(callback);

    dbus_error_init (&error);

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

    if (!domain)
        domain = "";

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

    db->ref = 1;
    db->client = client;
    db->callback = callback;
    db->userdata = userdata;
    db->path = NULL;
    db->interface = interface;
    db->protocol = protocol;
    db->static_browse_domains = NULL;
    db->defer_timeout = NULL;

    AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, db);

    if (!(client->flags & AVAHI_CLIENT_IGNORE_USER_CONFIG)) {
        parse_environment(db);
        parse_domain_file(db);
    }

    db->static_browse_domains = avahi_string_list_reverse(db->static_browse_domains);

    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    i_interface = (int32_t) interface;
    i_protocol = (int32_t) protocol;
    u_flags = (uint32_t) flags;
    bt = btype;

    if (!(dbus_message_append_args(
              message,
              DBUS_TYPE_INT32, &i_interface,
              DBUS_TYPE_INT32, &i_protocol,
              DBUS_TYPE_STRING, &domain,
              DBUS_TYPE_INT32, &bt,
              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 (!(db->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;
    }

    if (db->static_browse_domains && btype == AVAHI_DOMAIN_BROWSER_BROWSE) {
        struct timeval tv = { 0, 0 };

        if (!(db->defer_timeout = client->poll_api->timeout_new(client->poll_api, &tv, defer_timeout_callback, db))) {
            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
            goto fail;
        }
    }

    dbus_message_unref(message);
    dbus_message_unref(reply);

    return db;

fail:

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

    if (db)
        avahi_domain_browser_free(db);

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return NULL;
}
コード例 #23
0
ファイル: browser.c プロジェクト: Antares84/asuswrt-merlin
AvahiRecordBrowser* avahi_record_browser_new(
    AvahiClient *client,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    const char *name,
    uint16_t clazz,
    uint16_t type,
    AvahiLookupFlags flags,
    AvahiRecordBrowserCallback callback,
    void *userdata) {

    AvahiRecordBrowser *b = NULL;
    DBusMessage *message = NULL, *reply = NULL;
    DBusError error;
    char *path;
    int32_t i_protocol, i_interface;
    uint32_t u_flags;

    assert(client);
    assert(name);
    assert(callback);

    dbus_error_init(&error);

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

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

    b->client = client;
    b->callback = callback;
    b->userdata = userdata;
    b->path = NULL;
    b->name = NULL;
    b->clazz = clazz;
    b->type = type;
    b->interface = interface;
    b->protocol = protocol;

    AVAHI_LLIST_PREPEND(AvahiRecordBrowser, record_browsers, client->record_browsers, b);

    if (!(b->name = avahi_strdup(name))) {
        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, "RecordBrowserNew"))) {
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
        goto fail;
    }

    i_interface = (int32_t) interface;
    i_protocol = (int32_t) protocol;
    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_UINT16, &clazz,
            DBUS_TYPE_UINT16, &type,
            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 (!(b->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 b;

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

    if (b)
        avahi_record_browser_free(b);

    if (message)
        dbus_message_unref(message);

    if (reply)
        dbus_message_unref(reply);

    return NULL;
}