From 885d294fad822b5275a68127ab2ab925d1df1a0e Mon Sep 17 00:00:00 2001 From: jgeboski Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: bee-chat: create temporary users for unknown chat participants The imcb_chat_msg() function is unable to send messages to a chat with a user who was not previously added. This function should allow for the sending of messages with users who are not added. This is suitable for protocols which are sending messages to a chat from random users or a large amount of users which join and part frequently. --- protocols/bee_chat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'protocols') diff --git a/protocols/bee_chat.c b/protocols/bee_chat.c index 1b741730..39110a10 100644 --- a/protocols/bee_chat.c +++ b/protocols/bee_chat.c @@ -84,6 +84,7 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl struct im_connection *ic = c->ic; bee_t *bee = ic->bee; bee_user_t *bu; + gboolean temp; char *s; /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ @@ -91,16 +92,21 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl return; bu = bee_user_by_handle( bee, ic, who ); + temp = ( bu == NULL ); + + if( temp ) + bu = bee_user_new( bee, ic, who, BEE_USER_ONLINE ); s = set_getstr( &ic->bee->set, "strip_html" ); if( ( g_strcasecmp( s, "always" ) == 0 ) || ( ( ic->flags & OPT_DOES_HTML ) && s ) ) strip_html( msg ); - if( bu && bee->ui->chat_msg ) + if( bee->ui->chat_msg ) bee->ui->chat_msg( bee, c, bu, msg, sent_at ); - else - imcb_chat_log( c, "Message from unknown participant %s: %s", who, msg ); + + if( temp ) + bee_user_free( bee, bu ); } void imcb_chat_log( struct groupchat *c, char *format, ... ) -- cgit v1.2.3 From 7549d0074aa4917e62106ac285b05baa1e76c1e9 Mon Sep 17 00:00:00 2001 From: roger Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: twitter: start stream from last tweet on connect/reconnect This works by setting the last_tweet hidden account setting to the ID of the last shown tweet. --- protocols/twitter/twitter.c | 7 +++++++ protocols/twitter/twitter_lib.c | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index ca32b3ce..8e3fec77 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -50,6 +50,10 @@ static void twitter_main_loop_start(struct im_connection *ic) { struct twitter_data *td = ic->proto_data; + char *last_tweet = set_getstr(&ic->acc->set, "last_tweet"); + if (last_tweet) + td->timeline_id = g_ascii_strtoull(last_tweet, NULL, 0); + /* Create the room now that we "logged in". */ if (td->flags & TWITTER_MODE_CHAT) twitter_groupchat_init(ic); @@ -326,6 +330,9 @@ static void twitter_init(account_t * acc) s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); + s = set_add(&acc->set, "last_tweet", "0", NULL, acc); + s->flags |= SET_HIDDEN; + if (strcmp(acc->prpl->name, "twitter") == 0) { s = set_add(&acc->set, "stream", "true", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index b1995e73..3d579d7c 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -720,6 +720,7 @@ static void twitter_status_show_msg(struct im_connection *ic, struct twitter_xml static void twitter_status_show(struct im_connection *ic, struct twitter_xml_status *status) { struct twitter_data *td = ic->proto_data; + char *last_id_str; if (status->user == NULL || status->text == NULL) return; @@ -737,6 +738,10 @@ static void twitter_status_show(struct im_connection *ic, struct twitter_xml_sta // Update the timeline_id to hold the highest id, so that by the next request // we won't pick up the updates already in the list. td->timeline_id = MAX(td->timeline_id, status->rt_id); + + last_id_str = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id); + set_setstr(&ic->acc->set, "last_tweet", last_id_str); + g_free(last_id_str); } static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o); @@ -1001,7 +1006,7 @@ static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_curs args[3] = "true"; if (td->timeline_id) { args[4] = "since_id"; - args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id); + args[5] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id); } if (twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, -- cgit v1.2.3 From 25c4c78e2ddad482dfc9d5a104f76325fcc2f8e5 Mon Sep 17 00:00:00 2001 From: Jason Copenhaver Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: Fix compiler warnings on Cygwin and Mac OS X. * Don't use PIE/PIC on Cygwin/Darwin unless specified as these platforms don't support it. * Cleanup warnings for 'make check' build. * Fix the type issue for getsockopt calls. * Fix enum warnings in Yahoo libs on Mac OS X. --- protocols/oscar/conn.c | 2 +- protocols/yahoo/libyahoo2.c | 15 ++++++++------- protocols/yahoo/yahoo_util.h | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'protocols') diff --git a/protocols/oscar/conn.c b/protocols/oscar/conn.c index a178761e..16b6ac07 100644 --- a/protocols/oscar/conn.c +++ b/protocols/oscar/conn.c @@ -570,7 +570,7 @@ int aim_conn_completeconnect(aim_session_t *sess, aim_conn_t *conn) } if (FD_ISSET(conn->fd, &fds) || FD_ISSET(conn->fd, &wfds)) { - unsigned int len = sizeof(error); + socklen_t len = sizeof(error); if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) error = errno; diff --git a/protocols/yahoo/libyahoo2.c b/protocols/yahoo/libyahoo2.c index cc4724f6..9956514d 100644 --- a/protocols/yahoo/libyahoo2.c +++ b/protocols/yahoo/libyahoo2.c @@ -973,7 +973,8 @@ static void yahoo_process_conference(struct yahoo_input_data *yid, if (pair->key == 14) /* decline/conf message */ msg = pair->value; - if (pair->key == 13) ; + if (pair->key == 13) + ; if (pair->key == 16) /* error */ msg = pair->value; @@ -1794,9 +1795,9 @@ static enum yahoo_status yahoo_https_status_parse(int code) { switch (code) { - case 1212: return YAHOO_LOGIN_PASSWD; - case 1213: return YAHOO_LOGIN_LOCK; - case 1235: return YAHOO_LOGIN_UNAME; + case 1212: return (enum yahoo_status) YAHOO_LOGIN_PASSWD; + case 1213: return (enum yahoo_status) YAHOO_LOGIN_LOCK; + case 1235: return (enum yahoo_status) YAHOO_LOGIN_UNAME; default: return (enum yahoo_status) code; } } @@ -3609,7 +3610,7 @@ void yahoo_send_im(int id, const char *from, const char *who, const char *what, yd = yid->yd; - pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, + pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, (enum ypacket_status) YAHOO_STATUS_OFFLINE, yd->session_id); snprintf(pic_str, sizeof(pic_str), "%d", picture); @@ -3676,7 +3677,7 @@ void yahoo_set_away(int id, enum yahoo_status state, const char *msg, int away) /* Thank you libpurple :) */ if (yd->current_status == YAHOO_STATUS_INVISIBLE) { pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, - YAHOO_STATUS_AVAILABLE, 0); + (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 13, "2"); yahoo_send_packet(yid, pkt, 0); yahoo_packet_free(pkt); @@ -3695,7 +3696,7 @@ void yahoo_set_away(int id, enum yahoo_status state, const char *msg, int away) if (old_status == YAHOO_STATUS_INVISIBLE) { pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, - YAHOO_STATUS_AVAILABLE, 0); + (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); yahoo_packet_hash(pkt, 13, "1"); yahoo_send_packet(yid, pkt, 0); yahoo_packet_free(pkt); diff --git a/protocols/yahoo/yahoo_util.h b/protocols/yahoo/yahoo_util.h index 1f55e064..6099bf8f 100644 --- a/protocols/yahoo/yahoo_util.h +++ b/protocols/yahoo/yahoo_util.h @@ -47,6 +47,9 @@ # endif # define snprintf g_snprintf +#ifdef vsnprintf +#undef vsnprintf +#endif # define vsnprintf g_vsnprintf #else -- cgit v1.2.3 From 4f161e3abeecee0722487e9d61a85f6c953d11bd Mon Sep 17 00:00:00 2001 From: dequis Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: msn_ns_send_adl_1: Fix alloc_strlen coverity warning Allocating insufficient memory for the terminating null of the string --- protocols/msn/ns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index c4b6c462..7646e237 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -880,7 +880,7 @@ static gboolean msn_ns_send_adl_1( gpointer key, gpointer value, gpointer data ) struct bee_user *bu = value; struct msn_buddy_data *bd = bu->data; struct msn_data *md = bu->ic->proto_data; - char handle[strlen(bu->handle)]; + char handle[strlen(bu->handle) + 1]; char *domain; char l[4]; -- cgit v1.2.3 From 85c30041680c8147b8f320ba3eab912027cb0b3e Mon Sep 17 00:00:00 2001 From: dequis Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: twitter: minor cleanup, use G_G(U)INT64_FORMAT instead of casting --- protocols/twitter/twitter_lib.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'protocols') diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 3d579d7c..718867a7 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -233,10 +233,10 @@ static void twitter_http_get_friends_ids(struct http_request *req); */ void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor) { - // Primitive, but hey! It works... + // Primitive, but hey! It works... char *args[2]; args[0] = "cursor"; - args[1] = g_strdup_printf("%lld", (long long) next_cursor); + args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2); g_free(args[1]); @@ -1001,7 +1001,7 @@ static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_curs char *args[6]; args[0] = "cursor"; - args[1] = g_strdup_printf("%lld", (long long) next_cursor); + args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); args[2] = "include_entities"; args[3] = "true"; if (td->timeline_id) { @@ -1037,12 +1037,12 @@ static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor) char *args[6]; args[0] = "cursor"; - args[1] = g_strdup_printf("%lld", (long long) next_cursor); + args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); args[2] = "include_entities"; args[3] = "true"; if (td->timeline_id) { args[4] = "since_id"; - args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id); + args[5] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id); } else { args[4] = "count"; args[5] = g_strdup_printf("%d", set_getint(&ic->acc->set, "show_old_mentions")); @@ -1171,7 +1171,7 @@ void twitter_post_status(struct im_connection *ic, char *msg, guint64 in_reply_t char *args[4] = { "status", msg, "in_reply_to_status_id", - g_strdup_printf("%llu", (unsigned long long) in_reply_to) + g_strdup_printf("%" G_GUINT64_FORMAT, in_reply_to) }; twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, args, in_reply_to ? 4 : 2); @@ -1205,8 +1205,8 @@ void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int void twitter_status_destroy(struct im_connection *ic, guint64 id) { char *url; - url = g_strdup_printf("%s%llu%s", TWITTER_STATUS_DESTROY_URL, - (unsigned long long) id, ".json"); + url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", + TWITTER_STATUS_DESTROY_URL, id, ".json"); twitter_http_f(ic, url, twitter_http_post, ic, 1, NULL, 0, TWITTER_HTTP_USER_ACK); g_free(url); @@ -1215,8 +1215,8 @@ void twitter_status_destroy(struct im_connection *ic, guint64 id) void twitter_status_retweet(struct im_connection *ic, guint64 id) { char *url; - url = g_strdup_printf("%s%llu%s", TWITTER_STATUS_RETWEET_URL, - (unsigned long long) id, ".json"); + url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", + TWITTER_STATUS_RETWEET_URL, id, ".json"); twitter_http_f(ic, url, twitter_http_post, ic, 1, NULL, 0, TWITTER_HTTP_USER_ACK); g_free(url); @@ -1245,7 +1245,7 @@ void twitter_favourite_tweet(struct im_connection *ic, guint64 id) "id", NULL, }; - args[1] = g_strdup_printf("%llu", (unsigned long long) id); + args[1] = g_strdup_printf("%" G_GUINT64_FORMAT, id); twitter_http_f(ic, TWITTER_FAVORITE_CREATE_URL, twitter_http_post, ic, 1, args, 2, TWITTER_HTTP_USER_ACK); g_free(args[1]); -- cgit v1.2.3 From 4cff28fdfca2eaf71a13715b0fda114796091065 Mon Sep 17 00:00:00 2001 From: dequis Date: Fri, 16 Jan 2015 16:50:24 -0300 Subject: Add jabber_normalize_ext() to fix case sensitivity issues with ext jids Also refactor jabber_normalize() to be UTF8 aware. See trac ticket 1106 for more details --- protocols/jabber/jabber_util.c | 46 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 9d8011f8..d6396802 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -329,23 +329,37 @@ int jabber_compare_jid( const char *jid1, const char *jid2 ) return TRUE; } -/* Returns a new string. Don't leak it! */ +/* The /resource part is case sensitive. This stops once we see a slash. + Returns a new string. Don't leak it! */ char *jabber_normalize( const char *orig ) { - int len, i; - char *new; - - len = strlen( orig ); - new = g_new( char, len + 1 ); - - /* So it turns out the /resource part is case sensitive. Yeah, and - it's Unicode but feck Unicode. :-P So stop once we see a slash. */ - for( i = 0; i < len && orig[i] != '/' ; i ++ ) - new[i] = g_ascii_tolower( orig[i] ); - for( ; orig[i]; i ++ ) - new[i] = orig[i]; - - new[i] = 0; + char *lower, *new, *s; + + if ( ! ( s = strchr( orig, '/' ) ) ) + return g_utf8_strdown( orig, -1 ); + + lower = g_utf8_strdown( orig, (s - orig) ); /* stop in s */ + new = g_strconcat( lower, s, NULL ); + g_free( lower ); + return new; +} + +/* Similar to jabber_normalize, but works with addresses in the form + * resource=chatroom@example.com */ +char *jabber_normalize_ext( const char *orig ) +{ + char *lower, *new, *s; + + if ( ! ( s = strchr( orig, '=' ) ) ) + return g_utf8_strdown( orig, -1 ); + + lower = g_utf8_strdown( s, -1 ); /* start in s */ + + *s = 0; + new = g_strconcat( orig, lower, NULL ); + *s = '='; + + g_free( lower ); return new; } @@ -555,7 +569,7 @@ struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *ji struct jabber_buddy *bud; char *s, *jid; - jid = jabber_normalize( jid_ ); + jid = jabber_normalize_ext( jid_ ); if( ( s = strchr( jid, '=' ) ) == NULL ) return NULL; -- cgit v1.2.3