src/server/util/io.h

Sat, 31 Oct 2015 18:02:07 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 31 Oct 2015 18:02:07 +0100
changeset 108
2a394ccdd778
parent 106
b122f34ddc80
child 110
43a746e905f6
child 111
c93be34fde76
permissions
-rw-r--r--

fixed ssl

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #ifndef IOSTREAM_H
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define IOSTREAM_H
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
32 #include <openssl/ssl.h>
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
33
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
34 #include "../public/nsapi.h"
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
35
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #ifdef __cplusplus
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 extern "C" {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #endif
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 typedef struct io_stream IOStream;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 typedef ssize_t(*io_write_f)(IOStream *, void *, size_t);
64
c7f5b062e622 added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
43 typedef ssize_t(*io_writev_f)(IOStream *, struct iovec *, int);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 typedef ssize_t(*io_read_f)(IOStream *, void *, size_t);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
45 typedef ssize_t(*io_sendfile_f)(IOStream *, sendfiledata *);
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
46 typedef void(*io_close_f)(IOStream *);
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
47 typedef void(*io_finish_f)(IOStream *);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 struct io_stream {
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
50 io_write_f write;
64
c7f5b062e622 added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
51 io_writev_f writev;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
52 io_read_f read;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
53 io_sendfile_f sendfile;
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
54 io_close_f close;
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
55 io_finish_f finish;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 };
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 typedef struct SystemIOStream {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 IOStream st;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 int fd;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 } SystemIOStream;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
63 typedef struct NetIOStream {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
64 IOStream st;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
65 int fd;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
66 size_t max_read;
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
67 size_t read;
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
68 int chunked_enc;
65
14722c5f8856 added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
69 int buffered;
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
70 } NetIOStream;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
71
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
72 typedef struct SSLStream {
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
73 IOStream st;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
74 SSL *ssl;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
75 } SSLStream;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
76
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
77
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
78 /* net_ functions */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
79 ssize_t net_read(SYS_NETFD fd, void *buf, size_t nbytes);
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
80 ssize_t net_write(SYS_NETFD fd, void *buf, size_t nbytes);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
81 ssize_t net_printf(SYS_NETFD fd, char *format, ...);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
82 ssize_t net_sendfile(SYS_NETFD fd, sendfiledata *sfd);
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
83 void net_close(SYS_NETFD fd);
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
84 void net_finish(SYS_NETFD fd);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
86 /* iovec buffer */
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
87 typedef struct iovec_buf{
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
88 struct iovec *iov;
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
89 int iovctn;
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
90 int maxiovec;
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
91 pool_handle_t *pool;
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
92 } iovec_buf_t;
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
93
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
94
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
95 /* system stream */
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
96 IOStream* stream_new_from_fd(pool_handle_t *pool, int fd);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 ssize_t system_write(IOStream *st, void *buf, size_t nbytes);
64
c7f5b062e622 added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
99 ssize_t system_writev(IOStream *st, struct iovec *iovec, int iovcnt);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 ssize_t system_read(IOStream *st, void *buf, size_t nbytes);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
102 /* net stream */
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
103 IOStream* net_stream_from_fd(pool_handle_t *pool, int fd);
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
104
65
14722c5f8856 added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
105 ssize_t net_stream_write(NetIOStream *st, void *buf, size_t nbytes);
14722c5f8856 added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
106 ssize_t net_stream_writev(NetIOStream *st, struct iovec *iovec, int iovcnt);
14722c5f8856 added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
107 ssize_t net_stream_read(NetIOStream *st, void *buf, size_t nbytes);
14722c5f8856 added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
108 ssize_t net_stream_sendfile(NetIOStream *st, sendfiledata *sfd);
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
109 void net_stream_close(NetIOStream *st);
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
110 void net_stream_finish(NetIOStream *st);
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
111
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
112 /* ssl stream */
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
113 IOStream* net_ssl_stream(pool_handle_t *pool, SSL *ssl);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
114
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
115 ssize_t net_ssl_write(SSLStream *st, void *buf, size_t nbytes);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
116 ssize_t net_ssl_writev(SSLStream *st, struct iovec *iovec, int iovcnt);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
117 ssize_t net_ssl_read(SSLStream *st, void *buf, size_t nbytes);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
118 void net_ssl_close(SSLStream *st);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
119 void net_ssl_finish(SSLStream *st);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
120
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
121 /* iovec buffer */
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
122 iovec_buf_t *iovec_buf_create(pool_handle_t *pool);
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
123 void iovec_buf_write(iovec_buf_t *io, void *buf, size_t nbyte);
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
124 ssize_t iovec_buf_flush(iovec_buf_t *io, int fd);
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
125
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
126
32
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
127
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
128 #ifdef __SunOS_5_10
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
129
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
130 int vasprintf(char **str, const char *format, va_list ap);
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
131 int asprintf(char **str, const char *format, ...);
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
132
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
133 #endif
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
134
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 #ifdef __cplusplus
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 #endif
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 #endif /* IOSTREAM_H */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140

mercurial