1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id AC887421169
\r
6 for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 15:17:49 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id lCBKfDZhDz74 for <notmuch@notmuchmail.org>;
\r
17 Sat, 31 Mar 2012 15:17:48 -0700 (PDT)
\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id E5395421165
\r
22 for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 15:17:47 -0700 (PDT)
\r
23 Received: by mail-bk0-f53.google.com with SMTP id j4so1547751bkw.26
\r
24 for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 15:17:47 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references
\r
28 :in-reply-to:references:x-gm-message-state;
\r
29 bh=916Fk5v5PJ7EkIwyO9dergWO6FXSYYcbLohwghi2j7o=;
\r
30 b=gr08jZLjNwP2siIiZVdKcMzMGtroTxxqgyZsHmsRP5TwpUvVtwBE2kT+qpuocPxqn0
\r
31 UveIwHSRIy6Gr9q6ssLn8FoVj1Jk4mQRXP7Rbe6XsIGlDfoiPkN5hSt4CA6iNB6C52Sj
\r
32 MYp8SoH6xByzu1ImUdhKJ7LGH19zTa3h6RBKiAm4Qa9NUFN6i9HVYNu2nvgqPqSdLPf5
\r
33 xblO3mI+bT6Q9NC3dWh6V6EYP8js+OjCjuHhhwZwReNFPm+xooRdP2QzLG2kxUXZeO2q
\r
34 77HLAnPmZBTTgvt0KWn+6JOC2AULG8qpUTL+axUa+hboV0HLu3XlF3/MvnkGHJLYCRwD
\r
36 Received: by 10.204.154.139 with SMTP id o11mr1387845bkw.4.1333232267488;
\r
37 Sat, 31 Mar 2012 15:17:47 -0700 (PDT)
\r
38 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id r8sm8938072bki.2.2012.03.31.15.17.45
\r
41 (version=SSLv3 cipher=OTHER); Sat, 31 Mar 2012 15:17:46 -0700 (PDT)
\r
42 From: Jani Nikula <jani@nikula.org>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH 3/8] hex-escape: add function to decode escaped string
\r
46 Date: Sun, 1 Apr 2012 01:17:23 +0300
\r
48 <026815054d3e01e6f29c0834d43ccabdf6eda481.1333231401.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.5.4
\r
50 In-Reply-To: <cover.1333231401.git.jani@nikula.org>
\r
51 References: <cover.1333231401.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1333231401.git.jani@nikula.org>
\r
53 References: <cover.1333231401.git.jani@nikula.org>
\r
55 ALoCoQnI9qqQyUZDdWkPmV/b3Yb/QSpGHHob+38RirpGYe7zR67zK8ucrtOzU62C7CwxuaoxC9xb
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Sat, 31 Mar 2012 22:17:49 -0000
\r
70 Add function hex_decode_inplace() to decode the input string onto
\r
73 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
77 This could be folded to "hex-escape: (en|de)code strings to/from
\r
78 restricted character set".
\r
80 util/hex-escape.c | 62 ++++++++++++++++++++++++++++++----------------------
\r
81 util/hex-escape.h | 6 +++++
\r
82 2 files changed, 42 insertions(+), 26 deletions(-)
\r
84 diff --git a/util/hex-escape.c b/util/hex-escape.c
\r
85 index 9de79df..e794f98 100644
\r
86 --- a/util/hex-escape.c
\r
87 +++ b/util/hex-escape.c
\r
88 @@ -98,38 +98,15 @@ hex_encode (void *ctx, const char *in, char **out, size_t *out_size)
\r
93 -hex_decode (void *ctx, const char *in, char **out, size_t * out_size)
\r
94 +/* Note: This must succeed for p == q to support hex_decode_inplace(). */
\r
95 +static hex_status_t
\r
96 +hex_decode_internal (const char *p, unsigned char *q)
\r
102 - unsigned char *q;
\r
104 - size_t escape_count = 0;
\r
105 - size_t needed = 0;
\r
107 - assert (ctx); assert (in); assert (out); assert (out_size);
\r
109 - size_t len = strlen (in);
\r
111 - for (p = in; *p; p++)
\r
112 - escape_count += (*p == escape_char);
\r
114 - needed = len - escape_count * 2 + 1;
\r
116 - if (!maybe_realloc (ctx, needed, out, out_size))
\r
117 - return HEX_OUT_OF_MEMORY;
\r
120 - q = (unsigned char *) *out;
\r
125 if (*p == escape_char) {
\r
129 if (!isxdigit ((unsigned char) p[1]) ||
\r
130 @@ -155,3 +132,36 @@ hex_decode (void *ctx, const char *in, char **out, size_t * out_size)
\r
132 return HEX_SUCCESS;
\r
136 +hex_decode_inplace (char *p)
\r
138 + return hex_decode_internal (p, (unsigned char *) p);
\r
142 +hex_decode (void *ctx, const char *in, char **out, size_t * out_size)
\r
145 + unsigned char *q;
\r
147 + size_t escape_count = 0;
\r
148 + size_t needed = 0;
\r
150 + assert (ctx); assert (in); assert (out); assert (out_size);
\r
152 + size_t len = strlen (in);
\r
154 + for (p = in; *p; p++)
\r
155 + escape_count += (*p == escape_char);
\r
157 + needed = len - escape_count * 2 + 1;
\r
159 + if (!maybe_realloc (ctx, needed, out, out_size))
\r
160 + return HEX_OUT_OF_MEMORY;
\r
163 + q = (unsigned char *) *out;
\r
165 + return hex_decode_internal (p, q);
\r
167 diff --git a/util/hex-escape.h b/util/hex-escape.h
\r
168 index e409626..be70ad2 100644
\r
169 --- a/util/hex-escape.h
\r
170 +++ b/util/hex-escape.h
\r
171 @@ -29,4 +29,10 @@ hex_encode (void *talloc_ctx, const char *in, char **out,
\r
173 hex_decode (void *talloc_ctx, const char *in, char **out,
\r
177 + * Decode 'in' onto itself.
\r
180 +hex_decode_inplace (char *in);
\r