Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_dbus


Modified Files:
        Ecore_DBus.h ecore_dbus_address.c 


Log Message:
const on key also
namespace static functions for the hell of it
properly encode/decode address values
add function to print address as a string

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/Ecore_DBus.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- Ecore_DBus.h        25 Sep 2006 05:24:47 -0000      1.17
+++ Ecore_DBus.h        25 Sep 2006 05:30:48 -0000      1.18
@@ -210,9 +210,9 @@
    EAPI void                ecore_dbus_address_free(Ecore_DBus_Address 
*address);
 
    EAPI Ecore_List         *ecore_dbus_address_parse(const char *address);
+   EAPI char               *ecore_dbus_address_string(Ecore_DBus_Address 
*address);
 
-   EAPI const char         *ecore_dbus_address_value_get(Ecore_DBus_Address 
*address,
-                                                        char *key);
+   EAPI const char         *ecore_dbus_address_value_get(Ecore_DBus_Address 
*address, const char *key);
    EAPI void                ecore_dbus_print_address_list(Ecore_List 
*addresses);
    EAPI Ecore_DBus_Server  *ecore_dbus_address_list_connect(Ecore_List *addrs, 
const void *data);
    EAPI Ecore_DBus_Server  *ecore_dbus_address_connect(Ecore_DBus_Address 
*addr, const void *data);
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_dbus/ecore_dbus_address.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ecore_dbus_address.c        24 Sep 2006 07:53:47 -0000      1.2
+++ ecore_dbus_address.c        25 Sep 2006 05:30:48 -0000      1.3
@@ -8,9 +8,16 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <ctype.h>
+
+static void _ecore_dbus_address_list_free_cb(void *data);
+
+static int _ecore_dbus_address_value_char_optional_encode(char c);
+static char * _ecore_dbus_address_value_decode(const char *value);
+static char * _ecore_dbus_address_value_encode(const char *value);
 
 static void
-_list_free_cb(void *data)
+_ecore_dbus_address_list_free_cb(void *data)
 {
   if (data) free(data);
 }
@@ -23,9 +30,9 @@
    if (!a) return NULL;
 
    a->keys = ecore_list_new();
-   ecore_list_set_free_cb(a->keys, _list_free_cb);
+   ecore_list_set_free_cb(a->keys, _ecore_dbus_address_list_free_cb);
    a->vals = ecore_list_new();
-   ecore_list_set_free_cb(a->vals, _list_free_cb);
+   ecore_list_set_free_cb(a->vals, _ecore_dbus_address_list_free_cb);
 
    return a;
 }
@@ -84,7 +91,7 @@
                  break;
               }
             *p = '\0';
-            ecore_list_append(a->vals, strdup(val));
+            ecore_list_append(a->vals, _ecore_dbus_address_value_decode(val));
             val = NULL;
 
             if (sep == ',')
@@ -130,8 +137,8 @@
    return alist;
 }
 
-char *
-ecore_dbus_address_value_get(Ecore_DBus_Address *address, char *key)
+const char *
+ecore_dbus_address_value_get(Ecore_DBus_Address *address, const char *key)
 {
    int i;
    char *s;
@@ -150,6 +157,33 @@
    return NULL;
 }
 
+EAPI char *
+ecore_dbus_address_string(Ecore_DBus_Address *address)
+{
+   char buf[PATH_MAX];
+   char *key, *val;
+   int left = PATH_MAX - 1; /* space left in the buffer, leaving room for a 
final null */
+
+   if (!address) return NULL;
+  
+   snprintf(buf, PATH_MAX, "%s:", address->transport);
+   left -= strlen(address->transport) + 1;
+   ecore_list_goto_first(address->keys);
+   ecore_list_goto_first(address->vals);
+   while ((key = ecore_list_next(address->keys)) && (val = 
ecore_list_next(address->vals)))
+     {
+       char *encval;
+       strncat(buf, key, left);
+       left -= strlen(key);
+       strncat(buf, "=", left);
+       left -= 1;
+       encval = _ecore_dbus_address_value_encode(val);
+       strncat(buf, encval, left);
+       left -= strlen(encval);
+       free(encval);
+     }
+   return strdup(buf);
+}
 
 /**
  * Connect to the first successful server in a list of addresses.
@@ -179,6 +213,11 @@
   int type;
   int port;
 
+  char *addr_string;
+  addr_string = ecore_dbus_address_string(addr);
+  printf("[ecore_dbus] connecting to address: %s\n", addr_string);
+  free(addr_string);
+
   if (!strcmp(addr->transport, "unix")) 
     {
        type = ECORE_CON_LOCAL_SYSTEM;
@@ -229,3 +268,94 @@
      }
 }
 
+static int
+_ecore_dbus_address_value_char_optional_encode(char c)
+{
+   /* addl optional chars (other than 0-9A-Za-z) */
+   char OPTIONAL_CHARS[] = {'_', '-', '/', '.', '\\'};
+   int i;
+
+   if (isascii(c) && (isalpha(c) || isdigit(c))) return 1;
+   for (i = 0; i < sizeof(OPTIONAL_CHARS); i++)
+     if (c == OPTIONAL_CHARS[i]) return 1;
+   
+   return 0;
+
+
+}
+
+static char *
+_ecore_dbus_address_value_encode(const char *value)
+{
+   char *buf;
+   const char *p;
+   int i;
+
+   const char hexdigits[16] = {
+      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+      'a', 'b', 'c', 'd', 'e', 'f'
+   };
+
+   
+   if (!value) return NULL;
+   buf = malloc(3 * strlen(value) + 1);
+
+   p = value;
+   i = 0;
+   while (*p)
+     {
+       if (_ecore_dbus_address_value_char_optional_encode(*p))
+         buf[i++] = *p;
+       else
+         {
+            buf[i++] = '%';
+            buf[i++] = hexdigits[(*p >> 4)];
+            buf[i++] = hexdigits[(*p & 0xf)];
+         }
+       p++;
+     }
+
+   buf[i] = '\0';
+   return buf;
+}
+
+static char *
+_ecore_dbus_address_value_decode(const char *value)
+{
+   char *buf;
+   const char *p;
+   int i;
+
+   buf = malloc(strlen(value) + 1);
+ 
+   *buf = '\0';
+   p = value;
+   i = 0;
+   while (*p)
+     {
+       if (*p == '%')
+         {
+            char c = 0;
+            int j;
+            for (j = 0; j < 2; j++) 
+              {
+                 p++;
+                 c = c << 4;
+                 if ('0' <= *p && *p <= '9')
+                   c |= *p - '0';
+                 else if ('A' <= *p && *p <= 'F')
+                   c |= 10 + *p - 'A';
+                 else if ('a' <= *p && *p <= 'f') /* a-f */
+                   c |= 10 + *p - 'a';
+              }
+            buf[i++] = c;
+         }
+       else
+         buf[i++] = *p;
+
+       p++;
+     }
+
+   buf[i] = '\0';
+   return buf;
+}



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to