Mercurial > pidgin
annotate src/protocols/novell/nmuser.c @ 8874:a2affcdf8e01
[gaim-migrate @ 9643]
"This patch fixes the Novell protocol plugin on big
endian platforms (Bug #947017). It also includes a fix
for disconnects when sending large messages." --Mike Stoddard (novell)
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Wed, 05 May 2004 20:29:21 +0000 |
| parents | 5a2b5e4abf3a |
| children | 6663ad2386d9 |
| rev | line source |
|---|---|
| 8675 | 1 /* |
| 2 * nmuser.c | |
| 3 * | |
| 4 * Copyright © 2004 Unpublished Work of Novell, Inc. All Rights Reserved. | |
| 5 * | |
| 6 * THIS WORK IS AN UNPUBLISHED WORK OF NOVELL, INC. NO PART OF THIS WORK MAY BE | |
| 7 * USED, PRACTICED, PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED, | |
| 8 * TRANSLATED, ABRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, | |
| 9 * RECAST, TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, | |
| 10 * INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT | |
| 11 * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY. | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
12 * |
| 8675 | 13 * AS BETWEEN [GAIM] AND NOVELL, NOVELL GRANTS [GAIM] THE RIGHT TO REPUBLISH |
| 14 * THIS WORK UNDER THE GPL (GNU GENERAL PUBLIC LICENSE) WITH ALL RIGHTS AND | |
| 15 * LICENSES THEREUNDER. IF YOU HAVE RECEIVED THIS WORK DIRECTLY OR INDIRECTLY | |
| 16 * FROM [GAIM] AS PART OF SUCH A REPUBLICATION, YOU HAVE ALL RIGHTS AND LICENSES | |
| 17 * GRANTED BY [GAIM] UNDER THE GPL. IN CONNECTION WITH SUCH A REPUBLICATION, IF | |
| 18 * ANYTHING IN THIS NOTICE CONFLICTS WITH THE TERMS OF THE GPL, SUCH TERMS | |
| 19 * PREVAIL. | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 #include <glib.h> | |
| 24 #include <string.h> | |
| 25 #include "nmfield.h" | |
| 26 #include "nmuser.h" | |
| 27 #include "nmconn.h" | |
| 28 #include "nmcontact.h" | |
| 29 #include "nmuserrecord.h" | |
| 30 #include "util.h" | |
| 31 | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
32 /* This is the template that we wrap outgoing messages in, since the other |
| 8675 | 33 * GW Messenger clients expect messages to be in RTF. |
| 34 */ | |
| 35 #define RTF_TEMPLATE "{\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang1033"\ | |
| 36 "{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 "\ | |
| 37 "Microsoft Sans Serif;}}\n{\\colortbl ;\\red0"\ | |
| 38 "\\green0\\blue0;}\n\\viewkind4\\uc1\\pard\\ltrpar"\ | |
| 39 "\\li50\\ri50\\cf1\\f0\\fs20 %s\\par\n}" | |
| 40 | |
| 41 static NMERR_T nm_process_response(NMUser * user); | |
| 42 | |
| 43 static void _update_contact_list(NMUser * user, NMField * fields); | |
| 44 | |
| 45 /** | |
| 46 * See header for comments on on "public" functions | |
| 47 */ | |
| 48 | |
| 49 NMUser * | |
| 50 nm_initialize_user(const char *name, const char *server_addr, | |
| 51 int port, gpointer data, nm_event_cb event_callback) | |
| 52 { | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
53 NMUser *user; |
| 8675 | 54 if (name == NULL || server_addr == NULL || event_callback == NULL) |
| 55 return NULL; | |
| 56 | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
57 user = g_new0(NMUser, 1); |
| 8675 | 58 |
| 59 user->conn = g_new0(NMConn, 1); | |
| 60 | |
| 61 user->contacts = | |
| 62 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
| 63 g_free, (GDestroyNotify) nm_release_contact); | |
| 64 | |
| 65 user->user_records = | |
| 66 g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, g_free, | |
| 67 (GDestroyNotify) nm_release_user_record); | |
| 68 | |
| 69 user->display_id_to_dn = g_hash_table_new_full(g_str_hash, nm_utf8_str_equal, | |
| 70 g_free, g_free); | |
| 71 | |
| 72 user->name = g_strdup(name); | |
| 73 user->conn->addr = g_strdup(server_addr); | |
| 74 user->conn->port = port; | |
| 75 user->evt_callback = event_callback; | |
| 76 user->client_data = data; | |
| 77 | |
| 78 return user; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 void | |
| 83 nm_deinitialize_user(NMUser * user) | |
| 84 { | |
| 85 NMConn *conn = user->conn; | |
| 86 | |
| 87 g_free(conn->addr); | |
| 88 g_free(conn); | |
| 89 | |
| 90 if (user->contacts) { | |
| 91 g_hash_table_destroy(user->contacts); | |
| 92 } | |
| 93 | |
| 94 if (user->user_records) { | |
| 95 g_hash_table_destroy(user->user_records); | |
| 96 } | |
| 97 | |
| 98 if (user->display_id_to_dn) { | |
| 99 g_hash_table_destroy(user->display_id_to_dn); | |
| 100 } | |
| 101 | |
| 102 if (user->name) { | |
| 103 g_free(user->name); | |
| 104 } | |
| 105 | |
| 106 if (user->user_record) { | |
| 107 nm_release_user_record(user->user_record); | |
| 108 } | |
| 109 | |
| 110 nm_conference_list_free(user); | |
| 111 nm_destroy_contact_list(user); | |
| 112 | |
| 113 g_free(user); | |
| 114 } | |
| 115 | |
| 116 NMERR_T | |
| 117 nm_send_login(NMUser * user, const char *pwd, const char *my_addr, | |
| 118 const char *user_agent, nm_response_cb callback, gpointer data) | |
| 119 { | |
| 120 NMERR_T rc = NM_OK; | |
| 121 NMField *fields = NULL; | |
| 122 NMRequest *req = NULL; | |
| 123 | |
| 124 if (user == NULL || pwd == NULL || user_agent == NULL) { | |
| 125 return NMERR_BAD_PARM; | |
| 126 } | |
| 127 | |
| 128 fields = nm_add_field(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, | |
| 129 (guint32) g_strdup(user->name), NMFIELD_TYPE_UTF8); | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
130 |
| 8675 | 131 fields = nm_add_field(fields, NM_A_SZ_CREDENTIALS, 0, NMFIELD_METHOD_VALID, 0, |
| 132 (guint32) g_strdup(pwd), NMFIELD_TYPE_UTF8); | |
| 133 | |
| 134 fields = nm_add_field(fields, NM_A_SZ_USER_AGENT, 0, NMFIELD_METHOD_VALID, 0, | |
| 135 (guint32) g_strdup(user_agent), NMFIELD_TYPE_UTF8); | |
| 136 | |
| 137 fields = nm_add_field(fields, NM_A_UD_BUILD, 0, NMFIELD_METHOD_VALID, 0, | |
| 138 (guint32) NM_PROTOCOL_VERSION, | |
| 139 NMFIELD_TYPE_UDWORD); | |
| 140 if (my_addr) { | |
| 141 fields = nm_add_field(fields, NM_A_IP_ADDRESS, 0, NMFIELD_METHOD_VALID, 0, | |
| 142 (guint32) g_strdup(my_addr), NMFIELD_TYPE_UTF8); | |
| 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 */ | |
| 176 fields = nm_add_field(fields, NM_A_SZ_STATUS, 0, NMFIELD_METHOD_VALID, 0, | |
| 177 (guint32) g_strdup_printf("%d", status), | |
| 178 NMFIELD_TYPE_UTF8); | |
| 179 | |
| 180 /* Add the status text and auto reply text if there is any */ | |
| 181 if (text) { | |
| 182 fields = nm_add_field(fields, NM_A_SZ_STATUS_TEXT, | |
| 183 0, NMFIELD_METHOD_VALID, 0, | |
| 184 (guint32) g_strdup(text), NMFIELD_TYPE_UTF8); | |
| 185 } | |
| 186 | |
| 187 if (auto_resp) { | |
| 188 fields = nm_add_field(fields, NM_A_SZ_MESSAGE_BODY, 0, | |
| 189 NMFIELD_METHOD_VALID, 0, | |
| 190 (guint32) g_strdup(auto_resp), NMFIELD_TYPE_UTF8); | |
| 191 } | |
| 192 | |
| 193 rc = nm_send_request(user->conn, "setstatus", fields, &req); | |
| 194 if (rc == NM_OK && req) { | |
| 195 nm_request_set_callback(req, callback); | |
| 196 nm_request_set_user_define(req, data); | |
| 197 nm_conn_add_request_item(user->conn, req); | |
| 198 } | |
| 199 | |
| 200 if (fields) { | |
| 201 nm_free_fields(&fields); | |
| 202 } | |
| 203 | |
| 204 if (req) { | |
| 205 nm_release_request(req); | |
| 206 } | |
| 207 | |
| 208 return rc; | |
| 209 } | |
| 210 | |
| 211 NMERR_T | |
| 212 nm_send_get_details(NMUser * user, const char *name, | |
| 213 nm_response_cb callback, gpointer data) | |
| 214 { | |
| 215 NMERR_T rc = NM_OK; | |
| 216 NMField *fields = NULL; | |
| 217 NMRequest *req = NULL; | |
| 218 | |
| 219 if (user == NULL || name == NULL) | |
| 220 return NMERR_BAD_PARM; | |
| 221 | |
| 222 /* Add in DN or display id */ | |
| 223 if (strstr("=", name)) { | |
| 224 fields = nm_add_field(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 225 (guint32) g_strdup(name), NMFIELD_TYPE_DN); | |
| 226 } else { | |
| 227 | |
| 228 const char *dn = nm_lookup_dn(user, name); | |
| 229 | |
| 230 if (dn) { | |
| 231 fields = nm_add_field(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 232 (guint32) g_strdup(name), NMFIELD_TYPE_DN); | |
| 233 } else { | |
| 234 fields = | |
| 235 nm_add_field(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, | |
| 236 (guint32) g_strdup(name), NMFIELD_TYPE_UTF8); | |
| 237 } | |
| 238 | |
| 239 } | |
| 240 | |
| 241 rc = nm_send_request(user->conn, "getdetails", fields, &req); | |
| 242 if (rc == NM_OK) { | |
| 243 nm_request_set_callback(req, callback); | |
| 244 nm_request_set_user_define(req, data); | |
| 245 nm_conn_add_request_item(user->conn, req); | |
| 246 } | |
| 247 | |
| 248 if (fields) | |
| 249 nm_free_fields(&fields); | |
| 250 | |
| 251 if (req) | |
| 252 nm_release_request(req); | |
| 253 | |
| 254 return rc; | |
| 255 } | |
| 256 | |
| 257 NMERR_T | |
| 258 nm_send_create_conference(NMUser * user, NMConference * conference, | |
| 259 nm_response_cb callback, gpointer message) | |
| 260 { | |
| 261 NMERR_T rc = NM_OK; | |
| 262 NMField *fields = NULL; | |
| 263 NMField *tmp = NULL; | |
| 264 NMField *field = NULL; | |
| 265 NMRequest *req = NULL; | |
| 266 int count, i; | |
| 267 | |
| 268 if (user == NULL || conference == NULL) | |
| 269 return NMERR_BAD_PARM; | |
| 270 | |
| 271 /* Add in a blank guid */ | |
| 272 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 273 (guint32) g_strdup(BLANK_GUID), NMFIELD_TYPE_UTF8); | |
| 274 | |
| 275 fields = nm_add_field(fields, NM_A_FA_CONVERSATION, 0, | |
| 276 NMFIELD_METHOD_VALID, 0, (guint32) tmp, | |
| 277 NMFIELD_TYPE_ARRAY); | |
| 278 tmp = NULL; | |
| 279 | |
| 280 /* Add participants in */ | |
| 281 count = nm_conference_get_participant_count(conference); | |
| 282 for (i = 0; i < count; i++) { | |
| 283 NMUserRecord *user_record = nm_conference_get_participant(conference, i); | |
| 284 | |
| 285 if (user_record) { | |
| 286 fields = nm_add_field(fields, NM_A_SZ_DN, | |
| 287 0, NMFIELD_METHOD_VALID, 0, | |
| 288 (guint32) | |
| 289 g_strdup(nm_user_record_get_dn(user_record)), | |
| 290 NMFIELD_TYPE_DN); | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 /* Add our user in */ | |
| 295 field = nm_locate_field(NM_A_SZ_DN, user->fields); | |
| 296 if (field) { | |
| 297 fields = nm_add_field(fields, NM_A_SZ_DN, | |
| 298 0, NMFIELD_METHOD_VALID, 0, | |
| 299 (guint32) g_strdup((char *) field->value), | |
| 300 NMFIELD_TYPE_DN); | |
| 301 } | |
| 302 | |
| 303 rc = nm_send_request(user->conn, "createconf", fields, &req); | |
| 304 if (rc == NM_OK && req) { | |
| 305 nm_request_set_callback(req, callback); | |
| 306 nm_request_set_data(req, conference); | |
| 307 nm_request_set_user_define(req, message); | |
| 308 nm_conn_add_request_item(user->conn, req); | |
| 309 } | |
| 310 | |
| 311 if (req) | |
| 312 nm_release_request(req); | |
| 313 | |
| 314 if (fields) | |
| 315 nm_free_fields(&fields); | |
| 316 | |
| 317 return rc; | |
| 318 } | |
| 319 | |
| 320 NMERR_T | |
| 321 nm_send_leave_conference(NMUser * user, NMConference * conference, | |
| 322 nm_response_cb callback, gpointer message) | |
| 323 { | |
| 324 | |
| 325 NMERR_T rc = NM_OK; | |
| 326 NMField *fields = NULL; | |
| 327 NMField *tmp = NULL; | |
| 328 NMRequest *req = NULL; | |
| 329 | |
| 330 if (user == NULL || conference == NULL) | |
| 331 return NMERR_BAD_PARM; | |
| 332 | |
| 333 /* Add in the conference guid */ | |
| 334 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 335 (guint32) g_strdup(nm_conference_get_guid(conference)), | |
| 336 NMFIELD_TYPE_UTF8); | |
| 337 | |
| 338 fields = nm_add_field(fields, NM_A_FA_CONVERSATION, 0, | |
| 339 NMFIELD_METHOD_VALID, 0, (guint32) tmp, | |
| 340 NMFIELD_TYPE_ARRAY); | |
| 341 tmp = NULL; | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
342 |
| 8675 | 343 /* Send the request to the server */ |
| 344 rc = nm_send_request(user->conn, "leaveconf", fields, &req); | |
| 345 if (rc == NM_OK && req) { | |
| 346 nm_request_set_callback(req, callback); | |
| 347 nm_request_set_data(req, conference); | |
| 348 nm_request_set_user_define(req, message); | |
| 349 nm_conn_add_request_item(user->conn, req); | |
| 350 } | |
| 351 | |
| 352 if (req) | |
| 353 nm_release_request(req); | |
| 354 | |
| 355 if (fields) | |
| 356 nm_free_fields(&fields); | |
| 357 | |
| 358 return rc; | |
| 359 } | |
| 360 | |
| 361 NMERR_T | |
| 362 nm_send_join_conference(NMUser * user, NMConference * conference, | |
| 363 nm_response_cb callback, gpointer data) | |
| 364 { | |
| 365 NMERR_T rc = NM_OK; | |
| 366 NMField *fields = NULL, *tmp = NULL; | |
| 367 NMRequest *req = NULL; | |
| 368 | |
| 369 if (user == NULL || conference == NULL) | |
| 370 return NMERR_BAD_PARM; | |
| 371 | |
| 372 /* Add in the conference guid */ | |
| 373 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 374 (guint32) g_strdup(nm_conference_get_guid(conference)), | |
| 375 NMFIELD_TYPE_UTF8); | |
| 376 | |
| 377 fields = nm_add_field(fields, NM_A_FA_CONVERSATION, 0, | |
| 378 NMFIELD_METHOD_VALID, 0, (guint32) tmp, | |
| 379 NMFIELD_TYPE_ARRAY); | |
| 380 tmp = NULL; | |
| 381 | |
| 382 /* Send the request to the server */ | |
| 383 rc = nm_send_request(user->conn, "joinconf", fields, &req); | |
| 384 | |
| 385 /* Set up the request object so that we know what to do | |
| 386 * when we get a response | |
| 387 */ | |
| 388 if (rc == NM_OK && req) { | |
| 389 nm_request_set_callback(req, callback); | |
| 390 nm_request_set_data(req, conference); | |
| 391 nm_request_set_user_define(req, data); | |
| 392 nm_conn_add_request_item(user->conn, req); | |
| 393 } | |
| 394 | |
| 395 if (req) | |
| 396 nm_release_request(req); | |
| 397 | |
| 398 if (fields) | |
| 399 nm_free_fields(&fields); | |
| 400 | |
| 401 return rc; | |
| 402 } | |
| 403 | |
| 404 NMERR_T | |
| 405 nm_send_reject_conference(NMUser * user, NMConference * conference, | |
| 406 nm_response_cb callback, gpointer data) | |
| 407 { | |
| 408 NMERR_T rc = NM_OK; | |
| 409 NMField *fields = NULL; | |
| 410 NMField *tmp = NULL; | |
| 411 NMRequest *req = NULL; | |
| 412 | |
| 413 if (user == NULL || conference == NULL) | |
| 414 return NMERR_BAD_PARM; | |
| 415 | |
| 416 /* Add in the conference guid */ | |
| 417 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 418 (guint32) g_strdup(nm_conference_get_guid(conference)), | |
| 419 NMFIELD_TYPE_UTF8); | |
| 420 | |
| 421 fields = nm_add_field(fields, NM_A_FA_CONVERSATION, 0, | |
| 422 NMFIELD_METHOD_VALID, 0, (guint32) tmp, | |
| 423 NMFIELD_TYPE_ARRAY); | |
| 424 tmp = NULL; | |
| 425 | |
| 426 /* Send the request to the server */ | |
| 427 rc = nm_send_request(user->conn, "rejectconf", fields, &req); | |
| 428 | |
| 429 /* Set up the request object so that we know what to do | |
| 430 * when we get a response | |
| 431 */ | |
| 432 if (rc == NM_OK && req) { | |
| 433 nm_request_set_callback(req, callback); | |
| 434 nm_request_set_data(req, conference); | |
| 435 nm_request_set_user_define(req, data); | |
| 436 nm_conn_add_request_item(user->conn, req); | |
| 437 } | |
| 438 | |
| 439 if (req) | |
| 440 nm_release_request(req); | |
| 441 | |
| 442 if (fields) | |
| 443 nm_free_fields(&fields); | |
| 444 | |
| 445 return rc; | |
| 446 } | |
| 447 | |
| 448 NMERR_T | |
| 449 nm_send_message(NMUser * user, NMMessage * message, nm_response_cb callback) | |
| 450 { | |
| 451 NMERR_T rc = NM_OK; | |
| 452 const char *text; | |
| 453 NMField *fields = NULL, *tmp = NULL; | |
| 454 NMRequest *req = NULL; | |
| 455 NMConference *conf; | |
| 456 NMUserRecord *user_record; | |
| 457 int count, i; | |
| 458 | |
| 459 if (user == NULL || message == NULL) { | |
| 460 return NMERR_BAD_PARM; | |
| 461 } | |
| 462 | |
| 463 conf = nm_message_get_conference(message); | |
| 464 if (!nm_conference_is_instantiated(conf)) { | |
| 465 rc = NMERR_CONFERENCE_NOT_INSTANTIATED; | |
| 466 } else { | |
| 467 | |
| 468 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 469 (guint32) g_strdup(nm_conference_get_guid(conf)), | |
| 470 NMFIELD_TYPE_UTF8); | |
| 471 | |
| 472 fields = | |
| 473 nm_add_field(fields, NM_A_FA_CONVERSATION, 0, NMFIELD_METHOD_VALID, 0, | |
| 474 (guint32) tmp, NMFIELD_TYPE_ARRAY); | |
| 475 tmp = NULL; | |
| 476 | |
| 477 /* Add RTF and plain text versions of the message */ | |
| 478 text = nm_message_get_text(message); | |
| 479 | |
| 480 tmp = nm_add_field(tmp, NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_METHOD_VALID, 0, | |
| 481 (guint32) g_strdup_printf(RTF_TEMPLATE, text), | |
| 482 NMFIELD_TYPE_UTF8); | |
| 483 | |
| 484 tmp = nm_add_field(tmp, NM_A_UD_MESSAGE_TYPE, 0, NMFIELD_METHOD_VALID, 0, | |
| 485 (guint32) 0, NMFIELD_TYPE_UDWORD); | |
| 486 | |
| 487 tmp = nm_add_field(tmp, NM_A_SZ_MESSAGE_TEXT, 0, NMFIELD_METHOD_VALID, 0, | |
| 488 (guint32) g_strdup(text), NMFIELD_TYPE_UTF8); | |
| 489 | |
| 490 fields = nm_add_field(fields, NM_A_FA_MESSAGE, 0, NMFIELD_METHOD_VALID, 0, | |
| 491 (guint32) tmp, NMFIELD_TYPE_ARRAY); | |
| 492 tmp = NULL; | |
| 493 | |
| 494 /* Add participants */ | |
| 495 count = nm_conference_get_participant_count(conf); | |
| 496 for (i = 0; i < count; i++) { | |
| 497 user_record = nm_conference_get_participant(conf, i); | |
| 498 if (user_record) { | |
| 499 fields = | |
| 500 nm_add_field(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 501 (guint32) | |
| 502 g_strdup(nm_user_record_get_dn(user_record)), | |
| 503 NMFIELD_TYPE_DN); | |
| 504 } | |
| 505 } | |
| 506 | |
| 507 /* Send the request */ | |
| 508 rc = nm_send_request(user->conn, "sendmessage", fields, &req); | |
| 509 if (rc == NM_OK && req) { | |
| 510 nm_request_set_callback(req, callback); | |
| 511 nm_conn_add_request_item(user->conn, req); | |
| 512 } | |
| 513 } | |
| 514 | |
| 515 if (fields) { | |
| 516 nm_free_fields(&fields); | |
| 517 } | |
| 518 | |
| 519 if (req) { | |
| 520 nm_release_request(req); | |
| 521 } | |
| 522 | |
| 523 return rc; | |
| 524 } | |
| 525 | |
| 526 NMERR_T | |
| 527 nm_send_typing(NMUser * user, NMConference * conf, | |
| 528 gboolean typing, nm_response_cb callback) | |
| 529 { | |
| 530 NMERR_T rc = NM_OK; | |
| 531 char *str = NULL; | |
| 532 NMField *fields = NULL, *tmp = NULL; | |
| 533 NMRequest *req = NULL; | |
| 534 | |
| 535 if (user == NULL || conf == NULL) { | |
| 536 return NMERR_BAD_PARM; | |
| 537 } | |
| 538 | |
| 539 if (!nm_conference_is_instantiated(conf)) { | |
| 540 rc = NMERR_CONFERENCE_NOT_INSTANTIATED; | |
| 541 } else { | |
| 542 /* Add the conference GUID */ | |
| 543 tmp = nm_add_field(tmp, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 544 (guint32) g_strdup(nm_conference_get_guid(conf)), | |
| 545 NMFIELD_TYPE_UTF8); | |
| 546 | |
| 547 /* Add typing type */ | |
| 548 str = g_strdup_printf("%d", | |
| 549 (typing ? NMEVT_USER_TYPING : | |
| 550 NMEVT_USER_NOT_TYPING)); | |
| 551 | |
| 552 tmp = nm_add_field(tmp, NM_A_SZ_TYPE, 0, NMFIELD_METHOD_VALID, 0, | |
| 553 (guint32) str, NMFIELD_TYPE_UTF8); | |
| 554 | |
| 555 fields = | |
| 556 nm_add_field(fields, NM_A_FA_CONVERSATION, 0, NMFIELD_METHOD_VALID, 0, | |
| 557 (guint32) tmp, NMFIELD_TYPE_ARRAY); | |
| 558 tmp = NULL; | |
| 559 | |
| 560 rc = nm_send_request(user->conn, "sendtyping", fields, &req); | |
| 561 if (rc == NM_OK && req) { | |
| 562 nm_request_set_callback(req, callback); | |
| 563 nm_conn_add_request_item(user->conn, req); | |
| 564 } | |
| 565 } | |
| 566 | |
| 567 if (req) | |
| 568 nm_release_request(req); | |
| 569 | |
| 570 if (fields) | |
| 571 nm_free_fields(&fields); | |
| 572 | |
| 573 return rc; | |
| 574 } | |
| 575 | |
| 576 NMERR_T | |
| 577 nm_send_create_contact(NMUser * user, NMFolder * folder, | |
| 578 NMContact * contact, nm_response_cb callback, | |
| 579 gpointer data) | |
| 580 { | |
| 581 NMERR_T rc = NM_OK; | |
| 582 NMField *fields = NULL; | |
| 583 NMRequest *req = NULL; | |
| 584 const char *name = NULL; | |
| 585 const char *display_name = NULL; | |
| 586 | |
| 587 if (user == NULL || folder == NULL || contact == NULL) { | |
| 588 return NMERR_BAD_PARM; | |
| 589 } | |
| 590 | |
| 591 /* Add parent ID */ | |
| 592 fields = nm_add_field(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 593 (guint32) g_strdup_printf("%d", | |
| 594 nm_folder_get_id(folder)), | |
| 595 NMFIELD_TYPE_UTF8); | |
| 596 | |
| 597 /* Check to see if userid is current user and return an error? */ | |
| 598 | |
| 599 /* Check to see if contact already exists and return an error? */ | |
| 600 | |
| 601 /* Add userid or dn */ | |
| 602 name = nm_contact_get_dn(contact); | |
| 603 if (name == NULL) | |
| 604 return NMERR_BAD_PARM; | |
| 605 | |
| 606 if (strstr("=", name)) { | |
| 607 fields = nm_add_field(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 608 (guint32) g_strdup(name), NMFIELD_TYPE_DN); | |
| 609 } else { | |
| 610 fields = nm_add_field(fields, NM_A_SZ_USERID, 0, NMFIELD_METHOD_VALID, 0, | |
| 611 (guint32) g_strdup(name), NMFIELD_TYPE_UTF8); | |
| 612 } | |
| 613 | |
| 614 /* Add display name */ | |
| 615 display_name = nm_contact_get_display_name(contact); | |
| 616 if (display_name) | |
| 617 fields = nm_add_field(fields, NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_METHOD_VALID, 0, | |
| 618 (guint32) g_strdup(display_name), NMFIELD_TYPE_UTF8); | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
619 |
| 8675 | 620 /* Dispatch the request */ |
| 621 rc = nm_send_request(user->conn, "createcontact", fields, &req); | |
| 622 if (rc == NM_OK && req) { | |
| 623 nm_request_set_callback(req, callback); | |
| 624 nm_request_set_data(req, contact); | |
| 625 nm_request_set_user_define(req, data); | |
| 626 nm_conn_add_request_item(user->conn, req); | |
| 627 } | |
| 628 | |
| 629 if (fields) | |
| 630 nm_free_fields(&fields); | |
| 631 | |
| 632 if (req) | |
| 633 nm_release_request(req); | |
| 634 | |
| 635 return rc; | |
| 636 } | |
| 637 | |
| 638 NMERR_T | |
| 639 nm_send_remove_contact(NMUser * user, NMFolder * folder, | |
| 640 NMContact * contact, nm_response_cb callback, | |
| 641 gpointer data) | |
| 642 { | |
| 643 NMERR_T rc = NM_OK; | |
| 644 NMField *fields = NULL; | |
| 645 NMRequest *req = NULL; | |
| 646 | |
| 647 if (user == NULL || folder == NULL || contact == NULL) { | |
| 648 return NMERR_BAD_PARM; | |
| 649 } | |
| 650 | |
| 651 /* Add parent id */ | |
| 652 fields = nm_add_field(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 653 (guint32) g_strdup_printf("%d", | |
| 654 nm_folder_get_id(folder)), | |
| 655 NMFIELD_TYPE_UTF8); | |
| 656 | |
| 657 /* Add object id */ | |
| 658 fields = nm_add_field(fields, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 659 (guint32) g_strdup_printf("%d", | |
| 660 nm_contact_get_id(contact)), | |
| 661 NMFIELD_TYPE_UTF8); | |
| 662 | |
| 663 /* Dispatch the request */ | |
| 664 rc = nm_send_request(user->conn, "deletecontact", fields, &req); | |
| 665 if (rc == NM_OK && req) { | |
| 666 nm_request_set_callback(req, callback); | |
| 667 nm_request_set_data(req, contact); | |
| 668 nm_request_set_user_define(req, data); | |
| 669 nm_conn_add_request_item(user->conn, req); | |
| 670 } | |
| 671 | |
| 672 if (fields) | |
| 673 nm_free_fields(&fields); | |
| 674 | |
| 675 if (req) | |
| 676 nm_release_request(req); | |
| 677 | |
| 678 return rc; | |
| 679 } | |
| 680 | |
| 681 NMERR_T | |
| 682 nm_send_create_folder(NMUser * user, const char *name, | |
| 683 nm_response_cb callback, gpointer data) | |
| 684 { | |
| 685 NMERR_T rc = NM_OK; | |
| 686 NMField *fields = NULL; | |
| 687 NMRequest *req = NULL; | |
| 688 | |
| 689 if (user == NULL || name == NULL) { | |
| 690 return NMERR_BAD_PARM; | |
| 691 } | |
| 692 | |
| 693 /* Add parent ID */ | |
| 694 fields = nm_add_field(fields, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 695 (guint32) g_strdup("0"), NMFIELD_TYPE_UTF8); | |
| 696 | |
| 697 /* Add name of the folder to add */ | |
| 698 fields = | |
| 699 nm_add_field(fields, NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_METHOD_VALID, 0, | |
| 700 (guint32) g_strdup(name), NMFIELD_TYPE_UTF8); | |
| 701 | |
| 702 /* Add sequence, for now just put it at the bottom */ | |
| 703 fields = | |
| 704 nm_add_field(fields, NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_METHOD_VALID, 0, | |
| 705 (guint32) g_strdup("-1"), NMFIELD_TYPE_UTF8); | |
| 706 | |
| 707 /* Dispatch the request */ | |
| 708 rc = nm_send_request(user->conn, "createfolder", fields, &req); | |
| 709 if (rc == NM_OK && req) { | |
| 710 nm_request_set_callback(req, callback); | |
| 711 nm_request_set_data(req, g_strdup(name)); | |
| 712 nm_request_set_user_define(req, data); | |
| 713 nm_conn_add_request_item(user->conn, req); | |
| 714 } | |
| 715 | |
| 716 if (fields) | |
| 717 nm_free_fields(&fields); | |
| 718 | |
| 719 if (req) | |
| 720 nm_release_request(req); | |
| 721 | |
| 722 return rc; | |
| 723 } | |
| 724 | |
| 725 NMERR_T | |
| 726 nm_send_remove_folder(NMUser * user, NMFolder * folder, | |
| 727 nm_response_cb callback, gpointer data) | |
| 728 { | |
| 729 NMERR_T rc = NM_OK; | |
| 730 NMField *fields = NULL; | |
| 731 NMRequest *req = NULL; | |
| 732 | |
| 733 if (user == NULL || folder == NULL) { | |
| 734 return NMERR_BAD_PARM; | |
| 735 } | |
| 736 | |
| 737 /* Add the object id */ | |
| 738 fields = nm_add_field(fields, NM_A_SZ_OBJECT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 739 (guint32) g_strdup_printf("%d", nm_folder_get_id(folder)), | |
| 740 NMFIELD_TYPE_UTF8); | |
| 741 | |
| 742 /* Dispatch the request */ | |
| 743 rc = nm_send_request(user->conn, "deletecontact", fields, &req); | |
| 744 if (rc == NM_OK && req) { | |
| 745 nm_request_set_callback(req, callback); | |
| 746 nm_request_set_data(req, folder); | |
| 747 nm_request_set_user_define(req, data); | |
| 748 nm_conn_add_request_item(user->conn, req); | |
| 749 } | |
| 750 | |
| 751 if (fields) | |
| 752 nm_free_fields(&fields); | |
| 753 | |
| 754 if (req) | |
| 755 nm_release_request(req); | |
| 756 | |
| 757 return rc; | |
| 758 } | |
| 759 | |
| 760 NMERR_T | |
| 761 nm_send_get_status(NMUser * user, NMUserRecord * user_record, | |
| 762 nm_response_cb callback, gpointer data) | |
| 763 { | |
| 764 NMERR_T rc = NM_OK; | |
| 765 NMField *fields = NULL; | |
| 766 NMRequest *req = NULL; | |
| 767 const char *dn; | |
| 768 | |
| 769 if (user == NULL || user_record == NULL) | |
| 770 return NMERR_BAD_PARM; | |
| 771 | |
| 772 /* Add DN to field list */ | |
| 773 dn = nm_user_record_get_dn(user_record); | |
| 774 if (dn == NULL) | |
| 775 return (NMERR_T) -1; | |
| 776 | |
| 777 fields = nm_add_field(fields, NM_A_SZ_DN, 0, NMFIELD_METHOD_VALID, 0, | |
| 778 (guint32) g_strdup(dn), NMFIELD_TYPE_UTF8); | |
| 779 | |
| 780 /* Dispatch the request */ | |
| 781 rc = nm_send_request(user->conn, "getstatus", fields, &req); | |
| 782 if (rc == NM_OK && req) { | |
| 783 nm_request_set_callback(req, callback); | |
| 784 nm_request_set_data(req, user_record); | |
| 785 nm_request_set_user_define(req, data); | |
| 786 nm_conn_add_request_item(user->conn, req); | |
| 787 } | |
| 788 | |
| 789 if (fields) | |
| 790 nm_free_fields(&fields); | |
| 791 | |
| 792 if (req) | |
| 793 nm_release_request(req); | |
| 794 | |
| 795 return rc; | |
| 796 } | |
| 797 | |
| 798 NMERR_T | |
| 799 nm_send_rename_contact(NMUser * user, NMContact * contact, | |
| 800 const char *new_name, nm_response_cb callback, | |
| 801 gpointer data) | |
| 802 { | |
| 803 NMERR_T rc = NM_OK; | |
| 804 NMField *field = NULL, *fields = NULL, *list = NULL; | |
| 805 NMRequest *req = NULL; | |
| 806 | |
| 807 if (user == NULL || contact == NULL || new_name == NULL) | |
| 808 return NMERR_BAD_PARM; | |
| 809 | |
| 810 /* Create field list for current contact */ | |
| 811 field = nm_contact_to_fields(contact); | |
| 812 if (field) { | |
| 813 | |
| 814 fields = | |
| 815 nm_add_field(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_DELETE, 0, | |
| 816 (guint32) field, NMFIELD_TYPE_ARRAY); | |
| 817 field = NULL; | |
| 818 | |
| 819 /* Update the contacts display name locally */ | |
| 820 nm_contact_set_display_name(contact, new_name); | |
| 821 | |
| 822 /* Create field list for updated contact */ | |
| 823 field = nm_contact_to_fields(contact); | |
| 824 if (field) { | |
| 825 fields = | |
| 826 nm_add_field(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_ADD, 0, | |
| 827 (guint32) field, NMFIELD_TYPE_ARRAY); | |
| 828 field = NULL; | |
| 829 | |
| 830 /* Package it up */ | |
| 831 list = | |
| 832 nm_add_field(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, | |
| 833 0, (guint32) fields, NMFIELD_TYPE_ARRAY); | |
| 834 fields = NULL; | |
| 835 | |
| 836 rc = nm_send_request(user->conn, "updateitem", list, &req); | |
| 837 if (rc == NM_OK && req) { | |
| 838 nm_request_set_callback(req, callback); | |
| 839 nm_request_set_data(req, contact); | |
| 840 nm_request_set_user_define(req, data); | |
| 841 nm_conn_add_request_item(user->conn, req); | |
| 842 } | |
| 843 } | |
| 844 } | |
| 845 | |
| 846 if (list) | |
| 847 nm_free_fields(&list); | |
| 848 | |
| 849 return rc; | |
| 850 } | |
| 851 | |
| 852 NMERR_T | |
| 853 nm_send_rename_folder(NMUser * user, NMFolder * folder, const char *new_name, | |
| 854 nm_response_cb callback, gpointer data) | |
| 855 { | |
| 856 NMERR_T rc = NM_OK; | |
| 857 NMField *field = NULL, *fields = NULL, *list = NULL; | |
| 858 NMRequest *req = NULL; | |
| 859 | |
| 860 if (user == NULL || folder == NULL || new_name == NULL) | |
| 861 return NMERR_BAD_PARM; | |
| 862 | |
| 863 /* Make sure folder does not already exist!? */ | |
| 864 if (nm_find_folder(user, new_name)) | |
| 865 return NMERR_FOLDER_EXISTS; | |
| 866 | |
| 867 /* Create field list for current folder */ | |
| 868 field = nm_folder_to_fields(folder); | |
| 869 if (field) { | |
| 870 | |
| 871 fields = nm_add_field(fields, NM_A_FA_FOLDER, 0, NMFIELD_METHOD_DELETE, 0, | |
| 872 (guint32) field, NMFIELD_TYPE_ARRAY); | |
| 873 field = NULL; | |
| 874 | |
| 875 /* Update the folders display name locally */ | |
| 876 nm_folder_set_name(folder, new_name); | |
| 877 | |
| 878 /* Create field list for updated folder */ | |
| 879 field = nm_folder_to_fields(folder); | |
| 880 if (field) { | |
| 881 fields = | |
| 882 nm_add_field(fields, NM_A_FA_FOLDER, 0, NMFIELD_METHOD_ADD, 0, | |
| 883 (guint32) field, NMFIELD_TYPE_ARRAY); | |
| 884 field = NULL; | |
| 885 | |
| 886 /* Package it up */ | |
| 887 list = | |
| 888 nm_add_field(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, | |
| 889 0, (guint32) fields, NMFIELD_TYPE_ARRAY); | |
| 890 fields = NULL; | |
| 891 | |
| 892 rc = nm_send_request(user->conn, "updateitem", list, &req); | |
| 893 if (rc == NM_OK && req) { | |
| 894 nm_request_set_callback(req, callback); | |
| 895 nm_request_set_data(req, folder); | |
| 896 nm_request_set_user_define(req, data); | |
| 897 nm_conn_add_request_item(user->conn, req); | |
| 898 } | |
| 899 } | |
| 900 } | |
| 901 | |
| 902 if (list) | |
| 903 nm_free_fields(&list); | |
| 904 | |
| 905 return rc; | |
| 906 } | |
| 907 | |
| 908 NMERR_T | |
| 909 nm_send_move_contact(NMUser * user, NMContact * contact, NMFolder * folder, | |
| 910 nm_response_cb callback, gpointer data) | |
| 911 { | |
| 912 NMERR_T rc = NM_OK; | |
| 913 NMField *field = NULL, *fields = NULL, *list = NULL; | |
| 914 NMRequest *req = NULL; | |
| 915 | |
| 916 if (user == NULL || contact == NULL || folder == NULL) | |
| 917 return NMERR_BAD_PARM; | |
| 918 | |
| 919 /* Create field list for the contact */ | |
| 920 field = nm_contact_to_fields(contact); | |
| 921 if (field) { | |
| 922 | |
| 923 fields = | |
| 924 nm_add_field(fields, NM_A_FA_CONTACT, 0, NMFIELD_METHOD_DELETE, 0, | |
| 925 (guint32) field, NMFIELD_TYPE_ARRAY); | |
| 926 field = NULL; | |
| 927 | |
| 928 /* Wrap the contact up and add it to the request field list */ | |
| 929 list = | |
| 930 nm_add_field(list, NM_A_FA_CONTACT_LIST, 0, NMFIELD_METHOD_VALID, 0, | |
| 931 (guint32) fields, NMFIELD_TYPE_ARRAY); | |
| 932 fields = NULL; | |
| 933 | |
| 934 /* Add sequence number */ | |
| 935 list = | |
| 936 nm_add_field(list, NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_METHOD_VALID, | |
| 937 0, (guint32) g_strdup("-1"), NMFIELD_TYPE_UTF8); | |
| 938 | |
| 939 /* Add parent ID */ | |
| 940 list = nm_add_field(list, NM_A_SZ_PARENT_ID, 0, NMFIELD_METHOD_VALID, 0, | |
| 941 (guint32) g_strdup_printf("%d", | |
| 942 nm_folder_get_id(folder)), | |
| 943 NMFIELD_TYPE_UTF8); | |
| 944 | |
| 945 /* Dispatch the request */ | |
| 946 rc = nm_send_request(user->conn, "movecontact", list, &req); | |
| 947 if (rc == NM_OK && req) { | |
| 948 nm_request_set_callback(req, callback); | |
| 949 nm_request_set_data(req, contact); | |
| 950 nm_request_set_user_define(req, data); | |
| 951 nm_conn_add_request_item(user->conn, req); | |
| 952 | |
| 953 } | |
| 954 } | |
| 955 | |
| 956 if (list) | |
| 957 nm_free_fields(&list); | |
| 958 | |
| 959 return rc; | |
| 960 } | |
| 961 | |
| 962 | |
| 963 NMERR_T | |
| 964 nm_process_new_data(NMUser * user) | |
| 965 { | |
| 966 NMConn *conn; | |
| 967 NMERR_T rc = NM_OK; | |
| 968 int ret; | |
| 969 guint32 val; | |
| 970 | |
| 971 if (user == NULL) | |
| 972 return NMERR_BAD_PARM; | |
| 973 | |
| 974 conn = user->conn; | |
| 975 | |
| 976 /* Check to see if this is an event or a response */ | |
| 977 ret = nm_tcp_read(conn, (char *) &val, sizeof(val)); | |
| 978 if (ret == sizeof(val)) { | |
| 979 | |
| 980 if (strncmp((char *) &val, "HTTP", strlen("HTTP")) == 0) | |
| 981 rc = nm_process_response(user); | |
| 982 else | |
| 8874 | 983 rc = nm_process_event(user, GUINT32_FROM_LE(val)); |
| 8675 | 984 |
| 985 } else { | |
| 986 rc = NMERR_PROTOCOL; | |
| 987 } | |
| 988 | |
| 989 return rc; | |
| 990 } | |
| 991 | |
| 992 NMConference * | |
| 993 nm_find_conversation(NMUser * user, const char *who) | |
| 994 { | |
| 995 NMConference *conference = NULL; | |
| 996 NMConference *tmp; | |
| 997 GSList *cnode; | |
| 998 | |
| 999 if (user && user->conferences) { | |
| 1000 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1001 tmp = cnode->data; | |
| 1002 if (nm_conference_get_participant_count(tmp) == 1) { | |
| 1003 NMUserRecord *ur = nm_conference_get_participant(tmp, 0); | |
| 1004 | |
| 1005 if (ur) { | |
| 1006 if (nm_utf8_str_equal(nm_user_record_get_dn(ur), who)) { | |
| 1007 conference = tmp; | |
| 1008 break; | |
| 1009 } | |
| 1010 } | |
| 1011 } | |
| 1012 } | |
| 1013 } | |
| 1014 | |
| 1015 return conference; | |
| 1016 } | |
| 1017 | |
| 1018 void | |
| 1019 nm_conference_list_add(NMUser * user, NMConference * conf) | |
| 1020 { | |
| 1021 if (user == NULL || conf == NULL) | |
| 1022 return; | |
| 1023 | |
| 1024 nm_conference_add_ref(conf); | |
| 1025 user->conferences = g_slist_append(user->conferences, conf); | |
| 1026 } | |
| 1027 | |
| 1028 void | |
| 1029 nm_conference_list_remove(NMUser * user, NMConference * conf) | |
| 1030 { | |
| 1031 if (user == NULL || conf == NULL) | |
| 1032 return; | |
| 1033 | |
| 1034 if (g_slist_find(user->conferences, conf)) { | |
| 1035 user->conferences = g_slist_remove(user->conferences, conf); | |
| 1036 nm_release_conference(conf); | |
| 1037 } | |
| 1038 } | |
| 1039 | |
| 1040 void | |
| 1041 nm_conference_list_free(NMUser * user) | |
| 1042 { | |
| 1043 GSList *cnode; | |
| 1044 NMConference *conference; | |
| 1045 | |
| 1046 if (user == NULL) | |
| 1047 return; | |
| 1048 | |
| 1049 if (user->conferences) { | |
| 1050 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1051 conference = cnode->data; | |
| 1052 cnode->data = NULL; | |
| 1053 nm_release_conference(conference); | |
| 1054 } | |
| 1055 | |
| 1056 g_slist_free(user->conferences); | |
| 1057 user->conferences = NULL; | |
| 1058 } | |
| 1059 } | |
| 1060 | |
| 1061 NMConference * | |
| 1062 nm_conference_list_find(NMUser * user, const char *guid) | |
| 1063 { | |
| 1064 GSList *cnode; | |
| 1065 NMConference *conference = NULL, *tmp; | |
| 1066 | |
| 1067 if (user == NULL || guid == NULL) | |
| 1068 return NULL; | |
| 1069 | |
| 1070 if (user->conferences) { | |
| 1071 for (cnode = user->conferences; cnode; cnode = cnode->next) { | |
| 1072 tmp = cnode->data; | |
| 1073 if (nm_are_guids_equal(nm_conference_get_guid(tmp), guid)) { | |
| 1074 conference = tmp; | |
| 1075 break; | |
| 1076 } | |
| 1077 } | |
| 1078 } | |
| 1079 | |
| 1080 return conference; | |
| 1081 } | |
| 1082 | |
| 1083 gboolean | |
| 1084 nm_are_guids_equal(const char *guid1, const char *guid2) | |
| 1085 { | |
| 1086 if (guid1 == NULL || guid2 == NULL) | |
| 1087 return FALSE; | |
| 1088 | |
| 1089 return (strncmp(guid1, guid2, CONF_GUID_END) == 0); | |
| 1090 } | |
| 1091 | |
| 1092 void | |
| 1093 nm_user_add_contact(NMUser * user, NMContact * contact) | |
| 1094 { | |
| 1095 if (user == NULL || contact == NULL) | |
| 1096 return; | |
| 1097 | |
| 1098 nm_contact_add_ref(contact); | |
| 1099 | |
| 1100 g_hash_table_insert(user->contacts, | |
| 1101 g_utf8_strdown(nm_contact_get_dn(contact), -1), contact); | |
| 1102 } | |
| 1103 | |
| 1104 void | |
| 1105 nm_user_add_user_record(NMUser * user, NMUserRecord * user_record) | |
| 1106 { | |
| 1107 nm_user_record_add_ref(user_record); | |
| 1108 | |
| 1109 g_hash_table_insert(user->user_records, | |
| 1110 g_utf8_strdown(nm_user_record_get_dn(user_record), -1), | |
| 1111 user_record); | |
| 1112 | |
| 1113 g_hash_table_insert(user->display_id_to_dn, | |
| 1114 g_utf8_strdown(nm_user_record_get_display_id(user_record), | |
| 1115 -1), | |
| 1116 g_utf8_strdown(nm_user_record_get_dn(user_record), -1)); | |
| 1117 | |
| 1118 } | |
| 1119 | |
| 1120 nm_event_cb | |
| 1121 nm_user_get_event_callback(NMUser * user) | |
| 1122 { | |
| 1123 if (user == NULL) | |
| 1124 return NULL; | |
| 1125 | |
| 1126 return user->evt_callback; | |
| 1127 } | |
| 1128 | |
| 1129 NMConn * | |
| 1130 nm_user_get_conn(NMUser * user) | |
| 1131 { | |
| 1132 if (user == NULL) | |
| 1133 return NULL; | |
| 1134 | |
| 1135 return user->conn; | |
| 1136 } | |
| 1137 | |
| 1138 NMERR_T | |
| 1139 nm_create_contact_list(NMUser * user) | |
| 1140 { | |
| 1141 NMERR_T rc = NM_OK; | |
| 1142 NMField *locate = NULL; | |
| 1143 | |
| 1144 if (user == NULL || user->fields == NULL) { | |
| 1145 return NMERR_BAD_PARM; | |
| 1146 } | |
| 1147 | |
| 1148 /* Create the root folder */ | |
| 1149 user->root_folder = nm_create_folder(""); | |
| 1150 | |
| 1151 /* Find the contact list in the login fields */ | |
| 1152 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, user->fields); | |
| 1153 if (locate != NULL) { | |
| 1154 | |
| 1155 /* Add the folders and then the contacts */ | |
| 1156 nm_folder_add_contacts_and_folders(user, user->root_folder, | |
| 1157 (NMField *) (locate->value)); | |
| 1158 | |
| 1159 } | |
| 1160 | |
| 1161 return rc; | |
| 1162 } | |
| 1163 | |
| 1164 void | |
| 1165 nm_destroy_contact_list(NMUser * user) | |
| 1166 { | |
| 1167 if (user == NULL) | |
| 1168 return; | |
| 1169 | |
| 1170 if (user->root_folder) { | |
| 1171 nm_release_folder(user->root_folder); | |
| 1172 user->root_folder = NULL; | |
| 1173 } | |
| 1174 } | |
| 1175 | |
| 1176 NMFolder * | |
| 1177 nm_get_root_folder(NMUser * user) | |
| 1178 { | |
| 1179 if (user == NULL) | |
| 1180 return NULL; | |
| 1181 | |
| 1182 if (user->root_folder == NULL) | |
| 1183 nm_create_contact_list(user); | |
| 1184 | |
| 1185 return user->root_folder; | |
| 1186 } | |
| 1187 | |
| 1188 NMContact * | |
| 1189 nm_find_contact(NMUser * user, const char *name) | |
| 1190 { | |
| 1191 char *str; | |
| 1192 const char *dn = NULL; | |
| 1193 NMContact *contact = NULL; | |
| 1194 | |
| 1195 if (user == NULL || name == NULL) | |
| 1196 return NULL; | |
| 1197 | |
| 1198 str = g_utf8_strdown(name, -1); | |
| 1199 if (strstr(str, "=")) { | |
| 1200 dn = str; | |
| 1201 } else { | |
| 1202 /* Assume that we have a display id instead of a dn */ | |
| 1203 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
| 1204 } | |
| 1205 | |
| 1206 /* Find contact object in reference table */ | |
| 1207 if (dn) { | |
| 1208 contact = (NMContact *) g_hash_table_lookup(user->contacts, dn); | |
| 1209 } | |
| 1210 | |
| 1211 g_free(str); | |
| 1212 return contact; | |
| 1213 } | |
| 1214 | |
| 1215 GList * | |
| 1216 nm_find_contacts(NMUser * user, const char *dn) | |
| 1217 { | |
| 1218 guint32 i, cnt; | |
| 1219 NMFolder *folder; | |
| 1220 NMContact *contact; | |
| 1221 GList *contacts = NULL; | |
| 1222 | |
| 1223 if (user == NULL || dn == NULL) | |
| 1224 return NULL; | |
| 1225 | |
| 1226 /* Check for contact at the root */ | |
| 1227 contact = nm_folder_find_contact(user->root_folder, dn); | |
| 1228 if (contact) { | |
| 1229 contacts = g_list_append(contacts, contact); | |
| 1230 contact = NULL; | |
| 1231 } | |
| 1232 | |
| 1233 /* Check for contact in each subfolder */ | |
| 1234 cnt = nm_folder_get_subfolder_count(user->root_folder); | |
| 1235 for (i = 0; i < cnt; i++) { | |
| 1236 folder = nm_folder_get_subfolder(user->root_folder, i); | |
| 1237 contact = nm_folder_find_contact(folder, dn); | |
| 1238 if (contact) { | |
| 1239 contacts = g_list_append(contacts, contact); | |
| 1240 contact = NULL; | |
| 1241 } | |
| 1242 } | |
| 1243 | |
| 1244 return contacts; | |
| 1245 } | |
| 1246 | |
| 1247 NMUserRecord * | |
| 1248 nm_find_user_record(NMUser * user, const char *name) | |
| 1249 { | |
| 1250 char *str = NULL; | |
| 1251 const char *dn = NULL; | |
| 1252 NMUserRecord *user_record = NULL; | |
| 1253 | |
| 1254 if (user == NULL || name == NULL) | |
| 1255 return NULL; | |
| 1256 | |
| 1257 str = g_utf8_strdown(name, -1); | |
| 1258 if (strstr(str, "=")) { | |
| 1259 dn = str; | |
| 1260 } else { | |
| 1261 /* Assume that we have a display id instead of a dn */ | |
| 1262 dn = (const char *) g_hash_table_lookup(user->display_id_to_dn, str); | |
| 1263 } | |
| 1264 | |
| 1265 /* Find user record in reference table */ | |
| 1266 if (dn) { | |
| 1267 user_record = | |
| 1268 (NMUserRecord *) g_hash_table_lookup(user->user_records, dn); | |
| 1269 } | |
| 1270 | |
| 1271 g_free(str); | |
| 1272 return user_record; | |
| 1273 } | |
| 1274 | |
| 1275 const char * | |
| 1276 nm_lookup_dn(NMUser * user, const char *display_id) | |
| 1277 { | |
| 8744 | 1278 const char *dn; |
| 1279 char *lower; | |
| 1280 | |
| 8675 | 1281 if (user == NULL || display_id == NULL) |
| 1282 return NULL; | |
| 1283 | |
| 8744 | 1284 lower = g_utf8_strdown(display_id, -1); |
| 1285 dn = g_hash_table_lookup(user->display_id_to_dn, lower); | |
| 1286 g_free(lower); | |
| 1287 | |
| 1288 return dn; | |
| 8675 | 1289 } |
| 1290 | |
| 1291 NMFolder * | |
| 1292 nm_find_folder(NMUser * user, const char *name) | |
| 1293 { | |
| 1294 NMFolder *folder = NULL, *temp; | |
| 1295 int i, num_folders; | |
| 1296 const char *tname = NULL; | |
| 1297 | |
| 1298 if (user == NULL || name == NULL) | |
| 1299 return NULL; | |
| 1300 | |
| 1301 if (*name == '\0') | |
| 1302 return user->root_folder; | |
| 1303 | |
| 1304 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
| 1305 for (i = 0; i < num_folders; i++) { | |
| 1306 temp = nm_folder_get_subfolder(user->root_folder, i); | |
| 1307 tname = nm_folder_get_name(temp); | |
| 1308 | |
| 1309 if (tname && (strcmp(tname, name) == 0)) { | |
| 1310 folder = temp; | |
| 1311 break; | |
| 1312 } | |
| 1313 } | |
| 1314 | |
| 1315 return folder; | |
| 1316 } | |
| 1317 | |
| 1318 NMFolder * | |
| 1319 nm_find_folder_by_id(NMUser * user, int object_id) | |
| 1320 { | |
| 1321 NMFolder *folder = NULL, *temp; | |
| 1322 int i, num_folders; | |
| 1323 | |
| 1324 if (user == NULL) | |
| 1325 return NULL; | |
| 1326 | |
| 1327 if (object_id == 0) | |
| 1328 return user->root_folder; | |
| 1329 | |
| 1330 num_folders = nm_folder_get_subfolder_count(user->root_folder); | |
| 1331 for (i = 0; i < num_folders; i++) { | |
| 1332 temp = nm_folder_get_subfolder(user->root_folder, i); | |
| 1333 if (nm_folder_get_id(temp) == object_id) { | |
| 1334 folder = temp; | |
| 1335 break; | |
| 1336 } | |
| 1337 } | |
| 1338 | |
| 1339 return folder; | |
| 1340 } | |
| 1341 | |
| 1342 static void | |
| 1343 _handle_multiple_get_details_joinconf_cb(NMUser * user, NMERR_T ret_code, | |
| 1344 gpointer resp_data, gpointer user_data) | |
| 1345 { | |
| 1346 NMRequest *request = user_data; | |
| 1347 NMUserRecord *user_record = resp_data; | |
| 1348 NMConference *conference; | |
| 1349 GSList *list, *node; | |
| 1350 | |
| 1351 if (user == NULL || resp_data == NULL || user_data == NULL) | |
| 1352 return; | |
| 1353 | |
| 1354 conference = nm_request_get_data(request); | |
| 1355 list = nm_request_get_user_define(request); | |
| 1356 | |
| 1357 if (ret_code == 0 && conference && list) { | |
| 1358 | |
| 1359 /* Add the user to the conference */ | |
| 1360 nm_conference_add_participant(conference, user_record); | |
| 1361 | |
| 1362 /* Find the user in the list and remove it */ | |
| 1363 for (node = list; node; node = node->next) { | |
| 1364 if (nm_utf8_str_equal(nm_user_record_get_dn(user_record), | |
| 1365 (const char *) node->data)) { | |
| 1366 list = g_slist_remove(list, node->data); | |
| 1367 nm_request_set_user_define(request, list); | |
| 1368 g_free(node->data); | |
| 1369 break; | |
| 1370 } | |
| 1371 } | |
| 1372 | |
| 1373 /* Time to callback? */ | |
| 1374 if (g_slist_length(list) == 0) { | |
| 1375 nm_response_cb cb = nm_request_get_callback(request); | |
| 1376 | |
| 1377 if (cb) { | |
| 1378 cb(user, 0, conference, conference); | |
| 1379 } | |
| 1380 g_slist_free(list); | |
| 1381 nm_release_request(request); | |
| 1382 } | |
| 1383 } | |
| 1384 } | |
| 1385 | |
| 1386 NMERR_T | |
| 1387 nm_call_handler(NMUser * user, NMRequest * request, NMField * fields) | |
| 1388 { | |
| 1389 NMERR_T rc = NM_OK, ret_code = NM_OK; | |
| 1390 NMConference *conf = NULL; | |
| 1391 NMUserRecord *user_record = NULL; | |
| 1392 NMField *locate = NULL; | |
| 1393 NMField *field = NULL; | |
| 1394 const char *cmd; | |
| 1395 nm_response_cb cb; | |
| 1396 gboolean done = TRUE; | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1397 |
| 8675 | 1398 if (user == NULL || request == NULL || fields == NULL) |
| 1399 return NMERR_BAD_PARM; | |
| 1400 | |
| 1401 /* Get the return code */ | |
| 1402 field = nm_locate_field(NM_A_SZ_RESULT_CODE, fields); | |
| 1403 if (field) { | |
| 1404 ret_code = atoi((char *) field->value); | |
| 1405 } else { | |
| 1406 ret_code = NMERR_PROTOCOL; | |
| 1407 } | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
1408 |
| 8675 | 1409 cmd = nm_request_get_cmd(request); |
| 1410 if (ret_code == NM_OK && cmd != NULL) { | |
| 1411 | |
| 1412 if (strcmp("login", cmd) == 0) { | |
| 1413 | |
| 1414 user->user_record = nm_create_user_record_from_fields(fields); | |
| 1415 | |
| 1416 /* Save the users fields */ | |
| 8744 | 1417 user->fields = nm_copy_field_array(fields); |
| 8675 | 1418 |
| 1419 } else if (strcmp("setstatus", cmd) == 0) { | |
| 1420 | |
| 1421 /* Nothing to do */ | |
| 1422 | |
| 1423 } else if (strcmp("createconf", cmd) == 0) { | |
| 1424 | |
| 1425 conf = (NMConference *) nm_request_get_data(request); | |
| 1426 | |
| 1427 /* get the convo guid */ | |
| 1428 locate = nm_locate_field(NM_A_FA_CONVERSATION, fields); | |
| 1429 if (locate) { | |
| 1430 field = | |
| 1431 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->value); | |
| 1432 if (field) { | |
| 1433 nm_conference_set_guid(conf, (char *) field->value); | |
| 1434 } | |
| 1435 } | |
| 1436 | |
| 1437 nm_conference_list_add(user, conf); | |
| 1438 | |
| 1439 } else if (strcmp("leaveconf", cmd) == 0) { | |
| 1440 | |
| 1441 conf = (NMConference *) nm_request_get_data(request); | |
| 1442 nm_conference_list_remove(user, conf); | |
| 1443 | |
| 1444 } else if (strcmp("joinconf", cmd) == 0) { | |
| 1445 GSList *list = NULL, *node; | |
| 1446 | |
| 1447 conf = nm_request_get_data(request); | |
| 1448 | |
| 1449 locate = nm_locate_field(NM_A_FA_CONTACT_LIST, fields); | |
| 1450 if (locate && locate->value != 0) { | |
| 1451 | |
| 1452 field = (NMField *) locate->value; | |
| 1453 while ((field = nm_locate_field(NM_A_SZ_DN, field))) { | |
| 1454 if (field && field->value != 0) { | |
| 1455 | |
| 1456 if (nm_utf8_str_equal | |
| 1457 (nm_user_record_get_dn(user->user_record), | |
| 1458 (const char *) field->value)) { | |
| 1459 field++; | |
| 1460 continue; | |
| 1461 } | |
| 1462 | |
| 1463 user_record = | |
| 1464 nm_find_user_record(user, | |
| 1465 (const char *) field->value); | |
| 1466 if (user_record == NULL) { | |
| 1467 list = | |
| 1468 g_slist_append(list, | |
| 1469 g_strdup((char *) field->value)); | |
| 1470 } else { | |
| 1471 nm_conference_add_participant(conf, user_record); | |
| 1472 } | |
| 1473 } | |
| 1474 field++; | |
| 1475 } | |
| 1476 | |
| 1477 if (list != NULL) { | |
| 1478 | |
| 1479 done = FALSE; | |
| 1480 nm_request_add_ref(request); | |
| 1481 nm_request_set_user_define(request, list); | |
| 1482 for (node = list; node; node = node->next) { | |
| 1483 | |
| 1484 nm_send_get_details(user, (const char *) node->data, | |
| 1485 _handle_multiple_get_details_joinconf_cb, | |
| 1486 request); | |
| 1487 } | |
| 1488 } | |
| 1489 } | |
| 1490 | |
| 1491 } else if (strcmp("getdetails", cmd) == 0) { | |
| 1492 | |
| 1493 locate = nm_locate_field(NM_A_FA_RESULTS, fields); | |
| 1494 if (locate && locate->value != 0) { | |
| 1495 | |
| 1496 user_record = nm_create_user_record_from_fields(locate); | |
| 1497 if (user_record) { | |
| 1498 NMUserRecord *tmp; | |
| 1499 | |
| 1500 tmp = | |
| 1501 nm_find_user_record(user, | |
| 1502 nm_user_record_get_dn(user_record)); | |
| 1503 if (tmp) { | |
| 1504 | |
| 1505 /* Update the existing user record */ | |
| 1506 nm_user_record_copy(tmp, user_record); | |
| 1507 nm_release_user_record(user_record); | |
| 1508 user_record = tmp; | |
| 1509 | |
| 1510 } else { | |
| 1511 | |
| 1512 nm_user_add_user_record(user, user_record); | |
| 1513 nm_release_user_record(user_record); | |
| 1514 | |
| 1515 } | |
| 1516 | |
| 1517 /* Response data is new user record */ | |
| 1518 nm_request_set_data(request, (gpointer) user_record); | |
| 1519 } | |
| 1520 | |
| 1521 } | |
| 1522 | |
| 1523 } else if (strcmp("createfolder", cmd) == 0) { | |
| 1524 | |
| 1525 _update_contact_list(user, fields); | |
| 1526 | |
| 1527 } else if (strcmp("createcontact", cmd) == 0) { | |
| 1528 | |
| 1529 _update_contact_list(user, fields); | |
| 1530 | |
| 1531 locate = | |
| 1532 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->value); | |
| 1533 if (locate) { | |
| 1534 | |
| 1535 NMContact *new_contact = | |
| 1536 nm_folder_find_item_by_object_id(user->root_folder, | |
| 1537 atoi((char *) locate-> | |
| 1538 value)); | |
| 1539 | |
| 1540 if (new_contact) { | |
| 1541 | |
| 1542 /* Add the contact to our cache */ | |
| 1543 nm_user_add_contact(user, new_contact); | |
| 1544 | |
| 1545 /* Set the contact as the response data */ | |
| 1546 nm_request_set_data(request, (gpointer) new_contact); | |
| 1547 | |
| 1548 } | |
| 1549 | |
| 1550 } | |
| 1551 | |
| 1552 } else if (strcmp("deletecontact", cmd) == 0) { | |
| 1553 | |
| 1554 _update_contact_list(user, fields); | |
| 1555 | |
| 1556 } else if (strcmp("movecontact", cmd) == 0) { | |
| 1557 | |
| 1558 _update_contact_list(user, fields); | |
| 1559 | |
| 1560 } else if (strcmp("getstatus", cmd) == 0) { | |
| 1561 | |
| 1562 locate = nm_locate_field(NM_A_SZ_STATUS, fields); | |
| 1563 if (locate) { | |
| 1564 nm_user_record_set_status((NMUserRecord *) | |
| 1565 nm_request_get_data(request), | |
| 1566 atoi((char *) locate->value), NULL); | |
| 1567 } | |
| 1568 | |
| 1569 } else if (strcmp("updateitem", cmd) == 0) { | |
| 1570 | |
| 1571 /* Nothing extra to do here */ | |
| 1572 | |
| 1573 } else { | |
| 1574 | |
| 1575 /* Nothing to do, just print debug message */ | |
| 1576 gaim_debug(GAIM_DEBUG_INFO, "novell", | |
| 1577 "nm_call_handler(): Unknown request command, %s\n", cmd); | |
| 1578 | |
| 1579 } | |
| 1580 } | |
| 1581 | |
| 1582 if (done && (cb = nm_request_get_callback(request))) { | |
| 1583 | |
| 1584 cb(user, ret_code, nm_request_get_data(request), | |
| 1585 nm_request_get_user_define(request)); | |
| 1586 | |
| 1587 } | |
| 1588 | |
| 1589 return rc; | |
| 1590 } | |
| 1591 | |
| 1592 static NMERR_T | |
| 1593 nm_process_response(NMUser * user) | |
| 1594 { | |
| 1595 NMERR_T rc = NM_OK; | |
| 1596 NMField *fields = NULL; | |
| 1597 NMField *field = NULL; | |
| 1598 NMConn *conn = user->conn; | |
| 1599 NMRequest *req = NULL; | |
| 1600 | |
| 1601 rc = nm_read_header(conn); | |
| 1602 if (rc == NM_OK) { | |
| 1603 rc = nm_read_fields(conn, -1, &fields); | |
| 1604 } | |
| 1605 | |
| 1606 if (rc == NM_OK) { | |
| 1607 field = nm_locate_field(NM_A_SZ_TRANSACTION_ID, fields); | |
| 1608 if (field != NULL && field->value != 0) { | |
| 1609 req = nm_conn_find_request(conn, atoi((char *) field->value)); | |
| 1610 if (req != NULL) { | |
| 1611 rc = nm_call_handler(user, req, fields); | |
| 1612 } | |
| 1613 } | |
| 1614 } | |
| 1615 | |
| 8744 | 1616 if (fields) |
| 1617 nm_free_fields(&fields); | |
| 1618 | |
| 8675 | 1619 return rc; |
| 1620 } | |
| 1621 | |
| 1622 /* | |
| 1623 * Some utility functions...haven't figured out where | |
| 1624 * they belong yet. | |
| 1625 */ | |
| 1626 gint | |
| 1627 nm_utf8_strcasecmp(gconstpointer str1, gconstpointer str2) | |
| 1628 { | |
| 1629 gint rv; | |
| 1630 char *str1_down = g_utf8_strdown(str1, -1); | |
| 1631 char *str2_down = g_utf8_strdown(str2, -1); | |
| 1632 | |
| 1633 rv = g_utf8_collate(str1_down, str2_down); | |
| 1634 | |
| 1635 g_free(str1_down); | |
| 1636 g_free(str2_down); | |
| 1637 | |
| 1638 return rv; | |
| 1639 } | |
| 1640 | |
| 1641 gboolean | |
| 1642 nm_utf8_str_equal(gconstpointer str1, gconstpointer str2) | |
| 1643 { | |
| 1644 return (nm_utf8_strcasecmp(str1, str2) == 0); | |
| 1645 } | |
| 1646 | |
| 1647 char * | |
| 1648 nm_typed_to_dotted(const char *typed) | |
| 1649 { | |
| 1650 unsigned i = 0, j = 0; | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1651 char *dotted; |
| 8675 | 1652 |
| 1653 if (typed == NULL) | |
| 1654 return NULL; | |
| 1655 | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1656 dotted = g_new0(char, strlen(typed)); |
| 8675 | 1657 |
| 1658 do { | |
| 1659 | |
| 1660 /* replace comma with a dot */ | |
| 1661 if (j != 0) { | |
| 1662 dotted[j] = '.'; | |
| 1663 j++; | |
| 1664 } | |
| 1665 | |
| 1666 /* skip the type */ | |
| 1667 while (typed[i] != '\0' && typed[i] != '=') | |
| 1668 i++; | |
| 1669 | |
| 1670 /* verify that we aren't running off the end */ | |
| 1671 if (typed[i] == '\0') { | |
| 1672 dotted[j] = '\0'; | |
| 1673 break; | |
| 1674 } | |
| 1675 | |
| 1676 i++; | |
| 1677 | |
| 1678 /* copy the object name to context */ | |
| 1679 while (typed[i] != '\0' && typed[i] != ',') { | |
| 1680 dotted[j] = typed[i]; | |
| 1681 j++; | |
| 1682 i++; | |
| 1683 } | |
| 1684 | |
| 1685 } while (typed[i] != '\0'); | |
| 1686 | |
| 1687 return dotted; | |
| 1688 } | |
| 1689 | |
| 1690 static void | |
| 1691 _update_contact_list(NMUser * user, NMField * fields) | |
| 1692 { | |
| 1693 NMField *list, *cursor, *locate; | |
| 1694 gint objid1; | |
| 1695 NMContact *contact; | |
| 1696 NMFolder *folder; | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1697 gpointer item; |
| 8675 | 1698 |
| 1699 if (user == NULL || fields == NULL) | |
| 1700 return; | |
| 1701 | |
| 1702 /* Is it wrapped in a RESULTS array? */ | |
| 1703 if (strcmp(fields->tag, NM_A_FA_RESULTS) == 0) { | |
| 1704 list = (NMField *) fields->value; | |
| 1705 } else { | |
| 1706 list = fields; | |
| 1707 } | |
| 1708 | |
| 1709 /* Update the cached contact list */ | |
| 1710 cursor = (NMField *) list->value; | |
| 1711 while (cursor->tag != NULL) { | |
| 1712 if ((g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) || | |
| 1713 (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0)) { | |
| 1714 | |
| 1715 locate = | |
| 1716 nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) cursor->value); | |
| 1717 if (locate != NULL && locate->value != 0) { | |
| 1718 objid1 = atoi((char *) locate->value); | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8744
diff
changeset
|
1719 item = |
| 8675 | 1720 nm_folder_find_item_by_object_id(user->root_folder, objid1); |
| 1721 if (item != NULL) { | |
| 1722 if (cursor->method == NMFIELD_METHOD_ADD) { | |
| 1723 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 1724 contact = (NMContact *) item; | |
| 1725 nm_contact_update_list_properties(contact, cursor); | |
| 1726 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 1727 == 0) { | |
| 1728 folder = (NMFolder *) item; | |
| 1729 nm_folder_update_list_properties(folder, cursor); | |
| 1730 } | |
| 1731 } else if (cursor->method == NMFIELD_METHOD_DELETE) { | |
| 1732 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 1733 contact = (NMContact *) item; | |
| 1734 folder = | |
| 1735 nm_find_folder_by_id(user, | |
| 1736 nm_contact_get_parent_id | |
| 1737 (contact)); | |
| 1738 if (folder) { | |
| 1739 nm_folder_remove_contact(folder, contact); | |
| 1740 } | |
| 1741 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 1742 == 0) { | |
| 1743 /* TODO: write nm_folder_remove_folder */ | |
| 1744 /* ignoring for now, should not be a big deal */ | |
| 1745 /* folder = (NMFolder *) item;*/ | |
| 1746 /* nm_folder_remove_folder(user->root_folder, folder);*/ | |
| 1747 } | |
| 1748 } | |
| 1749 } else { | |
| 1750 | |
| 1751 if (cursor->method == NMFIELD_METHOD_ADD) { | |
| 1752 | |
| 1753 /* Not found, so we need to add it */ | |
| 1754 if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { | |
| 1755 | |
| 1756 const char *dn = NULL; | |
| 1757 | |
| 1758 locate = | |
| 1759 nm_locate_field(NM_A_SZ_DN, | |
| 1760 (NMField *) cursor->value); | |
| 1761 if (locate != NULL && locate->value != 0) { | |
| 1762 dn = (const char *) locate->value; | |
| 1763 if (dn != NULL) { | |
| 1764 contact = | |
| 1765 nm_create_contact_from_fields(cursor); | |
| 1766 if (contact) { | |
| 1767 nm_folder_add_contact_to_list(user-> | |
| 1768 root_folder, | |
| 1769 contact); | |
| 1770 nm_release_contact(contact); | |
| 1771 } | |
| 1772 } | |
| 1773 } | |
| 1774 } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) | |
| 1775 == 0) { | |
| 1776 folder = nm_create_folder_from_fields(cursor); | |
| 1777 nm_folder_add_folder_to_list(user->root_folder, | |
| 1778 folder); | |
| 1779 nm_release_folder(folder); | |
| 1780 } | |
| 1781 } | |
| 1782 } | |
| 1783 } | |
| 1784 } | |
| 1785 cursor++; | |
| 1786 } | |
| 1787 } |
