soylent r262 - trunk/libsoylent
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r262 - trunk/libsoylent
- Date: Fri, 1 Aug 2008 13:09:36 +0000 (UTC)
Author: svenp
Date: Fri Aug 1 13:09:36 2008
New Revision: 262
URL: http://svn.gnome.org/viewvc/soylent?rev=262&view=rev
Log:
removed systypes (the EDS backend is now supposed to provide values as strings only)
implemented bytes-mapper
strings are now shortened if they are too long and printed with to_string
Modified:
trunk/libsoylent/sl-attribute-eds.c
trunk/libsoylent/sl-attributes.c
trunk/libsoylent/sl-attributes.h
Modified: trunk/libsoylent/sl-attribute-eds.c
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.c (original)
+++ trunk/libsoylent/sl-attribute-eds.c Fri Aug 1 13:09:36 2008
@@ -187,7 +187,10 @@
if (name == NULL)
{
/* TODO: this leaks, cause name must be freed somehow */
- g_assert (g_str_has_prefix (eattrname, "X-"));
+ if (!g_str_has_prefix (eattrname, "X-"))
+ {
+ g_error ("EDS: illegal vCard field: %s", eattrname);
+ }
name = g_utf8_strdown (&eattrname[2], -1);
}
return name;
@@ -233,23 +236,23 @@
/* TODO: install attribute-definition if attribute is unknown? would
* solve the problem that reading is done in bytes while reading is still
- * done with strings */
+ * done with strings
GList* encodings = e_vcard_attribute_get_param (eattr, EVC_ENCODING);
if (encodings != NULL)
{
- g_debug ("now I'm decoding some base64 stuff!");
- /* TODO: handle other encodings */
+ g_debug ("now I'm decoding some base64 stuff!");*/
+ /* TODO: handle other encodings
GByteArray *bytes = g_byte_array_new ();
bytes->data = g_base64_decode (evalue, &bytes->len);
- value = sl_attribute_mapper_read (self->priv->name, bytes, SL_ATTRIBUTE_SYS_TYPE_BYTE);
+ value = sl_attribute_mapper_read (self->priv->name, bytes, SL_ATTRIBUTE_SYS_TYPE_BYTE);*/
/* TODO: Free bytes here. For the moment the bytes are just passed
- * through the mapper, so they are still needed later */
+ * through the mapper, so they are still needed later
}
else
- {
- value = sl_attribute_mapper_read (self->priv->name, evalue, SL_ATTRIBUTE_SYS_TYPE_STRING);
- }
+ {*/
+ value = sl_attribute_mapper_read (self->priv->name, evalue);
+ /*}*/
self->priv->values = g_list_append (self->priv->values, value);
}
@@ -321,18 +324,19 @@
void sl_attribute_add (SlAttribute *self, gpointer value)
{
- SlAttributeSysType systype = 0;
- gpointer evalue = sl_attribute_mapper_write (self->priv->name, value, &systype);
+ gpointer evalue = sl_attribute_mapper_write (self->priv->name, value);
/* TODO: encode value if binary */
self->priv->values = g_list_append (self->priv->values, value);
e_vcard_attribute_add_value (self->priv->eattr, evalue);
+ /* TODO: libebook crap: every ; seperates a value, so structs are just lists
+ * of values. 2 structs is a list of double length... solutions: a) don't use
+ * ; anymore for systypes and split before inserting in eattr. b) no idea*/
}
gboolean sl_attribute_set_at (SlAttribute *self, gint index, gpointer value)
{
- SlAttributeSysType systype = 0;
- gpointer result = sl_attribute_mapper_write (self->priv->name, value, &systype);
+ gpointer result = sl_attribute_mapper_write (self->priv->name, value);
GList *evalues = e_vcard_attribute_get_values (self->priv->eattr);
GList *evalue_nth = g_list_nth (evalues, index);
@@ -347,19 +351,7 @@
/* TODO: user has to free value, I don't know how */
value_nth->data = value;
- switch (systype)
- {
- case SL_ATTRIBUTE_SYS_TYPE_STRING:
- evalue_nth->data = result;
- break;
- case SL_ATTRIBUTE_SYS_TYPE_BYTE:
- /* TODO: encode in base64 */
- g_warning ("binary encoding not implemented yet");
- evalue_nth->data = result;
- break;
- default:
- g_assert_not_reached ();
- }
+ evalue_nth->data = result;
return TRUE;
}
Modified: trunk/libsoylent/sl-attributes.c
==============================================================================
--- trunk/libsoylent/sl-attributes.c (original)
+++ trunk/libsoylent/sl-attributes.c Fri Aug 1 13:09:36 2008
@@ -37,8 +37,8 @@
static GHashTable *attr_defs = NULL;
static GHashTable *attr_mappers = NULL;
-static SlAttributeMapper *attrmapper_string_string = NULL;
-static SlAttributeMapper *attrmapper_byte_byte = NULL;
+static SlAttributeMapper *attrmapper_default = NULL;
+static SlAttributeToStringFunc to_string_default = NULL;
void
sl_attributes_init (void)
@@ -46,60 +46,61 @@
attr_defs = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
attr_mappers = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
- attrmapper_string_string = (SlAttributeMapper *) sl_install_attribute_mapper (
- "string-string", SL_ATTRIBUTE_SYS_TYPE_STRING,
- SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_string_string),
- SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_string_string));
- attrmapper_byte_byte = (SlAttributeMapper *) sl_install_attribute_mapper (
- "byte-byte", SL_ATTRIBUTE_SYS_TYPE_STRING,
- SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_byte_byte),
- SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_byte_byte));
+ to_string_default = SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string);
- sl_install_attribute_mapper ("gint-string", SL_ATTRIBUTE_SYS_TYPE_STRING,
- SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_gint_string),
- SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_gint_string));
- sl_install_attribute_mapper ("gdate-string", SL_ATTRIBUTE_SYS_TYPE_STRING,
- SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_gdate_string),
- SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_gdate_string));
- sl_install_attribute_mapper ("sladdress-string", SL_ATTRIBUTE_SYS_TYPE_STRING,
- SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_sladdress_string),
- SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_sladdress_string));
+ attrmapper_default = (SlAttributeMapper *) sl_install_attribute_mapper (
+ "string",
+ SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_string),
+ SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_string));
+
+ sl_install_attribute_mapper ("bytes",
+ SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_bytes),
+ SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_bytes));
+ sl_install_attribute_mapper ("gint",
+ SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_gint),
+ SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_gint));
+ sl_install_attribute_mapper ("gdate",
+ SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_gdate),
+ SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_gdate));
+ sl_install_attribute_mapper ("sladdress",
+ SL_ATTRIBUTE_WRITER_FUNC (sl_attribute_writer_sladdress),
+ SL_ATTRIBUTE_READER_FUNC (sl_attribute_reader_sladdress));
/* TODO: perhaps this should go to SlPerson? */
- sl_install_attribute (SL_ATTR_ID, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_ID, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_NAME, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_NAME, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_NICK, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_NICK, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_GROUP, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_GROUP, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_ADDRESS, "sladdress-string", g_free,
+ sl_install_attribute (SL_ATTR_ADDRESS, "sladdress", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_sladdress_to_string));
- sl_install_attribute (SL_ATTR_EMAIL, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_EMAIL, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_TELEPHONE, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_TELEPHONE, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_BIRTHDAY, "gdate-string", (GDestroyNotify) g_date_free,
+ sl_install_attribute (SL_ATTR_BIRTHDAY, "gdate", (GDestroyNotify) g_date_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_gdate_to_string));
- sl_install_attribute (SL_ATTR_URL, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_URL, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_BLOG, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_BLOG, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_CALENDAR_URL, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_CALENDAR_URL, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_FREE_BUSY_URL, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_FREE_BUSY_URL, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_NOTE, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_NOTE, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_PHOTO, "byte-byte", (GDestroyNotify) g_byte_array_free,
- SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_byte_to_string));
- sl_install_attribute (SL_ATTR_ICON, "byte-byte", (GDestroyNotify) g_byte_array_free,
- SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_byte_to_string));
- sl_install_attribute (SL_ATTR_JOB_ROLE, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_PHOTO, "bytes", (GDestroyNotify) g_byte_array_free,
+ SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_bytes_to_string));
+ sl_install_attribute (SL_ATTR_ICON, "bytes", (GDestroyNotify) g_byte_array_free,
+ SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_bytes_to_string));
+ sl_install_attribute (SL_ATTR_JOB_ROLE, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
- sl_install_attribute (SL_ATTR_JOB_TITLE, "string-string", g_free,
+ sl_install_attribute (SL_ATTR_JOB_TITLE, "string", g_free,
SL_ATTRIBUTE_TO_STRING_FUNC (sl_attribute_string_to_string));
}
@@ -114,11 +115,9 @@
const SlAttributeMapper *
sl_install_attribute_mapper (const gchar *mappername,
- SlAttributeSysType systype, SlAttributeWriterFunc writer,
- SlAttributeReaderFunc reader)
+ SlAttributeWriterFunc writer, SlAttributeReaderFunc reader)
{
SlAttributeMapper *mapper = g_new (SlAttributeMapper, 1);
- mapper->systype = systype;
mapper->writer = writer;
mapper->reader = reader;
@@ -155,7 +154,7 @@
SlAttributeToStringFunc to_string = NULL;
if (attrdef == NULL || attrdef->to_string == NULL)
{
- to_string = sl_attribute_default_to_string;
+ to_string = to_string_default;
}
else
{
@@ -174,8 +173,7 @@
* if (systype == BYTES) encode base64
* now store in EDS */
gpointer
-sl_attribute_mapper_write (const gchar *attrname, gpointer value,
- SlAttributeSysType *systype)
+sl_attribute_mapper_write (const gchar *attrname, gpointer value)
{
SlAttributeMapper *mapper = NULL;
SlAttributeDef *attrdef = g_hash_table_lookup (attr_defs, attrname);
@@ -185,18 +183,15 @@
}
else
{
- mapper = attrmapper_string_string;
+ mapper = attrmapper_default;
}
-
- *systype = mapper->systype;
+
return mapper->writer (attrname, value);
}
gpointer
-sl_attribute_mapper_read (const gchar *attrname, gpointer value,
- SlAttributeSysType systype)
+sl_attribute_mapper_read (const gchar *attrname, gpointer value)
{
- g_debug ("mapper: reading %s", attrname);
SlAttributeMapper *mapper = NULL;
SlAttributeDef *attrdef = g_hash_table_lookup (attr_defs, attrname);
if (attrdef != NULL)
@@ -205,50 +200,40 @@
}
else
{
- switch (systype)
- {
- case SL_ATTRIBUTE_SYS_TYPE_STRING:
- mapper = attrmapper_string_string;
- break;
- case SL_ATTRIBUTE_SYS_TYPE_BYTE:
- mapper = attrmapper_byte_byte;
- break;
- default:
- g_assert_not_reached ();
- }
+ mapper = attrmapper_default;
}
return mapper->reader (attrname, value);
}
gchar *
-sl_attribute_writer_string_string (const gchar *attrname, gchar *value)
+sl_attribute_writer_string (const gchar *attrname, gchar *value)
{
- /* TODO: strdup? */
- return value;
+ return g_strdup (value);
}
gchar *
-sl_attribute_reader_string_string (const gchar *attrname, gchar *value)
+sl_attribute_reader_string (const gchar *attrname, gchar *value)
{
- return value;
+ return g_strdup (value);
}
-GByteArray *
-sl_attribute_writer_byte_byte (const gchar *attrname, GByteArray *value)
+gchar *
+sl_attribute_writer_bytes (const gchar *attrname, GByteArray *bytes)
{
- /* TODO: copy? */
- return value;
+ return g_base64_encode (bytes->data, bytes->len);
}
GByteArray *
-sl_attribute_reader_byte_byte (const gchar *attrname, GByteArray *value)
+sl_attribute_reader_bytes (const gchar *attrname, gchar *string)
{
- return value;
+ GByteArray *bytes = g_byte_array_new ();
+ bytes->data = g_base64_decode (string, &bytes->len);
+ return bytes;
}
gchar *
-sl_attribute_writer_gint_string (const gchar *attrname, GValue *value)
+sl_attribute_writer_gint (const gchar *attrname, GValue *value)
{
GString *str = g_string_new (NULL);
g_string_printf (str, "%d", g_value_get_int (value));
@@ -256,7 +241,7 @@
}
GValue *
-sl_attribute_reader_gint_string (const gchar *attrname, gchar *value)
+sl_attribute_reader_gint (const gchar *attrname, gchar *value)
{
GValue *gvalue = g_new (GValue, 1);
g_value_init (gvalue, G_TYPE_INT);
@@ -265,15 +250,14 @@
}
gchar *
-sl_attribute_writer_gdate_string (const gchar *attrname, GDate *date)
+sl_attribute_writer_gdate (const gchar *attrname, GDate *date)
{
return sl_attribute_gdate_to_string (attrname, date);
}
GDate *
-sl_attribute_reader_gdate_string (const gchar *attrname, gchar *string)
+sl_attribute_reader_gdate (const gchar *attrname, gchar *string)
{
- g_debug ("eds raw bday: %s", string);
/* TODO: more error handling */
gchar **tokens = g_strsplit (string, "-", 0);
gint year = strtol (tokens[0], NULL, 10);
@@ -284,8 +268,9 @@
}
gchar *
-sl_attribute_writer_sladdress_string (const gchar *attrname, SlAddress *address)
+sl_attribute_writer_sladdress (const gchar *attrname, SlAddress *address)
{
+ /* TODO: how to handle structs from eds? */
/* to the post office box; the extended address; the street
address; the locality (e.g., city); the region (e.g., state or
province); the postal code; the country name */
@@ -297,31 +282,34 @@
}
SlAddress *
-sl_attribute_reader_sladdress_string (const gchar *attrname, gchar *string)
+sl_attribute_reader_sladdress (const gchar *attrname, gchar *string)
{
+ /* TODO: how to handle structs from eds? */
g_debug ("from eds: %s", string);
return NULL;
}
-gchar *
-sl_attribute_default_to_string (const gchar *attrname, gpointer value)
-{
- /*GString *gstr = g_string_new (NULL);
- g_string_printf (gstr, "&0x%.8x", (guint) value);
- gchar *str = gstr->str;
- g_string_free (gstr, FALSE);
- return str;*/
- return sl_attribute_string_to_string (attrname, value);
-}
+#define STRING_TO_STRING_MAX_LEN 60
gchar *
sl_attribute_string_to_string (const gchar *attrname, gchar *string)
{
- return g_strdup (string);
+ if (g_utf8_strlen (string, -1) > STRING_TO_STRING_MAX_LEN)
+ {
+ GString *gstr = g_string_new_len (string, STRING_TO_STRING_MAX_LEN - 3);
+ g_string_append (gstr, "...");
+ string = gstr->str;
+ g_string_free (gstr, FALSE);
+ }
+ else
+ {
+ string = g_strdup (string);
+ }
+ return string;
}
gchar *
-sl_attribute_byte_to_string (const gchar *attrname, GByteArray *bytes)
+sl_attribute_bytes_to_string (const gchar *attrname, GByteArray *bytes)
{
GString *gstr = g_string_new (NULL);
g_string_printf (gstr, "GByteArray [&0x%.8x, length: %db]", (guint) bytes->data, bytes->len);
Modified: trunk/libsoylent/sl-attributes.h
==============================================================================
--- trunk/libsoylent/sl-attributes.h (original)
+++ trunk/libsoylent/sl-attributes.h Fri Aug 1 13:09:36 2008
@@ -47,15 +47,8 @@
typedef struct _SlAttributeDef SlAttributeDef;
typedef struct _SlAttributeMapper SlAttributeMapper;
-enum _SlAttributeSysType
-{
- SL_ATTRIBUTE_SYS_TYPE_STRING = 1,
- SL_ATTRIBUTE_SYS_TYPE_BYTE
-};
-
struct _SlAttributeMapper
{
- SlAttributeSysType systype;
SlAttributeWriterFunc writer;
SlAttributeReaderFunc reader;
};
@@ -71,39 +64,35 @@
void sl_attributes_cleanup (void);
const SlAttributeMapper *sl_install_attribute_mapper (const gchar *mappername,
- SlAttributeSysType systype, SlAttributeWriterFunc writer,
- SlAttributeReaderFunc reader);
+ SlAttributeWriterFunc writer,SlAttributeReaderFunc reader);
const SlAttributeDef *sl_install_attribute (const gchar *attrname,
const gchar *attr_mapper_name, GDestroyNotify cleanup,
SlAttributeToStringFunc to_string);
gchar *sl_attribute_to_string (const gchar *attrname, gpointer value);
-gpointer sl_attribute_mapper_write (const gchar *attrname, gpointer value,
- SlAttributeSysType *systype);
-gpointer sl_attribute_mapper_read (const gchar *attrname, gpointer value,
- SlAttributeSysType systype);
-
-gchar *sl_attribute_writer_string_string (const gchar *attrname, gchar *value);
-gchar *sl_attribute_reader_string_string (const gchar *attrname, gchar *value);
-GByteArray *sl_attribute_writer_byte_byte (const gchar *attrname,
- GByteArray *value);
-GByteArray *sl_attribute_reader_byte_byte (const gchar *attrname,
- GByteArray *value);
-gchar *sl_attribute_writer_gint_string (const gchar *attrname, GValue *value);
-GValue *sl_attribute_reader_gint_string (const gchar *attrname, gchar *value);
-gchar *sl_attribute_writer_gdate_string (const gchar *attrname, GDate *date);
-GDate *sl_attribute_reader_gdate_string (const gchar *attrname, gchar *string);
-gchar *sl_attribute_writer_sladdress_string (const gchar *attrname,
- SlAddress *address);
-SlAddress *sl_attribute_reader_sladdress_string (const gchar *attrname,
- gchar *string);
+gpointer sl_attribute_mapper_write (const gchar *attrname, gpointer value);
+gpointer sl_attribute_mapper_read (const gchar *attrname, gpointer value);
+
+gchar *sl_attribute_writer_string (const gchar *attrname, gchar *value);
+gchar *sl_attribute_reader_string (const gchar *attrname, gchar *value);
+gchar *sl_attribute_writer_bytes (const gchar *attrname, GByteArray *bytes);
+GByteArray *sl_attribute_reader_bytes (const gchar *attrname,
+ gchar *string);
+gchar *sl_attribute_writer_gint (const gchar *attrname, GValue *value);
+GValue *sl_attribute_reader_gint (const gchar *attrname, gchar *value);
+gchar *sl_attribute_writer_gdate (const gchar *attrname, GDate *date);
+GDate *sl_attribute_reader_gdate (const gchar *attrname, gchar *string);
+gchar *sl_attribute_writer_sladdress (const gchar *attrname,
+ SlAddress *address);
+SlAddress *sl_attribute_reader_sladdress (const gchar *attrname, gchar *string);
gchar *sl_attribute_default_to_string (const gchar *attrname, gpointer value);
gchar *sl_attribute_string_to_string (const gchar *attrname, gchar *string);
-gchar *sl_attribute_byte_to_string (const gchar *attrname, GByteArray *bytes);
+gchar *sl_attribute_bytes_to_string (const gchar *attrname, GByteArray *bytes);
gchar *sl_attribute_gint_to_string (const gchar *attrname, GValue *value);
gchar *sl_attribute_gdate_to_string (const gchar *attrname, GDate *date);
-gchar *sl_attribute_sladdress_to_string (const gchar *attrname, SlAddress *address);
+gchar *sl_attribute_sladdress_to_string (const gchar *attrname,
+ SlAddress *address);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]