11477
|
1 /*
|
|
2 * This program is free software; you can redistribute it and/or modify
|
|
3 * it under the terms of the GNU General Public License as published by
|
|
4 * the Free Software Foundation; either version 2 of the License, or
|
|
5 * (at your option) any later version.
|
|
6 *
|
|
7 * This program is distributed in the hope that it will be useful,
|
|
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 * GNU Library General Public License for more details.
|
|
11 *
|
|
12 * You should have received a copy of the GNU General Public License
|
|
13 * along with this program; if not, write to the Free Software
|
|
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
15 */
|
|
16
|
|
17 #include <glib.h>
|
|
18 #include <stdlib.h>
|
|
19
|
|
20 #include "buddy.h"
|
|
21 #include "account.h"
|
|
22 #include "blist.h"
|
|
23 #include "bonjour.h"
|
|
24 #include "debug.h"
|
|
25
|
|
26 /**
|
|
27 * Creates a new buddy.
|
|
28 */
|
11539
|
29 BonjourBuddy *
|
13649
|
30 bonjour_buddy_new(const gchar *name, const gchar *first, gint port_p2pj,
|
|
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)
|
11477
|
34 {
|
11539
|
35 BonjourBuddy *buddy = malloc(sizeof(BonjourBuddy));
|
11477
|
36
|
|
37 buddy->name = g_strdup(name);
|
|
38 buddy->first = g_strdup(first);
|
|
39 buddy->port_p2pj = port_p2pj;
|
|
40 buddy->phsh = g_strdup(phsh);
|
|
41 buddy->status = g_strdup(status);
|
|
42 buddy->email = g_strdup(email);
|
|
43 buddy->last = g_strdup(last);
|
|
44 buddy->jid = g_strdup(jid);
|
|
45 buddy->AIM = g_strdup(AIM);
|
|
46 buddy->vc = g_strdup(vc);
|
|
47 buddy->ip = g_strdup(ip);
|
|
48 buddy->msg = g_strdup(msg);
|
|
49 buddy->conversation = NULL;
|
11539
|
50
|
11477
|
51 return buddy;
|
|
52 }
|
|
53
|
|
54 /**
|
|
55 * Check if all the compulsory buddy data is present.
|
|
56 */
|
11539
|
57 gboolean
|
|
58 bonjour_buddy_check(BonjourBuddy *buddy)
|
11477
|
59 {
|
11539
|
60 if (buddy->name == NULL) {
|
11477
|
61 return FALSE;
|
|
62 }
|
11539
|
63
|
|
64 if (buddy->first == NULL) {
|
11477
|
65 return FALSE;
|
|
66 }
|
11539
|
67
|
|
68 if (buddy->last == NULL) {
|
11477
|
69 return FALSE;
|
|
70 }
|
11539
|
71
|
|
72 if (buddy->status == NULL) {
|
11477
|
73 return FALSE;
|
|
74 }
|
11539
|
75
|
11477
|
76 return TRUE;
|
|
77 }
|
|
78
|
|
79 /**
|
11496
|
80 * 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
|
|
82 * the buddy.
|
11477
|
83 */
|
11496
|
84 void
|
|
85 bonjour_buddy_add_to_gaim(GaimAccount *account, BonjourBuddy *bonjour_buddy)
|
11477
|
86 {
|
11496
|
87 GaimBuddy *buddy;
|
|
88 GaimGroup *group;
|
|
89 const char *status_id, *first, *last;
|
|
90 char *alias;
|
11477
|
91
|
11496
|
92 /* Translate between the Bonjour status and the Gaim status */
|
|
93 if (g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0)
|
|
94 status_id = BONJOUR_STATUS_ID_AWAY;
|
|
95 else
|
|
96 status_id = BONJOUR_STATUS_ID_AVAILABLE;
|
|
97
|
|
98 /*
|
|
99 * TODO: Figure out the idle time by getting the "away"
|
|
100 * field from the DNS SD.
|
|
101 */
|
11477
|
102
|
11496
|
103 /* Create the alias for the buddy using the first and the last name */
|
|
104 first = bonjour_buddy->first;
|
|
105 last = bonjour_buddy->last;
|
|
106 alias = g_strdup_printf("%s%s%s",
|
|
107 (first && *first ? first : ""),
|
|
108 (first && *first && last && *last ? " " : ""),
|
|
109 (last && *last ? last : ""));
|
|
110
|
|
111 /* Make sure the Bonjour group exists in our buddy list */
|
|
112 group = gaim_find_group(BONJOUR_GROUP_NAME); /* Use the buddy's domain, instead? */
|
|
113 if (group == NULL)
|
|
114 {
|
|
115 group = gaim_group_new(BONJOUR_GROUP_NAME);
|
|
116 gaim_blist_add_group(group, NULL);
|
11477
|
117 }
|
11496
|
118
|
|
119 /* Make sure the buddy exists in our buddy list */
|
|
120 buddy = gaim_find_buddy(account, bonjour_buddy->name);
|
|
121 if (buddy == NULL)
|
|
122 {
|
|
123 buddy = gaim_buddy_new(account, bonjour_buddy->name, alias);
|
11519
|
124 buddy->proto_data = bonjour_buddy;
|
11496
|
125 gaim_blist_node_set_flags((GaimBlistNode *)buddy, GAIM_BLIST_NODE_FLAG_NO_SAVE);
|
|
126 gaim_blist_add_buddy(buddy, NULL, group, NULL);
|
11477
|
127 }
|
11496
|
128
|
|
129 /* Set the user's status */
|
11519
|
130 if (bonjour_buddy->msg != NULL)
|
|
131 gaim_prpl_got_user_status(account, buddy->name, status_id,
|
|
132 "message", bonjour_buddy->msg,
|
|
133 NULL);
|
|
134 else
|
|
135 gaim_prpl_got_user_status(account, buddy->name, status_id,
|
|
136 NULL);
|
11496
|
137 gaim_prpl_got_user_idle(account, buddy->name, FALSE, 0);
|
|
138
|
|
139 g_free(alias);
|
11477
|
140 }
|
|
141
|
|
142 /**
|
|
143 * Deletes a buddy from memory.
|
|
144 */
|
11539
|
145 void
|
|
146 bonjour_buddy_delete(BonjourBuddy *buddy)
|
11477
|
147 {
|
|
148 g_free(buddy->name);
|
|
149 g_free(buddy->first);
|
|
150 g_free(buddy->phsh);
|
|
151 g_free(buddy->status);
|
|
152 g_free(buddy->email);
|
|
153 g_free(buddy->last);
|
|
154 g_free(buddy->jid);
|
|
155 g_free(buddy->AIM);
|
|
156 g_free(buddy->vc);
|
|
157 g_free(buddy->ip);
|
|
158 g_free(buddy->msg);
|
11539
|
159
|
|
160 if (buddy->conversation != NULL)
|
|
161 {
|
11477
|
162 g_free(buddy->conversation->buddy_name);
|
|
163 g_free(buddy->conversation);
|
|
164 }
|
11539
|
165
|
11477
|
166 free(buddy);
|
|
167 }
|