diff options
author | dequis <dx@dxzone.com.ar> | 2015-03-13 06:28:36 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-04-10 14:10:41 -0300 |
commit | a4be2f6df564eea09612731be194278e4fb755e0 (patch) | |
tree | 746d86bfa3691d19395802101dddf95d6e106527 | |
parent | 3b09b38a6f8bd15e0971085f9c6a48c31d7f1c17 (diff) |
msn: add msn_queue_feed(), move read() out of msn_handler()
-rw-r--r-- | protocols/msn/msn.h | 1 | ||||
-rw-r--r-- | protocols/msn/msn_util.c | 31 | ||||
-rw-r--r-- | protocols/msn/ns.c | 16 |
3 files changed, 27 insertions, 21 deletions
diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index 4052f7ef..7b1e0d26 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -247,6 +247,7 @@ int msn_buddy_list_add(struct im_connection *ic, msn_buddy_flags_t list, const c const char *group); int msn_buddy_list_remove(struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *group); void msn_buddy_ask(bee_user_t *bu); +void msn_queue_feed(struct msn_data *h, char *bytes, int st); int msn_handler(struct msn_data *h); char *msn_p11_challenge(char *challenge); gint msn_domaintree_cmp(gconstpointer a_, gconstpointer b_); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 4d9c85f2..931641ce 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -171,6 +171,19 @@ void msn_buddy_ask(bee_user_t *bu) imcb_ask_with_free(bu->ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no, msn_buddy_ask_free); } +void msn_queue_feed(struct msn_data *h, char *bytes, int st) +{ + h->rxq = g_renew(char, h->rxq, h->rxlen + 1024); + memcpy(h->rxq + h->rxlen, bytes, st); + h->rxlen += st; + + if (getenv("BITLBEE_DEBUG")) { + fprintf(stderr, "\n\x1b[92m<<< "); + write(2, bytes , st); + fprintf(stderr, "\x1b[97m"); + } +} + /* This one handles input from a MSN Messenger server. Both the NS and SB servers usually give commands, but sometimes they give additional data (payload). This function tries to handle this all in a nice way and send all data to the right places. */ @@ -181,23 +194,7 @@ void msn_buddy_ask(bee_user_t *bu) int msn_handler(struct msn_data *h) { - struct im_connection *ic = h->ic; - int st; - - h->rxq = g_renew(char, h->rxq, h->rxlen + 1024); - st = read(h->fd, h->rxq + h->rxlen, 1024); - h->rxlen += st; - - if (st <= 0) { - fprintf(stderr, "\n\x1b[92m<<< [closed]\x1b[97m "); - return(-1); - } - - if (getenv("BITLBEE_DEBUG")) { - fprintf(stderr, "\n\x1b[92m<<< "); - write(2, h->rxq + h->rxlen - st, st); - fprintf(stderr, "\x1b[97m"); - } + int st = 1; while (st) { int i; diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index 2d0d1a10..3976bfd0 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -147,15 +147,23 @@ static gboolean msn_ns_callback(gpointer data, gint source, b_input_condition co { struct msn_data *handler = data; struct im_connection *ic = handler->ic; + char bytes[1024]; + int st; - if (msn_handler(handler) == -1) { /* Don't do this on ret == 0, it's already done then. */ + st = read(handler->fd, bytes, 1024); + if (st <= 0) { imcb_error(ic, "Error while reading from server"); imc_logout(ic, TRUE); - return FALSE; - } else { - return TRUE; } + + msn_queue_feed(handler, bytes, st); + + /* Ignore ret == 0, it's already disconnected then. */ + msn_handler(handler); + + return TRUE; + } int msn_ns_command(struct msn_data *handler, char **cmd, int num_parts) |