diff options
Diffstat (limited to 'src/include/gnunet_psyc_lib.h')
-rw-r--r-- | src/include/gnunet_psyc_lib.h | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/include/gnunet_psyc_lib.h b/src/include/gnunet_psyc_lib.h new file mode 100644 index 000000000..bd8cbf025 --- /dev/null +++ b/src/include/gnunet_psyc_lib.h | |||
@@ -0,0 +1,164 @@ | |||
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_psyc_lib.h | ||
23 | * @brief Library for common PSYC functionality: | ||
24 | * types, variable (de)serialization. | ||
25 | * @author Gabor X Toth | ||
26 | */ | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Possible operations on PSYC state (persistent) and transient variables (per message). | ||
31 | */ | ||
32 | enum GNUNET_PSYC_Operator | ||
33 | { | ||
34 | /** | ||
35 | * Set value of a transient variable. | ||
36 | */ | ||
37 | GNUNET_PSYC_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_PSYC_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_PSYC_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_PSYC_OP_DIMINISH = '-', | ||
59 | |||
60 | /** | ||
61 | * Update state variable. | ||
62 | * | ||
63 | * Used for modifying a single item of a list or dictionary. | ||
64 | */ | ||
65 | GNUNET_PSYC_OP_UPDATE = '@', | ||
66 | }; | ||
67 | |||
68 | |||
69 | /** | ||
70 | * PSYC variable types. | ||
71 | */ | ||
72 | enum GNUNET_PSYC_Type | ||
73 | { | ||
74 | GNUNET_PSYC_TYPE_DATA = 0, | ||
75 | GNUNET_PSYC_TYPE_NUMBER, | ||
76 | GNUNET_PSYC_TYPE_LIST, | ||
77 | GNUNET_PSYC_TYPE_DICT | ||
78 | }; | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Get the type of variable. | ||
83 | * | ||
84 | * @param name Name of the variable. | ||
85 | * | ||
86 | * @return Variable type. | ||
87 | */ | ||
88 | enum GNUNET_PSYC_Type | ||
89 | GNUNET_PSYC_var_get_type (char *name); | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Get the variable's value as an integer. | ||
94 | * | ||
95 | * @param size Size of value. | ||
96 | * @param value Raw value of variable. | ||
97 | * @param[out] number Value converted to a 64-bit integer. | ||
98 | * | ||
99 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid). | ||
100 | */ | ||
101 | int | ||
102 | GNUNET_PSYC_value_to_number (size_t size, const void *value, int64_t *number); | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Get the variable's value as a list. | ||
107 | * | ||
108 | * @param size Size of value. | ||
109 | * @param value Raw value of variable. | ||
110 | * @param[out] list A newly created list holding the elements. | ||
111 | * | ||
112 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid). | ||
113 | */ | ||
114 | int | ||
115 | GNUNET_PSYC_value_to_list (size_t size, const void *value, GNUNET_CONTAINER_SList **list); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Get the variable's value as a dictionary. | ||
120 | * | ||
121 | * @param size Size of value. | ||
122 | * @param value Raw value of variable. | ||
123 | * @param[out] dict A newly created hashmap holding the elements of the dictionary. | ||
124 | * | ||
125 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid). | ||
126 | */ | ||
127 | int | ||
128 | GNUNET_PSYC_value_to_dict (size_t size, const void *value, GNUNET_CONTAINER_MultiHashMap **dict); | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Create a PSYC variable value from an integer. | ||
133 | * | ||
134 | * @param number The number to convert. | ||
135 | * @param[out] value_size Size of returned value. | ||
136 | * | ||
137 | * @return A newly allocated value or NULL on error. | ||
138 | */ | ||
139 | void * | ||
140 | GNUNET_PSYC_value_from_number (int64_t number, size_t *value_size); | ||
141 | |||
142 | |||
143 | /** | ||
144 | * Create a PSYC variable value from a list. | ||
145 | * | ||
146 | * @param list The list to convert. | ||
147 | * @param[out] value_size Size of returned value. | ||
148 | * | ||
149 | * @return A newly allocated value or NULL on error. | ||
150 | */ | ||
151 | void * | ||
152 | GNUNET_PSYC_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size); | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Create a PSYC variable value from a dictionary. | ||
157 | * | ||
158 | * @param dict The dict to convert. | ||
159 | * @param[out] value_size Size of returned value. | ||
160 | * | ||
161 | * @return A newly allocated value or NULL on error. | ||
162 | */ | ||
163 | void * | ||
164 | GNUNET_PSYC_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size); | ||