aboutgitcodelistschat:MatrixIRC
path: root/cooker/cooker.h
blob: a1cc360482017da2110850c96591f9d51be66d57 (plain) (blame)
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
/* SPDX-License-Identifier: GPL-3.0-or-later
 * Copyright 2023 Red Hat GmbH
 * Author: Stefano Brivio <sbrivio@redhat.com>
 */

#ifndef COOKER_H
#define COOKER_H

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <arpa/inet.h>

#define REFS_MAX			256
#define REF_NAMEMAX			256
#define CALL_ARGS			6

struct num;
struct field;
struct select;

union desc {
	struct num		*d_num;
	struct field		*d_struct;
	struct select		*d_select;
};

union value {
	int			v_int;
	uint32_t		v_u32;
	long long		v_num;
};

enum type {
	INT,
	INTMASK,
	INTFLAGS,

	U32,
	U32MASK,
	U32FLAGS,

	LONG,
	LONGMASK,
	LONGFLAGS,

	STRING,

	STRUCT,
	SELECT,

	PID,

	PORT,
	IPV4,
	IPV6,

	FDPATH,

	TYPE_END,
};

#define TYPE_COUNT		(TYPE_END - 1)

#define TYPE_IS_COMPOUND(t)	((t) == STRUCT || (t) == SELECT)
#define TYPE_IS_NUM(t)		((t) == INT || (t) == U32 || (t) == LONG)

enum jump_type {
	NEXT_BLOCK,
	END,
};

struct num {
	char *name;
	long long value;
};

struct field {
	char *name;
	enum type type;
	off_t offset;

	size_t strlen;

	union desc desc;
};

struct select_num {
	long long value;

	enum type type;
	union desc desc;
};

struct select {
	struct field *field;

	union {
		struct select_num *d_num;
	} desc;
};

struct arg {
	int pos;
	char *name;

	enum type type;
	size_t size;

	union desc desc;
};

#endif /* COOKER_H */