GNU libmicrohttpd
0.9.29
Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
structures.h
Go to the documentation of this file.
1
/*
2
This file is part of libmicrospdy
3
Copyright (C) 2012 Andrey Uzunov
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
26
#ifndef STRUCTURES_H
27
#define STRUCTURES_H
28
29
#include "
platform.h
"
30
#include "
microspdy.h
"
31
#include "
io.h
"
32
33
38
enum
SPDY_CONTROL_FRAME_TYPES
39
{
44
SPDY_CONTROL_FRAME_TYPES_SYN_STREAM
= 1,
45
50
SPDY_CONTROL_FRAME_TYPES_SYN_REPLY
= 2,
51
59
SPDY_CONTROL_FRAME_TYPES_RST_STREAM
= 3,
60
70
SPDY_CONTROL_FRAME_TYPES_SETTINGS
= 4,
71
80
SPDY_CONTROL_FRAME_TYPES_PING
= 6,
81
87
SPDY_CONTROL_FRAME_TYPES_GOAWAY
= 7,
88
96
SPDY_CONTROL_FRAME_TYPES_HEADERS
= 8,
97
106
SPDY_CONTROL_FRAME_TYPES_WINDOW_UPDATE
= 9,
107
120
SPDY_CONTROL_FRAME_TYPES_CREDENTIAL
= 11
121
};
122
123
129
enum
SPDY_SESSION_STATUS
130
{
135
SPDY_SESSION_STATUS_CLOSING
= 0,
136
140
SPDY_SESSION_STATUS_WAIT_FOR_HEADER
= 1,
141
147
SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER
= 2,
148
153
SPDY_SESSION_STATUS_WAIT_FOR_BODY
= 3,
154
158
SPDY_SESSION_STATUS_IGNORE_BYTES
= 4,
159
165
SPDY_SESSION_STATUS_FLUSHING
= 5,
166
};
167
168
172
enum
SPDY_SYN_STREAM_FLAG
173
{
177
SPDY_SYN_STREAM_FLAG_FIN
= 1,
178
182
SPDY_SYN_STREAM_FLAG_UNIDIRECTIONAL
= 2
183
};
184
185
189
enum
SPDY_SYN_REPLY_FLAG
190
{
194
SPDY_SYN_REPLY_FLAG_FIN
= 1
195
};
196
197
201
enum
SPDY_DATA_FLAG
202
{
206
SPDY_DATA_FLAG_FIN
= 1,
207
213
SPDY_DATA_FLAG_COMPRESS
= 2
214
};
215
219
enum
SPDY_RST_STREAM_STATUS
220
{
225
SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR
= 1,
226
231
SPDY_RST_STREAM_STATUS_INVALID_STREAM
= 2,
232
237
SPDY_RST_STREAM_STATUS_REFUSED_STREAM
= 3,
238
243
SPDY_RST_STREAM_STATUS_UNSUPPORTED_VERSION
= 4,
244
249
SPDY_RST_STREAM_STATUS_CANCEL
= 5,
250
255
SPDY_RST_STREAM_STATUS_INTERNAL_ERROR
= 6,
256
261
SPDY_RST_STREAM_STATUS_FLOW_CONTROL_ERROR
= 7,
262
266
SPDY_RST_STREAM_STATUS_STREAM_IN_USE
= 8,
267
272
SPDY_RST_STREAM_STATUS_STREAM_ALREADY_CLOSED
= 9,
273
278
SPDY_RST_STREAM_STATUS_INVALID_CREDENTIALS
= 10,
279
288
SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE
= 11
289
};
290
291
295
enum
SPDY_GOAWAY_STATUS
296
{
300
SPDY_GOAWAY_STATUS_OK
= 0,
301
306
SPDY_GOAWAY_STATUS_PROTOCOL_ERROR
= 1,
307
312
SPDY_GOAWAY_STATUS_INTERNAL_ERROR
= 11
313
};
314
315
316
struct
SPDYF_Stream
;
317
318
struct
SPDYF_Response_Queue
;
319
320
334
typedef
int
335
(*
SPDYF_NewDataCallback
) (
void
* cls,
336
struct
SPDYF_Stream
*stream,
337
const
void
* buf,
338
size_t
size,
339
bool
more);
340
341
351
typedef
int
352
(*
SPDYF_NewStreamCallback
) (
void
*
cls
,
353
struct
SPDYF_Stream
* stream);
354
355
369
typedef
void
370
(*
SPDYF_ResponseQueueResultCallback
) (
void
*
cls
,
371
struct
SPDYF_Response_Queue
*response_queue,
372
enum
SPDY_RESPONSE_RESULT
status);
373
374
379
struct
__attribute__
((__packed__)) SPDYF_Control_Frame
380
{
381
uint16_t version : 15;
382
uint16_t control_bit : 1;
/* always 1 for control frames */
383
uint16_t type;
384
uint32_t flags : 8;
385
uint32_t length : 24;
386
};
387
388
392
struct
__attribute__
((__packed__)) SPDYF_Data_Frame
393
{
394
uint32_t stream_id : 31;
395
uint32_t control_bit : 1;
/* always 0 for data frames */
396
uint32_t flags : 8;
397
uint32_t length : 24;
398
};
399
400
404
struct
SPDYF_Response_Queue
405
{
409
struct
SPDYF_Response_Queue
*
next
;
410
414
struct
SPDYF_Response_Queue
*
prev
;
415
419
struct
SPDYF_Stream
*
stream
;
420
424
struct
SPDY_Response
*
response
;
425
430
struct
SPDYF_Control_Frame *
control_frame
;
431
436
struct
SPDYF_Data_Frame *
data_frame
;
437
441
void
*
data
;
442
446
int (*
process_response_handler
)(
struct
SPDY_Session
*session);
447
452
SPDYF_ResponseQueueResultCallback
frqcb
;
453
457
void
*
frqcb_cls
;
458
462
SPDY_ResponseResultCallback
rrcb
;
463
467
void
*
rrcb_cls
;
468
472
size_t
data_size
;
473
478
bool
is_data
;
479
};
480
481
482
486
struct
SPDY_NameValue
487
{
491
struct
SPDY_NameValue
*
next
;
492
496
struct
SPDY_NameValue
*
prev
;
497
501
char
*
name
;
502
507
char
**
value
;
508
512
unsigned
int
num_values
;
513
};
514
515
519
struct
SPDYF_Stream
520
{
524
struct
SPDYF_Stream
*
next
;
525
529
struct
SPDYF_Stream
*
prev
;
530
534
struct
SPDY_Session
*
session
;
535
539
struct
SPDY_NameValue
*
headers
;
540
544
void
*
cls
;
545
549
uint32_t
stream_id
;
550
554
uint32_t
assoc_stream_id
;
555
559
uint32_t
window_size
;
560
564
uint8_t
priority
;
565
571
uint8_t
slot
;
572
576
bool
flag_unidirectional
;
577
583
bool
is_in_closed
;
584
590
bool
is_out_closed
;
591
595
bool
is_server_initiator
;
596
};
597
598
602
struct
SPDY_Session
603
{
610
z_stream
zlib_recv_stream
;
611
618
z_stream
zlib_send_stream
;
619
623
struct
SPDY_Session
*
next
;
624
628
struct
SPDY_Session
*
prev
;
629
633
struct
SPDY_Daemon
*
daemon
;
634
638
struct
sockaddr *
addr
;
639
644
struct
SPDYF_Stream
*
streams_head
;
645
649
struct
SPDYF_Stream
*
streams_tail
;
650
655
void
*
io_context
;
656
660
struct
SPDYF_Response_Queue
*
response_queue_head
;
661
665
struct
SPDYF_Response_Queue
*
response_queue_tail
;
666
670
void
*
read_buffer
;
671
675
void
*
write_buffer
;
676
680
void (*
frame_handler
) (
struct
SPDY_Session
* session);
681
685
void
*
frame_handler_cls
;
686
691
void
*
user_cls
;
692
696
SPDYF_IONewSession
fio_new_session
;
697
701
SPDYF_IOCloseSession
fio_close_session
;
702
706
SPDYF_IORecv
fio_recv
;
707
711
SPDYF_IOSend
fio_send
;
712
716
SPDYF_IOIsPending
fio_is_pending
;
717
721
SPDYF_IOBeforeWrite
fio_before_write
;
722
726
SPDYF_IOAfterWrite
fio_after_write
;
727
734
size_t
read_ignore_bytes
;
735
742
size_t
read_buffer_size
;
743
748
size_t
read_buffer_offset
;
749
753
size_t
read_buffer_beginning
;
754
759
size_t
write_buffer_size
;
760
765
size_t
write_buffer_offset
;
766
770
size_t
write_buffer_beginning
;
771
776
unsigned
long
long
last_activity
;
777
783
int
socket_fd
;
784
788
socklen_t
addr_len
;
789
794
uint32_t
last_in_stream_id
;
795
800
uint32_t
last_out_stream_id
;
801
809
uint32_t
last_replied_to_stream_id
;
810
816
uint32_t
current_stream_id
;
817
825
uint32_t
max_num_frames
;
826
831
enum
SPDY_SESSION_STATUS
status
;
832
840
bool
read_closed
;
841
846
bool
is_goaway_sent
;
847
853
bool
is_goaway_received
;
854
};
855
856
860
struct
SPDY_Daemon
861
{
862
866
struct
SPDY_Session
*
sessions_head
;
867
871
struct
SPDY_Session
*
sessions_tail
;
872
876
struct
SPDY_Session
*
cleanup_head
;
877
881
struct
SPDY_Session
*
cleanup_tail
;
882
886
void
*
io_context
;
887
891
char
*
certfile
;
892
897
char
*
keyfile
;
898
899
903
struct
sockaddr *
address
;
904
909
SPDY_NewSessionCallback
new_session_cb
;
910
914
SPDY_SessionClosedCallback
session_closed_cb
;
915
919
SPDY_NewRequestCallback
new_request_cb
;
920
925
SPDY_NewDataCallback
received_data_cb
;
926
930
SPDYF_NewDataCallback
freceived_data_cb
;
931
935
void
*
cls
;
936
940
SPDYF_NewStreamCallback
fnew_stream_cb
;
941
945
void
*
fcls
;
946
950
SPDYF_IOInit
fio_init
;
951
955
SPDYF_IODeinit
fio_deinit
;
956
961
unsigned
long
long
session_timeout
;
962
966
int
socket_fd
;
967
976
uint32_t
max_num_frames
;
977
981
enum
SPDY_DAEMON_OPTION
options
;
982
986
enum
SPDY_DAEMON_FLAG
flags
;
987
991
enum
SPDY_IO_SUBSYSTEM
io_subsystem
;
992
996
uint16_t
port
;
997
};
998
999
1003
struct
SPDY_Response
1004
{
1009
void
*
headers
;
1010
1015
void
*
data
;
1016
1022
SPDY_ResponseCallback
rcb
;
1023
1027
void
*
rcb_cls
;
1028
1032
size_t
headers_size
;
1033
1037
size_t
data_size
;
1038
1044
uint32_t
rcb_block_size
;
1045
};
1046
1047
1048
/* Macros for handling data and structures */
1049
1050
1059
#define DLL_insert(head,tail,element) do { \
1060
(element)->next = (head); \
1061
(element)->prev = NULL; \
1062
if ((tail) == NULL) \
1063
(tail) = element; \
1064
else \
1065
(head)->prev = element; \
1066
(head) = (element); } while (0)
1067
1068
1078
#define DLL_remove(head,tail,element) do { \
1079
if ((element)->prev == NULL) \
1080
(head) = (element)->next; \
1081
else \
1082
(element)->prev->next = (element)->next; \
1083
if ((element)->next == NULL) \
1084
(tail) = (element)->prev; \
1085
else \
1086
(element)->next->prev = (element)->prev; \
1087
(element)->next = NULL; \
1088
(element)->prev = NULL; } while (0)
1089
1090
1097
#if HAVE_BIG_ENDIAN
1098
#define SPDYF_CONTROL_FRAME_HTON(frame)
1099
#else
1100
#define SPDYF_CONTROL_FRAME_HTON(frame) do { \
1101
(*((uint16_t *) frame )) = (*((uint8_t *) (frame) +1 )) | ((*((uint8_t *) frame ))<<8);\
1102
(frame)->type = htons((frame)->type); \
1103
(frame)->length = HTON24((frame)->length); \
1104
} while (0)
1105
#endif
1106
1107
1114
#if HAVE_BIG_ENDIAN
1115
#define SPDYF_CONTROL_FRAME_NTOH(frame)
1116
#else
1117
#define SPDYF_CONTROL_FRAME_NTOH(frame) do { \
1118
(*((uint16_t *) frame )) = (*((uint8_t *) (frame) +1 )) | ((*((uint8_t *) frame ))<<8);\
1119
(frame)->type = ntohs((frame)->type); \
1120
(frame)->length = NTOH24((frame)->length); \
1121
} while (0)
1122
#endif
1123
1124
1131
#if HAVE_BIG_ENDIAN
1132
#define SPDYF_DATA_FRAME_HTON(frame)
1133
#else
1134
#define SPDYF_DATA_FRAME_HTON(frame) do { \
1135
*((uint32_t *) frame ) = htonl(*((uint32_t *) frame ));\
1136
(frame)->length = HTON24((frame)->length); \
1137
} while (0)
1138
#endif
1139
1140
1147
#if HAVE_BIG_ENDIAN
1148
#define SPDYF_DATA_FRAME_NTOH(frame)
1149
#else
1150
#define SPDYF_DATA_FRAME_NTOH(frame) do { \
1151
*((uint32_t *) frame ) = ntohl(*((uint32_t *) frame ));\
1152
(frame)->length = NTOH24((frame)->length); \
1153
} while (0)
1154
#endif
1155
1156
1178
struct
SPDYF_Response_Queue
*
1179
SPDYF_response_queue_create
(
bool
is_data
,
1180
void
*
data
,
1181
size_t
data_size
,
1182
struct
SPDY_Response
*
response
,
1183
struct
SPDYF_Stream
*stream,
1184
bool
closestream,
1185
SPDYF_ResponseQueueResultCallback
frqcb
,
1186
void
*
frqcb_cls
,
1187
SPDY_ResponseResultCallback
rrcb
,
1188
void
*
rrcb_cls
);
1189
1190
1196
void
1197
SPDYF_response_queue_destroy
(
struct
SPDYF_Response_Queue
*response_queue);
1198
1199
1208
int
1209
SPDYF_name_value_is_empty
(
struct
SPDY_NameValue
*container);
1210
1211
1224
int
1225
SPDYF_name_value_from_stream
(
void
*stream,
1226
size_t
size,
1227
struct
SPDY_NameValue
** container);
1228
1229
1241
ssize_t
1242
SPDYF_name_value_to_stream
(
struct
SPDY_NameValue
* container[],
1243
int
num_containers,
1244
void
**stream);
1245
1246
#endif
src
microspdy
structures.h
Generated by
1.8.3.1