libpurple/protocols/bonjour/mdns_common.c

Fri, 23 Dec 2011 08:21:58 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Fri, 23 Dec 2011 08:21:58 +0000
branch
cpw.qulogic.gtk3
changeset 32438
dc8991868906
parent 30826
83e7040d3565
child 35822
237ad851330e
child 36704
01edebf55111
permissions
-rw-r--r--

A boring and large patch so I can merge heads.

17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
1 /*
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
2 * This program is free software; you can redistribute it and/or modify
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
3 * it under the terms of the GNU General Public License as published by
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
5 * (at your option) any later version.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
6 *
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
7 * This program is distributed in the hope that it will be useful,
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
10 * GNU Library General Public License for more details.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
11 *
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
12 * You should have received a copy of the GNU General Public License
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
13 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19832
diff changeset
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
15 */
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
16
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
17 #include <string.h>
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
18
18338
d3cb08f27e04 More compile fixes from rekkanoryo for G_GNUC_NULL_TERMINATED issues
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17659
diff changeset
19 #include "internal.h"
19204
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
20 #include "debug.h"
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
21
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
22 #include "mdns_common.h"
19093
b2657106df0e 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 <datallah@pidgin.im>
parents: 18338
diff changeset
23 #include "mdns_interface.h"
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
24 #include "bonjour.h"
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
25 #include "buddy.h"
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
26
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
27
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
28 /**
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
29 * Allocate space for the dns-sd data.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
30 */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
31 BonjourDnsSd * bonjour_dns_sd_new() {
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
32 BonjourDnsSd *data = g_new0(BonjourDnsSd, 1);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
33 return data;
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
34 }
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
35
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
36 /**
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
37 * Deallocate the space of the dns-sd data.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
38 */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
39 void bonjour_dns_sd_free(BonjourDnsSd *data) {
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
40 g_free(data->first);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
41 g_free(data->last);
17608
795ce8e3d44e Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <datallah@pidgin.im>
parents: 17596
diff changeset
42 g_free(data->phsh);
795ce8e3d44e Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <datallah@pidgin.im>
parents: 17596
diff changeset
43 g_free(data->status);
795ce8e3d44e Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <datallah@pidgin.im>
parents: 17596
diff changeset
44 g_free(data->vc);
795ce8e3d44e Clean up Bonjour service publishing and improve XEP-0174 compliance.
Daniel Atallah <datallah@pidgin.im>
parents: 17596
diff changeset
45 g_free(data->msg);
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
46 g_free(data);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
47 }
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
48
24418
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
49 #define MAX_TXT_CONSTITUENT_LEN 255
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
50
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
51 /* Make sure that the value isn't longer than it is supposed to be */
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
52 static const char*
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
53 get_max_txt_record_value(const char *key, const char *value)
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
54 {
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
55 /* "each constituent string of a DNS TXT record is limited to 255 bytes"
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
56 * This includes the key and the '='
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
57 */
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
58 static char buffer[MAX_TXT_CONSTITUENT_LEN + 1];
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
59 gchar *end_valid = NULL;
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
60 int len = MIN(strlen(value), MAX_TXT_CONSTITUENT_LEN - (strlen(key) + 2));
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
61
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
62 strncpy(buffer, value, len);
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
63
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
64 buffer[len] = '\0';
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
65
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
66 /* If we've cut part of a utf-8 character, kill it */
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
67 if (!g_utf8_validate(buffer, -1, (const gchar **)&end_valid))
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
68 *end_valid = '\0';
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
69
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
70 return buffer;
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
71 }
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
72
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
73 static GSList *generate_presence_txt_records(BonjourDnsSd *data) {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
74 GSList *ret = NULL;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
75 PurpleKeyValuePair *kvp;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
76 char portstring[6];
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
77 const char *jid, *aim, *email;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
78
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
79 /* Convert the port to a string */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
80 snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
81
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
82 jid = purple_account_get_string(data->account, "jid", NULL);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
83 aim = purple_account_get_string(data->account, "AIM", NULL);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
84 email = purple_account_get_string(data->account, "email", NULL);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
85
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
86 #define _M_ADD_R(k, v) \
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
87 kvp = g_new0(PurpleKeyValuePair, 1); \
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
88 kvp->key = g_strdup(k); \
24418
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
89 kvp->value = g_strdup(get_max_txt_record_value(k, v)); \
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
90 ret = g_slist_prepend(ret, kvp); \
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
91
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
92 /* We should try to follow XEP-0174, but some clients have "issues", so we humor them.
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
93 * See http://telepathy.freedesktop.org/wiki/SalutInteroperability
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
94 */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
95
24418
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
96 /* Large TXT records are problematic.
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
97 * While it is technically possible for this to exceed a standard 512-byte
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
98 * DNS message, it shouldn't happen unless we get wacky data entered for
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
99 * some of the freeform fields. It is even less likely to exceed the
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
100 * recommended maximum of 1300 bytes.
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
101 */
987884c56bbb Prevent DNS-SD TXT record strings from exceeding the maximum length.
Daniel Atallah <datallah@pidgin.im>
parents: 19859
diff changeset
102
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
103 /* Needed by iChat */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
104 _M_ADD_R("txtvers", "1")
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
105 /* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
106 _M_ADD_R("1st", data->first)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
107 /* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
108 _M_ADD_R("last", data->last)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
109 /* Needed by Adium */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
110 _M_ADD_R("port.p2pj", portstring)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
111 /* Needed by iChat, Gaim/Pidgin <= 2.0.1 */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
112 _M_ADD_R("status", data->status)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
113 _M_ADD_R("node", "libpurple")
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
114 _M_ADD_R("ver", VERSION)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
115 /* Currently always set to "!" since we don't support AV and wont ever be in a conference */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
116 _M_ADD_R("vc", data->vc)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
117 if (email != NULL && *email != '\0') {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
118 _M_ADD_R("email", email)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
119 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
120 if (jid != NULL && *jid != '\0') {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
121 _M_ADD_R("jid", jid)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
122 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
123 /* Nonstandard, but used by iChat */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
124 if (aim != NULL && *aim != '\0') {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
125 _M_ADD_R("AIM", aim)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
126 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
127 if (data->msg != NULL && *data->msg != '\0') {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
128 _M_ADD_R("msg", data->msg)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
129 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
130 if (data->phsh != NULL && *data->phsh != '\0') {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
131 _M_ADD_R("phsh", data->phsh)
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
132 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
133
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
134 /* TODO: ext, nick */
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
135 return ret;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
136 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
137
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
138 static void free_presence_txt_records(GSList *lst) {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
139 PurpleKeyValuePair *kvp;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
140 while(lst) {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
141 kvp = lst->data;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
142 g_free(kvp->key);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
143 g_free(kvp->value);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
144 g_free(kvp);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
145 lst = g_slist_remove(lst, lst->data);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
146 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
147 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
148
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
149 static gboolean publish_presence(BonjourDnsSd *data, PublishType type) {
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
150 GSList *txt_records;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
151 gboolean ret;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
152
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
153 txt_records = generate_presence_txt_records(data);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
154 ret = _mdns_publish(data, type, txt_records);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
155 free_presence_txt_records(txt_records);
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
156
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
157 return ret;
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
158 }
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
159
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
160 /**
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
161 * Send a new dns-sd packet updating our status.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
162 */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
163 void bonjour_dns_sd_send_status(BonjourDnsSd *data, const char *status, const char *status_message) {
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
164 g_free(data->status);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
165 g_free(data->msg);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
166
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
167 data->status = g_strdup(status);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
168 data->msg = g_strdup(status_message);
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
169
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
170 /* Update our text record with the new status */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
171 publish_presence(data, PUBLISH_UPDATE);
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
172 }
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
173
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
174 /**
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
175 * Retrieve the buddy icon blob
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
176 */
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
177 void bonjour_dns_sd_retrieve_buddy_icon(BonjourBuddy* buddy) {
19210
4dcb230b1dbd _mdns_retrieve_retrieve_buddy_icon() - what kind of crack am I on anyway?
Daniel Atallah <datallah@pidgin.im>
parents: 19206
diff changeset
178 _mdns_retrieve_buddy_icon(buddy);
19204
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
179 }
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
180
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
181 void bonjour_dns_sd_update_buddy_icon(BonjourDnsSd *data) {
19204
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
182 PurpleStoredImage *img;
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
183
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
184 if ((img = purple_buddy_icons_find_account_icon(data->account))) {
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
185 gconstpointer avatar_data;
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
186 gsize avatar_len;
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
187
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
188 avatar_data = purple_imgstore_get_data(img);
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
189 avatar_len = purple_imgstore_get_size(img);
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
190
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
191 if (_mdns_set_buddy_icon_data(data, avatar_data, avatar_len)) {
19397
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
192 /* The filename is a SHA-1 hash of the data (conveniently what we need) */
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
193 const char *p, *filename = purple_imgstore_get_filename(img);
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
194
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
195 g_free(data->phsh);
19397
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
196 data->phsh = NULL;
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
197
19397
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
198 /* Get rid of the extension */
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
199 p = strchr(filename, '.');
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
200 if (p)
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
201 data->phsh = g_strndup(filename, p - filename);
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
202 else
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
203 purple_debug_error("bonjour", "account buddy icon returned unexpected filename (%s)"
b1befd204757 Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
Daniel Atallah <datallah@pidgin.im>
parents: 19221
diff changeset
204 "; unable to extract hash. Clearing buddy icon\n", filename);
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
205
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
206 /* Update our TXT record */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
207 publish_presence(data, PUBLISH_UPDATE);
19206
ed0343b92c15 Fix bonjour buddy icons to work with iChat.
Daniel Atallah <datallah@pidgin.im>
parents: 19204
diff changeset
208 }
19204
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
209
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
210 purple_imgstore_unref(img);
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
211 } else {
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
212 /* We need to do this regardless of whether data->phsh is set so that we
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
213 * cancel any icons that are currently in the process of being set */
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
214 _mdns_set_buddy_icon_data(data, NULL, 0);
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
215 if (data->phsh != NULL) {
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
216 /* Clear the buddy icon */
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
217 g_free(data->phsh);
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
218 data->phsh = NULL;
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
219 /* Update our TXT record */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
220 publish_presence(data, PUBLISH_UPDATE);
19204
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
221 }
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
222 }
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
223 }
ccc7ec4ea4dc Some more minor mdns implementation abstraction tweaks and implementation of setting buddy icons for the win32 bonjour implementation.
Daniel Atallah <datallah@pidgin.im>
parents: 19099
diff changeset
224
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
225 /**
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
226 * Advertise our presence within the dns-sd daemon and start browsing
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
227 * for other bonjour peers.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
228 */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
229 gboolean bonjour_dns_sd_start(BonjourDnsSd *data) {
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
230
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
231 /* Initialize the dns-sd data and session */
19093
b2657106df0e 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 <datallah@pidgin.im>
parents: 18338
diff changeset
232 if (!_mdns_init_session(data))
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
233 return FALSE;
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
234
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
235 /* Publish our bonjour IM client at the mDNS daemon */
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
236 if (!publish_presence(data, PUBLISH_START))
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
237 return FALSE;
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
238
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
239 /* Advise the daemon that we are waiting for connections */
19093
b2657106df0e 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 <datallah@pidgin.im>
parents: 18338
diff changeset
240 if (!_mdns_browse(data)) {
19832
84b69b21672b Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19397
diff changeset
241 purple_debug_error("bonjour", "Unable to get service.\n");
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
242 return FALSE;
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
243 }
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
244
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
245 return TRUE;
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
246 }
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
247
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
248 /**
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
249 * Unregister the "_presence._tcp" service at the mDNS daemon.
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
250 */
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
251
19221
29e6dd223bc5 Yay for code reuse.
Daniel Atallah <datallah@pidgin.im>
parents: 19210
diff changeset
252 void bonjour_dns_sd_stop(BonjourDnsSd *data) {
19093
b2657106df0e 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 <datallah@pidgin.im>
parents: 18338
diff changeset
253 _mdns_stop(data);
17596
45f6190fe54a 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 <datallah@pidgin.im>
parents:
diff changeset
254 }
30825
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
255
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
256 void
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
257 bonjour_dns_sd_set_jid(PurpleAccount *account, const char *hostname)
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
258 {
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
259 PurpleConnection *conn = purple_account_get_connection(account);
32438
dc8991868906 A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30826
diff changeset
260 BonjourData *bd = purple_connection_get_protocol_data(conn);
30825
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
261 const char *tmp, *account_name = purple_account_get_username(account);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
262
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
263 /* Previously we allowed the hostname part of the jid to be set
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
264 * explicitly when it should always be the current hostname.
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
265 * That is what this is intended to deal with.
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
266 */
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
267 if ((tmp = strchr(account_name, '@'))
30826
83e7040d3565 Deal with the hostname being a substring of the account name prior to the '@'
Daniel Atallah <datallah@pidgin.im>
parents: 30825
diff changeset
268 && strstr(tmp, hostname) == (tmp + 1)
83e7040d3565 Deal with the hostname being a substring of the account name prior to the '@'
Daniel Atallah <datallah@pidgin.im>
parents: 30825
diff changeset
269 && *((tmp + 1) + strlen(hostname)) == '\0')
30825
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
270 bd->jid = g_strdup(account_name);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
271 else {
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
272 const char *tmp2;
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
273 GString *str = g_string_new("");
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
274 /* Escape an '@' in the account name */
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
275 tmp = account_name;
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
276 while ((tmp2 = strchr(tmp, '@')) != NULL) {
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
277 g_string_append_len(str, tmp, tmp2 - tmp);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
278 g_string_append(str, "\\40");
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
279 tmp = tmp2 + 1;
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
280 }
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
281 g_string_append(str, tmp);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
282 g_string_append_c(str, '@');
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
283 g_string_append(str, hostname);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
284
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
285 bd->jid = g_string_free(str, FALSE);
87a79bbdc985 The hostname used for a bonjour account should always be the current machine
Daniel Atallah <datallah@pidgin.im>
parents: 24418
diff changeset
286 }
30826
83e7040d3565 Deal with the hostname being a substring of the account name prior to the '@'
Daniel Atallah <datallah@pidgin.im>
parents: 30825
diff changeset
287 }

mercurial