aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2004-01-24 03:35:02 +0800
committerChris Toshok <toshok@src.gnome.org>2004-01-24 03:35:02 +0800
commita5157a42da8130dbdf50ad0d5053378b13c2b882 (patch)
tree43967072a2b47e9591fd3d2818b81876864f6894 /addressbook
parentc6ba8e9f2d7c34b91e965343c9356d7e2a80e1a7 (diff)
downloadgsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.gz
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.bz2
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.lz
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.xz
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.zst
gsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.zip
[ fixes bug #52571 ] ugh. name fields that have \" around the name break
2004-01-23 Chris Toshok <toshok@ximian.com> [ fixes bug #52571 ] * util/eab-book-util.c (escape): ugh. name fields that have \" around the name break our queries, because it turns it into (for instance): (contains "full_name" ""Toshok""). so we need to turn that into: (contains "full_name" "\"Toshok\""). (eab_name_and_email_query): escape both the name and email, and use an EBookQuery instead of passing the string to e_book_async_get_contacts. Looks like ross missed a couple of spots. (eab_nickname_query): same. * gui/component/addressbook.c (free_load_source_data): new function, free up the data and unref the source if there is one. (load_source_auth_cb): call free_load_source_data instead of just g_free'ing the struct. (load_source_cb): same. (default_book_cb): new function, we need this so we can fill in the source for the default book. get the source, then call load_source_cb to continue processing as normal. (addressbook_load_default_book): use default_book_cb instead of load_source_cb. svn path=/trunk/; revision=24383
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog24
-rw-r--r--addressbook/gui/component/addressbook.c36
-rw-r--r--addressbook/util/eab-book-util.c72
3 files changed, 103 insertions, 29 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index e656ad2861..7b7807c163 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,27 @@
+2004-01-23 Chris Toshok <toshok@ximian.com>
+
+ [ fixes bug #52571 ]
+ * util/eab-book-util.c (escape): ugh. name fields that have \"
+ around the name break our queries, because it turns it into (for
+ instance): (contains "full_name" ""Toshok""). so we need to turn
+ that into: (contains "full_name" "\"Toshok\"").
+ (eab_name_and_email_query): escape both the name and email, and
+ use an EBookQuery instead of passing the string to
+ e_book_async_get_contacts. Looks like ross missed a couple of
+ spots.
+ (eab_nickname_query): same.
+
+ * gui/component/addressbook.c (free_load_source_data): new
+ function, free up the data and unref the source if there is one.
+ (load_source_auth_cb): call free_load_source_data instead of just
+ g_free'ing the struct.
+ (load_source_cb): same.
+ (default_book_cb): new function, we need this so we can fill in
+ the source for the default book. get the source, then call
+ load_source_cb to continue processing as normal.
+ (addressbook_load_default_book): use default_book_cb instead of
+ load_source_cb.
+
2004-01-22 Chris Toshok <toshok@ximian.com>
[ fixes bug #53184 ]
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index 1062e2632d..dcf85d9d79 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -686,12 +686,20 @@ typedef struct {
} LoadSourceData;
static void
+free_load_source_data (LoadSourceData *data)
+{
+ if (data->source)
+ g_object_unref (data->source);
+ g_free (data);
+}
+
+static void
load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure)
{
LoadSourceData *data = closure;
if (data->cancelled) {
- g_free (data);
+ free_load_source_data (data);
return;
}
@@ -707,7 +715,7 @@ load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure)
g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_widget_show (dialog);
data->cb (book, E_BOOK_ERROR_OK, data->closure);
- g_free (data);
+ free_load_source_data (data);
return;
}
else {
@@ -723,8 +731,7 @@ load_source_auth_cb (EBook *book, EBookStatus status, gpointer closure)
data->cb (book, status, data->closure);
- g_object_unref (data->source);
- g_free (data);
+ free_load_source_data (data);
}
static gboolean
@@ -812,7 +819,7 @@ load_source_cb (EBook *book, EBookStatus status, gpointer closure)
LoadSourceData *load_source_data = closure;
if (load_source_data->cancelled) {
- g_free (load_source_data);
+ free_load_source_data (load_source_data);
return;
}
@@ -832,8 +839,7 @@ load_source_cb (EBook *book, EBookStatus status, gpointer closure)
}
load_source_data->cb (book, status, load_source_data->closure);
- g_object_unref (load_source_data->source);
- g_free (load_source_data);
+ free_load_source_data (load_source_data);
}
guint
@@ -860,17 +866,27 @@ addressbook_load_source_cancel (guint id)
load_source_data->cancelled = TRUE;
}
+static void
+default_book_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ LoadSourceData *load_source_data = closure;
+
+ if (status == E_BOOK_ERROR_OK)
+ load_source_data->source = g_object_ref (e_book_get_source (book));
+
+ load_source_cb (book, status, closure);
+}
+
void
addressbook_load_default_book (EBookCallback cb, gpointer closure)
{
LoadSourceData *load_source_data = g_new (LoadSourceData, 1);
- /* FIXME: We need to get the source for the default book */
-
load_source_data->cb = cb;
+ load_source_data->source = NULL;
load_source_data->closure = closure;
- e_book_async_get_default_addressbook (load_source_cb, load_source_data);
+ e_book_async_get_default_addressbook (default_book_cb, load_source_data);
}
static void
diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c
index 611944b22d..7482ad2807 100644
--- a/addressbook/util/eab-book-util.c
+++ b/addressbook/util/eab-book-util.c
@@ -50,6 +50,26 @@ eab_get_config_database ()
*
*/
+static char*
+escape (const char *str)
+{
+ GString *s = g_string_new ("");
+ const char *p = str;
+
+ while (*p) {
+ if (*p == '\\')
+ g_string_append (s, "\\\\");
+ else if (*p == '"')
+ g_string_append (s, "\\\"");
+ else
+ g_string_append_c (s, *p);
+
+ p ++;
+ }
+
+ return g_string_free (s, FALSE);
+}
+
guint
eab_name_and_email_query (EBook *book,
const gchar *name,
@@ -57,8 +77,10 @@ eab_name_and_email_query (EBook *book,
EBookContactsCallback cb,
gpointer closure)
{
- gchar *email_query=NULL, *name_query=NULL, *query;
+ gchar *email_query=NULL, *name_query=NULL;
+ EBookQuery *query;
guint tag;
+ char *escaped_name, *escaped_email;
g_return_val_if_fail (book && E_IS_BOOK (book), 0);
g_return_val_if_fail (cb != NULL, 0);
@@ -71,20 +93,23 @@ eab_name_and_email_query (EBook *book,
if (name == NULL && email == NULL)
return 0;
+ escaped_name = name ? escape (name) : NULL;
+ escaped_email = email ? escape (email) : NULL;
+
/* Build our e-mail query.
* We only query against the username part of the address, to avoid not matching
* fred@foo.com and fred@mail.foo.com. While their may be namespace collisions
* in the usernames of everyone out there, it shouldn't be that bad. (Famous last words.)
*/
- if (email) {
- const gchar *t = email;
+ if (escaped_email) {
+ const gchar *t = escaped_email;
while (*t && *t != '@')
++t;
if (*t == '@') {
- email_query = g_strdup_printf ("(beginswith \"email\" \"%.*s@\")", t-email, email);
+ email_query = g_strdup_printf ("(beginswith \"email\" \"%.*s@\")", t-escaped_email, escaped_email);
} else {
- email_query = g_strdup_printf ("(beginswith \"email\" \"%s\")", email);
+ email_query = g_strdup_printf ("(beginswith \"email\" \"%s\")", escaped_email);
}
}
@@ -93,26 +118,31 @@ eab_name_and_email_query (EBook *book,
* is that the username part of the email is good enough to keep the amount of stuff returned
* in the query relatively small.
*/
- if (name && !email)
- name_query = g_strdup_printf ("(or (beginswith \"file_as\" \"%s\") (beginswith \"full_name\" \"%s\"))", name, name);
+ if (escaped_name && !escaped_email)
+ name_query = g_strdup_printf ("(or (beginswith \"file_as\" \"%s\") (beginswith \"full_name\" \"%s\"))", escaped_name, escaped_name);
/* Assemble our e-mail & name queries */
if (email_query && name_query) {
- query = g_strdup_printf ("(and %s %s)", email_query, name_query);
- } else if (email_query) {
- query = email_query;
- email_query = NULL;
- } else if (name_query) {
- query = name_query;
- name_query = NULL;
- } else
+ char *full_query = g_strdup_printf ("(and %s %s)", email_query, name_query);
+ query = e_book_query_from_string (full_query);
+ g_free (full_query);
+ }
+ else if (email_query) {
+ query = e_book_query_from_string (email_query);
+ }
+ else if (name_query) {
+ query = e_book_query_from_string (name_query);
+ }
+ else
return 0;
tag = e_book_async_get_contacts (book, query, cb, closure);
g_free (email_query);
g_free (name_query);
- g_free (query);
+ g_free (escaped_email);
+ g_free (escaped_name);
+ e_book_query_unref (query);
return tag;
}
@@ -126,7 +156,8 @@ eab_nickname_query (EBook *book,
EBookContactsCallback cb,
gpointer closure)
{
- gchar *query;
+ EBookQuery *query;
+ char *query_string;
guint retval;
g_return_val_if_fail (E_IS_BOOK (book), 0);
@@ -136,11 +167,14 @@ eab_nickname_query (EBook *book,
if (! *nickname)
return 0;
- query = g_strdup_printf ("(is \"nickname\" \"%s\")", nickname);
+ query_string = g_strdup_printf ("(is \"nickname\" \"%s\")", nickname);
+
+ query = e_book_query_from_string (query_string);
retval = e_book_async_get_contacts (book, query, cb, closure);
- g_free (query);
+ g_free (query_string);
+ g_object_unref (query);
return retval;
}