-
Notifications
You must be signed in to change notification settings - Fork 0
/
rparse.h
94 lines (81 loc) · 2.7 KB
/
rparse.h
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
/* @(#) header for parsing functions for udpxy
*
* Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com)
*
* This file is part of udpxy.
*
* udpxy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* udpxy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with udpxy. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RPARSE_H_121420071651_
#define RPARSE_H_121420071651_
#include <sys/types.h>
#include <sys/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
/* parse and copy parameters of HTTP GET request into
* request buffer
*
* @param src buffer with raw source data
* @param srclen length of raw data
* @param request destination buffer for the request
* @param rqlen length of request buffer on entry
* length of request on exit
*
* @return 0 if success: request buffer gets populated,
* non-zero if error
*/
int
get_request( const char* src, size_t srclen,
char* request, size_t* rqlen );
/* parse (GET) request into command and parameters (options)
* c-strings
*
* @param s source c-string
* @param cmd buffer for the parsed command c-string
* @param clen length of command buffer
* @param opt buffer for the parsed options c-string
* @param optlen length of options buffer
* @param tail buffer for tail (whatever is beyond options)
* @param tlen length of tail buffer
*
* @return 0 if success: cmd and opt get get populated
* non-zero if an error ocurred
*/
int
parse_param( const char* s, size_t slen,
char* cmd, size_t clen,
char* opt, size_t optlen,
char* tail, size_t tlen);
/* parse options of upd-relay command into IP address
* and port
*
* @param opt options string
* @param optlen options string size (including zero-terminating byte)
* @param addr destination for address string
* @param addrlen length of address string buffer
* @param port port to populate
*
* @return 0 if success: inaddr and port get populated
* non-zero if error
*/
int
parse_udprelay( const char* opt, size_t optlen,
char* addr, size_t addrlen,
uint16_t* port );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
/* __EOF__ */