Use sideband also for challenge response.
[paraslash.git] / para.h
diff --git a/para.h b/para.h
index 25cbd16ac663a30d15121c15bf3e287a97211c09..5e0501a6d34685a538e0cddbec07c87c2c0785be 100644 (file)
--- a/para.h
+++ b/para.h
@@ -71,6 +71,11 @@ extern __printf_2_3 void (*para_log)(int, const char*, ...);
                vfprintf(stderr, fmt, argp); \
                va_end(argp); \
        }
+/**
+ * Define the standard log function and activate it.
+ *
+ * \param loglevel_barrier See \ref DEFINE_STDERR_LOGGER.
+ */
 #define INIT_STDERR_LOGGING(loglevel_barrier) \
        DEFINE_STDERR_LOGGER(stderr_log, loglevel_barrier); \
        __printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log;
@@ -113,38 +118,9 @@ extern const char *status_item_list[];
 int for_each_stat_item(char *item_buf, size_t num_bytes,
        int (*item_handler)(int, char *));
 
-/**
- * Write a log message to a dynamically allocated string.
- *
- * \param fmt Usual format string.
- * \param p Result pointer.
- *
- * \sa printf(3). */
-#define PARA_VSPRINTF(fmt, p) \
-{ \
-       int n; \
-       size_t size = 100; \
-       p = para_malloc(size); \
-       while (1) { \
-               va_list ap; \
-               /* Try to print in the allocated space. */ \
-               va_start(ap, fmt); \
-               n = vsnprintf(p, size, fmt, ap); \
-               va_end(ap); \
-               /* If that worked, return the string. */ \
-               if (n > -1 && n < size) \
-                       break; \
-               /* Else try again with more space. */ \
-               if (n > -1) /* glibc 2.1 */ \
-                       size = n + 1; /* precisely what is needed */ \
-               else /* glibc 2.0 */ \
-                       size *= 2; /* twice the old size */ \
-               p = para_realloc(p, size); \
-       } \
-}
 
 /**
- *  Return a random non-negative integer in an interval.
+ * Return a random non-negative integer in an interval.
  *
  * \param max Determines maximal possible return value.
  *
@@ -155,6 +131,18 @@ _static_inline_ long int para_random(unsigned max)
        return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
 }
 
+/**
+ * Simple sanity check for I/O vectors.
+ *
+ * \param iov Pointer to the I/O vector to check.
+ *
+ * \return True if \a iov points to a non-empty buffer.
+ */
+_static_inline_ bool iov_valid(const struct iovec *iov)
+{
+       return iov && iov->iov_len > 0 && iov->iov_base;
+}
+
 /** Round up x to next multiple of y. */
 #define ROUND_UP(x, y) ({ \
        const typeof(y) _divisor = y; \