gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3172 - GNUnet/src/server


From: grothoff
Subject: [GNUnet-SVN] r3172 - GNUnet/src/server
Date: Sat, 29 Jul 2006 19:15:29 -0700 (PDT)

Author: grothoff
Date: 2006-07-29 19:15:28 -0700 (Sat, 29 Jul 2006)
New Revision: 3172

Modified:
   GNUnet/src/server/gnunet-transport-check.c
   GNUnet/src/server/gnunet-update.c
   GNUnet/src/server/gnunetd.c
   GNUnet/src/server/startup.c
   GNUnet/src/server/startup.h
Log:
towards gnunet-update

Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c  2006-07-30 02:00:30 UTC (rev 
3171)
+++ GNUnet/src/server/gnunet-transport-check.c  2006-07-30 02:15:28 UTC (rev 
3172)
@@ -379,7 +379,6 @@
   int res;
   unsigned long long Xrepeat;
   char * trans;
-  char * user;
   int ping;
   int stats[3];
   int pos;
@@ -402,20 +401,10 @@
     return -1;  
   }
 
-  user = NULL;
-  if (0 == GC_get_configuration_value_string(cfg,
-                                            "GNUNETD",
-                                            "USER",
-                                            NULL,
-                                            &user)) {
-    if (OK != os_change_user(ectx,
-                            user)) {
-      GC_free(cfg);
-      GE_free_context(ectx);
-      FREE(user);
-      return 1;
-    }
-    FREE(user);
+  if (OK != changeUser(ectx, cfg)) {
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return -1;
   }
 
   if (-1 == GC_get_configuration_value_number(cfg,
@@ -490,6 +479,7 @@
                                      "BLACKLIST",
                                      NULL);
   }
+  cron = cron_create(ectx);
   initCore(ectx, cfg, cron, NULL);
   initConnection(ectx, cfg, NULL, cron);
   registerPlaintextHandler(P2P_PROTO_noise,
@@ -536,6 +526,7 @@
   doneConnection();
   doneCore();
   FREE(expectedValue);
+  cron_destroy(cron);
   GC_free(cfg);
   GE_free_context(ectx);
  

Modified: GNUnet/src/server/gnunet-update.c
===================================================================
--- GNUnet/src/server/gnunet-update.c   2006-07-30 02:00:30 UTC (rev 3171)
+++ GNUnet/src/server/gnunet-update.c   2006-07-30 02:15:28 UTC (rev 3172)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2004 Christian Grothoff (and other contributing authors)
+     (C) 2004, 2006 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -26,6 +26,9 @@
 
 #include "platform.h"
 #include "gnunet_util.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_error_loggers.h"
+#include "gnunet_util_cron.h"
 #include "gnunet_core.h"
 #include "core.h"
 #include "startup.h"
@@ -40,134 +43,14 @@
  */
 #define DSO_PREFIX "libgnunet"
 
-/**
- * Print a list of the options we offer.
- */
-static void printhelp() {
-  static Help help[] = {
-    HELP_CONFIG,
-    { 'g', "get", "SECTION:ENTRY",
-      gettext_noop("print a value from the configuration file to stdout") },
-    HELP_HELP,
-    HELP_LOGLEVEL,
-#ifndef MINGW  /* not supported */
-    { 'u', "user", "LOGIN",
-      gettext_noop("run as user LOGIN") },
-#endif
-    { 'U', "client", NULL,
-      gettext_noop("run in client mode (for getting client configuration 
values)") },
-    HELP_VERSION,
-    HELP_VERBOSE,
-    HELP_END,
-  };
-  formatHelp("gnunet-update [OPTIONS]",
-            _("Updates GNUnet datastructures after version change."),
-            help);
-}
+static struct GC_Configuration * cfg;
 
-static int be_verbose = NO;
+static struct GE_Context * ectx;
 
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  int c;
-  int user = NO;
-  int get = NO;
-
-  /* set the 'magic' code that indicates that
-     this process is 'gnunetd' (and not any of
-     the user-tools).  Needed such that we use
-     the right configuration file... */
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "_MAGIC_",
-                                    "YES"));
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      LONG_DEFAULT_OPTIONS,
-      { "get", 1, 0, 'g' },
-#ifndef MINGW  /* not supported */
-      { "user", 0, 0, 'u' },
-#endif
-      { "client", 0, 0, 'U' },
-      { "verbose", 0, 0, 'V' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "vhdc:g:VL:",
-                     long_options,
-                     &option_index);
-    if (c == -1)
-      break;  /* No more flags to process */
-    if (YES == parseDefaultOptions(c, GNoptarg))
-      continue;
-    switch(c) {
-    case 'g':
-      FREENONNULL(setConfigurationString("GNUNET-UPDATE",
-                                        "GET",
-                                        GNoptarg));
-      get = YES;
-     break;
-    case 'L':
-      FREENONNULL(setConfigurationString("GNUNETD",
-                                        "LOGLEVEL",
-                                        GNoptarg));
-     break;
-    case 'h':
-      printhelp();
-      return SYSERR;
-#ifndef MINGW  /* not supported */
-    case 'u':
-      changeUser(GNoptarg);
-      break;
-#endif
-    case 'U':
-      FREENONNULL(setConfigurationString("GNUNETD",
-                                        "_MAGIC_",
-                                        "NO"));
-      user = YES;
-      break;
-    case 'v':
-      printf("GNUnet v%s, gnunet-update 0.0.1\n",
-            VERSION);
-      return SYSERR;
-    case 'V':
-      be_verbose = YES;
-      break;
-    default:
-      printf(_("Use --help to get a list of options.\n"));
-      return SYSERR;
-    } /* end of parsing commandline */
-  }
-  if (user && (! get)) {
-    printf(_("Option `%s' makes no sense without option `%s'."),
-          "-u", "-g");
-    return SYSERR;
-  }
-  if (GNoptind < argc) {
-    printf(_("Invalid arguments: "));
-    while (GNoptind < argc)
-      printf("%s ", argv[GNoptind++]);
-    printf(_("\nExiting.\n"));
-    return SYSERR;
-  }
-  if (get == NO) {
-    /* if we do not run in 'get' mode,
-       make sure we send error messages
-       to the console... */
-    FREENONNULL(setConfigurationString("GNUNETD",
-                                      "LOGFILE",
-                                      NULL));
-  }
-  return OK;
-}
-
 static char ** processed;
