-
Notifications
You must be signed in to change notification settings - Fork 44
/
in.c
144 lines (112 loc) · 3.46 KB
/
in.c
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
/*
** in.c -- Apache API in wrappers
**
** (c) FiveTech Software SL, 2019-2020
** Developed by Antonio Linares alinares@fivetechsoft.com
** MIT license https://github.com/FiveTechSoft/mod_harbour/blob/master/LICENSE
*/
#include <http_protocol.h>
#include <apr_pools.h>
#include <hbapi.h>
#include <hbapiitm.h>
request_rec * GetRequestRec( void );
char * szBody = NULL;
HB_SIZE szBodyLen = 0;
//----------------------------------------------------------------//
HB_FUNC( AP_ARGS )
{
hb_retc( GetRequestRec()->args );
}
//----------------------------------------------------------------//
HB_FUNC( AP_BODY )
{
request_rec * r = GetRequestRec();
if( szBody )
hb_retclen( szBody, szBodyLen );
else
{
if( ap_setup_client_block( r, REQUEST_CHUNKED_ERROR ) != OK )
hb_retc( "" );
else
{
if( ap_should_client_block( r ) )
{
long length = ( long ) r->remaining;
char * rbuf = ( char * ) apr_pcalloc( r->pool, length + 1 );
int iRead = 0, iTotal = 0;
while( ( iRead = ap_get_client_block( r, rbuf + iTotal, length + 1 - iTotal ) ) < ( length + 1 - iTotal ) && iRead != 0 )
{
iTotal += iRead;
iRead = 0;
}
hb_retclen( rbuf, length );
szBody = ( char * ) hb_xgrab( length + 1 );
szBodyLen = length;
memcpy( szBody, rbuf, szBodyLen + 1 );
}
else
hb_retc( "" );
}
}
}
//----------------------------------------------------------------//
HB_FUNC( AP_FILENAME )
{
hb_retc( GetRequestRec()->filename );
}
//----------------------------------------------------------------//
HB_FUNC( AP_GETENV )
{
hb_retc( apr_table_get( GetRequestRec()->subprocess_env, hb_parc( 1 ) ) );
}
//----------------------------------------------------------------//
int ap_headers_in_count( void )
{
return apr_table_elts( GetRequestRec()->headers_in )->nelts;
}
//----------------------------------------------------------------//
HB_FUNC( AP_HEADERSINCOUNT )
{
hb_retnl( ap_headers_in_count() );
}
//----------------------------------------------------------------//
const char * ap_headers_in_key( int iKey )
{
const apr_array_header_t * fields = apr_table_elts( GetRequestRec()->headers_in );
apr_table_entry_t * e = ( apr_table_entry_t * ) fields->elts;
if( iKey >= 0 && iKey < fields->nelts )
return e[ iKey ].key;
else
return "";
}
//----------------------------------------------------------------//
const char * ap_headers_in_val( int iKey )
{
const apr_array_header_t * fields = apr_table_elts( GetRequestRec()->headers_in );
apr_table_entry_t * e = ( apr_table_entry_t * ) fields->elts;
if( iKey >= 0 && iKey < fields->nelts )
return e[ iKey ].val;
else
return "";
}
//----------------------------------------------------------------//
HB_FUNC( AP_HEADERSINKEY )
{
hb_retc( ap_headers_in_key( hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------//
HB_FUNC( AP_HEADERSINVAL )
{
hb_retc( ap_headers_in_val( hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------//
HB_FUNC( AP_METHOD )
{
hb_retc( GetRequestRec()->method );
}
//----------------------------------------------------------------//
HB_FUNC( AP_USERIP )
{
hb_retc( GetRequestRec()->useragent_ip );
}
//----------------------------------------------------------------//