Mercurial > pidgin
annotate src/protocols/novell/nmuser.c @ 9125:668ffb8fec00
[gaim-migrate @ 9902]
(12:53:05) nosnilmot: LSchiere: not majorly important, but the pref changes
listed in the ChangeLog are out of sync
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sun, 30 May 2004 16:54:40 +0000 |
| parents | 6663ad2386d9 |
| children | 54fb1f466953 |
| 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 */ | |
| 34 #define RTF_TEMPLATE "{\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang1033"\ | |
| 35 "{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 "\ | |
| 36 "Microsoft Sans Serif;}}\n{\\colortbl ;\\red0"\ | |
| 37 "\\green0\\blue0;}\n\\viewkind4\\uc1\\pard\\ltrpar"\ | |
| 38 "\\li50\\ri50\\cf1\\f0\\fs20 %s\\par\n}" | |
| 8933 | 39 #define NM_MAX_MESSAGE_SIZE 2048 |
| 8675 | 40 |
| 41 static NMERR_T nm_process_response(NMUser * user); | |
| 42 | |
| 43 static void _update_contact_list(NMUser * user, NMField * fields); | |
| 44 | |
| 8933 | 45 static void |
| 46 _handle_multiple_get_details_login_cb(NMUser * user, NMERR_T ret_code, | |
| 47 gpointer resp_data, gpointer user_data); | |
| 48 | |
| 8675 | 49 /** |
| 50 * See header for comments on on "public" functions | |
| 51 */ | |
| 52 | |
| 53 NMUser * | |
| 54 nm_initialize_user(const char *name, const char *server_addr, | |
| 55 int port, gpointer data, nm_event_cb event_callback) | |
| 56 { | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
57 NMUser *user; |
| 8675 | 58 if (name == NULL || server_addr == NULL || event_callback == NULL) |
| 59 return NULL; | |
| 60 | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
61 user = g_new0(NMUser, 1); |
| 8675 | 62 |
| 63 user->conn = g_new0(NMConn, 1); | |
| 64 | |
| 65 user->contacts = | |
| 66 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
| 67 g_free, (GDestroyNotify) nm_release_contact); | |
| 68 | |
| 69 user->user_records = | |
| 70 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, g_free, | |
| 71 (GDestroyNotify) nm_release_user_record); | |
| 72 | |
| 73 user->display_id_to_dn = g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
| 74 g_free, g_free); | |
| 75 | |
| 76 user->name = g_strdup(name); | |
| 77 user->conn->addr = g_strdup(server_addr); | |
| 78 user->conn->port = port; | |
| 79 user->evt_callback = event_callback; | |
| 80 user->client_data = data; | |
| 81 | |
| 82 return user; | |
| 83 } | |
| 84 | |
| 85 | |
| 86 void | |
| 87 nm_deinitialize_user(NMUser * user) | |
| 88 { | |
| 89 NMConn *conn = user->conn; | |
| 90 | |
| 91 g_free(conn->addr); | |
| 92 g_free(conn); | |
| 93 | |
| 94 if (user->contacts) { | |
| 95 g_hash_table_destroy(user->contacts); | |
| 96 } | |
| 97 | |
| 98 if (user->user_records) { | |
| 99 g_hash_table_destroy(user->user_records); | |
| 100 } | |
| 101 | |
| 102 if (user->display_id_to_dn) { | |
| 103 g_hash_table_destroy(user->display_id_to_dn); | |
| 104 } | |
| 105 | |
| 106 if (user->name) { | |
| 107 g_free(user->name); | |
| 108 } | |
| 109 | |
| 110 if (user->user_record) { | |
| 111 nm_release_user_record(user->user_record); | |
| 112 } | |
| 113 | |
| 114 nm_conference_list_free(user); | |
| 115 nm_destroy_contact_list(user); | |
| 116 | |
| 117 g_free(user); | |
| 118 } | |
| 119 | |
| 120 NMERR_T | |
| 121 nm_send_login(NMUser * user, const char *pwd, const char *my_addr, | |
| 122 const char *user_agent, nm_response_cb callback, gpointer data) | |
| 123 { | |
| 124 NMERR_T rc = NM_OK; | |
| 125 NMField *fields = NULL; | |
| 126 NMRequest *req = NULL; | |
| 127 | |
| 128 if (user == NULL || pwd == NULL || user_agent == NULL) { | |
| 129 return NMERR_BAD_PARM; | |
| 130 } | |
| 131 | |
| 8933 | 132 fields = nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, |
| 133 g_strdup(user->name), NMFIELD_TYPE_UTF8); | |
| 134 | |
| 135 fields = nm_field_add_pointer(fields, NM_A_SZ_CREDENTIALS, 0, NMFIELD_METHOD_VALID, 0, | |
| 136 g_strdup(pwd), NMFIELD_TYPE_UTF8); | |
| 137 | |
| 138 fields = nm_field_add_pointer(fields, NM_A_SZ_USER_AGENT, 0, NMFIELD_METHOD_VALID, 0, | |
| 139 g_strdup(user_agent), NMFIELD_TYPE_UTF8); | |
| 140 | |
| 141 fields = nm_field_add_number(fields, NM_A_UD_BUILD, 0, NMFIELD_METHOD_VALID, 0, | |
| 142 NM_PROTOCOL_VERSION, NMFIELD_TYPE_UDWORD); | |
| 8675 | 143 if (my_addr) { |
| 8933 | 144 fields = nm_field_add_pointer(fields, NM_A_IP_ADDRESS, 0, NMFIELD_METHOD_VALID, 0, |
| 145 g_strdup(my_addr), NMFIELD_TYPE_UTF8); | |
| 8675 | 146 } |
| 147 | |
| 148 /* Send the login */ | |
| 149 rc = nm_send_request(user->conn, "login", fields, &req); | |
| 150 if (rc == NM_OK && req != NULL) { | |
| 151 nm_request_set_callback(req, callback); | |
| 152 nm_request_set_user_define(req, data); | |
| 153 nm_conn_add_request_item(user->conn, req); | |
| 154 } | |
| 155 | |
| 156 if (fields) { | |
| 157 nm_free_fields(&fields); | |
| 158 } | |
| 159 | |
| 160 if (req) { | |
| 161 nm_release_request(req); | |
| 162 } | |
| 163 | |
| 164 return rc; | |
| 165 } | |
| 166 | |
| 167 NMERR_T | |
| 168 nm_send_set_status(NMUser * user, int status, const char *text, | |
| 169 const char *auto_resp, nm_response_cb callback, gpointer data) | |
| 170 { | |
| 171 NMERR_T rc = NM_OK; | |
| 172 NMField *fields = NULL; | |
| 173 NMRequest *req = NULL; | |
| 174 | |
| 175 if (user == NULL) | |
| 176 return NMERR_BAD_PARM; | |
| 177 | |
| 178 /* Add the status */ | |
| 8933 | 179 fields = nm_field_add_pointer(fields, NM_A_SZ_STATUS, 0, NMFIELD_METHOD_VALID, 0, |
| 180 g_strdup_printf("%d", status), NMFIELD_TYPE_UTF8); | |
| 8675 | 181 |
| 182 /* Add the status text and auto reply text if there is any */ | |
| 183 if (text) { | |
| 8933 | 184 fields = nm_field_add_pointer(fields, NM_A_SZ_STATUS_TEXT, 0, |
| 185 NMFIELD_METHOD_VALID, 0, g_strdup(text), | |
| 186 NMFIELD_TYPE_UTF8); | |
| 8675 | 187 } |
| 188 | |
| 189 if (auto_resp) { | |
| 8933 | 190 fields = nm_field_add_pointer(fields, NM_A_SZ_MESSAGE_BODY, 0, |
| 191 NMFIELD_METHOD_VALID, 0, g_strdup(auto_resp), | |
| 192 NMFIELD_TYPE_UTF8); | |
| 8675 | 193 } |
| 194 | |
| 195 rc = nm_send_request(user->conn, "setstatus", fields, &req); | |
| 196 if (rc == NM_OK && req) { | |
| 197 nm_request_set_callback(req, callback); | |
| 198 nm_request_set_user_define(req, data); | |
| 199 nm_conn_add_request_item(user->conn, req); | |
| 200 } | |
| 201 | |
| 202 if (fields) { | |
| 203 nm_free_fields(&fields); | |
| 204 } | |
| 205 | |
| 206 if (req) { | |
| 207 nm_release_request(req); | |
| 208 } | |
| 209 | |
| 210 return rc; | |
| 211 } | |
| 212 | |
| 213 NMERR_T | |
| 8933 | 214 nm_send_multiple_get_details(NMUser * user, GSList *names, |
| 215 nm_response_cb callback, gpointer data) | |
| 216 { | |
| 217 NMERR_T rc = NM_OK; | |
| 218 NMField *fields = NULL; | |
| 219 NMRequest *req = NULL; | |
| 220 GSList *node; | |
| 221 | |
| 222 if (user == NULL || names == NULL) | |
| 223 return NMERR_BAD_PARM; | |
| 224 | |
| 225 /* Add in DN or display id */ | |
| 226 for (node = names; node; node = node->next) { | |
| 227 fields = nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, | |
| 228 g_strdup(node->data), NMFIELD_TYPE_UTF8); | |
| 229 } | |
| 230 | |
| 231 rc = nm_send_request(user->conn, "getdetails", fields, &req); | |
| 232 if (rc == NM_OK) { | |
| 233 nm_request_set_callback(req, callback); | |
| 234 nm_request_set_user_define(req, data); | |
| 235 nm_conn_add_request_item(user->conn, req); | |
| 236 } | |
| 237 | |
| 238 if (fields) | |
| 239 nm_free_fields(&fields); | |
| 240 | |
| 241 if (req) | |
| 242 nm_release_request(req); | |
| 243 | |
| 244 return rc; | |
| 245 } | |
| 246 | |
| 247 NMERR_T | |
| 8675 | 248 nm_send_get_details(NMUser * user, const char *name, |
| 249 nm_response_cb callback, gpointer data) | |
| 250 { | |
| 251 NMERR_T rc = NM_OK; | |
| 252 NMField *fields = NULL; | |
| 253 NMRequest *req = NULL; | |
| 254 | |
| 255 if (user == NULL || name == NULL) | |
| 256 return NMERR_BAD_PARM; | |
| 257 | |
| 258 /* Add in DN or display id */ | |
| 259 if (strstr("=", name)) { | |
| 8933 | 260 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
| 261 g_strdup(name), NMFIELD_TYPE_DN); | |
| 8675 | 262 } else { |
| 263 | |
| 264 const char *dn = nm_lookup_dn(user, name); | |
| 265 | |
| 266 if (dn) { | |
| 8933 | 267 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, |
| 268 g_strdup(name), NMFIELD_TYPE_DN); | |
| 8675 | 269 } else { |
| 270 fields = | |
| 8933 | 271 nm_field_add_pointer(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, |
| 272 g_strdup(name), NMFIELD_TYPE_UTF8); | |
| 8675 | 273 } |
| 274 | |
| 275 } | |
| 276 | |
| 277 rc = nm_send_request(user->conn, "getdetails", fields, &req); | |
| 278 if (rc == NM_OK) { | |
| 279 nm_request_set_callback(req, callback); | |
| 280 nm_request_set_user_define(req, data); | |
| 281 nm_conn_add_request_item(user->conn, req); | |
| 282 } | |
| 283 | |
| 284 if (fields) | |
| 285 nm_free_fields(&fields); | |
| 286 | |
| 287 if (req) | |
| 288 nm_release_request(req); | |
| 289 | |
| 290 return rc; | |
| 291 } | |
| 292 | |
| 293 NMERR_T | |
| 294 nm_send_create_conference(NMUser * user, NMConference * conference, | |
| 295 nm_response_cb callback, gpointer message) | |
| 296 { | |
| 297 NMERR_T rc = NM_OK; | |
| 298 NMField *fields = NULL; | |
| 299 NMField *tmp = NULL; | |
| 300 NMField *field = NULL; | |
| 301 NMRequest *req = NULL; | |
| 302 int count, i; | |
| 303 | |
| 304 if (user == NULL || conference == NULL) | |
| 305 return NMERR_BAD_PARM; | |
| 306 | |
| 307 /* Add in a blank guid */ | |
| 8933 | 308 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
| 309 g_strdup(BLANK_GUID), NMFIELD_TYPE_UTF8); | |
| 310 | |
| 311 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
| 312 NMFIELD_METHOD_VALID, 0, tmp, | |
| 313 NMFIELD_TYPE_ARRAY); | |
| 8675 | 314 tmp = NULL; |
| 315 | |
| 8933 | 316 |
| 8675 | 317 /* Add participants in */ |
| 318 count = nm_conference_get_participant_count(conference); | |
| 319 for (i = 0; i < count; i++) { | |
| 320 NMUserRecord *user_record = nm_conference_get_participant(conference, i); | |
| 321 | |
| 322 if (user_record) { | |
| 8933 | 323 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, |
| 324 0, NMFIELD_METHOD_VALID, 0, | |
| 325 g_strdup(nm_user_record_get_dn(user_record)), | |
| 326 NMFIELD_TYPE_DN); | |
| 8675 | 327 } |
| 328 } | |
| 329 | |
| 330 /* Add our user in */ | |
| 331 field = nm_locate_field(NM_A_SZ_DN, user->fields); | |
| 332 if (field) { | |
| 8933 | 333 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, |
| 334 0, NMFIELD_METHOD_VALID, 0, | |
| 335 g_strdup((char *) field->ptr_value), | |
| 336 NMFIELD_TYPE_DN); | |
| 8675 | 337 } |
| 338 | |
| 339 rc = nm_send_request(user->conn, "createconf", fields, &req); | |
| 340 if (rc == NM_OK && req) { | |
| 341 nm_request_set_callback(req, callback); | |
| 8933 | 342 nm_conference_add_ref(conference); |
| 8675 | 343 nm_request_set_data(req, conference); |
| 344 nm_request_set_user_define(req, message); | |
| 345 nm_conn_add_request_item(user->conn, req); | |
| 346 } | |
| 347 | |
| 348 if (req) | |
| 349 nm_release_request(req); | |
| 350 | |
| 351 if (fields) | |
| 352 nm_free_fields(&fields); | |
| 353 | |
| 354 return rc; | |
| 355 } | |
| 356 | |
| 357 NMERR_T | |
| 358 nm_send_leave_conference(NMUser * user, NMConference * conference, | |
| 359 nm_response_cb callback, gpointer message) | |
| 360 { | |
| 361 | |
| 362 NMERR_T rc = NM_OK; | |
| 363 NMField *fields = NULL; | |
| 364 NMField *tmp = NULL; | |
| 365 NMRequest *req = NULL; | |
| 366 | |
| 367 if (user == NULL || conference == NULL) | |
| 368 return NMERR_BAD_PARM; | |
| 369 | |
| 370 /* Add in the conference guid */ | |
| 8933 | 371 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
| 372 g_strdup(nm_conference_get_guid(conference)), | |
| 373 NMFIELD_TYPE_UTF8); | |
| 374 | |
| 375 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
| 376 NMFIELD_METHOD_VALID, 0, tmp, | |
| 377 NMFIELD_TYPE_ARRAY); | |
| 8675 | 378 tmp = NULL; |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
379 |
| 8675 | 380 /* Send the request to the server */ |
| 381 rc = nm_send_request(user->conn, "leaveconf", fields, &req); | |
| 382 if (rc == NM_OK && req) { | |
| 383 nm_request_set_callback(req, callback); | |
| 384 nm_request_set_data(req, conference); | |
| 385 nm_request_set_user_define(req, message); | |
| 386 nm_conn_add_request_item(user->conn, req); | |
| 387 } | |
| 388 | |
| 389 if (req) | |
| 390 nm_release_request(req); | |
| 391 | |
| 392 if (fields) | |
| 393 nm_free_fields(&fields); | |
| 394 | |
| 395 return rc; | |
| 396 } | |
| 397 | |
| 398 NMERR_T | |
| 399 nm_send_join_conference(NMUser * user, NMConference * conference, | |
| 400 nm_response_cb callback, gpointer data) | |
| 401 { | |
| 402 NMERR_T rc = NM_OK; | |
| 403 NMField *fields = NULL, *tmp = NULL; | |
| 404 NMRequest *req = NULL; | |
| 405 | |
| 406 if (user == NULL || conference == NULL) | |
| 407 return NMERR_BAD_PARM; | |
| 408 | |
| 409 /* Add in the conference guid */ | |
| 8933 | 410 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
| 411 g_strdup(nm_conference_get_guid(conference)), | |
| 412 NMFIELD_TYPE_UTF8); | |
| 413 | |
| 414 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
| 415 NMFIELD_METHOD_VALID, 0, tmp, | |
| 416 NMFIELD_TYPE_ARRAY); | |
| 8675 | 417 tmp = NULL; |
| 418 | |
| 419 /* Send the request to the server */ | |
| 420 rc = nm_send_request(user->conn, "joinconf", fields, &req); | |
| 421 | |
| 422 /* Set up the request object so that we know what to do | |
| 423 * when we get a response | |
| 424 */ | |
| 425 if (rc == NM_OK && req) { | |
| 426 nm_request_set_callback(req, callback); | |
| 427 nm_request_set_data(req, conference); | |
| 428 nm_request_set_user_define(req, data); | |
| 429 nm_conn_add_request_item(user->conn, req); | |
| 430 } | |
| 431 | |
| 432 if (req) | |
| 433 nm_release_request(req); | |
| 434 | |
| 435 if (fields) | |
| 436 nm_free_fields(&fields); | |
| 437 | |
| 438 return rc; | |
| 439 } | |
| 440 | |
| 441 NMERR_T | |
| 442 nm_send_reject_conference(NMUser * user, NMConference * conference, | |
| 443 nm_response_cb callback, gpointer data) | |
| 444 { | |
| 445 NMERR_T rc = NM_OK; | |
| 446 NMField *fields = NULL; | |
| 447 NMField *tmp = NULL; | |
| 448 NMRequest *req = NULL; | |
| 449 | |
| 450 if (user == NULL || conference == NULL) | |
| 451 return NMERR_BAD_PARM; | |
| 452 | |
| 453 /* Add in the conference guid */ | |
| 8933 | 454 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
| 455 g_strdup(nm_conference_get_guid(conference)), | |
| 456 NMFIELD_TYPE_UTF8); | |
| 457 | |
| 458 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
| 459 NMFIELD_METHOD_VALID, 0, tmp, | |
| 460 NMFIELD_TYPE_ARRAY); | |
| 8675 | 461 tmp = NULL; |
| 462 | |
| 463 /* Send the request to the server */ | |
| 464 rc = nm_send_request(user->conn, "rejectconf", fields, &req); | |
| 465 | |
| 466 /* Set up the request object so that we know what to do | |
| 467 * when we get a response | |
| 468 */ | |
| 469 if (rc == NM_OK && req) { | |
| 470 nm_request_set_callback(req, callback); | |
| 471 nm_request_set_data(req, conference); | |
| 472 nm_request_set_user_define(req, data); | |
| 473 nm_conn_add_request_item(user->conn, req); | |
| 474 } | |
| 475 | |
| 476 if (req) | |
| 477 nm_release_request(req); | |
| 478 | |
| 479 if (fields) | |
| 480 nm_free_fields(&fields); | |
| 481 | |
| 482 return rc; | |
| 483 } | |
| 484 | |
| 485 NMERR_T | |
| 8933 | 486 nm_send_conference_invite(NMUser *user, NMConference *conference, NMUserRecord *user_record, |
| 487 const char *message, nm_response_cb callback, gpointer data) | |
| 488 { | |
| 489 NMERR_T rc = NM_OK; | |
| 490 NMField *fields = NULL; | |
| 491 NMField *tmp = NULL; | |
| 492 NMRequest *req = NULL; | |
| 493 | |
| 494 if (user == NULL || conference == NULL || user_record == NULL) | |
| 495 return NMERR_BAD_PARM; | |
| 496 | |
| 497 /* Add in the conference guid */ | |
| 498 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 499 g_strdup(nm_conference_get_guid(conference)), | |
| 500 NMFIELD_TYPE_UTF8); | |
| 501 | |
| 502 fields = nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, | |
| 503 NMFIELD_METHOD_VALID, 0, tmp, | |
| 504 NMFIELD_TYPE_ARRAY); | |
| 505 tmp = NULL; | |
| 506 | |
| 507 /* Add in DN of user to invite */ | |
| 508 fields = nm_field_add_pointer(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 509 g_strdup(nm_user_record_get_dn(user_record)), | |
| 510 NMFIELD_TYPE_DN); | |
| 511 | |
| 512 /* Add the invite message if there is one */ | |
| 513 if (message) | |
| 514 fields = nm_field_add_pointer(fields, NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_METHOD_VALID, 0, | |
| 515 g_strdup(message), NMFIELD_TYPE_UTF8); | |
| 516 | |
| 517 /* Send the request to the server */ | |
| 518 rc = nm_send_request(user->conn, "sendinvite", fields, &req); | |
| 519 | |
| 520 /* Set up the request object so that we know what to do | |
| 521 * when we get a response | |
| 522 */ | |
| 523 if (rc == NM_OK && req) { | |
| 524 nm_request_set_callback(req, callback); | |
| 525 nm_request_set_data(req, conference); | |
| 526 nm_request_set_user_define(req, data); | |
| 527 nm_conn_add_request_item(user->conn, req); | |
| 528 } | |
| 529 | |
| 530 if (req) | |
| 531 nm_release_request(req); | |
| 532 | |
| 533 if (fields) | |
| 534 nm_free_fields(&fields); | |
| 535 | |
| 536 return rc; | |
| 537 } | |
| 538 | |
| 539 NMERR_T | |
| 8675 | 540 nm_send_message(NMUser * user, NMMessage * message, nm_response_cb callback) |
| 541 { | |
| 542 NMERR_T rc = NM_OK; | |
| 8933 | 543 char *text; |
| 8675 | 544 NMField *fields = NULL, *tmp = NULL; |
| 545 NMRequest *req = NULL; | |
| 546 NMConference *conf; | |
| 547 NMUserRecord *user_record; | |
| 548 int count, i; | |
| 549 | |
| 550 if (user == NULL || message == NULL) { | |
| 551 return NMERR_BAD_PARM; | |
| 552 } | |
| 553 | |
| 554 conf = nm_message_get_conference(message); | |
| 555 if (!nm_conference_is_instantiated(conf)) { | |
| 556 rc = NMERR_CONFERENCE_NOT_INSTANTIATED; | |
| 557 } else { | |
| 558 | |
| 8933 | 559 tmp = nm_field_add_pointer(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, |
| 560 g_strdup(nm_conference_get_guid(conf)), | |
| 561 NMFIELD_TYPE_UTF8); | |
| 8675 | 562 |
| 563 fields = | |
| 8933 | 564 nm_field_add_pointer(fields, NM_A_FA_CONVERSATION, 0, NMFIELD_METHOD_VALID, 0, |
| 565 tmp, NMFIELD_TYPE_ARRAY); | |
| 8675 | 566 tmp = NULL; |
| 567 | |
| 568 /* Add RTF and plain text versions of the message */ | |
| 8933 | 569 text = g_strdup(nm_message_get_text(message)); |
| 570 | |
| 571 /* Truncate if necessary */ | |
| 572 if (strlen(text) > NM_MAX_MESSAGE_SIZE) | |
| 573 text[NM_MAX_MESSAGE_SIZE] = 0; | |
| 574 | |
| 575 tmp = nm_field_add_pointer(tmp, NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_METHOD_VALID, 0, | |
| 576 g_strdup_printf(RTF_TEMPLATE, text), NMFIELD_TYPE_UTF8); | |
| 577 | |
| 578 tmp = nm_field_add_number(tmp, NM_A_UD_MESSAGE_TYPE, 0, NMFIELD_METHOD_VALID, 0, | |
| 579 0, NMFIELD_TYPE_UDWORD); | |
| 580 | |
| 581 tmp = nm_field_add_pointer(tmp, NM_A_SZ_MESSAGE_TEXT, 0, NMFIELD_METHOD_VALID, 0, | |
| 582 g_strdup(text), NMFIELD_TYPE_UTF8); | |
| 583 | |
| 584 fields = nm_field_add_pointer(fields, NM_A_FA_MESSAGE, 0, NMFIELD_METHOD_VALID, 0, | |
| 585 tmp, NMFIELD_TYPE_ARRAY); | |
| 8675 | 586 tmp = NULL; |
| 587 | |
| 8933 | 588 g_free(text); |
| 589 | |
| 8675 | 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 (rc == NM_OK) { | |
| 1120 } | |
| 1121 | |
| 1122 if (fields) | |
| 1123 nm_free_fields(&fields); | |
| 1124 | |
| 1125 return rc; | |
| 1126 | |
| 1127 } | |
| 1128 | |
| 1129 NMERR_T | |
| 1130 nm_send_set_privacy_default(NMUser *user, gboolean default_deny, | |
| 1131 nm_response_cb callback, gpointer data) | |
| 1132 { | |
| 1133 NMERR_T rc = NM_OK; | |
| 1134 NMField *fields = NULL; | |
| 1135 NMRequest *req = NULL; | |
| 1136 | |
| 1137 if (user == NULL) | |
| 1138 return NMERR_BAD_PARM; | |
| 1139 | |
| 1140 fields = nm_field_add_pointer(fields, NM_A_BLOCKING, 0, NMFIELD_METHOD_UPDATE, 0, | |
| 1141 (default_deny ? g_strdup("1") : g_strdup("0")), | |
| 1142 NMFIELD_TYPE_UTF8); | |
| 1143 | |
| 1144 rc = nm_send_request(user->conn, "updateblocks", fields, &req); | |
| 1145 if (rc == NM_OK && req) { | |
| 1146 nm_request_set_callback(req, callback); | |
| 1147 nm_request_set_user_define(req, data); | |
| 1148 nm_conn_add_request_item(user->conn, req); | |
| 1149 } | |
| 1150 | |
| 1151 if (fields) | |
| 1152 nm_free_fields(&fields); | |
| 1153 | |
| 1154 return rc; | |
| 1155 } | |
| 1156 | |
| 1157 NMERR_T | |
| 8675 | 1158 nm_process_new_data(NMUser * user) |
| 1159 { | |
| 1160 NMConn *conn; | |
| 1161 NMERR_T rc = NM_OK; | |
| 1162 int ret; | |
| 1163 guint32 val; | |
| 1164 | |
| 1165 if (user == NULL) | |
| 1166 return NMERR_BAD_PARM; | |
| 1167 | |
| 1168 conn = user->conn; | |
| 1169 | |
| 1170 /* Check to see if this is an event or a response */ | |
| 1171 ret = nm_tcp_read(conn, (char *) &val, sizeof(val)); | |
| 1172 if (ret == sizeof(val)) { | |
| 1173 | |
| 1174 if (strncmp((char *) &val, "HTTP", strlen("HTTP")) == 0) | |
| 1175 rc = nm_process_response(user); | |
| 1176 else | |
| 8874 | 1177 rc = nm_process_event(user, GUINT32_FROM_LE(val)); |
| 8675 | 1178 |
| 1179 } else { | |
| 1180 rc = NMERR_PROTOCOL; | |
| 1181 } | |
| 1182 | |
| 1183 return rc; | |
| 1184 } | |
| 1185 | |
| 1186 NMConference * | |
| 1187 nm_find_conversation(NMUser * user, const char *who) | |
| 1188 { | |
| 1189 NMConference *conference = NULL; | |
| 1190 NMConference *tmp; | |
| 1191 GSList *cnode; | |
| 1192 | |
| 1193 if (user && user->conferences) { | |
| 1194 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1195 tmp = cnode->data; | |
| 1196 if (nm_conference_get_participant_count(tmp) == 1) { | |
| 1197 NMUserRecord *ur = nm_conference_get_participant(tmp, 0); | |
| 1198 | |
| 1199 if (ur) { | |
| 1200 if (nm_utf8_str_equal(nm_user_record_get_dn(ur), who)) { | |
| 1201 conference = tmp; | |
| 1202 break; | |
| 1203 } | |
| 1204 } | |
| 1205 } | |
| 1206 } | |
| 1207 } | |
| 1208 | |
| 1209 return conference; | |
| 1210 } | |
| 1211 | |
| 1212 void | |
| 1213 nm_conference_list_add(NMUser * user, NMConference * conf) | |
| 1214 { | |
| 1215 if (user == NULL || conf == NULL) | |
| 1216 return; | |
| 1217 | |
| 1218 nm_conference_add_ref(conf); | |
| 1219 user->conferences = g_slist_append(user->conferences, conf); | |
| 1220 } | |
| 1221 | |
| 1222 void | |
| 1223 nm_conference_list_remove(NMUser * user, NMConference * conf) | |
| 1224 { | |
| 1225 if (user == NULL || conf == NULL) | |
| 1226 return; | |
| 1227 | |
| 1228 if (g_slist_find(user->conferences, conf)) { | |
| 1229 user->conferences = g_slist_remove(user->conferences, conf); | |
| 1230 nm_release_conference(conf); | |
| 1231 } | |
| 1232 } | |
| 1233 | |
| 1234 void | |
| 1235 nm_conference_list_free(NMUser * user) | |
| 1236 { | |
| 1237 GSList *cnode; | |
| 1238 NMConference *conference; | |
| 1239 | |
| 1240 if (user == NULL) | |
| 1241 return; | |
| 1242 | |
| 1243 if (user->conferences) { | |
| 1244 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1245 conference = cnode->data; | |
| 1246 cnode->data = NULL; | |
| 1247 nm_release_conference(conference); | |
| 1248 } | |
| 1249 | |
| 1250 g_slist_free(user->conferences); | |
| 1251 user->conferences = NULL; | |
| 1252 } | |
| 1253 } | |
| 1254 | |
| 1255 NMConference * | |
| 1256 nm_conference_list_find(NMUser * user, const char *guid) | |
| 1257 { | |
| 1258 GSList *cnode; | |
| 1259 NMConference *conference = NULL, *tmp; | |
| 1260 | |
| 1261 if (user == NULL || guid == NULL) | |
| 1262 return NULL; | |
| 1263 | |
| 1264 if (user->conferences) { | |
| 1265 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1266 tmp = cnode->data; | |
| 1267 if (nm_are_guids_equal(nm_conference_get_guid(tmp), guid)) { | |
| 1268 conference = tmp; | |
| 1269 break; | |
| 1270 } | |
| 1271 } | |
| 1272 } | |
| 1273 | |
| 1274 return conference; | |
| 1275 } | |
| 1276 | |
| 1277 gboolean | |
| 1278 nm_are_guids_equal(const char *guid1, const char *guid2) | |
| 1279 { | |
| 1280 if (guid1 == NULL || guid2 == NULL) | |
| 1281 return FALSE; | |
| 1282 | |
| 1283 return (strncmp(guid1, guid2, CONF_GUID_END) == 0); | |
| 1284 } | |
| 1285 | |
| 1286 void | |
| 1287 nm_user_add_contact(NMUser * user, NMContact * contact) | |
| 1288 { | |
| 1289 if (user == NULL || contact == NULL) | |
| 1290 return; | |
| 1291 | |
| 1292 nm_contact_add_ref(contact); | |
| 1293 | |
| 1294 g_hash_table_insert(user->contacts, | |
| 1295 g_utf8_strdown(nm_contact_get_dn(contact), -1), contact); | |
| 1296 } | |
| 1297 | |
| 1298 void | |
| 1299 nm_user_add_user_record(NMUser * user, NMUserRecord * user_record) | |
| 1300 { | |
| 1301 nm_user_record_add_ref(user_record); | |
| 1302 | |
| 1303 g_hash_table_insert(user->user_records, | |
| 1304 g_utf8_strdown(nm_user_record_get_dn(user_record), -1), | |
| 1305 user_record); | |
| 1306 | |
| 1307 g_hash_table_insert(user->display_id_to_dn, | |
| 1308 g_utf8_strdown(nm_user_record_get_display_id(user_record), | |
| 1309 -1), | |
| 1310 g_utf8_strdown(nm_user_record_get_dn(user_record), -1)); | |
| 1311 | |
| 1312 } | |
| 1313 | |
| 1314 nm_event_cb | |
| 1315 nm_user_get_event_callback(NMUser * user) | |
| 1316 { | |
| 1317 if (user == NULL) | |
| 1318 return NULL; | |
| 1319 | |
| 1320 return user->evt_callback; | |
| 1321 } | |
| 1322 | |
| 1323 NMConn * | |
| 1324 nm_user_get_conn(NMUser * user) | |
| 1325 { | |
| 1326 if (user == NULL) | |
| 1327 return NULL; | |
| 1328 | |
| 1329 return user->conn; | |
| 1330 } | |
| 1331 | |
| 1332 NMERR_T | |
| 1333 nm_create_contact_list(NMUser * user) | |
| 1334 { | |
| 1335 NMERR_T rc = NM_OK; | |
| 1336 NMField *locate = NULL; | |
| 1337 | |
| 1338 if (user == NULL || user->fields == NULL) { | |
| 1339 return NMERR_BAD_PARM; | |
| 1340 } | |
| 1341 | |
| 1342 /* Create the root folder */ | |
| 1343 user->root_folder = nm_create_folder(""); | |
| 1344 | |
| 1345 /* Find the contact list in the login fields */ | |
| 1346 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, user->fields); | |
| 1347 if (locate != NULL) { | |
| 1348 | |
| 1349 /* Add the folders and then the contacts */ | |
| 1350 nm_folder_add_contacts_and_folders(user, user->root_folder, | |
| 8933 | 1351 (NMField *) (locate->ptr_value)); |
| 8675 | 1352 |
| 1353 } | |
| 1354 | |
| 1355 return rc; | |
| 1356 } | |
| 1357 | |
| 8933 | 1358 gboolean nm_user_is_privacy_locked(NMUser *user) |
| 1359 { | |
| 1360 if (user) { | |
| 1361 return user->privacy_locked; | |
| 1362 } | |
| 1363 | |
| 1364 return FALSE; | |
| 1365 } | |
| 1366 | |
| 1367 static gboolean | |
| 1368 _create_privacy_list(NMUser * user, NMRequest *request) | |
| 1369 { | |
| 1370 NMField *locate = NULL; | |
| 1371 GSList *need_details = NULL; | |
| 1372 | |
| 1373 /* Are the privacy settings locked */ | |
| 1374 locate = nm_locate_field(NM_A_LOCKED_ATTR_LIST, user->fields); | |
| 1375 if (locate && locate->ptr_value) { | |
| 1376 if (locate->type == NMFIELD_TYPE_UTF8 && | |
| 1377 (nm_utf8_strcasecmp(locate->ptr_value, NM_A_BLOCKING) == 0)) { | |
| 1378 user->privacy_locked = TRUE; | |
| 1379 } else if (locate->type == NMFIELD_TYPE_MV || | |
| 1380 locate->type == NMFIELD_TYPE_ARRAY) { | |
| 1381 NMField *tmp = (NMField *)locate->ptr_value; | |
| 1382 while (tmp && tmp->tag) { | |
| 1383 if (nm_utf8_strcasecmp(tmp->ptr_value, NM_A_BLOCKING) == 0) { | |
| 1384 user->privacy_locked = TRUE; | |
| 1385 break; | |
| 1386 } | |
| 1387 tmp++; | |
| 1388 } | |
| 1389 } | |
| 1390 } | |
| 1391 | |
| 1392 /* Set default deny flag */ | |
| 1393 locate = nm_locate_field(NM_A_BLOCKING, user->fields); | |
| 1394 if (locate && locate->ptr_value) { | |
| 1395 user->default_deny = atoi((char *)locate->ptr_value); | |
| 1396 } | |
| 1397 | |
| 1398 /* Read internal blocking allow list */ | |
| 1399 locate = nm_locate_field(NM_A_BLOCKING_ALLOW_LIST, user->fields); | |
| 1400 if (locate && locate->ptr_value) { | |
| 1401 | |
| 1402 if (locate->type == NMFIELD_TYPE_MV) { | |
| 1403 locate = (NMField *)locate->ptr_value; | |
| 1404 for (; locate->tag != NULL; locate++) { | |
| 1405 if (locate->ptr_value) { | |
| 1406 | |
| 1407 user->allow_list = g_slist_append(user->allow_list, (char *)locate->ptr_value); | |
| 1408 | |
| 1409 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
| 1410 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
| 1411 | |
| 1412 } | |
| 1413 } | |
| 1414 } else { | |
| 1415 | |
| 1416 user->allow_list = g_slist_append(user->allow_list, (char *)locate->ptr_value); | |
| 1417 | |
| 1418 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
| 1419 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
| 1420 | |
| 1421 } | |
| 1422 } | |
| 1423 | |
| 1424 /* Read internal blocking deny list */ | |
| 1425 locate = nm_locate_field(NM_A_BLOCKING_DENY_LIST, user->fields); | |
| 1426 if (locate && locate->ptr_value) { | |
| 1427 | |
| 1428 if (locate->type == NMFIELD_TYPE_MV) { | |
| 1429 locate = (NMField *)locate->ptr_value; | |
| 1430 for (; locate->tag != NULL; locate++) { | |
| 1431 if (locate->ptr_value) { | |
| 1432 | |
| 1433 user->deny_list = g_slist_append(user->deny_list, (char *)locate->ptr_value); | |
| 1434 | |
| 1435 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
| 1436 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
| 1437 | |
| 1438 } | |
| 1439 } | |
| 1440 } else { | |
| 1441 | |
| 1442 user->deny_list = g_slist_append(user->deny_list, (char *)locate->ptr_value); | |
| 1443 | |
| 1444 if (nm_find_user_record(user, (char *)locate->ptr_value) == NULL) | |
| 1445 need_details = g_slist_append(need_details, (char *)locate->ptr_value); | |
| 1446 | |
| 1447 } | |
| 1448 } | |
| 1449 | |
| 1450 if (need_details) { | |
| 1451 | |
| 1452 nm_send_multiple_get_details(user, need_details, | |
| 1453 _handle_multiple_get_details_login_cb, request); | |
| 1454 | |
| 1455 return FALSE; | |
| 1456 } | |
| 1457 | |
| 1458 return TRUE; | |
| 1459 } | |
| 1460 | |
| 8675 | 1461 void |
| 1462 nm_destroy_contact_list(NMUser * user) | |
| 1463 { | |
| 1464 if (user == NULL) | |
| 1465 return; | |
| 1466 | |
| 1467 if (user->root_folder) { | |
| 1468 nm_release_folder(user->root_folder); | |
| 1469 user->root_folder = NULL; | |
| 1470 } | |
| 1471 } | |
| 1472 | |
| 1473 NMFolder * | |
| 1474 nm_get_root_folder(NMUser * user) | |
| 1475 { | |
| 1476 if (user == NULL) | |
| 1477 return NULL; | |
| 1478 | |
| 1479 if (user->root_folder == NULL) | |
| 1480 nm_create_contact_list(user); | |
| 1481 | |
| 1482 return user->root_folder; | |
| 1483 } | |
| 1484 | |
| 1485 NMContact * | |
| 1486 nm_find_contact(NMUser * user, const char *name) | |
| 1487 { | |
| 1488 char *str; | |
| 1489 const char *dn = NULL; | |
| 1490 NMContact *contact = NULL; | |
| 1491 | |
| 1492 if (user == NULL || name == NULL) | |
| 1493 return NULL; | |
| 1494 | |
| 1495 str = g_utf8_strdown(name, -1); | |
| 1496 if (strstr(str, "=")) { | |
| 1497 dn = str; | |
| 1498 } else { | |
| 1499 /* Assume that we have a display id instead of a dn */ | |
| 1500 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
| 1501 } | |
| 1502 | |
| 1503 /* Find contact object in reference table */ | |
| 1504 if (dn) { | |
| 1505 contact = (NMContact *) g_hash_table_lookup(user->contacts, dn); | |
| 1506 } | |
| 1507 | |
| 1508 g_free(str); | |
| 1509 return contact; | |
| 1510 } | |
| 1511 | |
| 1512 GList * | |
| 1513 nm_find_contacts(NMUser * user, const char *dn) | |
| 1514 { | |
| 1515 guint32 i, cnt; | |
| 1516 NMFolder *folder; | |
| 1517 NMContact *contact; | |
| 1518 GList *contacts = NULL; | |
| 1519 | |
| 1520 if (user == NULL || dn == NULL) | |
| 1521 return NULL; | |
| 1522 | |
| 1523 /* Check for contact at the root */ | |
| 1524 contact = nm_folder_find_contact(user->root_folder, dn); | |
| 1525 if (contact) { | |
| 1526 contacts = g_list_append(contacts, contact); | |
| 1527 contact = NULL; | |
| 1528 } | |
| 1529 | |
| 1530 /* Check for contact in each subfolder */ | |
| 1531 cnt = nm_folder_get_subfolder_count(user->root_folder); | |
| 1532 for (i = 0; i < cnt; i++) { | |
| 1533 folder = nm_folder_get_subfolder(user->root_folder, i); | |
| 1534 contact = nm_folder_find_contact(folder, dn); | |
| 1535 if (contact) { | |
| 1536 contacts = g_list_append(contacts, contact); | |
| 1537 contact = NULL; | |
| 1538 } | |
| 1539 } | |
| 1540 | |
| 1541 return contacts; | |
| 1542 } | |
| 1543 | |
| 1544 NMUserRecord * | |
| 1545 nm_find_user_record(NMUser * user, const char *name) | |
| 1546 { | |
| 1547 char *str = NULL; | |
| 1548 const char *dn = NULL; | |
| 1549 NMUserRecord *user_record = NULL; | |
| 1550 | |
| 1551 if (user == NULL || name == NULL) | |
| 1552 return NULL; | |
| 1553 | |
| 1554 str = g_utf8_strdown(name, -1); | |
| 1555 if (strstr(str, "=")) { | |
| 1556 dn = str; | |
| 1557 } else { | |
| 1558 /* Assume that we have a display id instead of a dn */ | |
| 1559 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
| 1560 } | |
| 1561 | |
| 1562 /* Find user record in reference table */ | |
| 1563 if (dn) { | |
| 1564 user_record = | |
| 1565 (NMUserRecord *) g_hash_table_lookup(user->user_records, dn); | |
| 1566 } | |
| 1567 | |
| 1568 g_free(str); | |
| 1569 return user_record; | |
| 1570 } | |
| 1571 | |
| 1572 const char * | |
| 1573 nm_lookup_dn(NMUser * user, const char *display_id) | |
| 1574 { | |
| 8744 | 1575 const char *dn; |
| 1576 char *lower; | |
| 1577 | |
| 8675 | 1578 if (user == NULL || display_id == NULL) |
| 1579 return NULL; | |
| 1580 | |
| 8744 | 1581 lower = g_utf8_strdown(display_id, -1); |
| 1582 dn = g_hash_table_lookup(user->display_id_to_dn, lower); | |
| 1583 g_free(lower); | |
| 1584 | |
| 1585 return dn; | |
| 8675 | 1586 } |
| 1587 | |
| 1588 NMFolder * | |
| 1589 nm_find_folder(NMUser * user, const char *name) | |
| 1590 { | |
| 1591 NMFolder *folder = NULL, *temp; | |
| 1592 int i, num_folders; | |
| 1593 const char *tname = NULL; | |
| 1594 | |
| 1595 if (user == NULL || name == NULL) | |
| 1596 return NULL; | |
| 1597 | |
| 1598 if (*name == '\0') | |
| 1599 return user->root_folder; | |
| 1600 | |
| 1601 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
| 1602 for (i = 0; i < num_folders; i++) { | |
| 1603 temp = nm_folder_get_subfolder(user->root_folder, i); | |
| 1604 tname = nm_folder_get_name(temp); | |
| 1605 if (tname && (strcmp(tname, name) == 0)) { | |
| 1606 folder = temp; | |
| 1607 break; | |
| 1608 } | |
| 1609 } | |
| 1610 | |
| 1611 return folder; | |
| 1612 } | |
| 1613 | |
| 1614 NMFolder * | |
| 1615 nm_find_folder_by_id(NMUser * user, int object_id) | |
| 1616 { | |
| 1617 NMFolder *folder = NULL, *temp; | |
| 1618 int i, num_folders; | |
| 1619 | |
| 1620 if (user == NULL) | |
| 1621 return NULL; | |
| 1622 | |
| 1623 if (object_id == 0) | |
| 1624 return user->root_folder; | |
| 1625 | |
| 1626 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
| 1627 for (i = 0; i < num_folders; i++) { | |
| 1628 temp = nm_folder_get_subfolder(user->root_folder, i); | |
| 1629 if (nm_folder_get_id(temp) == object_id) { | |
| 1630 folder = temp; | |
| 1631 break; | |
| 1632 } | |
| 1633 } | |
| 1634 | |
| 1635 return folder; | |
| 1636 } | |
| 1637 | |
| 1638 static void | |
| 8933 | 1639 _handle_multiple_get_details_login_cb(NMUser * user, NMERR_T ret_code, |
| 1640 gpointer resp_data, gpointer user_data) | |
| 1641 { | |
| 1642 nm_response_cb cb; | |
| 1643 NMRequest *request = user_data; | |
| 1644 | |
| 1645 if (user == NULL || request == NULL) | |
| 1646 return; | |
| 1647 | |
| 1648 if ((cb = nm_request_get_callback(request))) { | |
| 1649 cb(user, ret_code, nm_request_get_data(request), | |
| 1650 nm_request_get_user_define(request)); | |
| 1651 } | |
| 1652 } | |
| 1653 | |
| 1654 static void | |
| 8675 | 1655 _handle_multiple_get_details_joinconf_cb(NMUser * user, NMERR_T ret_code, |
| 1656 gpointer resp_data, gpointer user_data) | |
| 1657 { | |
| 1658 NMRequest *request = user_data; | |
| 1659 NMUserRecord *user_record = resp_data; | |
| 1660 NMConference *conference; | |
| 1661 GSList *list, *node; | |
| 1662 | |
| 1663 if (user == NULL || resp_data == NULL || user_data == NULL) | |
| 1664 return; | |
| 1665 | |
| 1666 conference = nm_request_get_data(request); | |
| 1667 list = nm_request_get_user_define(request); | |
| 1668 | |
| 1669 if (ret_code == 0 && conference && list) { | |
| 1670 | |
| 1671 /* Add the user to the conference */ | |
| 1672 nm_conference_add_participant(conference, user_record); | |
| 1673 | |
| 1674 /* Find the user in the list and remove it */ | |
| 1675 for (node = list; node; node = node->next) { | |
| 1676 if (nm_utf8_str_equal(nm_user_record_get_dn(user_record), | |
| 1677 (const char *) node->data)) { | |
| 1678 list = g_slist_remove(list, node->data); | |
| 1679 nm_request_set_user_define(request, list); | |
| 1680 g_free(node->data); | |
| 1681 break; | |
| 1682 } | |
| 1683 } | |
| 1684 | |
| 1685 /* Time to callback? */ | |
| 1686 if (g_slist_length(list) == 0) { | |
| 1687 nm_response_cb cb = nm_request_get_callback(request); | |
| 1688 | |
| 1689 if (cb) { | |
| 1690 cb(user, 0, conference, conference); | |
| 1691 } | |
| 1692 g_slist_free(list); | |
| 1693 nm_release_request(request); | |
| 1694 } | |
| 1695 } | |
| 1696 } | |
| 1697 | |
| 1698 NMERR_T | |
| 1699 nm_call_handler(NMUser * user, NMRequest * request, NMField * fields) | |
| 1700 { | |
| 1701 NMERR_T rc = NM_OK, ret_code = NM_OK; | |
| 1702 NMConference *conf = NULL; | |
| 1703 NMUserRecord *user_record = NULL; | |
| 1704 NMField *locate = NULL; | |
| 1705 NMField *field = NULL; | |
| 1706 const char *cmd; | |
| 1707 nm_response_cb cb; | |
| 1708 gboolean done = TRUE; | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1709 |
| 8675 | 1710 if (user == NULL || request == NULL || fields == NULL) |
| 1711 return NMERR_BAD_PARM; | |
| 1712 | |
| 1713 /* Get the return code */ | |
| 1714 field = nm_locate_field(NM_A_SZ_RESULT_CODE, fields); | |
| 1715 if (field) { | |
| 8933 | 1716 ret_code = atoi((char *) field->ptr_value); |
| 8675 | 1717 } else { |
| 1718 ret_code = NMERR_PROTOCOL; | |
| 1719 } | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1720 |
| 8675 | 1721 cmd = nm_request_get_cmd(request); |
| 1722 if (ret_code == NM_OK && cmd != NULL) { | |
| 1723 | |
| 1724 if (strcmp("login", cmd) == 0) { | |
| 1725 | |
| 1726 user->user_record = nm_create_user_record_from_fields(fields); | |
| 1727 | |
| 1728 /* Save the users fields */ | |
| 8744 | 1729 user->fields = nm_copy_field_array(fields); |
| 8675 | 1730 |
| 8933 | 1731 nm_create_contact_list(user); |
| 1732 done = _create_privacy_list(user, request); | |
| 1733 | |
| 8675 | 1734 } else if (strcmp("setstatus", cmd) == 0) { |
| 1735 | |
| 1736 /* Nothing to do */ | |
| 1737 | |
| 1738 } else if (strcmp("createconf", cmd) == 0) { | |
| 1739 | |
| 1740 conf = (NMConference *) nm_request_get_data(request); | |
| 1741 | |
| 1742 /* get the convo guid */ | |
| 1743 locate = nm_locate_field(NM_A_FA_CONVERSATION, fields); | |
| 1744 if (locate) { | |
| 1745 field = | |
| 8933 | 1746 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->ptr_value); |
| 8675 | 1747 if (field) { |
| 8933 | 1748 nm_conference_set_guid(conf, (char *) field->ptr_value); |
| 8675 | 1749 } |
| 1750 } | |
| 1751 | |
| 1752 nm_conference_list_add(user, conf); | |
| 8933 | 1753 nm_release_conference(conf); |
| 8675 | 1754 |
| 1755 } else if (strcmp("leaveconf", cmd) == 0) { | |
| 1756 | |
| 1757 conf = (NMConference *) nm_request_get_data(request); | |
| 1758 nm_conference_list_remove(user, conf); | |
| 1759 | |
| 1760 } else if (strcmp("joinconf", cmd) == 0) { | |
| 1761 GSList *list = NULL, *node; | |
| 1762 | |
| 1763 conf = nm_request_get_data(request); | |
| 1764 | |
| 1765 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, fields); | |
| 8933 | 1766 if (locate && locate->ptr_value != 0) { |
| 1767 | |
| 1768 field = (NMField *) locate->ptr_value; | |
| 8675 | 1769 while ((field = nm_locate_field(NM_A_SZ_DN, field))) { |
| 8933 | 1770 if (field && field->ptr_value != 0) { |
| 8675 | 1771 |
| 1772 if (nm_utf8_str_equal | |
| 1773 (nm_user_record_get_dn(user->user_record), | |
| 8933 | 1774 (const char *) field->ptr_value)) { |
| 8675 | 1775 field++; |
| 1776 continue; | |
| 1777 } | |
| 1778 | |
| 1779 user_record = | |
| 1780 nm_find_user_record(user, | |
| 8933 | 1781 (const char *) field->ptr_value); |
| 8675 | 1782 if (user_record == NULL) { |
| 1783 list = | |
| 1784 g_slist_append(list, | |
| 8933 | 1785 g_strdup((char *) field->ptr_value)); |
| 8675 | 1786 } else { |
| 1787 nm_conference_add_participant(conf, user_record); | |
| 1788 } | |
| 1789 } | |
| 1790 field++; | |
| 1791 } | |
| 1792 | |
| 1793 if (list != NULL) { | |
| 1794 | |
| 1795 done = FALSE; | |
| 1796 nm_request_add_ref(request); | |
| 1797 nm_request_set_user_define(request, list); | |
| 1798 for (node = list; node; node = node->next) { | |
| 1799 | |
| 1800 nm_send_get_details(user, (const char *) node->data, | |
| 1801 _handle_multiple_get_details_joinconf_cb, | |
| 1802 request); | |
| 1803 } | |
| 1804 } | |
| 1805 } | |
| 1806 | |
| 1807 } else if (strcmp("getdetails", cmd) == 0) { | |
| 1808 | |
| 1809 locate = nm_locate_field(NM_A_FA_RESULTS, fields); | |
| 8933 | 1810 while (locate && locate->ptr_value != 0) { |
| 8675 | 1811 |
| 1812 user_record = nm_create_user_record_from_fields(locate); | |
| 1813 if (user_record) { | |
| 1814 NMUserRecord *tmp; | |
| 1815 | |
| 1816 tmp = | |
| 1817 nm_find_user_record(user, | |
| 1818 nm_user_record_get_dn(user_record)); | |
| 1819 if (tmp) { | |
| 1820 | |
| 1821 /* Update the existing user record */ | |
| 1822 nm_user_record_copy(tmp, user_record); | |
| 1823 nm_release_user_record(user_record); | |
| 1824 user_record = tmp; | |
| 1825 | |
| 1826 } else { | |
| 1827 nm_user_add_user_record(user, user_record); | |
| 1828 nm_release_user_record(user_record); | |
| 1829 } | |
| 1830 | |
| 1831 /* Response data is new user record */ | |
| 1832 nm_request_set_data(request, (gpointer) user_record); | |
| 1833 } | |
| 1834 | |
| 8933 | 1835 locate = nm_locate_field(NM_A_FA_RESULTS, locate+1); |
| 8675 | 1836 } |
| 1837 | |
| 1838 } else if (strcmp("createfolder", cmd) == 0) { | |
| 1839 | |
| 1840 _update_contact_list(user, fields); | |
| 1841 | |
| 1842 } else if (strcmp("createcontact", cmd) == 0) { | |
| 1843 | |
| 1844 _update_contact_list(user, fields); | |
| 1845 | |
| 1846 locate = | |
| 8933 | 1847 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->ptr_value); |
| 8675 | 1848 if (locate) { |
| 1849 | |
| 1850 NMContact *new_contact = | |
| 1851 nm_folder_find_item_by_object_id(user->root_folder, | |
| 8933 | 1852 atoi((char *)locate->ptr_value)); |
| 8675 | 1853 |
| 1854 if (new_contact) { | |
| 1855 | |
| 1856 /* Add the contact to our cache */ | |
| 1857 nm_user_add_contact(user, new_contact); | |
| 1858 | |
| 1859 /* Set the contact as the response data */ | |
| 1860 nm_request_set_data(request, (gpointer) new_contact); | |
| 1861 | |
| 1862 } | |
| 1863 | |
| 1864 } | |
| 1865 | |
| 1866 } else if (strcmp("deletecontact", cmd) == 0) { | |
| 1867 | |
| 1868 _update_contact_list(user, fields); | |
| 1869 | |
| 1870 } else if (strcmp("movecontact", cmd) == 0) { | |
| 1871 | |
| 1872 _update_contact_list(user, fields); | |
| 1873 | |
| 1874 } else if (strcmp("getstatus", cmd) == 0) { | |
| 1875 | |
| 1876 locate = nm_locate_field(NM_A_SZ_STATUS, fields); | |
| 1877 if (locate) { | |
| 1878 nm_user_record_set_status((NMUserRecord *) | |
| 1879 nm_request_get_data(request), | |
| 8933 | 1880 atoi((char *) locate->ptr_value), NULL); |
| 8675 | 1881 } |
| 1882 | |
| 1883 } else if (strcmp("updateitem", cmd) == 0) { | |
| 1884 | |
| 1885 /* Nothing extra to do here */ | |
| 1886 | |
| 8933 | 1887 } else if (strcmp("createblock", cmd) == 0) { |
| 1888 if ((locate = nm_locate_field(NM_A_BLOCKING_DENY_LIST, fields))) { | |
| 1889 if (locate->ptr_value) { | |
| 1890 user->deny_list = g_slist_append(user->deny_list, g_strdup((char *)locate->ptr_value)); | |
| 1891 } | |
| 1892 } else if ((locate = nm_locate_field(NM_A_BLOCKING_ALLOW_LIST, fields))) { | |
| 1893 if (locate->ptr_value) { | |
| 1894 user->allow_list = g_slist_append(user->allow_list, g_strdup((char *)locate->ptr_value)); | |
| 1895 } | |
| 1896 } | |
| 1897 } else if (strcmp("updateblocks", cmd) == 0) { | |
| 1898 /* nothing to do here */ | |
| 8675 | 1899 } else { |
| 1900 | |
| 1901 /* Nothing to do, just print debug message */ | |
| 1902 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 1903 "nm_call_handler(): Unknown request command, %s\n", cmd); | |
| 1904 | |
| 1905 } | |
| 1906 } | |
| 1907 | |
| 1908 if (done && (cb = nm_request_get_callback(request))) { | |
| 1909 | |
| 1910 cb(user, ret_code, nm_request_get_data(request), | |
| 1911 nm_request_get_user_define(request)); | |
| 1912 | |
| 1913 } | |
| 1914 | |
| 1915 return rc; | |
| 1916 } | |
| 1917 | |
| 1918 static NMERR_T | |
| 1919 nm_process_response(NMUser * user) | |
| 1920 { | |
| 1921 NMERR_T rc = NM_OK; | |
| 1922 NMField *fields = NULL; | |
| 1923 NMField *field = NULL; | |
| 1924 NMConn *conn = user->conn; | |
| 1925 NMRequest *req = NULL; | |
| 1926 | |
| 1927 rc = nm_read_header(conn); | |
| 1928 if (rc == NM_OK) { | |
| 1929 rc = nm_read_fields(conn, -1, &fields); | |
| 1930 } | |
| 1931 | |
| 1932 if (rc == NM_OK) { | |
| 1933 field = nm_locate_field(NM_A_SZ_TRANSACTION_ID, fields); | |
| 8933 | 1934 if (field != NULL && field->ptr_value != 0) { |
| 1935 req = nm_conn_find_request(conn, atoi((char *) field->ptr_value)); | |
| 8675 | 1936 if (req != NULL) { |
| 1937 rc = nm_call_handler(user, req, fields); | |
| 1938 } | |
| 1939 } | |
| 1940 } | |
| 1941 | |
| 8744 | 1942 if (fields) |
| 1943 nm_free_fields(&fields); | |
| 1944 | |
| 8675 | 1945 return rc; |
| 1946 } | |
| 1947 | |
| 1948 /* | |
| 1949 * Some utility functions...haven't figured out where | |
| 1950 * they belong yet. | |
| 1951 */ | |
| 1952 gint | |
| 1953 nm_utf8_strcasecmp(gconstpointer str1, gconstpointer str2) | |
| 1954 { | |
| 1955 gint rv; | |
| 1956 char *str1_down = g_utf8_strdown(str1, -1); | |
| 1957 char *str2_down = g_utf8_strdown(str2, -1); | |
| 1958 | |
| 1959 rv = g_utf8_collate(str1_down, str2_down); | |
| 1960 | |
| 1961 g_free(str1_down); | |
| 1962 g_free(str2_down); | |
| 1963 | |
| 1964 return rv; | |
| 1965 } | |
| 1966 | |
| 1967 gboolean | |
| 1968 nm_utf8_str_equal(gconstpointer str1, gconstpointer str2) | |
| 1969 { | |
| 1970 return (nm_utf8_strcasecmp(str1, str2) == 0); | |
| 1971 } | |
| 1972 | |
| 1973 char * | |
| 1974 nm_typed_to_dotted(const char *typed) | |
| 1975 { | |
| 1976 unsigned i = 0, j = 0; | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1977 char *dotted; |
| 8675 | 1978 |
| 1979 if (typed == NULL) | |
| 1980 return NULL; | |
| 1981 | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1982 dotted = g_new0(char, strlen(typed)); |
| 8675 | 1983 |
| 1984 do { | |
| 1985 | |
| 1986 /* replace comma with a dot */ | |
| 1987 if (j != 0) { | |
| 1988 dotted[j] = '.'; | |
| 1989 j++; | |
| 1990 } | |
| 1991 | |
| 1992 /* skip the type */ | |
| 1993 while (typed[i] != '\0' && typed[i] != '=') | |
| 1994 i++; | |
| 1995 | |
| 1996 /* verify that we aren't running off the end */ | |
| 1997 if (typed[i] == '\0') { | |
| 1998 dotted[j] = '\0'; | |
| 1999 break; | |
| 2000 } | |
| 2001 | |
| 2002 i++; | |
| 2003 | |
| 2004 /* copy the object name to context */ | |
| 2005 while (typed[i] != '\0' && typed[i] != ',') { | |
| 2006 dotted[j] = typed[i]; | |
| 2007 j++; | |
| 2008 i++; | |
| 2009 } | |
| 2010 | |
| 2011 } while (typed[i] != '\0'); | |
| 2012 | |
| 2013 return dotted; | |
| 2014 } | |
| 2015 | |
| 8933 | 2016 const char * |
| 2017 nm_error_to_string(NMERR_T err) | |
| 2018 { | |
| 2019 static char *unknown_msg = NULL; | |
| 2020 | |
| 2021 g_free(unknown_msg); | |
| 2022 unknown_msg = NULL; | |
| 2023 | |
| 2024 switch (err) { | |
| 2025 | |
| 2026 case NMERR_BAD_PARM: | |
| 2027 return _("Required parameters not passed in"); | |
| 2028 | |
| 2029 case NMERR_TCP_WRITE: | |
| 2030 return _("Unable to write to network"); | |
| 2031 | |
| 2032 case NMERR_TCP_READ: | |
| 2033 return _("Unable to read from network"); | |
| 2034 | |
| 2035 case NMERR_PROTOCOL: | |
| 2036 return _("Error communicating with server"); | |
| 2037 | |
| 2038 case NMERR_CONFERENCE_NOT_FOUND: | |
| 2039 case NMERR_CONFERENCE_NOT_FOUND_2: | |
| 2040 return _("Conference not found"); | |
| 2041 | |
| 2042 case NMERR_CONFERENCE_NOT_INSTANTIATED: | |
| 2043 return _("Conference does not exist"); | |
| 2044 | |
| 2045 case NMERR_DUPLICATE_FOLDER: | |
| 2046 case NMERR_FOLDER_EXISTS: | |
| 2047 return _("A folder with that name already exists"); | |
| 2048 | |
| 2049 case NMERR_NOT_SUPPORTED: | |
| 2050 return _("Not supported"); | |
| 2051 | |
| 2052 case NMERR_PASSWORD_EXPIRED: | |
| 2053 case NMERR_PASSWORD_EXPIRED_2: | |
| 2054 return _("Password has expired"); | |
| 2055 | |
| 2056 case NMERR_PASSWORD_INVALID: | |
| 2057 return _("Invalid password"); | |
| 2058 | |
| 2059 case NMERR_USER_NOT_FOUND: | |
| 2060 return _("User not found"); | |
| 2061 | |
| 2062 case NMERR_USER_DISABLED: | |
| 2063 return _("Account has been disabled"); | |
| 2064 | |
| 2065 case NMERR_DIRECTORY_FAILURE: | |
| 2066 return _("The server could not access the directory"); | |
| 2067 | |
| 2068 case NMERR_ADMIN_LOCKED: | |
| 2069 return _("Your system administrator has disabled this operation"); | |
| 2070 | |
| 2071 case NMERR_SERVER_BUSY: | |
| 2072 return _("The server is unavailable; try again later"); | |
| 2073 | |
| 2074 case NMERR_DUPLICATE_CONTACT: | |
| 2075 return _("Cannot add a contact to the same folder twice"); | |
| 2076 | |
| 2077 case NMERR_USER_NOT_ALLOWED: | |
| 2078 return _("Cannot add yourself"); | |
| 2079 | |
| 2080 case NMERR_MASTER_ARCHIVE_MISSING: | |
| 2081 return _("Master archive is misconfigured"); | |
| 2082 | |
| 2083 case NMERR_AUTHENTICATION_FAILED: | |
| 2084 case NMERR_CREDENTIALS_MISSING: | |
| 2085 return _("Invalid username or password"); | |
| 2086 | |
| 2087 case NMERR_HOST_NOT_FOUND: | |
| 2088 return _("Could not recognize the host of the username you entered"); | |
| 2089 | |
| 2090 case NMERR_ACCESS_DENIED: | |
| 2091 return _("Your account has been disabled because too many invalid passwords were entered"); | |
| 2092 | |
| 2093 case NMERR_DUPLICATE_PARTICIPANT: | |
| 2094 return _("You cannot add the same person twice to a conversation"); | |
| 2095 | |
| 2096 case NMERR_TOO_MANY_CONTACTS: | |
| 2097 case NMERR_TOO_MANY_FOLDERS: | |
| 2098 return _("You have reached your limit for the number of contacts allowed"); | |
| 2099 | |
| 2100 case NMERR_OBJECT_NOT_FOUND: | |
| 2101 return _("You have entered an invalid username"); | |
| 2102 | |
| 2103 case NMERR_DIRECTORY_UPDATE: | |
| 2104 return _("An error occurred while updating the directory"); | |
| 2105 | |
| 2106 case NMERR_SERVER_PROTOCOL: | |
| 2107 return _("Incompatible protocol version"); | |
| 2108 | |
| 2109 case NMERR_USER_BLOCKED: | |
| 2110 return _("The user has blocked you"); | |
| 2111 | |
| 2112 case NMERR_EVAL_CONNECTION_LIMIT: | |
| 2113 return _("This evaluation version does not allow more than ten users to log in at one time"); | |
| 2114 | |
| 2115 case NMERR_CONVERSATION_INVITE: | |
| 2116 return _("The user is either offline or you are blocked"); | |
| 2117 | |
| 2118 default: | |
| 2119 unknown_msg = g_strdup_printf (_("Unknown error: 0x%X"), err); | |
| 2120 | |
| 2121 return unknown_msg; | |
| 2122 } | |
| 2123 } | |
| 2124 | |
| 8675 | 2125 static void |
| 2126 _update_contact_list(NMUser * user, NMField * fields) | |
| 2127 { | |
| 2128 NMField *list, *cursor, *locate; | |
| 2129 gint objid1; | |
| 2130 NMContact *contact; | |
| 2131 NMFolder *folder; | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
2132 gpointer item; |
| 8675 | 2133 |
| 2134 if (user == NULL || fields == NULL) | |
| 2135 return; | |
| 2136 | |
| 2137 /* Is it wrapped in a RESULTS array? */ | |
| 2138 if (strcmp(fields->tag, NM_A_FA_RESULTS) == 0) { | |
| 8933 | 2139 list = (NMField *) fields->ptr_value; |
| 8675 | 2140 } else { |
| 2141 list = fields; | |
| 2142 } | |
| 2143 | |
| 2144 /* Update the cached contact list */ | |
| 8933 | 2145 cursor = (NMField *) list->ptr_value; |
| 8675 | 2146 while (cursor->tag != NULL) { |
| 2147 if ((g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) || | |
| 2148 (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0)) { | |
| 2149 | |
| 2150 locate = | |
| 8933 | 2151 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) cursor->ptr_value); |
| 2152 if (locate != NULL && locate->ptr_value != 0) { | |
| 2153 objid1 = atoi((char *) locate->ptr_value); | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
2154 item = |
| 8675 | 2155 nm_folder_find_item_by_object_id(user->root_folder, objid1); |
| 2156 if (item != NULL) { | |
| 2157 if (cursor->method == NMFIELD_METHOD_ADD) { | |
| 2158 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 2159 contact = (NMContact *) item; | |
| 2160 nm_contact_update_list_properties(contact, cursor); | |
| 2161 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 2162 == 0) { | |
| 2163 folder = (NMFolder *) item; | |
| 2164 nm_folder_update_list_properties(folder, cursor); | |
| 2165 } | |
| 2166 } else if (cursor->method == NMFIELD_METHOD_DELETE) { | |
| 2167 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 2168 contact = (NMContact *) item; | |
| 2169 folder = | |
| 2170 nm_find_folder_by_id(user, | |
| 2171 nm_contact_get_parent_id | |
| 2172 (contact)); | |
| 2173 if (folder) { | |
| 2174 nm_folder_remove_contact(folder, contact); | |
| 2175 } | |
| 2176 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 2177 == 0) { | |
| 2178 /* TODO: write nm_folder_remove_folder */ | |
| 2179 /* ignoring for now, should not be a big deal */ | |
| 2180 /* folder = (NMFolder *) item;*/ | |
| 2181 /* nm_folder_remove_folder(user->root_folder, folder);*/ | |
| 2182 } | |
| 2183 } | |
| 2184 } else { | |
| 2185 | |
| 2186 if (cursor->method == NMFIELD_METHOD_ADD) { | |
| 2187 | |
| 2188 /* Not found, so we need to add it */ | |
| 2189 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 2190 | |
| 2191 const char *dn = NULL; | |
| 2192 | |
| 2193 locate = | |
| 2194 nm_locate_field(NM_A_SZ_DN, | |
| 8933 | 2195 (NMField *) cursor->ptr_value); |
| 2196 if (locate != NULL && locate->ptr_value != 0) { | |
| 2197 dn = (const char *) locate->ptr_value; | |
| 8675 | 2198 if (dn != NULL) { |
| 2199 contact = | |
| 2200 nm_create_contact_from_fields(cursor); | |
| 2201 if (contact) { | |
| 2202 nm_folder_add_contact_to_list(user-> | |
| 2203 root_folder, | |
| 2204 contact); | |
| 2205 nm_release_contact(contact); | |
| 2206 } | |
| 2207 } | |
| 2208 } | |
| 2209 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 2210 == 0) { | |
| 2211 folder = nm_create_folder_from_fields(cursor); | |
| 2212 nm_folder_add_folder_to_list(user->root_folder, | |
| 2213 folder); | |
| 2214 nm_release_folder(folder); | |
| 2215 } | |
| 2216 } | |
| 2217 } | |
| 2218 } | |
| 2219 } | |
| 2220 cursor++; | |
| 2221 } | |
| 2222 } |
