1 | /* |
2 | This file is part of Mtproto-proxy Library. |
3 | |
4 | Mtproto-proxy Library is free software: you can redistribute it and/or modify |
5 | it under the terms of the GNU Lesser General Public License as published by |
6 | the Free Software Foundation, either version 2 of the License, or |
7 | (at your option) any later version. |
8 | |
9 | Mtproto-proxy Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public License |
15 | along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>. |
16 | |
17 | Copyright 2010-2012 Vkontakte Ltd |
18 | 2010-2012 Nikolai Durov |
19 | 2010-2012 Andrey Lopatin |
20 | 2012 Anton Maydell |
21 | |
22 | Copyright 2014-2016 Telegram Messenger Inc |
23 | 2015-2016 Vitaly Valtman |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "net/net-connections.h" |
29 | //#include "net/net-buffers.h" |
30 | #define 16384 |
31 | |
32 | struct http_server_functions { |
33 | void *info; |
34 | int (*execute)(connection_job_t c, struct raw_message *raw, int op); /* invoked from parse_execute() */ |
35 | int (*ht_wakeup)(connection_job_t c); |
36 | int (*ht_alarm)(connection_job_t c); |
37 | int (*ht_close)(connection_job_t c, int who); |
38 | }; |
39 | |
40 | #define HTTP_V09 9 |
41 | #define HTTP_V10 0x100 |
42 | #define HTTP_V11 0x101 |
43 | |
44 | /* in conn->custom_data, 104 bytes */ |
45 | struct hts_data { |
46 | int query_type; |
47 | int query_flags; |
48 | int query_words; |
49 | int ; |
50 | int first_line_size; |
51 | int data_size; |
52 | int host_offset; |
53 | int host_size; |
54 | int uri_offset; |
55 | int uri_size; |
56 | int http_ver; |
57 | int wlen; |
58 | char word[16]; |
59 | void *; |
60 | int ; |
61 | int ; |
62 | int ; |
63 | int ; |
64 | double , ; |
65 | int parse_state; |
66 | int query_seqno; |
67 | }; |
68 | |
69 | /* for hts_data.query_type */ |
70 | enum hts_query_type { |
71 | htqt_none, |
72 | htqt_head, |
73 | htqt_get, |
74 | htqt_post, |
75 | htqt_options, |
76 | htqt_error, |
77 | htqt_empty |
78 | }; |
79 | |
80 | #define QF_ERROR 1 |
81 | #define QF_HOST 2 |
82 | #define QF_DATASIZE 4 |
83 | #define QF_CONNECTION 8 |
84 | #define QF_TRANSFER_ENCODING 16 |
85 | #define QF_TRANSFER_ENCODING_CHUNKED 32 |
86 | #define QF_KEEPALIVE 0x100 |
87 | #define 0x200 |
88 | |
89 | #define HTS_DATA(c) ((struct hts_data *) (CONN_INFO(c)->custom_data)) |
90 | #define HTS_FUNC(c) ((struct http_server_functions *) (CONN_INFO(c)->extra)) |
91 | |
92 | extern conn_type_t ct_http_server; |
93 | extern struct http_server_functions default_http_server; |
94 | |
95 | int hts_do_wakeup (connection_job_t c); |
96 | int hts_parse_execute (connection_job_t c); |
97 | int hts_std_wakeup (connection_job_t c); |
98 | int hts_std_alarm (connection_job_t c); |
99 | int hts_init_accepted (connection_job_t c); |
100 | int hts_close_connection (connection_job_t c, int who); |
101 | void http_flush (connection_job_t C, struct raw_message *raw); |
102 | |
103 | extern int http_connections; |
104 | extern long long http_queries, , http_queries_size; |
105 | |
106 | extern char *; |
107 | |
108 | /* useful functions */ |
109 | int (const char *, const int , char *buffer, int b_len, const char *arg_name, const int arg_len); |
110 | |
111 | #define HTTP_DATE_LEN 29 |
112 | void gen_http_date (char date_buffer[29], int time); |
113 | int gen_http_time (char *date_buffer, int *time); |
114 | char *cur_http_date (void); |
115 | //int write_basic_http_header (connection_job_t c, int code, int date, int len, const char *add_header, const char *content_type); |
116 | int (connection_job_t c, struct raw_message *raw, int code, int date, int len, const char *, const char *content_type); |
117 | int write_http_error (connection_job_t c, int code); |
118 | int write_http_error_raw (connection_job_t c, struct raw_message *raw, int code); |
119 | |
120 | /* END */ |
121 | |