From: Jani Nikula Date: Sat, 30 Nov 2013 15:33:52 +0000 (+0200) Subject: [PATCH v2 3/7] util: make sanitize string available in string util for reuse X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cef8f6041b49395b3b591fa91033b9fa5c80543a;p=notmuch-archives.git [PATCH v2 3/7] util: make sanitize string available in string util for reuse --- diff --git a/2c/c7a24b0c1abaca59837d0c2887483ec7ad1eb3 b/2c/c7a24b0c1abaca59837d0c2887483ec7ad1eb3 new file mode 100644 index 000000000..55e2b845d --- /dev/null +++ b/2c/c7a24b0c1abaca59837d0c2887483ec7ad1eb3 @@ -0,0 +1,162 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id E8913431FBC + for ; Sat, 30 Nov 2013 07:34:16 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id DapZPzOilK5N for ; + Sat, 30 Nov 2013 07:34:11 -0800 (PST) +Received: from mail-ea0-f174.google.com (mail-ea0-f174.google.com + [209.85.215.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 6A75E431FC7 + for ; Sat, 30 Nov 2013 07:34:08 -0800 (PST) +Received: by mail-ea0-f174.google.com with SMTP id b10so7490094eae.19 + for ; Sat, 30 Nov 2013 07:34:07 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=awJ8sTwb5zV9KmWYH7p/0CJsHSvVgVzVXv9ctBdYGDE=; + b=Ahw92OUn+d3zEv5VY0lE5NiCQV+8TNuowPeT+hj5bNtpL9uTmrbbClLn/y4/MtYq9T + 9+xWAbReT30bQxVByPq/ekHigTZkSNkXZa44Pc0mV7nBgsZcmULh43K35IOO7MLgH6hq + cbW5FeG68KYBYy+w3C8G+GgnE7oYtFpzGZwliec4mh0i5h3i1I6toiNtDLtta+TrqP9A + Mk8AA4bqRNJrpHk1wTfRCCA5Rh2t31aXpYHxeeiWWPNmtSeAKBE6Vt2YeKRvsHrRtxx8 + jYIdbrJ37Df/G4hrMHOVfMqhFLvynn90FU+7vYHWIVab8qFoCQ5+MneUmr7LVGeCDGH4 + 1VSQ== +X-Gm-Message-State: + ALoCoQmscjeV69WeNI4ij2DIFhOCSr20xdoAVe/p01QG7JbtERukMcJM1Iw02f1siHEpC+l3SBf3 +X-Received: by 10.15.67.195 with SMTP id u43mr33405654eex.14.1385825647433; + Sat, 30 Nov 2013 07:34:07 -0800 (PST) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id b42sm51870665eem.9.2013.11.30.07.34.06 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 30 Nov 2013 07:34:06 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/7] util: make sanitize string available in string util + for reuse +Date: Sat, 30 Nov 2013 17:33:52 +0200 +Message-Id: + <6859d1e9de273e00101c10122cd8ca162cc3a542.1385825425.git.jani@nikula.org> +X-Mailer: git-send-email 1.8.4.2 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 30 Nov 2013 15:34:17 -0000 + +No functional changes. +--- + notmuch-search.c | 19 ------------------- + util/string-util.c | 22 ++++++++++++++++++++++ + util/string-util.h | 7 +++++++ + 3 files changed, 29 insertions(+), 19 deletions(-) + +diff --git a/notmuch-search.c b/notmuch-search.c +index 11cd6ee..8b6940a 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -30,25 +30,6 @@ typedef enum { + OUTPUT_TAGS + } output_t; + +-static char * +-sanitize_string (const void *ctx, const char *str) +-{ +- char *out, *loop; +- +- if (NULL == str) +- return NULL; +- +- loop = out = talloc_strdup (ctx, str); +- +- for (; *loop; loop++) { +- if (*loop == '\t' || *loop == '\n') +- *loop = ' '; +- else if ((unsigned char)(*loop) < 32) +- *loop = '?'; +- } +- return out; +-} +- + /* Return two stable query strings that identify exactly the matched + * and unmatched messages currently in thread. If there are no + * matched or unmatched messages, the returned buffers will be +diff --git a/util/string-util.c b/util/string-util.c +index a5622d7..9e2f728 100644 +--- a/util/string-util.c ++++ b/util/string-util.c +@@ -37,6 +37,28 @@ strtok_len (char *s, const char *delim, size_t *len) + return *len ? s : NULL; + } + ++char * ++sanitize_string (const void *ctx, const char *str) ++{ ++ char *out, *loop; ++ ++ if (! str) ++ return NULL; ++ ++ out = talloc_strdup (ctx, str); ++ if (! out) ++ return NULL; ++ ++ for (loop = out; *loop; loop++) { ++ if (*loop == '\t' || *loop == '\n') ++ *loop = ' '; ++ else if ((unsigned char)(*loop) < 32) ++ *loop = '?'; ++ } ++ ++ return out; ++} ++ + static int + is_unquoted_terminator (unsigned char c) + { +diff --git a/util/string-util.h b/util/string-util.h +index 0194607..228420d 100644 +--- a/util/string-util.h ++++ b/util/string-util.h +@@ -19,6 +19,13 @@ + + char *strtok_len (char *s, const char *delim, size_t *len); + ++/* Return a talloced string with str sanitized. ++ * ++ * Whitespace (tabs and newlines) is replaced with spaces, ++ * non-printable characters with question marks. ++ */ ++char *sanitize_string (const void *ctx, const char *str); ++ + /* Construct a boolean term query with the specified prefix (e.g., + * "id") and search term, quoting term as necessary. Specifically, if + * term contains any non-printable ASCII characters, non-ASCII +-- +1.8.4.2 +