GValue *value,
GParamSpec *pspec);
+static void glib_mldonkey_dump_reply (GlibMldonkey *glibmldonkey);
+
#define GLIB_MLDONKEY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GLIB_TYPE_MLDONKEY, GlibMldonkeyPrivate))
typedef struct _GlibMldonkeyPrivate GlibMldonkeyPrivate;
struct _GlibMldonkeyPrivate
{
- gpointer nothing;
+ GSocketClient *sclient;
+ GSocketConnection *sconn;
};
G_DEFINE_TYPE (GlibMldonkey, glib_mldonkey, G_TYPE_OBJECT)
{
GlibMldonkeyPrivate *priv = GLIB_MLDONKEY_GET_PRIVATE (glib_mldonkey);
+ priv->sclient = NULL;
+ priv->sconn = NULL;
}
/**
return glib_mldonkey;
}
+gboolean
+glib_mldonkey_connect (GlibMldonkey *glibmldonkey, const gchar *host_port)
+{
+ GError *error;
+
+ GlibMldonkeyPrivate *priv = GLIB_MLDONKEY_GET_PRIVATE (glibmldonkey);
+
+ priv->sclient = g_socket_client_new ();
+ g_socket_client_set_enable_proxy (priv->sclient, FALSE);
+
+ error = NULL;
+ priv->sconn = g_socket_client_connect_to_host (priv->sclient,
+ host_port,
+ 4001,
+ NULL,
+ &error);
+ if (priv->sconn == NULL
+ || error != NULL)
+ {
+ g_warning ("Unable to connect to «%s»: %s.",
+ host_port,
+ error != NULL && error->message != NULL ? error->message : "no details");
+ g_object_unref (priv->sclient);
+ return FALSE;
+ }
+
+ if (g_socket_connection_is_connected (priv->sconn))
+ {
+ glib_mldonkey_dump_reply (glibmldonkey);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
/* PRIVATE */
static void
glib_mldonkey_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
break;
}
}
+
+static void
+glib_mldonkey_dump_reply (GlibMldonkey *glibmldonkey)
+{
+ GInputStream *istream;
+ guint32 buf;
+ GError *error;
+
+ GlibMldonkeyPrivate *priv = GLIB_MLDONKEY_GET_PRIVATE (glibmldonkey);
+
+ istream = g_io_stream_get_input_stream (G_IO_STREAM (priv->sconn));
+
+ /* read first 4 byte, the content size */
+ g_input_stream_read_all (istream,
+ &buf,
+ 4,
+ NULL,
+ NULL,
+ &error);
+ g_message ("content size: %d",GLONG_FROM_LE(buf));
+
+ /* read next 2 byte, the function opcode */
+ g_input_stream_read_all (istream,
+ &buf,
+ 2,
+ NULL,
+ NULL,
+ &error);
+ g_message ("function opcode: %d",GLONG_FROM_LE(buf));
+
+ /* function 0 */
+ g_input_stream_read_all (istream,
+ &buf,
+ 4,
+ NULL,
+ NULL,
+ &error);
+ g_message ("maximum protocol version: %d",GLONG_FROM_LE(buf));
+ g_input_stream_read_all (istream,
+ &buf,
+ 4,
+ NULL,
+ NULL,
+ &error);
+ g_message ("maximum opcode gui: %d",GLONG_FROM_LE(buf));
+ g_input_stream_read_all (istream,
+ &buf,
+ 4,
+ NULL,
+ NULL,
+ &error);
+ g_message ("maximum opcode core: %d",GLONG_FROM_LE(buf));
+
+}