gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9542 - in GNUnet: . doc/man src/util/boot


From: gnunet
Subject: [GNUnet-SVN] r9542 - in GNUnet: . doc/man src/util/boot
Date: Mon, 16 Nov 2009 01:27:41 -0700

Author: grothoff
Date: 2009-11-16 01:27:41 -0700 (Mon, 16 Nov 2009)
New Revision: 9542

Added:
   GNUnet/src/util/boot/lib_argz.c
Modified:
   GNUnet/ChangeLog
   GNUnet/configure.ac
   GNUnet/doc/man/gnunet-auto-share.1
   GNUnet/doc/man/gnunet-download.1
   GNUnet/doc/man/gnunet-insert.1
   GNUnet/doc/man/gnunet-search.1
   GNUnet/doc/man/gnunet-unindex.1
   GNUnet/src/util/boot/Makefile.am
   GNUnet/src/util/boot/startup.c
Log:
fixing Mantis #1467

Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog    2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/ChangeLog    2009-11-16 08:27:41 UTC (rev 9542)
@@ -1,6 +1,10 @@
+Mon Nov 16 09:25:47 CET 2009
+       Allow passing of command-line arguments using GNUNET_ARGS
+       environment variable (see Mantis #1467).
+
 Mon Apr 27 22:18:19 CEST 2009
-  Monitor low-traffic connections over a longer period
-  of time before terminating them.
+       Monitor low-traffic connections over a longer period
+       of time before terminating them.
 
 Fri Feb 27 22:05:50 MST 2009
        Releasing 0.8.0c.

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/configure.ac 2009-11-16 08:27:41 UTC (rev 9542)
@@ -283,7 +283,7 @@
 AC_CHECK_HEADERS([fcntl.h math.h errno.h ctype.h limits.h stdio.h stdlib.h 
string.h unistd.h stdarg.h signal.h locale.h sys/stat.h sys/types.h 
pthread.h],,AC_MSG_ERROR([Compiling GNUnet requires standard UNIX headers 
files]))
 
 # Checks for headers that are only required on some systems or opional (and 
where we do NOT abort if they are not there)
-AC_CHECK_HEADERS([langinfo.h sys/param.h sys/mount.h sys/statvfs.h 
sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h 
libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/time.h unistd.h 
kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h iconv.h ifaddrs.h 
mach/mach.h stddef.h sys/timeb.h terminos.h])
+AC_CHECK_HEADERS([langinfo.h sys/param.h sys/mount.h sys/statvfs.h 
sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h 
libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/time.h unistd.h 
kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h iconv.h ifaddrs.h 
mach/mach.h stddef.h sys/timeb.h terminos.h argz.h])
 
 # Check for GMP header (and abort if not present)
 AC_CHECK_HEADERS([gmp.h],,AC_MSG_ERROR([Compiling GNUnet requires gmp.h (from 
the GNU MP library, libgmp)]))

Modified: GNUnet/doc/man/gnunet-auto-share.1
===================================================================
--- GNUnet/doc/man/gnunet-auto-share.1  2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/doc/man/gnunet-auto-share.1  2009-11-16 08:27:41 UTC (rev 9542)
@@ -144,6 +144,10 @@
  $ gnunet\-auto\-share -d -V /home/share/ 
 
 
+.SH NOTES
+
+As most GNUnet command\-line tools, gnunet\-auto\-share supports passing 
arguments using environment variables.  This can improve your privacy since 
otherwise the name of the shared directory will likely be visible to other 
local users.  Setting "GNUNET_ARGS" will cause the respective string to be 
appended to the actual command-line and to be processed the same way as 
arguments given directly at the command line.
+
 .SH FILES
 .TP
 ~/.gnunet/gnunet.conf

Modified: GNUnet/doc/man/gnunet-download.1
===================================================================
--- GNUnet/doc/man/gnunet-download.1    2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/doc/man/gnunet-download.1    2009-11-16 08:27:41 UTC (rev 9542)
@@ -47,6 +47,8 @@
 \fB\-V\fR, \fB\-\-verbose\fR
 print progress information
 .SH NOTES
