annotate src/protocols/bonjour/dns_sd.c @ 11888:7d2d926704aa

[gaim-migrate @ 14179] Gtk 2.0 support. Deja Vu. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 29 Oct 2005 14:45:15 +0000
parents 4669e7461968
children 0d9c6d2ad64b
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 data */
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 typedef struct _dns_sd_packet
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
27 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
28 gchar *name;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
29 gchar *txtvers;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
30 gchar *version;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
31 gchar *first;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
32 gchar *last;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 gint port_p2pj;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
34 gchar *phsh;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
35 gchar *status;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
36 gchar *message;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
37 gchar *email;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
38 gchar *vc;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
39 gchar *jid;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
40 gchar *AIM;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
41 } dns_sd_packet;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
43 /* End private data */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
45 /* Private functions */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
47 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
48 _publish_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
49 sw_discovery_publish_status status, sw_opaque extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
51 gaim_debug_warning("bonjour", "_publish_reply --> Start\n");
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
52
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
53 /* Check the answer from the mDNS daemon */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
54 switch (status)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
55 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 case SW_DISCOVERY_PUBLISH_STARTED :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 gaim_debug_info("bonjour", "_publish_reply --> Service started\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 case SW_DISCOVERY_PUBLISH_STOPPED :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 gaim_debug_info("bonjour", "_publish_reply --> Service stopped\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 case SW_DISCOVERY_PUBLISH_NAME_COLLISION :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 gaim_debug_info("bonjour", "_publish_reply --> Name collision\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 case SW_DISCOVERY_PUBLISH_INVALID :
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 gaim_debug_info("bonjour", "_publish_reply --> Service invalid\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
69
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
73 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
74 _resolve_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
75 sw_uint32 interface_index, sw_const_string name,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
76 sw_const_string type, sw_const_string domain,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
77 sw_ipv4_address address, sw_port port,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
78 sw_octets text_record, sw_ulong text_record_len,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
79 sw_opaque extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
81 BonjourBuddy *buddy;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
82 GaimAccount *account = (GaimAccount*)extra;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
83 gchar *txtvers = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
84 gchar *version = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
85 gchar *first = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 gint port_p2pj = -1;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
87 gchar *phsh = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
88 gchar *status = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
89 gchar *email = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
90 gchar *last = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
91 gchar *jid = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
92 gchar *AIM = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
93 gchar *vc = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
94 gchar *msg = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 gint address_length = 16;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
96 gchar *ip = NULL;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 sw_text_record_iterator iterator;
11498
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11496
diff changeset
98 char key[SW_TEXT_RECORD_MAX_LEN];
ea52fefd3602 [gaim-migrate @ 13743]
Mark Doliner <mark@kingant.net>
parents: 11496
diff changeset
99 char value[SW_TEXT_RECORD_MAX_LEN];
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 sw_uint32 value_length;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 sw_discovery_cancel(discovery, oid);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
103
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
104 /* Get the ip as a string */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 ip = malloc(address_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 sw_ipv4_address_name(address, ip, address_length);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
108 /* Obtain the parameters from the text_record */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
109 if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
110 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 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
112 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
113 {
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
114 /* Compare the keys with the possible ones and save them on */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
115 /* the appropiate place of the buddy_list */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 if (strcmp(key, "txtvers") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117 txtvers = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 } else if (strcmp(key, "version") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 version = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 } else if (strcmp(key, "1st") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 first = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 } else if (strcmp(key, "port.p2pj") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123 port_p2pj = atoi(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 } else if (strcmp(key, "status") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 status = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126 } else if (strcmp(key, "email") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 email = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128 } else if (strcmp(key, "last") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 last = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 } else if (strcmp(key, "jid") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 jid = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 } else if (strcmp(key, "AIM") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 AIM = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134 } else if (strcmp(key, "vc") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 vc = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136 } else if (strcmp(key, "phsh") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 phsh = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 } else if (strcmp(key, "msg") == 0) {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139 msg = g_strdup(value);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
142 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
144 /* 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
145 /* the buddy list */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
146 buddy = bonjour_buddy_new((gchar *)name, first, port_p2pj, phsh,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
147 status, email, last, jid, AIM, vc, ip, msg);
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
148
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
149 if (bonjour_buddy_check(buddy) == FALSE)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
150 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 return SW_DISCOVERY_E_UNKNOWN;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
153
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
154 /* Add or update the buddy in our buddy list */
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
155 bonjour_buddy_add_to_gaim(account, buddy);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
156
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
157 /* Free all the temporal strings */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 g_free(txtvers);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 g_free(version);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160 g_free(first);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161 g_free(last);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162 g_free(status);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 g_free(email);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 g_free(jid);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 g_free(AIM);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 g_free(vc);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 g_free(phsh);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 g_free(msg);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
169
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
173 static sw_result HOWL_API
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
174 _browser_reply(sw_discovery discovery, sw_discovery_oid oid,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
175 sw_discovery_browse_status status,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
176 sw_uint32 interface_index, sw_const_string name,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
177 sw_const_string type, sw_const_string domain,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
178 sw_opaque_t extra)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180 sw_discovery_resolve_id rid;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
181 GaimAccount *account = (GaimAccount*)extra;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
182 GaimBuddy *gb = NULL;
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
183
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
184 switch (status)
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 case SW_DISCOVERY_BROWSE_INVALID:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 gaim_debug_warning("bonjour", "_browser_reply --> Invalid\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189 case SW_DISCOVERY_BROWSE_RELEASE:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 gaim_debug_warning("bonjour", "_browser_reply --> Release\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 gaim_debug_warning("bonjour", "_browser_reply --> Add domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195 case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 gaim_debug_warning("bonjour", "_browser_reply --> Add default domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 gaim_debug_warning("bonjour", "_browser_reply --> Remove domain\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 case SW_DISCOVERY_BROWSE_ADD_SERVICE:
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
202 /* A new peer has join the network and uses iChat bonjour */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203 gaim_debug_info("bonjour", "_browser_reply --> Add service\n");
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
204 if (g_ascii_strcasecmp(name, account->username) != 0)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
205 {
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
206 if (sw_discovery_resolve(discovery, interface_index, name, type,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
207 domain, _resolve_reply, extra, &rid) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
208 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209 gaim_debug_warning("bonjour", "_browser_reply --> Cannot send resolve\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 }
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 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
213 case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214 gaim_debug_info("bonjour", "_browser_reply --> Remove service\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 gb = gaim_find_buddy((GaimAccount*)extra, name);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
216 if (gb != NULL)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
217 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218 bonjour_buddy_delete(gb->proto_data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 gaim_blist_remove_buddy(gb);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222 case SW_DISCOVERY_BROWSE_RESOLVED:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 gaim_debug_info("bonjour", "_browse_reply --> Resolved\n");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 default:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
228
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229 return SW_OKAY;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
230 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11539
diff changeset
232 static int
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
233 _dns_sd_publish(BonjourDnsSd *data, PublishType type)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235 sw_text_record dns_data;
11773
92cf092f194e [gaim-migrate @ 14064]
Gary Kramlich <grim@reaperworld.com>
parents: 11678
diff changeset
236 sw_result publish_result = SW_OKAY;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
238 /* Fill the data for the service */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
239 if (sw_text_record_init(&dns_data) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
240 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241 gaim_debug_error("bonjour", "Unable to initialize the data for the mDNS.");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 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
246 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
247 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
248 sw_text_record_add_key_and_string_value(dns_data, "last", data->last);
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
249 /* sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", itoa(data->port_p2pj)); */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", BONJOUR_DEFAULT_PORT);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 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
252 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
253 sw_text_record_add_key_and_string_value(dns_data, "msg", data->msg);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 sw_text_record_add_key_and_string_value(dns_data, "email", data->email);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255 sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 sw_text_record_add_key_and_string_value(dns_data, "AIM", data->AIM);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
259 /* Publish the service */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
260 switch (type)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
261 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 case PUBLISH_START:
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
263 publish_result = sw_discovery_publish(*(data->session), 0, data->name, ICHAT_SERVICE, NULL,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
264 NULL, data->port_p2pj, sw_text_record_bytes(dns_data), sw_text_record_len(dns_data),
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 _publish_reply, NULL, &(data->session_id));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 case PUBLISH_UPDATE:
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268 publish_result = sw_discovery_publish_update(*(data->session),data->session_id,
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 sw_text_record_bytes(dns_data), sw_text_record_len(dns_data));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 break;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
272 if (publish_result != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
273 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274 gaim_debug_error("bonjour", "Unable to publish or change the status of the _presence._tcp service.");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 return -1;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
277
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
278 /* Free the memory used by temp data */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279 sw_text_record_fina(dns_data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 return 0;
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
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
284 static void
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
285 _dns_sd_handle_packets(gpointer data, gint source, GaimInputCondition condition)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 sw_discovery_read_socket(*((sw_discovery*)data));
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
290 /* End private functions */
11477
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 * Allocate space for the dns-sd data.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
295 BonjourDnsSd *
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
296 bonjour_dns_sd_new()
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
297 {
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
298 BonjourDnsSd *data = g_new(BonjourDnsSd, 1);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
299 data->session = g_malloc(sizeof(sw_discovery));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
300
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 return data;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 }
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 * Deallocate the space of the dns-sd data.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
307 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
308 bonjour_dns_sd_free(BonjourDnsSd *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309 {
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
310 g_free(data->session);
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
311 g_free(data->first);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
312 g_free(data->last);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
313 g_free(data->email);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314 g_free(data);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 * Send a new dns-sd packet updating our status.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
320 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
321 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
322 {
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
323 g_free(data->status);
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
324 g_free(data->msg);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
325
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
326 data->status = g_strdup(status);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 data->msg = g_strdup(status_message);
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
329 /* Update our text record with the new status */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
330 _dns_sd_publish(data, PUBLISH_UPDATE); /* <--We must control the errors */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
333 /**
11496
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
334 * Advertise our presence within the dns-sd daemon and start browsing
3f038da50a18 [gaim-migrate @ 13740]
Mark Doliner <mark@kingant.net>
parents: 11477
diff changeset
335 * for other bonjour peers.
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
337 void
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
338 bonjour_dns_sd_start(BonjourDnsSd *data)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
339 {
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
340 GaimAccount *account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
341 GaimConnection *gc;
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
342 gint dns_sd_socket;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
343 sw_discovery_oid session_id;
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
344
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
345 account = data->account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
346 gc = gaim_account_get_connection(account);
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
347
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
348 /* Initilizations of the dns-sd data and session */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 data->session = malloc(sizeof(sw_discovery));
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
350 if (sw_discovery_init(data->session) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
351 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 gaim_debug_error("bonjour", "Unable to initialize a mDNS session.");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
355
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
356 /* Publish our bonjour IM client at the mDNS daemon */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
357 _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
358
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
359 /* Advise the daemon that we are waiting for connections */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
360 if (sw_discovery_browse(*(data->session), 0, ICHAT_SERVICE, NULL, _browser_reply,
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
361 data->account, &session_id) != SW_OKAY)
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
362 {
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 gaim_debug_error("bonjour", "Unable to get service.");
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 return;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
365 }
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
366
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11773
diff changeset
367 /* 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
368 /* callback that will handle the dns_sd packets */
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 dns_sd_socket = sw_discovery_socket(*(data->session));
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
370 gc->inpa = gaim_input_add(dns_sd_socket, GAIM_INPUT_READ,
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
371 _dns_sd_handle_packets, data->session);
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 }
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
374 /**
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
375 * Unregister the "_presence._tcp" service at the mDNS daemon.
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376 */
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
377 int
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
378 bonjour_dns_sd_stop(BonjourDnsSd *data)
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
379 {
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
380 GaimAccount *account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
381 GaimConnection *gc;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
382
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 sw_discovery_cancel(*(data->session), data->session_id);
11539
5a2c38d33eb4 [gaim-migrate @ 13794]
Mark Doliner <mark@kingant.net>
parents: 11515
diff changeset
384
11678
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
385 account = data->account;
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
386 gc = gaim_account_get_connection(account);
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
387 gaim_input_remove(gc->inpa);
b37c439dfcc0 [gaim-migrate @ 13964]
Mark Doliner <mark@kingant.net>
parents: 11677
diff changeset
388
11477
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389 return 0;
36f575351c49 [gaim-migrate @ 13719]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 }