-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp2-push.cx
More file actions
executable file
·204 lines (204 loc) · 7.78 KB
/
Copy pathhttp2-push.cx
File metadata and controls
executable file
·204 lines (204 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//-*-C-*-
/*******************************************************************************
* ___ workplace
* ¦OUX¦ C+
* ¦/C+¦ server
* --- web server
* HTTP/2 push
* ©overcq on ‟Gentoo Linux 17.1” “x86_64” 2020‒10‒4 N
*******************************************************************************/
struct E_text_syntax_Z_body *E_http2_push_Z_syntax_html;
N entities_tag, entities_img, entities_link;
N entities_href, entities_src, entities_attr, entities_oth_attr;
enum E_http2_push_Z_tag
{ E_http2_push_Z_tag_S_oth
, E_http2_push_Z_tag_S_img
, E_http2_push_Z_tag_S_link
};
enum E_http2_push_Z_tag E_http2_push_S_tag;
B E_http2_push_S_attr;
Pc *E_http2_push_S_links;
N E_http2_push_S_links_n;
//==============================================================================
N
E_http2_push_I_parse_links( Pc req_path
, Pc authority
, Pc port
){ Pc req_path_end = E_text_Z_s0_R_search_last_c( req_path, '/' ) + 1;
for_n( links_i, E_http2_push_S_links_n )
{ Pc s = E_http2_push_S_links[ links_i ];
if(( E_text_Z_s0_T_starts_case_s0( s, "https:/""/" ) && (( s += 8 ), yes ))
|| ( E_text_Z_s0_T_starts_s0( s, "/""/" ) && (( s += 2 ), yes ))
)
{ if( !E_text_Z_s0_T_starts_case_s0( s, authority ))
{ if( !E_mem_Q_blk_I_remove( &E_http2_push_S_links, links_i, 1 ))
return ~0;
E_http2_push_S_links_n--;
links_i--;
continue;
}
s += E_text_Z_s0_R_l(authority);
if( *s != '/'
|| ( port
&& ( *s != ':'
|| !E_text_Z_s0_T_starts_s0( s + 1, port )
|| (( s += 1 + E_text_Z_s0_R_l(port) ), no )
|| *s != '/'
)))
{ if( !E_mem_Q_blk_I_remove( &E_http2_push_S_links, links_i, 1 ))
return ~0;
E_http2_push_S_links_n--;
links_i--;
continue;
}
if( !E_mem_Q_blk_I_remove( &E_http2_push_S_links[ links_i ], 0, s - E_http2_push_S_links[ links_i ] ))
return ~0;
s = E_http2_push_S_links[ links_i ];
}
if( *s != '/' )
{ Pc s_1 = E_mem_Q_blk_I_prepend( &E_http2_push_S_links[ links_i ], req_path_end - req_path );
if( !s_1 )
return ~0;
E_text_Z_s_P_copy_s( E_http2_push_S_links[ links_i ], req_path, req_path_end );
s = E_http2_push_S_links[ links_i ];
}
O{ Pc s_1 = E_text_Z_s0_R_search_c( s + 1, '/' );
Pc s_2;
for( s_2 = s; s_2 != s_1 - 1; s_2++ )
if( *s_2 != '.' )
break;
if( s_2 == s_1 - 1 )
{ s_2 = E_text_Z_s_R_search_last_c( E_http2_push_S_links[ links_i ], s, '/' );
if( s_1 - ( s + 1 ))
{ for_n( i, s_1 - ( s + 1 ) - 1 )
{ if( s_2 == E_http2_push_S_links[ links_i ] )
{ if( !E_mem_Q_blk_I_remove( &E_http2_push_S_links, links_i, 1 ))
return ~0;
links_i--;
goto Cont;
}
s_2 = E_text_Z_s_R_search_last_c( E_http2_push_S_links[ links_i ], s_2 - 1, '/' );
}
}
N s_i = s - E_http2_push_S_links[ links_i ];
N l = s - s_2;
if( !E_mem_Q_blk_I_remove( &E_http2_push_S_links[ links_i ], s_2 - E_http2_push_S_links[ links_i ], l ))
return ~0;
s = E_http2_push_S_links[ links_i ] + s_i;
s -= l;
}
if( !*s_1 )
{ s++;
break;
}
s = s_1;
}
Cont: ;
}
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I
E_http2_push_Q_tmp_file_M( Pc *s
){ int fd;
Pc s_ = M( J_s0_R_l( "/tmp/oux-web-srv-http2-push-XXXXXX" ) + 1 );
if( !s_ )
return ~0;
E_text_Z_s_P_copy_s0_0( s_, "/tmp/oux-web-srv-http2-push-XXXXXX" );
V1( fd = mkstemp( s_ ) )
{ W( s_ );
return ~0;
}
I file = E_mem_Q_file_M_fd(fd);
if( !~file )
{ VO0( close(fd) ){}
V0( unlink( s_ ) ){}
W( s_ );
return ~0;
}
*s = s_;
return file;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
N
E_http2_push_I_entities_func_Z_html( struct E_text_syntax_Z_body *syntax
, struct E_text_syntax_Z_state *state
, N state_n
){ if( state[ state_n - 1 ].entities_i == entities_tag )
E_http2_push_S_tag = E_http2_push_Z_tag_S_oth;
else if( state[ state_n - 1 ].entities_i == entities_img )
E_http2_push_S_tag = E_http2_push_Z_tag_S_img;
else if( state[ state_n - 1 ].entities_i == entities_link )
E_http2_push_S_tag = E_http2_push_Z_tag_S_link;
else if( state[ state_n - 1 ].entities_i == entities_href
&& E_http2_push_S_tag == E_http2_push_Z_tag_S_link
)
E_http2_push_S_attr = yes;
else if( state[ state_n - 1 ].entities_i == entities_src
&& E_http2_push_S_tag == E_http2_push_Z_tag_S_img
)
E_http2_push_S_attr = yes;
else if( state[ state_n - 1 ].entities_i == entities_attr
&& E_http2_push_S_attr
)
{ if( *state[ state_n - 1 ].s
&& E_mem_Q_blk_I_append( &E_http2_push_S_links, 1 )
)
{ Pc s = state[ state_n - 1 ].s;
Pc s_end = E_text_Z_s0_R_end(s);
if( state[ state_n - 1 ].s[0] == '\''
|| state[ state_n - 1 ].s[0] == '\"'
)
{ s++;
s_end--;
}
Pc s_1 = E_text_Z_s_R_search_c( s, s_end, '?' );
if( s_1 != s_end )
s_end = s_1;
if( s != s_end
&& *( s_end - 1 ) != '/'
&& !E_text_Z_s_T_ends_s0( s, s_end, ".html" )
&& !E_text_Z_s_T_ends_s0( s, s_end, ".php" )
)
{ E_http2_push_S_links[ E_http2_push_S_links_n ] = M( s_end - s + 1 );
if( E_http2_push_S_links[ E_http2_push_S_links_n ] )
{ E_text_Z_s_P_copy_s_0( E_http2_push_S_links[ E_http2_push_S_links_n ], s, s_end );
E_http2_push_S_links_n++;
}else
E_mem_Q_blk_I_remove( &E_http2_push_S_links, E_http2_push_S_links_n, 1 );
}
}
}else if( state[ state_n - 1 ].entities_i == entities_oth_attr )
E_http2_push_S_attr = no;
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
N
E_http2_push_M( void
){ I file = E_mem_Q_file_M( "html.syntax", yes, 0 );
if( !~file )
return ~0;
if( !~E_text_syntax_M( file, &E_http2_push_Z_syntax_html ))
{ E_mem_Q_file_W(file);
return ~0;
}
E_mem_Q_file_W(file);
entities_tag = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "inna nazwa znacznika" );
entities_img = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "img" );
entities_link = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "link" );
entities_href = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "href" );
entities_src = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "src" );
entities_attr = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "wartość atrybutu" );
entities_oth_attr = E_text_syntax_R_entity_by_name( E_http2_push_Z_syntax_html, "inna nazwa atrybutu" );
if( !~entities_tag
|| !~entities_img
|| !~entities_link
|| !~entities_href
|| !~entities_src
|| !~entities_attr
|| !~entities_oth_attr
)
return ~0;
return 0;
}
/******************************************************************************/