Mercurial > pidgin.yaz
comparison src/protocols/bonjour/dns_sd.c @ 13909:8264f52a1142
[gaim-migrate @ 16406]
More of sf patch #1490646, from Jonty Wareing & Jono Cole
"The screen name + hostname of the sending user is sent
in the outgoing jabber message, fixing a sporadic
problem with iChat.
The port in use has been fixed to the one described in
the Bonjour specification and can no longer be changed
in the prpl preferences - modifiying this just stops
the client from being able to start a chat.
The option for a buddy icon has been removed for now as
no code actually uses it yet - we plan to change this
in the future.
This update also introduces automatic local port retry
for up to ten attempts if the port is in
use (e.g. if multiple instances of gaim are running)."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 03 Jul 2006 00:37:41 +0000 |
parents | b986b6e2441b |
children |
comparison
equal
deleted
inserted
replaced
13908:cab785a7c766 | 13909:8264f52a1142 |
---|---|
19 #include "dns_sd.h" | 19 #include "dns_sd.h" |
20 #include "bonjour.h" | 20 #include "bonjour.h" |
21 #include "buddy.h" | 21 #include "buddy.h" |
22 #include "debug.h" | 22 #include "debug.h" |
23 | 23 |
24 /* Private data */ | |
25 | |
26 typedef struct _dns_sd_packet | |
27 { | |
28 gchar *name; | |
29 gchar *txtvers; | |
30 gchar *version; | |
31 gchar *first; | |
32 gchar *last; | |
33 gint port_p2pj; | |
34 gchar *phsh; | |
35 gchar *status; | |
36 gchar *message; | |
37 gchar *email; | |
38 gchar *vc; | |
39 gchar *jid; | |
40 gchar *AIM; | |
41 } dns_sd_packet; | |
42 | |
43 /* End private data */ | |
44 | |
45 /* Private functions */ | 24 /* Private functions */ |
46 | 25 |
47 static sw_result HOWL_API | 26 static sw_result HOWL_API |
48 _publish_reply(sw_discovery discovery, sw_discovery_oid oid, | 27 _publish_reply(sw_discovery discovery, sw_discovery_oid oid, |
49 sw_discovery_publish_status status, sw_opaque extra) | 28 sw_discovery_publish_status status, sw_opaque extra) |
81 BonjourBuddy *buddy; | 60 BonjourBuddy *buddy; |
82 GaimAccount *account = (GaimAccount*)extra; | 61 GaimAccount *account = (GaimAccount*)extra; |
83 gchar *txtvers = NULL; | 62 gchar *txtvers = NULL; |
84 gchar *version = NULL; | 63 gchar *version = NULL; |
85 gchar *first = NULL; | 64 gchar *first = NULL; |
86 gint port_p2pj = -1; | |
87 gchar *phsh = NULL; | 65 gchar *phsh = NULL; |
88 gchar *status = NULL; | 66 gchar *status = NULL; |
89 gchar *email = NULL; | 67 gchar *email = NULL; |
90 gchar *last = NULL; | 68 gchar *last = NULL; |
91 gchar *jid = NULL; | 69 gchar *jid = NULL; |
117 txtvers = g_strdup(value); | 95 txtvers = g_strdup(value); |
118 } else if (strcmp(key, "version") == 0) { | 96 } else if (strcmp(key, "version") == 0) { |
119 version = g_strdup(value); | 97 version = g_strdup(value); |
120 } else if (strcmp(key, "1st") == 0) { | 98 } else if (strcmp(key, "1st") == 0) { |
121 first = g_strdup(value); | 99 first = g_strdup(value); |
122 } else if (strcmp(key, "port.p2pj") == 0) { | |
123 port_p2pj = atoi(value); | |
124 } else if (strcmp(key, "status") == 0) { | 100 } else if (strcmp(key, "status") == 0) { |
125 status = g_strdup(value); | 101 status = g_strdup(value); |
126 } else if (strcmp(key, "email") == 0) { | 102 } else if (strcmp(key, "email") == 0) { |
127 email = g_strdup(value); | 103 email = g_strdup(value); |
128 } else if (strcmp(key, "last") == 0) { | 104 } else if (strcmp(key, "last") == 0) { |
141 } | 117 } |
142 } | 118 } |
143 | 119 |
144 /* Put the parameters of the text_record in a buddy and add the buddy to */ | 120 /* Put the parameters of the text_record in a buddy and add the buddy to */ |
145 /* the buddy list */ | 121 /* the buddy list */ |
146 buddy = bonjour_buddy_new(name, first, port_p2pj, phsh, | 122 buddy = bonjour_buddy_new(name, first, port, phsh, |
147 status, email, last, jid, AIM, vc, ip, msg); | 123 status, email, last, jid, AIM, vc, ip, msg); |
148 | 124 |
149 if (bonjour_buddy_check(buddy) == FALSE) | 125 if (bonjour_buddy_check(buddy) == FALSE) |
150 { | 126 { |
151 bonjour_buddy_delete(buddy); | 127 bonjour_buddy_delete(buddy); |
198 break; | 174 break; |
199 case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN: | 175 case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN: |
200 gaim_debug_warning("bonjour", "_browser_reply --> Remove domain\n"); | 176 gaim_debug_warning("bonjour", "_browser_reply --> Remove domain\n"); |
201 break; | 177 break; |
202 case SW_DISCOVERY_BROWSE_ADD_SERVICE: | 178 case SW_DISCOVERY_BROWSE_ADD_SERVICE: |
203 /* A new peer has join the network and uses iChat bonjour */ | 179 /* A new peer has joined the network and uses iChat bonjour */ |
204 gaim_debug_info("bonjour", "_browser_reply --> Add service\n"); | 180 gaim_debug_info("bonjour", "_browser_reply --> Add service\n"); |
205 if (g_ascii_strcasecmp(name, account->username) != 0) | 181 if (g_ascii_strcasecmp(name, account->username) != 0) |
206 { | 182 { |
207 if (sw_discovery_resolve(discovery, interface_index, name, type, | 183 if (sw_discovery_resolve(discovery, interface_index, name, type, |
208 domain, _resolve_reply, extra, &rid) != SW_OKAY) | 184 domain, _resolve_reply, extra, &rid) != SW_OKAY) |
233 static int | 209 static int |
234 _dns_sd_publish(BonjourDnsSd *data, PublishType type) | 210 _dns_sd_publish(BonjourDnsSd *data, PublishType type) |
235 { | 211 { |
236 sw_text_record dns_data; | 212 sw_text_record dns_data; |
237 sw_result publish_result = SW_OKAY; | 213 sw_result publish_result = SW_OKAY; |
214 char portstring[6]; | |
238 | 215 |
239 /* Fill the data for the service */ | 216 /* Fill the data for the service */ |
240 if (sw_text_record_init(&dns_data) != SW_OKAY) | 217 if (sw_text_record_init(&dns_data) != SW_OKAY) |
241 { | 218 { |
242 gaim_debug_error("bonjour", "Unable to initialize the data for the mDNS.\n"); | 219 gaim_debug_error("bonjour", "Unable to initialize the data for the mDNS.\n"); |
243 return -1; | 220 return -1; |
244 } | 221 } |
245 | 222 |
223 /* Convert the port to a string */ | |
224 snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj); | |
225 | |
226 /* Publish standard records */ | |
246 sw_text_record_add_key_and_string_value(dns_data, "txtvers", data->txtvers); | 227 sw_text_record_add_key_and_string_value(dns_data, "txtvers", data->txtvers); |
247 sw_text_record_add_key_and_string_value(dns_data, "version", data->version); | 228 sw_text_record_add_key_and_string_value(dns_data, "version", data->version); |
248 sw_text_record_add_key_and_string_value(dns_data, "1st", data->first); | 229 sw_text_record_add_key_and_string_value(dns_data, "1st", data->first); |
249 sw_text_record_add_key_and_string_value(dns_data, "last", data->last); | 230 sw_text_record_add_key_and_string_value(dns_data, "last", data->last); |
250 /* sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", itoa(data->port_p2pj)); */ | 231 sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", portstring); |
251 sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", BONJOUR_DEFAULT_PORT); | |
252 sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh); | 232 sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh); |
253 sw_text_record_add_key_and_string_value(dns_data, "status", data->status); | 233 sw_text_record_add_key_and_string_value(dns_data, "status", data->status); |
254 sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc); | 234 sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc); |
255 | 235 |
236 /* Publish extra records */ | |
256 if ((data->email != NULL) && (*data->email != '\0')) | 237 if ((data->email != NULL) && (*data->email != '\0')) |
257 sw_text_record_add_key_and_string_value(dns_data, "email", data->email); | 238 sw_text_record_add_key_and_string_value(dns_data, "email", data->email); |
258 | 239 |
259 if ((data->jid != NULL) && (*data->jid != '\0')) | 240 if ((data->jid != NULL) && (*data->jid != '\0')) |
260 sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid); | 241 sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid); |
278 sw_text_record_bytes(dns_data), sw_text_record_len(dns_data)); | 259 sw_text_record_bytes(dns_data), sw_text_record_len(dns_data)); |
279 break; | 260 break; |
280 } | 261 } |
281 if (publish_result != SW_OKAY) | 262 if (publish_result != SW_OKAY) |
282 { | 263 { |
283 gaim_debug_error("bonjour", "Unable to publish or change the status of the _presence._tcp service."); | 264 gaim_debug_error("bonjour", "Unable to publish or change the status of the _presence._tcp service.\n"); |
284 return -1; | 265 return -1; |
285 } | 266 } |
286 | 267 |
287 /* Free the memory used by temp data */ | 268 /* Free the memory used by temp data */ |
288 sw_text_record_fina(dns_data); | 269 sw_text_record_fina(dns_data); |