Changeset d1356cb
- Timestamp:
- 2012-11-12T23:57:43Z (12 years ago)
- Branches:
- master
- Children:
- b006464
- Parents:
- aef2077
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_lib.c
raef2077 rd1356cb 448 448 #endif 449 449 450 static char* expand_entities(char* text, const json_value *entities); 451 450 452 /** 451 453 * Function to fill a twitter_xml_status struct. … … 500 502 txs_free(rtxs); 501 503 } else if (entities) { 502 JSON_O_FOREACH (entities, k, v) { 503 int i; 504 505 if (v->type != json_array) 506 continue; 507 if (strcmp(k, "urls") != 0 && strcmp(k, "media") != 0) 504 txs->text = expand_entities(txs->text, entities); 505 } 506 507 return txs->text && txs->user && txs->id; 508 } 509 510 /** 511 * Function to fill a twitter_xml_status struct (DM variant). 512 */ 513 static gboolean twitter_xt_get_dm(const json_value *node, struct twitter_xml_status *txs) 514 { 515 const json_value *entities = NULL; 516 517 if (node->type != json_object) 518 return FALSE; 519 520 JSON_O_FOREACH (node, k, v) { 521 if (strcmp("text", k) == 0 && v->type == json_string) { 522 txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1); 523 } else if (strcmp("created_at", k) == 0 && v->type == json_string) { 524 struct tm parsed; 525 526 /* Very sensitive to changes to the formatting of 527 this field. :-( Also assumes the timezone used 528 is UTC since C time handling functions suck. */ 529 if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) 530 txs->created_at = mktime_utc(&parsed); 531 } else if (strcmp("sender", k) == 0 && v->type == json_object) { 532 txs->user = twitter_xt_get_user(v); 533 } else if (strcmp("id", k) == 0 && v->type == json_integer) { 534 txs->id = v->u.integer; 535 } 536 } 537 538 if (entities) { 539 txs->text = expand_entities(txs->text, entities); 540 } 541 542 return txs->text && txs->user && txs->id; 543 } 544 545 static char* expand_entities(char* text, const json_value *entities) { 546 JSON_O_FOREACH (entities, k, v) { 547 int i; 548 549 if (v->type != json_array) 550 continue; 551 if (strcmp(k, "urls") != 0 && strcmp(k, "media") != 0) 552 continue; 553 554 for (i = 0; i < v->u.array.length; i ++) { 555 if (v->u.array.values[i]->type != json_object) 508 556 continue; 509 557 510 for (i = 0; i < v->u.array.length; i ++) { 511 if (v->u.array.values[i]->type != json_object) 512 continue; 513 514 const char *kort = json_o_str(v->u.array.values[i], "url"); 515 const char *disp = json_o_str(v->u.array.values[i], "display_url"); 516 char *pos, *new; 517 518 if (!kort || !disp || !(pos = strstr(txs->text, kort))) 519 continue; 520 521 *pos = '\0'; 522 new = g_strdup_printf("%s%s <%s>%s", txs->text, kort, 523 disp, pos + strlen(kort)); 524 525 g_free(txs->text); 526 txs->text = new; 527 } 558 const char *kort = json_o_str(v->u.array.values[i], "url"); 559 const char *disp = json_o_str(v->u.array.values[i], "display_url"); 560 char *pos, *new; 561 562 if (!kort || !disp || !(pos = strstr(text, kort))) 563 continue; 564 565 *pos = '\0'; 566 new = g_strdup_printf("%s%s <%s>%s", text, kort, 567 disp, pos + strlen(kort)); 568 569 g_free(text); 570 text = new; 528 571 } 529 572 } 530 531 return t xs->text && txs->user && txs->id;573 574 return text; 532 575 } 533 576 … … 785 828 { 786 829 struct twitter_xml_status *txs = g_new0(struct twitter_xml_status, 1); 830 json_value *c; 787 831 788 832 if (twitter_xt_get_status(o, txs)) { 789 833 GSList *output = g_slist_append(NULL, txs); 790 834 twitter_groupchat(ic, output); 835 txs_free(txs); 836 g_slist_free(output); 837 return TRUE; 838 } else if ((c = json_o_get(o, "direct_message")) && 839 twitter_xt_get_dm(c, txs)) { 840 GSList *output = g_slist_append(NULL, txs); 841 twitter_private_message_chat(ic, output); 791 842 txs_free(txs); 792 843 g_slist_free(output);
Note: See TracChangeset
for help on using the changeset viewer.