aboutsummaryrefslogtreecommitdiff
path: root/src/microspdy
diff options
context:
space:
mode:
authorAndrey Uzunov <andrey.uzunov@gmail.com>2013-07-05 14:25:04 +0000
committerAndrey Uzunov <andrey.uzunov@gmail.com>2013-07-05 14:25:04 +0000
commit3b9e9c85b8dab59b73039c5bade324e07504da72 (patch)
treeab834d1842f6c1daf2eb0ae317dd8f7aed3f29b6 /src/microspdy
parentb8d6c063fe9e425e08652f74cb617514e6a8440d (diff)
downloadlibmicrohttpd-3b9e9c85b8dab59b73039c5bade324e07504da72.tar.gz
libmicrohttpd-3b9e9c85b8dab59b73039c5bade324e07504da72.zip
spdy: continue - previous one and rename tls to openssl
Diffstat (limited to 'src/microspdy')
-rw-r--r--src/microspdy/Makefile.am2
-rw-r--r--src/microspdy/applicationlayer.c6
-rw-r--r--src/microspdy/daemon.c6
-rw-r--r--src/microspdy/internal.h1
-rw-r--r--src/microspdy/io.h1
-rw-r--r--src/microspdy/io_openssl.c (renamed from src/microspdy/tls.c)34
-rw-r--r--src/microspdy/io_openssl.h (renamed from src/microspdy/tls.h)59
-rw-r--r--src/microspdy/session.c24
-rw-r--r--src/microspdy/structures.h1
9 files changed, 52 insertions, 82 deletions
diff --git a/src/microspdy/Makefile.am b/src/microspdy/Makefile.am
index 7d3c3d2b..11837717 100644
--- a/src/microspdy/Makefile.am
+++ b/src/microspdy/Makefile.am
@@ -16,7 +16,7 @@ lib_LTLIBRARIES = \
16 16
17libmicrospdy_la_SOURCES = \ 17libmicrospdy_la_SOURCES = \
18 io.h \ 18 io.h \
19 tls.h tls.c \ 19 io_openssl.h io_openssl.c \
20 structures.h structures.c \ 20 structures.h structures.c \
21 internal.h internal.c \ 21 internal.h internal.c \
22 daemon.h daemon.c \ 22 daemon.h daemon.c \
diff --git a/src/microspdy/applicationlayer.c b/src/microspdy/applicationlayer.c
index 8abeb57b..8bf9c67e 100644
--- a/src/microspdy/applicationlayer.c
+++ b/src/microspdy/applicationlayer.c
@@ -239,7 +239,7 @@ SPDY_init ()
239 "Buffer size is less than max supported frame size!"); 239 "Buffer size is less than max supported frame size!");
240 SPDYF_ASSERT(SPDY_MAX_SUPPORTED_FRAME_SIZE >= 32, 240 SPDYF_ASSERT(SPDY_MAX_SUPPORTED_FRAME_SIZE >= 32,
241 "Max supported frame size must be bigger than the minimal value!"); 241 "Max supported frame size must be bigger than the minimal value!");
242 SPDYF_tls_global_init(); 242 SPDYF_openssl_global_init();
243 return SPDY_YES; 243 return SPDY_YES;
244} 244}
245 245
@@ -248,8 +248,8 @@ void
248SPDY_deinit () 248SPDY_deinit ()
249{ 249{
250 //currently nothing to be freed/deinited 250 //currently nothing to be freed/deinited
251 //SPDYF_tls_global_deinit doesn't do anything now 251 //SPDYF_openssl_global_deinit doesn't do anything now
252 //SPDYF_tls_global_deinit(); 252 //SPDYF_openssl_global_deinit();
253} 253}
254 254
255 255
diff --git a/src/microspdy/daemon.c b/src/microspdy/daemon.c
index 4c59c2cc..ee7165ad 100644
--- a/src/microspdy/daemon.c
+++ b/src/microspdy/daemon.c
@@ -26,7 +26,7 @@
26#include "structures.h" 26#include "structures.h"
27#include "internal.h" 27#include "internal.h"
28#include "session.h" 28#include "session.h"
29#include "tls.h" 29#include "io.h"
30 30
31 31
32/** 32/**
@@ -191,8 +191,8 @@ SPDYF_start_daemon_va (uint16_t port,
191 memset (daemon, 0, sizeof (struct SPDY_Daemon)); 191 memset (daemon, 0, sizeof (struct SPDY_Daemon));
192 daemon->socket_fd = -1; 192 daemon->socket_fd = -1;
193 daemon->port = port; 193 daemon->port = port;
194 daemon->fio_init = &SPDYF_tls_init; 194 daemon->fio_init = &SPDYF_openssl_init;
195 daemon->fio_deinit = &SPDYF_tls_deinit; 195 daemon->fio_deinit = &SPDYF_openssl_deinit;
196 if (NULL == (daemon->certfile = strdup (certfile))) 196 if (NULL == (daemon->certfile = strdup (certfile)))
197 { 197 {
198 SPDYF_DEBUG("str"); 198 SPDYF_DEBUG("str");
diff --git a/src/microspdy/internal.h b/src/microspdy/internal.h
index becde9d5..7b07728c 100644
--- a/src/microspdy/internal.h
+++ b/src/microspdy/internal.h
@@ -27,7 +27,6 @@
27 27
28#include "platform.h" 28#include "platform.h"
29#include "microspdy.h" 29#include "microspdy.h"
30#include "tls.h"
31 30
32/* size of read buffers for each connection 31/* size of read buffers for each connection
33 * must be at least the size of SPDY_MAX_SUPPORTED_FRAME_SIZE */ 32 * must be at least the size of SPDY_MAX_SUPPORTED_FRAME_SIZE */
diff --git a/src/microspdy/io.h b/src/microspdy/io.h
index b1be69e6..19910d47 100644
--- a/src/microspdy/io.h
+++ b/src/microspdy/io.h
@@ -26,6 +26,7 @@
26#define IO_H 26#define IO_H
27 27
28#include "platform.h" 28#include "platform.h"
29#include "io_openssl.h"
29 30
30 31
31/** 32/**
diff --git a/src/microspdy/tls.c b/src/microspdy/io_openssl.c
index 57fd357d..c750fb72 100644
--- a/src/microspdy/tls.c
+++ b/src/microspdy/io_openssl.c
@@ -17,7 +17,7 @@
17*/ 17*/
18 18
19/** 19/**
20 * @file tls.c 20 * @file io_openssl.c
21 * @brief TLS handling using libssl. The current code assumes that 21 * @brief TLS handling using libssl. The current code assumes that
22 * blocking I/O is in use. 22 * blocking I/O is in use.
23 * @author Andrey Uzunov 23 * @author Andrey Uzunov
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "internal.h" 27#include "internal.h"
28#include "session.h" 28#include "session.h"
29#include "tls.h" 29#include "io_openssl.h"
30 30
31 31
32/** 32/**
@@ -53,7 +53,7 @@ spdyf_next_protos_advertised_cb (SSL *ssl, const unsigned char **out, unsigned i
53 53
54 54
55void 55void
56SPDYF_tls_global_init() 56SPDYF_openssl_global_init()
57{ 57{
58 //error strings are now not used by the lib 58 //error strings are now not used by the lib
59 //SSL_load_error_strings(); 59 //SSL_load_error_strings();
@@ -65,7 +65,7 @@ SPDYF_tls_global_init()
65 65
66 66
67void 67void
68SPDYF_tls_global_deinit() 68SPDYF_openssl_global_deinit()
69{ 69{
70 //if SSL_load_error_strings was called 70 //if SSL_load_error_strings was called
71 //ERR_free_strings(); 71 //ERR_free_strings();
@@ -75,7 +75,7 @@ SPDYF_tls_global_deinit()
75 75
76 76
77int 77int
78SPDYF_tls_init(struct SPDY_Daemon *daemon) 78SPDYF_openssl_init(struct SPDY_Daemon *daemon)
79{ 79{
80 //create ssl context. TLSv1 used 80 //create ssl context. TLSv1 used
81 if(NULL == (daemon->io_context = SSL_CTX_new(TLSv1_server_method()))) 81 if(NULL == (daemon->io_context = SSL_CTX_new(TLSv1_server_method())))
@@ -117,14 +117,14 @@ SPDYF_tls_init(struct SPDY_Daemon *daemon)
117 117
118 118
119void 119void
120SPDYF_tls_deinit(struct SPDY_Daemon *daemon) 120SPDYF_openssl_deinit(struct SPDY_Daemon *daemon)
121{ 121{
122 SSL_CTX_free(daemon->io_context); 122 SSL_CTX_free(daemon->io_context);
123} 123}
124 124
125 125
126int 126int
127SPDYF_tls_new_session(struct SPDY_Session *session) 127SPDYF_openssl_new_session(struct SPDY_Session *session)
128{ 128{
129 int ret; 129 int ret;
130 130
@@ -160,7 +160,7 @@ SPDYF_tls_new_session(struct SPDY_Session *session)
160 160
161 161
162void 162void
163SPDYF_tls_close_session(struct SPDY_Session *session) 163SPDYF_openssl_close_session(struct SPDY_Session *session)
164{ 164{
165 //SSL_shutdown sends TLS "close notify" as in TLS standard. 165 //SSL_shutdown sends TLS "close notify" as in TLS standard.
166 //The function may fail as it waits for the other party to also close 166 //The function may fail as it waits for the other party to also close
@@ -174,7 +174,7 @@ SPDYF_tls_close_session(struct SPDY_Session *session)
174 174
175 175
176int 176int
177SPDYF_tls_recv(struct SPDY_Session *session, 177SPDYF_openssl_recv(struct SPDY_Session *session,
178 void * buffer, 178 void * buffer,
179 size_t size) 179 size_t size)
180{ 180{
@@ -193,14 +193,14 @@ SPDYF_tls_recv(struct SPDY_Session *session,
193 193
194 case SSL_ERROR_WANT_READ: 194 case SSL_ERROR_WANT_READ:
195 case SSL_ERROR_WANT_WRITE: 195 case SSL_ERROR_WANT_WRITE:
196 return SPDY_TLS_ERROR_AGAIN; 196 return SPDY_IO_ERROR_AGAIN;
197 197
198 case SSL_ERROR_SYSCALL: 198 case SSL_ERROR_SYSCALL:
199 if(EINTR == errno) 199 if(EINTR == errno)
200 return SPDY_TLS_ERROR_AGAIN; 200 return SPDY_IO_ERROR_AGAIN;
201 201
202 default: 202 default:
203 return SPDY_TLS_ERROR_ERROR; 203 return SPDY_IO_ERROR_ERROR;
204 } 204 }
205 } 205 }
206 206
@@ -209,7 +209,7 @@ SPDYF_tls_recv(struct SPDY_Session *session,
209 209
210 210
211int 211int
212SPDYF_tls_send(struct SPDY_Session *session, 212SPDYF_openssl_send(struct SPDY_Session *session,
213 const void * buffer, 213 const void * buffer,
214 size_t size) 214 size_t size)
215{ 215{
@@ -229,14 +229,14 @@ SPDYF_tls_send(struct SPDY_Session *session,
229 229
230 case SSL_ERROR_WANT_READ: 230 case SSL_ERROR_WANT_READ:
231 case SSL_ERROR_WANT_WRITE: 231 case SSL_ERROR_WANT_WRITE:
232 return SPDY_TLS_ERROR_AGAIN; 232 return SPDY_IO_ERROR_AGAIN;
233 233
234 case SSL_ERROR_SYSCALL: 234 case SSL_ERROR_SYSCALL:
235 if(EINTR == errno) 235 if(EINTR == errno)
236 return SPDY_TLS_ERROR_AGAIN; 236 return SPDY_IO_ERROR_AGAIN;
237 237
238 default: 238 default:
239 return SPDY_TLS_ERROR_ERROR; 239 return SPDY_IO_ERROR_ERROR;
240 } 240 }
241 } 241 }
242 242
@@ -245,7 +245,7 @@ SPDYF_tls_send(struct SPDY_Session *session,
245 245
246 246
247int 247int
248SPDYF_tls_is_pending(struct SPDY_Session *session) 248SPDYF_openssl_is_pending(struct SPDY_Session *session)
249{ 249{
250 /* From openssl docs: 250 /* From openssl docs:
251 * BUGS 251 * BUGS
diff --git a/src/microspdy/tls.h b/src/microspdy/io_openssl.h
index 932d93b9..a4829736 100644
--- a/src/microspdy/tls.h
+++ b/src/microspdy/io_openssl.h
@@ -17,58 +17,29 @@
17*/ 17*/
18 18
19/** 19/**
20 * @file tls.h 20 * @file io_openssl.h
21 * @brief TLS handling. openssl with NPN is used, but as long as the 21 * @brief TLS handling. openssl with NPN is used, but as long as the
22 * functions conform to this interface file, other libraries 22 * functions conform to this interface file, other libraries
23 * can be used. 23 * can be used.
24 * @author Andrey Uzunov 24 * @author Andrey Uzunov
25 */ 25 */
26 26
27#ifndef TLS_H 27#ifndef IO_OPENSSL_H
28#define TLS_H 28#define IO_OPENSSL_H
29 29
30#include "platform.h" 30#include "platform.h"
31#include "io.h"
31#include <openssl/err.h> 32#include <openssl/err.h>
32#include <openssl/ssl.h> 33#include <openssl/ssl.h>
33#include <openssl/rand.h> 34#include <openssl/rand.h>
34 35
35/* macros used in other files instead of types.
36 * useful in case of changing openssl to something else */
37//#define SPDYF_TLS_SESSION_CONTEXT SSL
38//#define SPDYF_TLS_DAEMON_CONTEXT SSL_CTX
39
40
41/**
42 * Used for return code when reading and writing to the TLS socket.
43 */
44enum SPDY_TLS_ERROR
45{
46 /**
47 * The connection was closed by the other party.
48 */
49 SPDY_TLS_ERROR_CLOSED = 0,
50
51 /**
52 * Any kind of error ocurred. The session has to be closed.
53 */
54 SPDY_TLS_ERROR_ERROR = -2,
55
56 /**
57 * The function had to return without processing any data. The whole
58 * cycle of events has to be called again (SPDY_run) as something
59 * either has to be written or read or the the syscall was
60 * interrupted by a signal.
61 */
62 SPDY_TLS_ERROR_AGAIN = -3,
63};
64
65 36
66/** 37/**
67 * Global initializing of openssl. Must be called only once in the program. 38 * Global initializing of openssl. Must be called only once in the program.
68 * 39 *
69 */ 40 */
70void 41void
71SPDYF_tls_global_init(); 42SPDYF_openssl_global_init();
72 43
73 44
74/** 45/**
@@ -77,7 +48,7 @@ SPDYF_tls_global_init();
77 * 48 *
78 */ 49 */
79void 50void
80SPDYF_tls_global_deinit(); 51SPDYF_openssl_global_deinit();
81 52
82 53
83/** 54/**
@@ -89,7 +60,7 @@ SPDYF_tls_global_deinit();
89 * @return SPDY_YES on success or SPDY_NO on error 60 * @return SPDY_YES on success or SPDY_NO on error
90 */ 61 */
91int 62int
92SPDYF_tls_init(struct SPDY_Daemon *daemon); 63SPDYF_openssl_init(struct SPDY_Daemon *daemon);
93 64
94 65
95/** 66/**
@@ -99,7 +70,7 @@ SPDYF_tls_init(struct SPDY_Daemon *daemon);
99 * @param daemon SPDY_Daemon which is being stopped 70 * @param daemon SPDY_Daemon which is being stopped
100 */ 71 */
101void 72void
102SPDYF_tls_deinit(struct SPDY_Daemon *daemon); 73SPDYF_openssl_deinit(struct SPDY_Daemon *daemon);
103 74
104 75
105/** 76/**
@@ -110,7 +81,7 @@ SPDYF_tls_deinit(struct SPDY_Daemon *daemon);
110 * @return SPDY_NO if some openssl funcs fail. SPDY_YES otherwise 81 * @return SPDY_NO if some openssl funcs fail. SPDY_YES otherwise
111 */ 82 */
112int 83int
113SPDYF_tls_new_session(struct SPDY_Session *session); 84SPDYF_openssl_new_session(struct SPDY_Session *session);
114 85
115 86
116/** 87/**
@@ -120,7 +91,7 @@ SPDYF_tls_new_session(struct SPDY_Session *session);
120 * @param session SPDY_Session whose socket is used by openssl 91 * @param session SPDY_Session whose socket is used by openssl
121 */ 92 */
122void 93void
123SPDYF_tls_close_session(struct SPDY_Session *session); 94SPDYF_openssl_close_session(struct SPDY_Session *session);
124 95
125 96
126/** 97/**
@@ -132,10 +103,10 @@ SPDYF_tls_close_session(struct SPDY_Session *session);
132 * @param size of the buffer 103 * @param size of the buffer
133 * @return number of bytes (at most size) read from the TLS connection 104 * @return number of bytes (at most size) read from the TLS connection
134 * 0 if the other party has closed the connection 105 * 0 if the other party has closed the connection
135 * SPDY_TLS_ERROR code on error 106 * SPDY_IO_ERROR code on error
136 */ 107 */
137int 108int
138SPDYF_tls_recv(struct SPDY_Session *session, 109SPDYF_openssl_recv(struct SPDY_Session *session,
139 void * buffer, 110 void * buffer,
140 size_t size); 111 size_t size);
141 112
@@ -150,10 +121,10 @@ SPDYF_tls_recv(struct SPDY_Session *session,
150 * @return number of bytes (at most size) from the buffer that has been 121 * @return number of bytes (at most size) from the buffer that has been
151 * written to the TLS connection 122 * written to the TLS connection
152 * 0 if the other party has closed the connection 123 * 0 if the other party has closed the connection
153 * SPDY_TLS_ERROR code on error 124 * SPDY_IO_ERROR code on error
154 */ 125 */
155int 126int
156SPDYF_tls_send(struct SPDY_Session *session, 127SPDYF_openssl_send(struct SPDY_Session *session,
157 const void * buffer, 128 const void * buffer,
158 size_t size); 129 size_t size);
159 130
@@ -166,6 +137,6 @@ SPDYF_tls_send(struct SPDY_Session *session,
166 * @return SPDY_YES if data is pending or SPDY_NO otherwise 137 * @return SPDY_YES if data is pending or SPDY_NO otherwise
167 */ 138 */
168int 139int
169SPDYF_tls_is_pending(struct SPDY_Session *session); 140SPDYF_openssl_is_pending(struct SPDY_Session *session);
170 141
171#endif 142#endif
diff --git a/src/microspdy/session.c b/src/microspdy/session.c
index 5bd68d19..4056e20e 100644
--- a/src/microspdy/session.c
+++ b/src/microspdy/session.c
@@ -28,8 +28,8 @@
28#include "internal.h" 28#include "internal.h"
29#include "session.h" 29#include "session.h"
30#include "compression.h" 30#include "compression.h"
31#include "tls.h"
32#include "stream.h" 31#include "stream.h"
32#include "io.h"
33 33
34 34
35/** 35/**
@@ -826,7 +826,7 @@ SPDYF_session_read (struct SPDY_Session *session)
826 826
827 switch(bytes_read) 827 switch(bytes_read)
828 { 828 {
829 case SPDY_TLS_ERROR_CLOSED: 829 case SPDY_IO_ERROR_CLOSED:
830 //The TLS connection was closed by the other party, clean 830 //The TLS connection was closed by the other party, clean
831 //or not 831 //or not
832 shutdown (session->socket_fd, SHUT_RD); 832 shutdown (session->socket_fd, SHUT_RD);
@@ -834,7 +834,7 @@ SPDYF_session_read (struct SPDY_Session *session)
834 session->status = SPDY_SESSION_STATUS_CLOSING; 834 session->status = SPDY_SESSION_STATUS_CLOSING;
835 return SPDY_YES; 835 return SPDY_YES;
836 836
837 case SPDY_TLS_ERROR_ERROR: 837 case SPDY_IO_ERROR_ERROR:
838 //any kind of error in the TLS subsystem 838 //any kind of error in the TLS subsystem
839 //try to prepare GOAWAY frame 839 //try to prepare GOAWAY frame
840 SPDYF_prepare_goaway(session, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, false); 840 SPDYF_prepare_goaway(session, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, false);
@@ -842,7 +842,7 @@ SPDYF_session_read (struct SPDY_Session *session)
842 session->status = SPDY_SESSION_STATUS_FLUSHING; 842 session->status = SPDY_SESSION_STATUS_FLUSHING;
843 return SPDY_YES; 843 return SPDY_YES;
844 844
845 case SPDY_TLS_ERROR_AGAIN: 845 case SPDY_IO_ERROR_AGAIN:
846 //read or write should be called again; leave it for the 846 //read or write should be called again; leave it for the
847 //next time 847 //next time
848 return SPDY_NO; 848 return SPDY_NO;
@@ -958,7 +958,7 @@ SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
958 958
959 switch(bytes_written) 959 switch(bytes_written)
960 { 960 {
961 case SPDY_TLS_ERROR_CLOSED: 961 case SPDY_IO_ERROR_CLOSED:
962 //The TLS connection was closed by the other party, clean 962 //The TLS connection was closed by the other party, clean
963 //or not 963 //or not
964 shutdown (session->socket_fd, SHUT_RD); 964 shutdown (session->socket_fd, SHUT_RD);
@@ -966,13 +966,13 @@ SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
966 session->status = SPDY_SESSION_STATUS_CLOSING; 966 session->status = SPDY_SESSION_STATUS_CLOSING;
967 return SPDY_YES; 967 return SPDY_YES;
968 968
969 case SPDY_TLS_ERROR_ERROR: 969 case SPDY_IO_ERROR_ERROR:
970 //any kind of error in the TLS subsystem 970 //any kind of error in the TLS subsystem
971 //forbid more writing 971 //forbid more writing
972 session->status = SPDY_SESSION_STATUS_CLOSING; 972 session->status = SPDY_SESSION_STATUS_CLOSING;
973 return SPDY_YES; 973 return SPDY_YES;
974 974
975 case SPDY_TLS_ERROR_AGAIN: 975 case SPDY_IO_ERROR_AGAIN:
976 //read or write should be called again; leave it for the 976 //read or write should be called again; leave it for the
977 //next time; return from the function as we do not now 977 //next time; return from the function as we do not now
978 //whether reading or writing is needed 978 //whether reading or writing is needed
@@ -1306,11 +1306,11 @@ SPDYF_session_accept(struct SPDY_Daemon *daemon)
1306 session->daemon = daemon; 1306 session->daemon = daemon;
1307 session->socket_fd = new_socket_fd; 1307 session->socket_fd = new_socket_fd;
1308 1308
1309 session->fio_new_session = &SPDYF_tls_new_session; 1309 session->fio_new_session = &SPDYF_openssl_new_session;
1310 session->fio_close_session = &SPDYF_tls_close_session; 1310 session->fio_close_session = &SPDYF_openssl_close_session;
1311 session->fio_is_pending = &SPDYF_tls_is_pending; 1311 session->fio_is_pending = &SPDYF_openssl_is_pending;
1312 session->fio_recv = &SPDYF_tls_recv; 1312 session->fio_recv = &SPDYF_openssl_recv;
1313 session->fio_send = &SPDYF_tls_send; 1313 session->fio_send = &SPDYF_openssl_send;
1314 1314
1315 //init TLS context, handshake will be done 1315 //init TLS context, handshake will be done
1316 if(SPDY_YES != session->fio_new_session(session)) 1316 if(SPDY_YES != session->fio_new_session(session))
diff --git a/src/microspdy/structures.h b/src/microspdy/structures.h
index 529bc929..a53e12a9 100644
--- a/src/microspdy/structures.h
+++ b/src/microspdy/structures.h
@@ -28,7 +28,6 @@
28 28
29#include "platform.h" 29#include "platform.h"
30#include "microspdy.h" 30#include "microspdy.h"
31#include "tls.h"
32#include "io.h" 31#include "io.h"
33 32
34 33