lintian doesn't like orphan packages with uploaders...
[debian/amanda] / common-src / amanda.h
index d03d8bc8605373b586ef0ad85c0a5c643562e803..d44a765545f8c47003605f3e44f5c5799a51488a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1999 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
 #ifndef AMANDA_H
 #define AMANDA_H
 
-#include <glib.h>
-#include <glib/gprintf.h>
-
-#include "amflock.h"
-
 #ifdef HAVE_CONFIG_H
 /* use a relative path here to avoid conflicting with Perl's config.h. */
 #include "../config/config.h"
 #endif
 
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "amflock.h"
+
 /*
  * Force large file source even if configure guesses wrong.
  */
-#ifndef _LARGE_FILE_SOURCE
-#define _LARGE_FILES 1
-#endif
-
 #ifndef _LARGEFILE64_SOURCE
 #define _LARGEFILE64_SOURCE 1
 #endif
@@ -60,8 +57,9 @@
 #  include <sys/types.h>
 #endif
 
-/* gnulib creates this header locally if the system doesn't provide it */
-#include <stdint.h>
+/* gnulib creates this header locally if the system doesn't provide it,
+ * so it uses a local ("") include */
+#include "stdint.h"
 
 /*
  * I would prefer that each Amanda module include only those system headers
@@ -71,9 +69,6 @@
  * Also, some systems put key files in different places, so by including 
  * everything here the rest of the system is isolated from such things.
  */
-#ifdef HAVE_ALLOCA_H
-#  include <alloca.h>
-#endif
 
 /* from the autoconf documentation */
 #ifdef HAVE_DIRENT_H
 #endif
 #endif
 
-#ifdef HAVE_NETDB_H
-#  include <netdb.h>
-#endif
-
 #ifdef TIME_WITH_SYS_TIME
 #  include <sys/time.h>
 #  include <time.h>
@@ -298,14 +289,6 @@ struct iovec {
 #include <sys/resource.h>
 #include <sys/socket.h>
 
-#if !defined(CONFIGURE_TEST)
-#  include "amanda-int.h"
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
 #ifdef WORKING_IPV6
 #define INET6
 #endif
@@ -314,121 +297,6 @@ struct iovec {
 #define INET_ADDRSTRLEN 16
 #endif
 
-/* Calculate the length of the data in a struct sockaddr_storage.
- * THIS IS A HACK.
- *
- * To be truly portable, the length of an address should be passed
- * in a companion variable.  When such lengths are available
- * everywhere they are needed, this macro should be removed.
- */
-#ifdef WORKING_IPV6
-# define SS_LEN(ss) (((struct sockaddr *)(ss))->sa_family==AF_INET6?sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in))
-#else
-# define SS_LEN(ss) (sizeof(struct sockaddr_in))
-#endif
-
-
-/* AF_NATIVE is the "best" address family we support, backward compatible
- * through to AF_INET.
- */
-#ifdef WORKING_IPV6
-#define AF_NATIVE AF_INET6
-#else
-#define AF_NATIVE AF_INET
-#endif
-
-/* SS_INIT(ss, family) initializes ss to all zeroes (as directed by RFC),
- * and sets its ss_family as specified
- */
-#define SS_INIT(ss, family) do { \
-    memset((ss), 0, sizeof(*(ss))); \
-    (ss)->ss_family = (family); \
-} while (0);
-
-/* SS_SET_INADDR_ANY(ss) sets ss to the family-appropriate equivalent of
- * INADDR_ANY, a wildcard address and port.
- */
-#ifdef WORKING_IPV6
-#define SS_SET_INADDR_ANY(ss) do { \
-    switch ((ss)->ss_family) { \
-        case AF_INET6: \
-            ((struct sockaddr_in6 *)(ss))->sin6_flowinfo = 0; \
-            ((struct sockaddr_in6 *)(ss))->sin6_addr = in6addr_any; \
-            break; \
-        case AF_INET: \
-            ((struct sockaddr_in *)(ss))->sin_addr.s_addr = INADDR_ANY; \
-            break; \
-    } \
-} while (0);
-#else
-#define SS_SET_INADDR_ANY(ss) do { \
-    ((struct sockaddr_in *)(ss))->sin_addr.s_addr = INADDR_ANY; \
-} while (0);
-#endif
-
-/* Set/get the port in a sockaddr_storage that already has an family */
-#ifdef WORKING_IPV6
-#define SS_SET_PORT(ss, port) \
-switch ((ss)->ss_family) { \
-    case AF_INET: \
-        ((struct sockaddr_in *)(ss))->sin_port = (in_port_t)htons((port)); \
-        break; \
-    case AF_INET6: \
-        ((struct sockaddr_in6 *)(ss))->sin6_port = (in_port_t)htons((port)); \
-        break; \
-    default: assert(0); \
-}
-#else
-#define SS_SET_PORT(ss, port) \
-        ((struct sockaddr_in *)(ss))->sin_port = (in_port_t)htons((port));
-#endif
-
-#ifdef WORKING_IPV6
-#define SS_GET_PORT(ss) (ntohs( \
-       (ss)->ss_family == AF_INET6? \
-        ((struct sockaddr_in6 *)(ss))->sin6_port \
-       :((struct sockaddr_in *)(ss))->sin_port))
-#else
-#define SS_GET_PORT(ss) (ntohs( \
-        ((struct sockaddr_in *)(ss))->sin_port))
-#endif
-
-/*
- * The dbmalloc package comes from:
- *
- *  http://www.clark.net/pub/dickey/dbmalloc/dbmalloc.tar.gz
- *
- * or
- *
- *  ftp://gatekeeper.dec.com/pub/usenet/comp.sources.misc/volume32/dbmalloc/
- *
- * The following functions are sprinkled through the code, but are
- * disabled unless USE_DBMALLOC is defined:
- *
- *  malloc_enter(char *) -- stack trace for malloc reports
- *  malloc_leave(char *) -- stack trace for malloc reports
- *  malloc_mark(void *) -- mark an area as never to be free-d
- *  malloc_chain_check(void) -- check the malloc area now
- *  malloc_dump(int fd) -- report the malloc contents to a file descriptor
- *  malloc_list(int fd, ulong a, ulong b) -- report memory activated since
- *     history stamp a that is still active as of stamp b (leak check)
- *  malloc_inuse(ulong *h) -- create history stamp h and return the amount
- *     of memory currently in use.
- */
-
-#ifdef USE_DBMALLOC
-#include "dbmalloc.h"
-#else
-#define        malloc_enter(func)              ((void)0)
-#define        malloc_leave(func)              ((void)0)
-#define        malloc_mark(ptr)                ((void)0)
-#define        malloc_chain_check()            ((void)0)
-#define        malloc_dump(fd)                 ((void)0)
-#define        malloc_list(a,b,c)              ((void)0)
-#define        malloc_inuse(hist)              (*(hist) = 0, 0)
-#define        dbmalloc_caller_loc(x,y)        (x)
-#endif
-
 #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC)
 /* quick'n'dirty hack for NextStep31 */
 #  define sa_flags sv_flags
