annotate libpurple/protocols/bonjour/mdns_win32.c @ 20308:c2d3c9fc71b5

applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da through 6f133a093581cd9a632ca6d0ce110d180e582714
author Luke Schierer <lschiere@pidgin.im>
date Fri, 19 Oct 2007 17:10:04 +0000
parents 44b4e8bd759b
children 53691c081eab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20308
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
1 /**
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
2 *
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
5 * source distribution.
c2d3c9fc71b5 applied changes from fbb7ffaf4075cf690cc3ff9d171e56320e9af8da
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
6 *
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
7 * 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
8 * 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
9 * 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
10 * (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
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 * 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
13 * 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
14 * 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
15 * 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
16 *
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
17 * 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
18 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19654
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
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
20 */
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
21
18276
1faa319ab4c3 More compile fixes from rekkanoryo for G_GNUC_NULL_TERMINATED issues
Stu Tomlinson <stu@nosnilmot.com>
parents: 17552
diff changeset
22 #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
23 #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
24
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 #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
26 #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
27 #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
28 #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
29 #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
30
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
31
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 /* 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
33 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
34 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
35 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
36 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
37
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
38 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
39
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
40 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
41 } 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
42
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 /* 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
44 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
45 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
46 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
47 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
48
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
49 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
50 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
51 } 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
52
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 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
54 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
55 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
56 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
57 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
58 } 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
59
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
60 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
61 _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
62 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
63 }
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
64
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
65 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
66 _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
67 {
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 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
69 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
70 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
71
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
72 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
73 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
74 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
75 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
76 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
77 }
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 }
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
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 static void DNSSD_API
18856
5da32c4019ce Show bonjour status messages in the buddy list.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18849
diff changeset
81 _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
82 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
83 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
84 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
85 {
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
86
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
87 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
88 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
89 /* 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
90 } 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
91 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
92 /* 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
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 _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
95 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
96 } 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
97 /* 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
98 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
99 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
100
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 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
102
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
103 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
104
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 /* 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
106 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
107 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
108 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
109 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
110 }
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
111 }
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
112 }
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
113
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
114 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
115 _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
116 {
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
117 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
118 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
119
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 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
121 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
122 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
123 } 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
124 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
125 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
126
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
127 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
128
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
129 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
130 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
131
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
132 /* 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
133
18846
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
134 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
135 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
136 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
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 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
139
44ad08a02ead Fix recieving status updates for bonjour (win32 implementation).
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18845
diff changeset
140 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
141 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
142
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
143 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
144 } 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
145 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
146
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
147 }
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
148
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
149 /* 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
150 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
151
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
152 /* 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
153 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
154 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
155 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
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
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
158 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
159 _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
160 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
161 {
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 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
163
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 /* 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
165 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
166 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
167
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 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
169 {
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 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
171 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
172 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
173 }
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 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
175 {
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
176 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
177
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
178 /* 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
179 _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
180
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
181 /* 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
182 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
183
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
184 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
185 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
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 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
188 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
189 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
190 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
191 }
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 }
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
193
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
194 }
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
195
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
196 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
197 _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
198 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
199
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
200 /* 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
201 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
202 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
203 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
204 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
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
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
207 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
208 _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
209 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
210 {
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
211 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
212 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
213
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 if (kDNSServiceErr_NoError != errorCode)
19654
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19573
diff changeset
215 purple_debug_error("bonjour", "service browser - callback error\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
216 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
217 /* 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
218 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
219 /* 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
220 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
221 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
222
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
223 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
224 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
225 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
226 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
227 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
228 } 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
229 /* 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
230 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
231 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
232 }
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
233 }
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
234 } 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
235 /* 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
236 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
237 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
238 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
239 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
240 }
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
241 }
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
242
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
243 /****************************
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 * 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
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
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
247 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
248 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
249 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
250 }
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
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
252 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
253 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
254 gboolean ret = TRUE;
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
255 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
256 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
257
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
258 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
259
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
260 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
261
18859
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
262 while (records) {
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
263 PurpleKeyValuePair *kvp = records->data;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
264 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
265 if (set_ret != kDNSServiceErr_NoError)
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
266 break;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
267 records = records->next;
c1546f6c0432 Yay for code reuse.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18858
diff changeset
268 }
17501
c96b085ddf5c Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 17495
diff changeset
269
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
270 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
271 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
272 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
273 } 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
274 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
275
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
276 /* 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
277
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
278 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
279 case PUBLISH_START:
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
280 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
281 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
282 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
283 _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
284 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
285
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
286 case PUBLISH_UPDATE:
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
287 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
288 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
289 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
290 }
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
291
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
292 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
293 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
294 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
295 } 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
296 /* 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
297 * "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
298 * 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
299 * 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
300 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
301 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
302 }
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 }
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
304
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
305 /* 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
306 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
307 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
308 }
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
309
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
310 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
311 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
312
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
313 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
314
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
315 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
316 _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
317 == 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
318 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
319 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
320 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
321 }
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
322
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
323 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
324 }
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
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 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
327 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
328
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
329 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
330 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
331
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
332 if (idata->presence_svc != NULL) {
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
333 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
334 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
335 }
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
336
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
337 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
338 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
339 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
340 }
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
341
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
342 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
343
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
344 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
345 }
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
346
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
347 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
348 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
349 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
350
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
351 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
352
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
353 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
354 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
355 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
356 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
357 } 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
358 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
359 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
360 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
361 } 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
362 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
363 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
364 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
365 }
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 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
368 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
369
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
370 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
371 }
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
372
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
373 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
374 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
375 }
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 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
378 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
379
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 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
381
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
382 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
383 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
384 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
385 }
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
386
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
387 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
388 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
389 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
390 }
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
391
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
392 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
393
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
394 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
395 }
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
396
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
397 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
398 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
399 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
400
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 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
402
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 /* 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
404 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
405 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
406 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
407 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
408 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
409 }
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
410
18845
09f52521ff5b Fix bonjour buddy icons to work with iChat.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 18843
diff changeset
411 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
412 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
413 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
414 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
415 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
416 }
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
417
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
418 }
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
419