From: Andrea Zagli Date: Mon, 14 Sep 2015 16:10:07 +0000 (+0200) Subject: Stream is empty if bad username/password. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=d740c46db40166205fdaad66bb43cdfa0509db70;p=libglib-mldonkey Stream is empty if bad username/password. --- diff --git a/src/glib-mldonkey.c b/src/glib-mldonkey.c index eb1860e..aa68d1b 100644 --- a/src/glib-mldonkey.c +++ b/src/glib-mldonkey.c @@ -251,6 +251,8 @@ bytes2guint32 (const char *bytes) static gboolean glib_mldonkey_read_message (GlibMldonkey *glibmldonkey) { + gboolean ret; + GlibMldonkeyMessage *msg; guint16 buf16; guint32 buf32; @@ -296,24 +298,28 @@ glib_mldonkey_read_message (GlibMldonkey *glibmldonkey) g_message ("function opcode: %d", msg->fopcode); /* the content */ - error = NULL; - msg->data = (guint8 *)g_new0 (guint8, msg->length); - written = g_input_stream_read (priv->istream, - &msg->data[0], - msg->length, - NULL, - &error); - if (written < 1 - || error != NULL) + if (msg->fopcode != 47) { - g_warning ("error %s", error->message != NULL ? error->message : "no details"); - return FALSE; - } - else - { - g_message ("written: %d", written); + error = NULL; + msg->data = (guint8 *)g_new0 (guint8, msg->length); + written = g_input_stream_read (priv->istream, + &msg->data[0], + msg->length, + NULL, + &error); + if (written < 1 + || error != NULL) + { + g_warning ("error %s", error->message != NULL ? error->message : "no details"); + return FALSE; + } + else + { + g_message ("written: %d", written); + } } + ret = TRUE; switch (msg->fopcode) { case 0: /* CoreProtocol */ @@ -333,11 +339,12 @@ glib_mldonkey_read_message (GlibMldonkey *glibmldonkey) case 47: /* BadPassword */ g_warning ("Bad username/password"); + ret = FALSE; break; } - return TRUE; + return ret; } static void