/*
- * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
-/** \file para.h global paraslash definitions */
+/** \file adu.h \brief Global definitions. */
#include <sys/stat.h>
#include <fcntl.h>
-#include <sys/wait.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* time(), localtime() */
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
-#include <ctype.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/un.h> /* needed by create_pf_socket */
+#include <inttypes.h>
#include <string.h>
#include <assert.h>
#include <osl.h>
#include "gcc-compat.h"
-
-/** used in various contexts */
-#define MAXLINE 255
-
-/** compute the minimum of \a a and \a b */
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-/** compute the maximum of \a a and \a b */
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/** compute the absolute value of \a a */
-#define ABS(a) ((a) > 0 ? (a) : -(a))
+#include "portable_io.h"
/** debug loglevel, gets really noisy */
#define DEBUG 1
#endif
/** \endcond */
+/** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
+#define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
+
+/** The columns of the directory table. */
+enum dir_table_columns {
+ /** The name of the directory. */
+ DT_NAME,
+ /** The dir count number. */
+ DT_NUM,
+ /** The number of the parent directory. */
+ DT_PARENT_NUM,
+ /** The number of bytes of all regular files. */
+ DT_BYTES,
+ /** The number of all regular files. */
+ DT_FILES,
+ /** Number of columns in this table. */
+ NUM_DT_COLUMNS
+};
+
+extern struct osl_table *dir_table;
+
+/** The adu command line options. */
+extern struct gengetopt_args_info conf;
+
+/** Computed database dir. */
+extern char *database_dir;
+
/**
- * define a standard log function that always writes to stderr
- *
- * \param loglevel_barrier If the loglevel of the current message
- * is less than that, the message is going to be ignored.
+ * The select command line options.
*
+ * Either given at the command line, or via the \a set command
+ * in interactive mode.
*/
-#define INIT_STDERR_LOGGING(loglevel_barrier) \
- __printf_2_3 void __log(int ll, const char* fmt,...) \
- { \
- va_list argp; \
- if (ll < loglevel_barrier) \
- return; \
- va_start(argp, fmt); \
- vfprintf(stderr, fmt, argp); \
- va_end(argp); \
- }
-
-/** version text used by various commands if -V switch was given */
-#define VERSION_TEXT(prefix) "para_" prefix " " PACKAGE_VERSION " (" CODENAME ")" "\n" \
- "Copyright (C) 2008 Andre Noll\n" \
- "This is free software with ABSOLUTELY NO WARRANTY." \
- " See COPYING for details.\n" \
- "Written by Andre Noll.\n" \
- "Report bugs to <maan@systemlinux.org>.\n"
-
-/** print out \p VERSION_TEXT and exit if version flag was given */
-#define HANDLE_VERSION_FLAG(_prefix, _args_info_struct) \
- if (_args_info_struct.version_given) { \
- printf("%s", VERSION_TEXT(_prefix)); \
- exit(EXIT_SUCCESS); \
- }
-/** sent by para_server for commands that expect a data file */
-#define AWAITING_DATA_MSG "\nAwaiting Data."
-/** sent by para_server if authentication was successful */
-#define PROCEED_MSG "\nProceed.\n"
-/** length of the \p PROCEED_MSG string */
-#define PROCEED_MSG_LEN strlen(PROCEED_MSG)
-/** sent by para_client to indicate the end of the command line */
-#define EOC_MSG "\nEnd of Command."
-/** sent by para_client, followed by the decrypted challenge number */
-#define CHALLENGE_RESPONSE_MSG "challenge_response:"
-
-/* exec */
-int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds);
-
-/* time */
-int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff);
-long unsigned tv2ms(const struct timeval*);
-void d2tv(double, struct timeval*);
-void tv_add(const struct timeval*, const struct timeval *, struct timeval *);
-void tv_scale(const unsigned long, const struct timeval *, struct timeval *);
-void tv_divide(const unsigned long divisor, const struct timeval *tv,
- struct timeval *result);
-int tv_convex_combination(const long a, const struct timeval *tv1,
- const long b, const struct timeval *tv2,
- struct timeval *result);
-void ms2tv(const long unsigned n, struct timeval *tv);
-void compute_chunk_time(long unsigned chunk_num,
- struct timeval *chunk_tv, struct timeval *stream_start,
- struct timeval *result);
-
-__printf_2_3 void __log(int, const char*, ...);
+extern struct select_args_info select_conf;
/**
- * Write a log message to a dynamically allocated string.
+ * Compare two osl objects pointing to unsigned integers of 64 bit size.
*
- * \param fmt Usual format string.
- * \param p Result pointer.
+ * \param obj1 Pointer to the first integer.
+ * \param obj2 Pointer to the second integer.
*
- * \sa printf(3). */
-#define 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 The values required for an osl compare function.
+ *
+ * \sa osl_compare_func, osl_hash_compare().
+ */
+_static_inline_ int uint64_compare(const struct osl_object *obj1,
+ const struct osl_object *obj2)
+{
+ uint64_t d1 = read_u64((const char *)obj1->data);
+ uint64_t d2 = read_u64((const char *)obj2->data);
+
+ if (d1 < d2)
+ return 1;
+ if (d1 > d2)
+ return -1;
+ return 0;
}
/**
- * Return a random non-negative integer in an interval.
+ * Compare the size of two directories
*
- * \param max Determines maximal possible return value.
+ * \param obj1 Pointer to the first object.
+ * \param obj2 Pointer to the second object.
*
- * \return An integer between zero and \p max - 1, inclusively.
+ * This function first compares the size values as usual integers. If they compare as
+ * equal, the address of \a obj1 and \a obj2 are compared. So this compare function
+ * returns zero if and only if \a obj1 and \a obj2 point to the same memory area.
*/
-static inline long int para_random(unsigned max)
+_static_inline_ int size_compare(const struct osl_object *obj1, const struct osl_object *obj2)
{
- return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
+ uint64_t d1 = *(uint64_t *)obj1->data;
+ uint64_t d2 = *(uint64_t *)obj2->data;
+ int ret = NUM_COMPARE(d2, d1);
+
+ if (ret)
+ return ret;
+ //INFO_LOG("addresses: %p, %p\n", obj1->data, obj2->data);
+ return NUM_COMPARE(obj2->data, obj1->data);
}
-/** Round up x to a multiple of y */
-#define ROUND_UP(x, y) (((x) + ((y) - 1) / (y)) * (y))
-
-/** Get the size of an array */
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-/**
- * Wrapper for isspace.
- * NetBSD needs this.
- */
-/*
- * The values should be cast to an unsigned char first, then to int.
- * Why? Because the isdigit (as do all other is/to functions/macros)
- * expect a number from 0 upto and including 255 as their (int) argument.
- * Because char is signed on most systems, casting it to int immediately
- * gives the functions an argument between -128 and 127 (inclusive),
- * which they will use as an array index, and which will thus fail
- * horribly for characters which have their most significant bit set.
- */
-#define para_isspace(c) isspace((int)(unsigned char)(c))
+/* adu.c */
+__printf_2_3 void __log(int, const char*, ...);
+int open_dir_table(int create);
+void check_signals(void);
+/* create.c */
+int com_create(void);
+
+/* interactive.c */
+void print_interactive_help(void);
+int com_interactive(void);