WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
*
* @author Christian Grothoff
* @author Nils Durner
+ * @author Martin Schanzenbach
*
* @defgroup logging Logging
* @see [Documentation](https://gnunet.org/logging)
#endif
#endif
+/**
+ * wrap va_arg for enums
+ */
+#define GNUNET_VA_ARG_ENUM(va,X) ((enum X) va_arg (va, int))
+
+
/**
* @ingroup logging
* define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source
GNUNET_NETWORK_STRUCT_BEGIN
+/**
+ * @brief A 512-bit hashcode. These are the default length for GNUnet, using SHA-512.
+ */
+struct GNUNET_HashCode
+{
+ uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */
+};
+
+
+
+/**
+ * @brief A 256-bit hashcode. Used under special conditions, like when space
+ * is critical and security is not impacted by it.
+ */
+struct GNUNET_ShortHashCode
+{
+ uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */
+};
+
+
+
/**
* Header for all communications.
*/
*/
void
GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
- __attribute__ ((format (gnu_printf, 2, 3)));
+ __attribute__ ((format (printf, 2, 3)));
/* from glib */
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
* @ingroup logging
* Use this for fatal errors that cannot be handled
*/
-#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)
+#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)
/**
* @ingroup logging
* Use this for fatal errors that cannot be handled
*/
-#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)
+#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)
/**
* @param cond Condition to evaluate
* @param comp Component string to use for logging
*/
-#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)
+#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)
/**
*/
#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type))
+
+/**
+ * Compare memory in @a a and @a b, where both must be of
+ * the same pointer type.
+ */
+#define GNUNET_memcmp(a,b) ({ \
+ const typeof(*b) * _a = (a); \
+ const typeof(*a) * _b = (b); \
+ memcmp(_a, \
+ _b, \
+ sizeof (*a)); })
+
+
+/**
+ * Check that memory in @a a is all zeros. @a a must be a pointer.
+ *
+ * @param a pointer to a struct which should be tested for the
+ * entire memory being zero'ed out.
+ */
+#define GNUNET_is_zero(a) ({ \
+ static const typeof(*a) _z; \
+ memcmp((a), \
+ &_z, \
+ sizeof (_z)); })
+
+
/**
* Call memcpy() but check for @a n being 0 first. In the latter
* case, it is now safe to pass NULL for @a src or @a dst.
* @param tsize the target size for the resulting vector, use 0 to
* free the vector (then, arr will be NULL afterwards).
*/
-#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__)
+#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&(arr), sizeof((arr)[0]), &size, tsize, __FILE__, __LINE__)
/**
* @ingroup memory
* array size
* @param element the element that will be appended to the array
*/
-#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
+#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); (arr)[size-1] = element; } while(0)
/**
* @ingroup memory