aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/util/eab-book-util.c
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/util/eab-book-util.c
parentc6ba8e9f2d7c34b91e965343c9356d7e2a80e1a7 (diff)
downloadgsoc2013-evolution-a5157a42da8130dbdf50ad0d5053378b13c2b882.tar.gz
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/util/eab-book-util.c')
-rw-r--r--addressbook/util/eab-book-util.c72
1 files changed, 53 insertions, 19 deletions
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;
}