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
145
146
147
148
149
150
151
|
/*
* ZMap Copyright 2013 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
#ifndef XMAP_FIELDSET_H
#define XMAP_FIELDSET_H
#include <stdint.h>
#include <stdlib.h>
// maximum number of records that can be stored in a fieldset
#define MAX_FIELDS 1024
#define MAX_LIST_LENGTH 255
// types of data that can be stored in a field
#define FS_RESERVED 0
#define FS_STRING 1
#define FS_UINT64 2
#define FS_BINARY 3
#define FS_NULL 4
#define FS_BOOL 7
// recursive support
#define FS_FIELDSET 5
#define FS_REPEATED 6
// definition of a field that's provided by a probe module
// these are used so that users can ask at the command-line
// what fields are available for consumption
typedef struct field_def {
const char *name;
const char *type;
const char *desc;
} fielddef_t;
typedef struct fielddef_set {
fielddef_t fielddefs[MAX_FIELDS];
int len;
} fielddefset_t;
typedef union field_val {
void *ptr;
uint64_t num;
} field_val_t;
// the internal field type used by fieldset
typedef struct field {
const char *name;
int type;
int free_;
size_t len;
field_val_t value;
} field_t;
// data structure that is populated by the probe module
// and translated into the data structure that's passed
// to the output module
typedef struct fieldset {
int len;
field_t fields[MAX_FIELDS];
// only used for repeated.
int inner_type; // type of repeated element. e.g., FS_STRING
int type; // REPEATED or FIELDSET
int free_; // should elements be freed
} fieldset_t;
// we pass a different fieldset to an output module than
// the probe module generates for us because a user may
// only want certain fields and will expect them in a certain
// order. We generate a translated fieldset that contains
// only the fields we want to export to the output module.
// a translation specifies how to efficiently convert the fs
// povided by the probe module to the fs for the output module.
typedef struct translation {
int len;
int translation[MAX_FIELDS];
} translation_t;
fieldset_t *fs_new_fieldset(void);
fieldset_t *fs_new_repeated_field(int type, int free_);
fieldset_t *fs_new_repeated_uint64(void);
fieldset_t *fs_new_repeated_bool(void);
fieldset_t *fs_new_repeated_string(int free_);
fieldset_t *fs_new_repeated_binary(int free_);
fieldset_t *fs_new_repeated_fieldset();
char *fs_get_string_by_index(fieldset_t *fs, int index);
int fds_get_index_by_name(fielddefset_t *fds, char *name);
void gen_fielddef_set(fielddefset_t *fds, fielddef_t fs[], int len);
void fs_add_null(fieldset_t *fs, const char *name);
void fs_add_uint64(fieldset_t *fs, const char *name, uint64_t value);
void fs_add_bool(fieldset_t *fs, const char *name, int value);
void fs_add_string(fieldset_t *fs, const char *name, char *value, int free_);
void fs_add_unsafe_string(fieldset_t *fs, const char *name, char *value,
int free_);
void fs_chkadd_string(fieldset_t *fs, const char *name, char *value, int free_);
void fs_chkadd_unsafe_string(fieldset_t *fs, const char *name, char *value,
int free_);
void fs_add_constchar(fieldset_t *fs, const char *name, const char *value);
void fs_add_binary(fieldset_t *fs, const char *name, size_t len, void *value,
int free_);
void fs_add_fieldset(fieldset_t *fs, const char *name, fieldset_t *child);
void fs_add_repeated(fieldset_t *fs, const char *name, fieldset_t *child);
// Modify
void fs_modify_null(fieldset_t *fs, const char *name);
void fs_modify_uint64(fieldset_t *fs, const char *name, uint64_t value);
void fs_modify_bool(fieldset_t *fs, const char *name, int value);
void fs_modify_string(fieldset_t *fs, const char *name, char *value, int free_);
void fs_modify_binary(fieldset_t *fs, const char *name, size_t len, void *value,
int free_);
uint64_t fs_get_uint64_by_index(fieldset_t *fs, int index);
void fs_free(fieldset_t *fs);
void fs_generate_fieldset_translation(translation_t *t, fielddefset_t *avail,
char **req, int reqlen);
fieldset_t *translate_fieldset(fieldset_t *fs, translation_t *t);
void fs_generate_full_fieldset_translation(translation_t *t,
fielddefset_t *avail);
#endif // XMAP_FIELDSET_H
|