Lines Matching refs:client
43 static int init_server(AvahiClient *client, int *ret_error);
45 int avahi_client_set_errno (AvahiClient *client, int error) { in avahi_client_set_errno() argument
46 assert(client); in avahi_client_set_errno()
48 return client->error = error; in avahi_client_set_errno()
51 int avahi_client_set_dbus_error(AvahiClient *client, DBusError *error) { in avahi_client_set_dbus_error() argument
52 assert(client); in avahi_client_set_dbus_error()
55 return avahi_client_set_errno(client, avahi_error_dbus_to_number(error->name)); in avahi_client_set_dbus_error()
58 static void client_set_state(AvahiClient *client, AvahiClientState state) { in client_set_state() argument
59 assert(client); in client_set_state()
61 if (client->state == state) in client_set_state()
64 client->state = state; in client_set_state()
66 switch (client->state) { in client_set_state()
68 if (client->bus) { in client_set_state()
70 dbus_connection_close(client->bus); in client_set_state()
72 dbus_connection_disconnect(client->bus); in client_set_state()
74 dbus_connection_unref(client->bus); in client_set_state()
75 client->bus = NULL; in client_set_state()
84 avahi_free(client->host_name); in client_set_state()
85 avahi_free(client->host_name_fqdn); in client_set_state()
86 avahi_free(client->domain_name); in client_set_state()
88 client->host_name = NULL; in client_set_state()
89 client->host_name_fqdn = NULL; in client_set_state()
90 client->domain_name = NULL; in client_set_state()
99 if (client->callback) in client_set_state()
100 client->callback (client, state, client->userdata); in client_set_state()
104 AvahiClient *client = userdata; in filter_func() local
120 avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED); in filter_func()
138 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); in filter_func()
145 avahi_client_is_connected(client)) { in filter_func()
150 avahi_client_set_errno(client, AVAHI_ERR_DISCONNECTED); in filter_func()
153 } else if (client->state == AVAHI_CLIENT_CONNECTING && (!old || *old == 0)) { in filter_func()
158 if ((ret = init_server(client, NULL)) < 0) { in filter_func()
159 avahi_client_set_errno(client, ret); in filter_func()
165 } else if (!avahi_client_is_connected(client)) { in filter_func()
181 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); in filter_func()
186 avahi_client_set_errno(client, c); in filter_func()
188 client_set_state(client, (AvahiClientState) state); in filter_func()
195 for (g = client->groups; g; g = g->groups_next) in filter_func()
212 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); in filter_func()
217 avahi_client_set_errno(client, c); in filter_func()
223 return avahi_domain_browser_event(client, AVAHI_BROWSER_NEW, message); in filter_func()
225 return avahi_domain_browser_event(client, AVAHI_BROWSER_REMOVE, message); in filter_func()
227 return avahi_domain_browser_event(client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); in filter_func()
229 return avahi_domain_browser_event(client, AVAHI_BROWSER_ALL_FOR_NOW, message); in filter_func()
231 return avahi_domain_browser_event(client, AVAHI_BROWSER_FAILURE, message); in filter_func()
234 return avahi_service_type_browser_event (client, AVAHI_BROWSER_NEW, message); in filter_func()
236 return avahi_service_type_browser_event (client, AVAHI_BROWSER_REMOVE, message); in filter_func()
238 return avahi_service_type_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); in filter_func()
240 return avahi_service_type_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message); in filter_func()
242 return avahi_service_type_browser_event (client, AVAHI_BROWSER_FAILURE, message); in filter_func()
245 return avahi_service_browser_event (client, AVAHI_BROWSER_NEW, message); in filter_func()
247 return avahi_service_browser_event (client, AVAHI_BROWSER_REMOVE, message); in filter_func()
249 return avahi_service_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); in filter_func()
251 return avahi_service_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message); in filter_func()
253 return avahi_service_browser_event (client, AVAHI_BROWSER_FAILURE, message); in filter_func()
256 return avahi_service_resolver_event (client, AVAHI_RESOLVER_FOUND, message); in filter_func()
258 return avahi_service_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); in filter_func()
261 return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FOUND, message); in filter_func()
263 return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); in filter_func()
266 return avahi_address_resolver_event (client, AVAHI_RESOLVER_FOUND, message); in filter_func()
268 return avahi_address_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); in filter_func()
271 return avahi_record_browser_event (client, AVAHI_BROWSER_NEW, message); in filter_func()
273 return avahi_record_browser_event (client, AVAHI_BROWSER_REMOVE, message); in filter_func()
275 return avahi_record_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); in filter_func()
277 return avahi_record_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message); in filter_func()
279 return avahi_record_browser_event (client, AVAHI_BROWSER_FAILURE, message); in filter_func()
296 avahi_client_set_errno(client, avahi_error_dbus_to_number(error.name)); in filter_func()
300 client_set_state(client, AVAHI_CLIENT_FAILURE); in filter_func()
305 static int get_server_state(AvahiClient *client, int *ret_error) { in get_server_state() argument
311 assert(client); in get_server_state()
318 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in get_server_state()
327 client_set_state(client, (AvahiClientState) state); in get_server_state()
351 static int check_version(AvahiClient *client, int *ret_error) { in check_version() argument
357 assert(client); in check_version()
364 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in check_version()
383 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in check_version()
431 static int init_server(AvahiClient *client, int *ret_error) { in init_server() argument
434 if ((r = check_version(client, ret_error)) < 0) in init_server()
437 if ((r = get_server_state(client, ret_error)) < 0) in init_server()
479 AvahiClient *client = NULL; in avahi_client_new() local
487 if (!(client = avahi_new(AvahiClient, 1))) { in avahi_client_new()
493 client->poll_api = poll_api; in avahi_client_new()
494 client->error = AVAHI_OK; in avahi_client_new()
495 client->callback = callback; in avahi_client_new()
496 client->userdata = userdata; in avahi_client_new()
497 client->state = (AvahiClientState) -1; in avahi_client_new()
498 client->flags = flags; in avahi_client_new()
500 client->host_name = NULL; in avahi_client_new()
501 client->host_name_fqdn = NULL; in avahi_client_new()
502 client->domain_name = NULL; in avahi_client_new()
503 client->version_string = NULL; in avahi_client_new()
504 client->local_service_cookie_valid = 0; in avahi_client_new()
506 AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, client->groups); in avahi_client_new()
507 AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, client->domain_browsers); in avahi_client_new()
508 AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, client->service_browsers); in avahi_client_new()
509 AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, client->service_type_browsers); in avahi_client_new()
510 AVAHI_LLIST_HEAD_INIT(AvahiServiceResolver, client->service_resolvers); in avahi_client_new()
511 AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, client->host_name_resolvers); in avahi_client_new()
512 AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, client->address_resolvers); in avahi_client_new()
513 AVAHI_LLIST_HEAD_INIT(AvahiRecordBrowser, client->record_browsers); in avahi_client_new()
515 if (!(client->bus = avahi_dbus_bus_get(&error)) || dbus_error_is_set(&error)) { in avahi_client_new()
521 if (avahi_dbus_connection_glue(client->bus, poll_api) < 0) { in avahi_client_new()
527 if (!dbus_connection_add_filter(client->bus, filter_func, client, NULL)) { in avahi_client_new()
534 client->bus, in avahi_client_new()
545 client->bus, in avahi_client_new()
556 client->bus, in avahi_client_new()
567 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in avahi_client_new()
584 client_set_state(client, AVAHI_CLIENT_CONNECTING); in avahi_client_new()
588 if (init_server(client, ret_error) < 0) in avahi_client_new()
597 return client; in avahi_client_new()
606 if (client) in avahi_client_new()
607 avahi_client_free(client); in avahi_client_new()
625 void avahi_client_free(AvahiClient *client) { in avahi_client_free() argument
626 assert(client); in avahi_client_free()
628 if (client->bus) in avahi_client_free()
632 dbus_connection_close(client->bus); in avahi_client_free()
634 dbus_connection_disconnect(client->bus); in avahi_client_free()
637 while (client->groups) in avahi_client_free()
638 avahi_entry_group_free(client->groups); in avahi_client_free()
640 while (client->domain_browsers) in avahi_client_free()
641 avahi_domain_browser_free(client->domain_browsers); in avahi_client_free()
643 while (client->service_browsers) in avahi_client_free()
644 avahi_service_browser_free(client->service_browsers); in avahi_client_free()
646 while (client->service_type_browsers) in avahi_client_free()
647 avahi_service_type_browser_free(client->service_type_browsers); in avahi_client_free()
649 while (client->service_resolvers) in avahi_client_free()
650 avahi_service_resolver_free(client->service_resolvers); in avahi_client_free()
652 while (client->host_name_resolvers) in avahi_client_free()
653 avahi_host_name_resolver_free(client->host_name_resolvers); in avahi_client_free()
655 while (client->address_resolvers) in avahi_client_free()
656 avahi_address_resolver_free(client->address_resolvers); in avahi_client_free()
658 while (client->record_browsers) in avahi_client_free()
659 avahi_record_browser_free(client->record_browsers); in avahi_client_free()
661 if (client->bus) in avahi_client_free()
662 dbus_connection_unref(client->bus); in avahi_client_free()
664 avahi_free(client->version_string); in avahi_client_free()
665 avahi_free(client->host_name); in avahi_client_free()
666 avahi_free(client->host_name_fqdn); in avahi_client_free()
667 avahi_free(client->domain_name); in avahi_client_free()
669 avahi_free(client); in avahi_client_free()
672 static char* avahi_client_get_string_reply_and_block (AvahiClient *client, const char *method, cons… in avahi_client_get_string_reply_and_block() argument
677 assert(client); in avahi_client_get_string_reply_and_block()
683 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); in avahi_client_get_string_reply_and_block()
689 avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY); in avahi_client_get_string_reply_and_block()
694 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in avahi_client_get_string_reply_and_block()
704 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); in avahi_client_get_string_reply_and_block()
721 avahi_client_set_dbus_error(client, &error); in avahi_client_get_string_reply_and_block()
728 const char* avahi_client_get_version_string(AvahiClient *client) { in avahi_client_get_version_string() argument
729 assert(client); in avahi_client_get_version_string()
731 if (!avahi_client_is_connected(client)) { in avahi_client_get_version_string()
732 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_get_version_string()
736 if (!client->version_string) in avahi_client_get_version_string()
737 …client->version_string = avahi_client_get_string_reply_and_block(client, "GetVersionString", NULL); in avahi_client_get_version_string()
739 return client->version_string; in avahi_client_get_version_string()
742 const char* avahi_client_get_domain_name(AvahiClient *client) { in avahi_client_get_domain_name() argument
743 assert(client); in avahi_client_get_domain_name()
745 if (!avahi_client_is_connected(client)) { in avahi_client_get_domain_name()
746 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_get_domain_name()
750 if (!client->domain_name) in avahi_client_get_domain_name()
751 … client->domain_name = avahi_client_get_string_reply_and_block(client, "GetDomainName", NULL); in avahi_client_get_domain_name()
753 return client->domain_name; in avahi_client_get_domain_name()
756 const char* avahi_client_get_host_name(AvahiClient *client) { in avahi_client_get_host_name() argument
757 assert(client); in avahi_client_get_host_name()
759 if (!avahi_client_is_connected(client)) { in avahi_client_get_host_name()
760 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_get_host_name()
764 if (!client->host_name) in avahi_client_get_host_name()
765 client->host_name = avahi_client_get_string_reply_and_block(client, "GetHostName", NULL); in avahi_client_get_host_name()
767 return client->host_name; in avahi_client_get_host_name()
770 const char* avahi_client_get_host_name_fqdn (AvahiClient *client) { in avahi_client_get_host_name_fqdn() argument
771 assert(client); in avahi_client_get_host_name_fqdn()
773 if (!avahi_client_is_connected(client)) { in avahi_client_get_host_name_fqdn()
774 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_get_host_name_fqdn()
778 if (!client->host_name_fqdn) in avahi_client_get_host_name_fqdn()
779 … client->host_name_fqdn = avahi_client_get_string_reply_and_block(client, "GetHostNameFqdn", NULL); in avahi_client_get_host_name_fqdn()
781 return client->host_name_fqdn; in avahi_client_get_host_name_fqdn()
784 AvahiClientState avahi_client_get_state(AvahiClient *client) { in avahi_client_get_state() argument
785 assert(client); in avahi_client_get_state()
787 return client->state; in avahi_client_get_state()
790 int avahi_client_errno(AvahiClient *client) { in avahi_client_errno() argument
791 assert(client); in avahi_client_errno()
793 return client->error; in avahi_client_errno()
797 int avahi_client_simple_method_call(AvahiClient *client, const char *path, const char *interface, c… in avahi_client_simple_method_call() argument
804 assert(client); in avahi_client_simple_method_call()
810 r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); in avahi_client_simple_method_call()
814 if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) || in avahi_client_simple_method_call()
816 r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); in avahi_client_simple_method_call()
822 r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); in avahi_client_simple_method_call()
833 r = avahi_client_set_dbus_error(client, &error); in avahi_client_simple_method_call()
846 uint32_t avahi_client_get_local_service_cookie(AvahiClient *client) { in avahi_client_get_local_service_cookie() argument
849 assert(client); in avahi_client_get_local_service_cookie()
851 if (!avahi_client_is_connected(client)) { in avahi_client_get_local_service_cookie()
852 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_get_local_service_cookie()
856 if (client->local_service_cookie_valid) in avahi_client_get_local_service_cookie()
857 return client->local_service_cookie; in avahi_client_get_local_service_cookie()
862 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); in avahi_client_get_local_service_cookie()
866 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); in avahi_client_get_local_service_cookie()
871 …if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &client->local_service_cookie, DBUS_T… in avahi_client_get_local_service_cookie()
878 client->local_service_cookie_valid = 1; in avahi_client_get_local_service_cookie()
879 return client->local_service_cookie; in avahi_client_get_local_service_cookie()
889 avahi_client_set_dbus_error(client, &error); in avahi_client_get_local_service_cookie()
896 int avahi_client_is_connected(AvahiClient *client) { in avahi_client_is_connected() argument
897 assert(client); in avahi_client_is_connected()
900 client->bus && in avahi_client_is_connected()
901 dbus_connection_get_is_connected(client->bus) && in avahi_client_is_connected()
902 …(client->state == AVAHI_CLIENT_S_RUNNING || client->state == AVAHI_CLIENT_S_REGISTERING || client-… in avahi_client_is_connected()
905 int avahi_client_set_host_name(AvahiClient* client, const char *name) { in avahi_client_set_host_name() argument
909 assert(client); in avahi_client_set_host_name()
911 if (!avahi_client_is_connected(client)) in avahi_client_set_host_name()
912 return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); in avahi_client_set_host_name()
917 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); in avahi_client_set_host_name()
922 avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY); in avahi_client_set_host_name()
926 reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error); in avahi_client_set_host_name()
938 avahi_free(client->host_name); in avahi_client_set_host_name()
939 client->host_name = NULL; in avahi_client_set_host_name()
940 avahi_free(client->host_name_fqdn); in avahi_client_set_host_name()
941 client->host_name_fqdn = NULL; in avahi_client_set_host_name()
953 avahi_client_set_dbus_error(client, &error); in avahi_client_set_host_name()
957 return client->error; in avahi_client_set_host_name()