aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/util/eab-book-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/util/eab-book-util.c')
-rw-r--r--addressbook/util/eab-book-util.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c
index 53a09c323b..f6429dee0a 100644
--- a/addressbook/util/eab-book-util.c
+++ b/addressbook/util/eab-book-util.c
@@ -188,6 +188,18 @@ eab_contact_list_from_string (const char *str)
char *q;
char *blank_line;
+ if (!p)
+ return NULL;
+
+ if (!strncmp (p, "Book: ", 6)) {
+ p = strchr (p, '\n');
+ if (!p) {
+ g_warning (G_STRLOC ": Got book but no newline!");
+ return NULL;
+ }
+ p++;
+ }
+
while (*p) {
if (*p != '\r') g_string_append_c (gstr, *p);
@@ -240,6 +252,59 @@ eab_contact_list_to_string (GList *contacts)
return g_string_free (str, FALSE);
}
+gboolean
+eab_book_and_contact_list_from_string (const char *str, EBook **book, GList **contacts)
+{
+ const char *s0, *s1;
+ char *uri;
+
+ g_return_val_if_fail (str != NULL, FALSE);
+ g_return_val_if_fail (book != NULL, FALSE);
+ g_return_val_if_fail (contacts != NULL, FALSE);
+
+ *contacts = eab_contact_list_from_string (str);
+
+ if (!strncmp (str, "Book: ", 6)) {
+ s0 = str + 6;
+ s1 = strchr (str, '\r');
+
+ if (!s1)
+ s1 = strchr (str, '\n');
+ } else {
+ s0 = NULL;
+ s1 = NULL;
+ }
+
+ if (!s0 || !s1) {
+ *book = NULL;
+ return FALSE;
+ }
+
+ uri = g_strndup (s0, s1 - s0);
+ *book = e_book_new_from_uri (uri, NULL);
+ g_free (uri);
+
+ return *book ? TRUE : FALSE;
+}
+
+char *
+eab_book_and_contact_list_to_string (EBook *book, GList *contacts)
+{
+ char *s0, *s1;
+
+ s0 = eab_contact_list_to_string (contacts);
+ if (!s0)
+ s0 = g_strdup ("");
+
+ if (book)
+ s1 = g_strconcat ("Book: ", e_book_get_uri (book), "\r\n", s0, NULL);
+ else
+ s1 = g_strdup (s0);
+
+ g_free (s0);
+ return s1;
+}
+
#if notyet
/*
* Convenience routine to check for addresses in the local address book.