[2820] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 2/2] Kill owl_getquoting and fix quoting bugs

daemon@ATHENA.MIT.EDU (David Benjamin)
Wed Dec 15 00:01:57 2010

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Wed, 15 Dec 2010 00:00:42 -0500
In-Reply-To: <1292389242-2503-1-git-send-email-davidben@mit.edu>

That function is nonsense. Fix a number of quoting bugs relating to its
use (and lack thereof).

Also quote regex characters in CC narrows.
---
 filterelement.c |   11 ++++-------
 functions.c     |   41 +++++++++++++++++++----------------------
 global.c        |    4 +---
 text.c          |    9 ---------
 4 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/filterelement.c b/filterelement.c
index cb126f6..79e1585 100644
--- a/filterelement.c
+++ b/filterelement.c
@@ -138,27 +138,24 @@ static void owl_filterelement_print_false(const owl_filterelement *fe, GString *
 
 static void owl_filterelement_print_re(const owl_filterelement *fe, GString *buf)
 {
-  const char *re, *q;
+  const char *re;
   g_string_append(buf, fe->field);
   g_string_append(buf, " ");
 
   re = owl_regex_get_string(&(fe->re));
-  q = owl_getquoting(re);
-  g_string_append(buf, q);
-  g_string_append(buf, re);
-  g_string_append(buf, q);
+  owl_string_append_quoted_arg(buf, re);
 }
 
 static void owl_filterelement_print_filter(const owl_filterelement *fe, GString *buf)
 {
   g_string_append(buf, "filter ");
-  g_string_append(buf, fe->field);
+  owl_string_append_quoted_arg(buf, fe->field);
 }
 
 static void owl_filterelement_print_perl(const owl_filterelement *fe, GString *buf)
 {
   g_string_append(buf, "perl ");
-  g_string_append(buf, fe->field);
+  owl_string_append_quoted_arg(buf, fe->field);
 }
 
 static void owl_filterelement_print_group(const owl_filterelement *fe, GString *buf)
diff --git a/functions.c b/functions.c
index 7a8a880..98afb8a 100644
--- a/functions.c
+++ b/functions.c
@@ -2491,9 +2491,10 @@ void owl_function_delete_curview_msgs(int flag)
 
 static char *owl_function_smartfilter_cc(const owl_message *m) {
   const char *ccs;
+  char *ccs_quoted;
   char *filtname;
-  char *text;
   owl_filter *f;
+  GString *buf;
 
   ccs = owl_message_get_attribute_value(m, "zephyr_ccs");
 
@@ -2504,16 +2505,18 @@ static char *owl_function_smartfilter_cc(const owl_message *m) {
     return filtname;
   }
 
-  text = owl_sprintf("type ^zephyr$ and filter personal and "
-                     "zephyr_ccs ^%s%s%s$",
-                     owl_getquoting(ccs), ccs, owl_getquoting(ccs));
+  buf = g_string_new("type ^zephyr$ and filter personal and "
+                     "zephyr_ccs ^");
+  ccs_quoted = owl_text_quote(ccs, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
+  owl_string_append_quoted_arg(buf, ccs_quoted);
+  g_string_append_c(buf, '$');
+  owl_free(ccs_quoted);
 
-  f = owl_filter_new_fromstring(filtname, text);
+  f = owl_filter_new_fromstring(filtname, buf->str);
+  g_string_free(buf, TRUE);
 
   owl_global_add_filter(&g, f);
 
-  owl_free(text);
-
   return filtname;
 }
 
@@ -2610,8 +2613,8 @@ void owl_function_smartzpunt(int type)
    * If type=0, uses just class.  If type=1, uses instance as well. */
   const owl_view *v;
   const owl_message *m;
-  const char *cmdprefix, *mclass, *minst;
-  char *cmd;
+  const char *mclass, *minst;
+  GString *buf;
   
   v=owl_global_get_current_view(&g);
   m=owl_view_get_element(v, owl_global_get_curmsg(&g));
@@ -2637,22 +2640,16 @@ void owl_function_smartzpunt(int type)
     owl_function_error("smartzpunt can't safely do this for <%s,%s>",
 			 mclass, minst);
   } else {
-    cmdprefix = "start-command zpunt ";
-    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10);
-    strcpy(cmd, cmdprefix);
-    strcat(cmd, owl_getquoting(mclass));
-    strcat(cmd, mclass);
-    strcat(cmd, owl_getquoting(mclass));
+    buf = g_string_new("start-command zpunt ");
+    owl_string_append_quoted_arg(buf, mclass);
     if (type) {
-      strcat(cmd, " ");
-      strcat(cmd, owl_getquoting(minst));
-      strcat(cmd, minst);
-      strcat(cmd, owl_getquoting(minst));
+      g_string_append_c(buf, ' ');
+      owl_string_append_quoted_arg(buf, minst);
     } else {
-      strcat(cmd, " *");
+      g_string_append(buf, " *");
     }
-    owl_function_command(cmd);
-    owl_free(cmd);
+    owl_function_command(buf->str);
+    g_string_free(buf, TRUE);
   }
 }
 
diff --git a/global.c b/global.c
index 8eb5f68..80f5043 100644
--- a/global.c
+++ b/global.c
@@ -703,14 +703,12 @@ const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
 void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
 {
   char *sn_escaped;
-  const char *quote;
   g->aim_loggedin=1;
   if (g->aim_screenname) owl_free(g->aim_screenname);
   if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
   g->aim_screenname=owl_strdup(screenname);
   sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
-  quote = owl_getquoting(sn_escaped);
-  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
+  g->aim_screenname_for_filters = owl_arg_quote(sn_escaped);
   owl_free(sn_escaped);
 }
 
diff --git a/text.c b/text.c
index 0c31a2e..07e94de 100644
--- a/text.c
+++ b/text.c
@@ -263,15 +263,6 @@ int only_whitespace(const char *s)
   return(1);
 }
 
-const char *owl_getquoting(const char *line)
-{
-  if (line[0]=='\0') return("'");
-  if (strchr(line, '\'')) return("\"");
-  if (strchr(line, '"')) return("'");
-  if (strcspn(line, "\n\t ") != strlen(line)) return("'");
-  return("");
-}
-
 /* Return a string with any occurances of 'from' replaced with 'to'.
  * Does not currently handle backslash quoting, but may in the future.
  * Caller must free returned string.
-- 
1.7.3.3.399.g06ddf


home help back first fref pref prev next nref lref last post