avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_error_init(&error);
/* fprintf(stderr, "dbus: interface=%s, path=%s, member=%s\n", */
dbus_error_init(&error);
/* fprintf(stderr, "dbus: interface=%s, path=%s, member=%s\n", */
} else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameAcquired")) {
/* Ignore this message */
} else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameAcquired")) {
/* Ignore this message */
* available, so we disconnect ourselves */
avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED);
goto fail;
* available, so we disconnect ourselves */
avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED);
goto fail;
if ((ret = init_server(client, NULL)) < 0) {
avahi_client_set_errno(client, ret);
goto fail;
if ((ret = init_server(client, NULL)) < 0) {
avahi_client_set_errno(client, ret);
goto fail;
if ((c = avahi_error_dbus_to_number(e)) != AVAHI_OK)
avahi_client_set_errno(client, c);
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")) {
client_set_state(client, (AvahiClientState) state);
} else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged")) {
for (g = client->groups; g; g = g->groups_next)
if (strcmp(g->path, path) == 0)
break;
for (g = client->groups; g; g = g->groups_next)
if (strcmp(g->path, path) == 0)
break;
if ((c = avahi_error_dbus_to_number(e)) != AVAHI_OK)
avahi_client_set_errno(client, c);
if ((c = avahi_error_dbus_to_number(e)) != AVAHI_OK)
avahi_client_set_errno(client, c);
} else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "ItemNew"))
return avahi_domain_browser_event(client, AVAHI_BROWSER_NEW, message);
} else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "ItemNew"))
return avahi_domain_browser_event(client, AVAHI_BROWSER_NEW, message);
- else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemRemove"))
+ else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "ItemRemove"))
- else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "CacheExhausted"))
+ else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "CacheExhausted"))
return avahi_record_browser_event (client, AVAHI_BROWSER_FAILURE, message);
else {
fprintf(stderr, "WARNING: Unhandled message: interface=%s, path=%s, member=%s\n",
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_path(message),
dbus_message_get_member(message));
dbus_message_get_path(message),
dbus_message_get_member(message));
/* If the method GetAPIVersion is not known, we look if
* GetVersionString matches "avahi 0.6" which is the only
* version we support which doesn't have GetAPIVersion() .*/
/* If the method GetAPIVersion is not known, we look if
* GetVersionString matches "avahi 0.6" which is the only
* version we support which doesn't have GetAPIVersion() .*/
goto fail;
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
goto fail;
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &version_str, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error))
goto fail;
version = strcmp(version_str, "avahi 0.6") == 0 ? 0x0201 : 0x0000;
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &version_str, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error))
goto fail;
version = strcmp(version_str, "avahi 0.6") == 0 ? 0x0201 : 0x0000;
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &version, DBUS_TYPE_INVALID) ||
dbus_error_is_set(&error))
goto fail;
}
/*fprintf(stderr, "API Version 0x%04x\n", version);*/
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &version, DBUS_TYPE_INVALID) ||
dbus_error_is_set(&error))
goto fail;
}
/*fprintf(stderr, "API Version 0x%04x\n", version);*/
if ((version & 0xFF00) != (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0xFF00) ||
(version & 0x00FF) < (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0x00FF)) {
e = AVAHI_ERR_VERSION_MISMATCH;
if ((version & 0xFF00) != (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0xFF00) ||
(version & 0x00FF) < (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0x00FF)) {
e = AVAHI_ERR_VERSION_MISMATCH;
#ifdef HAVE_DBUS_BUS_GET_PRIVATE
if (!(c = dbus_bus_get_private(DBUS_BUS_SYSTEM, error)))
return NULL;
#ifdef HAVE_DBUS_BUS_GET_PRIVATE
if (!(c = dbus_bus_get_private(DBUS_BUS_SYSTEM, error)))
return NULL;
client->host_name = NULL;
client->host_name_fqdn = NULL;
client->domain_name = NULL;
client->version_string = NULL;
client->local_service_cookie_valid = 0;
client->host_name = NULL;
client->host_name_fqdn = NULL;
client->domain_name = NULL;
client->version_string = NULL;
client->local_service_cookie_valid = 0;
AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, client->groups);
AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, client->domain_browsers);
AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, client->service_browsers);
AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, client->groups);
AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, client->domain_browsers);
AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, client->service_browsers);
if (!dbus_connection_add_filter (client->bus, filter_func, client, NULL)) {
if (ret_error)
if (!dbus_connection_add_filter (client->bus, filter_func, client, NULL)) {
if (ret_error)
goto fail;
}
/* The user doesn't want this call to fail if the daemon is not
* available, so let's return succesfully */
client_set_state(client, AVAHI_CLIENT_CONNECTING);
goto fail;
}
/* The user doesn't want this call to fail if the daemon is not
* available, so let's return succesfully */
client_set_state(client, AVAHI_CLIENT_CONNECTING);
avahi_free(client->host_name);
avahi_free(client->host_name_fqdn);
avahi_free(client->domain_name);
avahi_free(client->host_name);
avahi_free(client->host_name_fqdn);
avahi_free(client->domain_name);
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
if (!reply || dbus_error_is_set (&error))
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
if (!reply || dbus_error_is_set (&error))
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error))
goto fail;
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error))
goto fail;
if (!(n = avahi_strdup(ret))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
if (!(n = avahi_strdup(ret))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (!client->domain_name)
client->domain_name = avahi_client_get_string_reply_and_block(client, "GetDomainName", NULL);
if (!client->domain_name)
client->domain_name = avahi_client_get_string_reply_and_block(client, "GetDomainName", NULL);
if (!avahi_client_is_connected(client)) {
avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
return NULL;
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);
if (!client->host_name_fqdn)
client->host_name_fqdn = avahi_client_get_string_reply_and_block(client, "GetHostNameFqdn", NULL);
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, path, interface, method))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, path, interface, method))) {
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 (!(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);
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);
fail:
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
fail:
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &client->local_service_cookie, DBUS_TYPE_INVALID) ||
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;
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (!avahi_client_is_connected(client))
return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
if (!avahi_client_is_connected(client))
return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error);
if (!reply || dbus_error_is_set (&error))
reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error);
if (!reply || dbus_error_is_set (&error))
client->host_name = NULL;
avahi_free(client->host_name_fqdn);
client->host_name_fqdn = NULL;
client->host_name = NULL;
avahi_free(client->host_name_fqdn);
client->host_name_fqdn = NULL;
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);