aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r--src/include/gnunet_common.h104
1 files changed, 86 insertions, 18 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 0fb39575c..1b982cc15 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2013 GNUnet e.V. 3 Copyright (C) 2006-2013 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -26,6 +24,7 @@
26 * 24 *
27 * @author Christian Grothoff 25 * @author Christian Grothoff
28 * @author Nils Durner 26 * @author Nils Durner
27 * @author Martin Schanzenbach
29 * 28 *
30 * @defgroup logging Logging 29 * @defgroup logging Logging
31 * @see [Documentation](https://gnunet.org/logging) 30 * @see [Documentation](https://gnunet.org/logging)
@@ -114,6 +113,11 @@ extern "C"
114#endif 113#endif
115 114
116/** 115/**
116 * wrap va_arg for enums
117 */
118#define GNUNET_VA_ARG_ENUM(va,X) ((enum X) va_arg (va, int))
119
120/**
117 * @ingroup logging 121 * @ingroup logging
118 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source 122 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source
119 * tree where gnunet_config.h is unavailable 123 * tree where gnunet_config.h is unavailable
@@ -592,7 +596,7 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
592 * @return string 596 * @return string
593 */ 597 */
594const char * 598const char *
595GNUNET_h2s (const struct GNUNET_HashCode * hc); 599GNUNET_h2s (const struct GNUNET_HashCode *hc);
596 600
597 601
598/** 602/**
@@ -607,7 +611,7 @@ GNUNET_h2s (const struct GNUNET_HashCode * hc);
607 * @return string 611 * @return string
608 */ 612 */
609const char * 613const char *
610GNUNET_h2s2 (const struct GNUNET_HashCode * hc); 614GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
611 615
612 616
613/** 617/**
@@ -621,7 +625,71 @@ GNUNET_h2s2 (const struct GNUNET_HashCode * hc);
621 * @return string 625 * @return string
622 */ 626 */
623const char * 627const char *
624GNUNET_h2s_full (const struct GNUNET_HashCode * hc); 628GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
629
630
631/**
632 * Public key. Details in gnunet_util_crypto.h.
633 */
634struct GNUNET_CRYPTO_EddsaPublicKey;
635
636
637/**
638 * Public key. Details in gnunet_util_crypto.h.
639 */
640struct GNUNET_CRYPTO_EcdhePublicKey;
641
642
643/**
644 * @ingroup logging
645 * Convert a public key value to a string (for printing debug messages).
646 * This is one of the very few calls in the entire API that is
647 * NOT reentrant!
648 *
649 * @param hc the hash code
650 * @return string
651 */
652const char *
653GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p);
654
655
656/**
657 * @ingroup logging
658 * Convert a public key value to a string (for printing debug messages).
659 * This is one of the very few calls in the entire API that is
660 * NOT reentrant!
661 *
662 * @param hc the hash code
663 * @return string
664 */
665const char *
666GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p);
667
668
669/**
670 * @ingroup logging
671 * Convert a public key value to a string (for printing debug messages).
672 * This is one of the very few calls in the entire API that is
673 * NOT reentrant!
674 *
675 * @param hc the hash code
676 * @return string
677 */
678const char *
679GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p);
680
681
682/**
683 * @ingroup logging
684 * Convert a public key value to a string (for printing debug messages).
685 * This is one of the very few calls in the entire API that is
686 * NOT reentrant!
687 *
688 * @param hc the hash code
689 * @return string
690 */
691const char *
692GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p);
625 693
626 694
627/** 695/**
@@ -699,14 +767,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
699 * @ingroup logging 767 * @ingroup logging
700 * Use this for fatal errors that cannot be handled 768 * Use this for fatal errors that cannot be handled
701 */ 769 */
702#define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort_(); } } while(0) 770#define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d. Aborting.\n"), __FILE__, __LINE__); GNUNET_abort_(); } } while(0)
703 771
704 772
705/** 773/**
706 * @ingroup logging 774 * @ingroup logging
707 * Use this for fatal errors that cannot be handled 775 * Use this for fatal errors that cannot be handled
708 */ 776 */
709#define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); GNUNET_abort_(); } } while(0) 777#define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d. Aborting.\n"), f, l); GNUNET_abort_(); } } while(0)
710 778
711 779
712/** 780/**
@@ -716,7 +784,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
716 * @param cond Condition to evaluate 784 * @param cond Condition to evaluate
717 * @param comp Component string to use for logging 785 * @param comp Component string to use for logging
718 */ 786 */
719#define GNUNET_assert_from(cond, comp) do { if (! (cond)) { GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, comp, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort_(); } } while(0) 787#define GNUNET_assert_from(cond, comp) do { if (! (cond)) { GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, comp, _("Assertion failed at %s:%d. Aborting.\n"), __FILE__, __LINE__); GNUNET_abort_(); } } while(0)
720 788
721 789
722/** 790/**
@@ -1006,7 +1074,7 @@ GNUNET_ntoh_double (double d);
1006 * @param tsize the target size for the resulting vector, use 0 to 1074 * @param tsize the target size for the resulting vector, use 0 to
1007 * free the vector (then, arr will be NULL afterwards). 1075 * free the vector (then, arr will be NULL afterwards).
1008 */ 1076 */
1009#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__) 1077#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&(arr), sizeof((arr)[0]), &size, tsize, __FILE__, __LINE__)
1010 1078
1011/** 1079/**
1012 * @ingroup memory 1080 * @ingroup memory
@@ -1021,7 +1089,7 @@ GNUNET_ntoh_double (double d);
1021 * array size 1089 * array size
1022 * @param element the element that will be appended to the array 1090 * @param element the element that will be appended to the array
1023 */ 1091 */
1024#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0) 1092#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); (arr)[size-1] = element; } while(0)
1025 1093
1026/** 1094/**
1027 * @ingroup memory 1095 * @ingroup memory