]> saetta.ns0.it Git - libglib-mldonkey/commitdiff
Stream is empty if bad username/password.
authorAndrea Zagli <azagli@libero.it>
Mon, 14 Sep 2015 16:10:07 +0000 (18:10 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 14 Sep 2015 16:10:07 +0000 (18:10 +0200)
src/glib-mldonkey.c

index eb1860e455fbbb9bb2346ec29b2db9a5f9b16d65..aa68d1b8bbe5f21676b0d5b871a13ad4deafb7b9 100644 (file)
@@ -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