Hello,

3rd-party applications often require a particular initialization, for
example localization or even just a custom version string.  Currently,
clients can solve some of these situations by calling `GNUNET_OS_init'
in their `main' function, before `GNUNET_PROGRAM_run' (anything else not
covered by GNUNET_OS_ProjectData is left to the application itself.)

For services, however, it is not as simple: the `GNUNET_SERVICE_MAIN'
macro completely hides the `main' function, so it's impossible to call
`GNUNET_OS_init' and the like.  The macro could be expanded manually
(i.e. use an explicit `main' rather than the macro), but
`GNUNET_SERVICE_run_' has a name that, by convention, denotes a private
function that should not be used directly.

I suggest to make the `GNUNET_SERVICE_run' public, so that applications
can run their initialization procedures before the service "connects"
with GNUnet.

In theory this change would only require to change "run_" to "run" and
rewrite the gnunet-ext service accordingly.  There's no need to outright
remove the macro as it can be used internally without problems.

In the meantime, the attached patch adds localization to services.
Until now, even if the locale is changed, any message printed by a
service would not be translated regardless of what the relevat PO file
contains.

Thanks,
A.V.

>From 85bd2ed1c06816cc851cb51263c44615f5e40347 Mon Sep 17 00:00:00 2001
From: Alessio Vanni <[email protected]>
Date: Sat, 7 Sep 2019 13:18:07 +0200
Subject: [PATCH] Make services localizable

---
 src/util/service.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/util/service.c b/src/util/service.c
index fba5a2f20..5986b0158 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -2067,6 +2067,9 @@ GNUNET_SERVICE_run_ (int argc,
                      const struct GNUNET_MQ_MessageHandler *handlers)
 {
   struct GNUNET_SERVICE_Handle sh;
+#if ENABLE_NLS
+  char *path;
+#endif
   char *cfg_filename;
   char *opt_cfg_filename;
   char *loglev;
@@ -2079,6 +2082,7 @@ GNUNET_SERVICE_run_ (int argc,
   struct GNUNET_CONFIGURATION_Handle *cfg;
   int ret;
   int err;
+  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
 
   struct GNUNET_GETOPT_CommandLineOption service_options[] =
     {GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
@@ -2090,7 +2094,7 @@ GNUNET_SERVICE_run_ (int argc,
      GNUNET_GETOPT_option_help (NULL),
      GNUNET_GETOPT_option_loglevel (&loglev),
      GNUNET_GETOPT_option_logfile (&logfile),
-     GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+     GNUNET_GETOPT_option_version (pd->version),
      GNUNET_GETOPT_OPTION_END};
 
   err = 1;
@@ -2101,10 +2105,9 @@ GNUNET_SERVICE_run_ (int argc,
                      "%s%s%s",
                      xdg,
                      DIR_SEPARATOR_STR,
-                     GNUNET_OS_project_data_get ()->config_file);
+                     pd->config_file);
   else
-    cfg_filename =
-      GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
+    cfg_filename = GNUNET_strdup (pd->user_config_file);
   sh.ready_confirm_fd = -1;
   sh.options = options;
   sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -2120,6 +2123,21 @@ GNUNET_SERVICE_run_ (int argc,
   logfile = NULL;
   opt_cfg_filename = NULL;
   do_daemonize = 0;
+#if ENABLE_NLS
+  if (NULL != pd->gettext_domain)
+  {
+    setlocale (LC_ALL, "");
+    path = (NULL == pd->gettext_path) ?
+      GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR) :
+      GNUNET_strdup (pd->gettext_path);
+    if (NULL != path)
+    {
+      bindtextdomain (pd->gettext_domain, path);
+      GNUNET_free (path);
+    }
+    textdomain (pd->gettext_domain);
+  }
+#endif
   ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
   if (GNUNET_SYSERR == ret)
     goto shutdown;
-- 
2.21.0

_______________________________________________
GNUnet-developers mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnunet-developers

Reply via email to