multicast/psyc/psycstore api: fix typos / type names
[oweals/gnunet.git] / src / include / gnunet_env_lib.h
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
24  *        PSYC and Social messages, and for (de)serializing variable values.
25  * @author Gabor X Toth
26  */
27
28
29 #ifndef GNUNET_ENV_LIB_H
30 #define GNUNET_ENV_LIB_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /** 
42  * Possible operations on PSYC state (persistent) and transient variables (per message).
43  */
44 enum GNUNET_ENV_Operator
45 {
46   /** 
47    * Set value of a transient variable.
48    */
49   GNUNET_ENV_OP_SET = ':',
50
51   /** 
52    * Assign value for a persistent state variable.
53    *
54    * If an assigned value is NULL, the variable is deleted.
55    */
56   GNUNET_ENV_OP_ASSIGN = '=',
57
58   /** 
59    * Augment state variable.
60    *
61    * Used for appending strings, adding numbers, and adding new items to a list or dictionary.
62    */
63   GNUNET_ENV_OP_AUGMENT = '+',
64
65   /** 
66    * Diminish state variable.
67    *
68    * Used for subtracting numbers, and removing items from a list or dictionary.
69    */
70   GNUNET_ENV_OP_DIMINISH = '-',
71
72   /** 
73    * Update state variable.
74    *
75    * Used for modifying a single item of a list or dictionary.
76    */
77   GNUNET_ENV_OP_UPDATE = '@',
78 };
79
80
81 /** 
82  * PSYC variable types.
83  */
84 enum GNUNET_ENV_Type
85 {
86   GNUNET_ENV_TYPE_DATA = 0,
87   GNUNET_ENV_TYPE_NUMBER,
88   GNUNET_ENV_TYPE_LIST,
89   GNUNET_ENV_TYPE_DICT
90 };
91
92
93 /** 
94  * PSYC state modifier.
95  */
96 struct GNUNET_ENV_Modifier {
97   /** 
98    * State operation.
99    */
100   enum GNUNET_ENV_Operator oper;
101
102   /** 
103    * Variable name.
104    */
105   const char *name;
106
107   /** 
108    * Size of @a value.
109    */
110   size_t value_size;
111
112   /** 
113    * Value of variable.
114    */
115   const void *value;
116 };
117
118
119 /** 
120  * Environment for a message.
121  *
122  * Contains modifiers.
123  */
124 struct GNUNET_ENV_Environment;
125
126
127 /** 
128  * Create an environment.
129  * 
130  * @return A newly allocated environment.
131  */
132 struct GNUNET_ENV_Environment *
133 GNUNET_ENV_environment_create ();
134
135
136 /** 
137  * Add an operation on a variable to the environment.
138  *
139  * @param env The environment.
140  * @param oper Operation to perform.
141  * @param name Name of the variable.
142  * @param value_size Size of @a value.
143  * @param value Value of the variable.
144  * 
145  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
146  */
147 int
148 GNUNET_ENV_environment_operation (struct GNUNET_ENV_Environment *env,
149                                   enum GNUNET_ENV_Operator oper,
150                                   const char *name,
151                                   size_t value_size, const void *value);
152
153
154 /** 
155  * Get all modifiers in the environment.
156  *
157  * FIXME: use an iterator instead, as we'll likely use a SList to store the
158  *        modifiers in the environment.
159  *
160  * @param env The environment.
161  * @param[out] modifier_count Set to the number of returned modifiers.
162  * 
163  * @return Array of modifiers.
164  */
165 const struct GNUNET_ENV_Modifier *
166 GNUNET_ENV_environment_get_modifiers (const struct GNUNET_ENV_Environment *env,
167                                       size_t *modifier_count);
168
169
170 /** 
171  * Add list of modifiers to the environment.
172  *
173  * @param env The environment.
174  * @param modifier_count Number of @a modifiers.
175  * @param modifiers Array of modifiers to add.
176  * 
177  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
178  */
179 int
180 GNUNET_ENV_environment_set_modifiers (const struct GNUNET_ENV_Environment *env,
181                                       size_t modifier_count,
182                                       const struct GNUNET_ENV_Modifier *modifiers);
183
184
185 /** 
186  * Destroy an environment.
187  *
188  * @param env The environment to destroy.
189  */
190 void
191 GNUNET_ENV_environment_destroy (struct GNUNET_ENV_Environment *env);
192
193
194 /** 
195  * Get the type of variable.
196  *
197  * @param name Name of the variable.
198  * 
199  * @return Variable type.
200  */
201 enum GNUNET_ENV_Type
202 GNUNET_ENV_var_get_type (char *name);
203
204
205 /** 
206  * Get the variable's value as an integer.
207  *
208  * @param size Size of value.
209  * @param value Raw value of variable.
210  * @param[out] number Value converted to a 64-bit integer.
211  *
212  * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
213  */
214 int
215 GNUNET_ENV_value_to_number (size_t size, const void *value, int64_t *number);
216
217
218 /** 
219  * Get the variable's value as a list.
220  *
221  * @param size Size of value.
222  * @param value Raw value of variable.
223  * @param[out] list A newly created list holding the elements.
224  *
225  * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
226  */
227 int
228 GNUNET_ENV_value_to_list (size_t size, const void *value, struct GNUNET_CONTAINER_SList **list);
229
230
231 /** 
232  * Get the variable's value as a dictionary.
233  *
234  * @param size Size of value.
235  * @param value Raw value of variable.
236  * @param[out] dict A newly created hashmap holding the elements of the dictionary.
237  *
238  * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
239  */
240 int
241 GNUNET_ENV_value_to_dict (size_t size, const void *value, struct GNUNET_CONTAINER_MultiHashMap **dict);
242
243
244 /** 
245  * Create a PSYC variable value from an integer.
246  *
247  * @param number The number to convert.
248  * @param[out] value_size Size of returned value.
249  * 
250  * @return A newly allocated value or NULL on error.
251  */
252 void *
253 GNUNET_ENV_value_from_number (int64_t number, size_t *value_size);
254
255
256 /** 
257  * Create a PSYC variable value from a list.
258  *
259  * @param list The list to convert.
260  * @param[out] value_size Size of returned value.
261  * 
262  * @return A newly allocated value or NULL on error.
263  */
264 void *
265 GNUNET_ENV_value_from_list (struct GNUNET_CONTAINER_SList *list, size_t *value_size);
266
267
268 /** 
269  * Create a PSYC variable value from a dictionary.
270  *
271  * @param dict The dict to convert.
272  * @param[out] value_size Size of returned value.
273  * 
274  * @return A newly allocated value or NULL on error.
275  */
276 void *
277 GNUNET_ENV_value_from_dict (struct GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size);
278
279
280 #if 0                           /* keep Emacsens' auto-indent happy */
281 {
282 #endif
283 #ifdef __cplusplus
284 }
285 #endif
286
287 /* ifndef GNUNET_ENV_LIB_H */
288 #endif
289 /* end of gnunet_env_lib.h */