GNUnet  0.11.x
Macros | Functions
pabc_helper.h File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include <pabc/pabc.h>
Include dependency graph for pabc_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PATH_MAX   4096
 
#define PABC_ISK_EXT   ".isk"
 
#define PABC_PP_EXT   ".pp"
 
#define PABC_USR_EXT   ".usr"
 
#define PABC_ATTR_DELIM   "="
 

Functions

enum GNUNET_GenericReturnValue PABC_write_public_parameters (char const *const pp_name, struct pabc_public_parameters *const pp)
 
enum GNUNET_GenericReturnValue PABC_load_public_parameters (struct pabc_context *const ctx, char const *const pp_name, struct pabc_public_parameters **pp)
 
enum GNUNET_GenericReturnValue PABC_write_usr_ctx (char const *const user_name, char const *const pp_name, struct pabc_context const *const ctx, struct pabc_public_parameters const *const pp, struct pabc_user_context *const usr_ctx)
 
enum GNUNET_GenericReturnValue PABC_read_usr_ctx (char const *const user_name, char const *const pp_name, struct pabc_context const *const ctx, struct pabc_public_parameters const *const pp, struct pabc_user_context **usr_ctx)
 

Macro Definition Documentation

◆ PATH_MAX

#define PATH_MAX   4096

Definition at line 6 of file pabc_helper.h.

◆ PABC_ISK_EXT

#define PABC_ISK_EXT   ".isk"

Definition at line 9 of file pabc_helper.h.

◆ PABC_PP_EXT

#define PABC_PP_EXT   ".pp"

Definition at line 11 of file pabc_helper.h.

Referenced by PABC_load_public_parameters(), and PABC_write_public_parameters().

◆ PABC_USR_EXT

#define PABC_USR_EXT   ".usr"

Definition at line 13 of file pabc_helper.h.

Referenced by PABC_read_usr_ctx(), and PABC_write_usr_ctx().

◆ PABC_ATTR_DELIM

#define PABC_ATTR_DELIM   "="

Definition at line 15 of file pabc_helper.h.

Function Documentation

◆ PABC_write_public_parameters()

enum GNUNET_GenericReturnValue PABC_write_public_parameters ( char const *const  pp_name,
struct pabc_public_parameters *const  pp 
)

Definition at line 170 of file pabc_helper.c.

References ctx, filename, get_pabcdir(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_urlencode(), GNUNET_SYSERR, PABC_PP_EXT, status, and write_file().

Referenced by cr_cont().

172 {
173  char *json;
174  char *filename;
175  char *pp_filename;
176  enum pabc_status status;
177  struct pabc_context *ctx = NULL;
178 
179  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
180  PABC_ASSERT (pabc_new_ctx (&ctx));
181  // store in json file
182  status = pabc_encode_public_parameters (ctx, pp, &json);
183  if (status != PABC_OK)
184  {
185  GNUNET_free (pp_filename);
187  "Failed to encode public parameters.\n");
188  pabc_free_ctx (&ctx);
189  return GNUNET_SYSERR;
190  }
191 
192  size_t filename_size =
193  strlen (get_pabcdir ()) + 1 + strlen (pp_filename) + strlen (PABC_PP_EXT)
194  + 1;
195  filename = GNUNET_malloc (filename_size);
196  if (! filename)
197  {
198  GNUNET_free (pp_filename);
199  PABC_FREE_NULL (json);
200  pabc_free_ctx (&ctx);
201  return GNUNET_SYSERR;
202  }
203  snprintf (filename, filename_size, "%s/%s%s", get_pabcdir (), pp_filename,
204  PABC_PP_EXT);
205 
206  GNUNET_free (pp_filename);
207  if (GNUNET_OK != write_file (filename, json))
208  {
209  PABC_FREE_NULL (filename);
210  PABC_FREE_NULL (json);
211  pabc_free_ctx (&ctx);
212  return GNUNET_SYSERR;
213  }
214  PABC_FREE_NULL (filename);
215  PABC_FREE_NULL (json);
216  pabc_free_ctx (&ctx);
217  return GNUNET_OK;
218 }
static const char * get_pabcdir()
Definition: pabc_helper.c:62
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define PABC_PP_EXT
Definition: pabc_helper.h:11
uint16_t status
See PRISM_STATUS_*-constants.
static char * filename
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:2147
static enum GNUNET_GenericReturnValue write_file(char const *const filename, const char *buffer)
Definition: pabc_helper.c:27
#define GNUNET_log(kind,...)
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PABC_load_public_parameters()

enum GNUNET_GenericReturnValue PABC_load_public_parameters ( struct pabc_context *const  ctx,
char const *const  pp_name,
struct pabc_public_parameters **  pp 
)

Definition at line 134 of file pabc_helper.c.

References get_pabcdir(), GNUNET_DISK_directory_test(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_urlencode(), GNUNET_SYSERR, GNUNET_YES, PABC_PP_EXT, PABC_read_issuer_ppfile(), and PATH_MAX.

Referenced by pabc_create_presentation().

137 {
138  char fname[PATH_MAX];
139  char *pp_filename;
140  const char *pdir = get_pabcdir ();
141 
142  if (ctx == NULL)
143  return GNUNET_SYSERR;
144  if (pp_name == NULL)
145  return GNUNET_SYSERR;
146 
147  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
149  {
150  GNUNET_free (pp_filename);
151  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error reading %s\n", pdir);
152  return GNUNET_SYSERR;
153  }
154  snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_filename, PABC_PP_EXT);
155  if (GNUNET_YES != GNUNET_DISK_file_test (fname))
156  {
157  GNUNET_free (pp_filename);
158  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error testing %s\n", fname);
159  return GNUNET_SYSERR;
160  }
161  *pp = PABC_read_issuer_ppfile (fname, ctx);
162  if (*pp)
163  return GNUNET_OK;
164  else
165  return GNUNET_SYSERR;
166 }
static const char * get_pabcdir()
Definition: pabc_helper.c:62
struct pabc_public_parameters * PABC_read_issuer_ppfile(const char *f, struct pabc_context *const ctx)
Definition: pabc_helper.c:105
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define PABC_PP_EXT
Definition: pabc_helper.h:11
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:247
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:2147
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:437
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PABC_write_usr_ctx()

