comparison libpurple/protocols/bonjour/buddy.c @ 17495:d7b50cac1c7a

This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it. There are a few changes by me, mainly to fix the howl implementation. Fixes #1117 . There appear to be a few bugs, but I believe that they were also present previously. I'm hoping to do some more tweaking before the next release. The howl implementation will eventually be supersceded by a native avahi implementation, so I opted for a somewhat dirty hack to enable it instead of doing something with config.h.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 05 Jun 2007 03:38:22 +0000
parents 32c366eeeb99
children e165d1ba8844
comparison
equal deleted inserted replaced
17488:7e856734b712 17495:d7b50cac1c7a
25 25
26 /** 26 /**
27 * Creates a new buddy. 27 * Creates a new buddy.
28 */ 28 */
29 BonjourBuddy * 29 BonjourBuddy *
30 bonjour_buddy_new(const gchar *name, const gchar *first, gint port_p2pj, 30 bonjour_buddy_new(const gchar *name, PurpleAccount* account)
31 const gchar *phsh, const gchar *status, const gchar *email,
32 const gchar *last, const gchar *jid, const gchar *AIM,
33 const gchar *vc, const gchar *ip, const gchar *msg)
34 { 31 {
35 BonjourBuddy *buddy = malloc(sizeof(BonjourBuddy)); 32 BonjourBuddy *buddy = malloc(sizeof(BonjourBuddy));
36 33
34 buddy->account = account;
37 buddy->name = g_strdup(name); 35 buddy->name = g_strdup(name);
38 buddy->first = g_strdup(first); 36 buddy->first = NULL;
39 buddy->port_p2pj = port_p2pj; 37 buddy->port_p2pj = 0;
40 buddy->phsh = g_strdup(phsh); 38 buddy->phsh = NULL;
41 buddy->status = g_strdup(status); 39 buddy->status = NULL;
42 buddy->email = g_strdup(email); 40 buddy->email = NULL;
43 buddy->last = g_strdup(last); 41 buddy->last = NULL;
44 buddy->jid = g_strdup(jid); 42 buddy->jid = NULL;
45 buddy->AIM = g_strdup(AIM); 43 buddy->AIM = NULL;
46 buddy->vc = g_strdup(vc); 44 buddy->vc = NULL;
47 buddy->ip = g_strdup(ip); 45 buddy->ip = NULL;
48 buddy->msg = g_strdup(msg); 46 buddy->msg = NULL;
49 buddy->conversation = NULL; 47 buddy->conversation = NULL;
48
49 #ifdef USE_BONJOUR_APPLE
50 buddy->txt_query = NULL;
51 buddy->txt_query_fd = 0;
52 #endif
50 53
51 return buddy; 54 return buddy;
55 }
56
57 void
58 set_bonjour_buddy_value(BonjourBuddy* buddy, bonjour_buddy_member member, const char* value, uint32_t len)
59 {
60 gchar **key = NULL;
61 switch (member)
62 {
63 case E_BUDDY_FIRST:
64 key = &buddy->first;
65 break;
66
67 case E_BUDDY_LAST:
68 key = &buddy->last;
69 break;
70
71 case E_BUDDY_STATUS:
72 key = &buddy->status;
73 break;
74
75 case E_BUDDY_EMAIL:
76 key = &buddy->email;
77 break;
78
79 case E_BUDDY_PHSH:
80 key = &buddy->phsh;
81 break;
82
83 case E_BUDDY_JID:
84 key = &buddy->jid;
85 break;
86
87 case E_BUDDY_AIM:
88 key = &buddy->AIM;
89 break;
90
91 case E_BUDDY_VC:
92 key = &buddy->vc;
93 break;
94
95 case E_BUDDY_MSG:
96 key = &buddy->msg;
97 break;
98 }
99
100 g_free(*key);
101 *key = NULL;
102 *key = g_strndup(value, len);
52 } 103 }
53 104
54 /** 105 /**
55 * Check if all the compulsory buddy data is present. 106 * Check if all the compulsory buddy data is present.
56 */ 107 */
57 gboolean 108 gboolean
58 bonjour_buddy_check(BonjourBuddy *buddy) 109 bonjour_buddy_check(BonjourBuddy *buddy)
59 { 110 {
60 if (buddy->name == NULL) { 111 if (buddy->account == NULL)
61 return FALSE; 112 {
62 } 113 return FALSE;
63 114 }
64 if (buddy->first == NULL) { 115
65 return FALSE; 116 if (buddy->name == NULL)
66 } 117 {
67 118 return FALSE;
68 if (buddy->last == NULL) { 119 }
69 return FALSE; 120
70 } 121 if (buddy->first == NULL)
71 122 {
72 if (buddy->status == NULL) { 123 return FALSE;
124 }
125
126 if (buddy->last == NULL)
127 {
128 return FALSE;
129 }
130
131 if (buddy->status == NULL)
132 {
73 return FALSE; 133 return FALSE;
74 } 134 }
75 135
76 return TRUE; 136 return TRUE;
77 } 137 }
80 * If the buddy does not yet exist, then create it and add it to 140 * If the buddy does not yet exist, then create it and add it to
81 * our buddy list. In either case we set the correct status for 141 * our buddy list. In either case we set the correct status for
82 * the buddy. 142 * the buddy.
83 */ 143 */
84 void 144 void
85 bonjour_buddy_add_to_purple(PurpleAccount *account, BonjourBuddy *bonjour_buddy) 145 bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy)
86 { 146 {
87 PurpleBuddy *buddy; 147 PurpleBuddy *buddy;
88 PurpleGroup *group; 148 PurpleGroup *group;
89 const char *status_id, *first, *last; 149 const char *status_id, *first, *last;
90 char *alias; 150 char *alias;
91 151
92 /* Translate between the Bonjour status and the Purple status */ 152 /* Translate between the Bonjour status and the Purple status */
93 if (g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0) 153 if (g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0)
94 status_id = BONJOUR_STATUS_ID_AWAY; 154 status_id = BONJOUR_STATUS_ID_AWAY;
95 else 155 else
96 status_id = BONJOUR_STATUS_ID_AVAILABLE; 156 status_id = BONJOUR_STATUS_ID_AVAILABLE;
106 alias = g_strdup_printf("%s%s%s", 166 alias = g_strdup_printf("%s%s%s",
107 (first && *first ? first : ""), 167 (first && *first ? first : ""),
108 (first && *first && last && *last ? " " : ""), 168 (first && *first && last && *last ? " " : ""),
109 (last && *last ? last : "")); 169 (last && *last ? last : ""));
110 170
171
111 /* Make sure the Bonjour group exists in our buddy list */ 172 /* Make sure the Bonjour group exists in our buddy list */
112 group = purple_find_group(BONJOUR_GROUP_NAME); /* Use the buddy's domain, instead? */ 173 group = purple_find_group(BONJOUR_GROUP_NAME); /* Use the buddy's domain, instead? */
113 if (group == NULL) 174 if (group == NULL)
114 { 175 {
115 group = purple_group_new(BONJOUR_GROUP_NAME); 176 group = purple_group_new(BONJOUR_GROUP_NAME);
116 purple_blist_add_group(group, NULL); 177 purple_blist_add_group(group, NULL);
117 } 178 }
118 179
119 /* Make sure the buddy exists in our buddy list */ 180 /* Make sure the buddy exists in our buddy list */
120 buddy = purple_find_buddy(account, bonjour_buddy->name); 181 buddy = purple_find_buddy(bonjour_buddy->account, bonjour_buddy->name);
182
121 if (buddy == NULL) 183 if (buddy == NULL)
122 { 184 {
123 buddy = purple_buddy_new(account, bonjour_buddy->name, alias); 185 buddy = purple_buddy_new(bonjour_buddy->account, bonjour_buddy->name, alias);
124 buddy->proto_data = bonjour_buddy; 186 buddy->proto_data = bonjour_buddy;
125 purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE); 187 purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
126 purple_blist_add_buddy(buddy, NULL, group, NULL); 188 purple_blist_add_buddy(buddy, NULL, group, NULL);
127 } 189 }
128 190
129 /* Set the user's status */ 191 /* Set the user's status */
130 if (bonjour_buddy->msg != NULL) 192 if (bonjour_buddy->msg != NULL)
131 purple_prpl_got_user_status(account, buddy->name, status_id, 193 purple_prpl_got_user_status(bonjour_buddy->account, buddy->name, status_id,
132 "message", bonjour_buddy->msg, 194 "message", bonjour_buddy->msg,
133 NULL); 195 NULL);
134 else 196 else
135 purple_prpl_got_user_status(account, buddy->name, status_id, 197 purple_prpl_got_user_status(bonjour_buddy->account, buddy->name, status_id,
136 NULL); 198 NULL);
137 purple_prpl_got_user_idle(account, buddy->name, FALSE, 0); 199 purple_prpl_got_user_idle(bonjour_buddy->account, buddy->name, FALSE, 0);
200
138 201
139 g_free(alias); 202 g_free(alias);
140 } 203 }
141 204
142 /** 205 /**
160 if (buddy->conversation != NULL) 223 if (buddy->conversation != NULL)
161 { 224 {
162 g_free(buddy->conversation->buddy_name); 225 g_free(buddy->conversation->buddy_name);
163 g_free(buddy->conversation); 226 g_free(buddy->conversation);
164 } 227 }
228
229 #ifdef USE_BONJOUR_APPLE
230 if (NULL != buddy->txt_query)
231 {
232 purple_input_remove(buddy->txt_query_fd);
233 DNSServiceRefDeallocate(buddy->txt_query);
234 }
235 #endif
165 236
166 free(buddy); 237 free(buddy);
167 } 238 }