@@ -494,76 +362,6 @@ extern int errno;
 #define stringize(x) #x
 #define stringconcat(x, y) x ## y
 
-/*
- * So that we can use GNUC attributes (such as to get -Wall warnings
- * for printf-like functions).  Only do this in gcc 2.7 or later ...
- * it may work on earlier stuff, but why chance it.
- */
-#if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(S_SPLINT_S) || defined(LINT) || defined(__lint)
-#undef __attribute__
-#define __attribute__(__x)
-#endif
-
-/*
- * assertions, but call error() instead of abort 
- */
-#ifndef ASSERTIONS
-
-#define assert(exp) ((void)0)
-
-#else  /* ASSERTIONS */
-
-#define assert(exp)    do {                                            \
-    if (!(exp)) {                                                      \
-       onerror(abort);                                                 \
-       error("assert: %s false, file %s, line %d",                     \
-          stringize(exp), __FILE__, __LINE__);                         \
-        /*NOTREACHED*/                                                 \
-    }                                                                  \
-} while (0)
-
-#endif /* ASSERTIONS */
-
-/*
- * print debug output, else compile to nothing.
- */
-
-#ifdef DEBUG_CODE                                                      /* { */
-#   define dbopen(a)   debug_open(a)
-#   define dbreopen(a,b) debug_reopen(a,b)
-#   define dbrename(a,b) debug_rename(a,b)
-#   define dbclose()   debug_close()
-#   define dbprintf(p) (debug_printf p)
-#   define dbfd()      debug_fd()
-#   define dbfp()      debug_fp()
-#   define dbfn()      debug_fn()
-
-extern void debug_open(char *subdir);
-extern void debug_reopen(char *file, char *notation);
-extern void debug_rename(char *config, char *subdir);
-extern void debug_close(void);
-extern void debug_printf(const char *format, ...)
-    __attribute__ ((format (printf, 1, 2)));
-extern int  debug_fd(void);
-extern FILE *  debug_fp(void);
-extern char *  debug_fn(void);
-extern void set_debug_prefix_pid(pid_t);
-extern char *debug_prefix(char *);
-extern char *debug_prefix_time(char *);
-#else                                                                  /* }{ */
-#   define dbopen(a)
-#   define dbreopen(a,b)
-#   define dbrename(a,b)
-#   define dbclose()
-#   define dbprintf(p)
-#   define dbfd()      (-1)
-#   define dbfp()      NULL
-#   define dbfn()      NULL
-#   define set_debug_prefix_pid(x)
-#   define debug_prefix(x) get_pname()
-#   define debug_prefix_time(x) get_pname()
-#endif                                                                 /* } */
-
 /* amanda #days calculation, with roundoff */
 
 #define SECS_PER_DAY   (24*60*60)
