GNUnet  0.19.5
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.

◆ PABC_USR_EXT

#define PABC_USR_EXT   ".usr"

Definition at line 13 of file pabc_helper.h.

◆ 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 106 of file pabc_helper.c.

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

Referenced by cr_cont().

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 106 of file pabc_helper.c.

138 {
139  char fname[PATH_MAX];
140  char *pp_filename;
141  const char *pdir = get_pabcdir ();
142 
143  if (ctx == NULL)
144  return GNUNET_SYSERR;
145  if (pp_name == NULL)
146  return GNUNET_SYSERR;
147 
148  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
150  {
151  GNUNET_free (pp_filename);
152  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error reading %s\n", pdir);
153  return GNUNET_SYSERR;
154  }
155  snprintf (fname, PATH_MAX, "%s/%s%s", pdir, pp_filename, PABC_PP_EXT);
156  if (GNUNET_YES != GNUNET_DISK_file_test (fname))
157  {
158  GNUNET_free (pp_filename);
159  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error testing %s\n", fname);
160  return GNUNET_SYSERR;
161  }
162  *pp = PABC_read_issuer_ppfile (fname, ctx);
163  if (*pp)
164  return GNUNET_OK;
165  else
166  return GNUNET_SYSERR;
167 }
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:482
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
@ GNUNET_YES
struct pabc_public_parameters * PABC_read_issuer_ppfile(const char *f, struct pabc_context *const ctx)
Definition: pabc_helper.c:106
#define PATH_MAX
Assumed maximum path length.
Definition: platform.h:241

References ctx, removetrailingwhitespace::f, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, and read_file().

Referenced by pabc_create_presentation().

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 106 of file pabc_helper.c.

228 {
229 
230  char *pp_filename;
231  char *json = NULL;
232  enum pabc_status status;
233  char *fname = NULL;
234 
235  if (NULL == usr_name)
236  {
237  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
238  return GNUNET_SYSERR;
239  }
240  if (NULL == pp_name)
241  {
242  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user given.\n");
243  return GNUNET_SYSERR;
244  }
245  if (NULL == ctx)
246  {
247  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No context given.\n");
248  return GNUNET_SYSERR;
249  }
250  if (NULL == pp)
251  {
252  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No public parameters given.\n");
253  return GNUNET_SYSERR;
254  }
255  if (NULL == usr_ctx)
256  {
257  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n");
258  return GNUNET_SYSERR;
259  }
260 
261  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
262  status = pabc_encode_user_ctx (ctx, pp, usr_ctx, &json);
263  if (PABC_OK != status)
264  {
265  GNUNET_free (pp_filename);
266  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n");
267  return status;
268  }
269 
270  size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
271  + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
272  fname = GNUNET_malloc (fname_size);
273 
274  snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
275  pp_filename,
276  PABC_USR_EXT);
277 
278  GNUNET_free (pp_filename);
279  if (GNUNET_OK == write_file (fname, json))
280  {
281  GNUNET_free (fname);
282  GNUNET_free (json);
283  return GNUNET_OK;
284  }
285  else
286  {
287  GNUNET_free (fname);
288  GNUNET_free (json);
289  return GNUNET_SYSERR;
290  }
291 }
#define PABC_USR_EXT
Definition: pabc_helper.h:13

Referenced by cr_cont().

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 106 of file pabc_helper.c.

300 {
301  char *json = NULL;
302  char *pp_filename;
303  enum pabc_status status;
304 
305  char *fname = NULL;
306 
307  if (NULL == usr_name)
308  {
309  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer given.\n");
310  return GNUNET_SYSERR;
311  }
312  if (NULL == pp_name)
313  {
314  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user given.\n");
315  return GNUNET_SYSERR;
316  }
317  if (NULL == ctx)
318  {
319  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No context given.\n");
320  return GNUNET_SYSERR;
321  }
322  if (NULL == pp)
323  {
324  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No public parameters given.\n");
325  return GNUNET_SYSERR;
326  }
327  if (NULL == usr_ctx)
328  {
329  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No user context given.\n");
330  return GNUNET_SYSERR;
331  }
332  GNUNET_STRINGS_urlencode (pp_name, strlen (pp_name), &pp_filename);
333 
334  size_t fname_size = strlen (get_pabcdir ()) + 1 + strlen (usr_name) + 1
335  + strlen (pp_filename) + strlen (PABC_USR_EXT) + 1;
336  fname = GNUNET_malloc (fname_size);
337  snprintf (fname, fname_size, "%s/%s_%s%s", get_pabcdir (), usr_name,
338  pp_filename,
339  PABC_USR_EXT);
340  GNUNET_free (pp_filename);
341  if (GNUNET_OK != read_file (fname, &json))
342  {
344  "Failed to read `%s'\n", fname);
345  PABC_FREE_NULL (fname);
346  return GNUNET_SYSERR;
347  }
348  GNUNET_free (fname);
349 
350  status = pabc_new_user_context (ctx, pp, usr_ctx);
351  if (PABC_OK != status)
352  {
353  GNUNET_free (json);
354  return GNUNET_SYSERR;
355  }
356  status = pabc_decode_user_ctx (ctx, pp, *usr_ctx, json);
357  GNUNET_free (json);
358  if (PABC_OK != status)
359  {
360  pabc_free_user_context (ctx, pp, usr_ctx);
361  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to encode user context.\n");
362  return GNUNET_SYSERR;
363  }
364 
365  return GNUNET_OK;
366 }
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71

Referenced by cr_cont(), and pabc_create_presentation().

Here is the caller graph for this function: