[tor-commits] [obfsproxy/master] Change argument parsing to support logfiles for managed proxies.

nickm at torproject.org nickm at torproject.org
Wed Jan 18 16:00:41 UTC 2012


commit 93f3a58532623a4e08106fdef99fa289660f5ca5
Author: George Kadianakis <desnacked at riseup.net>
Date:   Wed Jan 18 04:42:38 2012 +0200

    Change argument parsing to support logfiles for managed proxies.
---
 src/main.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/main.c b/src/main.c
index ec018d6..91f0395 100644
--- a/src/main.c
+++ b/src/main.c
@@ -133,14 +133,14 @@ is_supported_protocol(const char *name)
 static int
 handle_obfsproxy_args(const char *const *argv)
 {
-  int logmethod_set=0;
+  int logfile_set=0;
   int logsev_set=0;
   int i=1;
 
   while (argv[i] &&
          !strncmp(argv[i],"--",2)) {
     if (!strncmp(argv[i], "--log-file=", 11)) {
-      if (logmethod_set) {
+      if (logfile_set) {
         log_warn("You've already set a log file!");
         exit(1);
       }
@@ -149,7 +149,7 @@ handle_obfsproxy_args(const char *const *argv)
         log_warn("Failed creating logfile.");
         exit(1);
       }
-      logmethod_set=1;
+      logfile_set=1;
     } else if (!strncmp(argv[i], "--log-min-severity=", 19)) {
       if (logsev_set) {
         log_warn("You've already set a min. log severity!");
@@ -171,15 +171,6 @@ handle_obfsproxy_args(const char *const *argv)
         }
         logsev_set=1;
     } else if (!strncmp(argv[i], "--managed", 10)) {
-      if (logsev_set) {
-        printf("You can't combine --managed with other log options.\n");
-        exit(1);
-      }
-      if (log_set_method(LOG_METHOD_NULL, NULL) < 0) {
-        printf("Error at setting logging severity.\n");
-        exit(1);
-      }
-      logsev_set=1;
       is_external_proxy=0;
     } else {
       log_warn("Unrecognizable obfsproxy argument '%s'", argv[i]);
@@ -188,6 +179,17 @@ handle_obfsproxy_args(const char *const *argv)
     i++;
   }
 
+  if (!is_external_proxy && !logfile_set && logsev_set) {
+    printf("obfsproxy in managed proxy mode can only log to a file.\n");
+    exit(1);
+  } else if (!is_external_proxy && !logfile_set) { /* && !logsev_set */
+    /* managed proxies without a log file must not log at all. */
+    if (log_set_method(LOG_METHOD_NULL, NULL) < 0) {
+      printf("Error at setting logging severity.\n");
+      exit(1);
+    }
+  }
+
   return i;
 }
 





More information about the tor-commits mailing list