GNUnet  0.11.x
gnunet_common.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006-2021 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
36 #ifndef GNUNET_COMMON_H
37 #define GNUNET_COMMON_H
38 
39 #include <stdlib.h>
40 #if HAVE_SYS_SOCKET_H
41 #include <sys/socket.h>
42 #endif
43 #if HAVE_NETINET_IN_H
44 #include <netinet/in.h>
45 #endif
46 #ifdef HAVE_STDINT_H
47 #include <stdint.h>
48 #endif
49 #ifdef HAVE_STDARG_H
50 #include <stdarg.h>
51 #endif
52 #ifdef HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
57 #endif
58 
59 
60 #ifdef HAVE_BYTESWAP_H
61 #include <byteswap.h>
62 #endif
63 
64 
65 /* This is also included in platform.h, but over there a couple of
66  GNUnet-specific gettext-related macros are defined in addition to including
67  the header file. Because this header file uses gettext, this include
68  statement makes sure gettext macros are defined even when platform.h is
69  unavailable. */
70 #include "gettext.h"
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #if 0 /* keep Emacsens' auto-indent happy */
75 }
76 #endif
77 #endif
78 
82 #define GNUNET_UTIL_VERSION 0x000A0104
83 
84 
92 {
94  GNUNET_NO = 0,
95  GNUNET_OK = 1,
96  /* intentionally identical to #GNUNET_OK! */
98 };
99 
100 
101 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
102 
103 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
104 
105 /* some systems use one underscore only, and mingw uses no underscore... */
106 #ifndef __BYTE_ORDER
107 #ifdef _BYTE_ORDER
108 #define __BYTE_ORDER _BYTE_ORDER
109 #else
110 #ifdef BYTE_ORDER
111 #define __BYTE_ORDER BYTE_ORDER
112 #endif
113 #endif
114 #endif
115 #ifndef __BIG_ENDIAN
116 #ifdef _BIG_ENDIAN
117 #define __BIG_ENDIAN _BIG_ENDIAN
118 #else
119 #ifdef BIG_ENDIAN
120 #define __BIG_ENDIAN BIG_ENDIAN
121 #endif
122 #endif
123 #endif
124 #ifndef __LITTLE_ENDIAN
125 #ifdef _LITTLE_ENDIAN
126 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
127 #else
128 #ifdef LITTLE_ENDIAN
129 #define __LITTLE_ENDIAN LITTLE_ENDIAN
130 #endif
131 #endif
132 #endif
133 
137 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
138 
139 
145 #ifndef GNUNET_EXTRA_LOGGING
146 #define GNUNET_EXTRA_LOGGING 1
147 #endif
148 
153 #if __BYTE_ORDER == __LITTLE_ENDIAN
154 #ifdef HAVE_BYTESWAP_H
155 #define BYTE_SWAP_16(x) bswap_16 (x)
156 #define BYTE_SWAP_32(x) bswap_32 (x)
157 #define BYTE_SWAP_64(x) bswap_64 (x)
158 #else
159 #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
160 
161 #define BYTE_SWAP_32(x) \
162  ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
163  | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
164 
165 #define BYTE_SWAP_64(x) \
166  ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \
167  | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
168  | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
169  | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
170  56))
171 #endif
172 
173 #define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
174 #define GNUNET_htole16(x) (x)
175 #define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
176 #define GNUNET_le16toh(x) (x)
177 
178 #define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
179 #define GNUNET_htole32(x) (x)
180 #define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
181 #define GNUNET_le32toh(x) (x)
182 
183 #define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
184 #define GNUNET_htole64(x) (x)
185 #define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
186 #define GNUNET_le64toh(x) (x)
187 #endif
188 #if __BYTE_ORDER == __BIG_ENDIAN
189 #define GNUNET_htobe16(x) (x)
190 #define GNUNET_htole16(x) BYTE_SWAP_16 (x)
191 #define GNUNET_be16toh(x) (x)
192 #define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
193 
194 #define GNUNET_htobe32(x) (x)
195 #define GNUNET_htole32(x) BYTE_SWAP_32 (x)
196 #define GNUNET_be32toh(x) (x)
197 #define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
198 
199 #define GNUNET_htobe64(x) (x)
200 #define GNUNET_htole64(x) BYTE_SWAP_64 (x)
201 #define GNUNET_be64toh(x) (x)
202 #define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
203 #endif
204 
205 
218 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
219 
220 
224 #define GNUNET_PACKED __attribute__ ((packed))
225 
229 #define GNUNET_GCC_STRUCT_LAYOUT
230 
236 #ifdef __BIGGEST_ALIGNMENT__
237 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
238 #else
239 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
240 #endif
241 
245 #define GNUNET_UNUSED __attribute__ ((unused))
246 
250 #define GNUNET_NORETURN __attribute__ ((noreturn))
251 
255 #define GNUNET_NETWORK_STRUCT_BEGIN
256 
260 #define GNUNET_NETWORK_STRUCT_END
261 
262 /* ************************ super-general types *********************** */
263 
265 
270 {
271  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
272 };
273 
274 
280 {
281  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
282 };
283 
284 
294 {
298  uint32_t value[4];
299 };
300 
301 
306 {
311  uint16_t size GNUNET_PACKED;
312 
316  uint16_t type GNUNET_PACKED;
317 };
318 
319 
324 {
326 
328 
333 
338 
339  /* Followed by data. */
340 };
341 
342 
347 {
348  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
349 };
350 
352 
353 
358 {
363 
368 };
369 
370 
380 typedef enum GNUNET_GenericReturnValue
381 (*GNUNET_FileNameCallback) (void *cls,
382  const char *filename);
383 
384 
390 typedef void
391 (*GNUNET_ContinuationCallback) (void *cls);
392 
393 
406 typedef void
407 (*GNUNET_ResultCallback) (void *cls,
408  int64_t result_code,
409  const void *data,
410  uint16_t data_size);
411 
412 
413 /* ****************************** logging ***************************** */
414 
420 {
425  /* UX: We need a message type that is output by
426  * default without looking like there is a problem.
427  */
433 };
434 
435 
446 typedef void
447 (*GNUNET_Logger) (void *cls,
448  enum GNUNET_ErrorType kind,
449  const char *component,
450  const char *date,
451  const char *message);
452 
453 
460 int
461 GNUNET_get_log_skip (void);
462 
463 
464 #if ! defined(GNUNET_CULL_LOGGING)
465 int
466 GNUNET_get_log_call_status (int caller_level,
467  const char *comp,
468  const char *file,
469  const char *function,
470  int line);
471 
472 #endif
473 
474 
483 void
484 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
485 __attribute__ ((format (printf, 2, 3)));
486 
487 /* from glib */
488 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
489 #define _GNUNET_BOOLEAN_EXPR(expr) \
490  __extension__ ({ \
491  int _gnunet_boolean_var_; \
492  if (expr) \
493  _gnunet_boolean_var_ = 1; \
494  else \
495  _gnunet_boolean_var_ = 0; \
496  _gnunet_boolean_var_; \
497  })
498 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
499 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
500 #else
501 #define GN_LIKELY(expr) (expr)
502 #define GN_UNLIKELY(expr) (expr)
503 #endif
504 
505 #if ! defined(GNUNET_LOG_CALL_STATUS)
506 #define GNUNET_LOG_CALL_STATUS -1
507 #endif
508 
509 
520 void
522  const char *comp,
523  const char *message,
524  ...)
525 __attribute__ ((format (printf, 3, 4)));
526 
527 #if ! defined(GNUNET_CULL_LOGGING)
528 #define GNUNET_log_from(kind, comp, ...) \
529  do \
530  { \
531  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
532  if ((GNUNET_EXTRA_LOGGING > 0) || \
533  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
534  { \
535  if (GN_UNLIKELY (log_call_enabled == -1)) \
536  log_call_enabled = \
537  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
538  (comp), \
539  __FILE__, \
540  __FUNCTION__, \
541  __LINE__); \
542  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
543  { \
544  GNUNET_log_skip (-1, GNUNET_NO); \
545  } \
546  else \
547  { \
548  if (GN_UNLIKELY (log_call_enabled)) \
549  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
550  } \
551  } \
552  } while (0)
553 
554 #define GNUNET_log(kind, ...) \
555  do \
556  { \
557  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
558  if ((GNUNET_EXTRA_LOGGING > 0) || \
559  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
560  { \
561  if (GN_UNLIKELY (log_call_enabled == -1)) \
562  log_call_enabled = \
563  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
564  NULL, \
565  __FILE__, \
566  __FUNCTION__, \
567  __LINE__); \
568  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
569  { \
570  GNUNET_log_skip (-1, GNUNET_NO); \
571  } \
572  else \
573  { \
574  if (GN_UNLIKELY (log_call_enabled)) \
575  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
576  } \
577  } \
578  } while (0)
579 #else
580 #define GNUNET_log(...)
581 #define GNUNET_log_from(...)
582 #endif
583 
584 
593 void
595  const char *section,
596  const char *option);
597 
598 
608 void
610  const char *section,
611  const char *option,
612  const char *required);
613 
614 
621 void
623 
624 
632 void
633 GNUNET_log_skip (int n, int check_reset);
634 
635 
645 int
646 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
647 
648 
659 void
660 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
661 
662 
670 void
671 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
672 
673 
683 const char *
684 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
685 
686 
696 const char *
697 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
698 
699 
709 const char *
710 GNUNET_h2s (const struct GNUNET_HashCode *hc);
711 
712 
724 const char *
725 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
726 
727 
738 const char *
739 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
740 
741 
746 
747 
752 
753 
763 const char *
765 
766 
776 const char *
778 
779 
789 const char *
791 
792 
802 const char *
804 
805 
809 struct GNUNET_PeerIdentity;
810 
811 
822 const char *
823 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
824 
825 
838 const char *
839 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
840 
841 
852 const char *
853 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
854 
855 
867 const char *
868 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
869 
870 
878 const char *
880 
881 
886 #if __GNUC__ >= 6 || __clang_major__ >= 6
887 #define GNUNET_assert(cond) \
888  do \
889  { \
890  _Pragma("GCC diagnostic push") \
891  _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
892  if (! (cond)) \
893  { \
894  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
895  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
896  __FILE__, \
897  __LINE__); \
898  GNUNET_abort_ (); \
899  } \
900  _Pragma("GCC diagnostic pop") \
901  } while (0)
902 #else
903 /* older GCC/clangs do not support -Wtautological-compare */
904 #define GNUNET_assert(cond) \
905  do \
906  { \
907  if (! (cond)) \
908  { \
909  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
910  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
911  __FILE__, \
912  __LINE__); \
913  GNUNET_abort_ (); \
914  } \
915  } while (0)
916 #endif
917 
922 #define GNUNET_assert_at(cond, f, l) \
923  do \
924  { \
925  if (! (cond)) \
926  { \
927  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
928  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
929  f, \
930  l); \
931  GNUNET_abort_ (); \
932  } \
933  } while (0)
934 
935 
943 #define GNUNET_assert_from(cond, comp) \
944  do \
945  { \
946  if (! (cond)) \
947  { \
948  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
949  comp, \
950  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
951  __FILE__, \
952  __LINE__); \
953  GNUNET_abort_ (); \
954  } \
955  } while (0)
956 
957 
958 #if HAVE_STATIC_ASSERT
966 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
967 #else
976 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
977 #endif
978 
979 
985 #define GNUNET_break(cond) \
986  do \
987  { \
988  if (! (cond)) \
989  { \
990  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
991  dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
992  __FILE__, \
993  __LINE__); \
994  } \
995  } while (0)
996 
997 
1007 #define GNUNET_break_op(cond) \
1008  do \
1009  { \
1010  if (! (cond)) \
1011  { \
1012  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1013  dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \
1014  __FILE__, \
1015  __LINE__); \
1016  } \
1017  } while (0)
1018 
1019 
1026 #define GNUNET_log_strerror(level, cmd) \
1027  do \
1028  { \
1029  GNUNET_log (level, \
1030  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1031  cmd, \
1032  __FILE__, \
1033  __LINE__, \
1034  strerror (errno)); \
1035  } while (0)
1036 
1037 
1044 #define GNUNET_log_from_strerror(level, component, cmd) \
1045  do \
1046  { \
1047  GNUNET_log_from (level, \
1048  component, \
1049  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1050  cmd, \
1051  __FILE__, \
1052  __LINE__, \
1053  strerror (errno)); \
1054  } while (0)
1055 
1056 
1063 #define GNUNET_log_strerror_file(level, cmd, filename) \
1064  do \
1065  { \
1066  GNUNET_log (level, \
1067  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1068  cmd, \
1069  filename, \
1070  __FILE__, \
1071  __LINE__, \
1072  strerror (errno)); \
1073  } while (0)
1074 
1075 
1082 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1083  do \
1084  { \
1085  GNUNET_log_from (level, \
1086  component, \
1087  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1088  cmd, \
1089  filename, \
1090  __FILE__, \
1091  __LINE__, \
1092  strerror (errno)); \
1093  } while (0)
1094 
1095 /* ************************* endianness conversion ****************** */
1096 
1097 #ifdef htonbe64
1098 
1099 #define GNUNET_htonll(n) htobe64 (n)
1100 
1101 #else
1110 uint64_t
1111 GNUNET_htonll (uint64_t n);
1112 
1113 #endif
1114 
1115 
1116 #ifdef be64toh
1117 
1118 #define GNUNET_ntohll(n) be64toh (n)
1119 
1120 #else
1129 uint64_t
1130 GNUNET_ntohll (uint64_t n);
1131 
1132 #endif
1133 
1134 
1143 double
1144 GNUNET_hton_double (double d);
1145 
1146 
1155 double
1156 GNUNET_ntoh_double (double d);
1157 
1158 
1159 /* ************************* allocation functions ****************** */
1160 
1165 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1166 
1175 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1176 
1177 
1185 #define GNUNET_memcmp(a, b) \
1186  ({ \
1187  const typeof (*b) * _a = (a); \
1188  const typeof (*a) * _b = (b); \
1189  memcmp (_a, _b, sizeof(*a)); \
1190  })
1191 
1192 
1202 int
1203 GNUNET_memcmp_ct_ (const void *b1,
1204  const void *b2,
1205  size_t len);
1206 
1214 #define GNUNET_memcmp_priv(a, b) \
1215  ({ \
1216  const typeof (*b) * _a = (a); \
1217  const typeof (*a) * _b = (b); \
1218  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1219  })
1220 
1221 
1231 GNUNET_is_zero_ (const void *a,
1232  size_t n);
1233 
1234 
1242 #define GNUNET_is_zero(a) \
1243  GNUNET_is_zero_ (a, sizeof (*a))
1244 
1245 
1255 #define GNUNET_memcpy(dst, src, n) \
1256  do \
1257  { \
1258  if (0 != n) \
1259  { \
1260  (void) memcpy (dst, src, n); \
1261  } \
1262  } while (0)
1263 
1264 
1274 #define GNUNET_new_array(n, type) ({ \
1275  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1276  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1277  })
1278 
1288 #define GNUNET_new_array_2d(n, m, type) \
1289  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1290 
1301 #define GNUNET_new_array_3d(n, m, o, type) \
1302  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1303 
1313 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1314 
1323 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1324 
1333 #define GNUNET_malloc_large(size) \
1334  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1335 
1336 
1346 #define GNUNET_realloc(ptr, size) \
1347  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1348 
1349 
1359 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1360 
1361 
1373 #define GNUNET_free(ptr) do { \
1374  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1375  ptr = NULL; \
1376 } while (0)
1377 
1378 
1387 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1388 
1398 #define GNUNET_strndup(a, length) \
1399  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1400 
1436 #define GNUNET_array_grow(arr, size, tsize) \
1437  GNUNET_xgrow_ ((void **) &(arr), \
1438  sizeof((arr)[0]), \
1439  &size, \
1440  tsize, \
1441  __FILE__, \
1442  __LINE__)
1443 
1457 #define GNUNET_array_append(arr, len, element) \
1458  do \
1459  { \
1460  GNUNET_assert ((len) + 1 > (len)); \
1461  GNUNET_array_grow (arr, len, len + 1); \
1462  (arr) [len - 1] = element; \
1463  } while (0)
1464 
1465 
1489 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1490  do \
1491  { \
1492  const typeof (*arr2) * _a1 = (arr1); \
1493  const typeof (*arr1) * _a2 = (arr2); \
1494  GNUNET_assert ((len1) + (len2) >= (len1)); \
1495  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1496  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1497  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1498  } while (0)
1499 
1500 
1511 int
1513  size_t size,
1514  const char *format,
1515  ...)
1516 __attribute__ ((format (printf, 3, 4)));
1517 
1518 
1528 int
1530  const char *format,
1531  ...)
1532 __attribute__ ((format (printf, 2, 3)));
1533 
1534 
1535 /* ************** internal implementations, use macros above! ************** */
1536 
1548 void *
1549 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1550 
1551 
1566 void **
1567 GNUNET_xnew_array_2d_ (size_t n,
1568  size_t m,
1569  size_t elementSize,
1570  const char *filename,
1571  int linenumber);
1572 
1573 
1589 void ***
1590 GNUNET_xnew_array_3d_ (size_t n,
1591  size_t m,
1592  size_t o,
1593  size_t elementSize,
1594  const char *filename,
1595  int linenumber);
1596 
1597 
1609 void *
1610 GNUNET_xmemdup_ (const void *buf,
1611  size_t size,
1612  const char *filename,
1613  int linenumber);
1614 
1615 
1628 void *
1629 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1630 
1631 
1636 void *
1637 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1638 
1639 
1649 void
1650 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1651 
1652 
1660 char *
1661 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1662 
1672 char *
1673 GNUNET_xstrndup_ (const char *str,
1674  size_t len,
1675  const char *filename,
1676  int linenumber);
1677 
1693 void
1694 GNUNET_xgrow_ (void **old,
1695  size_t elementSize,
1696  unsigned int *oldCount,
1697  unsigned int newCount,
1698  const char *filename,
1699  int linenumber);
1700 
1701 
1709 struct GNUNET_MessageHeader *
1711 
1712 
1719 void
1721  struct GNUNET_AsyncScopeSave *old_scope);
1722 
1723 
1729 void
1731 
1732 
1738 void
1739 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1740 
1741 
1747 void
1749 
1750 
1751 #if __STDC_VERSION__ < 199901L
1752 #if __GNUC__ >= 2
1753 #define __func__ __FUNCTION__
1754 #else
1755 #define __func__ "<unknown>"
1756 #endif
1757 #endif
1758 
1759 
1768 {
1773 
1778 
1784 
1792 
1798 
1804 
1812 
1822 
1828 };
1829 
1830 
1831 #if 0 /* keep Emacsens' auto-indent happy */
1832 {
1833 #endif
1834 #ifdef __cplusplus
1835 }
1836 #endif
1837 
1838 #endif /* GNUNET_COMMON_H */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char * component
Running component.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static char * line
Desired phone line (string to be converted to a hash).
static char * filename
uint32_t data
The data value.
enum RadiotapType __attribute__
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char buf[2048]
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
enum GNUNET_GenericReturnValue GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
int GNUNET_memcmp_ct_(const void *b1, const void *b2, size_t len)
Compare memory in b1 and b2 in constant time, suitable for private data.
void(* GNUNET_ResultCallback)(void *cls, int64_t result_code, const void *data, uint16_t data_size)
Function called with the result of an asynchronous operation.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:92
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate memory.
void ** GNUNET_xnew_array_2d_(size_t n, size_t m, size_t elementSize, const char *filename, int linenumber)
Allocate memory for a two dimensional array in one block and set up pointers.
#define GNUNET_NORETURN
gcc-ism to document functions that don't return
void GNUNET_xgrow_(void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber)
Grow an array, the new elements are zeroed out.
void(* GNUNET_ContinuationCallback)(void *cls)
Generic continuation callback.
int int void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
int GNUNET_get_log_call_status(int caller_level, const char *comp, const char *file, const char *function, int line)
Decides whether a particular logging call should or should not be allowed to be made.
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
GNUNET_SCHEDULER_Priority
Valid task priorities.
@ GNUNET_SCHEDULER_PRIORITY_UI
Run with priority for interactive tasks.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_SCHEDULER_PRIORITY_URGENT
Run with priority for urgent tasks.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_SCHEDULER_PRIORITY_COUNT
Number of priorities (must be the last priority).
@ GNUNET_SCHEDULER_PRIORITY_KEEP
Run with the same priority as the current job.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_SCHEDULER_PRIORITY_SHUTDOWN
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:74
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
void * GNUNET_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
void *** GNUNET_xnew_array_3d_(size_t n, size_t m, size_t o, size_t elementSize, const char *filename, int linenumber)
Allocate memory for a three dimensional array in one block and set up pointers.
void GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret)
Generate a fresh async scope identifier.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread's async scope.
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_PACKED
gcc-ism to get packed structs.
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
GNUNET_ErrorType
Types of errors.
const char * GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_uuid2s(const struct GNUNET_Uuid *uuid)
Convert a UUID to a string (for printing debug messages).
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
Main log function.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
void GNUNET_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_abort_(void) __attribute__((noreturn))
Abort the process, generate a core dump if possible.
void GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls)
Add a custom logger.
void(* GNUNET_Logger)(void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
User-defined handler for log messages.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
void GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
Remove a custom logger.
@ GNUNET_ERROR_TYPE_UNSPECIFIED
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_NONE
@ GNUNET_ERROR_TYPE_INVALID
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Identifier for an asynchronous execution context.
uint32_t bits[16/sizeof(uint32_t)]
Saved async scope identifier or root scope.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
struct GNUNET_AsyncScopeId scope_id
Saved scope.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
A 512-bit hashcode.
uint32_t bits[512/8/sizeof(uint32_t)]
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Answer from service to client about last operation.
struct GNUNET_MessageHeader header
uint64_t result_code
Status code for the operation.
uint64_t op_id
Operation ID.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
uint32_t bits[256/8/sizeof(uint32_t)]
A UUID, a 128 bit "random" value.
uint32_t value[4]
128 random bits.