libimcv: Moved REST API from imv_swid and imv_swima to libimcv
authorAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 26 Jun 2017 16:07:11 +0000 (18:07 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 8 Jul 2017 21:19:51 +0000 (23:19 +0200)
12 files changed:
configure.ac
src/libimcv/Makefile.am
src/libimcv/plugins/imv_swid/Makefile.am
src/libimcv/plugins/imv_swid/imv_swid_agent.c
src/libimcv/plugins/imv_swid/imv_swid_rest.c [deleted file]
src/libimcv/plugins/imv_swid/imv_swid_rest.h [deleted file]
src/libimcv/plugins/imv_swima/Makefile.am
src/libimcv/plugins/imv_swima/imv_swima_agent.c
src/libimcv/plugins/imv_swima/imv_swima_rest.c [deleted file]
src/libimcv/plugins/imv_swima/imv_swima_rest.h [deleted file]
src/libimcv/rest/rest.c [new file with mode: 0644]
src/libimcv/rest/rest.h [new file with mode: 0644]

index e6e0402..4c45200 100644 (file)
@@ -1003,7 +1003,7 @@ if test x$tss_tss2 = xtrue; then
        AC_SUBST(tss2_LIBS)
 fi
 
-if test x$imv_swid = xtrue -o x$imv_swima = xtrue; then
+if test x$imc_swima = xtrue -o $imv_swima = xtrue -o x$imv_swid = xtrue; then
        PKG_CHECK_MODULES(json, [json-c], [],
                [PKG_CHECK_MODULES(json, [json])])
        AC_SUBST(json_CFLAGS)
@@ -1711,6 +1711,9 @@ fi
 if test x$fuzzing = xtrue; then
        AC_DEFINE([USE_FUZZING], [], [build code for fuzzing])
 fi
+if test x$imc_swima = xtrue -o x$imv_swima = xtrue -o x$imv_swid = xtrue ; then
+       AC_DEFINE([USE_JSON], [], [build code for JSON])
+fi
 
 # ====================================================
 #  options for enabled modules (see conf/Makefile.am)
index ab66bcc..dda0c2c 100644 (file)
@@ -5,6 +5,9 @@ AM_CPPFLAGS = \
        -DIPSEC_SCRIPT=\"${ipsec_script}\" \
        -DSWID_DIRECTORY=\"${prefix}/share\"
 
+AM_CFLAGS = \
+       $(json_CFLAGS)
+
 ipseclib_LTLIBRARIES = libimcv.la
 
 libimcv_la_LDFLAGS = \
@@ -13,7 +16,8 @@ libimcv_la_LDFLAGS = \
 libimcv_la_LIBADD = \
        $(top_builddir)/src/libstrongswan/libstrongswan.la \
        $(top_builddir)/src/libtncif/libtncif.la \
-       $(top_builddir)/src/libtpmtss/libtpmtss.la
+       $(top_builddir)/src/libtpmtss/libtpmtss.la \
+       $(json_LIBS)
 
 if USE_WINDOWS
   libimcv_la_LIBADD += -lws2_32
@@ -88,6 +92,7 @@ libimcv_la_SOURCES = \
        pts/components/tcg/tcg_comp_func_name.h pts/components/tcg/tcg_comp_func_name.c \
        pwg/pwg_attr.h pwg/pwg_attr.c \
        pwg/pwg_attr_vendor_smi_code.h pwg/pwg_attr_vendor_smi_code.c \
+       rest/rest.h rest/rest.c \
        seg/seg_contract.h seg/seg_contract.c \
        seg/seg_contract_manager.h seg/seg_contract_manager.c \
        seg/seg_env.h seg/seg_env.c \
index 73da84b..e573ea0 100644 (file)
@@ -16,7 +16,6 @@ imv_swid_la_LIBADD = \
 
 imv_swid_la_SOURCES = \
        imv_swid.c imv_swid_state.h imv_swid_state.c \
-       imv_swid_agent.h imv_swid_agent.c \
-       imv_swid_rest.h imv_swid_rest.c
+       imv_swid_agent.h imv_swid_agent.c
 
 imv_swid_la_LDFLAGS = -module -avoid-version -no-undefined
index c057e7e..09a387f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2016 Andreas Steffen
+ * Copyright (C) 2013-2017 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
 
 #include "imv_swid_agent.h"
 #include "imv_swid_state.h"
-#include "imv_swid_rest.h"
 
 #include <imcv.h>
 #include <imv/imv_agent.h>
 #include <imv/imv_msg.h>
 #include <ietf/ietf_attr_pa_tnc_error.h>
+#include "rest/rest.h"
 #include "tcg/seg/tcg_seg_attr_max_size.h"
 #include "tcg/seg/tcg_seg_attr_seg_env.h"
 #include "tcg/swid/tcg_swid_attr_req.h"
@@ -72,7 +72,7 @@ struct private_imv_swid_agent_t {
        /**
         * REST API to strongTNC manager
         */
-       imv_swid_rest_t *rest_api;
+       rest_t *rest_api;
 
 };
 
@@ -719,7 +719,7 @@ imv_agent_if_t *imv_swid_agent_create(const char *name, TNC_IMVID id,
                                                "%s.plugins.imv-swid.rest_api_timeout", 120, lib->ns);
        if (rest_api_uri)
        {
-               this->rest_api = imv_swid_rest_create(rest_api_uri, rest_api_timeout);
+               this->rest_api = rest_create(rest_api_uri, rest_api_timeout);
        }
 
        return &this->public;
diff --git a/src/libimcv/plugins/imv_swid/imv_swid_rest.c b/src/libimcv/plugins/imv_swid/imv_swid_rest.c
deleted file mode 100644 (file)
index 0fe96ed..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * 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 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-
-#include "imv_swid_rest.h"
-
-typedef struct private_imv_swid_rest_t private_imv_swid_rest_t;
-
-/**
- * Private data of an imv_swid_rest_t object.
- */
-struct private_imv_swid_rest_t {
-
-       /**
-        * Public members of imv_swid_rest_t
-        */
-       imv_swid_rest_t public;
-
-       /**
-        * URI of REST API
-        */
-       char *uri;
-
-       /**
-        * Timeout of REST API connection
-        */
-       u_int timeout;
-
-};
-
-#define HTTP_STATUS_CODE_PRECONDITION_FAILED   412
-
-METHOD(imv_swid_rest_t, post, status_t,
-       private_imv_swid_rest_t *this, char *command, json_object *jrequest,
-       json_object **jresponse)
-{
-       struct json_tokener *tokener;
-       chunk_t data, response = chunk_empty;
-       status_t status;
-       char *uri;
-       int code;
-
-       if (asprintf(&uri, "%s%s",this->uri, command) < 0)
-       {
-               return FAILED;
-       }
-       data = chunk_from_str((char*)json_object_to_json_string(jrequest));
-
-       status = lib->fetcher->fetch(lib->fetcher, uri, &response,
-                               FETCH_TIMEOUT, this->timeout,
-                               FETCH_REQUEST_DATA, data,
-                               FETCH_REQUEST_TYPE, "application/json; charset=utf-8",
-                               FETCH_REQUEST_HEADER, "Accept: application/json",
-                               FETCH_REQUEST_HEADER, "Expect:",
-                               FETCH_RESPONSE_CODE, &code,
-                               FETCH_END);
-       free(uri);
-
-       if (status != SUCCESS)
-       {
-               if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr)
-               {
-                       DBG2(DBG_IMV, "REST http request failed with status code: %d", code);
-                       status = FAILED;
-               }
-               else
-               {
-                       if (jresponse)
-                       {
-                               /* Parse HTTP response into a JSON object */
-                               tokener = json_tokener_new();
-                               *jresponse = json_tokener_parse_ex(tokener, response.ptr,
-                                                                                                                       response.len);
-                               json_tokener_free(tokener);
-                       }
-                       status = NEED_MORE;
-               }
-       }
-       free(response.ptr);
-
-       return status;
-}
-
-METHOD(imv_swid_rest_t, destroy, void,
-       private_imv_swid_rest_t *this)
-{
-       free(this->uri);
-       free(this);
-}
-
-/**
- * Described in header.
- */
-imv_swid_rest_t *imv_swid_rest_create(char *uri, u_int timeout)
-{
-       private_imv_swid_rest_t *this;
-
-       INIT(this,
-               .public = {
-                       .post = _post,
-                       .destroy = _destroy,
-               },
-               .uri = strdup(uri),
-               .timeout = timeout,
-       );
-
-       return &this->public;
-}
-
-
diff --git a/src/libimcv/plugins/imv_swid/imv_swid_rest.h b/src/libimcv/plugins/imv_swid/imv_swid_rest.h
deleted file mode 100644 (file)
index 32392cb..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2013-2014 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * 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 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-/**
- * @defgroup imv_swid imv_swid
- * @ingroup libimcv_plugins
- *
- * @defgroup imv_swid_rest_t imv_swid_rest
- * @{ @ingroup imv_swid
- */
-
-#ifndef IMV_SWID_REST_H_
-#define IMV_SWID_REST_H_
-
-#include <library.h>
-
-#include <json.h>
-
-typedef struct imv_swid_rest_t imv_swid_rest_t;
-
-/**
- * Public REST interface
- */
-struct imv_swid_rest_t {
-
-       /**
-        * Post a HTTP request including a JSON object
-        *
-        * @param jreq          JSON object in HTTP request
-        * @param jresp         JSON object in HTTP response if NEED_MORE
-        * @return                      Status (SUCCESS, NEED_MORE or FAILED)
-        */
-       status_t (*post)(imv_swid_rest_t *this, char *command, json_object *jreq,
-                                        json_object **jresp);
-
-       /**
-        * Destroy imv_swid_rest_t object
-        */
-       void (*destroy)(imv_swid_rest_t *this);
-
-};
-
-/**
- * Create an imv_swid_rest_t instance
- *
- * @param uri                  REST URI (http://username:password@hostname[:port]/api/)
- * @param timeout              Timeout of the REST connection
- */
-imv_swid_rest_t* imv_swid_rest_create(char *uri, u_int timeout);
-
-#endif /** IMV_SWID_REST_H_ @}*/
index 0c54841..b1726f0 100644 (file)
@@ -16,7 +16,6 @@ imv_swima_la_LIBADD = \
 
 imv_swima_la_SOURCES = \
        imv_swima.c imv_swima_state.h imv_swima_state.c \