+As most GNUnet command\-line tools, gnunet\-download supports passing 
arguments using environment variables.  This can improve your privacy since 
otherwise the download URI will likely be visible to other local users.  
Setting "GNUNET_ARGS" will cause the respective string to be appended to the 
actual command-line and to be processed the same way as arguments given 
directly at the command line.
+
 The GNUNET_URI is typically obtained from gnunet\-search. gnunet\-gtk can also 
be used instead of gnunet\-download.
 If youever have to abort a download, you can at any time continue it by 
re\-issuing gnunet\-download with the same filename. In that case GNUnet will 
not download blocks again that are already present. GNUnets file\-encoding will 
ensure file integrity, even if the existing file was not downloaded from GNUnet 
in the first place. Temporary information will be stored in FILENAME.X files 
until the download is completed. These files are used only if a download is 
resumed later. If you abort a download for good, you should remember to delete 
these files.
 

Modified: GNUnet/doc/man/gnunet-insert.1
===================================================================
--- GNUnet/doc/man/gnunet-insert.1      2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/doc/man/gnunet-insert.1      2009-11-16 08:27:41 UTC (rev 9542)
@@ -304,6 +304,10 @@
  # gnunet\-insert \-P MPAA-1 \-t next noise_updated.mp3
 
 
+.SH NOTES
+As most GNUnet command-line tools, gnunet\-insert supports passing arguments 
using environment variables.  This can improve your privacy since otherwise the 
published filenames will likely be visible to other local users.  Setting 
"GNUNET_ARGS" will cause the respective string to be appended to the actual 
command-line and to be processed the same way as arguments given directly at 
the command line.
+
+
 .SH FILES
 .TP
 ~/.gnunet/gnunet.conf

Modified: GNUnet/doc/man/gnunet-search.1
===================================================================
--- GNUnet/doc/man/gnunet-search.1      2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/doc/man/gnunet-search.1      2009-11-16 08:27:41 UTC (rev 9542)
@@ -42,10 +42,11 @@
 \fB\-v\fR, \fB\-\-version\fR
 print the version number
 .SH NOTES
+As most GNUnet command-line tools, gnunet\-search supports passing arguments 
using environment variables.  This can improve your privacy since otherwise the 
search terms will likely be visible to other local users.  Setting 
"GNUNET_ARGS" will cause the respective string to be appended to the actual 
command-line and to be processed the same way as arguments given directly at 
the command line.
 
 You can run gnunet\-search with an URI instead of a keyword.  The URI can have 
the format for a namespace search or for a keyword search.  For a namespace 
search, the format is gnunet://ecrs/sks/NAMESPACE/IDENTIFIER.  For a keyword 
search, use gnunet://ecrs/ksk/KEYWORD[+KEYWORD]*.  If the format does not 
correspond to a GNUnet URI, GNUnet will automatically assume that keywords are 
supplied directly.  
 
-If multiple keywords are passed, gnunet-search will look for content matching 
any of the keywords.  The prefix "+" makes a keyword mandatory.  
+If multiple keywords are passed, gnunet\-search will look for content matching 
any of the keywords.  The prefix "+" makes a keyword mandatory.  
 
 # gnunet\-search "Das Kapital"
 

Modified: GNUnet/doc/man/gnunet-unindex.1
===================================================================
--- GNUnet/doc/man/gnunet-unindex.1     2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/doc/man/gnunet-unindex.1     2009-11-16 08:27:41 UTC (rev 9542)
@@ -30,6 +30,8 @@
 \fB\-V\fR, \fB\-\-verbose\fR
 be verbose
 .SH NOTES
+As most GNUnet command\-line tools, gnunet\-unindex supports passing arguments 
using environment variables.  This can improve your privacy since otherwise the 
filename will likely be visible to other local users.  Setting "GNUNET_ARGS" 
will cause the respective string to be appended to the actual command-line and 
to be processed the same way as arguments given directly at the command line.
+
 You can only unindex files that you indexed and that you still have available 
locally in full.  You should use gnunet\-unindex on files that you indexed (not 
inserted) and that you are going to delete or move locally.
 .TP
 .SH FILES

