]> sjero.net Git - wget/blob - src/rbuf.h
[svn] Update copyright notices.
[wget] / src / rbuf.h
1 /* Declarations for rbuf.c.
2    Copyright (C) 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU Wget.
5
6 GNU Wget 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 2 of the License, or
9 (at your option) any later version.
10
11 GNU Wget 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 Wget; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #ifndef RBUF_H
21 #define RBUF_H
22
23 #ifdef HAVE_SSL
24 # include <openssl/ssl.h>
25 #endif
26
27 /* Retrieval stream */
28 struct rbuf
29 {
30   int fd;
31 #ifdef HAVE_SSL
32   SSL *ssl;             /* the ssl structure -- replaces fd for ssl connections */
33 #endif /* HAVE_SSL */
34   char buffer[4096];            /* the input buffer */
35   char *buffer_pos;             /* current position in the buffer */
36   size_t buffer_left;           /* number of bytes left in the buffer:
37                                    buffer_left = buffer_end - buffer_pos */
38   int internal_dont_touch_this; /* used by RBUF_READCHAR macro */
39 };
40
41 /* Read a character from RBUF.  If there is anything in the buffer,
42    the character is returned from the buffer.  Otherwise, refill the
43    buffer and return the first character.
44
45    The return value is the same as with read(2).  On buffered read,
46    the function returns 1.
47
48    #### That return value is totally screwed up, and is a direct
49    result of historical implementation of header code.  The macro
50    should return the character or EOF, and in case of error store it
51    to rbuf->err or something.  */
52
53 #define RBUF_READCHAR(rbuf, store)                                      \
54 ((rbuf)->buffer_left                                                    \
55  ? (--(rbuf)->buffer_left,                                              \
56     *((char *) (store)) = *(rbuf)->buffer_pos++, 1)                     \
57  : ((rbuf)->buffer_pos = (rbuf)->buffer,                                \
58     ((((rbuf)->internal_dont_touch_this                                 \
59        = rbuf_read_bufferful (rbuf)) <= 0)                              \
60      ? (rbuf)->internal_dont_touch_this                                 \
61      : ((rbuf)->buffer_left = (rbuf)->internal_dont_touch_this - 1,     \
62         *((char *) (store)) = *(rbuf)->buffer_pos++,                    \
63         1))))
64
65 /* Return the file descriptor of RBUF.  */
66 #define RBUF_FD(rbuf) ((rbuf)->fd)
67
68 /* Return the file descriptor of RBUF.  */
69 #define RBUF_SSL(rbuf) ((rbuf)->ssl)
70
71 /* Function declarations */
72 void rbuf_initialize PARAMS ((struct rbuf *, int));
73 int rbuf_initialized_p PARAMS ((struct rbuf *));
74 void rbuf_uninitialize PARAMS ((struct rbuf *));
75 int rbuf_readchar PARAMS ((struct rbuf *, char *));
76 int rbuf_peek PARAMS ((struct rbuf *, char *));
77 int rbuf_flush PARAMS ((struct rbuf *, char *, int));
78 void rbuf_discard PARAMS ((struct rbuf *));
79
80 /* Internal, but used by the macro. */
81 int rbuf_read_bufferful PARAMS ((struct rbuf *));
82
83 #endif /* RBUF_H */