-       imv_swima_agent.h imv_swima_agent.c \
-       imv_swima_rest.h imv_swima_rest.c
+       imv_swima_agent.h imv_swima_agent.c
 
 imv_swima_la_LDFLAGS = -module -avoid-version -no-undefined
index 5d653ff..eedc5da 100644 (file)
 
 #include "imv_swima_agent.h"
 #include "imv_swima_state.h"
-#include "imv_swima_rest.h"
 
 #include <imcv.h>
 #include <imv/imv_agent.h>
 #include <imv/imv_msg.h>
+#include "rest/rest.h"
 #include "tcg/seg/tcg_seg_attr_max_size.h"
 #include "tcg/seg/tcg_seg_attr_seg_env.h"
 #include "ietf/swima/ietf_swima_attr_req.h"
@@ -73,7 +73,7 @@ struct private_imv_swima_agent_t {
        /**
         * REST API to strongTNC manager
         */
-       imv_swima_rest_t *rest_api;
+       rest_t *rest_api;
 
 };
 
@@ -770,7 +770,7 @@ imv_agent_if_t *imv_swima_agent_create(const char *name, TNC_IMVID id,
                                                "%s.plugins.imv-swima.rest_api_timeout", 120, lib->ns);
        if (rest_api_uri)
        {
-               this->rest_api = imv_swima_rest_create(rest_api_uri, rest_api_timeout);
+               this->rest_api = rest_create(rest_api_uri, rest_api_timeout);
        }
 
        return &this->public;
