telepathy-mission-control: McdStorage: add support for storing structs (uss ) in keyfiles

Simon McVittie smcv at kemper.freedesktop.org
Wed Feb 13 06:45:04 PST 2013


Module: telepathy-mission-control
Branch: master
Commit: 938facb6517d2daecdf60a287f04d0cdf1f3fd66
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=938facb6517d2daecdf60a287f04d0cdf1f3fd66

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Wed Sep 12 14:28:07 2012 +0100

McdStorage: add support for storing structs (uss) in keyfiles

---

 src/mcd-storage.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index add47e3..7799752 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -29,6 +29,7 @@
 #include "mcd-misc.h"
 #include "plugin-loader.h"
 
+#include <errno.h>
 #include <string.h>
 
 #include <telepathy-glib/telepathy-glib.h>
@@ -386,6 +387,16 @@ mcd_storage_init_value_for_attribute (GValue *value,
               }
           }
         break;
+
+      case '(':
+          {
+            if (!tp_strdiff (s, "(uss)"))
+              {
+                g_value_init (value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
+                return TRUE;
+              }
+          }
+        break;
     }
 
   return FALSE;
@@ -1283,6 +1294,48 @@ mcd_keyfile_get_value (GKeyFile *keyfile,
                 ret = TRUE;
               }
           }
+        else if (type == TP_STRUCT_TYPE_SIMPLE_PRESENCE)
+          {
+            gchar **v = g_key_file_get_string_list (keyfile, group,
+                key, NULL, error);
+
+            if (v == NULL)
+              {
+                /* error is already set, do nothing */
+              }
+            else if (g_strv_length (v) != 3)
+              {
+                g_set_error (error, TP_ERROR, TP_ERROR_NOT_AVAILABLE,
+                    "Invalid simple-presence structure stored in keyfile");
+              }
+            else
+              {
+                guint64 u;
+                gchar *endptr;
+
+                errno = 0;
+                u = g_ascii_strtoull (v[0], &endptr, 10);
+
+                if (errno != 0 || *endptr != '\0' || u > G_MAXUINT32)
+                  {
+                    g_set_error (error, TP_ERROR, TP_ERROR_NOT_AVAILABLE,
+                        "Invalid presence type stored in keyfile: %s", v[0]);
+                  }
+                else
+                  {
+                    /* a syntactically valid simple presence */
+                    g_value_take_boxed (value,
+                        tp_value_array_build (3,
+                          G_TYPE_UINT, (guint) u,
+                          G_TYPE_STRING, v[1],
+                          G_TYPE_STRING, v[2],
+                          G_TYPE_INVALID));
+                    ret = TRUE;
+                  }
+              }
+
+            g_strfreev (v);
+          }
         else
           {
             gchar *message =
@@ -1739,6 +1792,22 @@ mcd_keyfile_set_value (GKeyFile *keyfile,
                 g_key_file_set_string_list (keyfile, name, key,
                     (const gchar * const *) arr->pdata, arr->len);
               }
+            else if (G_VALUE_HOLDS (value, TP_STRUCT_TYPE_SIMPLE_PRESENCE))
+              {
+                guint type;
+                /* enough for "4294967296" + \0 */
+                gchar printf_buf[11];
+                const gchar * strv[4] = { NULL, NULL, NULL, NULL };
+
+                tp_value_array_unpack (g_value_get_boxed (value), 3,
+                    &type,
+                    &(strv[1]),
+                    &(strv[2]));
+                g_snprintf (printf_buf, sizeof (printf_buf), "%u", type);
+                strv[0] = printf_buf;
+
+                g_key_file_set_string_list (keyfile, name, key, strv, 3);
+              }
             else
               {
                 g_warning ("Unexpected param type %s",



More information about the telepathy-commits mailing list