Mercurial > pidgin.yaz
annotate src/protocols/novell/nmuser.c @ 9268:54fb1f466953
[gaim-migrate @ 10069]
" - Added keepalive support
- Improved handling of character sets in RTF (improves
intl interoperability between Gaim and the
Windows/XPLAT Messenger clients)." --Mike Stoddard of Novell
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 12 Jun 2004 15:13:29 +0000 |
parents | 6663ad2386d9 |
children | d77537e8bfe5 |
rev | line source |
---|---|
8675 | 1 /* |
2 * nmuser.c | |
3 * | |
8933 | 4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; version 2 of the License. | |
8675 | 9 * |
8933 | 10 * This program is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 * |
8933 | 15 * You should have received a copy of the GNU General Public License |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
8675 | 18 * |
19 */ | |
20 | |
21 #include <glib.h> | |
22 #include <string.h> | |
8933 | 23 #include "internal.h" |
8675 | 24 #include "nmfield.h" |
25 #include "nmuser.h" | |
26 #include "nmconn.h" | |
27 #include "nmcontact.h" | |
28 #include "nmuserrecord.h" | |
29 #include "util.h" | |
30 | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
31 /* This is the template that we wrap outgoing messages in, since the other |
8675 | 32 * GW Messenger clients expect messages to be in RTF. |
33 */ | |
9268 | 34 #define RTF_TEMPLATE "{\\rtf1\\ansi\n"\ |
35 "{\\fonttbl{\\f0\\fnil Unknown;}}\n"\ | |
36 "{\\colortbl ;\\red0\\green0\\blue0;}\n"\ | |
37 "\\uc1\\cf1\\f0\\fs24 %s\\par\n}" | |
8933 | 38 #define NM_MAX_MESSAGE_SIZE 2048 |
8675 | 39 |
40 static NMERR_T nm_process_response(NMUser * user); | |
41 static void _update_contact_list(NMUser * user, NMField * fields); | |
9268 | 42 static void _handle_multiple_get_details_login_cb(NMUser * user, NMERR_T ret_code, |
43 gpointer resp_data, gpointer user_data); | |
44 static char * nm_rtfize_text(char *text); | |
8933 | 45 |
8675 | 46 /** |
47 * See header for comments on on "public" functions | |
48 */ | |
49 | |
50 NMUser * | |
51 nm_initialize_user(const char *name, const char *server_addr, | |
52 int port, gpointer data, nm_event_cb event_callback) | |
53 { | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
54 NMUser *user; |
8675 | 55 if (name == NULL || server_addr == NULL || event_callback == NULL) |
56 return NULL; | |
57 | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
58 user = g_new0(NMUser, 1); |
8675 | 59 |
60 user->conn = g_new0(NMConn, 1); | |
61 | |
62 user->contacts = | |
63 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
64 g_free, (GDestroyNotify) nm_release_contact); | |
65 | |
66 user->user_records = | |
67 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, g_free, | |
68 (GDestroyNotify) nm_release_user_record); | |
69 | |
70 user->display_id_to_dn = g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
71 g_free, g_free); | |
72 | |
73 user->name = g_strdup(name); | |
74 user->conn->addr = g_strdup(server_addr); | |
75 user->conn->port = port; | |
76 user->evt_callback = event_callback; | |
77 user->client_data = data; | |
78 | |
79 return user; | |
80 } | |
81 | |
82 | |
83 void | |
84 nm_deinitialize_user(NMUser * user) | |
85 { | |
86 NMConn *conn = user->conn; | |
87 | |
88 g_free(conn->addr); | |
89 g_free(conn); | |
90 | |
91 if (user->contacts) { | |
92 g_hash_table_destroy(user->contacts); | |
93 } | |
94 | |
95 if (user->user_records) { | |
96 g_hash_table_destroy(user->user_records); | |
97 } | |
98 | |
99 if (user->display_id_to_dn) { | |
100 g_hash_table_destroy(user->display_id_to_dn); | |
101 } | |
102 | |
103 if (user->name) { | |
104 g_free(user->name); | |
105 } | |
106 | |
107 if (user->user_record) { | |
108 nm_release_user_record(user->user_record); | |
109 } | |
110 | |
111 nm_conference_list_free(user); | |
112 nm_destroy_contact_list(user); | |
113 | |
114 g_free(user); | |
115 } | |
116 | |
117 NMERR_T | |
118 nm_send_login(NMUser * user, const char *pwd, const char *my_addr, | |
119 const char *user_agent, nm_response_cb callback, gpointer data) | |
120 { | |
121 NMERR_T rc = NM_OK; | |
122 NMField *fields = NULL; | |
123 NMRequest *req = NULL; | |
124 | |
125 if (user == NULL || pwd == NULL || user_agent == NULL) { | |
126 return NMERR_BAD_PARM; | |
127 } | |
128 | |
8933 | 129 fields = nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, |
130 g_strdup(user->name), NMFIELD_TYPE_UTF8); | |
131 | |
132 fields = nm_field_add_pointer(fields, NM_A_SZ_CREDENTIALS, 0, NMFIELD_METHOD_VALID, 0, | |
133 g_strdup(pwd), NMFIELD_TYPE_UTF8); | |
134 | |
135 fields = nm_field_add_pointer(fields, NM_A_SZ_USER_AGENT, 0, NMFIELD_METHOD_VALID, 0, | |
136 g_strdup(user_agent), NMFIELD_TYPE_UTF8); | |
137 | |
138 fields = nm_field_add_number(fields, NM_A_UD_BUILD, 0, NMFIELD_METHOD_VALID, 0, | |
139 NM_PROTOCOL_VERSION, NMFIELD_TYPE_UDWORD); | |
8675 | 140 if (my_addr) { |
8933 | 141 fields = nm_field_add_pointer(fields, NM_A_IP_ADDRESS, 0, NMFIELD_METHOD_VALID, 0, |
142 g_strdup(my_addr), NMFIELD_TYPE_UTF8); | |
8675 | 143 } |
144 | |
145 /* Send the login */ | |
146 rc = nm_send_request(user->conn, "login", fields, &req); | |
147 if (rc == NM_OK && req != NULL) { | |
148 nm_request_set_callback(req, callback); | |
149 nm_request_set_user_define(req, data); | |
150 nm_conn_add_request_item(user->conn, req); | |
151 } | |
152 | |
153 if (fields) { | |
154 nm_free_fields(&fields); | |
155 } | |
156 | |
157 if (req) { | |
158 nm_release_request(req); | |
159 } | |
160 | |
161 return rc; | |
162 } | |
163 | |
164 NMERR_T | |
165 nm_send_set_status(NMUser * user, int status, const char *text, | |
166 const char *auto_resp, nm_response_cb callback, gpointer data) | |
167 { | |
168 NMERR_T rc = NM_OK; | |
169 NMField *fields = NULL; | |
170 NMRequest *req = NULL; | |
171 | |
172 if (user == NULL) | |
173 return NMERR_BAD_PARM; | |
174 | |
175 /* Add the status */ | |
8933 | 176 fields = nm_field_add_pointer(fields, NM_A_SZ_STATUS, 0, NMFIELD_METHOD_VALID, 0, |
177 g_strdup_printf("%d", status), NMFIELD_TYPE_UTF8); | |
8675 | 178 |
179 /* Add the status text and auto reply text if there is any */ | |
180 if (text) { | |
8933 | 181 fields = nm_field_add_pointer(fields, NM_A_SZ_STATUS_TEXT, 0, |
182 NMFIELD_METHOD_VALID, 0, g_strdup(text), | |
183 NMFIELD_TYPE_UTF8); | |
8675 | 184 } |
185 | |
186 if (auto_resp) { | |
8933 | 187 fields = nm_field_add_pointer(fields, NM_A_SZ_MESSAGE_BODY, 0, |
188 NMFIELD_METHOD_VALID, 0, g_strdup(auto_resp), | |
189 NMFIELD_TYPE_UTF8); | |
8675 | 190 } |
191 | |
192 rc = nm_send_request(user->conn, "setstatus", fields, &req); | |
193 if (rc == NM_OK && req) { | |
194 nm_request_set_callback(req, callback); | |
195 nm_request_set_user_define(req, data); | |
196 nm_conn_add_request_item(user->conn, req); | |
197 } | |
198 | |
199 if (fields) { | |
200 nm_free_fields(&fields); | |
201 } | |
202 | |
203 if (req) { | |
204 nm_release_request(req); | |
205 } | |
206 | |
207 return rc; | |
208 } | |
209 | |
210 NMERR_T | |
8933 | 211 nm_send_multiple_get_details(NMUser * user, GSList *names, |
212 nm_response_cb callback, gpointer data) | |
213 { | |
214 NMERR_T rc = NM_OK; | |
215 NMField *fields = NULL; | |
216 NMRequest *req = NULL; | |
217 GSList *node; | |
218 | |
219 if (user == NULL || names == NULL) | |
220 return NMERR_BAD_PARM; | |
221 | |
222 /* Add in DN or display id */ | |
223 for (node = names; node; node = node->next) { | |
224 fields = nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, | |
225 g_strdup(node->data), NMFIELD_TYPE_UTF8); | |
226 } | |
227 | |
228 rc = nm_send_request(user->conn, "getdetails", fields, &req); | |
229 if (rc == NM_OK) { | |
230 nm_request_set_callback(req, callback); | |
231 nm_request_set_user_define(req, data); | |
232 nm_conn_add_request_item(user->conn, req); | |
233 } | |
234 | |
235 if (fields) | |
236 nm_free_fields(&fields); | |
237 | |
238 if (req) | |
239 nm_release_request(req); | |
240 | |
241 return rc; | |
242 } | |
243 | |
244 NMERR_T | |
8675 | 245 nm_send_get_details(NMUser * user, const char *name, |
246 nm_response_cb callback, gpointer data) | |
247 { | |
248 NMERR_T rc = NM_OK; | |
249 NMField *fields = NULL; | |
250 NMRequest *req = NULL; | |
251 | |
252 if (user == NULL || name == NULL) | |
253 return NMERR_BAD_PARM; | |
254 | |
255 /* Add in DN or display id */ | |
256 if (strstr("=", name)) { | |
8933 | 257 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
258 g_strdup(name), NMFIELD_TYPE_DN); | |
8675 | 259 } else { |
260 | |
261 const char *dn = nm_lookup_dn(user, name); | |
262 | |
263 if (dn) { | |
8933 | 264 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
265 g_strdup(name), NMFIELD_TYPE_DN); | |
8675 | 266 } else { |
267 fields = | |
8933 | 268 nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, |
269 g_strdup(name), NMFIELD_TYPE_UTF8); | |
8675 | 270 } |
271 | |
272 } | |
273 | |
274 rc = nm_send_request(user->conn, "getdetails", fields, &req); | |
275 if (rc == NM_OK) { | |
276 nm_request_set_callback(req, callback); | |
277 nm_request_set_user_define(req, data); | |
278 nm_conn_add_request_item(user->conn, req); | |
279 } | |
280 | |
281 if (fields) | |
282 nm_free_fields(&fields); | |
283 | |
284 if (req) | |
285 nm_release_request(req); | |
286 | |
287 return rc; | |
288 } | |
289 | |
290 NMERR_T | |
291 nm_send_create_conference(NMUser * user, NMConference * conference, | |
292 nm_response_cb callback, gpointer message) | |
293 { | |
294 NMERR_T rc = NM_OK; | |
295 NMField *fields = NULL; | |
296 NMField *tmp = NULL; | |
297 NMField *field = NULL; | |
298 NMRequest *req = NULL; | |
299 int count, i; | |
300 | |
301 if (user == NULL || conference == NULL) | |
302 return NMERR_BAD_PARM; | |
303 | |
304 /* Add in a blank guid */ | |
8933 | 305 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
306 g_strdup(BLANK_GUID), NMFIELD_TYPE_UTF8); | |
307 | |
308 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
309 NMFIELD_METHOD_VALID, 0, tmp, | |
310 NMFIELD_TYPE_ARRAY); | |
8675 | 311 tmp = NULL; |
312 | |
8933 | 313 |
8675 | 314 /* Add participants in */ |
315 count = nm_conference_get_participant_count(conference); | |
316 for (i = 0; i < count; i++) { | |
317 NMUserRecord *user_record = nm_conference_get_participant(conference, i); | |
318 | |
319 if (user_record) { | |
8933 | 320 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, |
321 0, NMFIELD_METHOD_VALID, 0, | |
322 g_strdup(nm_user_record_get_dn(user_record)), | |
323 NMFIELD_TYPE_DN); | |
8675 | 324 } |
325 } | |
326 | |
327 /* Add our user in */ | |
328 field = nm_locate_field(NM_A_SZ_DN, user->fields); | |
329 if (field) { | |
8933 | 330 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, |
331 0, NMFIELD_METHOD_VALID, 0, | |
332 g_strdup((char *) field->ptr_value), | |
333 NMFIELD_TYPE_DN); | |
8675 | 334 } |
335 | |
336 rc = nm_send_request(user->conn, "createconf", fields, &req); | |
337 if (rc == NM_OK && req) { | |
338 nm_request_set_callback(req, callback); | |
8933 | 339 nm_conference_add_ref(conference); |
8675 | 340 nm_request_set_data(req, conference); |
341 nm_request_set_user_define(req, message); | |
342 nm_conn_add_request_item(user->conn, req); | |
343 } | |
344 | |
345 if (req) | |
346 nm_release_request(req); | |
347 | |
348 if (fields) | |
349 nm_free_fields(&fields); | |
350 | |
351 return rc; | |
352 } | |
353 | |
354 NMERR_T | |
355 nm_send_leave_conference(NMUser * user, NMConference * conference, | |
356 nm_response_cb callback, gpointer message) | |
357 { | |
358 | |
359 NMERR_T rc = NM_OK; | |
360 NMField *fields = NULL; | |
361 NMField *tmp = NULL; | |
362 NMRequest *req = NULL; | |
363 | |
364 if (user == NULL || conference == NULL) | |
365 return NMERR_BAD_PARM; | |
366 | |
367 /* Add in the conference guid */ | |
8933 | 368 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
369 g_strdup(nm_conference_get_guid(conference)), | |
370 NMFIELD_TYPE_UTF8); | |
371 | |
372 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
373 NMFIELD_METHOD_VALID, 0, tmp, | |
374 NMFIELD_TYPE_ARRAY); | |
8675 | 375 tmp = NULL; |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
376 |
8675 | 377 /* Send the request to the server */ |
378 rc = nm_send_request(user->conn, "leaveconf", fields, &req); | |
379 if (rc == NM_OK && req) { | |
380 nm_request_set_callback(req, callback); | |
381 nm_request_set_data(req, conference); | |
382 nm_request_set_user_define(req, message); | |
383 nm_conn_add_request_item(user->conn, req); | |
384 } | |
385 | |
386 if (req) | |
387 nm_release_request(req); | |
388 | |
389 if (fields) | |
390 nm_free_fields(&fields); | |
391 | |
392 return rc; | |
393 } | |
394 | |
395 NMERR_T | |
396 nm_send_join_conference(NMUser * user, NMConference * conference, | |
397 nm_response_cb callback, gpointer data) | |
398 { | |
399 NMERR_T rc = NM_OK; | |
400 NMField *fields = NULL, *tmp = NULL; | |
401 NMRequest *req = NULL; | |
402 | |
403 if (user == NULL || conference == NULL) | |
404 return NMERR_BAD_PARM; | |
405 | |
406 /* Add in the conference guid */ | |
8933 | 407 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
408 g_strdup(nm_conference_get_guid(conference)), | |
409 NMFIELD_TYPE_UTF8); | |
410 | |
411 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
412 NMFIELD_METHOD_VALID, 0, tmp, | |
413 NMFIELD_TYPE_ARRAY); | |
8675 | 414 tmp = NULL; |
415 | |
416 /* Send the request to the server */ | |
417 rc = nm_send_request(user->conn, "joinconf", fields, &req); | |
418 | |
419 /* Set up the request object so that we know what to do | |
420 * when we get a response | |
421 */ | |
422 if (rc == NM_OK && req) { | |
423 nm_request_set_callback(req, callback); | |
424 nm_request_set_data(req, conference); | |
425 nm_request_set_user_define(req, data); | |
426 nm_conn_add_request_item(user->conn, req); | |
427 } | |
428 | |
429 if (req) | |
430 nm_release_request(req); | |
431 | |
432 if (fields) | |
433 nm_free_fields(&fields); | |
434 | |
435 return rc; | |
436 } | |
437 | |
438 NMERR_T | |
439 nm_send_reject_conference(NMUser * user, NMConference * conference, | |
440 nm_response_cb callback, gpointer data) | |
441 { | |
442 NMERR_T rc = NM_OK; | |
443 NMField *fields = NULL; | |
444 NMField *tmp = NULL; | |
445 NMRequest *req = NULL; | |
446 | |
447 if (user == NULL || conference == NULL) | |
448 return NMERR_BAD_PARM; | |
449 | |
450 /* Add in the conference guid */ | |
8933 | 451 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
452 g_strdup(nm_conference_get_guid(conference)), | |
453 NMFIELD_TYPE_UTF8); | |
454 | |
455 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
456 NMFIELD_METHOD_VALID, 0, tmp, | |
457 NMFIELD_TYPE_ARRAY); | |
8675 | 458 tmp = NULL; |
459 | |
460 /* Send the request to the server */ | |
461 rc = nm_send_request(user->conn, "rejectconf", fields, &req); | |
462 | |
463 /* Set up the request object so that we know what to do | |
464 * when we get a response | |
465 */ | |
466 if (rc == NM_OK && req) { | |
467 nm_request_set_callback(req, callback); | |
468 nm_request_set_data(req, conference); | |
469 nm_request_set_user_define(req, data); | |
470 nm_conn_add_request_item(user->conn, req); | |
471 } | |
472 | |
473 if (req) | |
474 nm_release_request(req); | |
475 | |
476 if (fields) | |
477 nm_free_fields(&fields); | |
478 | |
479 return rc; | |
480 } | |
481 | |
482 NMERR_T | |
8933 | 483 nm_send_conference_invite(NMUser *user, NMConference *conference, NMUserRecord *user_record, |
484 const char *message, nm_response_cb callback, gpointer data) | |
485 { | |
486 NMERR_T rc = NM_OK; | |
487 NMField *fields = NULL; | |
488 NMField *tmp = NULL; | |
489 NMRequest *req = NULL; | |
490 | |
491 if (user == NULL || conference == NULL || user_record == NULL) | |
492 return NMERR_BAD_PARM; | |
493 | |
494 /* Add in the conference guid */ | |
495 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
496 g_strdup(nm_conference_get_guid(conference)), | |
497 NMFIELD_TYPE_UTF8); | |
498 | |
499 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
500 NMFIELD_METHOD_VALID, 0, tmp, | |
501 NMFIELD_TYPE_ARRAY); | |
502 tmp = NULL; | |
503 | |
504 /* Add in DN of user to invite */ | |
505 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
506 g_strdup(nm_user_record_get_dn(user_record)), | |
507 NMFIELD_TYPE_DN); | |
508 | |
509 /* Add the invite message if there is one */ | |
510 if (message) | |
511 fields = nm_field_add_pointer(fields, NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_METHOD_VALID, 0, | |
512 g_strdup(message), NMFIELD_TYPE_UTF8); | |
513 | |
514 /* Send the request to the server */ | |
515 rc = nm_send_request(user->conn, "sendinvite", fields, &req); | |
516 | |
517 /* Set up the request object so that we know what to do | |
518 * when we get a response | |
519 */ | |
520 if (rc == NM_OK && req) { | |
521 nm_request_set_callback(req, callback); | |
522 nm_request_set_data(req, conference); | |
523 nm_request_set_user_define(req, data); | |
524 nm_conn_add_request_item(user->conn, req); | |
525 } | |
526 | |
527 if (req) | |
528 nm_release_request(req); | |
529 | |
530 if (fields) | |
531 nm_free_fields(&fields); | |
532 | |
533 return rc; | |
534 } | |
535 | |
536 NMERR_T | |
8675 | 537 nm_send_message(NMUser * user, NMMessage * message, nm_response_cb callback) |
538 { | |
539 NMERR_T rc = NM_OK; | |
9268 | 540 char *text, *rtfized; |
8675 | 541 NMField *fields = NULL, *tmp = NULL; |
542 NMRequest *req = NULL; | |
543 NMConference *conf; | |
544 NMUserRecord *user_record; | |
545 int count, i; | |
546 | |
547 if (user == NULL || message == NULL) { | |
548 return NMERR_BAD_PARM; | |
549 } | |
550 | |
551 conf = nm_message_get_conference(message); | |
552 if (!nm_conference_is_instantiated(conf)) { | |
553 rc = NMERR_CONFERENCE_NOT_INSTANTIATED; | |
554 } else { | |
555 | |
8933 | 556 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
557 g_strdup(nm_conference_get_guid(conf)), | |
558 NMFIELD_TYPE_UTF8); | |
8675 | 559 |
560 fields = | |
8933 | 561 nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, NMFIELD_METHOD_VALID, 0, |
562 tmp, NMFIELD_TYPE_ARRAY); | |
8675 | 563 tmp = NULL; |
564 | |
565 /* Add RTF and plain text versions of the message */ | |
8933 | 566 text = g_strdup(nm_message_get_text(message)); |
567 | |
568 /* Truncate if necessary */ | |
569 if (strlen(text) > NM_MAX_MESSAGE_SIZE) | |
570 text[NM_MAX_MESSAGE_SIZE] = 0; | |
571 | |
9268 | 572 rtfized = nm_rtfize_text(text); |
573 | |
574 gaim_debug_info("novell", "message text is: %s\n", text); | |
575 gaim_debug_info("novell", "message rtf is: %s\n", rtfized); | |
576 | |
8933 | 577 tmp = nm_field_add_pointer(tmp, NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_METHOD_VALID, 0, |
9268 | 578 rtfized, NMFIELD_TYPE_UTF8); |
8933 | 579 |
580 tmp = nm_field_add_number(tmp, NM_A_UD_MESSAGE_TYPE, 0, NMFIELD_METHOD_VALID, 0, | |
581 0, NMFIELD_TYPE_UDWORD); | |
582 | |
583 tmp = nm_field_add_pointer(tmp, NM_A_SZ_MESSAGE_TEXT, 0, NMFIELD_METHOD_VALID, 0, | |
9268 | 584 text, NMFIELD_TYPE_UTF8); |
8933 | 585 |
586 fields = nm_field_add_pointer(fields, NM_A_FA_MESSAGE, 0, NMFIELD_METHOD_VALID, 0, | |
587 tmp, NMFIELD_TYPE_ARRAY); | |
8675 | 588 tmp = NULL; |
589 | |
590 /* Add participants */ | |
591 count = nm_conference_get_participant_count(conf); | |
592 for (i = 0; i < count; i++) { | |
593 user_record = nm_conference_get_participant(conf, i); | |
594 if (user_record) { | |
595 fields = | |
8933 | 596 nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
597 g_strdup(nm_user_record_get_dn(user_record)), | |
598 NMFIELD_TYPE_DN); | |
8675 | 599 } |
600 } | |
601 | |
602 /* Send the request */ | |
603 rc = nm_send_request(user->conn, "sendmessage", fields, &req); | |
604 if (rc == NM_OK && req) { | |
605 nm_request_set_callback(req, callback); | |
606 nm_conn_add_request_item(user->conn, req); | |
607 } | |
608 } | |
609 | |
610 if (fields) { | |
611 nm_free_fields(&fields); | |
612 } | |
613 | |
614 if (req) { | |
615 nm_release_request(req); | |
616 } | |
617 | |
618 return rc; | |
619 } | |
620 | |
621 NMERR_T | |
622 nm_send_typing(NMUser * user, NMConference * conf, | |
623 gboolean typing, nm_response_cb callback) | |
624 { | |
625 NMERR_T rc = NM_OK; | |
626 char *str = NULL; | |
627 NMField *fields = NULL, *tmp = NULL; | |
628 NMRequest *req = NULL; | |
629 | |
630 if (user == NULL || conf == NULL) { | |
631 return NMERR_BAD_PARM; | |
632 } | |
633 | |
634 if (!nm_conference_is_instantiated(conf)) { | |
635 rc = NMERR_CONFERENCE_NOT_INSTANTIATED; | |
636 } else { | |
637 /* Add the conference GUID */ | |
8933 | 638 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
639 g_strdup(nm_conference_get_guid(conf)), | |
640 NMFIELD_TYPE_UTF8); | |
8675 | 641 |
642 /* Add typing type */ | |
643 str = g_strdup_printf("%d", | |
644 (typing ? NMEVT_USER_TYPING : | |
645 NMEVT_USER_NOT_TYPING)); | |
646 | |
8933 | 647 tmp = nm_field_add_pointer(tmp, NM_A_SZ_TYPE, 0, NMFIELD_METHOD_VALID, 0, |
648 str, NMFIELD_TYPE_UTF8); | |
8675 | 649 |
650 fields = | |
8933 | 651 nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, NMFIELD_METHOD_VALID, 0, |
652 tmp, NMFIELD_TYPE_ARRAY); | |
8675 | 653 tmp = NULL; |
654 | |
655 rc = nm_send_request(user->conn, "sendtyping", fields, &req); | |
656 if (rc == NM_OK && req) { | |
657 nm_request_set_callback(req, callback); | |
658 nm_conn_add_request_item(user->conn, req); | |
659 } | |
660 } | |
661 | |
662 if (req) | |
663 nm_release_request(req); | |
664 | |
665 if (fields) | |
666 nm_free_fields(&fields); | |
667 | |
668 return rc; | |
669 } | |
670 | |
671 NMERR_T | |
672 nm_send_create_contact(NMUser * user, NMFolder * folder, | |
673 NMContact * contact, nm_response_cb callback, | |
674 gpointer data) | |
675 { | |
676 NMERR_T rc = NM_OK; | |
677 NMField *fields = NULL; | |
678 NMRequest *req = NULL; | |
679 const char *name = NULL; | |
680 const char *display_name = NULL; | |
681 | |
682 if (user == NULL || folder == NULL || contact == NULL) { | |
683 return NMERR_BAD_PARM; | |
684 } | |
685 | |
686 /* Add parent ID */ | |
8933 | 687 fields = nm_field_add_pointer(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, |
688 g_strdup_printf("%d", nm_folder_get_id(folder)), | |
689 NMFIELD_TYPE_UTF8); | |
8675 | 690 |
691 /* Check to see if userid is current user and return an error? */ | |
692 | |
693 /* Check to see if contact already exists and return an error? */ | |
694 | |
695 /* Add userid or dn */ | |
696 name = nm_contact_get_dn(contact); | |
697 if (name == NULL) | |
698 return NMERR_BAD_PARM; | |
699 | |
700 if (strstr("=", name)) { | |
8933 | 701 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
702 g_strdup(name), NMFIELD_TYPE_DN); | |
8675 | 703 } else { |
8933 | 704 fields = nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, |
705 g_strdup(name), NMFIELD_TYPE_UTF8); | |
8675 | 706 } |
707 | |
708 /* Add display name */ | |
709 display_name = nm_contact_get_display_name(contact); | |
710 if (display_name) | |
8933 | 711 fields = nm_field_add_pointer(fields, NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_METHOD_VALID, 0, |
712 g_strdup(display_name), NMFIELD_TYPE_UTF8); | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
713 |
8675 | 714 /* Dispatch the request */ |
715 rc = nm_send_request(user->conn, "createcontact", fields, &req); | |
716 if (rc == NM_OK && req) { | |
717 nm_request_set_callback(req, callback); | |
718 nm_request_set_data(req, contact); | |
719 nm_request_set_user_define(req, data); | |
720 nm_conn_add_request_item(user->conn, req); | |
721 } | |
722 | |
723 if (fields) | |
724 nm_free_fields(&fields); | |
725 | |
726 if (req) | |
727 nm_release_request(req); | |
728 | |
729 return rc; | |
730 } | |
731 | |
732 NMERR_T | |
733 nm_send_remove_contact(NMUser * user, NMFolder * folder, | |
734 NMContact * contact, nm_response_cb callback, | |
735 gpointer data) | |
736 { | |
737 NMERR_T rc = NM_OK; | |
738 NMField *fields = NULL; | |
739 NMRequest *req = NULL; | |
740 | |
741 if (user == NULL || folder == NULL || contact == NULL) { | |
742 return NMERR_BAD_PARM; | |
743 } | |
744 | |
745 /* Add parent id */ | |
8933 | 746 fields = nm_field_add_pointer(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, |
747 g_strdup_printf("%d", nm_folder_get_id(folder)), | |
748 NMFIELD_TYPE_UTF8); | |
8675 | 749 |
750 /* Add object id */ | |
8933 | 751 fields = nm_field_add_pointer(fields, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
752 g_strdup_printf("%d", nm_contact_get_id(contact)), | |
753 NMFIELD_TYPE_UTF8); | |
8675 | 754 |
755 /* Dispatch the request */ | |
756 rc = nm_send_request(user->conn, "deletecontact", fields, &req); | |
757 if (rc == NM_OK && req) { | |
758 nm_request_set_callback(req, callback); | |
759 nm_request_set_data(req, contact); | |
760 nm_request_set_user_define(req, data); | |
761 nm_conn_add_request_item(user->conn, req); | |
762 } | |
763 | |
764 if (fields) | |
765 nm_free_fields(&fields); | |
766 | |
767 if (req) | |
768 nm_release_request(req); | |
769 | |
770 return rc; | |
771 } | |
772 | |
773 NMERR_T | |
774 nm_send_create_folder(NMUser * user, const char *name, | |
775 nm_response_cb callback, gpointer data) | |
776 { | |
777 NMERR_T rc = NM_OK; | |
778 NMField *fields = NULL; | |
779 NMRequest *req = NULL; | |
780 | |
781 if (user == NULL || name == NULL) { | |
782 return NMERR_BAD_PARM; | |
783 } | |
784 | |
785 /* Add parent ID */ | |
8933 | 786 fields = nm_field_add_pointer(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, |
787 g_strdup("0"), NMFIELD_TYPE_UTF8); | |
8675 | 788 |
789 /* Add name of the folder to add */ | |
790 fields = | |
8933 | 791 nm_field_add_pointer(fields, NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_METHOD_VALID, 0, |
792 g_strdup(name), NMFIELD_TYPE_UTF8); | |
8675 | 793 |
794 /* Add sequence, for now just put it at the bottom */ | |
795 fields = | |
8933 | 796 nm_field_add_pointer(fields, NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_METHOD_VALID, 0, |
797 g_strdup("-1"), NMFIELD_TYPE_UTF8); | |
8675 | 798 |
799 /* Dispatch the request */ | |
800 rc = nm_send_request(user->conn, "createfolder", fields, &req); | |
801 if (rc == NM_OK && req) { | |
802 nm_request_set_callback(req, callback); | |
803 nm_request_set_data(req, g_strdup(name)); | |
804 nm_request_set_user_define(req, data); | |
805 nm_conn_add_request_item(user->conn, req); | |
806 } | |
807 | |
808 if (fields) | |
809 nm_free_fields(&fields); | |
810 | |
811 if (req) | |
812 nm_release_request(req); | |
813 | |
814 return rc; | |
815 } | |
816 | |
817 NMERR_T | |
818 nm_send_remove_folder(NMUser * user, NMFolder * folder, | |
819 nm_response_cb callback, gpointer data) | |
820 { | |
821 NMERR_T rc = NM_OK; | |
822 NMField *fields = NULL; | |
823 NMRequest *req = NULL; | |
824 | |
825 if (user == NULL || folder == NULL) { | |
826 return NMERR_BAD_PARM; | |
827 } | |
828 | |
829 /* Add the object id */ | |
8933 | 830 fields = nm_field_add_pointer(fields, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
831 g_strdup_printf("%d", nm_folder_get_id(folder)), | |
832 NMFIELD_TYPE_UTF8); | |
8675 | 833 |
834 /* Dispatch the request */ | |
835 rc = nm_send_request(user->conn, "deletecontact", fields, &req); | |
836 if (rc == NM_OK && req) { | |
837 nm_request_set_callback(req, callback); | |
838 nm_request_set_data(req, folder); | |
839 nm_request_set_user_define(req, data); | |
840 nm_conn_add_request_item(user->conn, req); | |
841 } | |
842 | |
843 if (fields) | |
844 nm_free_fields(&fields); | |
845 | |
846 if (req) | |
847 nm_release_request(req); | |
848 | |
849 return rc; | |
850 } | |
851 | |
852 NMERR_T | |
853 nm_send_get_status(NMUser * user, NMUserRecord * user_record, | |
854 nm_response_cb callback, gpointer data) | |
855 { | |
856 NMERR_T rc = NM_OK; | |
857 NMField *fields = NULL; | |
858 NMRequest *req = NULL; | |
859 const char *dn; | |
860 | |
861 if (user == NULL || user_record == NULL) | |
862 return NMERR_BAD_PARM; | |
863 | |
864 /* Add DN to field list */ | |
865 dn = nm_user_record_get_dn(user_record); | |
866 if (dn == NULL) | |
867 return (NMERR_T) -1; | |
868 | |
8933 | 869 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
870 g_strdup(dn), NMFIELD_TYPE_UTF8); | |
8675 | 871 |
872 /* Dispatch the request */ | |
873 rc = nm_send_request(user->conn, "getstatus", fields, &req); | |
874 if (rc == NM_OK && req) { | |
875 nm_request_set_callback(req, callback); | |
876 nm_request_set_data(req, user_record); | |
877 nm_request_set_user_define(req, data); | |
878 nm_conn_add_request_item(user->conn, req); | |
879 } | |
880 | |
881 if (fields) | |
882 nm_free_fields(&fields); | |
883 | |
884 if (req) | |
885 nm_release_request(req); | |
886 | |
887 return rc; | |
888 } | |
889 | |
890 NMERR_T | |
891 nm_send_rename_contact(NMUser * user, NMContact * contact, | |
892 const char *new_name, nm_response_cb callback, | |
893 gpointer data) | |
894 { | |
895 NMERR_T rc = NM_OK; | |
896 NMField *field = NULL, *fields = NULL, *list = NULL; | |
897 NMRequest *req = NULL; | |
898 | |
899 if (user == NULL || contact == NULL || new_name == NULL) | |
900 return NMERR_BAD_PARM; | |
901 | |
902 /* Create field list for current contact */ | |
903 field = nm_contact_to_fields(contact); | |
904 if (field) { | |
905 | |
906 fields = | |
8933 | 907 nm_field_add_pointer(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_DELETE, 0, |
908 field, NMFIELD_TYPE_ARRAY); | |
8675 | 909 field = NULL; |
910 | |
911 /* Update the contacts display name locally */ | |
912 nm_contact_set_display_name(contact, new_name); | |
913 | |
914 /* Create field list for updated contact */ | |
915 field = nm_contact_to_fields(contact); | |
916 if (field) { | |
917 fields = | |
8933 | 918 nm_field_add_pointer(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_ADD, 0, |
919 field, NMFIELD_TYPE_ARRAY); | |
8675 | 920 field = NULL; |
921 | |
922 /* Package it up */ | |
923 list = | |
8933 | 924 nm_field_add_pointer(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, |
925 0, fields, NMFIELD_TYPE_ARRAY); | |
8675 | 926 fields = NULL; |
927 | |
928 rc = nm_send_request(user->conn, "updateitem", list, &req); | |
929 if (rc == NM_OK && req) { | |
930 nm_request_set_callback(req, callback); | |
931 nm_request_set_data(req, contact); | |
932 nm_request_set_user_define(req, data); | |
933 nm_conn_add_request_item(user->conn, req); | |
934 } | |
935 } | |
936 } | |
937 | |
938 if (list) | |
939 nm_free_fields(&list); | |
940 | |
941 return rc; | |
942 } | |
943 | |
944 NMERR_T | |
945 nm_send_rename_folder(NMUser * user, NMFolder * folder, const char *new_name, | |
946 nm_response_cb callback, gpointer data) | |
947 { | |
948 NMERR_T rc = NM_OK; | |
949 NMField *field = NULL, *fields = NULL, *list = NULL; | |
950 NMRequest *req = NULL; | |
951 | |
952 if (user == NULL || folder == NULL || new_name == NULL) | |
953 return NMERR_BAD_PARM; | |
954 | |
955 /* Make sure folder does not already exist!? */ | |
956 if (nm_find_folder(user, new_name)) | |
957 return NMERR_FOLDER_EXISTS; | |
958 | |
959 /* Create field list for current folder */ | |
960 field = nm_folder_to_fields(folder); | |
961 if (field) { | |
962 | |
8933 | 963 fields = nm_field_add_pointer(fields, NM_A_FA_FOLDER, 0, NMFIELD_METHOD_DELETE, 0, |
964 field, NMFIELD_TYPE_ARRAY); | |
8675 | 965 field = NULL; |
966 | |
967 /* Update the folders display name locally */ | |
968 nm_folder_set_name(folder, new_name); | |
969 | |
970 /* Create field list for updated folder */ | |
971 field = nm_folder_to_fields(folder); | |
972 if (field) { | |
8933 | 973 fields = nm_field_add_pointer(fields, NM_A_FA_FOLDER, 0, NMFIELD_METHOD_ADD, 0, |
974 field, NMFIELD_TYPE_ARRAY); | |
8675 | 975 field = NULL; |
976 | |
977 /* Package it up */ | |
8933 | 978 list = nm_field_add_pointer(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, |
979 0, fields, NMFIELD_TYPE_ARRAY); | |
8675 | 980 fields = NULL; |
981 | |
982 rc = nm_send_request(user->conn, "updateitem", list, &req); | |
983 if (rc == NM_OK && req) { | |
984 nm_request_set_callback(req, callback); | |
985 nm_request_set_data(req, folder); | |
986 nm_request_set_user_define(req, data); | |
987 nm_conn_add_request_item(user->conn, req); | |
988 } | |
989 } | |
990 } | |
991 | |
992 if (list) | |
993 nm_free_fields(&list); | |
994 | |
995 return rc; | |
996 } | |
997 | |
998 NMERR_T | |
999 nm_send_move_contact(NMUser * user, NMContact * contact, NMFolder * folder, | |
1000 nm_response_cb callback, gpointer data) | |
1001 { | |
1002 NMERR_T rc = NM_OK; | |
1003 NMField *field = NULL, *fields = NULL, *list = NULL; | |
1004 NMRequest *req = NULL; | |
1005 | |
1006 if (user == NULL || contact == NULL || folder == NULL) | |
1007 return NMERR_BAD_PARM; | |
1008 | |
1009 /* Create field list for the contact */ | |
1010 field = nm_contact_to_fields(contact); | |
1011 if (field) { | |
1012 | |
8933 | 1013 fields = nm_field_add_pointer(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_DELETE, 0, |
1014 field, NMFIELD_TYPE_ARRAY); | |
8675 | 1015 field = NULL; |
1016 | |
1017 /* Wrap the contact up and add it to the request field list */ | |
8933 | 1018 list = nm_field_add_pointer(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, 0, |
1019 fields, NMFIELD_TYPE_ARRAY); | |
8675 | 1020 fields = NULL; |
1021 | |
1022 /* Add sequence number */ | |
8933 | 1023 list = nm_field_add_pointer(list, NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_METHOD_VALID, |
1024 0, g_strdup("-1"), NMFIELD_TYPE_UTF8); | |
8675 | 1025 |
1026 /* Add parent ID */ | |
8933 | 1027 list = nm_field_add_pointer(list, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, |
1028 g_strdup_printf("%d", nm_folder_get_id(folder)), | |
1029 NMFIELD_TYPE_UTF8); | |
8675 | 1030 |
1031 /* Dispatch the request */ | |
1032 rc = nm_send_request(user->conn, "movecontact", list, &req); | |
1033 if (rc == NM_OK && req) { | |
1034 nm_request_set_callback(req, callback); | |
1035 nm_request_set_data(req, contact); | |
1036 nm_request_set_user_define(req, data); | |
1037 nm_conn_add_request_item(user->conn, req); | |
1038 | |
1039 } | |
1040 } | |
1041 | |
1042 if (list) | |
1043 nm_free_fields(&list); | |
1044 | |
1045 return rc; | |
1046 } | |
1047 | |
1048 | |
1049 NMERR_T | |
8933 | 1050 nm_send_create_privacy_item(NMUser *user, const char *who, gboolean allow_list, |
1051 nm_response_cb callback, gpointer data) | |
1052 { | |
1053 NMERR_T rc = NM_OK; | |
1054 NMField *fields = NULL; | |
1055 NMRequest *req = NULL; | |
1056 const char *tag; | |
1057 | |
1058 if (user == NULL || who == NULL) | |
1059 return NMERR_BAD_PARM; | |
1060 | |
1061 if (allow_list) | |
1062 tag = NM_A_SZ_BLOCKING_ALLOW_ITEM; | |
1063 else | |
1064 tag = NM_A_SZ_BLOCKING_DENY_ITEM; | |
1065 | |
1066 fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_ADD, 0, | |
1067 g_strdup(who), NMFIELD_TYPE_UTF8); | |
1068 | |
1069 rc = nm_send_request(user->conn, "createblock", fields, &req); | |
1070 if (rc == NM_OK && req) { | |
1071 nm_request_set_callback(req, callback); | |
1072 nm_request_set_user_define(req, data); | |
1073 nm_conn_add_request_item(user->conn, req); | |
1074 } | |
1075 | |
1076 if (fields) | |
1077 nm_free_fields(&fields); | |
1078 | |
1079 return rc; | |
1080 } | |
1081 | |
1082 NMERR_T | |
1083 nm_send_remove_privacy_item(NMUser *user, const char *dn, gboolean allow_list, | |
1084 nm_response_cb callback, gpointer data) | |
1085 { | |
1086 NMERR_T rc = NM_OK; | |
1087 NMField *fields = NULL; | |
1088 NMRequest *req = NULL; | |
1089 const char *tag; | |
1090 GSList **list_ptr, *node; | |
1091 | |
1092 if (user == NULL || dn == NULL) | |
1093 return NMERR_BAD_PARM; | |
1094 | |
1095 if (allow_list) { | |
1096 tag = NM_A_BLOCKING_ALLOW_LIST; | |
1097 list_ptr = &user->allow_list; | |
1098 } else { | |
1099 tag = NM_A_BLOCKING_DENY_LIST; | |
1100 list_ptr = &user->deny_list; | |
1101 } | |
1102 | |
1103 /* Remove item from the cached list */ | |
1104 if ((node = g_slist_find_custom(*list_ptr, dn, (GCompareFunc)nm_utf8_strcasecmp))) { | |
1105 *list_ptr = g_slist_remove_link(*list_ptr, node); | |
1106 g_slist_free_1(node); | |
1107 } | |
1108 | |
1109 fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_DELETE, 0, | |
1110 g_strdup(dn), NMFIELD_TYPE_DN); | |
1111 | |
1112 rc = nm_send_request(user->conn, "updateblocks", fields, &req); | |
1113 if (rc == NM_OK && req) { | |
1114 nm_request_set_callback(req, callback); | |
1115 nm_request_set_user_define(req, data); | |
1116 nm_conn_add_request_item(user->conn, req); | |
1117 } | |
1118 | |
1119 if (fields) | |
1120 nm_free_fields(&fields); | |
1121 | |
1122 return rc; | |
1123 | |
1124 } | |
1125 | |
1126 NMERR_T | |
1127 nm_send_set_privacy_default(NMUser *user, gboolean default_deny, | |
1128 nm_response_cb callback, gpointer data) | |
1129 { | |
1130 NMERR_T rc = NM_OK; | |
1131 NMField *fields = NULL; | |
1132 NMRequest *req = NULL; | |
1133 | |
1134 if (user == NULL) | |
1135 return NMERR_BAD_PARM; | |
1136 | |
1137 fields = nm_field_add_pointer(fields, NM_A_BLOCKING, 0, NMFIELD_METHOD_UPDATE, 0, | |
1138 (default_deny ? g_strdup("1") : g_strdup("0")), | |
1139 NMFIELD_TYPE_UTF8); | |
1140 | |
1141 rc = nm_send_request(user->conn, "updateblocks", fields, &req); | |
1142 if (rc == NM_OK && req) { | |
1143 nm_request_set_callback(req, callback); | |
1144 nm_request_set_user_define(req, data); | |
1145 nm_conn_add_request_item(user->conn, req); | |
1146 } | |
1147 | |
1148 if (fields) | |
1149 nm_free_fields(&fields); | |
1150 | |
1151 return rc; | |
1152 } | |
1153 | |
1154 NMERR_T | |
9268 | 1155 nm_send_keepalive(NMUser *user, nm_response_cb callback, gpointer data) |
1156 { | |
1157 NMERR_T rc = NM_OK; | |
1158 NMRequest *req = NULL; | |
1159 | |
1160 if (user == NULL) | |
1161 return NMERR_BAD_PARM; | |
1162 | |
1163 rc = nm_send_request(user->conn, "ping", NULL, &req); | |
1164 if (rc == NM_OK && req) { | |
1165 nm_request_set_callback(req, callback); | |
1166 nm_request_set_user_define(req, data); | |
1167 nm_conn_add_request_item(user->conn, req); | |
1168 } | |
1169 | |
1170 return rc; | |
1171 } | |
1172 | |
1173 NMERR_T | |
8675 | 1174 nm_process_new_data(NMUser * user) |
1175 { | |
1176 NMConn *conn; | |
1177 NMERR_T rc = NM_OK; | |
1178 int ret; | |
1179 guint32 val; | |
1180 | |
1181 if (user == NULL) | |
1182 return NMERR_BAD_PARM; | |
1183 | |
1184 conn = user->conn; | |
1185 | |
1186 /* Check to see if this is an event or a response */ | |
1187 ret = nm_tcp_read(conn, (char *) &val, sizeof(val)); | |
1188 if (ret == sizeof(val)) { | |
1189 | |
1190 if (strncmp((char *) &val, "HTTP", strlen("HTTP")) == 0) | |
1191 rc = nm_process_response(user); | |
1192 else | |
8874 | 1193 rc = nm_process_event(user, GUINT32_FROM_LE(val)); |
8675 | 1194 |
1195 } else { | |
1196 rc = NMERR_PROTOCOL; | |
1197 } | |
1198 | |
1199 return rc; | |
1200 } | |
1201 | |
1202 NMConference * | |
1203 nm_find_conversation(NMUser * user, const char *who) | |
1204 { | |
1205 NMConference *conference = NULL; | |
1206 NMConference *tmp; | |
1207 GSList *cnode; | |
1208 | |
1209 if (user && user->conferences) { | |
1210 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
1211 tmp = cnode->data; | |
1212 if (nm_conference_get_participant_count(tmp) == 1) { | |
1213 NMUserRecord *ur = nm_conference_get_participant(tmp, 0); | |
1214 | |
1215 if (ur) { | |
1216 if (nm_utf8_str_equal(nm_user_record_get_dn(ur), who)) { | |
1217 conference = tmp; | |
1218 break; | |
1219 } | |
1220 } | |
1221 } | |
1222 } | |
1223 } | |
1224 | |
1225 return conference; | |
1226 } | |
1227 | |
1228 void | |
1229 nm_conference_list_add(NMUser * user, NMConference * conf) | |
1230 { | |
1231 if (user == NULL || conf == NULL) | |
1232 return; | |
1233 | |
1234 nm_conference_add_ref(conf); | |
1235 user->conferences = g_slist_append(user->conferences, conf); | |
1236 } | |
1237 | |
1238 void | |
1239 nm_conference_list_remove(NMUser * user, NMConference * conf) | |
1240 { | |
1241 if (user == NULL || conf == NULL) | |
1242 return; | |
1243 | |
1244 if (g_slist_find(user->conferences, conf)) { | |
1245 user->conferences = g_slist_remove(user->conferences, conf); | |
1246 nm_release_conference(conf); | |
1247 } | |
1248 } | |
1249 | |
1250 void | |
1251 nm_conference_list_free(NMUser * user) | |
1252 { | |
1253 GSList *cnode; | |
1254 NMConference *conference; | |
1255 | |
1256 if (user == NULL) | |
1257 return; | |
1258 | |
1259 if (user->conferences) { | |
1260 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
1261 conference = cnode->data; | |
1262 cnode->data = NULL; | |
1263 nm_release_conference(conference); | |
1264 } | |
1265 | |
1266 g_slist_free(user->conferences); | |
1267 user->conferences = NULL; | |
1268 } | |
1269 } | |
1270 | |
1271 NMConference * | |
1272 nm_conference_list_find(NMUser * user, const char *guid) | |
1273 { | |
1274 GSList *cnode; | |
1275 NMConference *conference = NULL, *tmp; | |
1276 | |
1277 if (user == NULL || guid == NULL) | |
1278 return NULL; | |
1279 | |
1280 if (user->conferences) { | |
1281 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
1282 tmp = cnode->data; | |
1283 if (nm_are_guids_equal(nm_conference_get_guid(tmp), guid)) { | |
1284 conference = tmp; | |
1285 break; | |
1286 } | |
1287 } | |
1288 } | |
1289 | |
1290 return conference; | |
1291 } | |
1292 | |
1293 gboolean | |
1294 nm_are_guids_equal(const char *guid1, const char *guid2) | |
1295 { | |
1296 if (guid1 == NULL || guid2 == NULL) | |
1297 return FALSE; | |
1298 | |
1299 return (strncmp(guid1, guid2, CONF_GUID_END) == 0); | |
1300 } | |
1301 | |
1302 void | |
1303 nm_user_add_contact(NMUser * user, NMContact * contact) | |
1304 { | |
1305 if (user == NULL || contact == NULL) | |
1306 return; | |
1307 | |
1308 nm_contact_add_ref(contact); | |
1309 | |
1310 g_hash_table_insert(user->contacts, | |
1311 g_utf8_strdown(nm_contact_get_dn(contact), -1), contact); | |
1312 } | |
1313 | |
1314 void | |
1315 nm_user_add_user_record(NMUser * user, NMUserRecord * user_record) | |
1316 { | |
1317 nm_user_record_add_ref(user_record); | |
1318 | |
1319 g_hash_table_insert(user->user_records, | |
1320 g_utf8_strdown(nm_user_record_get_dn(user_record), -1), | |
1321 user_record); | |
1322 | |
1323 g_hash_table_insert(user->display_id_to_dn, | |
1324 g_utf8_strdown(nm_user_record_get_display_id(user_record), | |
1325 -1), | |
1326 g_utf8_strdown(nm_user_record_get_dn(user_record), -1)); | |
1327 | |
1328 } | |
1329 | |
1330 nm_event_cb | |
1331 nm_user_get_event_callback(NMUser * user) | |
1332 { | |
1333 if (user == NULL) | |
1334 return NULL; | |
1335 | |
1336 return user->evt_callback; | |
1337 } | |
1338 | |
1339 NMConn * | |
1340 nm_user_get_conn(NMUser * user) | |
1341 { | |
1342 if (user == NULL) | |
1343 return NULL; | |
1344 | |
1345 return user->conn; | |
1346 } | |
1347 | |
1348 NMERR_T | |
1349 nm_create_contact_list(NMUser * user) | |
1350 { | |
1351 NMERR_T rc = NM_OK; | |
1352 NMField *locate = NULL; | |
1353 | |
1354 if (user == NULL || user->fields == NULL) { | |
1355 return NMERR_BAD_PARM; | |
1356 } | |
1357 | |
1358 /* Create the root folder */ | |
1359 user->root_folder = nm_create_folder(""); | |
1360 | |
1361 /* Find the contact list in the login fields */ | |
1362 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, user->fields); | |
1363 if (locate != NULL) { | |
1364 | |
1365 /* Add the folders and then the contacts */ | |
1366 nm_folder_add_contacts_and_folders(user, user->root_folder, | |
8933 | 1367 (NMField *) (locate->ptr_value)); |
8675 | 1368 |
1369 } | |
1370 | |
1371 return rc; | |
1372 } | |
1373 | |
8933 | 1374 gboolean nm_user_is_privacy_locked(NMUser *user) |
1375 { | |
1376 if (user) { | |
1377 return user->privacy_locked; | |
1378 } | |
1379 | |
1380 return FALSE; | |
1381 } | |
1382 | |
1383 static gboolean | |
1384 _create_privacy_list(NMUser * user, NMRequest *request) | |
1385 { | |
1386 NMField *locate = NULL; | |
1387 GSList *need_details = NULL; | |
1388 | |
1389 /* Are the privacy settings locked */ | |
1390 locate = nm_locate_field(NM_A_LOCKED_ATTR_LIST, user->fields); | |
1391 if (locate && locate->ptr_value) { | |
1392 if (locate->type == NMFIELD_TYPE_UTF8 && | |
1393 (nm_utf8_strcasecmp(locate->ptr_value, NM_A_BLOCKING) == 0)) { | |
1394 user->privacy_locked = TRUE; | |
1395 } else if (locate->type == NMFIELD_TYPE_MV || | |
1396 locate->type == NMFIELD_TYPE_ARRAY) { | |
1397 NMField *tmp = (NMField *)locate->ptr_value; | |
1398 while (tmp && tmp->tag) { | |
1399 if (nm_utf8_strcasecmp(tmp->ptr_value, NM_A_BLOCKING) == 0) { | |
1400 user->privacy_locked = TRUE; | |
1401 break; | |
1402 } | |
1403 tmp++; | |
1404 } | |
1405 } | |
1406 } | |
1407 | |
1408 /* Set default deny flag */ | |
1409 locate = nm_locate_field(NM_A_BLOCKING, user->fields); | |
1410 if (locate && locate->ptr_value) { | |
1411 user->default_deny = atoi((char *)locate->ptr_value); | |
1412 } | |
1413 | |
1414 /* Read internal blocking allow list */ | |
1415 locate = nm_locate_field(NM_A_BLOCKING_ALLOW_LIST, user->fields); | |
1416 if (locate && locate->ptr_value) { | |
1417 | |
1418 if (locate->type == NMFIELD_TYPE_MV) { | |
1419 locate = (NMField *)locate->ptr_value; | |
1420 for (; locate->tag != NULL; locate++) { | |
1421 if (locate->ptr_value) { | |
1422 | |
1423 user->allow_list = g_slist_append(user->allow_list, (char *)locate->ptr_value); | |
1424 | |
1425 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
1426 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
1427 | |
1428 } | |
1429 } | |
1430 } else { | |
1431 | |
1432 user->allow_list = g_slist_append(user->allow_list, (char *)locate->ptr_value); | |
1433 | |
1434 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
1435 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
1436 | |
1437 } | |
1438 } | |
1439 | |
1440 /* Read internal blocking deny list */ | |
1441 locate = nm_locate_field(NM_A_BLOCKING_DENY_LIST, user->fields); | |
1442 if (locate && locate->ptr_value) { | |
1443 | |
1444 if (locate->type == NMFIELD_TYPE_MV) { | |
1445 locate = (NMField *)locate->ptr_value; | |
1446 for (; locate->tag != NULL; locate++) { | |
1447 if (locate->ptr_value) { | |
1448 | |
1449 user->deny_list = g_slist_append(user->deny_list, (char *)locate->ptr_value); | |
1450 | |
1451 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
1452 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
1453 | |
1454 } | |
1455 } | |
1456 } else { | |
1457 | |
1458 user->deny_list = g_slist_append(user->deny_list, (char *)locate->ptr_value); | |
1459 | |
1460 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
1461 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
1462 | |
1463 } | |
1464 } | |
1465 | |
1466 if (need_details) { | |
1467 | |
9268 | 1468 nm_request_add_ref(request); |
8933 | 1469 nm_send_multiple_get_details(user, need_details, |
1470 _handle_multiple_get_details_login_cb, request); | |
1471 | |
1472 return FALSE; | |
1473 } | |
1474 | |
1475 return TRUE; | |
1476 } | |
1477 | |
8675 | 1478 void |
1479 nm_destroy_contact_list(NMUser * user) | |
1480 { | |
1481 if (user == NULL) | |
1482 return; | |
1483 | |
1484 if (user->root_folder) { | |
1485 nm_release_folder(user->root_folder); | |
1486 user->root_folder = NULL; | |
1487 } | |
1488 } | |
1489 | |
1490 NMFolder * | |
1491 nm_get_root_folder(NMUser * user) | |
1492 { | |
1493 if (user == NULL) | |
1494 return NULL; | |
1495 | |
1496 if (user->root_folder == NULL) | |
1497 nm_create_contact_list(user); | |
1498 | |
1499 return user->root_folder; | |
1500 } | |
1501 | |
1502 NMContact * | |
1503 nm_find_contact(NMUser * user, const char *name) | |
1504 { | |
1505 char *str; | |
1506 const char *dn = NULL; | |
1507 NMContact *contact = NULL; | |
1508 | |
1509 if (user == NULL || name == NULL) | |
1510 return NULL; | |
1511 | |
1512 str = g_utf8_strdown(name, -1); | |
1513 if (strstr(str, "=")) { | |
1514 dn = str; | |
1515 } else { | |
1516 /* Assume that we have a display id instead of a dn */ | |
1517 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
1518 } | |
1519 | |
1520 /* Find contact object in reference table */ | |
1521 if (dn) { | |
1522 contact = (NMContact *) g_hash_table_lookup(user->contacts, dn); | |
1523 } | |
1524 | |
1525 g_free(str); | |
1526 return contact; | |
1527 } | |
1528 | |
1529 GList * | |
1530 nm_find_contacts(NMUser * user, const char *dn) | |
1531 { | |
1532 guint32 i, cnt; | |
1533 NMFolder *folder; | |
1534 NMContact *contact; | |
1535 GList *contacts = NULL; | |
1536 | |
1537 if (user == NULL || dn == NULL) | |
1538 return NULL; | |
1539 | |
1540 /* Check for contact at the root */ | |
1541 contact = nm_folder_find_contact(user->root_folder, dn); | |
1542 if (contact) { | |
1543 contacts = g_list_append(contacts, contact); | |
1544 contact = NULL; | |
1545 } | |
1546 | |
1547 /* Check for contact in each subfolder */ | |
1548 cnt = nm_folder_get_subfolder_count(user->root_folder); | |
1549 for (i = 0; i < cnt; i++) { | |
1550 folder = nm_folder_get_subfolder(user->root_folder, i); | |
1551 contact = nm_folder_find_contact(folder, dn); | |
1552 if (contact) { | |
1553 contacts = g_list_append(contacts, contact); | |
1554 contact = NULL; | |
1555 } | |
1556 } | |
1557 | |
1558 return contacts; | |
1559 } | |
1560 | |
1561 NMUserRecord * | |
1562 nm_find_user_record(NMUser * user, const char *name) | |
1563 { | |
1564 char *str = NULL; | |
1565 const char *dn = NULL; | |
1566 NMUserRecord *user_record = NULL; | |
1567 | |
1568 if (user == NULL || name == NULL) | |
1569 return NULL; | |
1570 | |
1571 str = g_utf8_strdown(name, -1); | |
1572 if (strstr(str, "=")) { | |
1573 dn = str; | |
1574 } else { | |
1575 /* Assume that we have a display id instead of a dn */ | |
1576 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
1577 } | |
1578 | |
1579 /* Find user record in reference table */ | |
1580 if (dn) { | |
1581 user_record = | |
1582 (NMUserRecord *) g_hash_table_lookup(user->user_records, dn); | |
1583 } | |
1584 | |
1585 g_free(str); | |
1586 return user_record; | |
1587 } | |
1588 | |
1589 const char * | |
1590 nm_lookup_dn(NMUser * user, const char *display_id) | |
1591 { | |
8744 | 1592 const char *dn; |
1593 char *lower; | |
1594 | |
8675 | 1595 if (user == NULL || display_id == NULL) |
1596 return NULL; | |
1597 | |
8744 | 1598 lower = g_utf8_strdown(display_id, -1); |
1599 dn = g_hash_table_lookup(user->display_id_to_dn, lower); | |
1600 g_free(lower); | |
1601 | |
1602 return dn; | |
8675 | 1603 } |
1604 | |
1605 NMFolder * | |
1606 nm_find_folder(NMUser * user, const char *name) | |
1607 { | |
1608 NMFolder *folder = NULL, *temp; | |
1609 int i, num_folders; | |
1610 const char *tname = NULL; | |
1611 | |
1612 if (user == NULL || name == NULL) | |
1613 return NULL; | |
1614 | |
1615 if (*name == '\0') | |
1616 return user->root_folder; | |
1617 | |
1618 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
1619 for (i = 0; i < num_folders; i++) { | |
1620 temp = nm_folder_get_subfolder(user->root_folder, i); | |
1621 tname = nm_folder_get_name(temp); | |
1622 if (tname && (strcmp(tname, name) == 0)) { | |
1623 folder = temp; | |
1624 break; | |
1625 } | |
1626 } | |
1627 | |
1628 return folder; | |
1629 } | |
1630 | |
1631 NMFolder * | |
1632 nm_find_folder_by_id(NMUser * user, int object_id) | |
1633 { | |
1634 NMFolder *folder = NULL, *temp; | |
1635 int i, num_folders; | |
1636 | |
1637 if (user == NULL) | |
1638 return NULL; | |
1639 | |
1640 if (object_id == 0) | |
1641 return user->root_folder; | |
1642 | |
1643 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
1644 for (i = 0; i < num_folders; i++) { | |
1645 temp = nm_folder_get_subfolder(user->root_folder, i); | |
1646 if (nm_folder_get_id(temp) == object_id) { | |
1647 folder = temp; | |
1648 break; | |
1649 } | |
1650 } | |
1651 | |
1652 return folder; | |
1653 } | |
1654 | |
1655 static void | |
8933 | 1656 _handle_multiple_get_details_login_cb(NMUser * user, NMERR_T ret_code, |
1657 gpointer resp_data, gpointer user_data) | |
1658 { | |
1659 nm_response_cb cb; | |
1660 NMRequest *request = user_data; | |
1661 | |
1662 if (user == NULL || request == NULL) | |
1663 return; | |
1664 | |
1665 if ((cb = nm_request_get_callback(request))) { | |
1666 cb(user, ret_code, nm_request_get_data(request), | |
1667 nm_request_get_user_define(request)); | |
9268 | 1668 nm_release_request(request); |
8933 | 1669 } |
1670 } | |
1671 | |
1672 static void | |
8675 | 1673 _handle_multiple_get_details_joinconf_cb(NMUser * user, NMERR_T ret_code, |
1674 gpointer resp_data, gpointer user_data) | |
1675 { | |
1676 NMRequest *request = user_data; | |
1677 NMUserRecord *user_record = resp_data; | |
1678 NMConference *conference; | |
1679 GSList *list, *node; | |
1680 | |
1681 if (user == NULL || resp_data == NULL || user_data == NULL) | |
1682 return; | |
1683 | |
1684 conference = nm_request_get_data(request); | |
1685 list = nm_request_get_user_define(request); | |
1686 | |
1687 if (ret_code == 0 && conference && list) { | |
1688 | |
1689 /* Add the user to the conference */ | |
1690 nm_conference_add_participant(conference, user_record); | |
1691 | |
1692 /* Find the user in the list and remove it */ | |
1693 for (node = list; node; node = node->next) { | |
1694 if (nm_utf8_str_equal(nm_user_record_get_dn(user_record), | |
1695 (const char *) node->data)) { | |
1696 list = g_slist_remove(list, node->data); | |
1697 nm_request_set_user_define(request, list); | |
1698 g_free(node->data); | |
1699 break; | |
1700 } | |
1701 } | |
1702 | |
1703 /* Time to callback? */ | |
1704 if (g_slist_length(list) == 0) { | |
1705 nm_response_cb cb = nm_request_get_callback(request); | |
1706 | |
1707 if (cb) { | |
1708 cb(user, 0, conference, conference); | |
1709 } | |
1710 g_slist_free(list); | |
1711 nm_release_request(request); | |
1712 } | |
1713 } | |
1714 } | |
1715 | |
1716 NMERR_T | |
1717 nm_call_handler(NMUser * user, NMRequest * request, NMField * fields) | |
1718 { | |
1719 NMERR_T rc = NM_OK, ret_code = NM_OK; | |
1720 NMConference *conf = NULL; | |
1721 NMUserRecord *user_record = NULL; | |
1722 NMField *locate = NULL; | |
1723 NMField *field = NULL; | |
1724 const char *cmd; | |
1725 nm_response_cb cb; | |
1726 gboolean done = TRUE; | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1727 |
8675 | 1728 if (user == NULL || request == NULL || fields == NULL) |
1729 return NMERR_BAD_PARM; | |
1730 | |
1731 /* Get the return code */ | |
1732 field = nm_locate_field(NM_A_SZ_RESULT_CODE, fields); | |
1733 if (field) { | |
8933 | 1734 ret_code = atoi((char *) field->ptr_value); |
8675 | 1735 } else { |
1736 ret_code = NMERR_PROTOCOL; | |
1737 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1738 |
8675 | 1739 cmd = nm_request_get_cmd(request); |
1740 if (ret_code == NM_OK && cmd != NULL) { | |
1741 | |
1742 if (strcmp("login", cmd) == 0) { | |
1743 | |
1744 user->user_record = nm_create_user_record_from_fields(fields); | |
1745 | |
1746 /* Save the users fields */ | |
8744 | 1747 user->fields = nm_copy_field_array(fields); |
8675 | 1748 |
8933 | 1749 nm_create_contact_list(user); |
1750 done = _create_privacy_list(user, request); | |
1751 | |
8675 | 1752 } else if (strcmp("setstatus", cmd) == 0) { |
1753 | |
1754 /* Nothing to do */ | |
1755 | |
1756 } else if (strcmp("createconf", cmd) == 0) { | |
1757 | |
1758 conf = (NMConference *) nm_request_get_data(request); | |
1759 | |
1760 /* get the convo guid */ | |
1761 locate = nm_locate_field(NM_A_FA_CONVERSATION, fields); | |
1762 if (locate) { | |
1763 field = | |
8933 | 1764 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->ptr_value); |
8675 | 1765 if (field) { |
8933 | 1766 nm_conference_set_guid(conf, (char *) field->ptr_value); |
8675 | 1767 } |
1768 } | |
1769 | |
1770 nm_conference_list_add(user, conf); | |
8933 | 1771 nm_release_conference(conf); |
8675 | 1772 |
1773 } else if (strcmp("leaveconf", cmd) == 0) { | |
1774 | |
1775 conf = (NMConference *) nm_request_get_data(request); | |
1776 nm_conference_list_remove(user, conf); | |
1777 | |
1778 } else if (strcmp("joinconf", cmd) == 0) { | |
1779 GSList *list = NULL, *node; | |
1780 | |
1781 conf = nm_request_get_data(request); | |
1782 | |
1783 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, fields); | |
8933 | 1784 if (locate && locate->ptr_value != 0) { |
1785 | |
1786 field = (NMField *) locate->ptr_value; | |
8675 | 1787 while ((field = nm_locate_field(NM_A_SZ_DN, field))) { |
8933 | 1788 if (field && field->ptr_value != 0) { |
8675 | 1789 |
1790 if (nm_utf8_str_equal | |
1791 (nm_user_record_get_dn(user->user_record), | |
8933 | 1792 (const char *) field->ptr_value)) { |
8675 | 1793 field++; |
1794 continue; | |
1795 } | |
1796 | |
1797 user_record = | |
1798 nm_find_user_record(user, | |
8933 | 1799 (const char *) field->ptr_value); |
8675 | 1800 if (user_record == NULL) { |
1801 list = | |
1802 g_slist_append(list, | |
8933 | 1803 g_strdup((char *) field->ptr_value)); |
8675 | 1804 } else { |
1805 nm_conference_add_participant(conf, user_record); | |
1806 } | |
1807 } | |
1808 field++; | |
1809 } | |
1810 | |
1811 if (list != NULL) { | |
1812 | |
1813 done = FALSE; | |
9268 | 1814 nm_request_set_user_define(request, list); |
8675 | 1815 nm_request_add_ref(request); |
1816 for (node = list; node; node = node->next) { | |
1817 | |
1818 nm_send_get_details(user, (const char *) node->data, | |
1819 _handle_multiple_get_details_joinconf_cb, | |
1820 request); | |
1821 } | |
1822 } | |
1823 } | |
1824 | |
1825 } else if (strcmp("getdetails", cmd) == 0) { | |
1826 | |
1827 locate = nm_locate_field(NM_A_FA_RESULTS, fields); | |
8933 | 1828 while (locate && locate->ptr_value != 0) { |
8675 | 1829 |
1830 user_record = nm_create_user_record_from_fields(locate); | |
1831 if (user_record) { | |
1832 NMUserRecord *tmp; | |
1833 | |
1834 tmp = | |
1835 nm_find_user_record(user, | |
1836 nm_user_record_get_dn(user_record)); | |
1837 if (tmp) { | |
1838 | |
1839 /* Update the existing user record */ | |
1840 nm_user_record_copy(tmp, user_record); | |
1841 nm_release_user_record(user_record); | |
1842 user_record = tmp; | |
1843 | |
1844 } else { | |
1845 nm_user_add_user_record(user, user_record); | |
1846 nm_release_user_record(user_record); | |
1847 } | |
1848 | |
1849 /* Response data is new user record */ | |
1850 nm_request_set_data(request, (gpointer) user_record); | |
1851 } | |
1852 | |
8933 | 1853 locate = nm_locate_field(NM_A_FA_RESULTS, locate+1); |
8675 | 1854 } |
1855 | |
1856 } else if (strcmp("createfolder", cmd) == 0) { | |
1857 | |
1858 _update_contact_list(user, fields); | |
1859 | |
1860 } else if (strcmp("createcontact", cmd) == 0) { | |
1861 | |
1862 _update_contact_list(user, fields); | |
1863 | |
1864 locate = | |
8933 | 1865 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->ptr_value); |
8675 | 1866 if (locate) { |
1867 | |
1868 NMContact *new_contact = | |
1869 nm_folder_find_item_by_object_id(user->root_folder, | |
8933 | 1870 atoi((char *)locate->ptr_value)); |
8675 | 1871 |
1872 if (new_contact) { | |
1873 | |
1874 /* Add the contact to our cache */ | |
1875 nm_user_add_contact(user, new_contact); | |
1876 | |
1877 /* Set the contact as the response data */ | |
1878 nm_request_set_data(request, (gpointer) new_contact); | |
1879 | |
1880 } | |
1881 | |
1882 } | |
1883 | |
1884 } else if (strcmp("deletecontact", cmd) == 0) { | |
1885 | |
1886 _update_contact_list(user, fields); | |
1887 | |
1888 } else if (strcmp("movecontact", cmd) == 0) { | |
1889 | |
1890 _update_contact_list(user, fields); | |
1891 | |
1892 } else if (strcmp("getstatus", cmd) == 0) { | |
1893 | |
1894 locate = nm_locate_field(NM_A_SZ_STATUS, fields); | |
1895 if (locate) { | |
1896 nm_user_record_set_status((NMUserRecord *) | |
1897 nm_request_get_data(request), | |
8933 | 1898 atoi((char *) locate->ptr_value), NULL); |
8675 | 1899 } |
1900 | |
1901 } else if (strcmp("updateitem", cmd) == 0) { | |
1902 | |
1903 /* Nothing extra to do here */ | |
1904 | |
8933 | 1905 } else if (strcmp("createblock", cmd) == 0) { |
1906 if ((locate = nm_locate_field(NM_A_BLOCKING_DENY_LIST, fields))) { | |
1907 if (locate->ptr_value) { | |
1908 user->deny_list = g_slist_append(user->deny_list, g_strdup((char *)locate->ptr_value)); | |
1909 } | |
1910 } else if ((locate = nm_locate_field(NM_A_BLOCKING_ALLOW_LIST, fields))) { | |
1911 if (locate->ptr_value) { | |
1912 user->allow_list = g_slist_append(user->allow_list, g_strdup((char *)locate->ptr_value)); | |
1913 } | |
1914 } | |
1915 } else if (strcmp("updateblocks", cmd) == 0) { | |
1916 /* nothing to do here */ | |
8675 | 1917 } else { |
1918 | |
1919 /* Nothing to do, just print debug message */ | |
1920 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
1921 "nm_call_handler(): Unknown request command, %s\n", cmd); | |
1922 | |
1923 } | |
1924 } | |
1925 | |
1926 if (done && (cb = nm_request_get_callback(request))) { | |
1927 | |
1928 cb(user, ret_code, nm_request_get_data(request), | |
1929 nm_request_get_user_define(request)); | |
1930 } | |
1931 | |
1932 return rc; | |
1933 } | |
1934 | |
1935 static NMERR_T | |
1936 nm_process_response(NMUser * user) | |
1937 { | |
1938 NMERR_T rc = NM_OK; | |
1939 NMField *fields = NULL; | |
1940 NMField *field = NULL; | |
1941 NMConn *conn = user->conn; | |
1942 NMRequest *req = NULL; | |
1943 | |
1944 rc = nm_read_header(conn); | |
1945 if (rc == NM_OK) { | |
1946 rc = nm_read_fields(conn, -1, &fields); | |
1947 } | |
1948 | |
1949 if (rc == NM_OK) { | |
1950 field = nm_locate_field(NM_A_SZ_TRANSACTION_ID, fields); | |
8933 | 1951 if (field != NULL && field->ptr_value != 0) { |
1952 req = nm_conn_find_request(conn, atoi((char *) field->ptr_value)); | |
8675 | 1953 if (req != NULL) { |
1954 rc = nm_call_handler(user, req, fields); | |
9268 | 1955 nm_conn_remove_request_item(conn, req); |
8675 | 1956 } |
9268 | 1957 |
8675 | 1958 } |
1959 } | |
1960 | |
8744 | 1961 if (fields) |
1962 nm_free_fields(&fields); | |
1963 | |
8675 | 1964 return rc; |
1965 } | |
1966 | |
1967 /* | |
1968 * Some utility functions...haven't figured out where | |
1969 * they belong yet. | |
1970 */ | |
1971 gint | |
1972 nm_utf8_strcasecmp(gconstpointer str1, gconstpointer str2) | |
1973 { | |
1974 gint rv; | |
1975 char *str1_down = g_utf8_strdown(str1, -1); | |
1976 char *str2_down = g_utf8_strdown(str2, -1); | |
1977 | |
1978 rv = g_utf8_collate(str1_down, str2_down); | |
1979 | |
1980 g_free(str1_down); | |
1981 g_free(str2_down); | |
1982 | |
1983 return rv; | |
1984 } | |
1985 | |
1986 gboolean | |
1987 nm_utf8_str_equal(gconstpointer str1, gconstpointer str2) | |
1988 { | |
1989 return (nm_utf8_strcasecmp(str1, str2) == 0); | |
1990 } | |
1991 | |
1992 char * | |
1993 nm_typed_to_dotted(const char *typed) | |
1994 { | |
1995 unsigned i = 0, j = 0; | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1996 char *dotted; |
8675 | 1997 |
1998 if (typed == NULL) | |
1999 return NULL; | |
2000 | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
2001 dotted = g_new0(char, strlen(typed)); |
8675 | 2002 |
2003 do { | |
2004 | |
2005 /* replace comma with a dot */ | |
2006 if (j != 0) { | |
2007 dotted[j] = '.'; | |
2008 j++; | |
2009 } | |
2010 | |
2011 /* skip the type */ | |
2012 while (typed[i] != '\0' && typed[i] != '=') | |
2013 i++; | |
2014 | |
2015 /* verify that we aren't running off the end */ | |
2016 if (typed[i] == '\0') { | |
2017 dotted[j] = '\0'; | |
2018 break; | |
2019 } | |
2020 | |
2021 i++; | |
2022 | |
2023 /* copy the object name to context */ | |
2024 while (typed[i] != '\0' && typed[i] != ',') { | |
2025 dotted[j] = typed[i]; | |
2026 j++; | |
2027 i++; | |
2028 } | |
2029 | |
2030 } while (typed[i] != '\0'); | |
2031 | |
2032 return dotted; | |
2033 } | |
2034 | |
8933 | 2035 const char * |
2036 nm_error_to_string(NMERR_T err) | |
2037 { | |
2038 static char *unknown_msg = NULL; | |
2039 | |
2040 g_free(unknown_msg); | |
2041 unknown_msg = NULL; | |
2042 | |
2043 switch (err) { | |
2044 | |
2045 case NMERR_BAD_PARM: | |
2046 return _("Required parameters not passed in"); | |
2047 | |
2048 case NMERR_TCP_WRITE: | |
2049 return _("Unable to write to network"); | |
2050 | |
2051 case NMERR_TCP_READ: | |
2052 return _("Unable to read from network"); | |
2053 | |
2054 case NMERR_PROTOCOL: | |
2055 return _("Error communicating with server"); | |
2056 | |
2057 case NMERR_CONFERENCE_NOT_FOUND: | |
2058 case NMERR_CONFERENCE_NOT_FOUND_2: | |
2059 return _("Conference not found"); | |
2060 | |
2061 case NMERR_CONFERENCE_NOT_INSTANTIATED: | |
2062 return _("Conference does not exist"); | |
2063 | |
2064 case NMERR_DUPLICATE_FOLDER: | |
2065 case NMERR_FOLDER_EXISTS: | |
2066 return _("A folder with that name already exists"); | |
2067 | |
2068 case NMERR_NOT_SUPPORTED: | |
2069 return _("Not supported"); | |
2070 | |
2071 case NMERR_PASSWORD_EXPIRED: | |
2072 case NMERR_PASSWORD_EXPIRED_2: | |
2073 return _("Password has expired"); | |
2074 | |
2075 case NMERR_PASSWORD_INVALID: | |
2076 return _("Invalid password"); | |
2077 | |
2078 case NMERR_USER_NOT_FOUND: | |
2079 return _("User not found"); | |
2080 | |
2081 case NMERR_USER_DISABLED: | |
2082 return _("Account has been disabled"); | |
2083 | |
2084 case NMERR_DIRECTORY_FAILURE: | |
2085 return _("The server could not access the directory"); | |
2086 | |
2087 case NMERR_ADMIN_LOCKED: | |
2088 return _("Your system administrator has disabled this operation"); | |
2089 | |
2090 case NMERR_SERVER_BUSY: | |
2091 return _("The server is unavailable; try again later"); | |
2092 | |
2093 case NMERR_DUPLICATE_CONTACT: | |
2094 return _("Cannot add a contact to the same folder twice"); | |
2095 | |
2096 case NMERR_USER_NOT_ALLOWED: | |
2097 return _("Cannot add yourself"); | |
2098 | |
2099 case NMERR_MASTER_ARCHIVE_MISSING: | |
2100 return _("Master archive is misconfigured"); | |
2101 | |
2102 case NMERR_AUTHENTICATION_FAILED: | |
2103 case NMERR_CREDENTIALS_MISSING: | |
2104 return _("Invalid username or password"); | |
2105 | |
2106 case NMERR_HOST_NOT_FOUND: | |
2107 return _("Could not recognize the host of the username you entered"); | |
2108 | |
2109 case NMERR_ACCESS_DENIED: | |
2110 return _("Your account has been disabled because too many invalid passwords were entered"); | |
2111 | |
2112 case NMERR_DUPLICATE_PARTICIPANT: | |
2113 return _("You cannot add the same person twice to a conversation"); | |
2114 | |
2115 case NMERR_TOO_MANY_CONTACTS: | |
2116 case NMERR_TOO_MANY_FOLDERS: | |
2117 return _("You have reached your limit for the number of contacts allowed"); | |
2118 | |
2119 case NMERR_OBJECT_NOT_FOUND: | |
2120 return _("You have entered an invalid username"); | |
2121 | |
2122 case NMERR_DIRECTORY_UPDATE: | |
2123 return _("An error occurred while updating the directory"); | |
2124 | |
2125 case NMERR_SERVER_PROTOCOL: | |
2126 return _("Incompatible protocol version"); | |
2127 | |
2128 case NMERR_USER_BLOCKED: | |
2129 return _("The user has blocked you"); | |
2130 | |
2131 case NMERR_EVAL_CONNECTION_LIMIT: | |
2132 return _("This evaluation version does not allow more than ten users to log in at one time"); | |
2133 | |
2134 case NMERR_CONVERSATION_INVITE: | |
2135 return _("The user is either offline or you are blocked"); | |
2136 | |
2137 default: | |
2138 unknown_msg = g_strdup_printf (_("Unknown error: 0x%X"), err); | |
2139 | |
2140 return unknown_msg; | |
2141 } | |
2142 } | |
2143 | |
8675 | 2144 static void |
2145 _update_contact_list(NMUser * user, NMField * fields) | |
2146 { | |
2147 NMField *list, *cursor, *locate; | |
2148 gint objid1; | |
2149 NMContact *contact; | |
2150 NMFolder *folder; | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
2151 gpointer item; |
8675 | 2152 |
2153 if (user == NULL || fields == NULL) | |
2154 return; | |
2155 | |
2156 /* Is it wrapped in a RESULTS array? */ | |
2157 if (strcmp(fields->tag, NM_A_FA_RESULTS) == 0) { | |
8933 | 2158 list = (NMField *) fields->ptr_value; |
8675 | 2159 } else { |
2160 list = fields; | |
2161 } | |
2162 | |
2163 /* Update the cached contact list */ | |
8933 | 2164 cursor = (NMField *) list->ptr_value; |
8675 | 2165 while (cursor->tag != NULL) { |
2166 if ((g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) || | |
2167 (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0)) { | |
2168 | |
2169 locate = | |
8933 | 2170 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) cursor->ptr_value); |
2171 if (locate != NULL && locate->ptr_value != 0) { | |
2172 objid1 = atoi((char *) locate->ptr_value); | |
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
2173 item = |
8675 | 2174 nm_folder_find_item_by_object_id(user->root_folder, objid1); |
2175 if (item != NULL) { | |
2176 if (cursor->method == NMFIELD_METHOD_ADD) { | |
2177 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
2178 contact = (NMContact *) item; | |
2179 nm_contact_update_list_properties(contact, cursor); | |
2180 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
2181 == 0) { | |
2182 folder = (NMFolder *) item; | |
2183 nm_folder_update_list_properties(folder, cursor); | |
2184 } | |
2185 } else if (cursor->method == NMFIELD_METHOD_DELETE) { | |
2186 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
2187 contact = (NMContact *) item; | |
2188 folder = | |
2189 nm_find_folder_by_id(user, | |
2190 nm_contact_get_parent_id | |
2191 (contact)); | |
2192 if (folder) { | |
2193 nm_folder_remove_contact(folder, contact); | |
2194 } | |
2195 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
2196 == 0) { | |
2197 /* TODO: write nm_folder_remove_folder */ | |
2198 /* ignoring for now, should not be a big deal */ | |
2199 /* folder = (NMFolder *) item;*/ | |
2200 /* nm_folder_remove_folder(user->root_folder, folder);*/ | |
2201 } | |
2202 } | |
2203 } else { | |
2204 | |
2205 if (cursor->method == NMFIELD_METHOD_ADD) { | |
2206 | |
2207 /* Not found, so we need to add it */ | |
2208 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
2209 | |
2210 const char *dn = NULL; | |
2211 | |
2212 locate = | |
2213 nm_locate_field(NM_A_SZ_DN, | |
8933 | 2214 (NMField *) cursor->ptr_value); |
2215 if (locate != NULL && locate->ptr_value != 0) { | |
2216 dn = (const char *) locate->ptr_value; | |
8675 | 2217 if (dn != NULL) { |
2218 contact = | |
2219 nm_create_contact_from_fields(cursor); | |
2220 if (contact) { | |
2221 nm_folder_add_contact_to_list(user-> | |
2222 root_folder, | |
2223 contact); | |
2224 nm_release_contact(contact); | |
2225 } | |
2226 } | |
2227 } | |
2228 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
2229 == 0) { | |
2230 folder = nm_create_folder_from_fields(cursor); | |
2231 nm_folder_add_folder_to_list(user->root_folder, | |
2232 folder); | |
2233 nm_release_folder(folder); | |
2234 } | |
2235 } | |
2236 } | |
2237 } | |
2238 } | |
2239 cursor++; | |
2240 } | |
2241 } | |
9268 | 2242 |
2243 static char * | |
2244 nm_rtfize_text(char *text) | |
2245 { | |
2246 GString *gstr = NULL; | |
2247 unsigned char *pch; | |
2248 char *uni_str = NULL, *rtf = NULL; | |
2249 int bytes; | |
2250 gunichar uc; | |
2251 | |
2252 gstr = g_string_sized_new(strlen(text)*2); | |
2253 pch = text; | |
2254 while (*pch) { | |
2255 if ((*pch) <= 0x7F) { | |
2256 switch (*pch) { | |
2257 case '{': | |
2258 case '}': | |
2259 case '\\': | |
2260 gstr = g_string_append_c(gstr, '\\'); | |
2261 gstr = g_string_append_c(gstr, *pch); | |
2262 break; | |
2263 case '\n': | |
2264 gstr = g_string_append(gstr, "\\par "); | |
2265 break; | |
2266 default: | |
2267 gstr = g_string_append_c(gstr, *pch); | |
2268 break; | |
2269 } | |
2270 pch++; | |
2271 } else { | |
2272 /* convert the utf-8 character to ucs-4 for rtf encoding */ | |
2273 if(*pch <= 0xDF) { | |
2274 uc = ((((gunichar)pch[0]) & 0x001F) << 6) | | |
2275 (((gunichar)pch[1]) & 0x003F); | |
2276 bytes = 2; | |
2277 } else if(*pch <= 0xEF) { | |
2278 uc = ((((gunichar)pch[0]) & 0x000F) << 12) | | |
2279 ((((gunichar)pch[1]) & 0x003F) << 6) | | |
2280 (((gunichar)pch[2]) & 0x003F); | |
2281 bytes = 3; | |
2282 } else if (*pch <= 0xF7) { | |
2283 uc = ((((gunichar)pch[0]) & 0x0007) << 18) | | |
2284 ((((gunichar)pch[1]) & 0x003F) << 12) | | |
2285 ((((gunichar)pch[2]) & 0x003F) << 6) | | |
2286 (((gunichar)pch[3]) & 0x003F); | |
2287 bytes = 4; | |
2288 } else if (*pch <= 0xFB) { | |
2289 uc = ((((gunichar)pch[0]) & 0x0003) << 24) | | |
2290 ((((gunichar)pch[1]) & 0x003F) << 18) | | |
2291 ((((gunichar)pch[2]) & 0x003F) << 12) | | |
2292 ((((gunichar)pch[3]) & 0x003F) << 6) | | |
2293 (((gunichar)pch[4]) & 0x003F); | |
2294 bytes = 5; | |
2295 } else if (*pch <= 0xFD) { | |
2296 uc = ((((gunichar)pch[0]) & 0x0001) << 30) | | |
2297 ((((gunichar)pch[1]) & 0x003F) << 24) | | |
2298 ((((gunichar)pch[2]) & 0x003F) << 18) | | |
2299 ((((gunichar)pch[3]) & 0x003F) << 12) | | |
2300 ((((gunichar)pch[4]) & 0x003F) << 6) | | |
2301 (((gunichar)pch[5]) & 0x003F); | |
2302 bytes = 6; | |
2303 } else { | |
2304 /* should never happen ... bogus utf-8! */ | |
2305 gaim_debug_info("novell", "bogus utf-8 lead byte: 0x%X\n", pch[0]); | |
2306 uc = 0x003F; | |
2307 bytes = 1; | |
2308 } | |
2309 uni_str = g_strdup_printf("\\u%d?", uc); | |
2310 gaim_debug_info("novell", "unicode escaped char %s\n", uni_str); | |
2311 gstr = g_string_append(gstr, uni_str); | |
2312 pch += bytes; | |
2313 g_free(uni_str); | |
2314 } | |
2315 } | |
2316 | |
2317 rtf = g_strdup_printf(RTF_TEMPLATE, gstr->str); | |
2318 g_string_free(gstr, TRUE); | |
2319 return rtf; | |
2320 } |