Author: ArcRiley
Date: 2009-02-25 04:55:15 -0500 (Wed, 25 Feb 2009)
New Revision: 1517

Added:
   trunk/concordance/src/utils.c
Removed:
   trunk/concordance/src/_core/utils.c
   trunk/concordance/src/_core/utils.h
Modified:
   trunk/concordance/include/concordance.h
   trunk/concordance/include/concordance.sockets.h
   trunk/concordance/setup.py
   trunk/concordance/src/sockets/Client.c
Log:
working utils.c back in

Modified: trunk/concordance/include/concordance.h
===================================================================
--- trunk/concordance/include/concordance.h     2009-02-25 09:55:09 UTC (rev 
1516)
+++ trunk/concordance/include/concordance.h     2009-02-25 09:55:15 UTC (rev 
1517)
@@ -37,6 +37,9 @@
   #include <netdb.h>
 #endif
 
+gchar*        concordFindAttr          (const gchar** attrs, const gchar* key);
+gchar*        concordPyUnicodeToUTF8   (PyObject* unicode);
+gboolean      concordStrToUI           (const gchar* string, guint* result);
 
 typedef struct {
   GMainContext*    context;              /* Concordance's Glib context */

Modified: trunk/concordance/include/concordance.sockets.h
===================================================================
--- trunk/concordance/include/concordance.sockets.h     2009-02-25 09:55:09 UTC 
(rev 1516)
+++ trunk/concordance/include/concordance.sockets.h     2009-02-25 09:55:15 UTC 
(rev 1517)
@@ -71,7 +71,7 @@
 
 
 typedef struct {
-  socketsClient_Object  self;          /* the listening socket this belongs */
+  socketsClient_Object* self;          /* the listening socket this belongs */
   PyObject*             node;          /* Node object for this or NULL */
   GMutex*               lock;          /* Mutex for self test/add/remove */
   GIOChannel*           chan;          /* Glib IO channel for this session */

Modified: trunk/concordance/setup.py
===================================================================
--- trunk/concordance/setup.py  2009-02-25 09:55:09 UTC (rev 1516)
+++ trunk/concordance/setup.py  2009-02-25 09:55:15 UTC (rev 1517)
@@ -90,7 +90,7 @@
     Extension(
       name         = '_core',
       sources      = ['src/_core/__init__.c',
-                      'src/_core/utils.c',
+                      'src/utils.c',
       ],
       include_dirs = include_dirs,
       libraries    = libraries,
@@ -98,6 +98,7 @@
     Extension(
       name         = 'services',
       sources      = ['src/services/__init__.c',
+                      'src/utils.c',
       ],
       include_dirs = include_dirs,
       libraries    = libraries,
@@ -107,6 +108,7 @@
       sources      = ['src/sockets/__init__.c',
                       'src/sockets/Socket.c',
                       'src/sockets/Client.c',
+                      'src/utils.c',
       ],
       include_dirs = include_dirs,
       libraries    = libraries,

Deleted: trunk/concordance/src/_core/utils.c
===================================================================
--- trunk/concordance/src/_core/utils.c 2009-02-25 09:55:09 UTC (rev 1516)
+++ trunk/concordance/src/_core/utils.c 2009-02-25 09:55:15 UTC (rev 1517)
@@ -1,225 +0,0 @@
-/*
-# Concordance XMPP Service Framework
-#
-# Copyright (C) 2009 Copyleft Games Group
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU Affero General Public License as published
-#  by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
-#
-#  You should have received a copy of the GNU Affero General Public License
-#  along with this program; if not, see http://www.gnu.org/licenses
-#
-# $Id$
-*/
-
-#include "__init__.h"
-
-GIOChannel*
-concordAddSocket(gint fd, GIOCondition condition, GSourceFunc callback,
-                 gpointer data, GMainContext* context) {                  /*\
-  cdef :                                                                  \*/
-    GIOChannel* channel;
-
-  /* create a new channel using an OS-dependent function
-
-     GIOChannel*       g_io_channel_win32_new_fd     (gint fd);
-     GIOChannel*       g_io_channel_unix_new         (gint fd);
-  */
-  #ifdef MS_WINDOWS
-    channel = g_io_channel_win32_new_socket(fd);
-  #else
-    channel = g_io_channel_unix_new(fd);
-  #endif
-
-  /* See below */
-  concordAddWatch(channel, condition, callback, data, context);
-
-  return channel;
-}
-
-
-gint
-concordAddWatch(GIOChannel* channel, GIOCondition condition,
-                GSourceFunc callback, gpointer data,
-                GMainContext* context) {                                  /*\
-  cdef :                                                                  \*/
-    GSource* source;
-    guint    id;
-
-  /* add a channel to our context watch
-
-     Note that this function is a replacement for g_io_add_watch() which
-     uses our own context rather than the default context.
-
-     GSource *    g_io_create_watch        (GIOChannel *channel,
-                                            GIOCondition condition);
-     void         g_source_set_callback    (GSource *source,
-                                            GSourceFunc func,
-                                            gpointer data,
-                                            GDestroyNotify notify);
-     guint        g_source_attach          (GSource *source,
-                                            GMainContext *context);
-  */
-  source = g_io_create_watch(channel, condition);
-  g_source_set_callback(source, callback, data, NULL);
-  id = g_source_attach(source, context);
-  g_source_unref(source);
-  return id;
-}
-
-gchar*
-concordSearchAttributes(const gchar** attrs, const gchar* key) {          /*\
-  cdef :                                                                  \*/
-    gint i;
-
-  for (i = 0; attrs[i]; i += 2) {
-    /* compare attribute strings case insensitive
-
-       gint             g_ascii_strcasecmp       (const gchar *s1,
-                                                  const gchar *s2);
-    */
-    if (g_ascii_strcasecmp(attrs[i], key) == 0)
-      break;
-  }
-
-  /* return either the found attribute value or NULL */
-  if (attrs[i])
-    return (gchar*) attrs[i+1];
-  else
-    return NULL;
-}
-
-gchar*
-concordPyUnicodeToUTF8(PyObject* unicode) {                               /*\
-  cdef :                                                                  \*/
-    PY_UNICODE_TYPE* uni;
-    Py_ssize_t       len;
-
-  if (!unicode)
-    return NULL;
-
-  /* return Python unicode object converted to UTF8 gchar*
-
-     Returned gchar* must be freed with g_free().
-
-     Py_UNICODE*        PyUnicode_AsUnicode      (PyObject *unicode);
-     Py_ssize_t         PyUnicode_GetSize        (PyObject *unicode);
-     gchar*             g_utf16_to_utf8          (const gunichar2 *str,
-                                                  glong len,
-                                                  glong *items_read,
-                                                  glong *items_written,
-                                                  GError **error);
-     gchar*             g_ucs4_to_utf8           (const gunichar *str,
-                                                  glong len,
-                                                  glong *items_read,
-                                                  glong *items_written,
-                                                  GError **error);
-  */
-  uni = PyUnicode_AsUnicode(unicode);
-  len = PyUnicode_GetSize(unicode);
-  #if Py_UNICODE_SIZE == 2
-    return g_utf16_to_utf8((gunichar2*) uni, len, NULL, NULL, NULL);
-  #else
-    return g_ucs4_to_utf8((gunichar*) uni, len, NULL, NULL, NULL);
-  #endif
-}
-
-
-gboolean
-concordStrToUI(const gchar* string, guint* result) {                      /*\
-  cdef :                                                                  \*/
-    gint  d;
-    guint i = 0;
-    guint r = 0;
-
-  /* return error now in case of empty string */
-  if (*string == 0)
-    return FALSE;
-
-  /* continue until hit end of string */
-  while (string[i] != 0) {
-    /* shift existing value up by 10, ie total input "92":
-       i=0, r=0, r*10=0,  string[0] = "9", r =  0 + 9 =  9
-       i=1, r=9, r*10=90, string[1] = "2", r = 90 + 2 = 92
-       i=2, which is \0, so we exit while loop
-    */
-    r = r * 10;
-
-    /* get digit value from string position and test it.
-
-       gint             g_ascii_digit_value      (gchar c);
-       Returns -1 on error.
-    */
-    d = g_ascii_digit_value(string[i]);
-    if (d == -1)
-      return FALSE;
-
-    r+=d; /* add d to r, see above */
-    i++;  /* increment i for the next loop */
-
-    /* prevent wasted processing time or overflow on long strings */
-    if (i == 10)
-      return FALSE;
-  }
-
-  /* pass r to the result pointer and return */
-  *result = r;
-  return TRUE;
-}
-
-
-gchar*
-conSession_getVersion(gchar* version, gchar** error) {                    /*\
-  cdef :                                                                  \*/
-    guint major, minor;
-    gchar** versions;
-
-  /* There are four possible outcomes to this function:
-       * NULL is passed, meaning the version attribute was not found, so:
-         * return is ""
-         * error is "<unsupported-version/>"
-
-       * "1.*" is passed, meaning a version we support, so:
-         * return is " version='1.0'"
-         * error is NULL
-
-       * "2.0" or greater is passed, meaning a version we do not support, so:
-         * return is " version='1.0'"
-         * error is "<unsupported-version/>"
-
-       * something unparsable is passed, so:
-         * return is " version='1.0'"
-         * error is "<bad-format/>"
-  */
-
-  if (version == NULL) {
-    *error = "<unsupported-version/>";
-    return "";
-  }
-
-  if (g_strrstr(version, ".") != NULL) {
-    versions = g_strsplit(version, ".", 2); // Separate Major from minor
-    if (g_strv_length(versions) == 2 &&
-        concordStrToUI(versions[0], &major) &&
-        concordStrToUI(versions[1], &minor)) {
-      g_strfreev(versions);
-      if (major == 1)
-        return " version='1.0'";
-      else {
-        *error = "<unsupported-version/>";
-        return " version='1.0'";
-      }
-    }
-    g_strfreev(versions);
-  }
-  // else (because it should have returned above)
-  *error = "<bad-format/>";
-  return " version='1.0'";
-}

Deleted: trunk/concordance/src/_core/utils.h
===================================================================
--- trunk/concordance/src/_core/utils.h 2009-02-25 09:55:09 UTC (rev 1516)
+++ trunk/concordance/src/_core/utils.h 2009-02-25 09:55:15 UTC (rev 1517)
@@ -1,39 +0,0 @@
-/*
-# Concordance XMPP Service Framework
-#
-# Copyright (C) 2009 Copyleft Games Group
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU Affero General Public License as published
-#  by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
-#
-#  You should have received a copy of the GNU Affero General Public License
-#  along with this program; if not, see http://www.gnu.org/licenses
-#
-# $Id$
-*/
-
-#ifndef CONCORD_UTILS_H
-#define CONCORD_UTILS_H
-
-#include "concordance.h"
-
-GIOChannel*   concordAddSocket         (gint fd, GIOCondition condition,
-                                        GSourceFunc callback, gpointer data,
-                                        GMainContext* context);
-gint          concordAddWatch          (GIOChannel* channel,
-                                        GIOCondition condition, 
-                                        GSourceFunc callback, gpointer data,
-                                        GMainContext* context);
-gchar*        concordSearchAttributes  (const gchar**, const gchar*);
-gchar*        concordPyUnicodeToUTF8   (PyObject* unicode);
-gboolean      concordStrToUI           (const gchar* string, guint* result);
-gchar*        conSession_getVersion    (gchar*, gchar**);
-
-#endif

Modified: trunk/concordance/src/sockets/Client.c
===================================================================
--- trunk/concordance/src/sockets/Client.c      2009-02-25 09:55:09 UTC (rev 
1516)
+++ trunk/concordance/src/sockets/Client.c      2009-02-25 09:55:15 UTC (rev 
1517)
@@ -35,7 +35,7 @@
   static gboolean
   _gioNew(GIOChannel* channel, GIOCondition condition, gpointer s) {      /*\
     cdef :                                                                \*/
-      socketsSocket_Object*      self = (socketsSocket_Object*) s;
+      socketsClient_Object*      self = (socketsClient_Object*) s;
       gint                       socket;
       struct sockaddr            addr;
       guint                      addrlen = sizeof(addr);
@@ -89,7 +89,8 @@
     */
     source = g_io_create_watch(session->chan, G_IO_IN | G_IO_HUP);
     g_source_set_callback(source, (GSourceFunc)
-                          ((socketsClient_TypeObject*) s->ob_type)->_gioRead,
+                          ((socketsClient_TypeObject*) self->base->ob_type)->
+                          _gioRead,
                           (gpointer) session, NULL);
     g_source_attach(source, self->context);
     g_source_unref(source);

Added: trunk/concordance/src/utils.c
===================================================================
--- trunk/concordance/src/utils.c                               (rev 0)
+++ trunk/concordance/src/utils.c       2009-02-25 09:55:15 UTC (rev 1517)
@@ -0,0 +1,100 @@
+/*
+# Concordance XMPP Service Framework
+#
+# Copyright (C) 2009 Copyleft Games Group
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Affero General Public License as published
+#  by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+#
+#  You should have received a copy of the GNU Affero General Public License
+#  along with this program; if not, see http://www.gnu.org/licenses
+#
+# $Id$
+*/
+
+#include "utils.h"
+
+gchar*
+concordPyUnicodeToUTF8(PyObject* unicode) {                               /*\
+  cdef :                                                                  \*/
+    PY_UNICODE_TYPE* uni;
+    Py_ssize_t       len;
+
+  if (!unicode)
+    return NULL;
+
+  /* return Python unicode object converted to UTF8 gchar*
+
+     Returned gchar* must be freed with g_free().
+
+     Py_UNICODE*        PyUnicode_AsUnicode      (PyObject *unicode);
+     Py_ssize_t         PyUnicode_GetSize        (PyObject *unicode);
+     gchar*             g_utf16_to_utf8          (const gunichar2 *str,
+                                                  glong len,
+                                                  glong *items_read,
+                                                  glong *items_written,
+                                                  GError **error);
+     gchar*             g_ucs4_to_utf8           (const gunichar *str,
+                                                  glong len,
+                                                  glong *items_read,
+                                                  glong *items_written,
+                                                  GError **error);
+  */
+  uni = PyUnicode_AsUnicode(unicode);
+  len = PyUnicode_GetSize(unicode);
+  #if Py_UNICODE_SIZE == 2
+    return g_utf16_to_utf8((gunichar2*) uni, len, NULL, NULL, NULL);
+  #else
+    return g_ucs4_to_utf8((gunichar*) uni, len, NULL, NULL, NULL);
+  #endif
+}
+
+
+gboolean
+concordStrToUI(const gchar* string, guint* result) {                      /*\
+  cdef :                                                                  \*/
+    gint  d;
+    guint i = 0;
+    guint r = 0;
+
+  /* return error now in case of empty string */
+  if (*string == 0)
+    return FALSE;
+
+  /* continue until hit end of string */
+  while (string[i] != 0) {
+    /* shift existing value up by 10, ie total input "92":
+       i=0, r=0, r*10=0,  string[0] = "9", r =  0 + 9 =  9
+       i=1, r=9, r*10=90, string[1] = "2", r = 90 + 2 = 92
+       i=2, which is \0, so we exit while loop
+    */
+    r = r * 10;
+
+    /* get digit value from string position and test it.
+
+       gint             g_ascii_digit_value      (gchar c);
+       Returns -1 on error.
+    */
+    d = g_ascii_digit_value(string[i]);
+    if (d == -1)
+      return FALSE;
+
+    r+=d; /* add d to r, see above */
+    i++;  /* increment i for the next loop */
+
+    /* prevent wasted processing time or overflow on long strings */
+    if (i == 10)
+      return FALSE;
+  }
+
+  /* pass r to the result pointer and return */
+  *result = r;
+  return TRUE;
+}

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to