enum GNUNET_GenericReturnValue PABC_write_usr_ctx ( char const *const  user_name,
char const *const  pp_name,
struct pabc_context const *const  ctx,
struct pabc_public_parameters const *const  pp,
struct pabc_user_context *const  usr_ctx 
)

Definition at line 222 of file pabc_helper.c.

References get_pabcdir(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_urlencode(), GNUNET_SYSERR, PABC_USR_EXT, status, and write_file().

Referenced by cr_cont().

227 {
228 
229  char *pp_filename;
230  char *json = NULL;
231  enum pabc_status status;
232  char *fname = NULL;
233 
234  if (NULL == usr_name)
235  {
236  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
237  return GNUNET_SYSERR;
238  }
239  if (NULL == pp_name)
240  {
241  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user given.\n");
242  return GNUNET_SYSERR;
243  }
244  if (NULL == ctx)
245  {
246  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No context given.\n");
247  return GNUNET_SYSERR;
248  }
249  if (NULL == pp)
250  {
251  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No public parameters given.\n");
252  return GNUNET_SYSERR;
253  }
254  if (NULL == usr_ctx)
255  {
256  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n");
257  return GNUNET_SYSERR;
258  }
259 
260  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
261  status = pabc_encode_user_ctx (ctx, pp, usr_ctx, &json);
262  if (PABC_OK != status)
263  {
264  GNUNET_free (pp_filename);
265  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n");
266  return status;
267  }
268 
269  size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
270  + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
271  fname = GNUNET_malloc (fname_size);
272 
273  snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
274  pp_filename,
275  PABC_USR_EXT);
276 
277  GNUNET_free (pp_filename);
278  if (GNUNET_OK == write_file (fname, json))
279  {
280  GNUNET_free (fname);
281  GNUNET_free (json);
282  return GNUNET_OK;
283  }
284  else
285  {
286  GNUNET_free (fname);
287  GNUNET_free (json);
288  return GNUNET_SYSERR;
289  }
290 }
static const char * get_pabcdir()
Definition: pabc_helper.c:62
#define PABC_USR_EXT
Definition: pabc_helper.h:13
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
uint16_t status
See PRISM_STATUS_*-constants.
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:2147
static enum GNUNET_GenericReturnValue write_file(char const *const filename, const char *buffer)
Definition: pabc_helper.c:27
#define GNUNET_log(kind,...)
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PABC_read_usr_ctx()

enum GNUNET_GenericReturnValue PABC_read_usr_ctx ( char const *const  user_name,
char const *const  pp_name,
struct pabc_context const *const  ctx,
struct pabc_public_parameters const *const  pp,
struct pabc_user_context **  usr_ctx 
)

Definition at line 294 of file pabc_helper.c.

References get_pabcdir(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_urlencode(), GNUNET_SYSERR, PABC_USR_EXT, read_file(), and status.

Referenced by cr_cont(), and pabc_create_presentation().

299 {
300  char *json = NULL;
301  char *pp_filename;
302  enum pabc_status status;
303 
304  char *fname = NULL;
305 
306  if (NULL == usr_name)
307  {
308  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
309  return GNUNET_SYSERR;
310  }
311  if (NULL == pp_name)
312  {
313  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user given.\n");
314  return GNUNET_SYSERR;
315  }
316  if (NULL == ctx)
317  {
318  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No context given.\n");
319  return GNUNET_SYSERR;
320  }
321  if (NULL == pp)
322  {
323  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No public parameters given.\n");
324  return GNUNET_SYSERR;
325  }
326  if (NULL == usr_ctx)
327  {
328  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n");
329  return GNUNET_SYSERR;
330  }
331  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
332 
333  size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
334  + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
335  fname = GNUNET_malloc (fname_size);
336  snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
337  pp_filename,
338  PABC_USR_EXT);
339  GNUNET_free (pp_filename);
340  if (GNUNET_OK != read_file (fname, &json))
341  {
343  "Failed to read `%s'\n", fname);
344  PABC_FREE_NULL (fname);
345  return GNUNET_SYSERR;
346  }
347  GNUNET_free (fname);
348 
349  status = pabc_new_user_context (ctx, pp, usr_ctx);
350  if (PABC_OK != status)
351  {
352  GNUNET_free (json);
353  return GNUNET_SYSERR;
354  }
355  status = pabc_decode_user_ctx (ctx, pp, *usr_ctx, json);
356  GNUNET_free (json);
357  if (PABC_OK != status)
358  {
359  pabc_free_user_context (ctx, pp, usr_ctx);
360  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n");
361  return GNUNET_SYSERR;
362  }
363 
364  return GNUNET_OK;
365 }
static const char * get_pabcdir()
Definition: pabc_helper.c:62
#define PABC_USR_EXT
Definition: pabc_helper.h:13
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
uint16_t status
See PRISM_STATUS_*-constants.
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:70
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:2147
#define GNUNET_log(kind,...)
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: