Mercurial > pidgin
comparison src/protocols/msn/sync.c @ 9193:502707ca1836
[gaim-migrate @ 9988]
Patch by Felipe Contreras to add MSN file transfer and buddy icons. Please
test and report any bugs!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 06 Jun 2004 02:39:08 +0000 |
parents | |
children | ab6636c5a136 |
comparison
equal
deleted
inserted
replaced
9192:5655dcd94d0f | 9193:502707ca1836 |
---|---|
1 #include "msn.h" | |
2 #include "sync.h" | |
3 #include "state.h" | |
4 | |
5 static MsnTable *cbs_table; | |
6 | |
7 static void | |
8 blp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
9 { | |
10 GaimConnection *gc = cmdproc->session->account->gc; | |
11 const char *list_name; | |
12 | |
13 list_name = cmd->params[0]; | |
14 | |
15 if (!g_ascii_strcasecmp(list_name, "AL")) | |
16 { | |
17 /* | |
18 * If the current setting is AL, messages from users who | |
19 * are not in BL will be delivered. | |
20 * | |
21 * In other words, deny some. | |
22 */ | |
23 gc->account->perm_deny = GAIM_PRIVACY_DENY_USERS; | |
24 } | |
25 else | |
26 { | |
27 /* If the current setting is BL, only messages from people | |
28 * who are in the AL will be delivered. | |
29 * | |
30 * In other words, permit some. | |
31 */ | |
32 gc->account->perm_deny = GAIM_PRIVACY_ALLOW_USERS; | |
33 } | |
34 } | |
35 | |
36 static void | |
37 prp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
38 { | |
39 MsnSession *session = cmdproc->session; | |
40 const char *type, *value; | |
41 | |
42 type = cmd->params[0]; | |
43 value = cmd->params[1]; | |
44 | |
45 if (cmd->param_count == 2) | |
46 { | |
47 if (!strcmp(type, "PHH")) | |
48 msn_user_set_home_phone(session->user, gaim_url_decode(value)); | |
49 else if (!strcmp(type, "PHW")) | |
50 msn_user_set_work_phone(session->user, gaim_url_decode(value)); | |
51 else if (!strcmp(type, "PHM")) | |
52 msn_user_set_mobile_phone(session->user, gaim_url_decode(value)); | |
53 } | |
54 else | |
55 { | |
56 if (!strcmp(type, "PHH")) | |
57 msn_user_set_home_phone(session->user, NULL); | |
58 else if (!strcmp(type, "PHW")) | |
59 msn_user_set_work_phone(session->user, NULL); | |
60 else if (!strcmp(type, "PHM")) | |
61 msn_user_set_mobile_phone(session->user, NULL); | |
62 } | |
63 } | |
64 | |
65 static void | |
66 lsg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
67 { | |
68 MsnSession *session = cmdproc->session; | |
69 MsnGroup *group; | |
70 GaimGroup *g; | |
71 const char *name; | |
72 int group_id; | |
73 | |
74 group_id = atoi(cmd->params[0]); | |
75 name = gaim_url_decode(cmd->params[1]); | |
76 | |
77 group = msn_group_new(session->userlist, group_id, name); | |
78 | |
79 if ((g = gaim_find_group(name)) == NULL) | |
80 { | |
81 g = gaim_group_new(name); | |
82 gaim_blist_add_group(g, NULL); | |
83 } | |
84 } | |
85 | |
86 static void | |
87 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
88 { | |
89 MsnSession *session = cmdproc->session; | |
90 GaimAccount *account = session->account; | |
91 GaimConnection *gc = gaim_account_get_connection(account); | |
92 char *passport = NULL; | |
93 const char *friend = NULL; | |
94 int list_op; | |
95 MsnUser *user; | |
96 | |
97 passport = cmd->params[0]; | |
98 friend = gaim_url_decode(cmd->params[1]); | |
99 list_op = atoi(cmd->params[2]); | |
100 | |
101 user = msn_user_new(session->userlist, passport, friend); | |
102 | |
103 msn_userlist_add_user(session->userlist, user); | |
104 | |
105 session->sync->last_user = user; | |
106 | |
107 /* TODO: This can be improved */ | |
108 | |
109 if (list_op & MSN_LIST_FL_OP) | |
110 { | |
111 char **c; | |
112 char **tokens; | |
113 const char *group_nums; | |
114 GSList *group_ids; | |
115 | |
116 group_nums = cmd->params[3]; | |
117 | |
118 group_ids = NULL; | |
119 | |
120 tokens = g_strsplit(group_nums, ",", -1); | |
121 | |
122 for (c = tokens; *c != NULL; c++) | |
123 { | |
124 int id; | |
125 | |
126 id = atoi(*c); | |
127 group_ids = g_slist_append(group_ids, GINT_TO_POINTER(id)); | |
128 } | |
129 | |
130 g_strfreev(tokens); | |
131 | |
132 msn_got_lst_user(session, user, list_op, group_ids); | |
133 | |
134 g_slist_free(group_ids); | |
135 } | |
136 else | |
137 { | |
138 msn_got_lst_user(session, user, list_op, NULL); | |
139 } | |
140 | |
141 session->sync->num_users++; | |
142 | |
143 if (session->sync->num_users == session->sync->total_users) | |
144 { | |
145 cmdproc->cbs_table = session->sync->old_cbs_table; | |
146 | |
147 msn_user_set_buddy_icon(session->user, | |
148 gaim_account_get_buddy_icon(session->account)); | |
149 | |
150 msn_change_status(session, MSN_ONLINE); | |
151 | |
152 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
153 serv_finish_login(gc); | |
154 | |
155 msn_sync_destroy(session->sync); | |
156 session->sync = NULL; | |
157 } | |
158 } | |
159 | |
160 static void | |
161 bpr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
162 { | |
163 MsnSync *sync = cmdproc->session->sync; | |
164 const char *type, *value; | |
165 MsnUser *user; | |
166 | |
167 user = sync->last_user; | |
168 | |
169 type = cmd->params[0]; | |
170 value = cmd->params[1]; | |
171 | |
172 if (value) | |
173 { | |
174 if (!strcmp(type, "MOB")) | |
175 { | |
176 if (!strcmp(value, "Y")) | |
177 user->mobile = TRUE; | |
178 } | |
179 else if (!strcmp(type, "PHH")) | |
180 msn_user_set_home_phone(user, gaim_url_decode(value)); | |
181 else if (!strcmp(type, "PHW")) | |
182 msn_user_set_work_phone(user, gaim_url_decode(value)); | |
183 else if (!strcmp(type, "PHM")) | |
184 msn_user_set_mobile_phone(user, gaim_url_decode(value)); | |
185 } | |
186 } | |
187 | |
188 void | |
189 msn_sync_init(void) | |
190 { | |
191 /* TODO: check prp, blp, bpr */ | |
192 | |
193 cbs_table = msn_table_new(); | |
194 | |
195 /* Syncing */ | |
196 msn_table_add_cmd(cbs_table, NULL, "GTC", NULL); | |
197 msn_table_add_cmd(cbs_table, NULL, "BLP", blp_cmd); | |
198 msn_table_add_cmd(cbs_table, NULL, "PRP", prp_cmd); | |
199 msn_table_add_cmd(cbs_table, NULL, "LSG", lsg_cmd); | |
200 msn_table_add_cmd(cbs_table, NULL, "LST", lst_cmd); | |
201 msn_table_add_cmd(cbs_table, NULL, "BPR", bpr_cmd); | |
202 } | |
203 | |
204 void | |
205 msn_sync_end(void) | |
206 { | |
207 msn_table_destroy(cbs_table); | |
208 } | |
209 | |
210 MsnSync * | |
211 msn_sync_new(MsnSession *session) | |
212 { | |
213 MsnSync *sync; | |
214 | |
215 sync = g_new0(MsnSync, 1); | |
216 | |
217 sync->session = session; | |
218 sync->cbs_table = cbs_table; | |
219 | |
220 return sync; | |
221 } | |
222 | |
223 void | |
224 msn_sync_destroy(MsnSync *sync) | |
225 { | |
226 g_free(sync); | |
227 } |