Changeset 7b87539
- Timestamp:
- 2010-08-07T19:39:01Z (14 years ago)
- Branches:
- master
- Children:
- 203a2d2
- Parents:
- daae10f
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
rdaae10f r7b87539 652 652 } 653 653 654 /* Split commands (root-style, *not* IRC-style). Handles "quoting of" 655 white\ space in 'various ways'. Returns a NULL-terminated static 656 char** so watch out with nested use! Definitely not thread-safe. */ 654 657 char **split_command_parts( char *command ) 655 658 { -
protocols/twitter/twitter.c
rdaae10f r7b87539 189 189 s->flags |= ACC_SET_OFFLINE_ONLY; 190 190 191 s = set_add( &acc->set, "commands", "true", set_eval_bool, acc ); 192 191 193 s = set_add( &acc->set, "message_length", "140", set_eval_int, acc ); 192 194 … … 273 275 twitter_connections = g_slist_remove( twitter_connections, ic ); 274 276 } 277 278 static void twitter_handle_command( struct im_connection *ic, char *message ); 275 279 276 280 /** … … 302 306 } 303 307 } 304 else if( twitter_length_check(ic, message) )305 twitter_ post_status(ic, message);308 else 309 twitter_handle_command(ic, message); 306 310 } 307 311 else … … 335 339 static void twitter_chat_msg( struct groupchat *c, char *message, int flags ) 336 340 { 337 if( c && message && twitter_length_check( c->ic, message ) ) 338 { 339 char *s, *new = NULL; 340 341 if( ( s = strchr( message, ':' ) ) || 342 ( s = strchr( message, ',' ) ) ) 343 { 344 bee_user_t *bu; 345 346 new = g_strdup( message ); 347 new[s-message] = '\0'; 348 if( ( bu = bee_user_by_handle( c->ic->bee, c->ic, new ) ) ) 349 { 350 sprintf( new, "@%s", bu->handle ); 351 new[s-message+1] = ' '; 352 message = new; 353 } 354 } 355 356 twitter_post_status( c->ic, message ); 357 g_free( new ); 358 } 341 if( c && message ) 342 twitter_handle_command( c->ic, message ); 359 343 } 360 344 … … 410 394 // return value; 411 395 //} 396 397 static void twitter_handle_command( struct im_connection *ic, char *message ) 398 { 399 struct twitter_data *td = ic->proto_data; 400 char *cmds, **cmd; 401 402 cmds = g_strdup( message ); 403 cmd = split_command_parts( cmds ); 404 405 if( cmd[0] == NULL ) 406 { 407 g_free( cmds ); 408 return; 409 } 410 else if( !set_getbool( &ic->set, "commands" ) ) 411 { 412 /* Not supporting commands. */ 413 } 414 else if( g_strcasecmp( cmd[0], "undo" ) == 0 ) 415 { 416 guint64 id; 417 418 if( cmd[1] ) 419 { 420 char *end = NULL; 421 422 id = g_ascii_strtoull( cmd[1], &end, 10 ); 423 if( end == NULL ) 424 id = 0; 425 } 426 else 427 id = td->last_status_id; 428 429 /* TODO: User feedback. */ 430 if( id ) 431 twitter_status_destroy( ic, id ); 432 433 g_free( cmds ); 434 return; 435 } 436 else if( g_strcasecmp( cmd[0], "post" ) == 0 ) 437 { 438 message += 5; 439 } 440 441 { 442 char *s, *new = NULL; 443 bee_user_t *bu; 444 445 if( !twitter_length_check( ic, message ) ) 446 { 447 g_free( cmds ); 448 return; 449 } 450 451 s = cmd[0] + strlen( cmd[0] ) - 1; 452 if( s > cmd[0] && ( *s == ':' || *s == ',' ) ) 453 { 454 *s = '\0'; 455 456 if( ( bu = bee_user_by_handle( ic->bee, ic, cmd[0] ) ) ) 457 { 458 new = g_strdup_printf( "@%s %s", bu->handle, 459 message + ( s - cmd[0] ) + 2 ); 460 message = new; 461 } 462 } 463 464 twitter_post_status( ic, message ); 465 g_free( new ); 466 } 467 g_free( cmds ); 468 } 412 469 413 470 void twitter_initmodule() -
protocols/twitter/twitter.h
rdaae10f r7b87539 44 44 struct oauth_info *oauth_info; 45 45 guint64 home_timeline_id; 46 guint64 last_status_id; /* For undo */ 46 47 gint main_loop_id; 47 48 struct groupchat *home_timeline_gc; -
protocols/twitter/twitter_lib.c
rdaae10f r7b87539 736 736 { 737 737 struct im_connection *ic = req->data; 738 struct twitter_data *td; 738 739 739 740 // Check if the connection is still active. … … 741 742 return; 742 743 744 td = ic->proto_data; 745 td->last_status_id = 0; 746 743 747 // Check if the HTTP request went well. 744 748 if (req->status_code != 200) { … … 746 750 imcb_error(ic, "HTTP error: %s", twitter_parse_error(req)); 747 751 return; 752 } 753 754 if (req->body_size > 0) 755 { 756 struct xt_parser *xp = NULL; 757 struct xt_node *node; 758 759 xp = xt_new(NULL, NULL); 760 xt_feed(xp, req->reply_body, req->body_size); 761 762 if ((node = xt_find_node(xp->root, "status")) && 763 (node = xt_find_node(node->children, "id")) && node->text) 764 td->last_status_id = g_ascii_strtoull( node->text, NULL, 10 ); 765 766 xt_free(xp); 748 767 } 749 768 } … … 785 804 twitter_http(ic, create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, args, 2); 786 805 } 806 807 void twitter_status_destroy(struct im_connection *ic, guint64 id) 808 { 809 char *url; 810 url = g_strdup_printf("%s%llu%s", TWITTER_STATUS_DESTROY_URL, (unsigned long long) id, ".xml"); 811 twitter_http(ic, url, twitter_http_post, ic, 1, NULL, 0); 812 g_free(url); 813 } -
protocols/twitter/twitter_lib.h
rdaae10f r7b87539 84 84 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *message); 85 85 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create); 86 void twitter_status_destroy(struct im_connection *ic, guint64 id); 86 87 87 88 #endif //_TWITTER_LIB_H
Note: See TracChangeset
for help on using the changeset viewer.