-
Notifications
You must be signed in to change notification settings - Fork 20
/
f_sysmsg.c
227 lines (204 loc) · 6.33 KB
/
f_sysmsg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "internal.h"
#include "accountopt.h"
#include "blist.h"
#include "conversation.h"
#include "dnsquery.h"
#include "debug.h"
#include "notify.h"
#include "privacy.h"
#include "prpl.h"
#include "plugin.h"
#include "util.h"
#include "version.h"
#include "network.h"
#include "xmlnode.h"
#include "request.h"
#include "imgstore.h"
#include "sslconn.h"
#include "sipmsg.h"
#include "dnssrv.h"
#include "ntlm.h"
#include "sipmsg.h"
#include "f_sysmsg.h"
void process_incoming_BN(struct fetion_account_data *sip, struct sipmsg *msg)
{
const gchar *new_crc;
const gchar *nickname, *basicstatus, *event_type, *uri, *impresa;
struct fetion_buddy *buddy = NULL;
struct group_chat *g_chat = NULL;
const gchar *from;
gchar *cur, *alias, *nickbuf;
xmlnode *root, *event_node, *item;
xmlnode *basic, *personal;
PurpleBuddy *b = NULL;
root = xmlnode_from_str(msg->body, msg->bodylen);
g_return_if_fail(root != NULL);
purple_debug(PURPLE_DEBUG_MISC, "fetion", "in BN[%s]\n", msg->body);
event_node = xmlnode_get_child(root, "event");
g_return_if_fail(event_node != NULL);
event_type = xmlnode_get_attrib(event_node, "type");
if (strncmp(event_type, "PresenceChanged", 15) == 0) {
for (item = xmlnode_get_child(event_node, "presence"); item;
item = xmlnode_get_next_twin(item)) {
uri = xmlnode_get_attrib(item, "uri");
basic = xmlnode_get_child(item, "basic");
if (basic != NULL) {
basicstatus =
xmlnode_get_attrib(basic, "value");
if ((basicstatus != NULL)
&& (strncmp(basicstatus, "0", 1) != 0)) {
buddy =
g_hash_table_lookup(sip->buddies,
uri);
if (buddy == NULL) {
buddy =
g_new0(struct fetion_buddy,
1);
buddy->name = g_strdup(uri);
g_hash_table_insert
(sip->buddies, buddy->name,
buddy);
}
buddy->dialog = NULL;
switch (atoi(basicstatus)) {
case 100: //away
purple_prpl_got_user_status
(sip->account, uri, "away",
NULL);
break;
case 300: //be right back
purple_prpl_got_user_status
(sip->account, uri, "brb",
NULL);
break;
case 600: //busy
case 800:
case 850:
purple_prpl_got_user_status
(sip->account, uri, "busy",
NULL);
break;
case 150:
purple_prpl_got_user_status
(sip->account, uri, "lunch",
NULL);
break;
default:
purple_prpl_got_user_status
(sip->account, uri,
"available", NULL);
}
} else
purple_prpl_got_user_status
(sip->account, uri, "mobile", NULL);
}
personal = xmlnode_get_child(item, "personal");
if (personal == NULL)
continue;
nickname = xmlnode_get_attrib(personal, "nickname");
impresa = xmlnode_get_attrib(personal, "impresa");
new_crc = xmlnode_get_attrib(personal, "portrait-crc");
b = purple_find_buddy(sip->account, uri);
g_return_if_fail(b != NULL);
if (nickname == NULL) {
nickbuf = g_strdup(b->server_alias);
cur = strstr(nickbuf, "--(");
if (cur != NULL)
*cur = '\0';
nickname = g_strdup(nickbuf);
g_free(nickbuf);
}
if (impresa != NULL && *impresa != '\0')
alias =
g_strdup_printf("%s--(%s)", nickname,
impresa);
else
alias = g_strdup_printf("%s",nickname);
if ((b != NULL) && (alias != NULL) && (*alias != '\0'))
purple_blist_server_alias_buddy(b, alias);
if ((new_crc != NULL) && (strcmp(new_crc, "0") != 0))
CheckPortrait(sip, uri, new_crc);
g_free(alias);
}
} else if (strncmp(event_type, "UserEntered", 11) == 0) {
from = sipmsg_find_header(msg, "F");
if (from != NULL && strncmp(from, "sip:TG", 6) == 0) {
g_chat = g_hash_table_lookup(sip->tempgroup, from);
g_return_if_fail(g_chat != NULL);
}
for (item = xmlnode_get_child(event_node, "member"); item;
item = xmlnode_get_next_twin(item)) {
uri = xmlnode_get_attrib(item, "uri");
b = purple_find_buddy(sip->account, uri);
if (b == NULL)
purple_conv_chat_add_user(PURPLE_CONV_CHAT
(g_chat->conv), uri,
NULL,
PURPLE_CBFLAGS_NONE,
TRUE);
else
purple_conv_chat_add_user(PURPLE_CONV_CHAT
(g_chat->conv),
purple_buddy_get_alias
(b), NULL,
PURPLE_CBFLAGS_NONE,
TRUE);
}
} else if (strncmp(event_type, "UserLeft", 11) == 0) {
from = sipmsg_find_header(msg, "F");
if (from != NULL && strncmp(from, "sip:TG", 6) == 0) {
g_chat = g_hash_table_lookup(sip->tempgroup, from);
g_return_if_fail(g_chat != NULL);
}
for (item = xmlnode_get_child(event_node, "member"); item;
item = xmlnode_get_next_twin(item)) {
uri = xmlnode_get_attrib(item, "uri");
b = purple_find_buddy(sip->account, uri);
if (b == NULL)
purple_conv_chat_remove_user(PURPLE_CONV_CHAT
(g_chat->conv),
uri, NULL);
else
purple_conv_chat_remove_user(PURPLE_CONV_CHAT
(g_chat->conv),
purple_buddy_get_alias
(b), NULL);
}
} else if (strncmp(event_type, "deregistered", 12) == 0) {
purple_connection_error_reason(sip->gc,
PURPLE_CONNECTION_ERROR_NAME_IN_USE,
_
("You have signed on from another location."));
} else if (strncmp(event_type, "ServiceResult", 13) == 0) {
for (item = xmlnode_get_child(event_node, "results/contacts/contact"); item; item = xmlnode_get_next_twin(item)) {
uri = xmlnode_get_attrib(item, "uri");
personal = xmlnode_get_child(item, "personal");
if (personal == NULL)
continue;
nickname = xmlnode_get_attrib(personal, "nickname");
impresa = xmlnode_get_attrib(personal, "impresa");
new_crc = xmlnode_get_attrib(personal, "portrait-crc");
b = purple_find_buddy(sip->account, uri);
g_return_if_fail(b != NULL);
if (nickname == NULL) {
nickbuf = g_strdup(b->server_alias);
cur = strstr(nickbuf, "--(");
if (cur != NULL)
*cur = '\0';
nickname = g_strdup(nickbuf);
g_free(nickbuf);
}
if (impresa != NULL && *impresa != '\0')
alias = g_strdup_printf("%s--(%s)", nickname,
impresa);
else
alias = g_strdup_printf("%s",nickname);
if ((b != NULL) && (alias != NULL) && (*alias != '\0'))
purple_blist_server_alias_buddy(b, alias);
if ((new_crc != NULL) && (strcmp(new_crc, "0") != 0))
CheckPortrait(sip, uri, new_crc);
g_free(alias);
}
}
xmlnode_free(root);
}