summaryrefslogtreecommitdiff
path: root/ot_urlencoded.h
diff options
context:
space:
mode:
Diffstat (limited to 'ot_urlencoded.h')
-rw-r--r--ot_urlencoded.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/ot_urlencoded.h b/ot_urlencoded.h
new file mode 100644
index 0000000..b6f1208
--- /dev/null
+++ b/ot_urlencoded.h
@@ -0,0 +1,55 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever.
3
4 $id$ */
5
6#ifndef SCAN_URLENCODED_QUERY_H__
7#define SCAN_URLENCODED_QUERY_H__
8
9#include <stddef.h>
10#include <stdint.h>
11#include <sys/types.h>
12
13typedef struct {
14 const char *key;
15 int value;
16} ot_keywords;
17
18typedef enum {
19 SCAN_PATH = 1,
20 SCAN_SEARCHPATH_PARAM = 2,
21 SCAN_SEARCHPATH_VALUE = 4,
22 SCAN_SEARCHPATH_TERMINATOR = 8
23} SCAN_SEARCHPATH_FLAG;
24
25/* string in: pointer to source
26 out: pointer to next scan position
27 deststring pointer to destination
28 flags determines, what to parse
29 returns number of valid converted characters in deststring
30 or -1 for parse error
31 or -2 for terminator found
32*/
33ssize_t urlencoded_parse(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags);
34
35/* string in: pointer to source
36 out: pointer to next scan position
37 flags determines, what to parse
38 returns value for matched keyword
39 or -1 for parse error
40 or -2 for terminator found
41 or -3 for no keyword matched
42 */
43int urlencoded_match_keyword(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags);
44
45/* string in: pointer to value of a param=value pair to skip
46 out: pointer to next scan position on return
47*/
48void urlencoded_skip_value(char **string);
49
50
51/* The other direction: percent encode len bytes from src into dest and return
52 how many characters were written. dest needs room for three times len. */
53size_t urlencoded_format(char *dest, const uint8_t *src, size_t len);
54
55#endif