Modified: GNUnet/src/util/boot/Makefile.am
===================================================================
--- GNUnet/src/util/boot/Makefile.am    2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/src/util/boot/Makefile.am    2009-11-16 08:27:41 UTC (rev 9542)
@@ -12,3 +12,5 @@
 libboot_la_SOURCES = \
   startup.c
 
+EXTRA_DIST = lib_argz.c
+

Added: GNUnet/src/util/boot/lib_argz.c
===================================================================
--- GNUnet/src/util/boot/lib_argz.c                             (rev 0)
+++ GNUnet/src/util/boot/lib_argz.c     2009-11-16 08:27:41 UTC (rev 9542)
@@ -0,0 +1,406 @@
+/* Functions for dealing with '\0' separated arg vectors.
+   Copyright (C) 1995-1998, 2000-2002, 2006, 2008 Free Software Foundation, 
Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+#include <argz.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+
+/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN.  */
+error_t
+argz_append (char **argz, size_t *argz_len, const char *buf, size_t buf_len)
+{
+  size_t new_argz_len = *argz_len + buf_len;
+  char *new_argz = realloc (*argz, new_argz_len);
+  if (new_argz)
+    {
+      memcpy (new_argz + *argz_len, buf, buf_len);
+      *argz = new_argz;
+      *argz_len = new_argz_len;
+      return 0;
+    }
+  else
+    return ENOMEM;
+}
+
+/* Add STR to the argz vector in ARGZ & ARGZ_LEN.  This should be moved into
+   argz.c in libshouldbelibc.  */
+error_t
+argz_add (char **argz, size_t *argz_len, const char *str)
+{
+  return argz_append (argz, argz_len, str, strlen (str) + 1);
+}
+
+
+
+error_t
+argz_add_sep (char **argz, size_t *argz_len, const char *string, int delim)
+{
+  size_t nlen = strlen (string) + 1;
+
+  if (nlen > 1)
+    {
+      const char *rp;
+      char *wp;
+
+      *argz = (char *) realloc (*argz, *argz_len + nlen);
+      if (*argz == NULL)
+       return ENOMEM;
+
+      wp = *argz + *argz_len;
+      rp = string;
+      do
+       if (*rp == delim)
+         {
+           if (wp > *argz && wp[-1] != '\0')
+             *wp++ = '\0';
+           else
+             --nlen;
+         }
+       else
+         *wp++ = *rp;
+      while (*rp++ != '\0');
+
+      *argz_len += nlen;
+    }
+
+  return 0;
+}
+
+
+
+error_t
+argz_create_sep (const char *string, int delim, char **argz, size_t *len)
+{
+  size_t nlen = strlen (string) + 1;
+
+  if (nlen > 1)
+    {
+      const char *rp;
+      char *wp;
+
+      *argz = (char *) malloc (nlen);
+      if (*argz == NULL)
+       return ENOMEM;
+
+      rp = string;
+      wp = *argz;
+      do
+       if (*rp == delim)
+         {
+           if (wp > *argz && wp[-1] != '\0')
+             *wp++ = '\0';
+           else
+             --nlen;
+         }
+       else
+         *wp++ = *rp;
+      while (*rp++ != '\0');
+
+      if (nlen == 0)
+       {
+         free (*argz);
+         *argz = NULL;
+         *len = 0;
+       }
+
+      *len = nlen;
+    }
+  else
+    {
+      *argz = NULL;
+      *len = 0;
+    }
+
+  return 0;
+}
+
+
+/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
+   existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
+   Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
+   ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ.  If BEFORE is not
+   in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
+   ARGZ, ENOMEM is returned, else 0.  */
+error_t
+argz_insert (char **argz, size_t *argz_len, char *before, const char *entry)
+{
+  if (! before)
+    return argz_add (argz, argz_len, entry);
+
+  if (before < *argz || before >= *argz + *argz_len)
+    return EINVAL;
+
+  if (before > *argz)
+    /* Make sure before is actually the beginning of an entry.  */
+    while (before[-1])
+      before--;
+
+  {
+    size_t after_before = *argz_len - (before - *argz);
+    size_t entry_len = strlen  (entry) + 1;
+    size_t new_argz_len = *argz_len + entry_len;
+    char *new_argz = realloc (*argz, new_argz_len);
+
+    if (new_argz)
+      {
+       before = new_argz + (before - *argz);
+       memmove (before + entry_len, before, after_before);
+       memmove (before, entry, entry_len);
+       *argz = new_argz;
+       *argz_len = new_argz_len;
+       return 0;
+      }
+    else
+      return ENOMEM;
+  }
+}
+
+
+char *
+argz_next (const char *argz, size_t argz_len, const char *entry)
+{
+  if (entry)
+    {
+      if (entry < argz + argz_len)
+       entry = strchr (entry, '\0') + 1;
+
+      return entry >= argz + argz_len ? NULL : (char *) entry;
+    }
+  else
+    if (argz_len > 0)
+      return (char *) argz;
+    else
+      return NULL;
+}
+
+
+/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
+   except the last into the character SEP.  */
+void
+argz_stringify (char *argz, size_t len, int sep)
+{
+  if (len > 0)
+    while (1)
+      {
+       size_t part_len = strnlen (argz, len);
+       argz += part_len;
+       len -= part_len;
+       if (len-- <= 1)         /* includes final '\0' we want to stop at */
+         break;
+       *argz++ = sep;
+      }
+}
+
+
+/* Returns the number of strings in ARGZ.  */
+size_t
+argz_count (const char *argz, size_t len)
+{
+  size_t count = 0;
+  while (len > 0)
+    {
+      size_t part_len = strlen(argz);
+      argz += part_len + 1;
+      len -= part_len + 1;
+      count++;
+    }
+  return count;
+}
+
+
+/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into
+   ARGV, which must be large enough to hold them all.  */
+void
+argz_extract (const char *argz, size_t len, char **argv)
+{
+  while (len > 0)
+    {
+      size_t part_len = strlen (argz);
+      *argv++ = (char *) argz;
+      argz += part_len + 1;
+      len -= part_len + 1;
+    }
+  *argv = 0;
+}
+
+
+/* Make a '\0' separated arg vector from a unix argv vector, returning it in
+   ARGZ, and the total length in LEN.  If a memory allocation error occurs,
+   ENOMEM is returned, otherwise 0.  */
+error_t
+argz_create (char *const argv[], char **argz, size_t *len)
+{
+  int argc;
+  size_t tlen = 0;
+  char *const *ap;
+  char *p;
+
+  for (argc = 0; argv[argc] != NULL; ++argc)
+    tlen += strlen (argv[argc]) + 1;
+
+  if (tlen == 0)
+    *argz = NULL;
+  else
+    {
+      *argz = malloc (tlen);
+      if (*argz == NULL)
+       return ENOMEM;
+
+      for (p = *argz, ap = argv; *ap; ++ap, ++p)
+       p = stpcpy (p, *ap);
+    }
+  *len = tlen;
+
+  return 0;
+}
+
+
+/* Delete ENTRY from ARGZ & ARGZ_LEN, if any.  */
+void
+argz_delete (char **argz, size_t *argz_len, char *entry)
+{
+  if (entry)
+    /* Get rid of the old value for NAME.  */
+    {
+      size_t entry_len = strlen (entry) + 1;
+      *argz_len -= entry_len;
+      memmove (entry, entry + entry_len, *argz_len - (entry - *argz));
+      if (*argz_len == 0)
+       {
+         free (*argz);
+         *argz = 0;
+       }
+    }
+}
+
+
+/* Append BUF, of length BUF_LEN to *TO, of length *TO_LEN, reallocating and
+   updating *TO & *TO_LEN appropriately.  If an allocation error occurs,
+   *TO's old value is freed, and *TO is set to 0.  */
+void
+str_append (char **to, size_t *to_len, const char *buf, const size_t buf_len)
+{
+  size_t new_len = *to_len + buf_len;
+  char *new_to = realloc (*to, new_len + 1);
+
+  if (new_to)
+    {
+      *((char *) mempcpy (new_to + *to_len, buf, buf_len)) = '\0';
+      *to = new_to;
+      *to_len = new_len;
+    }
+  else
+    {
+      free (*to);
+      *to = 0;
+    }
+}
+
+/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
+   ARGZ as necessary.  If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
+   incremented by number of replacements performed.  */
+error_t
+argz_replace (char **argz, size_t *argz_len, const char *str, const char *with,
+               unsigned *replace_count)
+{
+  error_t err = 0;
+
+  if (str && *str)
+    {
+      char *arg = 0;
+      char *src = *argz;
+      size_t src_len = *argz_len;
+      char *dst = 0;
+      size_t dst_len = 0;
+      int delayed_copy = 1;    /* True while we've avoided copying anything.  
*/
+      size_t str_len = strlen (str), with_len = strlen (with);
+
+      while (!err && (arg = argz_next (src, src_len, arg)))
+       {
+         char *match = strstr (arg, str);
+         if (match)
+           {
+             char *from = match + str_len;
+             size_t to_len = match - arg;
+             char *to = strndup (arg, to_len);
+
+             while (to && from)
+               {
+                 str_append (&to, &to_len, with, with_len);
+                 if (to)
+                   {
+                     match = strstr (from, str);
+                     if (match)
+                       {
+                         str_append (&to, &to_len, from, match - from);
+                         from = match + str_len;
+                       }
+                     else
+                       {
+                         str_append (&to, &to_len, from, strlen (from));
+                         from = 0;
+                       }
+                   }
+               }
+
+             if (to)
+               {
+                 if (delayed_copy)
+                   /* We avoided copying SRC to DST until we found a match;
+                       now that we've done so, copy everything from the start
+                       of SRC.  */
+                   {
+                     if (arg > src)
+                       err = argz_append (&dst, &dst_len, src, (arg - src));
+                     delayed_copy = 0;
+                   }
+                 if (! err)
+                   err = argz_add (&dst, &dst_len, to);
+                 free (to);
+               }
+             else
+               err = ENOMEM;
+
+             if (replace_count)
+               (*replace_count)++;
+           }
+         else if (! delayed_copy)
+           err = argz_add (&dst, &dst_len, arg);
+       }
+
+      if (! err)
+       {
+         if (! delayed_copy)
+           /* We never found any instances of str.  */
+           {
+             free (src);
+             *argz = dst;
+             *argz_len = dst_len;
+           }
+       }
+      else if (dst_len > 0)
+       free (dst);
+    }
+
+  return err;
+}