@@ -593,11 +391,6 @@ extern char *debug_prefix_time(char *);
 #define DISK_BLOCK_KB          32
 #define DISK_BLOCK_BYTES       (DISK_BLOCK_KB * 1024)
 
-/* Maximum size of a tape block */
-/* MAX_TAPE_BLOCK_KB is defined in config.h */
-/* by configure --with-maxtapeblocksize     */
-#define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
-
 /* Maximum length of tape label, plus one for null-terminator. */
 #define MAX_TAPE_LABEL_LEN (10240)
 #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
@@ -658,39 +451,12 @@ char *debug_vstrextend(const char *file, int line, char **oldstr, ...);
 #define agets(f)             debug_agets(__FILE__,__LINE__,(f))
 #define areads(f)            debug_areads(__FILE__,__LINE__,(f))
 
-extern int debug_amtable_alloc(const char *file,
-                                 int line,
-                                 void **table,
-                                 size_t *current,
-                                 size_t elsize,
-                                 size_t count,
-                                 int bump,
-                                 void (*init_func)(void *));
-
-#define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__,      \
-                                                    __LINE__,        \
-                                                    (t),             \
-                                                    (c),             \
-                                                    (s),             \
-                                                    (n),             \
-                                                    (b),             \
-                                                    (f))
-
-extern void amtable_free(void **, size_t *);
-
-char **        safe_env(void);
-char * validate_regexp(const char *regex);
-char * validate_glob(const char *glob);
-char * clean_regex(const char *regex);
-int    match(const char *regex, const char *str);
-int    match_glob(const char *glob, const char *str);
-char * glob_to_regex(const char *glob);
-int    match_tar(const char *glob, const char *str);
-char * tar_to_regex(const char *glob);
-int    match_host(const char *glob, const char *host);
-int    match_disk(const char *glob, const char *disk);
-int    match_datestamp(const char *dateexp, const char *datestamp);
-int    match_level(const char *levelexp, const char *level);
+/* return a "safe" version of the current environment; pass this to execle */
+#define safe_env() safe_env_full(NULL)
+
+/* like safe_env, but optionally add additional environment variables */
+char **        safe_env_full(char **add);
+
 time_t unctime(char *timestr);
 
 /*
@@ -814,15 +580,15 @@ time_t    unctime(char *timestr);
 #define        NUM_STR_SIZE    128             /* a generic number buffer size */
 
 #define        skip_whitespace(ptr,c) do {                                     \
-    while((c) != '\n' && isspace((int)c)) (c) = *(ptr)++;              \
+    while((c) != '\n' && g_ascii_isspace((int)c)) (c) = *(ptr)++;              \
 } while(0)
 
 #define        skip_non_whitespace(ptr,c) do {                                 \
-    while((c) != '\0' && !isspace((int)c)) (c) = *(ptr)++;             \
+    while((c) != '\0' && !g_ascii_isspace((int)c)) (c) = *(ptr)++;             \
 } while(0)
 
 #define        skip_non_whitespace_cs(ptr,c) do {                              \
-    while((c) != '\0' && (c) != '#' && !isspace((int)c)) (c) = *(ptr)++;\
+    while((c) != '\0' && (c) != '#' && !g_ascii_isspace((int)c)) (c) = *(ptr)++;\
 } while(0)
 
 #define        skip_non_integer(ptr,c) do {                                    \
@@ -836,11 +602,12 @@ time_t    unctime(char *timestr);
 
 #define skip_quoted_string(ptr, c) do {                                        \
     int        iq = 0;                                                         \
