summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/afb-plugin.h2
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c10
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/afb-apis.c9
-rw-r--r--src/afb-hreq.c5
-rw-r--r--src/helper-api.c312
-rw-r--r--src/http-svc.c9
-rw-r--r--src/local-def.h2
-rw-r--r--src/main.c19
-rw-r--r--src/proto-def.h10
-rw-r--r--src/verbose.c29
-rw-r--r--src/verbose.h39
12 files changed, 98 insertions, 350 deletions
diff --git a/include/afb-plugin.h b/include/afb-plugin.h
index f2f4d6ec..88938e3d 100644
--- a/include/afb-plugin.h
+++ b/include/afb-plugin.h
@@ -72,7 +72,7 @@ typedef struct AFB_plugin AFB_plugin;
struct AFB_interface
{
- int verbose;
+ int verbosity;
enum AFB_Mode mode;
};
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index fbf5b590..d86e9263 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -73,7 +73,7 @@ static struct json_object *embed(const char *tag, struct json_object *obj)
static void embed_call_void(struct afb_req request, const char *method)
{
struct json_object *obj = jbus_call_sj_sync(jbus, method, "true");
- if (interface->verbose)
+ if (interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s(true) -> %s\n", method, obj ? json_object_to_json_string(obj) : "NULL");
if (obj == NULL) {
afb_req_fail(request, "failed", "framework daemon failure");
@@ -101,7 +101,7 @@ static void call_appid(struct afb_req request, const char *method)
return;
}
obj = jbus_call_sj_sync(jbus, method, sid);
- if (interface->verbose)
+ if (interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, sid, obj ? json_object_to_json_string(obj) : "NULL");
free(sid);
if (obj == NULL) {
@@ -120,7 +120,7 @@ static void call_runid(struct afb_req request, const char *method)
return;
}
obj = jbus_call_sj_sync(jbus, method, id);
- if (interface->verbose)
+ if (interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, id,
obj ? json_object_to_json_string(obj) : "NULL");
if (obj == NULL) {
@@ -171,7 +171,7 @@ static void start(struct afb_req request)
/* calls the service */
obj = jbus_call_sj_sync(jbus, _start_, query);
- if (interface->verbose)
+ if (interface->verbosity)
fprintf(stderr, "(afm-main-plugin) start(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL");
free(query);
@@ -234,7 +234,7 @@ static void install(struct afb_req request)
}
obj = jbus_call_sj_sync(jbus, _install_, query);
- if (interface->verbose)
+ if (interface->verbosity)
fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL");
free(query);
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9ddb5113..7e02578e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,7 +8,7 @@ ADD_LIBRARY(src OBJECT
afb-hreq.c
afb-websock.c
websock.c
- helper-api.c)
+ verbose.c)
INCLUDE_DIRECTORIES(${include_dirs})
diff --git a/src/afb-apis.c b/src/afb-apis.c
index 735649ca..7634dca1 100644
--- a/src/afb-apis.c
+++ b/src/afb-apis.c
@@ -43,6 +43,7 @@
#include "afb-req-itf.h"
#include "session.h"
#include "afb-apis.h"
+#include "verbose.h"
struct api_desc {
struct AFB_plugin *plugin; /* descriptor */
@@ -97,7 +98,7 @@ int afb_apis_add_plugin(const char *path)
fprintf(stderr, "[%s] not an AFB plugin, continuing...\n", path);
goto error2;
}
- if (verbose)
+ if (verbosity)
fprintf(stderr, "[%s] is a valid AFB plugin\n", path);
/* allocates enough memory */
@@ -114,7 +115,7 @@ int afb_apis_add_plugin(const char *path)
fprintf(stderr, "ERROR: plugin [%s] memory missing. continuing...\n", path);
goto error2;
}
- interface->verbose = 0;
+ interface->verbosity = 0;
interface->mode = AFB_MODE_LOCAL;
/* init the plugin */
@@ -151,7 +152,7 @@ int afb_apis_add_plugin(const char *path)
}
/* record the plugin */
- if (verbose)
+ if (verbosity)
fprintf(stderr, "Loading plugin[%lu] prefix=[%s] info=%s\n", (unsigned long)apis_count, plugin->prefix, plugin->info);
apis = &apis_array[apis_count];
apis->plugin = plugin;
@@ -184,7 +185,7 @@ static int adddirs(char path[PATH_MAX], size_t end)
fprintf(stderr, "ERROR in scanning plugin directory %s, %m\n", path);
return -1;
}
- if (verbose)
+ if (verbosity)
fprintf(stderr, "Scanning dir=[%s] for plugins\n", path);
/* scan each entry */
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index 16c235ab..b4fe2925 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -32,6 +32,7 @@
#include "afb-req-itf.h"
#include "afb-hreq.h"
#include "session.h"
+#include "verbose.h"
#define SIZE_RESPONSE_BUFFER 8000
@@ -269,7 +270,7 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f
if (inm && 0 == strcmp(inm, etag)) {
/* etag ok, return NOT MODIFIED */
close(fd);
- if (verbose)
+ if (verbosity)
fprintf(stderr, "Not Modified: [%s]\n", filename);
response = MHD_create_response_from_buffer(0, empty_string, MHD_RESPMEM_PERSISTENT);
status = MHD_HTTP_NOT_MODIFIED;
@@ -319,7 +320,7 @@ int afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url)
MHD_add_response_header(response, MHD_HTTP_HEADER_LOCATION, url);
MHD_queue_response(hreq->connection, MHD_HTTP_MOVED_PERMANENTLY, response);
MHD_destroy_response(response);
- if (verbose)
+ if (verbosity)
fprintf(stderr, "redirect from [%s] to [%s]\n", hreq->url, url);
return 1;
}
diff --git a/src/helper-api.c b/src/helper-api.c
deleted file mode 100644
index 9d1ec0b7..00000000
--- a/src/helper-api.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright (C) 2015 "IoT.bzh"
- * Author "Fulup Ar Foll"
- *
- * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-
-/*
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-*/
-
-#include "local-def.h"
-#include "afb-req-itf.h"
-
-// handle to hold queryAll values
-typedef struct {
- char *msg;
- size_t idx;
- size_t len;
-} queryHandleT;
-
-// Error code are requested through function to manage json usage count
-typedef struct {
- int level;
- const char* label;
- json_object *json;
-} AFB_errorT;
-
-static AFB_errorT AFBerr [AFB_UNAUTH+1];
-static json_object *jTypeStatic;
-
-PUBLIC int verbose;
-
-static const char *ERROR_LABEL[] = {"false", "true", "fatal", "fail", "warning", "empty", "success", "done", "unauth"};
-
-
-// Helper to retrieve argument from connection
-const char* getQueryValue(const AFB_request * request, const char *name) {
- return afb_req_argument(*request->areq, name);
-}
-
-static int getQueryCB (queryHandleT *query, struct afb_arg arg) {
- if (query->idx >= query->len)
- return 0;
- query->idx += (unsigned)snprintf (&query->msg[query->idx], query->len-query->idx, " %s: %s\'%s\',", arg.name, arg.is_file?"FILE=":"", arg.value);
- return 1; /* continue to iterate */
-}
-
-// Helper to retrieve argument from connection
-size_t getQueryAll(AFB_request * request, char *buffer, size_t len) {
- queryHandleT query;
- buffer[0] = '\0'; // start with an empty string
- query.msg = buffer;
- query.len = len;
- query.idx = 0;
-
- afb_req_iterate(*request->areq, (void*)getQueryCB, &query);
- buffer[len-1] = 0;
- return query.idx >= len ? len - 1 : query.idx;
-}
-
-#if 0
-char* getPostPath (AFB_request *request) {
- AFB_PostHandle *postHandle = getPostHandle(request);
- AFB_PostCtx *postFileCtx;
-
- if (postHandle == NULL) return NULL;
-
- postFileCtx = (AFB_PostCtx*) postHandle->ctx;
- if (postFileCtx == NULL) return NULL;
-
- return (postFileCtx->path);
-}
-
-json_object* getPostFile (AFB_request *request, AFB_PostItem *item, char* destination) {
-
- AFB_PostHandle *postHandle = getPostHandle(request);
- AFB_PostCtx *postFileCtx;
- char filepath[512];
- ssize_t len;
-
- // This is called after PostForm and then after DonePostForm
- if (item == NULL) {
- json_object* jresp;
- postFileCtx = (AFB_PostCtx*) postHandle->ctx;
-
- // No Post Application Context [something really bad happen]
- if (postFileCtx == NULL) {
- request->errcode = MHD_HTTP_EXPECTATION_FAILED;
- return(jsonNewMessage(AFB_FAIL,"Error: PostForm no PostContext to free\n"));
- }
-
- // We have a context but last Xform iteration fail or application set a message
- if (request->jresp != NULL) {
- jresp = request->jresp; // retrieve previous error from postCtx
- } else jresp = jsonNewMessage(AFB_SUCCESS,"getPostFile Post Request done");
-
- // Error or not let's free all resources
- close(postFileCtx->fd);
- free (postFileCtx->path);
- free (postFileCtx);
- return (jresp);
- }
-#if defined(PLEASE_FIX_ME_THE_ERROR_IS_postFileCtx_NOT_INITIALIZED)
- // Make sure it's a valid PostForm request
- if (!request->post && request->post->type != AFB_POST_FORM) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"This is not a valid PostForm request\n");
- goto ExitOnError;
- }
-
- // Check this is a file element
- if (item->filename == NULL) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"No Filename attached to key=%s\n", item->key);
- goto ExitOnError;
- }
-
- // Check we got something in buffer
- if (item->len <= 0) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"Buffer size NULL key=%s]\n", item->key);
- goto ExitOnError;
- }
-#endif
- // Extract Application Context from posthandle [NULL == 1st iteration]
- postFileCtx = (AFB_PostCtx*) postHandle->ctx;
-
- // This is the 1st Item iteration let's open output file and allocate necessary resources
- if (postFileCtx == NULL) {
- DIR* destDir;
-
- // Create an application specific context
- postFileCtx = calloc (1, sizeof(AFB_PostCtx)); // May place anything here until post->completeCB handle resources liberation
-
- // attach application to postHandle
- postHandle->ctx = (void*) postFileCtx; // May place anything here until post->completeCB handle resources liberation
-
- // Build destination directory full path
- if (destination[0] != '/') {
- strncpy (filepath, request->config->sessiondir, sizeof(filepath));
- strncat (filepath, "/", sizeof(filepath));
- strncat (filepath, destination, sizeof(filepath));
- } else strncpy (filepath, destination, sizeof(filepath));
-
-
- // make sure destination directory exist
- destDir = opendir (filepath);
- if (destDir == NULL) {
- if (mkdir(filepath,O_RDWR | S_IRWXU | S_IRGRP) < 0) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"Fail to Create destination directory=[%s] error=%s\n", filepath, strerror(errno));
- goto ExitOnError;
- }
- } else closedir (destDir);
-
- strncat (filepath, "/", sizeof(filepath));
- strncat (filepath, item->filename, sizeof(filepath));
-
- postFileCtx->path = strdup (filepath);
- if (verbose) fprintf(stderr, "getPostFile path=%s\n", filepath);
-
- if((postFileCtx->fd = open(filepath, O_RDWR |O_CREAT, S_IRWXU|S_IRGRP)) <= 0) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"Fail to Create destination File=[%s] error=%s\n", filepath, strerror(errno));
- goto ExitOnError;
- }
- } else {
- // reuse existing application context
- postFileCtx = (AFB_PostCtx*) postHandle->ctx;
- }
-
- // Check we successfully wrote full buffer
- len = write (postFileCtx->fd, item->data, item->len);
- if ((ssize_t)item->len != len) {
- postFileCtx->jresp= jsonNewMessage(AFB_FAIL,"Fail to write file [%s] at [%s] error=\n", item->filename, strerror(errno));
- goto ExitOnError;
- }
-
- // every intermediary iteration should return Success & NULL
- request->errcode = MHD_HTTP_OK;
- return NULL;
-
-ExitOnError:
- request->errcode = MHD_HTTP_EXPECTATION_FAILED;
- return NULL;
-}
-
-#endif
-
-static void jsoninit()
-{
- int idx, verbosesav;
-
- if (jTypeStatic)
- return;
-
- // initialise JSON constant messages and increase reference count to make them permanent
- verbosesav = verbose;
- verbose = 0; // run initialisation in silent mode
- jTypeStatic = json_object_new_string ("AFB_message");
- for (idx = 0; idx <= AFB_UNAUTH; idx++) {
- AFBerr[idx].level = idx;
- AFBerr[idx].label = ERROR_LABEL [idx];
- AFBerr[idx].json = jsonNewMessage (idx, NULL);
- }
- verbose = verbosesav;
-}
-
-
-// build an ERROR message and return it as a valid json object
-json_object *json_add_status (json_object *obj, const char *status, const char *info)
-{
- if (obj == NULL)
- obj = json_object_new_object();
- json_object_object_add(obj, "status", json_object_new_string(status));
- if (info)
- json_object_object_add(obj, "info", json_object_new_string(info));
- return obj;
-}
-
-// build an ERROR message and return it as a valid json object
-json_object *json_add_status_v (json_object *obj, const char *status, const char *info, va_list args)
-{
- char *message;
- if (info == NULL || vasprintf(&message, info, args) < 0)
- message = NULL;
- obj = json_add_status(obj, status, message);
- free(message);
- return obj;
-}
-
-
-// build an ERROR message and return it as a valid json object
-json_object *json_add_status_f (json_object *obj, const char *status, const char *info, ...)
-{
- va_list args;
- va_start(args, info);
- obj = json_add_status_v(obj, status, info, args);
- va_end(args);
- return obj;
-}
-
-
-
-// build an ERROR message and return it as a valid json object
-struct json_object *jsonNewMessage (AFB_error level, char* format, ...) {
- static int count = 0;
- json_object * AFBResponse;
- va_list args;
- char message [512];
-
- jsoninit();
-
- // format message
- if (format != NULL) {
- va_start(args, format);
- vsnprintf (message, sizeof (message), format, args);
- va_end(args);
- }
-
- AFBResponse = json_object_new_object();
- json_object_object_add (AFBResponse, "jtype", json_object_get (jTypeStatic));
- json_object_object_add (AFBResponse, "status" , json_object_new_string (ERROR_LABEL[level]));
- if (format != NULL) {
- json_object_object_add (AFBResponse, "info" , json_object_new_string (message));
- }
- if (verbose) {
- fprintf (stderr, "AFB:%-6s [%3d]: ", AFBerr [level].label, count++);
- if (format != NULL) {
- fprintf (stderr, "%s", message);
- } else {
- fprintf (stderr, "No Message");
- }
- fprintf (stderr, "\n");
- }
-
- return (AFBResponse);
-}
-
-#if 0
-{
- jtype: "AFB_message"
- request:
- {
- prefix: "",
- api: "",
- status: "", /* exist, fail, empty, null, processed */
- info: "",
- uuid: "",
- token: "",
- timeout: ""
- }
- response: ...
-}
-#endif
-
diff --git a/src/http-svc.c b/src/http-svc.c
index c767de71..b36d5f7e 100644
--- a/src/http-svc.c
+++ b/src/http-svc.c
@@ -32,6 +32,7 @@
#include "afb-websock.h"
#include "afb-apis.h"
#include "afb-req-itf.h"
+#include "verbose.h"
#define JSON_CONTENT "application/json"
#define FORM_CONTENT MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA
@@ -380,7 +381,7 @@ static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t
static int init_lib_magic (AFB_session *session)
{
/* MAGIC_MIME tells magic to return a mime of the file, but you can specify different things */
- if (verbose)
+ if (verbosity)
printf("Loading mimetype default magic database\n");
session->magic = magic_open(MAGIC_MIME_TYPE);
@@ -436,7 +437,7 @@ AFB_error httpdStart(AFB_session * session)
init_lib_magic (session);
#endif
- if (verbose) {
+ if (verbosity) {
printf("AFB:notice Waiting port=%d rootdir=%s\n", session->config->httpdPort, session->config->rootdir);
printf("AFB:notice Browser URL= http:/*localhost:%d\n", session->config->httpdPort);
}
@@ -472,10 +473,10 @@ AFB_error httpdLoop(AFB_session * session)
pfd.fd = info->listen_fd;
pfd.events = POLLIN;
- if (verbose)
+ if (verbosity)
fprintf(stderr, "AFB:notice entering httpd waiting loop\n");
while (TRUE) {
- if (verbose)
+ if (verbosity)
fprintf(stderr, "AFB:notice httpd alive [%d]\n", count++);
poll(&pfd, 1, 15000); /* 15 seconds (as above timeout when starting) */
MHD_run(session->httpd);
diff --git a/src/local-def.h b/src/local-def.h
index 39ae3181..3298322e 100644
--- a/src/local-def.h
+++ b/src/local-def.h
@@ -53,8 +53,6 @@
#define AUDIO_BUFFER "/tmp/buf"
-extern int verbose; // this is the only global variable
-
// prebuild json error are constructed in helper-api.c
typedef enum { AFB_FALSE, AFB_TRUE, AFB_FATAL, AFB_FAIL, AFB_WARNING, AFB_EMPTY, AFB_SUCCESS, AFB_DONE, AFB_UNAUTH} AFB_error;
diff --git a/src/main.c b/src/main.c
index 95b5a653..37183e72 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,7 @@
#include "local-def.h"
#include "afb-apis.h"
#include "session.h"
+#include "verbose.h"
#if !defined(PLUGIN_INSTALL_DIR)
#error "you should define PLUGIN_INSTALL_DIR"
@@ -255,7 +256,7 @@ static void parse_arguments(int argc, char *argv[], AFB_session *session)
switch (optc)
{
case SET_VERBOSE:
- verbose = 1;
+ verbosity++;
break;
case SET_TCP_PORT:
@@ -276,19 +277,19 @@ static void parse_arguments(int argc, char *argv[], AFB_session *session)
case SET_ROOT_DIR:
if (optarg == 0) goto needValueForOption;
session->config->rootdir = optarg;
- if (verbose) fprintf(stderr, "Forcing Rootdir=%s\n",session->config->rootdir);
+ if (verbosity) fprintf(stderr, "Forcing Rootdir=%s\n",session->config->rootdir);
break;
case SET_ROOT_BASE:
if (optarg == 0) goto needValueForOption;
session->config->rootbase = optarg;
- if (verbose) fprintf(stderr, "Forcing Rootbase=%s\n",session->config->rootbase);
+ if (verbosity) fprintf(stderr, "Forcing Rootbase=%s\n",session->config->rootbase);
break;
case SET_ROOT_API:
if (optarg == 0) goto needValueForOption;
session->config->rootapi = optarg;
- if (verbose) fprintf(stderr, "Forcing Rootapi=%s\n",session->config->rootapi);
+ if (verbosity) fprintf(stderr, "Forcing Rootapi=%s\n",session->config->rootapi);
break;
case SET_ALIAS:
@@ -300,7 +301,7 @@ static void parse_arguments(int argc, char *argv[], AFB_session *session)
} else {
aliasdir[aliascount].path = optarg;
aliasdir[aliascount].len = strlen(aliasdir[aliascount].url);
- if (verbose) fprintf(stderr, "Alias url=%s path=%s\n", aliasdir[aliascount].url, aliasdir[aliascount].path);
+ if (verbosity) fprintf(stderr, "Alias url=%s path=%s\n", aliasdir[aliascount].url, aliasdir[aliascount].path);
aliascount++;
}
} else {
@@ -581,19 +582,19 @@ int main(int argc, char *argv[]) {
exit (1);
}
#endif
- if (verbose) fprintf (stderr, "AFB: notice Init config done\n");
+ if (verbosity) fprintf (stderr, "AFB: notice Init config done\n");
// ---- run in foreground mode --------------------
if (session->foreground) {
- if (verbose) fprintf (stderr,"AFB: notice Foreground mode\n");
+ if (verbosity) fprintf (stderr,"AFB: notice Foreground mode\n");
} // end foreground
// --------- run in background mode -----------
if (session->background) {
- if (verbose) printf ("AFB: Entering background mode\n");
+ if (verbosity) printf ("AFB: Entering background mode\n");
daemonize(session);
@@ -605,7 +606,7 @@ int main(int argc, char *argv[]) {
listenLoop(session);
- if (verbose) printf ("\n---- Application Framework Binder Normal End ------\n");
+ if (verbosity) printf ("\n---- Application Framework Binder Normal End ------\n");
exit(0);
}
diff --git a/src/proto-def.h b/src/proto-def.h
index e2190eb1..b549a62e 100644
--- a/src/proto-def.h
+++ b/src/proto-def.h
@@ -19,16 +19,6 @@
*/
-// helper-api
-extern const char* getQueryValue (const AFB_request * request, const char *name);
-extern size_t getQueryAll(AFB_request * request, char *query, size_t len);
-/*
-extern json_object* getPostFile (AFB_request *request, AFB_PostItem *item, char* destination) ;
-extern char* getPostPath (AFB_request *request);
-*/
-
-extern json_object *jsonNewMessage (AFB_error level, char* format, ...);
-
// Httpd server
extern AFB_error httpdStart (AFB_session *session);
diff --git a/src/verbose.c b/src/verbose.c
new file mode 100644
index 00000000..7e46a333
--- /dev/null
+++ b/src/verbose.c
@@ -0,0 +1,29 @@
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "verbose.h"
+
+#if !defined(NDEBUG)
+int verbosity = 1;
+#else
+void verbose_error(const char *file, int line)
+{
+ syslog(LOG_ERR, "error file %s line %d", file, line);
+}
+#endif
+
diff --git a/src/verbose.h b/src/verbose.h
new file mode 100644
index 00000000..7b32a663
--- /dev/null
+++ b/src/verbose.h
@@ -0,0 +1,39 @@
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#if !defined(NDEBUG)
+#include <syslog.h>
+extern int verbosity;
+#define LOGUSER(app) openlog(app,LOG_PERROR,LOG_USER)
+#define LOGAUTH(app) openlog(app,LOG_PERROR,LOG_AUTH)
+#define ERROR(...) syslog(LOG_ERR,__VA_ARGS__)
+#define WARNING(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
+#define NOTICE(...) do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
+#define INFO(...) do{if(verbosity>1)syslog(LOG_INFO,__VA_ARGS__);}while(0)
+#define DEBUG(...) do{if(verbosity>2)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
+#else
+#include <syslog.h>
+#define LOGUSER(app) openlog(app,LOG_PERROR,LOG_USER)
+#define LOGAUTH(app) openlog(app,LOG_PERROR,LOG_AUTH)
+extern void verbose_error(const char *file, int line);
+#define ERROR(...) verbose_error(__FILE__,__LINE__)
+#define WARNING(...) do{/*nothing*/}while(0)
+#define NOTICE(...) do{/*nothing*/}while(0)
+#define INFO(...) do{/*nothing*/}while(0)
+#define DEBUG(...) do{/*nothing*/}while(0)
+#endif