From b42213aa6c2481a7b41e965ae718721cbc4433fe Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Mon, 3 Feb 2014 21:51:43 +0200 Subject: [PATCH] [PATCH v3 3/6] util: make sanitize string available in string util for reuse --- 2f/a2a1779b32c94147cb2435bf60f5fdfc487120 | 162 ++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 2f/a2a1779b32c94147cb2435bf60f5fdfc487120 diff --git a/2f/a2a1779b32c94147cb2435bf60f5fdfc487120 b/2f/a2a1779b32c94147cb2435bf60f5fdfc487120 new file mode 100644 index 000000000..2ceec4bb0 --- /dev/null +++ b/2f/a2a1779b32c94147cb2435bf60f5fdfc487120 @@ -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 825DB429E4B + for ; Mon, 3 Feb 2014 11:52:18 -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 2g2Z9HY8NUl9 for ; + Mon, 3 Feb 2014 11:52:14 -0800 (PST) +Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com + [74.125.83.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + F395F431FBC for ; Mon, 3 Feb 2014 11:52:06 -0800 + (PST) +Received: by mail-ee0-f45.google.com with SMTP id b15so3782391eek.18 + for ; Mon, 03 Feb 2014 11:52:04 -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=JwBvHluoJzjtyBf6dvx9NzZqVeYE9ZEAZ90FMAsmkB4=; + b=UgOkw0rCgZCt7GdkkzOuDAkel8Sxl25xYYQofQY/EJ5JgUf7hWHVP3rAqNUhEyxkp0 + SrHSe6AAvL0JzRV2uSQn8lNAEv28GO61NDzDWjFf8B4i7/UgbJ6bD/meFJzpXv+Zmsd3 + 1lujxDd79TsLcIEfatG8dWHYVpOZ5fknCOmxF5cxyJ1yZmfhZEdLCLgFgvI9s4kOPbB4 + jmZQYGTO8MvrCkMYBNZcHVrcYZxf4wEdmH4Jst1AkUVtX6K7YOkEKSSOrR5zWLKNKiCo + kMA+qNIYKLw7XQK26NlxIPGBnsWcQ1Y3hENX+0ztSbCMHdgTuRW1ohOvMhsmWRtGB+HH + FVTQ== +X-Gm-Message-State: + ALoCoQnVI1apW47ZVS9GBCNYBW9hnT/Ih+34Lqtf2A5DuybPP2nIDXWb6jNu07s8wCTdAZrMNCW5 +X-Received: by 10.14.216.3 with SMTP id f3mr5126715eep.66.1391457124479; + Mon, 03 Feb 2014 11:52:04 -0800 (PST) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id d9sm52614741eei.9.2014.02.03.11.52.02 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 03 Feb 2014 11:52:03 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v3 3/6] util: make sanitize string available in string util + for reuse +Date: Mon, 3 Feb 2014 21:51:43 +0200 +Message-Id: + +X-Mailer: git-send-email 1.8.5.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: Mon, 03 Feb 2014 19:52:18 -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 0262eb3..bc9be45 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..8a3ad19 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 characters (tabs and newlines) are 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.5.2 + -- 2.26.2