-fix
[oweals/gnunet.git] / src / include / gnunet_common.h
index 7e6d20b157b9923876f48d0a17a2a0ef7501c10e..141df1a5dba8ed58556299d6272f73662f0ba05b 100644 (file)
@@ -49,7 +49,7 @@
 /**
  * Version of the API (for entire gnunetutil.so library).
  */
-#define GNUNET_UTIL_VERSION 0x00090100
+#define GNUNET_UTIL_VERSION 0x00090200
 
 /**
  * Named constants for return values.  The following
 
 #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b))
 
-/* some systems use one underscore only... */
+/* some systems use one underscore only, and mingw uses no underscore... */
 #ifndef __BYTE_ORDER
 #ifdef _BYTE_ORDER
 #define __BYTE_ORDER _BYTE_ORDER
+#else
+#ifdef BYTE_ORDER
+#define __BYTE_ORDER BYTE_ORDER
+#endif
 #endif
 #endif
 #ifndef __BIG_ENDIAN
 #ifdef _BIG_ENDIAN
 #define __BIG_ENDIAN _BIG_ENDIAN
+#else
+#ifdef BIG_ENDIAN
+#define __BIG_ENDIAN BIG_ENDIAN
+#endif
 #endif
 #endif
 #ifndef __LITTLE_ENDIAN
 #ifdef _LITTLE_ENDIAN
 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#else
+#ifdef LITTLE_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
 #endif
 #endif
 
  */
 #define GNUNET_PACKED __attribute__((packed))
 
+/**
+ * gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
+ */
+#if MINGW
+#define GNUNET_GCC_STRUCT_LAYOUT __attribute__((gcc_struct))
+#else
+#define GNUNET_GCC_STRUCT_LAYOUT
+#endif
+
 /**
  * gcc-ism to document unused arguments
  */
@@ -187,27 +208,25 @@ struct GNUNET_MessageHeader
   uint16_t type GNUNET_PACKED;
 
 };
-GNUNET_NETWORK_STRUCT_END
+
 
 /**
  * @brief 512-bit hashcode
  */
-typedef struct
+typedef struct GNUNET_HashCode
 {
   uint32_t bits[512 / 8 / sizeof (uint32_t)];   /* = 16 */
 }
 GNUNET_HashCode;
 
 
-GNUNET_NETWORK_STRUCT_BEGIN
-
 /**
  * The identity of the host (basically the SHA-512 hashcode of
  * it's public key).
  */
 struct GNUNET_PeerIdentity
 {
-  GNUNET_HashCode hashPubKey GNUNET_PACKED;
+  GNUNET_HashCode hashPubKey;
 };
 GNUNET_NETWORK_STRUCT_END
 
@@ -312,23 +331,27 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
 #if !defined(GNUNET_CULL_LOGGING)
 #define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\
   static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
-  if (GN_UNLIKELY(log_call_enabled == -1))\
-    log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), comp, __FILE__, __FUNCTION__, log_line);\
-  if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
-  else {\
-    if (GN_UNLIKELY(log_call_enabled))\
-      GNUNET_log_from_nocheck (kind, comp, __VA_ARGS__);\
+  if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
+    if (GN_UNLIKELY(log_call_enabled == -1))\
+      log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), (comp), __FILE__, __FUNCTION__, log_line); \
+    if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
+    else {\
+      if (GN_UNLIKELY(log_call_enabled))\
+        GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__);   \
+    }\
   }\
 } while (0)
 
 #define GNUNET_log(kind,...) do { int log_line = __LINE__;\
   static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
-  if (GN_UNLIKELY(log_call_enabled == -1))\
-    log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\
-  if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
-  else {\
-    if (GN_UNLIKELY(log_call_enabled))\
-      GNUNET_log_nocheck (kind, __VA_ARGS__);\
+  if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
+    if (GN_UNLIKELY(log_call_enabled == -1))\
+      log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\
+    if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
+    else {\
+      if (GN_UNLIKELY(log_call_enabled))\
+        GNUNET_log_nocheck ((kind), __VA_ARGS__);      \
+    }\
   }\
 } while (0)
 #else
@@ -422,6 +445,17 @@ GNUNET_h2s_full (const GNUNET_HashCode * hc);
 const char *
 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
 
+/**
+ * Convert a peer identity to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param pid the peer identity
+ * @return string form of the pid; will be overwritten by next
+ *         call to GNUNET_i2s.
+ */
+const char *
+GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
 
 /**
  * Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string