+
 static unsigned int processedCount;
+
 static UpdateAPI uapi;
 
 /**
@@ -271,11 +154,11 @@
     *ent = '\0';
     ent++;
   }
-  val = getConfigurationString(sec, ent);
-  if (val == NULL)
-    printf("%u\n",
-          getConfigurationInt(sec, ent));
-  else {
+  if (0 == GC_get_configuration_value_string(cfg,
+                                            sec,
+                                            ent,
+                                            NULL,
+                                            &val)) {
     printf("%s\n",
           val);
     FREE(val);
@@ -285,14 +168,16 @@
 
 static void work() {
   int i;
-  uapi.updateModule = &updateModule;
+  struct CronManager * cron;
+
+  uapi.updateModule   = &updateModule;
   uapi.requestService = &requestService;
   uapi.releaseService = &releaseService;
 
-  initCore();
+  cron = cron_create(ectx);
+  initCore(ectx, cfg, cron, NULL);
 
-  /* force update of common modules
-     (used by core) */
+  /* force update of common modules (used by core) */
   updateModule("transport");
   updateModule("identity");
   updateModule("session");
@@ -310,29 +195,74 @@
           processedCount);
   GROW(processed, processedCount, 0);
   doneCore();
+  cron_destroy(cron);
 }
 
+
+/**
+ * All gnunet-update command line options
+ */
+static struct CommandLineOption gnunetupdateOptions[] = {
+  COMMAND_LINE_OPTION_CFG_FILE, /* -c */
+  { 'g', "get", "", 
+    gettext_noop("ping peers from HOSTLISTURL that match transports"), 
+    0, &gnunet_getopt_configure_set_option, "GNUNET-UPDATE:GET" },
+  COMMAND_LINE_OPTION_HELP(gettext_noop("Updates GNUnet datastructures after 
version change.")), /* -h */
+  COMMAND_LINE_OPTION_HOSTNAME, /* -H */
+  COMMAND_LINE_OPTION_LOGGING, /* -L */
+  { 'u', "user", "LOGIN",
+    gettext_noop("run as user LOGIN"),
+    1, &gnunet_getopt_configure_set_option, "GNUNETD:USER" },  
+  { 'U', "client", NULL,
+    gettext_noop("run in client mode (for getting client configuration 
values)"),
+    0, &gnunet_getopt_configure_set_option, "GNUNETD:_MAGIC_=NO" },    
+  COMMAND_LINE_OPTION_VERSION(PACKAGE_VERSION), /* -v */
+  COMMAND_LINE_OPTION_VERBOSE,
+  COMMAND_LINE_OPTION_END,
+};
+
+
 int main(int argc,
-        char * argv[]) {
+        const char * argv[]) {
   char * get;
   char * user;
 
-  if (SYSERR == initUtil(argc, argv, &parseCommandLine))
-    return 0;
-#ifndef MINGW
-  user = getConfigurationString("GNUNETD", "USER");
-  if (user && strlen(user))
-    changeUser(user);
-  FREENONNULL(user);
-#endif
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  cfg = GC_create_C_impl();
+  GE_ASSERT(ectx, cfg != NULL);
 
-  get = getConfigurationString("GNUNET-UPDATE",
-                              "GET");
-  if (get != NULL)
-    doGet(get);
-  else
+  if (-1 == gnunet_parse_options("gnunet-update",
+                                ectx,
+                                cfg,
+                                gnunetupdateOptions,
+                                (unsigned int) argc,
+                                argv)) {
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return -1;  
+  }
+  if (OK != changeUser(ectx, cfg)) {
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return -1;
+  }
+  if (0 == GC_get_configuration_value_string(cfg,
+                                            "GNUNET-UPDATE",
+                                            "GET",
+                                            NULL,
+                                            &get)) {
+    doGet(get);  
+    FREE(get);
+  } else {
     work();
-  doneUtil();
+  }
+  GC_free(cfg);
+  GE_free_context(ectx);
+
   return 0;
 }
 

Modified: GNUnet/src/server/gnunetd.c
===================================================================
--- GNUnet/src/server/gnunetd.c 2006-07-30 02:00:30 UTC (rev 3171)
+++ GNUnet/src/server/gnunetd.c 2006-07-30 02:15:28 UTC (rev 3172)
@@ -175,7 +175,6 @@
  */
 int main(int argc, 
         const char * argv[]) {
-  char * user;
   int ret;
   struct GE_Context * ectx;
 
@@ -202,20 +201,10 @@
     GE_free_context(ectx);
     return -1;  
   }
-  user = NULL;
-  if (0 == GC_get_configuration_value_string(cfg,
-                                            "GNUNETD",
-                                            "USER",
-                                            NULL,
-                                            &user)) {
-    if (OK != os_change_user(ectx,
-                            user)) {
-      GC_free(cfg);
-      GE_free_context(ectx);
-      FREE(user);
-      return 1;
-    }
-    FREE(user);
+  if (OK != changeUser(ectx, cfg)) {
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return 1;
   }
   if (OK != checkUpToDate(ectx,
                          cfg)) {

Modified: GNUnet/src/server/startup.c
===================================================================
--- GNUnet/src/server/startup.c 2006-07-30 02:00:30 UTC (rev 3171)
+++ GNUnet/src/server/startup.c 2006-07-30 02:15:28 UTC (rev 3172)
@@ -36,6 +36,27 @@
 #include "core.h"
 #include "startup.h"
 
+int changeUser(struct GE_Context * ectx,
+              struct GC_Configuration * cfg) {
+  char * user;
+
+  user = NULL;
+  if (0 == GC_get_configuration_value_string(cfg,
+                                            "GNUNETD",
+                                            "USER",
+                                            NULL,
+                                            &user)) {
+    if (OK != os_change_user(ectx,
+                            user)) {
+      FREE(user);
+      return SYSERR;
+    }
+    FREE(user);
+  }
+  return OK;
+}
+
+
 static char * getPIDFile(struct GC_Configuration * cfg) {
   char * pif;
   

Modified: GNUnet/src/server/startup.h
===================================================================
--- GNUnet/src/server/startup.h 2006-07-30 02:00:30 UTC (rev 3171)
+++ GNUnet/src/server/startup.h 2006-07-30 02:15:28 UTC (rev 3172)
@@ -31,15 +31,18 @@
 #include "gnunet_util.h"
 #include "platform.h"
 
+int changeUser(struct GE_Context * ectx,
+              struct GC_Configuration * cfg);
+
 /**
  * Write our process ID to the pid file.
- **/
+ */
 void writePIDFile(struct GE_Context * ectx,
                  struct GC_Configuration * cfg);
 
 /**
  * Delete the pid file.
- **/
+ */
 void deletePIDFile(struct GE_Context * ectx,
                   struct GC_Configuration * cfg);
 





reply via email to

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