Mercurial > pidgin.yaz
comparison libpurple/protocols/bonjour/mdns_common.c @ 18798:ed1def07d86e
Refactor the bonjour mdns implementation abstraction in preparation for the avahi implementation. Also fix alias assignment from the server to populate the server alias instead of the local alias.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sun, 05 Aug 2007 02:44:53 +0000 |
parents | 1faa319ab4c3 |
children | b839f427cbb2 |
comparison
equal
deleted
inserted
replaced
18796:95fe5195bf98 | 18798:ed1def07d86e |
---|---|
15 */ | 15 */ |
16 | 16 |
17 #include <string.h> | 17 #include <string.h> |
18 | 18 |
19 #include "internal.h" | 19 #include "internal.h" |
20 #include "config.h" | |
21 #include "mdns_common.h" | 20 #include "mdns_common.h" |
21 #include "mdns_interface.h" | |
22 #include "bonjour.h" | 22 #include "bonjour.h" |
23 #include "buddy.h" | 23 #include "buddy.h" |
24 #include "debug.h" | 24 #include "debug.h" |
25 | 25 |
26 | 26 |
71 * for other bonjour peers. | 71 * for other bonjour peers. |
72 */ | 72 */ |
73 gboolean | 73 gboolean |
74 bonjour_dns_sd_start(BonjourDnsSd *data) | 74 bonjour_dns_sd_start(BonjourDnsSd *data) |
75 { | 75 { |
76 PurpleAccount *account; | |
77 PurpleConnection *gc; | 76 PurpleConnection *gc; |
78 gint dns_sd_socket; | |
79 gpointer opaque_data; | |
80 | 77 |
81 #ifdef USE_BONJOUR_HOWL | 78 gc = purple_account_get_connection(data->account); |
82 sw_discovery_oid session_id; | |
83 #endif | |
84 | |
85 account = data->account; | |
86 gc = purple_account_get_connection(account); | |
87 | 79 |
88 /* Initialize the dns-sd data and session */ | 80 /* Initialize the dns-sd data and session */ |
89 #ifndef USE_BONJOUR_APPLE | 81 if (!_mdns_init_session(data)) |
90 if (sw_discovery_init(&data->session) != SW_OKAY) | |
91 { | |
92 purple_debug_error("bonjour", "Unable to initialize an mDNS session.\n"); | |
93 | |
94 /* In Avahi, sw_discovery_init frees data->session but doesn't clear it */ | |
95 data->session = NULL; | |
96 | |
97 return FALSE; | 82 return FALSE; |
98 } | |
99 #endif | |
100 | 83 |
101 /* Publish our bonjour IM client at the mDNS daemon */ | 84 /* Publish our bonjour IM client at the mDNS daemon */ |
102 | 85 if (!_mdns_publish(data, PUBLISH_START)) |
103 if (0 != _mdns_publish(data, PUBLISH_START)) | |
104 { | |
105 return FALSE; | 86 return FALSE; |
106 } | |
107 | 87 |
108 /* Advise the daemon that we are waiting for connections */ | 88 /* Advise the daemon that we are waiting for connections */ |
109 | 89 if (!_mdns_browse(data)) { |
110 #ifdef USE_BONJOUR_APPLE | |
111 if (DNSServiceBrowse(&data->browser, 0, 0, ICHAT_SERVICE, NULL, _mdns_service_browse_callback, account) | |
112 != kDNSServiceErr_NoError) | |
113 #else /* USE_BONJOUR_HOWL */ | |
114 if (sw_discovery_browse(data->session, 0, ICHAT_SERVICE, NULL, _browser_reply, | |
115 account, &session_id) != SW_OKAY) | |
116 #endif | |
117 { | |
118 purple_debug_error("bonjour", "Unable to get service."); | 90 purple_debug_error("bonjour", "Unable to get service."); |
119 return FALSE; | 91 return FALSE; |
120 } | 92 } |
121 | 93 |
94 | |
122 /* Get the socket that communicates with the mDNS daemon and bind it to a */ | 95 /* Get the socket that communicates with the mDNS daemon and bind it to a */ |
123 /* callback that will handle the dns_sd packets */ | 96 /* callback that will handle the dns_sd packets */ |
124 | 97 gc->inpa = _mdns_register_to_mainloop(data); |
125 #ifdef USE_BONJOUR_APPLE | |
126 dns_sd_socket = DNSServiceRefSockFD(data->browser); | |
127 opaque_data = data->browser; | |
128 #else /* USE_BONJOUR_HOWL */ | |
129 dns_sd_socket = sw_discovery_socket(data->session); | |
130 opaque_data = data->session; | |
131 #endif | |
132 | |
133 gc->inpa = purple_input_add(dns_sd_socket, PURPLE_INPUT_READ, | |
134 _mdns_handle_event, opaque_data); | |
135 | 98 |
136 return TRUE; | 99 return TRUE; |
137 } | 100 } |
138 | 101 |
139 /** | 102 /** |
141 */ | 104 */ |
142 | 105 |
143 void | 106 void |
144 bonjour_dns_sd_stop(BonjourDnsSd *data) | 107 bonjour_dns_sd_stop(BonjourDnsSd *data) |
145 { | 108 { |
146 PurpleAccount *account; | |
147 PurpleConnection *gc; | 109 PurpleConnection *gc; |
148 | 110 |
149 #ifdef USE_BONJOUR_APPLE | 111 _mdns_stop(data); |
150 if (data->advertisement == NULL || data->browser == NULL) | |
151 #else /* USE_BONJOUR_HOWL */ | |
152 if (data->session == NULL) | |
153 #endif | |
154 return; | |
155 | 112 |
156 #ifdef USE_BONJOUR_HOWL | 113 gc = purple_account_get_connection(data->account); |
157 sw_discovery_cancel(data->session, data->session_id); | |
158 #endif | |
159 | |
160 account = data->account; | |
161 gc = purple_account_get_connection(account); | |
162 purple_input_remove(gc->inpa); | 114 purple_input_remove(gc->inpa); |
163 | |
164 #ifdef USE_BONJOUR_APPLE | |
165 /* hack: for win32, we need to stop listening to the advertisement pipe too */ | |
166 purple_input_remove(data->advertisement_handler); | |
167 | |
168 DNSServiceRefDeallocate(data->advertisement); | |
169 DNSServiceRefDeallocate(data->browser); | |
170 data->advertisement = NULL; | |
171 data->browser = NULL; | |
172 #else /* USE_BONJOUR_HOWL */ | |
173 g_free(data->session); | |
174 data->session = NULL; | |
175 #endif | |
176 } | 115 } |