Modified: GNUnet/src/util/boot/startup.c
===================================================================
--- GNUnet/src/util/boot/startup.c      2009-11-15 23:03:06 UTC (rev 9541)
+++ GNUnet/src/util/boot/startup.c      2009-11-16 08:27:41 UTC (rev 9542)
@@ -183,6 +183,12 @@
   return 0;
 }
 
+#if HAVE_ARGZ_H
+#include <argz.h>
+#else
+#include "lib_argz.c"
+#endif
+
 /**
  * Run a standard GNUnet startup sequence
  * (initialize loggers and configuration,
@@ -205,9 +211,27 @@
   char *path;
   int is_daemon;
   int ret;
+  const char *gargs;
 
   GNUNET_os_init (NULL);
+  gargs = getenv ("GNUNET_ARGS");
+  if (gargs != NULL)
+    {
+      char *gargz;
+      size_t gargl;
+      char **gargv;
+      int i;
 
+      argz_create_sep (gargs, ' ', &gargz, &gargl);
+      for (i=0;i<argc;i++)
+       argz_insert (&gargz, &gargl, gargz, argv[i]);
+      gargv = GNUNET_malloc (sizeof (char*) * (gargl+1));
+      argz_extract (gargz, gargl, gargv);
+      argc = argz_count (gargz, gargl);
+      free (gargz);
+      argv = (char *const *) gargv;
+    }
+
 #if ENABLE_NLS
   setlocale (LC_ALL, "");
   path = GNUNET_get_installation_path (GNUNET_IPK_LOCALEDIR);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]