added "dont compress" option with the default setting of
[rsync/rsync.git] / token.c
diff --git a/token.c b/token.c
index 7d49613..e1039e2 100644 (file)
--- a/token.c
+++ b/token.c
 #include "zlib/zlib.h"
 
 extern int do_compression;
+static int compression_level = Z_DEFAULT_COMPRESSION;
 
+/* determine the compression level based on a wildcard filename list */
+void set_compression(char *fname)
+{
+       extern int module_id;
+       char *dont;
+       char *tok;
+
+       if (!do_compression) return;
+
+       compression_level = Z_DEFAULT_COMPRESSION;
+       dont = lp_dont_compress(module_id);
+
+       if (!dont || !*dont) return;
+
+       dont = strdup(dont);
+       fname = strdup(fname);
+       if (!dont || !fname) return;
+
+       strlower(dont);
+       strlower(fname);
+
+       for (tok=strtok(dont," ");tok;tok=strtok(NULL," ")) {
+               if (fnmatch(tok, fname, 0) == 0) {
+                       compression_level = 0;
+                       break;
+               }
+       }
+       free(dont);
+       free(fname);
+}
 
 /* non-compressing recv token */
 static int simple_recv_token(int f,char **data)
@@ -104,7 +135,7 @@ send_deflated_token(int f, int token,
                        tx_strm.next_in = NULL;
                        tx_strm.zalloc = NULL;
                        tx_strm.zfree = NULL;
-                       if (deflateInit2(&tx_strm, Z_DEFAULT_COMPRESSION,
+                       if (deflateInit2(&tx_strm, compression_level,
                                         Z_DEFLATED, -15, 8,
                                         Z_DEFAULT_STRATEGY) != Z_OK) {
                                rprintf(FERROR, "compression init failed\n");