annotate libpurple/protocols/bonjour/mdns_win32.c @ 19573:affacee881e8

Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times. Thanks to Lennart from the Avahi team for suggestions on how to improve the avahi implementation.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 02 Sep 2007 17:54:44 +0000
parents 649ac48fce1d
children 941965d6fd88
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
1 /*
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
2 * This program is free software; you can redistribute it and/or modify
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
3 * it under the terms of the GNU General Public License as published by
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
5 * (at your option) any later version.
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
6 *
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
7 * This program is distributed in the hope that it will be useful,
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
10 * GNU Library General Public License for more details.
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
11 *
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
12 * You should have received a copy of the GNU General Public License
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
13 * along with this program; if not, write to the Free Software
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
15 */
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
16
18276
1faa319ab4c3 More compile fixes from rekkanoryo for G_GNUC_NULL_TERMINATED issues
Stu Tomlinson <stu@nosnilmot.com>
parents: 17552
diff changeset
17 #include "internal.h"
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
18 #include "debug.h"
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
19
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
20 #include "buddy.h"
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
21 #include "mdns_interface.h"
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
22 #include "dns_sd_proxy.h"
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
23 #include "dnsquery.h"
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
24 #include "mdns_common.h"
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
25
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
26
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
27 /* data structure for the resolve callback */
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
28 typedef struct _ResolveCallbackArgs {
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
29 DNSServiceRef resolver;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
30 guint resolver_handler;
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
31 gchar *full_service_name;
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
32
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
33 PurpleDnsQueryData *query;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
34
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
35 BonjourBuddy* buddy;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
36 } ResolveCallbackArgs;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
37
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
38 /* data used by win32 bonjour implementation */
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
39 typedef struct _win32_session_impl_data {
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
40 DNSServiceRef presence_svc;
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
41 DNSServiceRef browser_svc;
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
42 DNSRecordRef buddy_icon_rec;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
43
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
44 guint presence_handler;
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
45 guint browser_handler;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
46 } Win32SessionImplData;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
47
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
48 typedef struct _win32_buddy_impl_data {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
49 DNSServiceRef txt_query;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
50 guint txt_query_handler;
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
51 DNSServiceRef null_query;
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
52 guint null_query_handler;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
53 } Win32BuddyImplData;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
54
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
55 static void
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
56 _mdns_handle_event(gpointer data, gint source, PurpleInputCondition condition) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
57 DNSServiceProcessResult((DNSServiceRef) data);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
58 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
59
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
60 static void
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
61 _mdns_parse_text_record(BonjourBuddy* buddy, const char* record, uint16_t record_len)
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
62 {
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
63 const char *txt_entry;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
64 uint8_t txt_len;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
65 int i;
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
66
18858
f773aa054dca Clear bonjour buddy values before resetting them so that we notice value removals.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18856
diff changeset
67 clear_bonjour_buddy_values(buddy);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
68 for (i = 0; buddy_TXT_records[i] != NULL; i++) {
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
69 txt_entry = TXTRecordGetValuePtr(record_len, record, buddy_TXT_records[i], &txt_len);
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
70 if (txt_entry != NULL)
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
71 set_bonjour_buddy_value(buddy, buddy_TXT_records[i], txt_entry, txt_len);
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
72 }
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
73 }
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
74
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
75 static void DNSSD_API
18856
5da32c4019ce Show bonjour status messages in the buddy list.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18849
diff changeset
76 _mdns_record_query_callback(DNSServiceRef DNSServiceRef, DNSServiceFlags flags,
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
77 uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname,
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
78 uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata,
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
79 uint32_t ttl, void *context)
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
80 {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
81
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
82 if (kDNSServiceErr_NoError != errorCode) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
83 purple_debug_error("bonjour", "record query - callback error.\n");
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
84 /* TODO: Probably should remove the buddy when this happens */
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
85 } else if (flags & kDNSServiceFlagsAdd) {
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
86 if (rrtype == kDNSServiceType_TXT) {
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
87 /* New Buddy */
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
88 BonjourBuddy *bb = (BonjourBuddy*) context;
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
89 _mdns_parse_text_record(bb, rdata, rdlen);
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
90 bonjour_buddy_add_to_purple(bb, NULL);
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
91 } else if (rrtype == kDNSServiceType_NULL) {
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
92 /* Buddy Icon response */
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
93 BonjourBuddy *bb = (BonjourBuddy*) context;
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
94 Win32BuddyImplData *idata = bb->mdns_impl_data;
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
95
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
96 g_return_if_fail(idata != NULL);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
97
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
98 bonjour_buddy_got_buddy_icon(bb, rdata, rdlen);
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
99
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
100 /* We've got what we need; stop listening */
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
101 purple_input_remove(idata->null_query_handler);
19399
649ac48fce1d Reset unsigned int input handlers to 0 instead of -1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18859
diff changeset
102 idata->null_query_handler = 0;
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
103 DNSServiceRefDeallocate(idata->null_query);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
104 idata->null_query = NULL;
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
105 }
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
106 }
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
107 }
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
108
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
109 static void
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
110 _mdns_resolve_host_callback(GSList *hosts, gpointer data, const char *error_message)
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
111 {
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
112 ResolveCallbackArgs* args = (ResolveCallbackArgs*)data;
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
113 BonjourBuddy* bb = args->buddy;
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
114
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
115 if (!hosts || !hosts->data) {
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
116 purple_debug_error("bonjour", "host resolution - callback error.\n");
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
117 bonjour_buddy_delete(bb);
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
118 } else {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
119 struct sockaddr_in *addr = (struct sockaddr_in*)g_slist_nth_data(hosts, 1);
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
120 Win32BuddyImplData *idata = bb->mdns_impl_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
121
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
122 g_return_if_fail(idata != NULL);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
123
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
124 g_free(bb->ip);
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
125 bb->ip = g_strdup(inet_ntoa(addr->sin_addr));
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
126
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
127 /* finally, set up the continuous txt record watcher, and add the buddy to purple */
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
128
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
129 if (kDNSServiceErr_NoError == DNSServiceQueryRecord(&idata->txt_query, kDNSServiceFlagsLongLivedQuery,
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
130 kDNSServiceInterfaceIndexAny, args->full_service_name, kDNSServiceType_TXT,
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
131 kDNSServiceClass_IN, _mdns_record_query_callback, bb)) {
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
132
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
133 purple_debug_info("bonjour", "Found buddy %s at %s:%d\n", bb->name, bb->ip, bb->port_p2pj);
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
134
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
135 idata->txt_query_handler = purple_input_add(DNSServiceRefSockFD(idata->txt_query),
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
136 PURPLE_INPUT_READ, _mdns_handle_event, idata->txt_query);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
137
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
138 bonjour_buddy_add_to_purple(bb, NULL);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
139 } else
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
140 bonjour_buddy_delete(bb);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
141
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
142 }
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
143
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
144 /* free the hosts list*/
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
145 g_slist_free(hosts);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
146
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
147 /* free the remaining args memory */
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
148 purple_dnsquery_destroy(args->query);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
149 g_free(args->full_service_name);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
150 g_free(args);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
151 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
152
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
153 static void DNSSD_API
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
154 _mdns_service_resolve_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode,
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
155 const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const char *txtRecord, void *context)
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
156 {
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
157 ResolveCallbackArgs *args = (ResolveCallbackArgs*)context;
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
158
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
159 /* remove the input fd and destroy the service ref */
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
160 purple_input_remove(args->resolver_handler);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
161 DNSServiceRefDeallocate(args->resolver);
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
162
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
163 if (kDNSServiceErr_NoError != errorCode)
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
164 {
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
165 purple_debug_error("bonjour", "service resolver - callback error.\n");
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
166 bonjour_buddy_delete(args->buddy);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
167 g_free(args);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
168 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
169 else
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
170 {
17506
bbe9248337ea Fix network byte order issues with win32 bonjour stuff. Also copy the buddy's ip address so that subsequent calls don't overwrite it (it already is being copied and freed because of the howl implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17505
diff changeset
171 args->buddy->port_p2pj = ntohs(port);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
172
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
173 /* parse the text record */
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
174 _mdns_parse_text_record(args->buddy, txtRecord, txtLen);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
175
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
176 /* set more arguments, and start the host resolver */
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
177 args->full_service_name = g_strdup(fullname);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
178
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
179 if (!(args->query =
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
180 purple_dnsquery_a(hosttarget, port, _mdns_resolve_host_callback, args)))
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
181 {
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
182 purple_debug_error("bonjour", "service resolver - host resolution failed.\n");
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
183 bonjour_buddy_delete(args->buddy);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
184 g_free(args->full_service_name);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
185 g_free(args);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
186 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
187 }
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
188
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
189 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
190
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
191 static void DNSSD_API
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
192 _mdns_service_register_callback(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode,
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
193 const char *name, const char *regtype, const char *domain, void *context) {
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
194
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
195 /* TODO: deal with collision */
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
196 if (kDNSServiceErr_NoError != errorCode)
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
197 purple_debug_error("bonjour", "service advertisement - callback error (%d).\n", errorCode);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
198 else
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
199 purple_debug_info("bonjour", "service advertisement - callback.\n");
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
200 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
201
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
202 static void DNSSD_API
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
203 _mdns_service_browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
204 DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context)
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
205 {
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
206 PurpleAccount *account = (PurpleAccount*)context;
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
207 PurpleBuddy *pb = NULL;
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
208
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
209 if (kDNSServiceErr_NoError != errorCode)
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
210 purple_debug_error("bonjour", "service browser - callback error");
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
211 else if (flags & kDNSServiceFlagsAdd) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
212 /* A presence service instance has been discovered... check it isn't us! */
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
213 if (purple_utf8_strcasecmp(serviceName, account->username) != 0) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
214 /* OK, lets go ahead and resolve it to add to the buddy list */
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
215 ResolveCallbackArgs *args = g_new0(ResolveCallbackArgs, 1);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
216 args->buddy = bonjour_buddy_new(serviceName, account);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
217
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
218 if (kDNSServiceErr_NoError != DNSServiceResolve(&args->resolver, 0, 0, serviceName, regtype,
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
219 replyDomain, _mdns_service_resolve_callback, args)) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
220 bonjour_buddy_delete(args->buddy);
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
221 g_free(args);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
222 purple_debug_error("bonjour", "service browser - failed to resolve service.\n");
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
223 } else {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
224 /* get a file descriptor for this service ref, and add it to the input list */
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
225 gint fd = DNSServiceRefSockFD(args->resolver);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
226 args->resolver_handler = purple_input_add(fd, PURPLE_INPUT_READ, _mdns_handle_event, args->resolver);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
227 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
228 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
229 } else {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
230 /* A peer has sent a goodbye packet, remove them from the buddy list */
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
231 purple_debug_info("bonjour", "service browser - remove notification\n");
19573
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
232 pb = purple_find_buddy(account, serviceName);
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
233 if (pb != NULL)
affacee881e8 Fix a couple potential leaks and prevent the avahi record resolver from being freed multiple times.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19399
diff changeset
234 purple_blist_remove_buddy(pb);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
235 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
236 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
237
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
238 /****************************
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
239 * mdns_interface functions *
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
240 ****************************/
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
241
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
242 gboolean _mdns_init_session(BonjourDnsSd *data) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
243 data->mdns_impl_data = g_new0(Win32SessionImplData, 1);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
244 return TRUE;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
245 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
246
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
247 gboolean _mdns_publish(BonjourDnsSd *data, PublishType type, GSList *records) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
248 TXTRecordRef dns_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
249 gboolean ret = TRUE;
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
250 DNSServiceErrorType set_ret = kDNSServiceErr_NoError;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
251 Win32SessionImplData *idata = data->mdns_impl_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
252
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
253 g_return_val_if_fail(idata != NULL, FALSE);
17501
c96b085ddf5c Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17495
diff changeset
254
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
255 TXTRecordCreate(&dns_data, 256, NULL);
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
256
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
257 while (records) {
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
258 PurpleKeyValuePair *kvp = records->data;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
259 set_ret = TXTRecordSetValue(&dns_data, kvp->key, strlen(kvp->value), kvp->value);
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
260 if (set_ret != kDNSServiceErr_NoError)
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
261 break;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
262 records = records->next;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
263 }
17501
c96b085ddf5c Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17495
diff changeset
264
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
265 if (set_ret != kDNSServiceErr_NoError) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
266 purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
267 ret = FALSE;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
268 } else {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
269 DNSServiceErrorType err = kDNSServiceErr_NoError;
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
270
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
271 /* OK, we're done constructing the text record, (re)publish the service */
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
272
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
273 switch (type) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
274 case PUBLISH_START:
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
275 purple_debug_info("bonjour", "Registering presence on port %d\n", data->port_p2pj);
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
276 err = DNSServiceRegister(&idata->presence_svc, 0, 0, purple_account_get_username(data->account), ICHAT_SERVICE,
17506
bbe9248337ea Fix network byte order issues with win32 bonjour stuff. Also copy the buddy's ip address so that subsequent calls don't overwrite it (it already is being copied and freed because of the howl implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17505
diff changeset
277 NULL, NULL, htons(data->port_p2pj), TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data),
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
278 _mdns_service_register_callback, NULL);
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
279 break;
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
280
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
281 case PUBLISH_UPDATE:
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
282 purple_debug_info("bonjour", "Updating presence.\n");
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
283 err = DNSServiceUpdateRecord(idata->presence_svc, NULL, 0, TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data), 0);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
284 break;
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
285 }
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
286
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
287 if (err != kDNSServiceErr_NoError) {
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
288 purple_debug_error("bonjour", "Failed to publish presence service.\n");
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
289 ret = FALSE;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
290 } else if (type == PUBLISH_START) {
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
291 /* We need to do this because according to the Apple docs:
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
292 * "the client is responsible for ensuring that DNSServiceProcessResult() is called
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
293 * whenever there is a reply from the daemon - the daemon may terminate its connection
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
294 * with a client that does not process the daemon's responses */
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
295 idata->presence_handler = purple_input_add(DNSServiceRefSockFD(idata->presence_svc),
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
296 PURPLE_INPUT_READ, _mdns_handle_event, idata->presence_svc);
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
297 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
298 }
17505
9ccec98b8ca9 Cleanup win32 of bonjour stuff - fix to only use glib to allocate and free memory to avoid confusion later.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17504
diff changeset
299
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
300 /* Free the memory used by temp data */
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
301 TXTRecordDeallocate(&dns_data);
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
302 return ret;
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
303 }
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
304
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
305 gboolean _mdns_browse(BonjourDnsSd *data) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
306 Win32SessionImplData *idata = data->mdns_impl_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
307
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
308 g_return_val_if_fail(idata != NULL, FALSE);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
309
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
310 if (DNSServiceBrowse(&idata->browser_svc, 0, 0, ICHAT_SERVICE, NULL,
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
311 _mdns_service_browse_callback, data->account)
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
312 == kDNSServiceErr_NoError) {
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
313 idata->browser_handler = purple_input_add(DNSServiceRefSockFD(idata->browser_svc),
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
314 PURPLE_INPUT_READ, _mdns_handle_event, idata->browser_svc);
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
315 return TRUE;
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
316 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
317
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
318 return FALSE;
17495
d7b50cac1c7a This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
319 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
320
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
321 void _mdns_stop(BonjourDnsSd *data) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
322 Win32SessionImplData *idata = data->mdns_impl_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
323
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
324 if (idata == NULL)
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
325 return;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
326
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
327 if (idata->presence_svc != NULL) {
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
328 purple_input_remove(idata->presence_handler);
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
329 DNSServiceRefDeallocate(idata->presence_svc);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
330 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
331
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
332 if (idata->browser_svc != NULL) {
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
333 purple_input_remove(idata->browser_handler);
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
334 DNSServiceRefDeallocate(idata->browser_svc);
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
335 }
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
336
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
337 g_free(idata);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
338
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
339 data->mdns_impl_data = NULL;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
340 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
341
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
342 gboolean _mdns_set_buddy_icon_data(BonjourDnsSd *data, gconstpointer avatar_data, gsize avatar_len) {
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
343 Win32SessionImplData *idata = data->mdns_impl_data;
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
344 DNSServiceErrorType err = kDNSServiceErr_NoError;
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
345
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
346 g_return_val_if_fail(idata != NULL, FALSE);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
347
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
348 if (avatar_data != NULL && idata->buddy_icon_rec == NULL) {
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
349 purple_debug_info("bonjour", "Setting new buddy icon.\n");
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
350 err = DNSServiceAddRecord(idata->presence_svc, &idata->buddy_icon_rec,
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
351 0, kDNSServiceType_NULL, avatar_len, avatar_data, 0);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
352 } else if (avatar_data != NULL) {
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
353 purple_debug_info("bonjour", "Updating existing buddy icon.\n");
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
354 err = DNSServiceUpdateRecord(idata->presence_svc, idata->buddy_icon_rec,
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
355 0, avatar_len, avatar_data, 0);
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
356 } else if (idata->buddy_icon_rec != NULL) {
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
357 purple_debug_info("bonjour", "Removing existing buddy icon.\n");
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
358 DNSServiceRemoveRecord(idata->presence_svc, idata->buddy_icon_rec, 0);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
359 idata->buddy_icon_rec = NULL;
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
360 }
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
361
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
362 if (err != kDNSServiceErr_NoError)
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
363 purple_debug_error("bonjour", "Error (%d) setting buddy icon record.\n", err);
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
364
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
365 return (err == kDNSServiceErr_NoError);
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
366 }
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
367
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
368 void _mdns_init_buddy(BonjourBuddy *buddy) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
369 buddy->mdns_impl_data = g_new0(Win32BuddyImplData, 1);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
370 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
371
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
372 void _mdns_delete_buddy(BonjourBuddy *buddy) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
373 Win32BuddyImplData *idata = buddy->mdns_impl_data;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
374
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
375 g_return_if_fail(idata != NULL);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
376
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
377 if (idata->txt_query != NULL) {
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
378 purple_input_remove(idata->txt_query_handler);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
379 DNSServiceRefDeallocate(idata->txt_query);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
380 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
381
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
382 if (idata->null_query != NULL) {
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
383 purple_input_remove(idata->null_query_handler);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
384 DNSServiceRefDeallocate(idata->null_query);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
385 }
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
386
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
387 g_free(idata);
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
388
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
389 buddy->mdns_impl_data = NULL;
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
390 }
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.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18761
diff changeset
391
18849
1787e601aafc _mdns_retrieve_retrieve_buddy_icon() - what kind of crack am I on anyway?
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18847
diff changeset
392 void _mdns_retrieve_buddy_icon(BonjourBuddy* buddy) {
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
393 Win32BuddyImplData *idata = buddy->mdns_impl_data;
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
394 char svc_name[kDNSServiceMaxDomainName];
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
395
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
396 g_return_if_fail(idata != NULL);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
397
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
398 /* Cancel any existing query */
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
399 if (idata->null_query != NULL) {
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
400 purple_input_remove(idata->null_query_handler);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
401 idata->null_query_handler = 0;
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
402 DNSServiceRefDeallocate(idata->null_query);
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
403 idata->null_query = NULL;
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
404 }
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
405
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
406 DNSServiceConstructFullName(svc_name, buddy->name, ICHAT_SERVICE, "local");
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
407 if (kDNSServiceErr_NoError == DNSServiceQueryRecord(&idata->null_query, 0, kDNSServiceInterfaceIndexAny, svc_name,
18856
5da32c4019ce Show bonjour status messages in the buddy list.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18849
diff changeset
408 kDNSServiceType_NULL, kDNSServiceClass_IN, _mdns_record_query_callback, buddy)) {
18843
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
409 idata->null_query_handler = purple_input_add(DNSServiceRefSockFD(idata->null_query),
7bf6b9a70b41 Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18804
diff changeset
410 PURPLE_INPUT_READ, _mdns_handle_event, idata->null_query);
18799
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
411 }
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
412
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
413 }
83719d57a8ee Implement bonjour buddy icons in the win32 implementation. Avahi's howl wrapper doesn't implement sw_discovery_query_record(), so we can't do it elsewhere yet.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18798
diff changeset
414