annotate src/protocols/bonjour/dns_sd.c @ 13910:6c907830a45f

[gaim-migrate @ 16408] Get rid of an assertion failure that I hit committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 03 Jul 2006 01:39:51 +0000
parents 8264f52a1142
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * This program is free software; you can redistribute it and/or modify
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 * it under the terms of the GNU General Public License as published by
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * (at your option) any later version.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 * This program is distributed in the hope that it will be useful,
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 * GNU Library General Public License for more details.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 *
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 * You should have received a copy of the GNU General Public License
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * along with this program; if not, write to the Free Software
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 */
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 #include <string.h>
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 #include "dns_sd.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 #include "bonjour.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 #include "buddy.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 #include "debug.h"
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
24 /* Private functions */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
26 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
27 _publish_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
28 sw_discovery_publish_status status, sw_opaque extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
30 gaim_debug_warning("bonjour", "_publish_reply --> Start\n");
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
31
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
32 /* Check the answer from the mDNS daemon */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
33 switch (status)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
34 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 case SW_DISCOVERY_PUBLISH_STARTED :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 gaim_debug_info("bonjour", "_publish_reply --> Service started\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 case SW_DISCOVERY_PUBLISH_STOPPED :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 gaim_debug_info("bonjour", "_publish_reply --> Service stopped\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 case SW_DISCOVERY_PUBLISH_NAME_COLLISION :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 gaim_debug_info("bonjour", "_publish_reply --> Name collision\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 case SW_DISCOVERY_PUBLISH_INVALID :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 gaim_debug_info("bonjour", "_publish_reply --> Service invalid\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
48
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
52 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
53 _resolve_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
54 sw_uint32 interface_index, sw_const_string name,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
55 sw_const_string type, sw_const_string domain,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
56 sw_ipv4_address address, sw_port port,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
57 sw_octets text_record, sw_ulong text_record_len,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
58 sw_opaque extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
60 BonjourBuddy *buddy;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
61 GaimAccount *account = (GaimAccount*)extra;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
62 gchar *txtvers = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
63 gchar *version = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
64 gchar *first = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
65 gchar *phsh = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
66 gchar *status = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
67 gchar *email = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
68 gchar *last = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
69 gchar *jid = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
70 gchar *AIM = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
71 gchar *vc = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
72 gchar *msg = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 gint address_length = 16;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
74 gchar *ip = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 sw_text_record_iterator iterator;
11498
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11496
diff changeset
76 char key[SW_TEXT_RECORD_MAX_LEN];
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11496
diff changeset
77 char value[SW_TEXT_RECORD_MAX_LEN];
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 sw_uint32 value_length;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 sw_discovery_cancel(discovery, oid);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
81
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
82 /* Get the ip as a string */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 ip = malloc(address_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84 sw_ipv4_address_name(address, ip, address_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
86 /* Obtain the parameters from the text_record */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
87 if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
88 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 sw_text_record_iterator_init(&iterator, text_record, text_record_len);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
90 while (sw_text_record_iterator_next(iterator, key, (sw_octet *)value, &value_length) == SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
91 {
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
92 /* Compare the keys with the possible ones and save them on */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
93 /* the appropiate place of the buddy_list */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 if (strcmp(key, "txtvers") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 txtvers = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 } else if (strcmp(key, "version") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 version = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 } else if (strcmp(key, "1st") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 first = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 } else if (strcmp(key, "status") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 status = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 } else if (strcmp(key, "email") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 email = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 } else if (strcmp(key, "last") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 last = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 } else if (strcmp(key, "jid") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 jid = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 } else if (strcmp(key, "AIM") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 AIM = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 } else if (strcmp(key, "vc") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 vc = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 } else if (strcmp(key, "phsh") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 phsh = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 } else if (strcmp(key, "msg") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 msg = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
120 /* Put the parameters of the text_record in a buddy and add the buddy to */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
121 /* the buddy list */
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
122 buddy = bonjour_buddy_new(name, first, port, phsh,
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
123 status, email, last, jid, AIM, vc, ip, msg);
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
124
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
125 if (bonjour_buddy_check(buddy) == FALSE)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
126 {
13649
b10030f6eab7 [gaim-migrate @ 16050]
Mark Doliner <mark@kingant.net>
parents: 13063
diff changeset
127 bonjour_buddy_delete(buddy);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128 return SW_DISCOVERY_E_UNKNOWN;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
130
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
131 /* Add or update the buddy in our buddy list */
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
132 bonjour_buddy_add_to_gaim(account, buddy);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
133
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
134 /* Free all the temporal strings */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 g_free(txtvers);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136 g_free(version);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 g_free(first);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 g_free(last);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139 g_free(status);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140 g_free(email);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 g_free(jid);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
142 g_free(AIM);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 g_free(vc);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 g_free(phsh);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145 g_free(msg);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
146
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
150 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
151 _browser_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
152 sw_discovery_browse_status status,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
153 sw_uint32 interface_index, sw_const_string name,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
154 sw_const_string type, sw_const_string domain,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
155 sw_opaque_t extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 sw_discovery_resolve_id rid;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
158 GaimAccount *account = (GaimAccount*)extra;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
159 GaimBuddy *gb = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
160
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
161 switch (status)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
162 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 case SW_DISCOVERY_BROWSE_INVALID:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 gaim_debug_warning("bonjour", "_browser_reply --> Invalid\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 case SW_DISCOVERY_BROWSE_RELEASE:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 gaim_debug_warning("bonjour", "_browser_reply --> Release\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 gaim_debug_warning("bonjour", "_browser_reply --> Add domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172 case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173 gaim_debug_warning("bonjour", "_browser_reply --> Add default domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175 case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 gaim_debug_warning("bonjour", "_browser_reply --> Remove domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 case SW_DISCOVERY_BROWSE_ADD_SERVICE:
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
179 /* A new peer has joined the network and uses iChat bonjour */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180 gaim_debug_info("bonjour", "_browser_reply --> Add service\n");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
181 if (g_ascii_strcasecmp(name, account->username) != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
182 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
183 if (sw_discovery_resolve(discovery, interface_index, name, type,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
184 domain, _resolve_reply, extra, &rid) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
185 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186 gaim_debug_warning("bonjour", "_browser_reply --> Cannot send resolve\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 gaim_debug_info("bonjour", "_browser_reply --> Remove service\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 gb = gaim_find_buddy((GaimAccount*)extra, name);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
193 if (gb != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
194 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195 bonjour_buddy_delete(gb->proto_data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 gaim_blist_remove_buddy(gb);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 case SW_DISCOVERY_BROWSE_RESOLVED:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 gaim_debug_info("bonjour", "_browse_reply --> Resolved\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202 default:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
205
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11539
diff changeset
209 static int
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
210 _dns_sd_publish(BonjourDnsSd *data, PublishType type)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 sw_text_record dns_data;
11773
92cf092f194e [gaim-migrate @ 14064]
Gary Kramlich <grim@reaperworld.com>
parents: 11678
diff changeset
213 sw_result publish_result = SW_OKAY;
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
214 char portstring[6];
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
216 /* Fill the data for the service */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
217 if (sw_text_record_init(&dns_data) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
218 {
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
219 gaim_debug_error("bonjour", "Unable to initialize the data for the mDNS.\n");
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
223 /* Convert the port to a string */
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
224 snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj);
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
225
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
226 /* Publish standard records */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 sw_text_record_add_key_and_string_value(dns_data, "txtvers", data->txtvers);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228 sw_text_record_add_key_and_string_value(dns_data, "version", data->version);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 sw_text_record_add_key_and_string_value(dns_data, "1st", data->first);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 sw_text_record_add_key_and_string_value(dns_data, "last", data->last);
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
231 sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", portstring);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 sw_text_record_add_key_and_string_value(dns_data, "status", data->status);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc);
13906
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
235
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
236 /* Publish extra records */
13906
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
237 if ((data->email != NULL) && (*data->email != '\0'))
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
238 sw_text_record_add_key_and_string_value(dns_data, "email", data->email);
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
239
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
240 if ((data->jid != NULL) && (*data->jid != '\0'))
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
241 sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid);
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
242
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
243 if ((data->AIM != NULL) && (*data->AIM != '\0'))
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
244 sw_text_record_add_key_and_string_value(dns_data, "AIM", data->AIM);
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
245
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
246 if ((data->msg != NULL) && (*data->msg != '\0'))
b986b6e2441b [gaim-migrate @ 16400]
Mark Doliner <mark@kingant.net>
parents: 13649
diff changeset
247 sw_text_record_add_key_and_string_value(dns_data, "msg", data->msg);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
249 /* Publish the service */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
250 switch (type)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
251 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 case PUBLISH_START:
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
253 publish_result = sw_discovery_publish(data->session, 0, data->name, ICHAT_SERVICE, NULL,
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
254 NULL, data->port_p2pj, sw_text_record_bytes(dns_data), sw_text_record_len(dns_data),
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
255 _publish_reply, NULL, &data->session_id);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 case PUBLISH_UPDATE:
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
258 publish_result = sw_discovery_publish_update(data->session, data->session_id,
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 sw_text_record_bytes(dns_data), sw_text_record_len(dns_data));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
260 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
262 if (publish_result != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
263 {
13909
8264f52a1142 [gaim-migrate @ 16406]
Mark Doliner <mark@kingant.net>
parents: 13906
diff changeset
264 gaim_debug_error("bonjour", "Unable to publish or change the status of the _presence._tcp service.\n");
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
268 /* Free the memory used by temp data */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 sw_text_record_fina(dns_data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 return 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
274 static void
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
275 _dns_sd_handle_packets(gpointer data, gint source, GaimInputCondition condition)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 {
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
277 sw_discovery_read_socket((sw_discovery)data);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
278 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
280 /* End private functions */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 * Allocate space for the dns-sd data.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
285 BonjourDnsSd *
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
286 bonjour_dns_sd_new()
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 {
12035
52eaf0f0db4c [gaim-migrate @ 14328]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11927
diff changeset
288 BonjourDnsSd *data = g_new0(BonjourDnsSd, 1);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
289
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 return data;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 * Deallocate the space of the dns-sd data.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
296 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
297 bonjour_dns_sd_free(BonjourDnsSd *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298 {
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
299 g_free(data->first);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
300 g_free(data->last);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
301 g_free(data->email);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 g_free(data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
304
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 * Send a new dns-sd packet updating our status.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
308 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
309 bonjour_dns_sd_send_status(BonjourDnsSd *data, const char *status, const char *status_message)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
310 {
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
311 g_free(data->status);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
312 g_free(data->msg);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314 data->status = g_strdup(status);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 data->msg = g_strdup(status_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
317 /* Update our text record with the new status */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
318 _dns_sd_publish(data, PUBLISH_UPDATE); /* <--We must control the errors */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 /**
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
322 * Advertise our presence within the dns-sd daemon and start browsing
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
323 * for other bonjour peers.
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 */
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
325 gboolean
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
326 bonjour_dns_sd_start(BonjourDnsSd *data)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
327 {
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
328 GaimAccount *account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
329 GaimConnection *gc;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330 gint dns_sd_socket;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 sw_discovery_oid session_id;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
332
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
333 account = data->account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
334 gc = gaim_account_get_connection(account);
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
335
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
336 /* Initialize the dns-sd data and session */
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
337 if (sw_discovery_init(&data->session) != SW_OKAY)
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
338 {
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
339 gaim_debug_error("bonjour", "Unable to initialize an mDNS session.\n");
13063
41ec0316cd65 [gaim-migrate @ 15425]
Mark Doliner <mark@kingant.net>
parents: 12104
diff changeset
340
41ec0316cd65 [gaim-migrate @ 15425]
Mark Doliner <mark@kingant.net>
parents: 12104
diff changeset
341 /* In Avahi, sw_discovery_init frees data->session but doesn't clear it */
41ec0316cd65 [gaim-migrate @ 15425]
Mark Doliner <mark@kingant.net>
parents: 12104
diff changeset
342 data->session = NULL;
41ec0316cd65 [gaim-migrate @ 15425]
Mark Doliner <mark@kingant.net>
parents: 12104
diff changeset
343
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
344 return FALSE;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
346
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
347 /* Publish our bonjour IM client at the mDNS daemon */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
348 _dns_sd_publish(data, PUBLISH_START); /* <--We must control the errors */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
349
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
350 /* Advise the daemon that we are waiting for connections */
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
351 if (sw_discovery_browse(data->session, 0, ICHAT_SERVICE, NULL, _browser_reply,
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
352 data->account, &session_id) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
353 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 gaim_debug_error("bonjour", "Unable to get service.");
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
355 return FALSE;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
356 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
357
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
358 /* Get the socket that communicates with the mDNS daemon and bind it to a */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
359 /* callback that will handle the dns_sd packets */
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
360 dns_sd_socket = sw_discovery_socket(data->session);
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
361 gc->inpa = gaim_input_add(dns_sd_socket, GAIM_INPUT_READ,
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
362 _dns_sd_handle_packets, data->session);
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
363
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
364 return TRUE;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
365 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
366
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
367 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 * Unregister the "_presence._tcp" service at the mDNS daemon.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 */
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
370 void
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
371 bonjour_dns_sd_stop(BonjourDnsSd *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 {
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
373 GaimAccount *account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
374 GaimConnection *gc;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
375
11927
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
376 if (data->session == NULL)
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
377 return;
0d9c6d2ad64b [gaim-migrate @ 14218]
Mark Doliner <mark@kingant.net>
parents: 11829
diff changeset
378
12104
3db14853d9ae [gaim-migrate @ 14401]
Mark Doliner <mark@kingant.net>
parents: 12094
diff changeset
379 sw_discovery_cancel(data->session, data->session_id);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
380
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
381 account = data->account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
382 gc = gaim_account_get_connection(account);
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
383 gaim_input_remove(gc->inpa);
12093
78ca702b3338 [gaim-migrate @ 14390]
Mark Doliner <mark@kingant.net>
parents: 12035
diff changeset
384
78ca702b3338 [gaim-migrate @ 14390]
Mark Doliner <mark@kingant.net>
parents: 12035
diff changeset
385 g_free(data->session);
78ca702b3338 [gaim-migrate @ 14390]
Mark Doliner <mark@kingant.net>
parents: 12035
diff changeset
386 data->session = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
387 }