diff --git a/src/libimcv/plugins/imv_swima/imv_swima_rest.c b/src/libimcv/plugins/imv_swima/imv_swima_rest.c
deleted file mode 100644 (file)
index b82e38a..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2017 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * 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 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-
-#include "imv_swima_rest.h"
-
-typedef struct private_imv_swima_rest_t private_imv_swima_rest_t;
-
-/**
- * Private data of an imv_swima_rest_t object.
- */
-struct private_imv_swima_rest_t {
-
-       /**
-        * Public members of imv_swima_rest_t
-        */
-       imv_swima_rest_t public;
-
-       /**
-        * URI of REST API
-        */
-       char *uri;
-
-       /**
-        * Timeout of REST API connection
-        */
-       u_int timeout;
-
-};
-
-#define HTTP_STATUS_CODE_PRECONDITION_FAILED   412
-
-METHOD(imv_swima_rest_t, post, status_t,
-       private_imv_swima_rest_t *this, char *command, json_object *jrequest,
-       json_object **jresponse)
-{
-       struct json_tokener *tokener;
-       chunk_t data, response = chunk_empty;
-       status_t status;
-       char *uri;
-       int code;
-
-       if (asprintf(&uri, "%s%s",this->uri, command) < 0)
-       {
-               return FAILED;
-       }
-       data = chunk_from_str((char*)json_object_to_json_string(jrequest));
-
-       status = lib->fetcher->fetch(lib->fetcher, uri, &response,
-                               FETCH_TIMEOUT, this->timeout,
-                               FETCH_REQUEST_DATA, data,
-                               FETCH_REQUEST_TYPE, "application/json; charset=utf-8",
-                               FETCH_REQUEST_HEADER, "Accept: application/json",
-                               FETCH_REQUEST_HEADER, "Expect:",
-                               FETCH_RESPONSE_CODE, &code,
-                               FETCH_END);
-       free(uri);
-
-       if (status != SUCCESS)
-       {
-               if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr)
-               {
-                       DBG2(DBG_IMV, "REST http request failed with status code: %d", code);
-                       status = FAILED;
-               }
-               else
-               {
-                       if (jresponse)
-                       {
-                               /* Parse HTTP response into a JSON object */
-                               tokener = json_tokener_new();
-                               *jresponse = json_tokener_parse_ex(tokener, response.ptr,
-                                                                                                                       response.len);
-                               json_tokener_free(tokener);
-                       }
-                       status = NEED_MORE;
-               }
-       }
-       free(response.ptr);
-
-       return status;
-}
-
-METHOD(imv_swima_rest_t, destroy, void,
-       private_imv_swima_rest_t *this)
-{
-       free(this->uri);
-       free(this);
-}
-
-/**
- * Described in header.
- */
-imv_swima_rest_t *imv_swima_rest_create(char *uri, u_int timeout)
-{
-       private_imv_swima_rest_t *this;
-
-       INIT(this,
-               .public = {
-                       .post = _post,
-                       .destroy = _destroy,
-               },
-               .uri = strdup(uri),
-               .timeout = timeout,
-       );
-
-       return &this->public;
-}
-
-
diff --git a/src/libimcv/plugins/imv_swima/imv_swima_rest.h b/src/libimcv/plugins/imv_swima/imv_swima_rest.h
deleted file mode 100644 (file)
index 55266dd..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2017 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * 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 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-/**
- * @defgroup imv_swima imv_swima
- * @ingroup libimcv_plugins
- *
- * @defgroup imv_swima_rest_t imv_swima_rest
- * @{ @ingroup imv_swima
- */
-
-#ifndef IMV_SWIMA_REST_H_
-#define IMV_SWIMA_REST_H_
-
-#include <library.h>
-
-#include <json.h>
-
-typedef struct imv_swima_rest_t imv_swima_rest_t;
-
-/**
- * Public REST interface
- */
-struct imv_swima_rest_t {
-
-       /**
-        * Post a HTTP request including a JSON object
-        *
-        * @param jreq          JSON object in HTTP request
-        * @param jresp         JSON object in HTTP response if NEED_MORE
-        * @return                      Status (SUCCESS, NEED_MORE or FAILED)
-        */
-       status_t (*post)(imv_swima_rest_t *this, char *command, json_object *jreq,
-                                        json_object **jresp);
-
-       /**
-        * Destroy imv_swima_rest_t object
-        */
-       void (*destroy)(imv_swima_rest_t *this);
-
-};
-
-/**
- * Create an imv_swima_rest_t instance
- *
- * @param uri                  REST URI (http://username:password@hostname[:port]/api/)
- * @param timeout              Timeout of the REST connection
- */
-imv_swima_rest_t* imv_swima_rest_create(char *uri, u_int timeout);
-
-#endif /** IMV_SWIMA_REST_H_ @}*/
diff --git a/src/libimcv/rest/rest.c b/src/libimcv/rest/rest.c
new file mode 100644 (file)
index 0000000..531da09
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2017 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#ifdef USE_JSON
+
+#define _GNU_SOURCE
+#include <stdio.h>
+
+#include "rest.h"
+
+typedef struct private_rest_t private_rest_t;
+
+/**
+ * Private data of an rest_t object.
+ */
+struct private_rest_t {
+
+       /**
+        * Public members of rest_t
+        */
+       rest_t public;
+
+       /**
+        * URI of REST API
+        */
+       char *uri;
+
+       /**
+        * Timeout of REST API connection
+        */
+       u_int timeout;
+
+};
+
+METHOD(rest_t, get, status_t,
+       private_rest_t *this, char *command, json_object **jresponse)
+{
+       struct json_tokener *tokener;
+       chunk_t response = chunk_empty;
+       status_t status;
+       char *uri;
+
+       if (asprintf(&uri, "%s%s",this->uri, command) < 0)
+       {
+               return FAILED;
+       }
+
+       status = lib->fetcher->fetch(lib->fetcher, uri, &response,
+                               FETCH_TIMEOUT, this->timeout,
+                               FETCH_END);
+       free(uri);
+
+       if (status == SUCCESS && jresponse)
+       {
+               /* Parse HTTP response into a JSON object */
+               tokener = json_tokener_new();
+               *jresponse = json_tokener_parse_ex(tokener, response.ptr, response.len);
+               json_tokener_free(tokener);
+       }
+       free(response.ptr);
+
+       return status;
+}
+
+#define HTTP_STATUS_CODE_NOT_FOUND                             404
+#define HTTP_STATUS_CODE_PRECONDITION_FAILED   412
+
+METHOD(rest_t, post, status_t,
+       private_rest_t *this, char *command, json_object *jrequest,
+       json_object **jresponse)
+{
+       struct json_tokener *tokener;
+       chunk_t data, response = chunk_empty;
+       status_t status;
+       char *uri;
+       int code;
+
+       if (asprintf(&uri, "%s%s",this->uri, command) < 0)
+       {
+               return FAILED;
+       }
+       data = chunk_from_str((char*)json_object_to_json_string(jrequest));
+
+       status = lib->fetcher->fetch(lib->fetcher, uri, &response,
+                               FETCH_TIMEOUT, this->timeout,
+                               FETCH_REQUEST_DATA, data,
+                               FETCH_REQUEST_TYPE, "application/json; charset=utf-8",
+                               FETCH_REQUEST_HEADER, "Accept: application/json",
+                               FETCH_REQUEST_HEADER, "Expect:",
+                               FETCH_RESPONSE_CODE, &code,
+                               FETCH_END);
+       free(uri);
+
+       if (status != SUCCESS)
+       {
+               switch (code)
+               {
+                       case HTTP_STATUS_CODE_NOT_FOUND:
+                               status = NOT_FOUND;
+                               break;
+                       case HTTP_STATUS_CODE_PRECONDITION_FAILED:
+                               if (!response.ptr)
+                               {
+                                       return FAILED;
+                               }
+                               if (jresponse)
+                               {
+                                       /* Parse HTTP response into a JSON object */
+                                       tokener = json_tokener_new();
+                                       *jresponse = json_tokener_parse_ex(tokener, response.ptr,
+                                                                                                                               response.len);
+                                       json_tokener_free(tokener);
+                               }
+                               status = NEED_MORE;
+                               break;
+                       default:
+                               DBG2(DBG_IMV, "REST http request failed with status code: %d",
+                                                          code);
+                               status = FAILED;
+                               break;
+               }
+       }
+       free(response.ptr);
+
+       return status;
+}
+
+METHOD(rest_t, destroy, void,
+       private_rest_t *this)
+{
+       free(this->uri);
+       free(this);
+}
+
+/**
+ * Described in header.
+ */
+rest_t *rest_create(char *uri, u_int timeout)
+{
+       private_rest_t *this;
+
+       INIT(this,
+               .public = {
+                       .get = _get,
+                       .post = _post,
+                       .destroy = _destroy,
+               },
+               .uri = strdup(uri),
+               .timeout = timeout,
+       );
+
+       return &this->public;
+}
+
+#endif /* USE_JSON */
diff --git a/src/libimcv/rest/rest.h b/src/libimcv/rest/rest.h
new file mode 100644 (file)
index 0000000..bddb881
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+/**
+ * @defgroup imv_swima imv_swima
+ * @ingroup libimcv_plugins
+ *
+ * @defgroup rest_t rest
+ * @{ @ingroup imv_swima
+ */
+
+#ifndef REST_H_
+#define REST_H_
+
+#ifdef USE_JSON
+
+#include <library.h>
+#include <json.h>
+
+typedef struct rest_t rest_t;
+
+/**
+ * Public REST interface
+ */
+struct rest_t {
+
+       /**
+        * Send an HTTP GET request returning a JSON object
+        *
+        * @param jresp         JSON object in HTTP
+        * @return                      Status (SUCCESS or FAILED)
+        */
+       status_t (*get)(rest_t *this, char *command, json_object **jresp);
+
+       /**
+        * Send an HTTP POST request including a JSON object
+        *
+        * @param jreq          JSON object in HTTP request
+        * @param jresp         JSON object in HTTP response if NEED_MORE
+        * @return                      Status (SUCCESS, NEED_MORE or FAILED)
+        */
+       status_t (*post)(rest_t *this, char *command, json_object *jreq,
+                                        json_object **jresp);
+
+       /**
+        * Destroy rest_t object
+        */
+       void (*destroy)(rest_t *this);
+
+};
+
+/**
+ * Create an rest_t instance
+ *
+ * @param uri                  REST URI (http://username:password@hostname[:port]/api/)
+ * @param timeout              Timeout of the REST connection
+ */
+rest_t* rest_create(char *uri, u_int timeout);
+
+#endif /* USE_JSON */
+
+#endif /** REST_H_ @}*/