Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 34 / 36d970c5bc63cca915aecb0437b3396a638538
1 Return-Path: <bremner@tethera.net>\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 BD08E431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 04:23:47 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id CXd66+iA+4IA for <notmuch@notmuchmail.org>;\r
16         Sun, 30 Mar 2014 04:23:38 -0700 (PDT)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id EB82E431FB6\r
21         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 04:23:37 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1WUDpr-0002vi-CJ; Sun, 30 Mar 2014 08:23:31 -0300\r
25 Received: (nullmailer pid 7793 invoked by uid 1000); Sun, 30 Mar 2014\r
26         11:23:27 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v3] util: add gzreadline\r
30 Date: Sun, 30 Mar 2014 08:23:22 -0300\r
31 Message-Id: <1396178602-7583-1-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.9.0\r
33 In-Reply-To: <m2zjk8um02.fsf@guru.guru-group.fi>\r
34 References: <m2zjk8um02.fsf@guru.guru-group.fi>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Sun, 30 Mar 2014 11:23:47 -0000\r
48 \r
49 The idea is to provide a more or less drop in replacement for readline\r
50 to read from zlib/gzip streams.  Take the opportunity to replace\r
51 malloc with talloc.\r
52 ---\r
53 \r
54 This corrects one nasty bug, and a few style/optimization issues brought up by Tomi.\r
55 \r
56 I'm not sure about the name. I agree in principle it would be good to\r
57 signal "talloc". I'm just not sure the best way to do that.\r
58 \r
59 I'm also not sure about the error handling. the "real" getline sets\r
60 errno. Should we?\r
61 \r
62  util/Makefile.local |  2 +-\r
63  util/zlib-extra.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
64  util/zlib-extra.h   | 10 +++++++++\r
65  3 files changed, 73 insertions(+), 1 deletion(-)\r
66  create mode 100644 util/zlib-extra.c\r
67  create mode 100644 util/zlib-extra.h\r
68 \r
69 diff --git a/util/Makefile.local b/util/Makefile.local\r
70 index 29c0ce6..e2a5b65 100644\r
71 --- a/util/Makefile.local\r
72 +++ b/util/Makefile.local\r
73 @@ -4,7 +4,7 @@ dir := util\r
74  extra_cflags += -I$(srcdir)/$(dir)\r
75  \r
76  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
77 -                 $(dir)/string-util.c $(dir)/talloc-extra.c\r
78 +                 $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c\r
79  \r
80  libutil_modules := $(libutil_c_srcs:.c=.o)\r
81  \r
82 diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
83 new file mode 100644\r
84 index 0000000..7afe175\r
85 --- /dev/null\r
86 +++ b/util/zlib-extra.c\r
87 @@ -0,0 +1,62 @@\r
88 +/* zlib-extra.c -  Extra or enhanced routines for compressed I/O.\r
89 + *\r
90 + * Copyright (c) 2014 David Bremner\r
91 + *\r
92 + * This program is free software: you can redistribute it and/or modify\r
93 + * it under the terms of the GNU General Public License as published by\r
94 + * the Free Software Foundation, either version 3 of the License, or\r
95 + * (at your option) any later version.\r
96 + *\r
97 + * This program is distributed in the hope that it will be useful,\r
98 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
99 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
100 + * GNU General Public License for more details.\r
101 + *\r
102 + * You should have received a copy of the GNU General Public License\r
103 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
104 + *\r
105 + * Author: David Bremner <david@tethera.net>\r
106 + */\r
107 +\r
108 +#include "zlib-extra.h"\r
109 +#include <talloc.h>\r
110 +#include <stdio.h>\r
111 +#include <string.h>\r
112 +\r
113 +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
114 +ssize_t\r
115 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {\r
116 +\r
117 +    size_t len = *n;\r
118 +    char *buf = *lineptr;\r
119 +    size_t offset = 0;\r
120 +\r
121 +    if (len == 0 || buf == NULL) {\r
122 +       /* same as getdelim from gnulib */\r
123 +       len = 120;\r
124 +       buf = talloc_size (ctx, len);\r
125 +       if (buf == NULL)\r
126 +           return -1;\r
127 +    }\r
128 +\r
129 +    while (1) {\r
130 +\r
131 +       if (!gzgets (stream, buf + offset, len - offset))\r
132 +           return -1;\r
133 +\r
134 +       offset += strlen (buf+offset);\r
135 +\r
136 +       if ( buf[offset-1] == '\n' )\r
137 +           break;\r
138 +\r
139 +       len *= 2;\r
140 +       buf = talloc_realloc (ctx, buf, char, len);\r
141 +       if (buf == NULL)\r
142 +           return -1;\r
143 +\r
144 +    }\r
145 +\r
146 +    *lineptr = buf;\r
147 +    *n = len;\r
148 +    return offset;\r
149 +}\r
150 diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
151 new file mode 100644\r
152 index 0000000..c18480f\r
153 --- /dev/null\r
154 +++ b/util/zlib-extra.h\r
155 @@ -0,0 +1,10 @@\r
156 +#ifndef _ZLIB_EXTRA_H\r
157 +#define _ZLIB_EXTRA_H\r
158 +\r
159 +#include <zlib.h>\r
160 +\r
161 +/* Like getline, but read from a gzFile. Allocation is with talloc */\r
162 +ssize_t\r
163 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);\r
164 +\r
165 +#endif\r
166 -- \r
167 1.9.0\r
168 \r