gnome-mud r791 - in trunk: . src



Author: lharris
Date: Sat Mar 14 17:40:50 2009
New Revision: 791
URL: http://svn.gnome.org/viewvc/gnome-mud?rev=791&view=rev

Log:
Added MSSP support

Added:
   trunk/src/mud-telnet-mssp.c
   trunk/src/mud-telnet-mssp.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/mud-telnet.c
   trunk/src/mud-telnet.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Mar 14 17:40:50 2009
@@ -58,6 +58,8 @@
 	mud-telnet-mccp.h			\
 	mud-telnet-msp.c			\
 	mud-telnet-msp.h			\
+	mud-telnet-mssp.c			\
+	mud-telnet-mssp.h			\
 	mud-telnet-zmp.c			\
 	mud-telnet-zmp.h			\
 	mud-tray.c				\

Added: trunk/src/mud-telnet-mssp.c
==============================================================================
--- (empty file)
+++ trunk/src/mud-telnet-mssp.c	Sat Mar 14 17:40:50 2009
@@ -0,0 +1,369 @@
+/* GNOME-Mud - A simple Mud Client
+ * mud-telnet-mssp.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include "gnome-mud.h"
+#include "mud-telnet.h"
+#include "mud-telnet-handler-interface.h"
+#include "mud-telnet-mssp.h"
+
+struct _MudTelnetMsspPrivate
+{
+    /* Interface Properties */
+    MudTelnet *telnet;
+    gboolean enabled;
+    gint option;
+
+    /* Private Instance Members */
+    GHashTable *mssp_data;
+};
+
+/* Property Identifiers */
+enum
+{
+    PROP_MUD_TELNET_MSSP_0,
+    PROP_ENABLED,
+    PROP_HANDLES_OPTION,
+    PROP_TELNET,
+    PROP_MSSP
+};
+
+enum
+{
+    PARSE_STATE_VAR,
+    PARSE_STATE_VAR_STRING,
+    PARSE_STATE_VAL,
+    PARSE_STATE_VAL_STRING
+};
+
+/* Class Functions */
+static void mud_telnet_mssp_init (MudTelnetMssp *self);
+static void mud_telnet_mssp_class_init (MudTelnetMsspClass *klass);
+static void mud_telnet_mssp_interface_init(MudTelnetHandlerInterface *iface);
+static void mud_telnet_mssp_finalize (GObject *object);
+static GObject *mud_telnet_mssp_constructor (GType gtype,
+                                             guint n_properties,
+                                             GObjectConstructParam *properties);
+static void mud_telnet_mssp_set_property(GObject *object,
+                                         guint prop_id,
+                                         const GValue *value,
+                                         GParamSpec *pspec);
+static void mud_telnet_mssp_get_property(GObject *object,
+                                         guint prop_id,
+                                         GValue *value,
+                                         GParamSpec *pspec);
+
+/*Interface Implementation */
+void mud_telnet_mssp_enable(MudTelnetHandler *self);
+void mud_telnet_mssp_disable(MudTelnetHandler *self);
+void mud_telnet_mssp_handle_sub_neg(MudTelnetHandler *self,
+                                    guchar *buf,
+                                    guint len);
+
+/* Private Methods */
+static void mud_telnet_mssp_destroy_key(gpointer k);
+static void mud_telnet_mssp_destroy_value(gpointer c);
+
+/* Create the Type. We implement MudTelnetHandlerInterface */
+G_DEFINE_TYPE_WITH_CODE(MudTelnetMssp, mud_telnet_mssp, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (MUD_TELNET_HANDLER_TYPE,
+                                               mud_telnet_mssp_interface_init));
+/* MudTelnetMssp class functions */
+static void
+mud_telnet_mssp_class_init (MudTelnetMsspClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    /* Override base object constructor */
+    object_class->constructor = mud_telnet_mssp_constructor;
+
+    /* Override base object's finalize */
+    object_class->finalize = mud_telnet_mssp_finalize;
+
+    /* Override base object property methods */
+    object_class->set_property = mud_telnet_mssp_set_property;
+    object_class->get_property = mud_telnet_mssp_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(MudTelnetMsspPrivate));
+
+    /* Override Implementation Properties */
+    g_object_class_override_property(object_class,
+                                     PROP_ENABLED,
+                                     "enabled");
+
+    g_object_class_override_property(object_class,
+                                     PROP_HANDLES_OPTION,
+                                     "handles-option");
+
+    g_object_class_override_property(object_class,
+                                     PROP_TELNET,
+                                     "telnet");
+    /* Custom Class Properties */
+    g_object_class_install_property(object_class,
+                            PROP_MSSP,
+                            g_param_spec_pointer("mssp-data",
+                                                 "MSSP Data",
+                                                 "The MSSP data provided by the mud.",
+                                                 G_PARAM_READABLE));
+}
+
+static void
+mud_telnet_mssp_interface_init(MudTelnetHandlerInterface *iface)
+{
+    iface->Enable = mud_telnet_mssp_enable;
+    iface->Disable = mud_telnet_mssp_disable;
+    iface->HandleSubNeg = mud_telnet_mssp_handle_sub_neg;
+}
+
+static void
+mud_telnet_mssp_init (MudTelnetMssp *self)
+{
+    /* Get our private data */
+    self->priv = MUD_TELNET_MSSP_GET_PRIVATE(self);
+
+    /* Set the defaults */
+    self->priv->telnet = NULL;
+    self->priv->option = TELOPT_MSSP;
+    self->priv->enabled = FALSE;
+
+    self->priv->mssp_data = NULL;
+}
+
+static GObject *
+mud_telnet_mssp_constructor (GType gtype,
+                             guint n_properties,
+                             GObjectConstructParam *properties)
+{
+    MudTelnetMssp *self;
+    GObject *obj;
+    MudTelnetMsspClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = MUD_TELNET_MSSP_CLASS( g_type_class_peek(MUD_TYPE_TELNET_MSSP) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = MUD_TELNET_MSSP(obj);
+
+    if(!self->priv->telnet)
+    {
+        g_printf("ERROR: Tried to instantiate MudTelnetMssp without passing parent MudTelnet\n");
+        g_error("Tried to instantiate MudTelnetMssp without passing parent MudTelnet");
+    }
+
+    self->priv->mssp_data = g_hash_table_new_full(g_str_hash,
+                                                  g_str_equal,
+                                                  mud_telnet_mssp_destroy_key,
+                                                  mud_telnet_mssp_destroy_value);
+
+    return obj;
+}
+
+static void
+mud_telnet_mssp_finalize (GObject *object)
+{
+    MudTelnetMssp *self;
+    GObjectClass *parent_class;
+
+    self = MUD_TELNET_MSSP(object);
+
+    if(self->priv->mssp_data)
+        g_hash_table_destroy(self->priv->mssp_data);
+
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
+}
+
+static void
+mud_telnet_mssp_set_property(GObject *object,
+                             guint prop_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+    MudTelnetMssp *self;
+
+    self = MUD_TELNET_MSSP(object);
+
+    switch(prop_id)
+    {
+        case PROP_TELNET:
+            self->priv->telnet = MUD_TELNET(g_value_get_object(value));
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+mud_telnet_mssp_get_property(GObject *object,
+                             guint prop_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+    MudTelnetMssp *self;
+
+    self = MUD_TELNET_MSSP(object);
+
+    switch(prop_id)
+    {
+        case PROP_ENABLED:
+            g_value_set_boolean(value, self->priv->enabled);
+            break;
+
+        case PROP_HANDLES_OPTION:
+            g_value_set_int(value, self->priv->option);
+            break;
+
+        case PROP_TELNET:
+            g_value_take_object(value, self->priv->telnet);
+            break;
+
+        case PROP_MSSP:
+            g_value_set_pointer(value, self->priv->mssp_data);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+/* Interface Implementation */
+void 
+mud_telnet_mssp_enable(MudTelnetHandler *handler)
+{
+    MudTelnetMssp *self;
+
+    self = MUD_TELNET_MSSP(handler);
+
+    g_return_if_fail(MUD_IS_TELNET_MSSP(self));
+
+    self->priv->enabled = TRUE;
+
+    g_log("Telnet", G_LOG_LEVEL_INFO, "%s", "MSSP Enabled");
+}
+
+void
+mud_telnet_mssp_disable(MudTelnetHandler *handler)
+{
+    MudTelnetMssp *self;
+
+    self = MUD_TELNET_MSSP(handler);
+
+    g_return_if_fail(MUD_IS_TELNET_MSSP(self));
+
+    self->priv->enabled = FALSE;
+
+    g_log("Telnet", G_LOG_LEVEL_INFO, "%s", "MSSP Disabled");
+}
+
+void
+mud_telnet_mssp_handle_sub_neg(MudTelnetHandler *handler,
+                               guchar *buf,
+                               guint len)
+{
+    MudTelnetMssp *self;
+    guint i, state;
+    GString *key, *value;
+
+    self = MUD_TELNET_MSSP(handler);
+
+    g_return_if_fail(MUD_IS_TELNET_MSSP(self));
+
+    state = PARSE_STATE_VAR;
+
+    for(i = 0; i < len; ++i)
+    {
+        switch(state)
+        {
+            case PARSE_STATE_VAR:
+                key = g_string_new(NULL);
+
+                state = PARSE_STATE_VAR_STRING;
+                break;
+
+            case PARSE_STATE_VAR_STRING:
+                if( buf[i] != TEL_MSSP_VAL )
+                    key = g_string_append_c(key, buf[i]);
+                else
+                {
+                    state = PARSE_STATE_VAL;
+                    i--;
+                } 
+                break;
+
+            case PARSE_STATE_VAL:
+                value = g_string_new(NULL);
+
+                state = PARSE_STATE_VAL_STRING;
+                break;
+
+            case PARSE_STATE_VAL_STRING:
+                if( buf[i] != TEL_MSSP_VAR )
+                    value = g_string_append_c(value, buf[i]);
+                else
+                {
+                    g_hash_table_replace(self->priv->mssp_data,
+                                         g_string_free(key, FALSE),
+                                         g_string_free(value, FALSE));
+
+                    state = PARSE_STATE_VAR;
+                    i--;
+                }
+
+                if( i + 1 == len) // Last value in subnegotiation.
+                    g_hash_table_replace(self->priv->mssp_data,
+                                         g_string_free(key, FALSE),
+                                         g_string_free(value, FALSE));
+
+                break;
+        }
+    }
+}
+
+/* Private Methods */
+static void
+mud_telnet_mssp_destroy_key(gpointer k)
+{
+    gchar *key = (gchar *)k;
+
+    if(key)
+        g_free(key);
+}
+
+static void
+mud_telnet_mssp_destroy_value(gpointer v)
+{
+    gchar *value = (gchar *)v;
+
+    if(value)
+        g_free(value);
+}
+

Added: trunk/src/mud-telnet-mssp.h
==============================================================================
--- (empty file)
+++ trunk/src/mud-telnet-mssp.h	Sat Mar 14 17:40:50 2009
@@ -0,0 +1,57 @@
+/* GNOME-Mud - A simple Mud Client
+ * mud-telnet-mssp.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef MUD_TELNET_MSSP_H
+#define MUD_TELNET_MSSP_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+
+#define MUD_TYPE_TELNET_MSSP              (mud_telnet_mssp_get_type ())
+#define MUD_TELNET_MSSP(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), MUD_TYPE_TELNET_MSSP, MudTelnetMssp))
+#define MUD_TELNET_MSSP_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_TELNET_MSSP, MudTelnetMsspClass))
+#define MUD_IS_TELNET_MSSP(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), MUD_TYPE_TELNET_MSSP))
+#define MUD_IS_TELNET_MSSP_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), MUD_TYPE_TELNET_MSSP))
+#define MUD_TELNET_MSSP_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), MUD_TYPE_TELNET_MSSP, MudTelnetMsspClass))
+#define MUD_TELNET_MSSP_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MUD_TYPE_TELNET_MSSP, MudTelnetMsspPrivate))
+
+typedef struct _MudTelnetMssp            MudTelnetMssp;
+typedef struct _MudTelnetMsspClass       MudTelnetMsspClass;
+typedef struct _MudTelnetMsspPrivate     MudTelnetMsspPrivate;
+
+struct _MudTelnetMsspClass
+{
+    GObjectClass parent_class;
+};
+
+struct _MudTelnetMssp
+{
+    GObject parent_instance;
+
+    /*< private >*/
+    MudTelnetMsspPrivate *priv;
+};
+
+GType mud_telnet_mssp_get_type (void);
+
+G_END_DECLS
+
+#endif // MUD_TELNET_MSSP_H
+

Modified: trunk/src/mud-telnet.c
==============================================================================
--- trunk/src/mud-telnet.c	(original)
+++ trunk/src/mud-telnet.c	Sat Mar 14 17:40:50 2009
@@ -40,6 +40,7 @@
 #include "mud-telnet-eor.h"
 #include "mud-telnet-charset.h"
 #include "mud-telnet-zmp.h"
+#include "mud-telnet-mssp.h"
 
 #ifdef ENABLE_GST
 #include "mud-telnet-msp.h"
@@ -795,6 +796,12 @@
                          g_object_new(MUD_TYPE_TELNET_ZMP,
                                       "telnet", telnet,
                                       NULL));
+    /* MSSP */
+    g_hash_table_replace(telnet->priv->handlers,
+                         GINT_TO_POINTER(TELOPT_MSSP),
+                         g_object_new(MUD_TYPE_TELNET_MSSP,
+                                      "telnet", telnet,
+                                      NULL));
 #ifdef ENABLE_GST
     /* MSP */
     g_hash_table_replace(telnet->priv->handlers,

Modified: trunk/src/mud-telnet.h
==============================================================================
--- trunk/src/mud-telnet.h	(original)
+++ trunk/src/mud-telnet.h	Sat Mar 14 17:40:50 2009
@@ -83,6 +83,11 @@
 /* Zenith Mud Protocol - http://www.awemud.net/zmp/draft.php */
 #define TELOPT_ZMP                      93
 
+/* Mud Server Status Protocol - http://mudbytes.net/index.php?a=topic&t=1336&min=0&num=15*/
+#define TELOPT_MSSP                     70
+#define TEL_MSSP_VAR                    1
+#define TEL_MSSP_VAL                    2
+
 // FIXME: What size should we use?
 #define TEL_SUBREQ_BUFFER_SIZE 16318 
 #define TELOPT_STATE_QUEUE_EMPTY	FALSE



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]