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