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 3E668429E26 for ; Mon, 12 Dec 2011 03:30:03 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 RaH+Pqj7Iwmz for ; Mon, 12 Dec 2011 03:30:00 -0800 (PST) Received: from mail-gw3.nixu.fi (mail-gw3.nixu.fi [193.209.237.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 55D86429E25 for ; Mon, 12 Dec 2011 03:30:00 -0800 (PST) Received: from pps.filterd (mail-gw3 [127.0.0.1]) by mail-gw3.nixu.fi (8.14.4/8.14.4) with SMTP id pBCBSQBj020852; Mon, 12 Dec 2011 13:29:46 +0200 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by mail-gw3.nixu.fi with ESMTP id 114cs0stgy-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 12 Dec 2011 13:29:46 +0200 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pBCBTjeM004007; Mon, 12 Dec 2011 13:29:45 +0200 From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH] util/hex-escape.[ch]: encoding/decoding strings into restricted character set In-Reply-To: <1323620384-16043-1-git-send-email-david@tethera.net> References: <1323620384-16043-1-git-send-email-david@tethera.net> User-Agent: Notmuch/0.10.2+93~g631d290 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.5.7110, 1.0.211, 0.0.0000 definitions=2011-12-12_02:2011-12-12, 2011-12-12, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1012030000 definitions=main-1112120054 Cc: David Bremner 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, 12 Dec 2011 11:30:03 -0000 On Sun, 11 Dec 2011 12:19:44 -0400, David Bremner wrote: > From: David Bremner > > The character set is chosen to be suitable for pathnames, and the same > as that used by contrib/nmbug. The new encoded/decoded strings are > allocated using talloc. > --- > This isn't urgent, but it is useful for a couple projects I have > brewing (nmbug compatible dump/restore and tag logging), so I thought > I would get some feedback on it. > > > util/Makefile.local | 4 +- > util/hex-escape.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ > util/hex-escape.h | 10 +++++ > 3 files changed, 122 insertions(+), 2 deletions(-) > create mode 100644 util/hex-escape.c > create mode 100644 util/hex-escape.h Like Dmitry mentioned, Makefile.local change in separate patch after hex-escape additions. > diff --git a/util/hex-escape.c b/util/hex-escape.c > new file mode 100644 > index 0000000..c294bb5 > --- /dev/null > +++ b/util/hex-escape.c [ ... snip ... ] > + > +static int > +escapes_needed (const char *str){ Opening { in separate line, like in all other source files. > + int escapes = 0; > + > + while (*str) { > + if (index (HEX_NO_ESCAPE, *str) == NULL) strchr() instead of index() And, like Dmitry mentioned, static const char _hex_no_escape[] = "..."; > + escapes++; > + str++; > + } > + > + return escapes; > +} > + > +char * > +hex_encode (void *ctx, const char *str) { > + char *newstr = talloc_size (ctx, strlen (str)+3*escapes_needed (str)+1); Consistent spacing, like Dmitry mentioned (I compared with _optimize_tag_query () in notmuch-tag.c ). > + > + char *out = newstr; > + > + while (*str) { > + if (index (HEX_NO_ESCAPE, *str)) { ... if (strchr ( _hex_no_escape, *str) != NULL) { [ ... snip ... ] > + > +inline static int > +_digit (char c) { Maybe _hexdigit () ? > + if ('0' <= c && c <= '9') > + return c - '0'; > + > + if ('A' <= c && c <= 'F') > + return c - 'A'; > + > + if ('a' <= c && c <= 'f') > + return c - 'a'; Fix this (or change to sscanf) like Dmitry mentioned (c - 'A' + 10 and c - 'a' + 10) > + > + INTERNAL_ERROR ("Illegal hex digit %c", c); Is this too heavy ? -- but there may not be alternative. > + /*NOTREACHED*/ > + return 0; > +} [ ... snip ... ] Tomi