-    while (((c) != '\0') && !((iq == 0) && isspace((int)c))) {         \
+    while (((c) != '\0') && !((iq == 0) && g_ascii_isspace((int)c))) {         \
        if ((c) == '"') {                                               \
            iq = !iq;                                                   \
-       } else if (((c) == '\\') && (*(ptr) == '"')) {                  \
-           (ptr)++;                                                    \
+       } else if ((c) == '\\') {                                       \
+           if (*ptr)   /* not last character */                        \
+               (ptr)++;                                                \
        }                                                               \
        (c) = *(ptr)++;                                                 \
     }                                                                  \
@@ -866,7 +633,7 @@ time_t      unctime(char *timestr);
 
 #define        copy_string(ptr,c,f,l,fp) do {                                  \
     (fp) = (f);                                                                \
-    while((c) != '\0' && !isspace((int)c)) {                           \
+    while((c) != '\0' && !g_ascii_isspace((int)c)) {                           \
        if((fp) >= (f) + (l) - 1) {                                     \
            *(fp) = '\0';                                               \
            (fp) = NULL;                                                \
@@ -882,7 +649,7 @@ time_t      unctime(char *timestr);
 
 #define        copy_string_cs(ptr,c,f,l,fp) do {                               \
     (fp) = (f);                                                                \
-    while((c) != '\0' && (c) != '#' && !isspace((int)c)) {             \
+    while((c) != '\0' && (c) != '#' && !g_ascii_isspace((int)c)) {             \
        if((fp) >= (f) + (l) - 1) {                                     \
            *(fp) = '\0';                                               \
            (fp) = NULL;                                                \
@@ -1262,9 +1029,15 @@ extern int vfprintf(FILE *stream, const char *format, va_list ap);
 extern int vprintf(const char *format, va_list ap);
 #endif
 
-/* gnulib-only includes (hence "" instead of <>) */
-#include "getaddrinfo.h"
-#include "inet_ntop.h"
+/* these system headers are added by gnulib if they
+ * do not exist */
+#include "netdb.h"
+#include "arpa/inet.h"
+
+/* gnulib-only includes */
+#include "safe-read.h"
+#include "full-read.h"
+#include "full-write.h"
 
 #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
 #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
@@ -1370,68 +1143,6 @@ extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
 #  endif
 #endif
 
-#if SIZEOF_OFF_T == 8
-#  ifdef OFF_MAX
-#    define AM64_MAX (off_t)(OFF_MAX)
-#  else
-#    define AM64_MAX (off_t)(9223372036854775807LL)
-#  endif
-#  ifdef OFF_MIN
-#    define AM64_MIN (off_t)(OFF_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else
-#if SIZEOF_LONG == 8
-#  ifdef LONG_MAX
-#    define AM64_MAX (off_t)(LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807L
-#  endif
-#  ifdef LONG_MIN
-#    define AM64_MIN (off_t)(LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807L -1L)
-#  endif
-#else
-#if SIZEOF_LONG_LONG == 8
-#  ifdef LONG_LONG_MAX
-#    define AM64_MAX (off_t)(LONG_LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807LL
-#  endif
-#  ifdef LONG_LONG_MIN
-#    define AM64_MIN (off_t)(LONG_LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else
-#if SIZEOF_INTMAX_T == 8
-#  ifdef INTMAX_MAX
-#    define AM64_MAX (off_t)(INTMAX_MAX)
-#  else
-#    define AM64_MAX (off_t)9223372036854775807LL
-#  endif
-#  ifdef INTMAX_MIN
-#    define AM64_MIN (off_t)(INTMAX_MIN)
-#  else
-#    define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
-#  endif
-#else  /* no 64 bits type found, use long. */
-#  ifdef LONG_MAX
-#    define AM64_MAX (off_t)(LONG_MAX)
-#  else
-#    define AM64_MAX (off_t)2147483647
-#  endif
-#  ifdef LONG_MIN
-#    define AM64_MIN (off_t)(LONG_MIN)
-#  else
-#    define AM64_MIN (off_t)(-2147483647 -1)
-#  endif
-#endif
-#endif
-#endif
-#endif
 
 #define BIND_CYCLE_RETRIES     120             /* Total of 30 minutes */
 
@@ -1448,4 +1159,13 @@ typedef enum {
     KENCRYPT_YES       /* krb5 encryption enabled on all stream */
 } kencrypt_type;
 
+#define DUMP_LEVELS    400
+
+/* Constants to define the number of pre-opened pipes between amandad and
+ * its services */
+
+/* If you change these (don't!), change them in perl/Amanda/Constants.pm, too */
+#define DATA_FD_COUNT   3               /* number of general-use pipes */
+#define DATA_FD_OFFSET  50
+
 #endif /* !AMANDA_H */