gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libfints] branch master updated: Polishing.


From: gnunet
Subject: [GNUnet-SVN] [libfints] branch master updated: Polishing.
Date: Wed, 10 Oct 2018 17:36:57 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libfints.

The following commit(s) were added to refs/heads/master by this push:
     new 8e34816  Polishing.
8e34816 is described below

commit 8e34816cffe9a63b42ddf819c646318e0331f83d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 10 17:36:39 2018 +0200

    Polishing.
---
 src/Makefile.am |  14 ++++-
 src/libebics.c  |  22 ++++++-
 src/tests.c     |   8 +++
 src/util.c      | 173 +++++++++++++++++++++++++++++++++++++-------------------
 src/util.h      |  10 +++-
 5 files changed, 164 insertions(+), 63 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 7d14e11..a89fc2b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,8 @@ libebics_la_LIBADD = \
   $(LIBGCRYPT_LIBS) \
   $(GNUTLS_LIBS) \
   $(ZLIB_LIBS) \
-  $(XLIB)
+  $(XLIB) \
+  -lgnunetutil
 
 libebics_CPPFLAGS = \
   $(XML_CPPFLAGS) \
@@ -34,4 +35,13 @@ check_PROGRAMS = tests
 TESTS = $(check_PROGRAMS)
 
 tests_SOURCES = tests.c
-tests_LDADD = libebics.la
+tests_LDADD = \
+  -lebics \
+  -lgnunetutil
+
+tests_CPPFLAGS = \
+  $(XML_CPPFLAGS) \
+  $(XMLSEC1_CFLAGS) \
+  $(LIBGCRYPT_CFLAGS) \
+  $(GNUTLS_CFLAGS) \
+  $(ZLIB_CFLAGS)
diff --git a/src/libebics.c b/src/libebics.c
index c6106f0..5cd17c7 100644
--- a/src/libebics.c
+++ b/src/libebics.c
@@ -34,6 +34,18 @@
 #define LOG(level,...) EBICS_util_log_from (__LINE__,__FILE__,__func__,level, 
"libebics",__VA_ARGS__)
 
 
+static const struct GNUNET_OS_ProjectData libebics_pd = {
+  .libname = "libebics",
+  .project_dirname = "libebics",
+  .binary_name = "NOBINARYINSTALLED",
+  .env_varname = "EBICS_PREFIX",
+  .base_config_varname = "EBICS_BASE_CONFIG",
+  .bug_email = "address@hidden",
+  .homepage = "http://www.gnu.org/s/taler/";,
+  .config_file = "ebics.conf",
+  .user_config_file = "~/.config/ebics.conf",
+};
+
 /**
  * List of (persistent) XML templates.
  */
@@ -76,6 +88,8 @@ init_libgnutls()
   gnutls_global_init ();
   gnutls_global_set_log_function (&gnutlslog);
   gnutls_global_set_log_level (99);
+
+  return EBICS_SUCCESS;
 }
 
 
@@ -227,7 +241,9 @@ free_libxmlsec ()
 static int
 init_zlib ()
 {
-  /* TODO or not? */
+  LOG (EBICS_LOGLEVEL_DEBUG,
+       "zlib mock init\n");
+  return EBICS_SUCCESS;
 }
 
 
@@ -237,7 +253,7 @@ init_zlib ()
 static int
 free_zlib ()
 {
-  /* TODO or not? */
+  return EBICS_SUCCESS;
 }
 
 
@@ -469,6 +485,8 @@ EBICS_init_library ()
   if (retv)
     return retv;
 
+  GNUNET_OS_init (&libebics_pd);
+
   /* Challenge: get the "shared" directory. */
   if (NULL == (data_dir = GNUNET_OS_installation_get_path
       (GNUNET_OS_IPK_DATADIR)))
