src/server/util/io.h

Mon, 16 Jan 2017 14:41:20 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 16 Jan 2017 14:41:20 +0100
changeset 149
aa016efb9ad7
parent 147
d050449c3b9e
child 161
aadda87bad1b
child 172
5580517faafc
permissions
-rw-r--r--

fixes cgi cleanup

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>
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
33 #include "../public/nsapi.h"
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
34 #include "systems.h"
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
35
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
36 #ifdef _WIN32
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
37 #include <windows.h>
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
38 #include <winsock2.h>
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
39 #endif
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
40
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #ifdef __cplusplus
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 extern "C" {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #endif
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
147
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
45 #ifdef XP_UNIX
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
46 #define SYS_SOCKET int
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
47 #elif defined(XP_WIN32)
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
48 #define SYS_SOCKET SOCKET
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
49 #endif
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
50
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
51 typedef struct IOStream IOStream;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
52 typedef struct SysStream SysStream;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
53 typedef struct HttpStream HttpStream;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 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
56 typedef ssize_t(*io_writev_f)(IOStream *, struct iovec *, int);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 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
58 typedef ssize_t(*io_sendfile_f)(IOStream *, sendfiledata *);
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
59 typedef void(*io_close_f)(IOStream *);
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
60 typedef void(*io_finish_f)(IOStream *);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
62 struct IOStream {
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
63 io_write_f write;
64
c7f5b062e622 added net_writev
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
64 io_writev_f writev;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
65 io_read_f read;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
66 io_sendfile_f sendfile;
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
67 io_close_f close;
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
68 io_finish_f finish;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 };
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
71 struct SysStream {
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
72 IOStream st;
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
73 #ifdef XP_UNIX
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
74 int fd;
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
75 #elif defined(XP_WIN32)
147
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
76 SOCKET fd;
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
77 #endif
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
78 };
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
79
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
80 struct HttpStream {
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
81 IOStream st;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
82 IOStream *fd;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
83 uint64_t max_read;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
84 uint64_t read;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
85 WSBool chunked_enc;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
86 WSBool buffered;
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
87 };
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
88
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
89 typedef struct SSLStream {
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
90 IOStream st;
133
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 112
diff changeset
91 SSL *ssl;
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 112
diff changeset
92 int error;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
93 } SSLStream;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
94
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
95
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
96
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 /* system stream */
147
d050449c3b9e ported io.c and some headers to windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
98 IOStream* sysstream_new(pool_handle_t *pool, SYS_SOCKET fd);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
100 ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
101 ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
102 ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
103 ssize_t net_sys_sendfile(SysStream *st, sendfiledata *sfd);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
104 void net_sys_close(SysStream *st);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
106 /* http stream */
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
107 IOStream* httpstream_new(pool_handle_t *pool, IOStream *fd);
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
108
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
109 ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
110 ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
111 ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
112 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
113 void net_http_close(HttpStream *st);
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
114 void net_http_finish(HttpStream *st);
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
115
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
116 /* ssl stream */
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
117 IOStream* sslstream_new(pool_handle_t *pool, SSL *ssl);
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
118
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
119 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
120 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
121 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
122 void net_ssl_close(SSLStream *st);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
123 void net_ssl_finish(SSLStream *st);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
124
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
125 /* net_ functions */
112
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110 111
diff changeset
126 ssize_t net_fallback_sendfile(IOStream *fd, sendfiledata *sfd);
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
127 void net_finish(SYS_NETFD fd);
32
ebba53de8b18 added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
128
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 #ifdef __cplusplus
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 #endif
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 #endif /* IOSTREAM_H */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134

mercurial