aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_env_lib.h
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-07-15 07:25:13 +0000
committerGabor X Toth <*@tg-x.net>2013-07-15 07:25:13 +0000
commitb9f677a21cc21b3554b68e74f16c5fac6358c97b (patch)
treeca88507d8ce3405c3418afd56fb2f0b32ff2e78c /src/include/gnunet_env_lib.h
parent87093621a5223dd1f0d48ded2c41821af7def6f7 (diff)
downloadgnunet-b9f677a21cc21b3554b68e74f16c5fac6358c97b.tar.gz
gnunet-b9f677a21cc21b3554b68e74f16c5fac6358c97b.zip
PSYC/social: use an Environment for setting variables / state operations
Diffstat (limited to 'src/include/gnunet_env_lib.h')
-rw-r--r--src/include/gnunet_env_lib.h262
1 files changed, 262 insertions, 0 deletions
diff --git a/src/include/gnunet_env_lib.h b/src/include/gnunet_env_lib.h
new file mode 100644
index 000000000..5ff5c22db
--- /dev/null
+++ b/src/include/gnunet_env_lib.h
@@ -0,0 +1,262 @@
1/*
2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file include/gnunet_env_lib.h
23 * @brief Library providing operations for the @e environment of PSYC and Social messages,
24 * and for (de)serializing variable values.
25 * @author Gabor X Toth
26 */
27
28
29/**
30 * Possible operations on PSYC state (persistent) and transient variables (per message).
31 */
32enum GNUNET_ENV_Operator
33{
34 /**
35 * Set value of a transient variable.
36 */
37 GNUNET_ENV_OP_SET = ':',
38
39 /**
40 * Assign value for a persistent state variable.
41 *
42 * If an assigned value is NULL, the variable is deleted.
43 */
44 GNUNET_ENV_OP_ASSIGN = '=',
45
46 /**
47 * Augment state variable.
48 *
49 * Used for appending strings, adding numbers, and adding new items to a list or dictionary.
50 */
51 GNUNET_ENV_OP_AUGMENT = '+',
52
53 /**
54 * Diminish state variable.
55 *
56 * Used for subtracting numbers, and removing items from a list or dictionary.
57 */
58 GNUNET_ENV_OP_DIMINISH = '-',
59
60 /**
61 * Update state variable.
62 *
63 * Used for modifying a single item of a list or dictionary.
64 */
65 GNUNET_ENV_OP_UPDATE = '@',
66};
67
68
69/**
70 * PSYC variable types.
71 */
72enum GNUNET_ENV_Type
73{
74 GNUNET_ENV_TYPE_DATA = 0,
75 GNUNET_ENV_TYPE_NUMBER,
76 GNUNET_ENV_TYPE_LIST,
77 GNUNET_ENV_TYPE_DICT
78};
79
80
81/**
82 * PSYC state modifier.
83 */
84struct GNUNET_ENV_Modifier {
85 /**
86 * State operation.
87 */
88 GNUNET_ENV_Operator oper;
89
90 /**
91 * Variable name.
92 */
93 const char *name;
94
95 /**
96 * Size of @a value.
97 */
98 size_t value_size;
99
100 /**
101 * Value of variable.
102 */
103 const void *value;
104};
105
106
107/**
108 * Environment for a message.
109 *
110 * Contains modifiers.
111 */
112struct GNUNET_ENV_Environment;
113
114
115/**
116 * Create an environment.
117 *
118 * @return A newly allocated environment.
119 */
120struct GNUNET_ENV_Environment *
121GNUNET_ENV_environment_create ();
122
123
124/**
125 * Add an operation on a variable to the environment.
126 *
127 * @param env The environment.
128 * @param oper Operation to perform.
129 * @param name Name of the variable.
130 * @param value_size Size of @a value.
131 * @param value Value of the variable.
132 *
133 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
134 */
135int
136GNUNET_ENV_environment_operation (struct GNUNET_ENV_Environment *env,
137 enum GNUNET_ENV_Operator oper,
138 const char *name,
139 size_t value_size, const void *value);
140
141
142/**
143 * Get all modifiers in the environment.
144 *
145 * @param env The environment.
146 * @param[out] modifiers_length Set to the number of returned modifiers.
147 *
148 * @return Array of modifiers.
149 */
150struct GNUNET_ENV_Modifier *
151GNUNET_ENV_environment_get_modifiers (const struct GNUNET_ENV_Environment *env,
152 size_t *modifiers_length);
153
154
155/**
156 * Add list of modifiers to the environment.
157 *
158 * @param env The environment.
159 * @param modifiers_length Number of @a modifiers.
160 * @param modifiers Array of modifiers to add.
161 *
162 * @return
163 */
164int
165GNUNET_ENV_environment_set_modifiers (const struct GNUNET_ENV_Environment *env,
166 size_t modifiers_length,
167 const struct GNUNET_ENV_Modifier *modifiers);
168
169
170/**
171 * Destroy an environment.
172 *
173 * @param env The environment to destroy.
174 */
175void
176GNUNET_ENV_environment_destroy (struct GNUNET_ENV_Environment *env);
177
178
179/**
180 * Get the type of variable.
181 *
182 * @param name Name of the variable.
183 *
184 * @return Variable type.
185 */
186enum GNUNET_ENV_Type
187GNUNET_ENV_var_get_type (char *name);
188
189
190/**
191 * Get the variable's value as an integer.
192 *
193 * @param size Size of value.
194 * @param value Raw value of variable.
195 * @param[out] number Value converted to a 64-bit integer.
196 *
197 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
198 */
199int
200GNUNET_ENV_value_to_number (size_t size, const void *value, int64_t *number);
201
202
203/**
204 * Get the variable's value as a list.
205 *
206 * @param size Size of value.
207 * @param value Raw value of variable.
208 * @param[out] list A newly created list holding the elements.
209 *
210 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
211 */
212int
213GNUNET_ENV_value_to_list (size_t size, const void *value, GNUNET_CONTAINER_SList **list);
214
215
216/**
217 * Get the variable's value as a dictionary.
218 *
219 * @param size Size of value.
220 * @param value Raw value of variable.
221 * @param[out] dict A newly created hashmap holding the elements of the dictionary.
222 *
223 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
224 */
225int
226GNUNET_ENV_value_to_dict (size_t size, const void *value, GNUNET_CONTAINER_MultiHashMap **dict);
227
228
229/**
230 * Create a PSYC variable value from an integer.
231 *
232 * @param number The number to convert.
233 * @param[out] value_size Size of returned value.
234 *
235 * @return A newly allocated value or NULL on error.
236 */
237void *
238GNUNET_ENV_value_from_number (int64_t number, size_t *value_size);
239
240
241/**
242 * Create a PSYC variable value from a list.
243 *
244 * @param list The list to convert.
245 * @param[out] value_size Size of returned value.
246 *
247 * @return A newly allocated value or NULL on error.
248 */
249void *
250GNUNET_ENV_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size);
251
252
253/**
254 * Create a PSYC variable value from a dictionary.
255 *
256 * @param dict The dict to convert.
257 * @param[out] value_size Size of returned value.
258 *
259 * @return A newly allocated value or NULL on error.
260 */
261void *
262GNUNET_ENV_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size);