- Timestamp:
- 2012-11-08T22:38:20Z (12 years ago)
- Branches:
- master
- Children:
- fb351ce
- Parents:
- 0688e99
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_lib.c
r0688e99 r8e3b7ac 272 272 273 273 txl->list = g_slist_prepend(txl->list, 274 g_strdup_printf("%l d", c->u.array.values[i]->u.integer));274 g_strdup_printf("%lld", c->u.array.values[i]->u.integer)); 275 275 276 276 } … … 403 403 } 404 404 405 struct twitter_xml_user *twitter_xt_get_user(const json_value *node) 406 { 407 struct twitter_xml_user *txu; 408 409 txu = g_new0(struct twitter_xml_user, 1); 410 txu->name = g_strdup(json_o_str(node, "name")); 411 txu->screen_name = g_strdup(json_o_str(node, "screen_name")); 412 413 return txu; 414 } 415 405 416 /** 406 417 * Function to fill a twitter_xml_list struct. … … 422 433 // Walk over the nodes children. 423 434 for (i = 0; i < node->u.array.length; i ++) { 424 txu = g_new0(struct twitter_xml_user, 1); 425 txu->name = g_strdup(json_o_str(node->u.array.values[i], "name")); 426 txu->screen_name = g_strdup(json_o_str(node->u.array.values[i], "screen_name")); 427 txl->list = g_slist_prepend(txl->list, txu); 435 txu = twitter_xt_get_user(node->u.array.values[i]); 436 if (txu) 437 txl->list = g_slist_prepend(txl->list, txu); 428 438 } 429 439 … … 445 455 * - the user in a twitter_xml_user struct. 446 456 */ 447 static xt_status twitter_xt_get_status(struct xt_node *node, struct twitter_xml_status *txs) 448 { 449 struct xt_node *child, *rt = NULL; 450 451 // Walk over the nodes children. 452 for (child = node->children; child; child = child->next) { 453 if (g_strcasecmp("text", child->name) == 0) { 454 txs->text = g_memdup(child->text, child->text_len + 1); 455 } else if (g_strcasecmp("retweeted_status", child->name) == 0) { 456 rt = child; 457 } else if (g_strcasecmp("created_at", child->name) == 0) { 457 static xt_status twitter_xt_get_status(const json_value *node, struct twitter_xml_status *txs) 458 { 459 const json_value *c, *rt = NULL, *entities = NULL; 460 int i; 461 462 if (node->type != json_object) 463 return XT_ABORT; 464 465 for (i = 0; i < node->u.object.length; i ++) { 466 const char *k = node->u.object.values[i].name; 467 const json_value *v = node->u.object.values[i].value; 468 469 if (strcmp("text", k) == 0 && v->type == json_string) { 470 txs->text = g_memdup(v->u.string.ptr, v->u.string.length); 471 } else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) { 472 rt = v; 473 } else if (strcmp("created_at", k) == 0 && v->type == json_string) { 458 474 struct tm parsed; 459 475 … … 461 477 this field. :-( Also assumes the timezone used 462 478 is UTC since C time handling functions suck. */ 463 if (strptime( child->text, TWITTER_TIME_FORMAT, &parsed) != NULL)479 if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) 464 480 txs->created_at = mktime_utc(&parsed); 465 } else if (g_strcasecmp("user", child->name) == 0) { 466 txs->user = g_new0(struct twitter_xml_user, 1); 467 // twitter_xt_get_user(child, txs->user); 468 } else if (g_strcasecmp("id", child->name) == 0) { 469 txs->id = g_ascii_strtoull(child->text, NULL, 10); 470 } else if (g_strcasecmp("in_reply_to_status_id", child->name) == 0) { 471 txs->reply_to = g_ascii_strtoull(child->text, NULL, 10); 481 } else if (strcmp("user", k) == 0 && v->type == json_object) { 482 txs->user = twitter_xt_get_user(v); 483 } else if (strcmp("id", k) == 0 && v->type == json_integer) { 484 txs->id = v->u.integer; 485 } else if (strcmp("in_reply_to_status_id", k) == 0 && v->type == json_integer) { 486 txs->reply_to = v->u.integer; 487 } else if (strcmp("entities", k) == 0 && v->type == json_object) { 488 txs->reply_to = v->u.integer; 472 489 } 473 490 } … … 485 502 txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text); 486 503 txs_free(rtxs); 487 } else { 488 struct xt_node *urls, *url; 489 490 urls = xt_find_path(node, "entities"); 491 if (urls != NULL) 492 urls = urls->children; 493 for (; urls; urls = urls->next) { 494 if (strcmp(urls->name, "urls") != 0 && strcmp(urls->name, "media") != 0) 504 } else if (entities && NULL) { 505 JSON_O_FOREACH (entities, k, v) { 506 int i; 507 508 if (v->type != json_array) 509 continue; 510 if (strcmp(k, "urls") != 0 && strcmp(k, "media") != 0) 495 511 continue; 496 512 497 for (url = urls ? urls->children : NULL; url; url = url->next) { 498 /* "short" is a reserved word. :-P */ 499 struct xt_node *kort = xt_find_node(url->children, "url"); 500 struct xt_node *disp = xt_find_node(url->children, "display_url"); 513 for (i = 0; i < v->u.array.length; i ++) { 514 if (v->u.array.values[i]->type != json_object) 515 continue; 516 517 const char *kort = json_o_str(v->u.array.values[i], "url"); 518 const char *disp = json_o_str(v->u.array.values[i], "display_url"); 501 519 char *pos, *new; 502 520 503 if (!kort || !kort->text || !disp || !disp->text || 504 !(pos = strstr(txs->text, kort->text))) 521 if (!kort || !disp || !(pos = strstr(txs->text, kort))) 505 522 continue; 506 523 507 524 *pos = '\0'; 508 new = g_strdup_printf("%s%s <%s>%s", txs->text, kort ->text,509 disp ->text, pos + strlen(kort->text));525 new = g_strdup_printf("%s%s <%s>%s", txs->text, kort, 526 disp, pos + strlen(kort)); 510 527 511 528 g_free(txs->text); … … 524 541 * - the next_cursor. 525 542 */ 526 static xt_status twitter_xt_get_status_list(struct im_connection *ic, struct xt_node *node,543 static xt_status twitter_xt_get_status_list(struct im_connection *ic, const json_value *node, 527 544 struct twitter_xml_list *txl) 528 545 { 529 546 struct twitter_xml_status *txs; 530 struct xt_node *child;547 json_value *c; 531 548 bee_user_t *bu; 549 int i; 532 550 533 551 // Set the type of the list. 534 552 txl->type = TXL_STATUS; 553 554 if (node->type != json_array) 555 return XT_ABORT; 535 556 536 557 // The root <statuses> node should hold the list of statuses <status> 537 558 // Walk over the nodes children. 538 for (child = node->children; child; child = child->next) { 539 if (g_strcasecmp("status", child->name) == 0) { 540 txs = g_new0(struct twitter_xml_status, 1); 541 twitter_xt_get_status(child, txs); 542 // Put the item in the front of the list. 543 txl->list = g_slist_prepend(txl->list, txs); 544 545 if (txs->user && txs->user->screen_name && 546 (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) { 547 struct twitter_user_data *tud = bu->data; 548 549 if (txs->id > tud->last_id) { 550 tud->last_id = txs->id; 551 tud->last_time = txs->created_at; 552 } 559 for (i = 0; i < node->u.array.length; i ++) { 560 txs = g_new0(struct twitter_xml_status, 1); 561 twitter_xt_get_status(node->u.array.values[i], txs); 562 // Put the item in the front of the list. 563 txl->list = g_slist_prepend(txl->list, txs); 564 565 if (txs->user && txs->user->screen_name && 566 (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) { 567 struct twitter_user_data *tud = bu->data; 568 569 if (txs->id > tud->last_id) { 570 tud->last_id = txs->id; 571 tud->last_time = txs->created_at; 553 572 } 554 } else if (g_strcasecmp("next_cursor", child->name) == 0) {555 // twitter_xt_next_cursor(child, txl);556 573 } 557 574 } … … 879 896 struct im_connection *ic = req->data; 880 897 struct twitter_data *td; 881 struct xt_node *parsed;898 json_value *parsed; 882 899 struct twitter_xml_list *txl; 883 900 … … 912 929 struct im_connection *ic = req->data; 913 930 struct twitter_data *td; 914 struct xt_node *parsed;931 json_value *parsed; 915 932 struct twitter_xml_list *txl; 916 933
Note: See TracChangeset
for help on using the changeset viewer.