aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-10 22:47:57 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-10 22:47:57 +0000
commit7e5c0a94bacdfe6e1c65035b16fd97a77398df12 (patch)
tree70380ec85a0f4841247de81e8359e063da7486c1
parentdf62a12c9b51fd13cc37058d4a88a32d93386d79 (diff)
LRN: new utf8 argv converter for W32, converting strings on command-line to UTF-8 for all command-line tools.
-rw-r--r--src/arm/gnunet-arm.c3
-rw-r--r--src/ats/perf_ats_mlp.c2
-rw-r--r--src/chat/gnunet-chat.c4
-rw-r--r--src/core/gnunet-core.c4
-rw-r--r--src/dht/gnunet-dht-get.c4
-rw-r--r--src/dht/gnunet-dht-monitor.c3
-rw-r--r--src/dht/gnunet-dht-put.c3
-rw-r--r--src/dns/gnunet-dns-monitor.c4
-rw-r--r--src/dns/gnunet-dns-redirector.c4
-rw-r--r--src/exit/gnunet-daemon-exit.c3
-rw-r--r--src/fs/gnunet-directory.c4
-rw-r--r--src/fs/gnunet-download.c4
-rw-r--r--src/fs/gnunet-fs.c4
-rw-r--r--src/fs/gnunet-helper-fs-publish.c5
-rw-r--r--src/fs/gnunet-pseudonym.c4
-rw-r--r--src/fs/gnunet-publish.c4
-rw-r--r--src/fs/gnunet-search.c4
-rw-r--r--src/fs/gnunet-unindex.c4
-rw-r--r--src/gns/gnunet-gns-fcfsd.c3
-rw-r--r--src/gns/gnunet-gns-lookup.c3
-rw-r--r--src/gns/gnunet-gns-proxy.c3
-rw-r--r--src/gns/gnunet-gns.c3
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c3
-rw-r--r--src/include/gnunet_strings_lib.h18
-rw-r--r--src/integration-tests/connection_watchdog.c4
-rw-r--r--src/namestore/gnunet-namestore.c3
-rw-r--r--src/nat/gnunet-nat-server.c3
-rw-r--r--src/nse/gnunet-nse-profiler.c5
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c4
-rw-r--r--src/pt/gnunet-daemon-pt.c3
-rw-r--r--src/statistics/gnunet-statistics.c4
-rw-r--r--src/template/gnunet-template.c4
-rw-r--r--src/testing_old/gnunet-testing.c4
-rw-r--r--src/topology/gnunet-daemon-topology.c3
-rw-r--r--src/transport/gnunet-transport.c4
-rw-r--r--src/util/gnunet-resolver.c4
-rw-r--r--src/util/gnunet-rsa.c4
-rw-r--r--src/util/program.c1
-rw-r--r--src/util/strings.c90
-rw-r--r--src/vpn/gnunet-vpn.c4
40 files changed, 242 insertions, 2 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index 58aa709578..744c3f208f 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -431,6 +431,9 @@ main (int argc, char *const *argv)
if (temp_timeout_ms > 0)
timeout.rel_value = temp_timeout_ms;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
if (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-arm",
gettext_noop
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
index b9ee5e4dcc..ff2d8dadaa 100644
--- a/src/ats/perf_ats_mlp.c
+++ b/src/ats/perf_ats_mlp.c
@@ -360,6 +360,8 @@ main (int argc, char *argv[])
GNUNET_GETOPT_OPTION_END
};
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
GNUNET_PROGRAM_run (argc, argv,
"perf_ats_mlp", "nohelp", options,
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c
index 7b11c0d187..012f78ed90 100644
--- a/src/chat/gnunet-chat.c
+++ b/src/chat/gnunet-chat.c
@@ -737,6 +737,10 @@ main (int argc, char *const *argv)
flags |= O_NONBLOCK;
fcntl (0, F_SETFL, flags);
#endif
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-chat",
gettext_noop ("Join a chat on GNUnet."), options,
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index 4fe0a4f86d..78bc14154f 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -89,6 +89,10 @@ main (int argc, char *const *argv)
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-core",
gettext_noop
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index fb185c489b..7555f90093 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -226,6 +226,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
int
main (int argc, char *const *argv)
{
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get",
gettext_noop
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 8ca3beb2a6..088874a534 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -315,6 +315,9 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
int
main (int argc, char *const *argv)
{
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get",
gettext_noop
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index 59acc792ba..f6409bdff1 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -217,6 +217,9 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
int
main (int argc, char *const *argv)
{
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-put",
gettext_noop
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c
index 82715aabc3..2a05efdeed 100644
--- a/src/dns/gnunet-dns-monitor.c
+++ b/src/dns/gnunet-dns-monitor.c
@@ -342,6 +342,10 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-monitor",
gettext_noop
diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c
index a45b896095..5ba7e87c6f 100644
--- a/src/dns/gnunet-dns-redirector.c
+++ b/src/dns/gnunet-dns-redirector.c
@@ -241,6 +241,10 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-redirector",
gettext_noop
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 26f3e75369..2166255672 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -3230,6 +3230,9 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_END
};
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit",
gettext_noop
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index c722f57ff2..4122cb154f 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -173,6 +173,10 @@ main (int argc, char *const *argv)
static struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME",
gettext_noop
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index 5a66aea27c..bd5b09c0d5 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -272,6 +272,10 @@ main (int argc, char *const *argv)
0, &GNUNET_GETOPT_increment_value, &verbose},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-download [OPTIONS] URI",
gettext_noop
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c
index 0b28923712..404c64e4d5 100644
--- a/src/fs/gnunet-fs.c
+++ b/src/fs/gnunet-fs.c
@@ -119,6 +119,10 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_VERBOSE (&verbose),
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]",
gettext_noop ("Special file-sharing operations"),
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c
index 86b02492d1..45f6d588d6 100644
--- a/src/fs/gnunet-helper-fs-publish.c
+++ b/src/fs/gnunet-helper-fs-publish.c
@@ -413,7 +413,7 @@ extract_files (struct ScanTreeNode *item)
* @return 0 on success
*/
int main(int argc,
- char **argv)
+ char *const *argv)
{
const char *filename_expanded;
const char *ex;
@@ -424,6 +424,9 @@ int main(int argc,
* binary mode.
*/
_setmode (1, _O_BINARY);
+ /* Get utf-8-encoded arguments */
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 5;
#endif
/* parse command line */
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c
index 38826d1de1..2b1b897c24 100644
--- a/src/fs/gnunet-pseudonym.c
+++ b/src/fs/gnunet-pseudonym.c
@@ -313,6 +313,10 @@ main (int argc, char *const *argv)
};
bo.expiration_time =
GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]",
gettext_noop ("Manage GNUnet pseudonyms."),
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index a1b26dbd58..24e49d3694 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -736,6 +736,10 @@ main (int argc, char *const *argv)
"GNUnet publish starts\n");
bo.expiration_time =
GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-publish [OPTIONS] FILENAME",
gettext_noop
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index 60620a4b3a..88507f608a 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -302,6 +302,10 @@ main (int argc, char *const *argv)
1, &GNUNET_GETOPT_set_uint, &results_limit},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-search [OPTIONS] KEYWORD",
gettext_noop
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index 3e8308df24..f4e3527379 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -170,6 +170,10 @@ main (int argc, char *const *argv)
0, &GNUNET_GETOPT_set_one, &verbose},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME",
gettext_noop
diff --git a/src/gns/gnunet-gns-fcfsd.c b/src/gns/gnunet-gns-fcfsd.c
index cd4e8e72dc..b919b4fed5 100644
--- a/src/gns/gnunet-gns-fcfsd.c
+++ b/src/gns/gnunet-gns-fcfsd.c
@@ -797,6 +797,9 @@ main (int argc, char *const *argv)
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("fcfsd", "WARNING", NULL);
ret =
(GNUNET_OK ==
diff --git a/src/gns/gnunet-gns-lookup.c b/src/gns/gnunet-gns-lookup.c
index f33264f61d..bcd2b5bccc 100644
--- a/src/gns/gnunet-gns-lookup.c
+++ b/src/gns/gnunet-gns-lookup.c
@@ -204,6 +204,9 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
int
main (int argc, char *const *argv)
{
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-get",
gettext_noop
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index b35cacad0a..2fef343436 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -2320,6 +2320,9 @@ main (int argc, char *const *argv)
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("gnunet-gns-proxy", "WARNING", NULL);
ret =
(GNUNET_OK ==
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 2a49ba1c27..1efe74842a 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -248,6 +248,9 @@ main (int argc, char *const *argv)
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
ret =
(GNUNET_OK ==
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 8b7bf3a3e0..6637f37cee 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -334,6 +334,9 @@ main (int argc, char *const *argv)
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("hostlist", "WARNING", NULL);
ret =
(GNUNET_OK ==
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 54d2e3034d..d68ca5c789 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -390,6 +390,24 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
struct sockaddr_storage *r_buf);
+/**
+ * Returns utf-8 encoded arguments.
+ * Does nothing (returns a copy of argc and argv) on any platform
+ * other than W32.
+ * Returned argv has u8argv[u8argc] == NULL.
+ * Returned argv is a single memory block, and can be freed with a single
+ * GNUNET_free () call.
+ *
+ * @param argc argc (as given by main())
+ * @param argv argv (as given by main())
+ * @param u8argc a location to store new argc in (though it's th same as argc)
+ * @param u8argv a location to store new argv in
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int
+GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc,
+ char *const **u8argv);
+
/* ifndef GNUNET_UTIL_STRING_H */
#endif
/* end of gnunet_util_string.h */
diff --git a/src/integration-tests/connection_watchdog.c b/src/integration-tests/connection_watchdog.c
index a06b5a763a..bcf9d03796 100644
--- a/src/integration-tests/connection_watchdog.c
+++ b/src/integration-tests/connection_watchdog.c
@@ -1090,6 +1090,10 @@ main (int argc, char *const *argv)
GNUNET_NO, &GNUNET_GETOPT_set_one, &ping},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "cn",
gettext_noop ("help text"), options, &run,
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index a0d1de10a1..6249812014 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -493,6 +493,9 @@ main (int argc, char *const *argv)
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
ret =
(GNUNET_OK ==
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index 9b6846cf0e..e971bd3b1d 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -313,6 +313,9 @@ main (int argc, char *const argv[])
GNUNET_GETOPT_OPTION_END
};
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc, argv, "gnunet-nat-server [options] PORT",
_("GNUnet NAT traversal test helper daemon"), options,
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 4a4bea5edd..cf88690d5c 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -914,8 +914,11 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
int
-main (int argc, char *argv[])
+main (int argc, char *const *argv)
{
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
GNUNET_log_setup ("nse-profiler",
#if VERBOSE
"DEBUG",
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index de27cd276e..d3637af44c 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -952,6 +952,10 @@ main (int argc, char *const *argv)
1, &GNUNET_GETOPT_set_string, &put_uri},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-peerinfo",
gettext_noop ("Print information about peers."),
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index 2ad8468efa..73936a4895 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -967,6 +967,9 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_END
};
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-pt",
gettext_noop
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 3eef887fc6..add2ddf413 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -240,6 +240,10 @@ main (int argc, char *const *argv)
&GNUNET_GETOPT_set_one, &watch},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-statistics [options [value]]",
gettext_noop
diff --git a/src/template/gnunet-template.c b/src/template/gnunet-template.c
index 7b1d9dfff8..3020a73beb 100644
--- a/src/template/gnunet-template.c
+++ b/src/template/gnunet-template.c
@@ -63,6 +63,10 @@ main (int argc, char *const *argv)
/* FIMXE: add options here */
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-template",
gettext_noop ("help text"), options, &run,
diff --git a/src/testing_old/gnunet-testing.c b/src/testing_old/gnunet-testing.c
index bdbb5e8c5e..375185b0e7 100644
--- a/src/testing_old/gnunet-testing.c
+++ b/src/testing_old/gnunet-testing.c
@@ -282,6 +282,10 @@ main (int argc, char *const *argv)
GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template},
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-testing",
gettext_noop ("Command line tool to access the testing library"), options, &run,
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 57da127fdd..356e2c963d 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -1356,6 +1356,9 @@ main (int argc, char *const *argv)
};
int ret;
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
ret =
(GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-topology",
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 3b6b7e4c54..d07afccea9 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -639,6 +639,10 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
gettext_noop
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index 142dd0d2fd..5596377483 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -149,6 +149,10 @@ main (int argc, char *const *argv)
0, &GNUNET_GETOPT_set_one, &reverse },
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
gettext_noop ("Use build-in GNUnet stub resolver"),
diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c
index f3cd83a8b6..fc9d200640 100644
--- a/src/util/gnunet-rsa.c
+++ b/src/util/gnunet-rsa.c
@@ -119,6 +119,10 @@ main (int argc, char *const *argv)
0, &GNUNET_GETOPT_set_one, &print_short_identity },
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-rsa [OPTIONS] keyfile",
gettext_noop ("Manipulate GNUnet private RSA key files"),
diff --git a/src/util/program.c b/src/util/program.c
index 9e1a83d0bc..a8178b93a0 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -165,6 +165,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
char *lpfx;
char *spc;
+
logfile = NULL;
gargs = getenv ("GNUNET_ARGS");
if (gargs != NULL)
diff --git a/src/util/strings.c b/src/util/strings.c
index 11134f139a..cc44767d62 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -32,6 +32,7 @@
#include "gnunet_common.h"
#include "gnunet_strings_lib.h"
#include <unicase.h>
+#include <unistr.h>
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
@@ -1113,4 +1114,93 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
return GNUNET_STRINGS_to_address_ipv4 (addr, addrlen, (struct sockaddr_in *) r_buf);
}
+/**
+ * Makes a copy of argv that consists of a single memory chunk that can be
+ * freed with a single call to GNUNET_free ();
+ */
+static char *const *
+_make_continuous_arg_copy (int argc, char *const *argv)
+{
+ size_t argvsize = 0;
+ int i;
+ char **new_argv;
+ char *p;
+ for (i = 0; i < argc; i++)
+ argvsize += strlen (argv[i]) + 1 + sizeof (char *);
+ new_argv = GNUNET_malloc (argvsize + sizeof (char *));
+ p = (char *) &new_argv[argc + 1];
+ for (i = 0; i < argc; i++)
+ {
+ new_argv[i] = p;
+ strcpy (p, argv[i]);
+ p += strlen (argv[i]) + 1;
+ }
+ new_argv[argc] = NULL;
+ return (char *const *) new_argv;
+}
+
+/**
+ * Returns utf-8 encoded arguments.
+ * Does nothing (returns a copy of argc and argv) on any platform
+ * other than W32.
+ * Returned argv has u8argv[u8argc] == NULL.
+ * Returned argv is a single memory block, and can be freed with a single
+ * GNUNET_free () call.
+ *
+ * @param argc argc (as given by main())
+ * @param argv argv (as given by main())
+ * @param u8argc a location to store new argc in (though it's th same as argc)
+ * @param u8argv a location to store new argv in
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int
+GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc, char *const **u8argv)
+{
+#if WINDOWS
+ wchar_t *wcmd;
+ wchar_t **wargv;
+ int wargc;
+ int i;
+ char **split_u8argv;
+
+ wcmd = GetCommandLineW ();
+ if (NULL == wcmd)
+ return GNUNET_SYSERR;
+ wargv = CommandLineToArgvW (wcmd, &wargc);
+ if (NULL == wargv)
+ return GNUNET_SYSERR;
+
+ split_u8argv = GNUNET_malloc (argc * sizeof (char *));
+
+ for (i = 0; i < wargc; i++)
+ {
+ size_t strl;
+ /* Hopefully it will allocate us NUL-terminated strings... */
+ split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
+ if (split_u8argv == NULL)
+ {
+ int j;
+ for (j = 0; j < i; j++)
+ free (split_u8argv[j]);
+ GNUNET_free (split_u8argv);
+ LocalFree (wargv);
+ return GNUNET_SYSERR;
+ }
+ }
+
+ *u8argv = _make_continuous_arg_copy (wargc, split_u8argv);
+ *u8argc = wargc;
+
+ for (i = 0; i < wargc; i++)
+ free (split_u8argv[i]);
+ free (split_u8argv);
+ return GNUNET_OK;
+#else
+ char *const *new_argv = (char *const *) _make_continuous_arg_copy (argc, argv);
+ *u8argv = new_argv;
+ *u8argc = argc;
+ return GNUNET_OK;
+#endif
+}
+
/* end of strings.c */
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
index ecc0442c65..b75b1d29a0 100644
--- a/src/vpn/gnunet-vpn.c
+++ b/src/vpn/gnunet-vpn.c
@@ -323,6 +323,10 @@ main (int argc, char *const *argv)
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn",
gettext_noop