pcpstream.h
1 /*
2  This file is part of Pretty Curved Privacy (pcp1).
3 
4  Copyright (C) 2013-2014 T.v.Dein.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19  You can contact me by mail: <tom AT vondein DOT org>.
20 */
21 
22 #ifndef HAVE_PCP_PCPSTEAM_H
23 #define HAVE_PCP_PCPSTEAM_H
24 
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <assert.h>
28 #include "mem.h"
29 #include "structs.h"
30 #include "util.h"
31 #include "defines.h"
32 #include "context.h"
33 #include "buffer.h"
34 #include "z85.h"
35 
61 /* initialize a new empty stream */
62 Pcpstream *ps_init(void);
63 
72 Pcpstream *ps_new_file(FILE *backendfd);
73 
83 
92 
93 
114 size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes);
115 
131 size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes);
132 
144 size_t ps_finish(Pcpstream *stream);
145 
161 size_t ps_print(Pcpstream *stream, const char * fmt, ...);
162 
172 size_t ps_tell(Pcpstream *stream);
173 
185 Buffer *ps_buffer(Pcpstream *stream);
186 
196 void ps_close(Pcpstream *stream);
197 
209 int ps_end(Pcpstream *stream);
210 
217 int ps_err(Pcpstream *stream);
218 
219 
229 void ps_setdetermine(Pcpstream *stream, size_t blocksize);
230 
231 
238 void ps_armor(Pcpstream *stream, size_t blocksize);
239 
240 
245 void ps_unarmor(Pcpstream *stream);
246 
247 
248 
249 /* read from primary source, decode z85 and out into cache.
250  if buf != NULL, consider it as the start of encoded data
251  and remove headers and comments, then continue as normal. */
252 size_t ps_read_decode(Pcpstream *stream);
253 
254 /* determine if primary source is z85 encoded, put the data
255  read from it into the cache */
256 void ps_determine(Pcpstream *stream);
257 
258 /* read and decode the next chunk and put it into stream->next */
259 size_t ps_read_next(Pcpstream *stream);
260 
261 /* return readbytes from cache. if it is more than left in the cache
262  fetch (and decode) the next chunk, append it to cache and return from
263  that */
264 size_t ps_read_cached(Pcpstream *stream, void *buf, size_t readbytes);
265 
266 /* really read from the source */
267 size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes);
268 
269 /* helper, Z85 encodes current cache into the dst buffer */
270 void ps_write_encode(Pcpstream *stream, Buffer *dst);
271 
272 /* really write the buffer z into the output stream */
273 size_t ps_write_buf(Pcpstream *stream, Buffer *z);
274 
275 /* tell if we really reached eof, caching or not. 1=eof, 0=ok */
276 int ps_left(Pcpstream *stream);
277 
286 int ps_readline(Pcpstream *stream, Buffer *line);
287 
288 #endif // HAVE_PCP_PCPSTEAM_H
289 
290