Some memory allocation improvements
[rsync.git] / loadparm.c
index eaa15d7de2cc921f3326cddc8593566544f7f16a..819888c5d35c9cb061333658c1823d2ab5229a76 100644 (file)
@@ -30,7 +30,7 @@
  * 1) add it to the global_vars or local_vars structure definition
  * 2) add it to the parm_table
  * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
- * 4) initialise it in the Defaults static stucture
+ * 4) initialise it in the Defaults static structure
  *
  * Notes:
  *   The configuration file is processed sequentially for speed. For this
@@ -42,6 +42,8 @@
 
 #include "rsync.h"
 #include "itypes.h"
+#include "ifuncs.h"
+#include "default-dont-compress.h"
 
 extern item_list dparam_list;
 
@@ -52,10 +54,6 @@ extern item_list dparam_list;
 #define LOG_DAEMON 0
 #endif
 
-#define DEFAULT_DONT_COMPRESS "*.gz *.zip *.z *.rpm *.deb *.iso *.bz2" \
-       " *.t[gb]z *.7z *.mp[34] *.mov *.avi *.ogg *.jpg *.jpeg *.png" \
-       " *.lzo *.rzip *.lzma *.rar *.ace *.gpg *.xz *.txz *.lz *.tlz"
-
 /* the following are used by loadparm for option lists */
 typedef enum {
        P_BOOL, P_BOOLREV, P_CHAR, P_INTEGER,
@@ -110,17 +108,20 @@ typedef struct {
 
        int listen_backlog;
        int rsync_port;
+
+       BOOL proxy_protocol;
 } global_vars;
 
 /* This structure describes a single section.  Their order must match the
  * initializers below, which you can accomplish by keeping each sub-section
  * sorted.  (e.g. in vim, just visually select each subsection and use !sort.)
- * NOTE: the char* variables MUST all remain at the start of the stuct! */
+ * NOTE: the char* variables MUST all remain at the start of the struct! */
 typedef struct {
        char *auth_users;
        char *charset;
        char *comment;
        char *dont_compress;
+       char *early_exec;
        char *exclude;
        char *exclude_from;
        char *filter;
@@ -149,6 +150,7 @@ typedef struct {
        BOOL charset_EXP;
        BOOL comment_EXP;
        BOOL dont_compress_EXP;
+       BOOL early_exec_EXP;
        BOOL exclude_EXP;
        BOOL exclude_from_EXP;
        BOOL filter_EXP;
@@ -227,6 +229,8 @@ static const all_vars Defaults = {
 
  /* listen_backlog; */         5,
  /* rsync_port; */             0,
+
+ /* proxy_protocol; */         False,
  },
 
  /* ==== local_vars ==== */
@@ -235,7 +239,8 @@ static const all_vars Defaults = {
  /* charset; */                NULL,
  /* comment; */                NULL,
  /* dont_compress; */          DEFAULT_DONT_COMPRESS,
- /* exclude; */                        NULL,
+ /* early_exec; */             NULL,
+ /* exclude; */                NULL,
  /* exclude_from; */           NULL,
  /* filter; */                 NULL,
  /* gid; */                    NULL,
@@ -262,6 +267,7 @@ static const all_vars Defaults = {
  /* charset_EXP; */            False,
  /* comment_EXP; */            False,
  /* dont_compress_EXP; */      False,
+ /* early_exec_EXP; */         False,
  /* exclude_EXP; */            False,
  /* exclude_from_EXP; */       False,
  /* filter_EXP; */             False,
@@ -397,12 +403,14 @@ static struct parm_struct parm_table[] =
  {"motd file",         P_STRING, P_GLOBAL,&Vars.g.motd_file,           NULL,0},
  {"pid file",          P_STRING, P_GLOBAL,&Vars.g.pid_file,            NULL,0},
  {"port",              P_INTEGER,P_GLOBAL,&Vars.g.rsync_port,          NULL,0},
+ {"proxy protocol",    P_BOOL,   P_LOCAL, &Vars.g.proxy_protocol,      NULL,0},
  {"socket options",    P_STRING, P_GLOBAL,&Vars.g.socket_options,      NULL,0},
 
  {"auth users",        P_STRING, P_LOCAL, &Vars.l.auth_users,          NULL,0},
  {"charset",           P_STRING, P_LOCAL, &Vars.l.charset,             NULL,0},
  {"comment",           P_STRING, P_LOCAL, &Vars.l.comment,             NULL,0},
  {"dont compress",     P_STRING, P_LOCAL, &Vars.l.dont_compress,       NULL,0},
+ {"early exec",        P_STRING, P_LOCAL, &Vars.l.early_exec,          NULL,0},
  {"exclude from",      P_STRING, P_LOCAL, &Vars.l.exclude_from,        NULL,0},
  {"exclude",           P_STRING, P_LOCAL, &Vars.l.exclude,             NULL,0},
  {"fake super",        P_BOOL,   P_LOCAL, &Vars.l.fake_super,          NULL,0},
@@ -464,8 +472,7 @@ static char *expand_vars(char *str)
                return str;
 
        bufsize = strlen(str) + 2048;
-       if ((buf = new_array(char, bufsize+1)) == NULL) /* +1 for trailing '\0' */
-               out_of_memory("expand_vars");
+       buf = new_array(char, bufsize+1); /* +1 for trailing '\0' */
 
        for (t = buf, f = str; bufsize && *f; ) {
                if (*f == '%' && *++f != '%') {
@@ -538,10 +545,13 @@ FN_GLOBAL_STRING(lp_socket_options, socket_options)
 FN_GLOBAL_INTEGER(lp_listen_backlog, listen_backlog)
 FN_GLOBAL_INTEGER(lp_rsync_port, rsync_port)
 
+FN_GLOBAL_BOOL(lp_proxy_protocol, proxy_protocol)
+
 FN_LOCAL_STRING(lp_auth_users, auth_users)
 FN_LOCAL_STRING(lp_charset, charset)
 FN_LOCAL_STRING(lp_comment, comment)
 FN_LOCAL_STRING(lp_dont_compress, dont_compress)
+FN_LOCAL_STRING(lp_early_exec, early_exec)
 FN_LOCAL_STRING(lp_exclude, exclude)
 FN_LOCAL_STRING(lp_exclude_from, exclude_from)
 FN_LOCAL_STRING(lp_filter, filter)
@@ -591,10 +601,7 @@ FN_LOCAL_BOOL(lp_write_only, write_only)
  * the start, so any lost memory is inconsequential. */
 static inline void string_set(char **s, const char *v)
 {
-       if (!v)
-               *s = NULL;
-       else if (!(*s = strdup(v)))
-               out_of_memory("string_set");
+       *s = v ? strdup(v) : NULL;
 }
 
 /* Copy local_vars into a new section. No need to strdup since we don't free. */