aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_psyc_lib.h
blob: bd8cbf0252a4399f0d9d61b3e937bec77b23bba6 (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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
     This file is part of GNUnet.
     (C) 2013 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/** 
 * @file include/gnunet_psyc_lib.h
 * @brief Library for common PSYC functionality:
 *        types, variable (de)serialization.
 * @author Gabor X Toth
 */


/** 
 * Possible operations on PSYC state (persistent) and transient variables (per message).
 */
enum GNUNET_PSYC_Operator
{ 
  /**
   * Set value of a transient variable.
   */
  GNUNET_PSYC_OP_SET = ':',

  /**
   * Assign value for a persistent state variable.
   *
   * If an assigned value is NULL, the variable is deleted.
   */
  GNUNET_PSYC_OP_ASSIGN = '=',

  /**
   * Augment state variable.
   *
   * Used for appending strings, adding numbers, and adding new items to a list or dictionary.
   */
  GNUNET_PSYC_OP_AUGMENT = '+',

  /**
   * Diminish state variable.
   *
   * Used for subtracting numbers, and removing items from a list or dictionary.
   */
  GNUNET_PSYC_OP_DIMINISH = '-',

  /**
   * Update state variable.
   *
   * Used for modifying a single item of a list or dictionary.
   */
  GNUNET_PSYC_OP_UPDATE = '@',
};


/**
 * PSYC variable types.
 */
enum GNUNET_PSYC_Type
{
  GNUNET_PSYC_TYPE_DATA = 0,
  GNUNET_PSYC_TYPE_NUMBER,
  GNUNET_PSYC_TYPE_LIST,
  GNUNET_PSYC_TYPE_DICT
};


/** 
 * Get the type of variable.
 *
 * @param name Name of the variable.
 * 
 * @return Variable type.
 */
enum GNUNET_PSYC_Type
GNUNET_PSYC_var_get_type (char *name);


/** 
 * Get the variable's value as an integer.
 *
 * @param size Size of value.
 * @param value Raw value of variable.
 * @param[out] number Value converted to a 64-bit integer. 
 *
 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
 */
int
GNUNET_PSYC_value_to_number (size_t size, const void *value, int64_t *number);


/** 
 * Get the variable's value as a list.
 *
 * @param size Size of value.
 * @param value Raw value of variable.
 * @param[out] list A newly created list holding the elements.
 *
 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
 */
int
GNUNET_PSYC_value_to_list (size_t size, const void *value, GNUNET_CONTAINER_SList **list);


/** 
 * Get the variable's value as a dictionary.
 *
 * @param size Size of value.
 * @param value Raw value of variable.
 * @param[out] dict A newly created hashmap holding the elements of the dictionary.
 *
 * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
 */
int
GNUNET_PSYC_value_to_dict (size_t size, const void *value, GNUNET_CONTAINER_MultiHashMap **dict);


/** 
 * Create a PSYC variable value from an integer.
 *
 * @param number The number to convert.
 * @param[out] value_size Size of returned value.
 * 
 * @return A newly allocated value or NULL on error.
 */
void *
GNUNET_PSYC_value_from_number (int64_t number, size_t *value_size);


/** 
 * Create a PSYC variable value from a list.
 *
 * @param list The list to convert.
 * @param[out] value_size Size of returned value.
 * 
 * @return A newly allocated value or NULL on error.
 */
void *
GNUNET_PSYC_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size);


/** 
 * Create a PSYC variable value from a dictionary.
 *
 * @param dict The dict to convert.
 * @param[out] value_size Size of returned value.
 * 
 * @return A newly allocated value or NULL on error.
 */
void *
GNUNET_PSYC_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size);