aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Uzunov <andrey.uzunov@gmail.com>2013-08-11 19:35:43 +0000
committerAndrey Uzunov <andrey.uzunov@gmail.com>2013-08-11 19:35:43 +0000
commite421dc4c64105540b24ee732e8887ee26c40276a (patch)
tree6d6674c83330ecaf6ff2fd94edcde343971ba3c2
parent62f53d643f796ad3a32d8eabfdceb985245ec15f (diff)
downloadlibmicrohttpd-e421dc4c64105540b24ee732e8887ee26c40276a.tar.gz
libmicrohttpd-e421dc4c64105540b24ee732e8887ee26c40276a.zip
spdy: simple POST support implemented; API changes; fixed warnings in spdy tests
-rw-r--r--src/examples/mhd2spdy.c2
-rw-r--r--src/examples/mhd2spdy_http.c60
-rw-r--r--src/examples/mhd2spdy_spdy.c112
-rw-r--r--src/examples/mhd2spdy_spdy.h3
-rw-r--r--src/examples/mhd2spdy_structures.c20
-rw-r--r--src/examples/mhd2spdy_structures.h7
-rw-r--r--src/examples/spdy_event_loop.c21
-rw-r--r--src/examples/spdy_fileserver.c16
-rw-r--r--src/examples/spdy_response_with_callback.c9
-rw-r--r--src/include/microspdy.h26
-rw-r--r--src/microspdy/applicationlayer.c25
-rw-r--r--src/microspdy/daemon.c6
-rw-r--r--src/microspdy/daemon.h3
-rw-r--r--src/microspdy/session.c45
-rw-r--r--src/microspdy/stream.c19
-rw-r--r--src/microspdy/stream.h13
-rw-r--r--src/microspdy/structures.h36
-rw-r--r--src/spdy2http/proxy.c245
-rw-r--r--src/testspdy/test_daemon_start_stop.c2
-rw-r--r--src/testspdy/test_daemon_start_stop_many.c2
-rw-r--r--src/testspdy/test_misc.c25
-rw-r--r--src/testspdy/test_new_connection.c30
-rw-r--r--src/testspdy/test_notls.c36
-rw-r--r--src/testspdy/test_request_response.c43
-rw-r--r--src/testspdy/test_request_response_with_callback.c27
-rw-r--r--src/testspdy/test_requests_with_assets.c17
-rw-r--r--src/testspdy/test_session_timeout.c32
-rw-r--r--src/testspdy/test_struct_namevalue.c11
28 files changed, 790 insertions, 103 deletions
diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c
index 0426a276..a642d936 100644
--- a/src/examples/mhd2spdy.c
+++ b/src/examples/mhd2spdy.c
@@ -151,7 +151,7 @@ run_everything ()
151 glob_opt.spdy_data_received = false; 151 glob_opt.spdy_data_received = false;
152 152
153 ret = select(maxfd+1, &rs, &ws, &es, &timeout); 153 ret = select(maxfd+1, &rs, &ws, &es, &timeout);
154 PRINT_INFO2("timeout now %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); 154 PRINT_INFO2("timeout now %lld %lld ret is %i", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec, ret);
155 155
156 switch(ret) 156 switch(ret)
157 { 157 {
diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c
index 7881d57a..1f7dec97 100644
--- a/src/examples/mhd2spdy_http.c
+++ b/src/examples/mhd2spdy_http.c
@@ -36,6 +36,7 @@ const char * uri)
36 36
37 PRINT_INFO2("log uri '%s'\n", uri); 37 PRINT_INFO2("log uri '%s'\n", uri);
38 38
39 //TODO not freed once in a while
39 if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) 40 if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI ))))
40 DIE("no memory"); 41 DIE("no memory");
41 http_uri->uri = strdup(uri); 42 http_uri->uri = strdup(uri);
@@ -176,6 +177,7 @@ http_cb_request (void *cls,
176 int ret; 177 int ret;
177 struct Proxy *proxy; 178 struct Proxy *proxy;
178 struct SPDY_Headers spdy_headers; 179 struct SPDY_Headers spdy_headers;
180 bool with_body = false;
179 181
180 //PRINT_INFO2("request cb %i; %s", *ptr,url); 182 //PRINT_INFO2("request cb %i; %s", *ptr,url);
181 183
@@ -185,14 +187,14 @@ http_cb_request (void *cls,
185 187
186 if(NULL == http_uri->proxy) 188 if(NULL == http_uri->proxy)
187 { 189 {
188 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 190 if (0 != strcmp (method, MHD_HTTP_METHOD_GET) && 0 != strcmp (method, MHD_HTTP_METHOD_POST))
189 { 191 {
190 free(http_uri->uri); 192 free(http_uri->uri);
191 free(http_uri); 193 free(http_uri);
192 PRINT_INFO2("unexpected method %s", method); 194 PRINT_INFO2("unexpected method %s", method);
193 return MHD_NO; 195 return MHD_NO;
194 } 196 }
195 197
196 if(NULL == (proxy = au_malloc(sizeof(struct Proxy)))) 198 if(NULL == (proxy = au_malloc(sizeof(struct Proxy))))
197 { 199 {
198 PRINT_INFO("No memory"); 200 PRINT_INFO("No memory");
@@ -211,14 +213,62 @@ http_cb_request (void *cls,
211 213
212 if(proxy->spdy_active) 214 if(proxy->spdy_active)
213 { 215 {
216 if(0 == strcmp (method, MHD_HTTP_METHOD_POST))
217 {
218 PRINT_INFO("POST processing");
219
220 int rc= spdylay_session_resume_data(proxy->spdy_connection->session, proxy->stream_id);
221 PRINT_INFO2("rc is %i stream is %i", rc, proxy->stream_id);
222 proxy->spdy_connection->want_io |= WANT_WRITE;
223
224 if(0 == *upload_data_size)
225 {
226 PRINT_INFO("POST http EOF");
227 proxy->receiving_done = true;
228 return MHD_YES;
229 }
230
231 if(!copy_buffer(upload_data, *upload_data_size, &proxy->received_body, &proxy->received_body_size))
232 {
233 //TODO handle it better?
234 PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
235 return MHD_NO;
236 }
237 /*
238 if(NULL == proxy->received_body)
239 proxy->received_body = malloc(*upload_data_size);
240 else
241 proxy->received_body = realloc(proxy->received_body, proxy->received_body_size + *upload_data_size);
242 if(NULL == proxy->received_body)
243 {
244 //TODO handle it better?
245 PRINT_INFO("not enough memory (realloc returned NULL)");
246 return MHD_NO;
247 }
248
249 memcpy(proxy->received_body + proxy->received_body_size, upload_data, *upload_data_size);
250 proxy->received_body_size += *upload_data_size;
251 */
252 *upload_data_size = 0;
253
254 //raise(SIGINT);
255
256 return MHD_YES;
257 }
258
214 //already handled 259 //already handled
215 PRINT_INFO("unnecessary call to http_cb_request"); 260 PRINT_INFO("unnecessary call to http_cb_request");
216 return MHD_YES; 261 return MHD_YES;
217 } 262 }
218 263
219 PRINT_INFO2("received request for '%s %s %s'\n", method, http_uri->uri, version); 264 PRINT_INFO2("received request for '%s %s %s'", method, http_uri->uri, version);
220 265
221 proxy->url = http_uri->uri; 266 proxy->url = http_uri->uri;
267
268 with_body = 0 == strcmp (method, MHD_HTTP_METHOD_POST) && 0 != strcmp ("0",
269 MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH));
270
271 PRINT_INFO2("body will be sent %i", with_body);
222 272
223 ret = parse_uri(&glob_opt.uri_preg, proxy->url, &proxy->uri); 273 ret = parse_uri(&glob_opt.uri_preg, proxy->url, &proxy->uri);
224 if(ret != 0) 274 if(ret != 0)
@@ -232,7 +282,7 @@ http_cb_request (void *cls,
232 NULL); 282 NULL);
233 if(NULL == (spdy_headers.nv = au_malloc(((spdy_headers.num + 5) * 2 + 1) * sizeof(char *)))) 283 if(NULL == (spdy_headers.nv = au_malloc(((spdy_headers.num + 5) * 2 + 1) * sizeof(char *))))
234 DIE("no memory"); 284 DIE("no memory");
235 spdy_headers.nv[0] = ":method"; spdy_headers.nv[1] = "GET"; 285 spdy_headers.nv[0] = ":method"; spdy_headers.nv[1] = method;
236 spdy_headers.nv[2] = ":path"; spdy_headers.nv[3] = proxy->uri->path_and_more; 286 spdy_headers.nv[2] = ":path"; spdy_headers.nv[3] = proxy->uri->path_and_more;
237 spdy_headers.nv[4] = ":version"; spdy_headers.nv[5] = (char *)version; 287 spdy_headers.nv[4] = ":version"; spdy_headers.nv[5] = (char *)version;
238 spdy_headers.nv[6] = ":scheme"; spdy_headers.nv[7] = proxy->uri->scheme; 288 spdy_headers.nv[6] = ":scheme"; spdy_headers.nv[7] = proxy->uri->scheme;
@@ -248,7 +298,7 @@ http_cb_request (void *cls,
248 if(NULL == spdy_headers.nv[9]) 298 if(NULL == spdy_headers.nv[9])
249 spdy_headers.nv[9] = proxy->uri->host_and_port; 299 spdy_headers.nv[9] = proxy->uri->host_and_port;
250 300
251 if(0 != spdy_request(spdy_headers.nv, proxy)) 301 if(0 != spdy_request(spdy_headers.nv, proxy, with_body))
252 { 302 {
253 free(spdy_headers.nv); 303 free(spdy_headers.nv);
254 free_proxy(proxy); 304 free_proxy(proxy);
diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c
index 413de7f3..fb749291 100644
--- a/src/examples/mhd2spdy_spdy.c
+++ b/src/examples/mhd2spdy_spdy.c
@@ -63,6 +63,69 @@ spdy_diec(const char *func,
63} 63}
64 64
65 65
66static ssize_t
67spdy_cb_data_source_read(spdylay_session *session, int32_t stream_id, uint8_t *buf, size_t length, int *eof, spdylay_data_source *source, void *user_data)
68{
69 (void)session;
70 (void)stream_id;
71 (void)user_data;
72
73 ssize_t ret;
74 assert(NULL != source);
75 assert(NULL != source->ptr);
76 struct Proxy *proxy = (struct Proxy *)(source->ptr);
77 void *newbody;
78
79
80 if(length < 1)
81 {
82 PRINT_INFO("spdy_cb_data_source_read: length is 0");
83 return 0;
84 }
85
86 if(!proxy->received_body_size)//nothing to write now
87 {
88 if(proxy->receiving_done)
89 {
90 PRINT_INFO("POST spdy EOF");
91 *eof = 1;
92 }
93 PRINT_INFO("POST SPDYLAY_ERR_DEFERRED");
94 return SPDYLAY_ERR_DEFERRED;//TODO SPDYLAY_ERR_DEFERRED should be used
95 }
96
97 if(length >= proxy->received_body_size)
98 {
99 ret = proxy->received_body_size;
100 newbody = NULL;
101 }
102 else
103 {
104 ret = length;
105 if(NULL == (newbody = malloc(proxy->received_body_size - length)))
106 {
107 PRINT_INFO("no memory");
108 return SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE;
109 }
110 memcpy(newbody, proxy->received_body + length, proxy->received_body_size - length);
111 }
112 memcpy(buf, proxy->received_body, ret);
113 free(proxy->received_body);
114 proxy->received_body = newbody;
115 proxy->received_body_size -= ret;
116
117 if(0 == proxy->received_body_size && proxy->receiving_done)
118 {
119 PRINT_INFO("POST spdy EOF");
120 *eof = 1;
121 }
122
123 PRINT_INFO2("given POST bytes to spdylay: %zd", ret);
124
125 return ret;
126}
127
128
66/* 129/*
67 * The implementation of spdylay_send_callback type. Here we write 130 * The implementation of spdylay_send_callback type. Here we write
68 * |data| with size |length| to the network and return the number of 131 * |data| with size |length| to the network and return the number of
@@ -91,7 +154,7 @@ spdy_cb_send(spdylay_session *session,
91 if(rv < 0) { 154 if(rv < 0) {
92 int err = SSL_get_error(connection->ssl, rv); 155 int err = SSL_get_error(connection->ssl, rv);
93 if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) { 156 if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
94 connection->want_io = (err == SSL_ERROR_WANT_READ ? 157 connection->want_io |= (err == SSL_ERROR_WANT_READ ?
95 WANT_READ : WANT_WRITE); 158 WANT_READ : WANT_WRITE);
96 rv = SPDYLAY_ERR_WOULDBLOCK; 159 rv = SPDYLAY_ERR_WOULDBLOCK;
97 } else { 160 } else {
@@ -113,7 +176,7 @@ spdy_cb_send(spdylay_session *session,
113 #if EAGAIN != EWOULDBLOCK 176 #if EAGAIN != EWOULDBLOCK
114 case EWOULDBLOCK: 177 case EWOULDBLOCK:
115 #endif 178 #endif
116 connection->want_io = WANT_WRITE; 179 connection->want_io |= WANT_WRITE;
117 rv = SPDYLAY_ERR_WOULDBLOCK; 180 rv = SPDYLAY_ERR_WOULDBLOCK;
118 break; 181 break;
119 182
@@ -122,6 +185,9 @@ spdy_cb_send(spdylay_session *session,
122 } 185 }
123 } 186 }
124 } 187 }
188
189 PRINT_INFO2("%zd bytes written by spdy", rv);
190
125 return rv; 191 return rv;
126} 192}
127 193
@@ -156,7 +222,7 @@ spdy_cb_recv(spdylay_session *session,
156 if(rv < 0) { 222 if(rv < 0) {
157 int err = SSL_get_error(connection->ssl, rv); 223 int err = SSL_get_error(connection->ssl, rv);
158 if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) { 224 if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
159 connection->want_io = (err == SSL_ERROR_WANT_READ ? 225 connection->want_io |= (err == SSL_ERROR_WANT_READ ?
160 WANT_READ : WANT_WRITE); 226 WANT_READ : WANT_WRITE);
161 rv = SPDYLAY_ERR_WOULDBLOCK; 227 rv = SPDYLAY_ERR_WOULDBLOCK;
162 } else { 228 } else {
@@ -180,7 +246,7 @@ spdy_cb_recv(spdylay_session *session,
180 #if EAGAIN != EWOULDBLOCK 246 #if EAGAIN != EWOULDBLOCK
181 case EWOULDBLOCK: 247 case EWOULDBLOCK:
182 #endif 248 #endif
183 connection->want_io = WANT_READ; 249 connection->want_io |= WANT_READ;
184 rv = SPDYLAY_ERR_WOULDBLOCK; 250 rv = SPDYLAY_ERR_WOULDBLOCK;
185 break; 251 break;
186 252
@@ -210,6 +276,7 @@ spdy_cb_on_ctrl_send(spdylay_session *session,
210 case SPDYLAY_SYN_STREAM: 276 case SPDYLAY_SYN_STREAM:
211 stream_id = frame->syn_stream.stream_id; 277 stream_id = frame->syn_stream.stream_id;
212 proxy = spdylay_session_get_stream_user_data(session, stream_id); 278 proxy = spdylay_session_get_stream_user_data(session, stream_id);
279 proxy->stream_id = stream_id;
213 ++glob_opt.streams_opened; 280 ++glob_opt.streams_opened;
214 ++proxy->spdy_connection->streams_opened; 281 ++proxy->spdy_connection->streams_opened;
215 PRINT_INFO2("opening stream: str open %i; %s", glob_opt.streams_opened, proxy->url); 282 PRINT_INFO2("opening stream: str open %i; %s", glob_opt.streams_opened, proxy->url);
@@ -325,6 +392,13 @@ spdy_cb_on_data_chunk_recv(spdylay_session *session,
325 struct Proxy *proxy; 392 struct Proxy *proxy;
326 proxy = spdylay_session_get_stream_user_data(session, stream_id); 393 proxy = spdylay_session_get_stream_user_data(session, stream_id);
327 394
395 if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size))
396 {
397 //TODO handle it better?
398 PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
399 return;
400 }
401 /*
328 if(NULL == proxy->http_body) 402 if(NULL == proxy->http_body)
329 proxy->http_body = au_malloc(len); 403 proxy->http_body = au_malloc(len);
330 else 404 else
@@ -337,6 +411,7 @@ spdy_cb_on_data_chunk_recv(spdylay_session *session,
337 411
338 memcpy(proxy->http_body + proxy->http_body_size, data, len); 412 memcpy(proxy->http_body + proxy->http_body_size, data, len);
339 proxy->http_body_size += len; 413 proxy->http_body_size += len;
414 */
340 PRINT_INFO2("received data for %s; %zu bytes", proxy->url, len); 415 PRINT_INFO2("received data for %s; %zu bytes", proxy->url, len);
341 glob_opt.spdy_data_received = true; 416 glob_opt.spdy_data_received = true;
342} 417}
@@ -533,12 +608,12 @@ spdy_ctl_poll(struct pollfd *pollfd,
533{ 608{
534 pollfd->events = 0; 609 pollfd->events = 0;
535 if(spdylay_session_want_read(connection->session) || 610 if(spdylay_session_want_read(connection->session) ||
536 connection->want_io == WANT_READ) 611 connection->want_io & WANT_READ)
537 { 612 {
538 pollfd->events |= POLLIN; 613 pollfd->events |= POLLIN;
539 } 614 }
540 if(spdylay_session_want_write(connection->session) || 615 if(spdylay_session_want_write(connection->session) ||
541 connection->want_io == WANT_WRITE) 616 connection->want_io & WANT_WRITE)
542 { 617 {
543 pollfd->events |= POLLOUT; 618 pollfd->events |= POLLOUT;
544 } 619 }
@@ -559,13 +634,13 @@ spdy_ctl_select(fd_set * read_fd_set,
559 bool ret = false; 634 bool ret = false;
560 635
561 if(spdylay_session_want_read(connection->session) || 636 if(spdylay_session_want_read(connection->session) ||
562 connection->want_io == WANT_READ) 637 connection->want_io & WANT_READ)
563 { 638 {
564 FD_SET(connection->fd, read_fd_set); 639 FD_SET(connection->fd, read_fd_set);
565 ret = true; 640 ret = true;
566 } 641 }
567 if(spdylay_session_want_write(connection->session) || 642 if(spdylay_session_want_write(connection->session) ||
568 connection->want_io == WANT_WRITE) 643 connection->want_io & WANT_WRITE)
569 { 644 {
570 FD_SET(connection->fd, write_fd_set); 645 FD_SET(connection->fd, write_fd_set);
571 ret = true; 646 ret = true;
@@ -690,11 +765,13 @@ spdy_free_connection(struct SPDY_Connection * connection)
690 765
691int 766int
692spdy_request(const char **nv, 767spdy_request(const char **nv,
693 struct Proxy *proxy) 768 struct Proxy *proxy,
769 bool with_body)
694{ 770{
695 int ret; 771 int ret;
696 uint16_t port; 772 uint16_t port;
697 struct SPDY_Connection *connection; 773 struct SPDY_Connection *connection;
774 spdylay_data_provider post_data;
698 775
699 if(glob_opt.only_proxy) 776 if(glob_opt.only_proxy)
700 { 777 {
@@ -733,7 +810,15 @@ spdy_request(const char **nv,
733 } 810 }
734 811
735 proxy->spdy_connection = connection; 812 proxy->spdy_connection = connection;
736 ret = spdylay_submit_request(connection->session, 0, nv, NULL, proxy); 813 if(with_body)
814 {
815 post_data.source.ptr = proxy;
816 post_data.read_callback = &spdy_cb_data_source_read;
817 ret = spdylay_submit_request(connection->session, 0, nv, &post_data, proxy);
818 }
819 else
820 ret = spdylay_submit_request(connection->session, 0, nv, NULL, proxy);
821
737 if(ret != 0) { 822 if(ret != 0) {
738 spdy_diec("spdylay_spdy_submit_request", ret); 823 spdy_diec("spdylay_spdy_submit_request", ret);
739 } 824 }
@@ -958,6 +1043,7 @@ spdy_run_select(fd_set * read_fd_set,
958 // PRINT_INFO2("exec about to be called for %s", connections[i]->host); 1043 // PRINT_INFO2("exec about to be called for %s", connections[i]->host);
959 if(FD_ISSET(connections[i]->fd, read_fd_set) || FD_ISSET(connections[i]->fd, write_fd_set) || FD_ISSET(connections[i]->fd, except_fd_set)) 1044 if(FD_ISSET(connections[i]->fd, read_fd_set) || FD_ISSET(connections[i]->fd, write_fd_set) || FD_ISSET(connections[i]->fd, except_fd_set))
960 { 1045 {
1046 //raise(SIGINT);
961 ret = spdy_exec_io(connections[i]); 1047 ret = spdy_exec_io(connections[i]);
962 1048
963 if(0 != ret) 1049 if(0 != ret)
@@ -981,6 +1067,12 @@ spdy_run_select(fd_set * read_fd_set,
981 } 1067 }
982 } 1068 }
983 else 1069 else
1070 {
984 PRINT_INFO("not called"); 1071 PRINT_INFO("not called");
1072 PRINT_INFO2("connection->want_io %i",connections[i]->want_io);
1073 PRINT_INFO2("read %i",spdylay_session_want_read(connections[i]->session));
1074 PRINT_INFO2("write %i",spdylay_session_want_write(connections[i]->session));
1075 //raise(SIGINT);
1076 }
985 } 1077 }
986} 1078}
diff --git a/src/examples/mhd2spdy_spdy.h b/src/examples/mhd2spdy_spdy.h
index 980ee1d1..13e850b9 100644
--- a/src/examples/mhd2spdy_spdy.h
+++ b/src/examples/mhd2spdy_spdy.h
@@ -56,7 +56,8 @@ spdy_diec(const char *func,
56 56
57int 57int
58spdy_request(const char **nv, 58spdy_request(const char **nv,
59 struct Proxy *proxy); 59 struct Proxy *proxy,
60 bool with_body);
60 61
61 62
62void 63void
diff --git a/src/examples/mhd2spdy_structures.c b/src/examples/mhd2spdy_structures.c
index 2982b2a4..8e7852c2 100644
--- a/src/examples/mhd2spdy_structures.c
+++ b/src/examples/mhd2spdy_structures.c
@@ -138,3 +138,23 @@ void *au_malloc(size_t size)
138 } 138 }
139 return new_memory; 139 return new_memory;
140} 140}
141
142
143bool
144copy_buffer(const void *src, size_t src_size, void **dst, size_t *dst_size)
145{
146 if(0 == src_size)
147 return true;
148
149 if(NULL == *dst)
150 *dst = malloc(src_size);
151 else
152 *dst = realloc(*dst, src_size + *dst_size);
153 if(NULL == *dst)
154 return false;
155
156 memcpy(*dst + *dst_size, src, src_size);
157 *dst_size += src_size;
158
159 return true;
160}
diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h
index 88c28c64..863661b2 100644
--- a/src/examples/mhd2spdy_structures.h
+++ b/src/examples/mhd2spdy_structures.h
@@ -112,14 +112,18 @@ struct Proxy
112 char *url; 112 char *url;
113 char *version; 113 char *version;
114 void *http_body; 114 void *http_body;
115 void *received_body;
115 size_t http_body_size; 116 size_t http_body_size;
117 size_t received_body_size;
116 ssize_t length; 118 ssize_t length;
117 int status; 119 int status;
118 int id; 120 int id;
121 int32_t stream_id;
119 bool done; 122 bool done;
120 bool error; 123 bool error;
121 bool http_active; 124 bool http_active;
122 bool spdy_active; 125 bool spdy_active;
126 bool receiving_done;
123}; 127};
124 128
125 129
@@ -265,4 +269,7 @@ void *
265au_malloc(size_t size); 269au_malloc(size_t size);
266 270
267 271
272bool
273copy_buffer(const void *src, size_t src_size, void **dst, size_t *dst_size);
274
268#endif 275#endif
diff --git a/src/examples/spdy_event_loop.c b/src/examples/spdy_event_loop.c
index e5e2a5b1..3b6f9c82 100644
--- a/src/examples/spdy_event_loop.c
+++ b/src/examples/spdy_event_loop.c
@@ -199,7 +199,8 @@ standard_request_handler(void *cls,
199 const char *version, 199 const char *version,
200 const char *host, 200 const char *host,
201 const char *scheme, 201 const char *scheme,
202 struct SPDY_NameValue * headers) 202 struct SPDY_NameValue * headers,
203 bool more)
203{ 204{
204 char *html; 205 char *html;
205 char *data; 206 char *data;
@@ -259,6 +260,20 @@ standard_request_handler(void *cls,
259} 260}
260 261
261 262
263static int
264new_post_data_cb (void * cls,
265 struct SPDY_Request *request,
266 const void * buf,
267 size_t size,
268 bool more)
269{
270 printf("DATA:\n===============================\n");
271 write(0, buf, size);
272 printf("\n===============================\n");
273 return SPDY_YES;
274}
275
276
262static void 277static void
263sig_handler(int signo) 278sig_handler(int signo)
264{ 279{
@@ -288,7 +303,7 @@ main (int argc, char *const *argv)
288 struct SPDY_Daemon *daemon = SPDY_start_daemon(atoi(argv[1]), 303 struct SPDY_Daemon *daemon = SPDY_start_daemon(atoi(argv[1]),
289 DATA_DIR "cert-and-key.pem", 304 DATA_DIR "cert-and-key.pem",
290 DATA_DIR "cert-and-key.pem", 305 DATA_DIR "cert-and-key.pem",
291 &new_session_callback,&session_closed_handler,&standard_request_handler,NULL,NULL, 306 &new_session_callback,&session_closed_handler,&standard_request_handler,&new_post_data_cb,NULL,
292 SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 10, 307 SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 10,
293 //SPDY_DAEMON_OPTION_SOCK_ADDR, (struct sockaddr *)&addr4, 308 //SPDY_DAEMON_OPTION_SOCK_ADDR, (struct sockaddr *)&addr4,
294 SPDY_DAEMON_OPTION_END); 309 SPDY_DAEMON_OPTION_END);
@@ -306,7 +321,7 @@ main (int argc, char *const *argv)
306 struct SPDY_Daemon *daemon2 = SPDY_start_daemon(atoi(argv[1]) + 1, 321 struct SPDY_Daemon *daemon2 = SPDY_start_daemon(atoi(argv[1]) + 1,
307 DATA_DIR "cert-and-key.pem", 322 DATA_DIR "cert-and-key.pem",
308 DATA_DIR "cert-and-key.pem", 323 DATA_DIR "cert-and-key.pem",
309 &new_session_callback,NULL,&standard_request_handler,NULL,&main, 324 &new_session_callback,NULL,&standard_request_handler,&new_post_data_cb,&main,
310 //SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 0, 325 //SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 0,
311 //SPDY_DAEMON_OPTION_SOCK_ADDR, (struct sockaddr *)&addr6, 326 //SPDY_DAEMON_OPTION_SOCK_ADDR, (struct sockaddr *)&addr6,
312 //SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_FLAG_ONLY_IPV6, 327 //SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_FLAG_ONLY_IPV6,
diff --git a/src/examples/spdy_fileserver.c b/src/examples/spdy_fileserver.c
index f2b8f7b0..024bb644 100644
--- a/src/examples/spdy_fileserver.c
+++ b/src/examples/spdy_fileserver.c
@@ -22,7 +22,10 @@
22 * files directly read from the system 22 * files directly read from the system
23 * @author Andrey Uzunov 23 * @author Andrey Uzunov
24 */ 24 */
25 25
26//for asprintf
27#define _GNU_SOURCE
28
26#include <unistd.h> 29#include <unistd.h>
27#include <stdlib.h> 30#include <stdlib.h>
28#include <stdint.h> 31#include <stdint.h>
@@ -114,6 +117,7 @@ response_done_callback(void *cls,
114 bool streamopened) 117 bool streamopened)
115{ 118{
116 (void)streamopened; 119 (void)streamopened;
120 (void)status;
117 //printf("answer for %s was sent\n", (char *)cls); 121 //printf("answer for %s was sent\n", (char *)cls);
118 122
119 /*if(SPDY_RESPONSE_RESULT_SUCCESS != status) 123 /*if(SPDY_RESPONSE_RESULT_SUCCESS != status)
@@ -135,7 +139,8 @@ standard_request_handler(void *cls,
135 const char *version, 139 const char *version,
136 const char *host, 140 const char *host,
137 const char *scheme, 141 const char *scheme,
138 struct SPDY_NameValue * headers) 142 struct SPDY_NameValue * headers,
143 bool more)
139{ 144{
140 (void)cls; 145 (void)cls;
141 (void)request; 146 (void)request;
@@ -143,6 +148,9 @@ standard_request_handler(void *cls,
143 (void)host; 148 (void)host;
144 (void)scheme; 149 (void)scheme;
145 (void)headers; 150 (void)headers;
151 (void)method;
152 (void)version;
153 (void)more;
146 154
147 struct SPDY_Response *response=NULL; 155 struct SPDY_Response *response=NULL;
148 struct SPDY_NameValue *resp_headers; 156 struct SPDY_NameValue *resp_headers;
@@ -165,7 +173,7 @@ standard_request_handler(void *cls,
165 || -1 == (filesize = ftell(fd)) 173 || -1 == (filesize = ftell(fd))
166 || 0 != (ret = fseek(fd, 0L, SEEK_SET))) 174 || 0 != (ret = fseek(fd, 0L, SEEK_SET)))
167 { 175 {
168 printf("Error on opening %s\n%i %i %i\n",fname, fd, ret, filesize); 176 printf("Error on opening %s\n%p %i %zd\n",fname, fd, ret, filesize);
169 response = SPDY_build_response(SPDY_HTTP_INTERNAL_SERVER_ERROR,NULL,SPDY_HTTP_VERSION_1_1,NULL,NULL,0); 177 response = SPDY_build_response(SPDY_HTTP_INTERNAL_SERVER_ERROR,NULL,SPDY_HTTP_VERSION_1_1,NULL,NULL,0);
170 } 178 }
171 else 179 else
@@ -185,7 +193,7 @@ standard_request_handler(void *cls,
185 } 193 }
186 free(date); 194 free(date);
187 195
188 if(-1 == asprintf(&fsize, "%i", filesize) 196 if(-1 == asprintf(&fsize, "%zd", filesize)
189 || SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_CONTENT_LENGTH,fsize)) 197 || SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_CONTENT_LENGTH,fsize))
190 { 198 {
191 printf("SPDY_name_value_add or asprintf failed\n"); 199 printf("SPDY_name_value_add or asprintf failed\n");
diff --git a/src/examples/spdy_response_with_callback.c b/src/examples/spdy_response_with_callback.c
index 1a029a64..e3233802 100644
--- a/src/examples/spdy_response_with_callback.c
+++ b/src/examples/spdy_response_with_callback.c
@@ -22,6 +22,9 @@
22 * @author Andrey Uzunov 22 * @author Andrey Uzunov
23 */ 23 */
24 24
25//for asprintf
26#define _GNU_SOURCE
27
25#include <unistd.h> 28#include <unistd.h>
26#include <stdlib.h> 29#include <stdlib.h>
27#include <stdint.h> 30#include <stdint.h>
@@ -61,6 +64,8 @@ response_done_callback(void *cls,
61 bool streamopened) 64 bool streamopened)
62{ 65{
63 (void)streamopened; 66 (void)streamopened;
67 (void)status;
68
64 printf("answer for %s was sent\n", (char *)cls); 69 printf("answer for %s was sent\n", (char *)cls);
65 70
66 SPDY_destroy_request(request); 71 SPDY_destroy_request(request);
@@ -78,7 +83,8 @@ standard_request_handler(void *cls,
78 const char *version, 83 const char *version,
79 const char *host, 84 const char *host,
80 const char *scheme, 85 const char *scheme,
81 struct SPDY_NameValue * headers) 86 struct SPDY_NameValue * headers,
87 bool more)
82{ 88{
83 (void)cls; 89 (void)cls;
84 (void)request; 90 (void)request;
@@ -86,6 +92,7 @@ standard_request_handler(void *cls,
86 (void)host; 92 (void)host;
87 (void)scheme; 93 (void)scheme;
88 (void)headers; 94 (void)headers;
95 (void)more;
89 96
90 char *html; 97 char *html;
91 struct SPDY_Response *response=NULL; 98 struct SPDY_Response *response=NULL;
diff --git a/src/include/microspdy.h b/src/include/microspdy.h
index 272c411a..3b36025f 100644
--- a/src/include/microspdy.h
+++ b/src/include/microspdy.h
@@ -628,7 +628,9 @@ typedef int
628 628
629 629
630/** 630/**
631 * Callback for received SPDY request. 631 * Callback for received SPDY request. The functions is called whenever
632 * a reqest comes, but will also be called if more headers/trailers are
633 * received.
632 * 634 *
633 * @param cls client-defined closure 635 * @param cls client-defined closure
634 * @param request handler. The request object is required for 636 * @param request handler. The request object is required for
@@ -642,6 +644,11 @@ typedef int
642 * @param host called host as in HTTP 644 * @param host called host as in HTTP
643 * @param scheme used ("http" or "https"). In SPDY 3 it is only "https". 645 * @param scheme used ("http" or "https"). In SPDY 3 it is only "https".
644 * @param headers other HTTP headers from the request 646 * @param headers other HTTP headers from the request
647 * @param more a flag saying if more data related to the request is
648 * expected to be received. HTTP body may arrive (e.g. POST data);
649 * then SPDY_NewDataCallback will be called for the connection.
650 * It is also possible that more headers/trailers may arrive;
651 * then the same callback will be invoked.
645 */ 652 */
646typedef void (*SPDY_NewRequestCallback) (void * cls, 653typedef void (*SPDY_NewRequestCallback) (void * cls,
647 struct SPDY_Request * request, 654 struct SPDY_Request * request,
@@ -651,24 +658,27 @@ typedef void (*SPDY_NewRequestCallback) (void * cls,
651 const char * version, 658 const char * version,
652 const char * host, 659 const char * host,
653 const char * scheme, 660 const char * scheme,
654 struct SPDY_NameValue * headers); 661 struct SPDY_NameValue * headers,
662 bool more);
655 663
656 664
657/** 665/**
658 * Callback for received new data chunk from the POST data of a given 666 * Callback for received new data chunk (HTTP body) from a given
659 * request. 667 * request (e.g. POST data).
660 * 668 *
661 * @param cls client-defined closure 669 * @param cls client-defined closure
662 * @param request handler 670 * @param request handler
663 * @param buf data chunk from the POST data 671 * @param buf data chunk from the POST data
664 * @param size the size of the data chunk 'buf' in bytes 672 * @param size the size of the data chunk 'buf' in bytes. Note that it
665 * @param more false if this is the last chunk from the POST data. Note: 673 * may be 0.
674 * @param more false if this is the last chunk from the data. Note:
666 * true does not mean that more data will come, exceptional 675 * true does not mean that more data will come, exceptional
667 * situation is possible 676 * situation is possible
668 * @return SPDY_YES to continue calling the function, 677 * @return SPDY_YES to continue calling the function,
669 * SPDY_NO to stop calling the function for this request 678 * SPDY_NO to stop calling the function for this request
670 */ 679 */
671typedef int (*SPDY_NewPOSTDataCallback) (void * cls, 680typedef int
681(*SPDY_NewDataCallback) (void * cls,
672 struct SPDY_Request *request, 682 struct SPDY_Request *request,
673 const void * buf, 683 const void * buf,
674 size_t size, 684 size_t size,
@@ -855,7 +865,7 @@ SPDY_start_daemon (uint16_t port,
855 SPDY_NewSessionCallback nscb, 865 SPDY_NewSessionCallback nscb,
856 SPDY_SessionClosedCallback sccb, 866 SPDY_SessionClosedCallback sccb,
857 SPDY_NewRequestCallback nrcb, 867 SPDY_NewRequestCallback nrcb,
858 SPDY_NewPOSTDataCallback npdcb, 868 SPDY_NewDataCallback npdcb,
859 void * cls, 869 void * cls,
860 ...); 870 ...);
861 871
diff --git a/src/microspdy/applicationlayer.c b/src/microspdy/applicationlayer.c
index efcf2b3d..17a00289 100644
--- a/src/microspdy/applicationlayer.c
+++ b/src/microspdy/applicationlayer.c
@@ -157,7 +157,7 @@ spdy_handler_new_stream (void *cls,
157 } 157 }
158 158
159 //ignore everything but GET 159 //ignore everything but GET
160 if(strcasecmp("GET",method)) 160 if(strcasecmp("GET",method) && strcasecmp("POST",method))
161 { 161 {
162 SPDYF_DEBUG("received method '%s'", method); 162 SPDYF_DEBUG("received method '%s'", method);
163 static char * html = "Method not implemented. libmicrospdy supports now only GET."; 163 static char * html = "Method not implemented. libmicrospdy supports now only GET.";
@@ -187,7 +187,10 @@ spdy_handler_new_stream (void *cls,
187 version, 187 version,
188 host, 188 host,
189 scheme, 189 scheme,
190 headers); 190 headers,
191 !stream->is_in_closed);
192
193 stream->cls = request;
191 194
192 return SPDY_YES; 195 return SPDY_YES;
193 196
@@ -200,6 +203,21 @@ spdy_handler_new_stream (void *cls,
200 203
201 204
202/** 205/**
206 * TODO
207 */
208static int
209spdy_handler_new_data (void * cls,
210 struct SPDYF_Stream *stream,
211 const void * buf,
212 size_t size,
213 bool more)
214{
215 return stream->session->daemon->received_data_cb(cls, stream->cls, buf, size, more);
216}
217
218
219
220/**
203 * Callback to be called when the response queue object was handled and 221 * Callback to be called when the response queue object was handled and
204 * the data was already sent or discarded. 222 * the data was already sent or discarded.
205 * 223 *
@@ -332,7 +350,7 @@ SPDY_start_daemon (uint16_t port,
332 SPDY_NewSessionCallback nscb, 350 SPDY_NewSessionCallback nscb,
333 SPDY_SessionClosedCallback sccb, 351 SPDY_SessionClosedCallback sccb,
334 SPDY_NewRequestCallback nrcb, 352 SPDY_NewRequestCallback nrcb,
335 SPDY_NewPOSTDataCallback npdcb, 353 SPDY_NewDataCallback npdcb,
336 void * cls, 354 void * cls,
337 ...) 355 ...)
338{ 356{
@@ -367,6 +385,7 @@ SPDY_start_daemon (uint16_t port,
367 nrcb, 385 nrcb,
368 npdcb, 386 npdcb,
369 &spdy_handler_new_stream, 387 &spdy_handler_new_stream,
388 &spdy_handler_new_data,
370 cls, 389 cls,
371 NULL, 390 NULL,
372 valist 391 valist
diff --git a/src/microspdy/daemon.c b/src/microspdy/daemon.c
index a8bea83b..77129894 100644
--- a/src/microspdy/daemon.c
+++ b/src/microspdy/daemon.c
@@ -173,8 +173,9 @@ SPDYF_start_daemon_va (uint16_t port,
173 SPDY_NewSessionCallback nscb, 173 SPDY_NewSessionCallback nscb,
174 SPDY_SessionClosedCallback sccb, 174 SPDY_SessionClosedCallback sccb,
175 SPDY_NewRequestCallback nrcb, 175 SPDY_NewRequestCallback nrcb,
176 SPDY_NewPOSTDataCallback npdcb, 176 SPDY_NewDataCallback npdcb,
177 SPDYF_NewStreamCallback fnscb, 177 SPDYF_NewStreamCallback fnscb,
178 SPDYF_NewDataCallback fndcb,
178 void * cls, 179 void * cls,
179 void * fcls, 180 void * fcls,
180 va_list valist) 181 va_list valist)
@@ -237,10 +238,11 @@ SPDYF_start_daemon_va (uint16_t port,
237 daemon->new_session_cb = nscb; 238 daemon->new_session_cb = nscb;
238 daemon->session_closed_cb = sccb; 239 daemon->session_closed_cb = sccb;
239 daemon->new_request_cb = nrcb; 240 daemon->new_request_cb = nrcb;
240 daemon->new_post_data_cb = npdcb; 241 daemon->received_data_cb = npdcb;
241 daemon->cls = cls; 242 daemon->cls = cls;
242 daemon->fcls = fcls; 243 daemon->fcls = fcls;
243 daemon->fnew_stream_cb = fnscb; 244 daemon->fnew_stream_cb = fnscb;
245 daemon->freceived_data_cb = fndcb;
244 246
245#if HAVE_INET6 247#if HAVE_INET6
246 //handling IPv6 248 //handling IPv6
diff --git a/src/microspdy/daemon.h b/src/microspdy/daemon.h
index 03e322b5..0dbc5ab1 100644
--- a/src/microspdy/daemon.h
+++ b/src/microspdy/daemon.h
@@ -62,8 +62,9 @@ SPDYF_start_daemon_va (uint16_t port,
62 SPDY_NewSessionCallback nscb, 62 SPDY_NewSessionCallback nscb,
63 SPDY_SessionClosedCallback sccb, 63 SPDY_SessionClosedCallback sccb,
64 SPDY_NewRequestCallback nrcb, 64 SPDY_NewRequestCallback nrcb,
65 SPDY_NewPOSTDataCallback npdcb, 65 SPDY_NewDataCallback npdcb,
66 SPDYF_NewStreamCallback fnscb, 66 SPDYF_NewStreamCallback fnscb,
67 SPDYF_NewDataCallback fndcb,
67 void * cls, 68 void * cls,
68 void * fcls, 69 void * fcls,
69 va_list valist); 70 va_list valist);
diff --git a/src/microspdy/session.c b/src/microspdy/session.c
index 856bed85..7edebaba 100644
--- a/src/microspdy/session.c
+++ b/src/microspdy/session.c
@@ -325,14 +325,15 @@ spdyf_handler_read_rst_stream (struct SPDY_Session *session)
325static void 325static void
326spdyf_handler_read_data (struct SPDY_Session *session) 326spdyf_handler_read_data (struct SPDY_Session *session)
327{ 327{
328 //just ignore the whole frame for now 328 int ret;
329 struct SPDYF_Data_Frame * frame; 329 struct SPDYF_Data_Frame * frame;
330 struct SPDYF_Stream * stream;
330 331
331 SPDYF_ASSERT(SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER == session->status 332 SPDYF_ASSERT(SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER == session->status
332 || SPDY_SESSION_STATUS_WAIT_FOR_BODY == session->status, 333 || SPDY_SESSION_STATUS_WAIT_FOR_BODY == session->status,
333 "the function is called wrong"); 334 "the function is called wrong");
334 335
335 SPDYF_DEBUG("DATA frame received (POST?). Ignoring"); 336 //SPDYF_DEBUG("DATA frame received (POST?). Ignoring");
336 337
337 //SPDYF_SIGINT(""); 338 //SPDYF_SIGINT("");
338 339
@@ -355,9 +356,41 @@ spdyf_handler_read_data (struct SPDY_Session *session)
355 if(session->read_buffer_offset - session->read_buffer_beginning 356 if(session->read_buffer_offset - session->read_buffer_beginning
356 >= frame->length) 357 >= frame->length)
357 { 358 {
358 session->read_buffer_beginning += frame->length; 359 stream = SPDYF_stream_find(frame->stream_id, session);
359 session->status = SPDY_SESSION_STATUS_WAIT_FOR_HEADER; 360
360 free(frame); 361 if(NULL == stream || stream->is_in_closed || NULL == session->daemon->received_data_cb)
362 {
363 if(NULL == session->daemon->received_data_cb)
364 SPDYF_DEBUG("No callback for DATA frame set");
365
366 SPDYF_DEBUG("Ignoring DATA frame!");
367
368 //TODO send error?
369
370 //TODO for now ignore frame
371 session->read_buffer_beginning += frame->length;
372 session->status = SPDY_SESSION_STATUS_WAIT_FOR_HEADER;
373 free(frame);
374 return;
375 }
376
377 ret = session->daemon->freceived_data_cb(session->daemon->cls,
378 stream,
379 session->read_buffer + session->read_buffer_beginning,
380 frame->length,
381 0 == (SPDY_DATA_FLAG_FIN & frame->flags));
382
383 session->read_buffer_beginning += frame->length;
384
385 //TODO close in and send rst maybe
386 SPDYF_ASSERT(SPDY_YES == ret, "Cancel POST data is not yet implemented");
387
388 if(SPDY_DATA_FLAG_FIN & frame->flags)
389 {
390 stream->is_in_closed = true;
391 }
392 session->status = SPDY_SESSION_STATUS_WAIT_FOR_HEADER;
393 free(frame);
361 } 394 }
362} 395}
363 396
@@ -1020,7 +1053,7 @@ SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
1020 } 1053 }
1021 1054
1022 //set stream to closed if the frame's fin flag is set 1055 //set stream to closed if the frame's fin flag is set
1023 SPDYF_stream_set_flags(queue_head); 1056 SPDYF_stream_set_flags_on_write(queue_head);
1024 1057
1025 if(NULL != queue_head->frqcb) 1058 if(NULL != queue_head->frqcb)
1026 { 1059 {
diff --git a/src/microspdy/stream.c b/src/microspdy/stream.c
index 97fdd6c8..336672ac 100644
--- a/src/microspdy/stream.c
+++ b/src/microspdy/stream.c
@@ -122,7 +122,7 @@ SPDYF_stream_destroy(struct SPDYF_Stream *stream)
122 122
123 123
124void 124void
125SPDYF_stream_set_flags(struct SPDYF_Response_Queue *response_queue) 125SPDYF_stream_set_flags_on_write(struct SPDYF_Response_Queue *response_queue)
126{ 126{
127 struct SPDYF_Stream * stream = response_queue->stream; 127 struct SPDYF_Stream * stream = response_queue->stream;
128 128
@@ -149,3 +149,20 @@ SPDYF_stream_set_flags(struct SPDYF_Response_Queue *response_queue)
149 } 149 }
150 } 150 }
151} 151}
152
153
154//TODO add function *on_read
155
156
157struct SPDYF_Stream *
158SPDYF_stream_find(uint32_t stream_id, struct SPDY_Session * session)
159{
160 struct SPDYF_Stream * stream = session->streams_head;
161
162 while(NULL != stream && stream_id != stream->stream_id)
163 {
164 stream = stream->next;
165 }
166
167 return stream;
168}
diff --git a/src/microspdy/stream.h b/src/microspdy/stream.h
index a795ad28..de51077a 100644
--- a/src/microspdy/stream.h
+++ b/src/microspdy/stream.h
@@ -60,6 +60,17 @@ SPDYF_stream_destroy(struct SPDYF_Stream *stream);
60 * @param response_queue sent for this stream 60 * @param response_queue sent for this stream
61 */ 61 */
62void 62void
63SPDYF_stream_set_flags(struct SPDYF_Response_Queue *response_queue); 63SPDYF_stream_set_flags_on_write(struct SPDYF_Response_Queue *response_queue);
64
65
66/**
67 * Find and return a session's stream, based on stream's ID.
68 *
69 * @param stream_id to search for
70 * @param session whose streams are considered
71 * @return SPDY_Stream with the desired ID. Can be NULL.
72 */
73struct SPDYF_Stream *
74SPDYF_stream_find(uint32_t stream_id, struct SPDY_Session * session);
64 75
65#endif 76#endif
diff --git a/src/microspdy/structures.h b/src/microspdy/structures.h
index ff4c47ff..1c2a0aaf 100644
--- a/src/microspdy/structures.h
+++ b/src/microspdy/structures.h
@@ -317,6 +317,28 @@ struct SPDYF_Stream;
317 317
318struct SPDYF_Response_Queue; 318struct SPDYF_Response_Queue;
319 319
320
321/**
322 * Callback for received new data chunk.
323 *
324 * @param cls client-defined closure
325 * @param stream handler
326 * @param buf data chunk from the data
327 * @param size the size of the data chunk 'buf' in bytes
328 * @param more false if this is the last frame received on this stream. Note:
329 * true does not mean that more data will come, exceptional
330 * situation is possible
331 * @return SPDY_YES to continue calling the function,
332 * SPDY_NO to stop calling the function for this stream
333 */
334typedef int
335(*SPDYF_NewDataCallback) (void * cls,
336 struct SPDYF_Stream *stream,
337 const void * buf,
338 size_t size,
339 bool more);
340
341
320/** 342/**
321 * Callback for new stream. To be used in the application layer of the 343 * Callback for new stream. To be used in the application layer of the
322 * lib. 344 * lib.
@@ -515,6 +537,11 @@ struct SPDYF_Stream
515 * Name value pairs, sent within the frame which created the stream. 537 * Name value pairs, sent within the frame which created the stream.
516 */ 538 */
517 struct SPDY_NameValue *headers; 539 struct SPDY_NameValue *headers;
540
541 /**
542 * Any object to be used by the application layer.
543 */
544 void *cls;
518 545
519 /** 546 /**
520 * This stream's ID. 547 * This stream's ID.
@@ -888,9 +915,14 @@ struct SPDY_Daemon
888 915
889 /** 916 /**
890 * Callback called when HTTP POST params are received 917 * Callback called when HTTP POST params are received
891 * after request 918 * after request. To be used by the application layer
919 */
920 SPDY_NewDataCallback received_data_cb;
921
922 /**
923 * Callback called when DATA frame is received.
892 */ 924 */
893 SPDY_NewPOSTDataCallback new_post_data_cb; 925 SPDYF_NewDataCallback freceived_data_cb;
894 926
895 /** 927 /**
896 * Closure argument for all the callbacks that can be used by the client. 928 * Closure argument for all the callbacks that can be used by the client.
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index 19cb26f6..e896bbc4 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -163,11 +163,16 @@ struct Proxy
163 char *version; 163 char *version;
164 char *status_msg; 164 char *status_msg;
165 void *http_body; 165 void *http_body;
166 void *received_body;
166 bool *session_alive; 167 bool *session_alive;
167 size_t http_body_size; 168 size_t http_body_size;
169 size_t received_body_size;
168 //ssize_t length; 170 //ssize_t length;
169 int status; 171 int status;
170 bool done; 172 bool done;
173 bool receiving_done;
174 bool is_curl_read_paused;
175 bool is_with_body_data;
171 bool error; 176 bool error;
172}; 177};
173 178
@@ -219,6 +224,7 @@ deinit_parse_uri(regex_t * preg)
219static int 224static int
220parse_uri(regex_t * preg, const char * full_uri, struct URI ** uri) 225parse_uri(regex_t * preg, const char * full_uri, struct URI ** uri)
221{ 226{
227 //TODO memeory checks
222 int ret; 228 int ret;
223 char *colon; 229 char *colon;
224 long long port; 230 long long port;
@@ -277,7 +283,55 @@ parse_uri(regex_t * preg, const char * full_uri, struct URI ** uri)
277} 283}
278 284
279 285
280static void catch_signal(int signal) 286static bool
287store_in_buffer(const void *src, size_t src_size, void **dst, size_t *dst_size)
288{
289 if(0 == src_size)
290 return true;
291
292 if(NULL == *dst)
293 *dst = malloc(src_size);
294 else
295 *dst = realloc(*dst, src_size + *dst_size);
296 if(NULL == *dst)
297 return false;
298
299 memcpy(*dst + *dst_size, src, src_size);
300 *dst_size += src_size;
301
302 return true;
303}
304
305
306static ssize_t
307get_from_buffer(void **src, size_t *src_size, void *dst, size_t max_size)
308{
309 size_t ret;
310 void *newbody;
311
312 if(max_size >= *src_size)
313 {
314 ret = *src_size;
315 newbody = NULL;
316 }
317 else
318 {
319 ret = max_size;
320 if(NULL == (newbody = malloc(*src_size - max_size)))
321 return -1;
322 memcpy(newbody, *src + ret, *src_size - ret);
323 }
324 memcpy(dst, *src, ret);
325 free(*src);
326 *src = newbody;
327 *src_size -= ret;
328
329 return ret;
330}
331
332
333static void
334catch_signal(int signal)
281{ 335{
282 (void)signal; 336 (void)signal;
283 337
@@ -319,7 +373,58 @@ session_closed_cb (void * cls,
319 373
320 *session_alive = false; 374 *session_alive = false;
321} 375}
322 376
377
378static int
379spdy_post_data_cb (void * cls,
380 struct SPDY_Request *request,
381 const void * buf,
382 size_t size,
383 bool more)
384{
385 (void)cls;
386 int ret;
387 struct Proxy *proxy = (struct Proxy *)SPDY_get_cls_from_request(request);
388
389 if(!store_in_buffer(buf, size, &proxy->received_body, &proxy->received_body_size))
390 {
391 PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
392 return 0;
393 }
394 /*
395 if(NULL == proxy->received_body)
396 proxy->received_body = malloc(size);
397 else
398 proxy->received_body = realloc(proxy->received_body, proxy->received_body_size + size);
399 if(NULL == proxy->received_body)
400 {
401 PRINT_INFO("not enough memory (realloc returned NULL)");
402 return 0;
403 }
404
405 memcpy(proxy->received_body + proxy->received_body_size, buf, size);
406 proxy->received_body_size += size;
407 */
408
409 proxy->receiving_done = !more;
410
411 PRINT_VERBOSE2("POST bytes from SPDY: %zu", size);
412
413 call_curl_run = true;
414
415 if(proxy->is_curl_read_paused)
416 {
417 if(CURLE_OK != (ret = curl_easy_pause(proxy->curl_handle, CURLPAUSE_CONT)))
418 {
419 PRINT_INFO2("curl_easy_pause returned %i", ret);
420 abort();
421 }
422 PRINT_VERBOSE("curl_read_cb pause resumed");
423 }
424
425 return SPDY_YES;
426}
427
323 428
324ssize_t 429ssize_t
325response_callback (void *cls, 430response_callback (void *cls,
@@ -329,7 +434,7 @@ response_callback (void *cls,
329{ 434{
330 ssize_t ret; 435 ssize_t ret;
331 struct Proxy *proxy = (struct Proxy *)cls; 436 struct Proxy *proxy = (struct Proxy *)cls;
332 void *newbody; 437 //void *newbody;
333 438
334 //printf("response_callback\n"); 439 //printf("response_callback\n");
335 440
@@ -347,6 +452,14 @@ response_callback (void *cls,
347 return 0; 452 return 0;
348 } 453 }
349 454
455 ret = get_from_buffer(&(proxy->http_body), &(proxy->http_body_size), buffer, max);
456 if(ret < 0)
457 {
458 PRINT_INFO("no memory");
459 return -1;
460 }
461
462 /*
350 if(max >= proxy->http_body_size) 463 if(max >= proxy->http_body_size)
351 { 464 {
352 ret = proxy->http_body_size; 465 ret = proxy->http_body_size;
@@ -366,7 +479,7 @@ response_callback (void *cls,
366 free(proxy->http_body); 479 free(proxy->http_body);
367 proxy->http_body = newbody; 480 proxy->http_body = newbody;
368 proxy->http_body_size -= ret; 481 proxy->http_body_size -= ret;
369 482 */
370 if(proxy->done && 0 == proxy->http_body_size) *more = false; 483 if(proxy->done && 0 == proxy->http_body_size) *more = false;
371 484
372 PRINT_VERBOSE2("given bytes to microspdy: %zd", ret); 485 PRINT_VERBOSE2("given bytes to microspdy: %zd", ret);
@@ -407,6 +520,7 @@ response_done_callback(void *cls,
407} 520}
408 521
409 522
523
410static size_t 524static size_t
411curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp) 525curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
412{ 526{
@@ -560,6 +674,12 @@ curl_write_cb(void *contents, size_t size, size_t nmemb, void *userp)
560 return 0; 674 return 0;
561 } 675 }
562 676
677 if(!store_in_buffer(contents, realsize, &proxy->http_body, &proxy->http_body_size))
678 {
679 PRINT_INFO("not enough memory (malloc/realloc returned NULL)");
680 return 0;
681 }
682 /*
563 if(NULL == proxy->http_body) 683 if(NULL == proxy->http_body)
564 proxy->http_body = malloc(realsize); 684 proxy->http_body = malloc(realsize);
565 else 685 else
@@ -572,6 +692,7 @@ curl_write_cb(void *contents, size_t size, size_t nmemb, void *userp)
572 692
573 memcpy(proxy->http_body + proxy->http_body_size, contents, realsize); 693 memcpy(proxy->http_body + proxy->http_body_size, contents, realsize);
574 proxy->http_body_size += realsize; 694 proxy->http_body_size += realsize;
695 */
575 696
576 PRINT_VERBOSE2("received bytes from curl: %zu", realsize); 697 PRINT_VERBOSE2("received bytes from curl: %zu", realsize);
577 698
@@ -581,6 +702,69 @@ curl_write_cb(void *contents, size_t size, size_t nmemb, void *userp)
581} 702}
582 703
583 704
705static size_t
706curl_read_cb(void *ptr, size_t size, size_t nmemb, void *userp)
707{
708 ssize_t ret;
709 size_t max = size * nmemb;
710 struct Proxy *proxy = (struct Proxy *)userp;
711 //void *newbody;
712
713
714 if((proxy->receiving_done && !proxy->received_body_size) || !proxy->is_with_body_data || max < 1)
715 {
716 PRINT_VERBOSE("curl_read_cb last call");
717 return 0;
718 }
719
720 if(!*(proxy->session_alive))
721 {
722 PRINT_VERBOSE("POST is still being sent, but session is dead");
723 return CURL_READFUNC_ABORT;
724 }
725
726 if(!proxy->received_body_size)//nothing to write now
727 {
728 PRINT_VERBOSE("curl_read_cb called paused");
729 proxy->is_curl_read_paused = true;
730 return CURL_READFUNC_PAUSE;//TODO curl pause should be used
731 }
732
733 ret = get_from_buffer(&(proxy->received_body), &(proxy->received_body_size), ptr, max);
734 if(ret < 0)
735 {
736 PRINT_INFO("no memory");
737 return CURL_READFUNC_ABORT;
738 }
739
740 /*
741 if(max >= proxy->received_body_size)
742 {
743 ret = proxy->received_body_size;
744 newbody = NULL;
745 }
746 else
747 {
748 ret = max;
749 if(NULL == (newbody = malloc(proxy->received_body_size - max)))
750 {
751 PRINT_INFO("no memory");
752 return CURL_READFUNC_ABORT;
753 }
754 memcpy(newbody, proxy->received_body + max, proxy->received_body_size - max);
755 }
756 memcpy(ptr, proxy->received_body, ret);
757 free(proxy->received_body);
758 proxy->received_body = newbody;
759 proxy->received_body_size -= ret;
760 * */
761
762 PRINT_VERBOSE2("given POST bytes to curl: %zd", ret);
763
764 return ret;
765}
766
767
584static int 768static int
585iterate_cb (void *cls, const char *name, const char * const * value, int num_values) 769iterate_cb (void *cls, const char *name, const char * const * value, int num_values)
586{ 770{
@@ -630,7 +814,8 @@ standard_request_handler(void *cls,
630 const char *version, 814 const char *version,
631 const char *host, 815 const char *host,
632 const char *scheme, 816 const char *scheme,
633 struct SPDY_NameValue * headers) 817 struct SPDY_NameValue * headers,
818 bool more)
634{ 819{
635 (void)cls; 820 (void)cls;
636 (void)priority; 821 (void)priority;
@@ -641,6 +826,13 @@ standard_request_handler(void *cls,
641 int ret; 826 int ret;
642 struct URI *uri; 827 struct URI *uri;
643 struct SPDY_Session *session; 828 struct SPDY_Session *session;
829
830 proxy = SPDY_get_cls_from_request(request);
831 if(NULL != proxy)
832 {
833 //ignore trailers or more headers
834 return;
835 }
644 836
645 PRINT_VERBOSE2("received request for '%s %s %s'\n", method, path, version); 837 PRINT_VERBOSE2("received request for '%s %s %s'\n", method, path, version);
646 838
@@ -654,7 +846,10 @@ standard_request_handler(void *cls,
654 proxy->session_alive = SPDY_get_cls_from_session(session); 846 proxy->session_alive = SPDY_get_cls_from_session(session);
655 assert(NULL != proxy->session_alive); 847 assert(NULL != proxy->session_alive);
656 848
849 SPDY_set_cls_to_request(request, proxy);
850
657 proxy->request = request; 851 proxy->request = request;
852 proxy->is_with_body_data = more;
658 if(NULL == (proxy->headers = SPDY_name_value_create())) 853 if(NULL == (proxy->headers = SPDY_name_value_create()))
659 DIE("No memory"); 854 DIE("No memory");
660 855
@@ -703,6 +898,16 @@ standard_request_handler(void *cls,
703 898
704 if(glob_opt.curl_verbose) 899 if(glob_opt.curl_verbose)
705 CURL_SETOPT(proxy->curl_handle, CURLOPT_VERBOSE, 1); 900 CURL_SETOPT(proxy->curl_handle, CURLOPT_VERBOSE, 1);
901
902 if(0 == strcmp(SPDY_HTTP_METHOD_POST,method))
903 {
904 if(NULL == (proxy->curl_headers = curl_slist_append(proxy->curl_headers, "Expect:")))
905 DIE("curl_slist_append failed");
906 CURL_SETOPT(proxy->curl_handle, CURLOPT_POST, 1);
907 CURL_SETOPT(proxy->curl_handle, CURLOPT_READFUNCTION, curl_read_cb);
908 CURL_SETOPT(proxy->curl_handle, CURLOPT_READDATA, proxy);
909 }
910
706 if(glob_opt.timeout) 911 if(glob_opt.timeout)
707 CURL_SETOPT(proxy->curl_handle, CURLOPT_TIMEOUT, glob_opt.timeout); 912 CURL_SETOPT(proxy->curl_handle, CURLOPT_TIMEOUT, glob_opt.timeout);
708 CURL_SETOPT(proxy->curl_handle, CURLOPT_URL, proxy->url); 913 CURL_SETOPT(proxy->curl_handle, CURLOPT_URL, proxy->url);
@@ -720,7 +925,7 @@ standard_request_handler(void *cls,
720 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 925 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
721 else if(glob_opt.ipv6 && !glob_opt.ipv4) 926 else if(glob_opt.ipv6 && !glob_opt.ipv4)
722 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6); 927 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
723 928
724 if(CURLM_OK != (ret = curl_multi_add_handle(multi_handle, proxy->curl_handle))) 929 if(CURLM_OK != (ret = curl_multi_add_handle(multi_handle, proxy->curl_handle)))
725 { 930 {
726 PRINT_INFO2("curl_multi_add_handle failed (%i)", ret); 931 PRINT_INFO2("curl_multi_add_handle failed (%i)", ret);
@@ -765,7 +970,7 @@ run ()
765 struct addrinfo *gai; 970 struct addrinfo *gai;
766 enum SPDY_IO_SUBSYSTEM io = glob_opt.notls ? SPDY_IO_SUBSYSTEM_RAW : SPDY_IO_SUBSYSTEM_OPENSSL; 971 enum SPDY_IO_SUBSYSTEM io = glob_opt.notls ? SPDY_IO_SUBSYSTEM_RAW : SPDY_IO_SUBSYSTEM_OPENSSL;
767 enum SPDY_DAEMON_FLAG flags = SPDY_DAEMON_FLAG_NO; 972 enum SPDY_DAEMON_FLAG flags = SPDY_DAEMON_FLAG_NO;
768 struct SPDY_Response *error_response; 973 //struct SPDY_Response *error_response;
769 char *curl_private; 974 char *curl_private;
770 975
771 signal(SIGPIPE, SIG_IGN); 976 signal(SIGPIPE, SIG_IGN);
@@ -790,7 +995,7 @@ run ()
790 &new_session_cb, 995 &new_session_cb,
791 &session_closed_cb, 996 &session_closed_cb,
792 &standard_request_handler, 997 &standard_request_handler,
793 NULL, 998 &spdy_post_data_cb,
794 NULL, 999 NULL,
795 SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 1000 SPDY_DAEMON_OPTION_SESSION_TIMEOUT,
796 1800, 1001 1800,
@@ -819,7 +1024,7 @@ run ()
819 &new_session_cb, 1024 &new_session_cb,
820 &session_closed_cb, 1025 &session_closed_cb,
821 &standard_request_handler, 1026 &standard_request_handler,
822 NULL, 1027 &spdy_post_data_cb,
823 NULL, 1028 NULL,
824 SPDY_DAEMON_OPTION_SESSION_TIMEOUT, 1029 SPDY_DAEMON_OPTION_SESSION_TIMEOUT,
825 1800, 1030 1800,
@@ -924,6 +1129,7 @@ run ()
924 1129
925 while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { 1130 while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
926 if (msg->msg == CURLMSG_DONE) { 1131 if (msg->msg == CURLMSG_DONE) {
1132 PRINT_VERBOSE("A curl handler is done");
927 if(CURLE_OK != (ret = curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &curl_private))) 1133 if(CURLE_OK != (ret = curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &curl_private)))
928 { 1134 {
929 PRINT_INFO2("err %i",ret); 1135 PRINT_INFO2("err %i",ret);
@@ -944,7 +1150,7 @@ run ()
944 SPDY_name_value_destroy(proxy->headers); 1150 SPDY_name_value_destroy(proxy->headers);
945 if(!*(proxy->session_alive)) 1151 if(!*(proxy->session_alive))
946 { 1152 {
947 if(NULL == (error_response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY, 1153 /*if(NULL == (error_response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY,
948 NULL, 1154 NULL,
949 SPDY_HTTP_VERSION_1_1, 1155 SPDY_HTTP_VERSION_1_1,
950 NULL, 1156 NULL,
@@ -961,7 +1167,24 @@ run ()
961 //clean and forget 1167 //clean and forget
962 //TODO 1168 //TODO
963 DIE("no queue"); 1169 DIE("no queue");
964 } 1170 }*/
1171
1172 free(proxy->http_body);
1173 proxy->http_body = NULL;
1174
1175 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle)))
1176 {
1177 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
1178 }
1179 debug_num_curls--;
1180 curl_slist_free_all(proxy->curl_headers);
1181 curl_easy_cleanup(proxy->curl_handle);
1182
1183 SPDY_destroy_request(proxy->request);
1184 //SPDY_destroy_response(proxy->response);
1185 free(proxy->url);
1186 free(proxy);
1187
965 } 1188 }
966 else 1189 else
967 proxy->error = true; 1190 proxy->error = true;
diff --git a/src/testspdy/test_daemon_start_stop.c b/src/testspdy/test_daemon_start_stop.c
index 175e6365..8f572762 100644
--- a/src/testspdy/test_daemon_start_stop.c
+++ b/src/testspdy/test_daemon_start_stop.c
@@ -21,7 +21,7 @@
21 * @brief starts and stops a SPDY daemon 21 * @brief starts and stops a SPDY daemon
22 * @author Andrey Uzunov 22 * @author Andrey Uzunov
23 */ 23 */
24 24
25#include "platform.h" 25#include "platform.h"
26#include "microspdy.h" 26#include "microspdy.h"
27#include "common.h" 27#include "common.h"
diff --git a/src/testspdy/test_daemon_start_stop_many.c b/src/testspdy/test_daemon_start_stop_many.c
index 276f784c..c5db6050 100644
--- a/src/testspdy/test_daemon_start_stop_many.c
+++ b/src/testspdy/test_daemon_start_stop_many.c
@@ -21,7 +21,7 @@
21 * @brief starts and stops several SPDY daemons, reusing port numbers 21 * @brief starts and stops several SPDY daemons, reusing port numbers
22 * @author Andrey Uzunov 22 * @author Andrey Uzunov
23 */ 23 */
24 24
25#include "platform.h" 25#include "platform.h"
26#include "microspdy.h" 26#include "microspdy.h"
27#include "common.h" 27#include "common.h"
diff --git a/src/testspdy/test_misc.c b/src/testspdy/test_misc.c
index a39afa66..d8198061 100644
--- a/src/testspdy/test_misc.c
+++ b/src/testspdy/test_misc.c
@@ -21,7 +21,7 @@
21 * @brief tests a lot of small calls and callbacks. TODO mention what 21 * @brief tests a lot of small calls and callbacks. TODO mention what
22 * @author Andrey Uzunov 22 * @author Andrey Uzunov
23 */ 23 */
24 24
25#include "platform.h" 25#include "platform.h"
26#include "microspdy.h" 26#include "microspdy.h"
27#include "stdio.h" 27#include "stdio.h"
@@ -93,10 +93,14 @@ create_child()
93 93
94void 94void
95response_done_callback(void *cls, 95response_done_callback(void *cls,
96 struct SPDY_Response *response, 96 struct SPDY_Response * response,
97 struct SPDY_Request *request, 97 struct SPDY_Request * request,
98 enum SPDY_RESPONSE_RESULT status,
98 bool streamopened) 99 bool streamopened)
99{ 100{
101 (void)status;
102 (void)streamopened;
103
100 if(strcmp(cls,"/main.css")) 104 if(strcmp(cls,"/main.css"))
101 { 105 {
102 session1 = SPDY_get_session_for_request(request); 106 session1 = SPDY_get_session_for_request(request);
@@ -152,8 +156,19 @@ standard_request_handler(void *cls,
152 const char *version, 156 const char *version,
153 const char *host, 157 const char *host,
154 const char *scheme, 158 const char *scheme,
155 struct SPDY_NameValue * headers) 159 struct SPDY_NameValue * headers,
160 bool more)
156{ 161{
162 (void)cls;
163 (void)request;
164 (void)priority;
165 (void)host;
166 (void)scheme;
167 (void)headers;
168 (void)method;
169 (void)version;
170 (void)more;
171
157 struct SPDY_Response *response=NULL; 172 struct SPDY_Response *response=NULL;
158 char *cls_path = strdup(path); 173 char *cls_path = strdup(path);
159 174
@@ -259,7 +274,7 @@ parentproc()
259 274
260 275
261int 276int
262main(int argc, char **argv) 277main()
263{ 278{
264 port = get_port(13123); 279 port = get_port(13123);
265 SPDY_init(); 280 SPDY_init();
diff --git a/src/testspdy/test_new_connection.c b/src/testspdy/test_new_connection.c
index 1a9e47a4..b07a0e84 100644
--- a/src/testspdy/test_new_connection.c
+++ b/src/testspdy/test_new_connection.c
@@ -24,7 +24,7 @@
24 * @author Tatsuhiro Tsujikawa 24 * @author Tatsuhiro Tsujikawa
25 */ 25 */
26 26
27 //TODO child exits with ret val 1 sometimes 27//TODO child exits with ret val 1 sometimes
28 28
29#include "platform.h" 29#include "platform.h"
30#include "microspdy.h" 30#include "microspdy.h"
@@ -44,12 +44,17 @@ pid_t child;
44int 44int
45spdylay_printf(const char *format, ...) 45spdylay_printf(const char *format, ...)
46{ 46{
47 (void)format;
48
47 return 0; 49 return 0;
48} 50}
49 51
50int 52int
51spdylay_fprintf(FILE *stream, const char *format, ...) 53spdylay_fprintf(FILE *stream, const char *format, ...)
52{ 54{
55 (void)stream;
56 (void)format;
57
53 return 0; 58 return 0;
54} 59}
55 60
@@ -215,6 +220,9 @@ static ssize_t send_callback(spdylay_session *session,
215 const uint8_t *data, size_t length, int flags, 220 const uint8_t *data, size_t length, int flags,
216 void *user_data) 221 void *user_data)
217{ 222{
223 (void)session;
224 (void)flags;
225
218 struct Connection *connection; 226 struct Connection *connection;
219 ssize_t rv; 227 ssize_t rv;
220 connection = (struct Connection*)user_data; 228 connection = (struct Connection*)user_data;
@@ -244,6 +252,9 @@ static ssize_t recv_callback(spdylay_session *session,
244 uint8_t *buf, size_t length, int flags, 252 uint8_t *buf, size_t length, int flags,
245 void *user_data) 253 void *user_data)
246{ 254{
255 (void)session;
256 (void)flags;
257
247 struct Connection *connection; 258 struct Connection *connection;
248 ssize_t rv; 259 ssize_t rv;
249 connection = (struct Connection*)user_data; 260 connection = (struct Connection*)user_data;
@@ -276,6 +287,8 @@ static void before_ctrl_send_callback(spdylay_session *session,
276 spdylay_frame *frame, 287 spdylay_frame *frame,
277 void *user_data) 288 void *user_data)
278{ 289{
290 (void)user_data;
291
279 if(type == SPDYLAY_SYN_STREAM) { 292 if(type == SPDYLAY_SYN_STREAM) {
280 struct Request *req; 293 struct Request *req;
281 int stream_id = frame->syn_stream.stream_id; 294 int stream_id = frame->syn_stream.stream_id;
@@ -291,6 +304,8 @@ static void on_ctrl_send_callback(spdylay_session *session,
291 spdylay_frame_type type, 304 spdylay_frame_type type,
292 spdylay_frame *frame, void *user_data) 305 spdylay_frame *frame, void *user_data)
293{ 306{
307 (void)user_data;
308
294 char **nv; 309 char **nv;
295 const char *name = NULL; 310 const char *name = NULL;
296 int32_t stream_id; 311 int32_t stream_id;
@@ -316,6 +331,8 @@ static void on_ctrl_recv_callback(spdylay_session *session,
316 spdylay_frame_type type, 331 spdylay_frame_type type,
317 spdylay_frame *frame, void *user_data) 332 spdylay_frame *frame, void *user_data)
318{ 333{
334 (void)user_data;
335
319 struct Request *req; 336 struct Request *req;
320 char **nv; 337 char **nv;
321 const char *name = NULL; 338 const char *name = NULL;
@@ -359,6 +376,8 @@ static void on_stream_close_callback(spdylay_session *session,
359 spdylay_status_code status_code, 376 spdylay_status_code status_code,
360 void *user_data) 377 void *user_data)
361{ 378{
379 (void)user_data;
380 (void)status_code;
362 struct Request *req; 381 struct Request *req;
363 req = spdylay_session_get_stream_user_data(session, stream_id); 382 req = spdylay_session_get_stream_user_data(session, stream_id);
364 if(req) { 383 if(req) {
@@ -381,6 +400,9 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
381 const uint8_t *data, size_t len, 400 const uint8_t *data, size_t len,
382 void *user_data) 401 void *user_data)
383{ 402{
403 (void)user_data;
404 (void)flags;
405
384 struct Request *req; 406 struct Request *req;
385 req = spdylay_session_get_stream_user_data(session, stream_id); 407 req = spdylay_session_get_stream_user_data(session, stream_id);
386 if(req) { 408 if(req) {
@@ -441,6 +463,8 @@ static int select_next_proto_cb(SSL* ssl,
441 const unsigned char *in, unsigned int inlen, 463 const unsigned char *in, unsigned int inlen,
442 void *arg) 464 void *arg)
443{ 465{
466 (void)ssl;
467
444 int rv; 468 int rv;
445 uint16_t *spdy_proto_version; 469 uint16_t *spdy_proto_version;
446 /* spdylay_select_next_protocol() selects SPDY protocol version the 470 /* spdylay_select_next_protocol() selects SPDY protocol version the
@@ -799,7 +823,7 @@ new_session_callback (void *cls,
799{ 823{
800 char ipstr[1024]; 824 char ipstr[1024];
801 825
802 const struct sockaddr *addr; 826 struct sockaddr *addr;
803 socklen_t addr_len = SPDY_get_remote_addr(session, &addr); 827 socklen_t addr_len = SPDY_get_remote_addr(session, &addr);
804 828
805 if(!addr_len) 829 if(!addr_len)
@@ -955,7 +979,7 @@ parentproc(int child)
955 return 0; 979 return 0;
956} 980}
957 981
958int main(int argc, char **argv) 982int main()
959{ 983{
960 port = get_port(14123); 984 port = get_port(14123);
961 parent = getpid(); 985 parent = getpid();
diff --git a/src/testspdy/test_notls.c b/src/testspdy/test_notls.c
index ec42920e..566f0a74 100644
--- a/src/testspdy/test_notls.c
+++ b/src/testspdy/test_notls.c
@@ -199,6 +199,9 @@ static ssize_t send_callback(spdylay_session *session,
199 const uint8_t *data, size_t length, int flags, 199 const uint8_t *data, size_t length, int flags,
200 void *user_data) 200 void *user_data)
201{ 201{
202 (void)session;
203 (void)flags;
204
202 struct Connection *connection; 205 struct Connection *connection;
203 ssize_t rv; 206 ssize_t rv;
204 connection = (struct Connection*)user_data; 207 connection = (struct Connection*)user_data;
@@ -237,6 +240,9 @@ static ssize_t recv_callback(spdylay_session *session,
237 uint8_t *buf, size_t length, int flags, 240 uint8_t *buf, size_t length, int flags,
238 void *user_data) 241 void *user_data)
239{ 242{
243 (void)session;
244 (void)flags;
245
240 struct Connection *connection; 246 struct Connection *connection;
241 ssize_t rv; 247 ssize_t rv;
242 connection = (struct Connection*)user_data; 248 connection = (struct Connection*)user_data;
@@ -278,6 +284,8 @@ static void before_ctrl_send_callback(spdylay_session *session,
278 spdylay_frame *frame, 284 spdylay_frame *frame,
279 void *user_data) 285 void *user_data)
280{ 286{
287 (void)user_data;
288
281 if(type == SPDYLAY_SYN_STREAM) { 289 if(type == SPDYLAY_SYN_STREAM) {
282 struct Request *req; 290 struct Request *req;
283 int stream_id = frame->syn_stream.stream_id; 291 int stream_id = frame->syn_stream.stream_id;
@@ -293,6 +301,8 @@ static void on_ctrl_send_callback(spdylay_session *session,
293 spdylay_frame_type type, 301 spdylay_frame_type type,
294 spdylay_frame *frame, void *user_data) 302 spdylay_frame *frame, void *user_data)
295{ 303{
304 (void)user_data;
305
296 char **nv; 306 char **nv;
297 const char *name = NULL; 307 const char *name = NULL;
298 int32_t stream_id; 308 int32_t stream_id;
@@ -318,6 +328,8 @@ static void on_ctrl_recv_callback(spdylay_session *session,
318 spdylay_frame_type type, 328 spdylay_frame_type type,
319 spdylay_frame *frame, void *user_data) 329 spdylay_frame *frame, void *user_data)
320{ 330{
331 (void)user_data;
332
321 struct Request *req; 333 struct Request *req;
322 char **nv; 334 char **nv;
323 const char *name = NULL; 335 const char *name = NULL;
@@ -361,6 +373,9 @@ static void on_stream_close_callback(spdylay_session *session,
361 spdylay_status_code status_code, 373 spdylay_status_code status_code,
362 void *user_data) 374 void *user_data)
363{ 375{
376 (void)status_code;
377 (void)user_data;
378
364 struct Request *req; 379 struct Request *req;
365 req = spdylay_session_get_stream_user_data(session, stream_id); 380 req = spdylay_session_get_stream_user_data(session, stream_id);
366 if(req) { 381 if(req) {
@@ -383,6 +398,9 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
383 const uint8_t *data, size_t len, 398 const uint8_t *data, size_t len,
384 void *user_data) 399 void *user_data)
385{ 400{
401 (void)flags;
402 (void)user_data;
403
386 struct Request *req; 404 struct Request *req;
387 req = spdylay_session_get_stream_user_data(session, stream_id); 405 req = spdylay_session_get_stream_user_data(session, stream_id);
388 if(req) { 406 if(req) {
@@ -743,8 +761,19 @@ standard_request_handler(void *cls,
743 const char *version, 761 const char *version,
744 const char *host, 762 const char *host,
745 const char *scheme, 763 const char *scheme,
746 struct SPDY_NameValue * headers) 764 struct SPDY_NameValue * headers,
765 bool more)
747{ 766{
767 (void)cls;
768 (void)request;
769 (void)priority;
770 (void)host;
771 (void)scheme;
772 (void)headers;
773 (void)method;
774 (void)version;
775 (void)more;
776
748 struct SPDY_Response *response=NULL; 777 struct SPDY_Response *response=NULL;
749 778
750 if(strcmp(CLS,cls)!=0) 779 if(strcmp(CLS,cls)!=0)
@@ -818,9 +847,6 @@ childproc(int port)
818 if(NULL == (rcvbuf = malloc(strlen(RESPONSE_BODY)+1))) 847 if(NULL == (rcvbuf = malloc(strlen(RESPONSE_BODY)+1)))
819 killparent(parent,"no memory"); 848 killparent(parent,"no memory");
820 849
821 SSL_load_error_strings();
822 SSL_library_init();
823
824 rv = parse_uri(&uri, uristr); 850 rv = parse_uri(&uri, uristr);
825 if(rv != 0) { 851 if(rv != 0) {
826 killparent(parent,"parse_uri failed"); 852 killparent(parent,"parse_uri failed");
@@ -912,7 +938,7 @@ parentproc( int port)
912 return WEXITSTATUS(childstatus); 938 return WEXITSTATUS(childstatus);
913} 939}
914 940
915int main(int argc, char **argv) 941int main()
916{ 942{
917 int port = get_port(12123); 943 int port = get_port(12123);
918 parent = getpid(); 944 parent = getpid();
diff --git a/src/testspdy/test_request_response.c b/src/testspdy/test_request_response.c
index 6c311be3..07ed236b 100644
--- a/src/testspdy/test_request_response.c
+++ b/src/testspdy/test_request_response.c
@@ -23,7 +23,7 @@
23 * @author Andrey Uzunov 23 * @author Andrey Uzunov
24 * @author Tatsuhiro Tsujikawa 24 * @author Tatsuhiro Tsujikawa
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "microspdy.h" 28#include "microspdy.h"
29#include <sys/wait.h> 29#include <sys/wait.h>
@@ -202,6 +202,9 @@ static ssize_t send_callback(spdylay_session *session,
202 const uint8_t *data, size_t length, int flags, 202 const uint8_t *data, size_t length, int flags,
203 void *user_data) 203 void *user_data)
204{ 204{
205 (void)session;
206 (void)flags;
207
205 struct Connection *connection; 208 struct Connection *connection;
206 ssize_t rv; 209 ssize_t rv;
207 connection = (struct Connection*)user_data; 210 connection = (struct Connection*)user_data;
@@ -231,6 +234,9 @@ static ssize_t recv_callback(spdylay_session *session,
231 uint8_t *buf, size_t length, int flags, 234 uint8_t *buf, size_t length, int flags,
232 void *user_data) 235 void *user_data)
233{ 236{
237 (void)session;
238 (void)flags;
239
234 struct Connection *connection; 240 struct Connection *connection;
235 ssize_t rv; 241 ssize_t rv;
236 connection = (struct Connection*)user_data; 242 connection = (struct Connection*)user_data;
@@ -263,6 +269,8 @@ static void before_ctrl_send_callback(spdylay_session *session,
263 spdylay_frame *frame, 269 spdylay_frame *frame,
264 void *user_data) 270 void *user_data)
265{ 271{
272 (void)user_data;
273
266 if(type == SPDYLAY_SYN_STREAM) { 274 if(type == SPDYLAY_SYN_STREAM) {
267 struct Request *req; 275 struct Request *req;
268 int stream_id = frame->syn_stream.stream_id; 276 int stream_id = frame->syn_stream.stream_id;
@@ -278,6 +286,8 @@ static void on_ctrl_send_callback(spdylay_session *session,
278 spdylay_frame_type type, 286 spdylay_frame_type type,
279 spdylay_frame *frame, void *user_data) 287 spdylay_frame *frame, void *user_data)
280{ 288{
289 (void)user_data;
290
281 char **nv; 291 char **nv;
282 const char *name = NULL; 292 const char *name = NULL;
283 int32_t stream_id; 293 int32_t stream_id;
@@ -303,6 +313,8 @@ static void on_ctrl_recv_callback(spdylay_session *session,
303 spdylay_frame_type type, 313 spdylay_frame_type type,
304 spdylay_frame *frame, void *user_data) 314 spdylay_frame *frame, void *user_data)
305{ 315{
316 (void)user_data;
317
306 struct Request *req; 318 struct Request *req;
307 char **nv; 319 char **nv;
308 const char *name = NULL; 320 const char *name = NULL;
@@ -346,6 +358,9 @@ static void on_stream_close_callback(spdylay_session *session,
346 spdylay_status_code status_code, 358 spdylay_status_code status_code,
347 void *user_data) 359 void *user_data)
348{ 360{
361 (void)user_data;
362 (void)status_code;
363
349 struct Request *req; 364 struct Request *req;
350 req = spdylay_session_get_stream_user_data(session, stream_id); 365 req = spdylay_session_get_stream_user_data(session, stream_id);
351 if(req) { 366 if(req) {
@@ -368,6 +383,9 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
368 const uint8_t *data, size_t len, 383 const uint8_t *data, size_t len,
369 void *user_data) 384 void *user_data)
370{ 385{
386 (void)user_data;
387 (void)flags;
388
371 struct Request *req; 389 struct Request *req;
372 req = spdylay_session_get_stream_user_data(session, stream_id); 390 req = spdylay_session_get_stream_user_data(session, stream_id);
373 if(req) { 391 if(req) {
@@ -433,6 +451,8 @@ static int select_next_proto_cb(SSL* ssl,
433 const unsigned char *in, unsigned int inlen, 451 const unsigned char *in, unsigned int inlen,
434 void *arg) 452 void *arg)
435{ 453{
454 (void)ssl;
455
436 int rv; 456 int rv;
437 uint16_t *spdy_proto_version; 457 uint16_t *spdy_proto_version;
438 /* spdylay_select_next_protocol() selects SPDY protocol version the 458 /* spdylay_select_next_protocol() selects SPDY protocol version the
@@ -795,15 +815,30 @@ standard_request_handler(void *cls,
795 const char *version, 815 const char *version,
796 const char *host, 816 const char *host,
797 const char *scheme, 817 const char *scheme,
798 struct SPDY_NameValue * headers) 818 struct SPDY_NameValue * headers,
819 bool more)
799{ 820{
821 (void)cls;
822 (void)request;
823 (void)priority;
824 (void)host;
825 (void)scheme;
826 (void)headers;
827 (void)method;
828 (void)version;
829
800 struct SPDY_Response *response=NULL; 830 struct SPDY_Response *response=NULL;
801 831
802 if(strcmp(CLS,cls)!=0) 832 if(strcmp(CLS,cls)!=0)
803 { 833 {
804 killchild(child,"wrong cls"); 834 killchild(child,"wrong cls");
805 } 835 }
806 836
837 if(false != more){
838 fprintf(stdout,"more has wrong value\n");
839 exit(5);
840 }
841
807 response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY)); 842 response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY));
808 843
809 if(NULL==response){ 844 if(NULL==response){
@@ -961,7 +996,7 @@ parentproc( int port)
961 return WEXITSTATUS(childstatus); 996 return WEXITSTATUS(childstatus);
962} 997}
963 998
964int main(int argc, char **argv) 999int main()
965{ 1000{
966 int port = get_port(12123); 1001 int port = get_port(12123);
967 parent = getpid(); 1002 parent = getpid();
diff --git a/src/testspdy/test_request_response_with_callback.c b/src/testspdy/test_request_response_with_callback.c
index 6eed8eba..7cc4f7ac 100644
--- a/src/testspdy/test_request_response_with_callback.c
+++ b/src/testspdy/test_request_response_with_callback.c
@@ -21,7 +21,7 @@
21 * @brief tests responses with callbacks 21 * @brief tests responses with callbacks
22 * @author Andrey Uzunov 22 * @author Andrey Uzunov
23 */ 23 */
24 24
25#include "platform.h" 25#include "platform.h"
26#include "microspdy.h" 26#include "microspdy.h"
27#include "stdio.h" 27#include "stdio.h"
@@ -85,10 +85,14 @@ response_callback (void *cls,
85 85
86void 86void
87response_done_callback(void *cls, 87response_done_callback(void *cls,
88 struct SPDY_Response *response, 88 struct SPDY_Response * response,
89 struct SPDY_Request *request, 89 struct SPDY_Request * request,
90 enum SPDY_RESPONSE_RESULT status,
90 bool streamopened) 91 bool streamopened)
91{ 92{
93 (void)status;
94 (void)streamopened;
95
92 printf("answer for %s was sent\n", (char*)cls); 96 printf("answer for %s was sent\n", (char*)cls);
93 97
94 SPDY_destroy_request(request); 98 SPDY_destroy_request(request);
@@ -107,8 +111,19 @@ standard_request_handler(void *cls,
107 const char *version, 111 const char *version,
108 const char *host, 112 const char *host,
109 const char *scheme, 113 const char *scheme,
110 struct SPDY_NameValue * headers) 114 struct SPDY_NameValue * headers,
115 bool more)
111{ 116{
117 (void)cls;
118 (void)request;
119 (void)priority;
120 (void)host;
121 (void)scheme;
122 (void)headers;
123 (void)method;
124 (void)version;
125 (void)more;
126
112 struct SPDY_Response *response=NULL; 127 struct SPDY_Response *response=NULL;
113 struct SPDY_NameValue *resp_headers; 128 struct SPDY_NameValue *resp_headers;
114 129
@@ -271,7 +286,7 @@ childproc()
271 if(0 == ret && 0 == stat(DATA_DIR "spdy-draft.txt", &st)) 286 if(0 == ret && 0 == stat(DATA_DIR "spdy-draft.txt", &st))
272 { 287 {
273 usecs = (uint64_t)1000000 * (uint64_t)(tv2.tv_sec - tv1.tv_sec) + tv2.tv_usec - tv1.tv_usec; 288 usecs = (uint64_t)1000000 * (uint64_t)(tv2.tv_sec - tv1.tv_sec) + tv2.tv_usec - tv1.tv_usec;
274 printf("%i bytes read in %i usecs\n", st.st_size, usecs); 289 printf("%lld bytes read in %llu usecs\n", (long long)st.st_size, (long long unsigned )usecs);
275 } 290 }
276 291
277 return ret; 292 return ret;
@@ -279,7 +294,7 @@ childproc()
279 294
280 295
281int 296int
282main(int argc, char **argv) 297main()
283{ 298{
284 port = get_port(11123); 299 port = get_port(11123);
285 parent = getpid(); 300 parent = getpid();
diff --git a/src/testspdy/test_requests_with_assets.c b/src/testspdy/test_requests_with_assets.c
index 6ec927e8..90869278 100644
--- a/src/testspdy/test_requests_with_assets.c
+++ b/src/testspdy/test_requests_with_assets.c
@@ -23,7 +23,7 @@
23 * libxml2. 23 * libxml2.
24 * @author Andrey Uzunov 24 * @author Andrey Uzunov
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "microspdy.h" 28#include "microspdy.h"
29#include "common.h" 29#include "common.h"
@@ -133,8 +133,19 @@ standard_request_handler(void *cls,
133 const char *version, 133 const char *version,
134 const char *host, 134 const char *host,
135 const char *scheme, 135 const char *scheme,
136 struct SPDY_NameValue * headers) 136 struct SPDY_NameValue * headers,
137 bool more)
137{ 138{
139 (void)cls;
140 (void)request;
141 (void)priority;
142 (void)host;
143 (void)scheme;
144 (void)headers;
145 (void)method;
146 (void)version;
147 (void)more;
148
138 struct SPDY_Response *response; 149 struct SPDY_Response *response;
139 150
140 if(NULL != strstr(path,".css")) 151 if(NULL != strstr(path,".css"))
@@ -279,7 +290,7 @@ parentproc()
279 return html_resp_count != html_req_count; 290 return html_resp_count != html_req_count;
280} 291}
281 292
282int main(int argc, char **argv) 293int main()
283{ 294{
284 parent = getpid(); 295 parent = getpid();
285 port = get_port(10123); 296 port = get_port(10123);
diff --git a/src/testspdy/test_session_timeout.c b/src/testspdy/test_session_timeout.c
index 66872d72..a89933b4 100644
--- a/src/testspdy/test_session_timeout.c
+++ b/src/testspdy/test_session_timeout.c
@@ -22,7 +22,7 @@
22 * client 22 * client
23 * @author Andrey Uzunov 23 * @author Andrey Uzunov
24 */ 24 */
25 25
26#include "platform.h" 26#include "platform.h"
27#include "microspdy.h" 27#include "microspdy.h"
28#include "stdio.h" 28#include "stdio.h"
@@ -66,6 +66,9 @@ void
66new_session_cb (void *cls, 66new_session_cb (void *cls,
67 struct SPDY_Session * session) 67 struct SPDY_Session * session)
68{ 68{
69 (void)cls;
70 (void)session;
71
69 if(!new_session)do_sleep = 1; 72 if(!new_session)do_sleep = 1;
70 new_session = 1; 73 new_session = 1;
71 printf("new session\n"); 74 printf("new session\n");
@@ -76,6 +79,9 @@ closed_session_cb (void *cls,
76 struct SPDY_Session * session, 79 struct SPDY_Session * session,
77 int by_client) 80 int by_client)
78{ 81{
82 (void)cls;
83 (void)session;
84
79 printf("closed_session_cb called\n"); 85 printf("closed_session_cb called\n");
80 86
81 if(SPDY_YES == by_client) 87 if(SPDY_YES == by_client)
@@ -150,20 +156,20 @@ parentproc()
150 killchild("clock_gettime returned wrong value"); 156 killchild("clock_gettime returned wrong value");
151 if(now - beginning > TIMEOUT*1000 + SELECT_MS_TIMEOUT) 157 if(now - beginning > TIMEOUT*1000 + SELECT_MS_TIMEOUT)
152 { 158 {
153 printf("Started at: %ims\n",beginning); 159 printf("Started at: %llums\n",beginning);
154 printf("Now is: %ims\n",now); 160 printf("Now is: %llums\n",now);
155 printf("Timeout is: %i\n",TIMEOUT); 161 printf("Timeout is: %i\n",TIMEOUT);
156 printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT); 162 printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT);
157 printf("SPDY_get_timeout gave: %ims\n",timeoutlong); 163 printf("SPDY_get_timeout gave: %llums\n",timeoutlong);
158 killchild("Timeout passed but session was not closed"); 164 killchild("Timeout passed but session was not closed");
159 } 165 }
160 if(timeoutlong > beginning + TIMEOUT *1000) 166 if(timeoutlong > beginning + TIMEOUT *1000)
161 { 167 {
162 printf("Started at: %ims\n",beginning); 168 printf("Started at: %llums\n",beginning);
163 printf("Now is: %ims\n",now); 169 printf("Now is: %llums\n",now);
164 printf("Timeout is: %i\n",TIMEOUT); 170 printf("Timeout is: %i\n",TIMEOUT);
165 printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT); 171 printf("Select Timeout is: %ims\n",SELECT_MS_TIMEOUT);
166 printf("SPDY_get_timeout gave: %ims\n",timeoutlong); 172 printf("SPDY_get_timeout gave: %llums\n",timeoutlong);
167 killchild("SPDY_get_timeout returned wrong timeout"); 173 killchild("SPDY_get_timeout returned wrong timeout");
168 } 174 }
169 } 175 }
@@ -210,10 +216,12 @@ parentproc()
210 default: 216 default:
211 SPDY_run(daemon); 217 SPDY_run(daemon);
212 if(0 == beginning) 218 if(0 == beginning)
213 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 219 {
214 beginning = ts.tv_nsec / 1000000 + ts.tv_sec*1000; 220 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
215 else 221 beginning = ts.tv_nsec / 1000000 + ts.tv_sec*1000;
216 killchild("clock_gettime returned wrong number"); 222 else
223 killchild("clock_gettime returned wrong number");
224 }
217 /*if(do_sleep) 225 /*if(do_sleep)
218 { 226 {
219 sleep(TIMEOUT); 227 sleep(TIMEOUT);
@@ -283,7 +291,7 @@ childproc()
283 291
284 292
285int 293int
286main(int argc, char **argv) 294main()
287{ 295{
288 port = get_port(11123); 296 port = get_port(11123);
289 parent = getpid(); 297 parent = getpid();
diff --git a/src/testspdy/test_struct_namevalue.c b/src/testspdy/test_struct_namevalue.c
index fb912bfa..dbd60e5b 100644
--- a/src/testspdy/test_struct_namevalue.c
+++ b/src/testspdy/test_struct_namevalue.c
@@ -37,6 +37,7 @@ int size2;
37int brake_at = 3; 37int brake_at = 3;
38bool flag; 38bool flag;
39 39
40
40int 41int
41iterate_cb (void *cls, const char *name, const char * const * value, int num_values) 42iterate_cb (void *cls, const char *name, const char * const * value, int num_values)
42{ 43{
@@ -68,6 +69,10 @@ iterate_cb (void *cls, const char *name, const char * const * value, int num_val
68int 69int
69iterate_brake_cb (void *cls, const char *name, const char * const *value, int num_values) 70iterate_brake_cb (void *cls, const char *name, const char * const *value, int num_values)
70{ 71{
72 (void)name;
73 (void)value;
74 (void)num_values;
75
71 int *c = (int*)cls; 76 int *c = (int*)cls;
72 77
73 if(*c < 0 || *c >= brake_at) 78 if(*c < 0 || *c >= brake_at)
@@ -102,7 +107,7 @@ main()
102 struct SPDY_NameValue *container; 107 struct SPDY_NameValue *container;
103 struct SPDY_NameValue *container2; 108 struct SPDY_NameValue *container2;
104 struct SPDY_NameValue *container3; 109 struct SPDY_NameValue *container3;
105 struct SPDY_NameValue *container_arr[1]; 110 struct SPDY_NameValue *container_arr[2];
106 111
107 size = sizeof(pairs)/sizeof(pairs[0]); 112 size = sizeof(pairs)/sizeof(pairs[0]);
108 113
@@ -144,7 +149,7 @@ main()
144 value = SPDY_name_value_lookup(container,pairs[i], &ret); 149 value = SPDY_name_value_lookup(container,pairs[i], &ret);
145 if(NULL == value || 1 !=ret || strcmp(value[0], pairs[i+1]) != 0) 150 if(NULL == value || 1 !=ret || strcmp(value[0], pairs[i+1]) != 0)
146 { 151 {
147 printf("%i; %i; %i\n", value, ret, strcmp(value[0], pairs[i+1])); 152 printf("%p; %i; %i\n", value, ret, strcmp(value[0], pairs[i+1]));
148 FAIL_TEST("SPDY_name_value_lookup failed\n"); 153 FAIL_TEST("SPDY_name_value_lookup failed\n");
149 } 154 }
150 } 155 }
@@ -251,7 +256,7 @@ main()
251 value = SPDY_name_value_lookup(container,pairs_with_empty[i], &ret); 256 value = SPDY_name_value_lookup(container,pairs_with_empty[i], &ret);
252 if(NULL == value || 1 != ret) 257 if(NULL == value || 1 != ret)
253 { 258 {
254 printf("%i; %i\n", value, ret); 259 printf("%p; %i\n", value, ret);
255 FAIL_TEST("SPDY_name_value_lookup failed\n"); 260 FAIL_TEST("SPDY_name_value_lookup failed\n");
256 } 261 }
257 } 262 }