diff --git a/src/tests.c b/src/tests.c
index e84828f..f4edeec 100644
--- a/src/tests.c
+++ b/src/tests.c
@@ -18,6 +18,8 @@
 
 
 #include "libebics.h"
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
 
 #define LOG(level,...) \
   EBICS_util_log_from (__LINE__, \
@@ -37,7 +39,13 @@ int
 main (int argc, char **argv)
 {
   if (EBICS_SUCCESS != EBICS_init_library ()) 
+  {
+    LOG (EBICS_FATAL,
+         "no init lib");
     return EBICS_ERROR;
+  }
   
   EBICS_close_library ();
+  
+  return EBICS_SUCCESS;
 }
diff --git a/src/util.c b/src/util.c
index 8151023..1859b77 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,17 +1,20 @@
-/*
-  This file is part of libfints
-
-  libfints 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 3, or (at your option) any later version.
-
-  libfints 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
-  libfints; see the file COPYING.  If not, If not, see 
<http://www.gnu.org/license>
-*/
+/**
+ * This file is part of libebics
+ *
+ * libfints 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 3,
+ * or (at your option) any later version.
+ *
+ * libebics 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 libebics; see the file COPYING.
+ * If not, see <http://www.gnu.org/license>
+ */
 
 #include "util.h"
 
@@ -26,18 +29,30 @@
  * @param message the actual message
  */
 static void
-myprint (uint8_t level, const char *component, const char *date, const char 
*message)
+myprint (uint8_t level,
+         const char *component,
+         const char *date,
+         const char *message)
 {
-  char *errornames[8] = {"FATAL","ERROR","INFO ","DEBUG"};
-  printf ("%s: %s: %s: %s\n",date,component,errornames[level],message);
+  char *errornames[8] = {"FATAL",
+                         "ERROR",
+                         "WARNING",
+                         "INFO",
+                         "DEBUG"};
+  printf ("%s: %s: %s: %s\n",
+          date,
+          component,
+          errornames[level],
+          message);
 }
 
 
 /**
  * Example for default global logging config.
- * Example global logging config using myprint and logelvel 1.
  */
-extern struct util_logging_config global_config = { .target = myprint, 1 };
+struct util_logging_config global_config = {
+  .target = myprint,
+  1};
 
 
 /**
@@ -49,47 +64,89 @@ extern struct util_logging_config global_config = { .target 
= myprint, 1 };
  * @param ... the arguments to the format string
  */
 void
-EBICS_util_log_from (int32_t fileline, const char *filename, const char 
*funcname, const uint8_t level, const char *component, const char *message, ...)
+EBICS_util_log_from (int32_t fileline,
+                     const char *filename,
+                     const char *funcname,
+                     const uint8_t level,
+                     const char *component,
+                     const char *message,
+                     ...)
 {
-  if (EBICS_LOGLEVEL_NONE < global_config.loglevel)
-  {
-    char date[DATE_STR_SIZE];
-    size_t size;
-    time_t timeval;
-    struct tm *tmptr;
-    va_list vacp;
-    va_list va;
-
-    va_start (va, message);
-    va_copy (vacp, va);
-    size = vsnprintf (NULL, 0, message, vacp) + 1;
-    size += snprintf (NULL, 0, "%s:%d: %s: %s", filename, fileline, funcname, 
"");
-    assert (0 != size);
-    va_end (vacp);
-
-    char content[size];
-    char wrapper[size];
-
-    vsnprintf (content, sizeof(content), message, va);
-    va_end (va);
-
-    if (level == EBICS_LOGLEVEL_FATAL || EBICS_LOGLEVEL_DEBUG <= 
global_config.loglevel)
-    {
-      snprintf (wrapper,sizeof(wrapper),"%s:%d: %s: %s", filename, fileline, 
funcname, content);
-    }
-    else
-    {
-      snprintf (wrapper,sizeof(wrapper),"%s", content);
-    }
 
-    time (&timeval);
-    tmptr = localtime (&timeval);
-
-    memset (date, 0, DATE_STR_SIZE);
-    strftime (date, DATE_STR_SIZE, "%b %d %H:%M:%S", tmptr);
-
-    global_config.target (level, component, date, wrapper);
-  }
+  if (EBICS_LOGLEVEL_NONE > global_config.loglevel)
+    return;
+
+  char date[DATE_STR_SIZE];
+  size_t content_size;
+  size_t wrapper_size;
+  time_t timeval;
+  struct tm *tmptr;
+  va_list vacp;
+  va_list va;
+
+  va_start (va, message);
+  va_copy (vacp, va);
+
+  content_size = vsnprintf (NULL,
+                            0,
+                            message,
+                            va);
+  va_end (va);
+
+  wrapper_size = snprintf (NULL,
+                           0,
+                           "%s:%d: %s: %s",
+                           filename,
+                           fileline,
+                           funcname,
+                           "");
+
+  assert ((0 != content_size)
+    && (0 != wrapper_size));
+
+  char content[content_size];
+  char wrapper[wrapper_size];
+
+  /* user-provided message.  */
+  vsnprintf (content,
+             sizeof (content),
+             message,
+             vacp);
+
+  va_end (vacp);
+
+  if ( (level == EBICS_LOGLEVEL_FATAL) ||
+      (EBICS_LOGLEVEL_DEBUG <= global_config.loglevel) )
+    snprintf (wrapper,
+              /* size accounts for both 0-terminators */
+              wrapper_size + content_size - 1,
+              "%s:%d: %s: %s",
+              filename,
+              fileline,
+              funcname,
+              content);
+  else
+    snprintf (wrapper,
+              content_size,
+              "%s",
+              content);
+
+  time (&timeval);
+  tmptr = localtime (&timeval);
+
+  memset (date,
+          0,
+          DATE_STR_SIZE);
+
+  strftime (date,
+            DATE_STR_SIZE,
+            "%b %d %H:%M:%S",
+            tmptr);
+
+  global_config.target (level,
+                        component,
+                        date,
+                        wrapper);
 }
 
 
diff --git a/src/util.h b/src/util.h
index a674d36..d14eafb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -72,12 +72,20 @@ typedef void (*util_logging_target_function_pointer) 
(uint8_t level, const char
  */
 struct util_logging_config
 {
+
+  /**
+   * Routine for the very final print.
+   */
   util_logging_target_function_pointer target;
+
+  /**
+   * Default loglevel.
+   */
   uint8_t loglevel;
 };
 
 /*
- * Base64 encoding from GNUNET
+ * Base64 encoding from GNUnet
  */
 size_t
 EBICS_UTIL_base64_encode (const char *data,

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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