aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-20 00:06:56 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-20 00:06:56 +0200
commit711d2d431b27b7232de735c6f96b39cd94dd23c6 (patch)
tree6cf82fbf927b7873ca468997bc00b1ffd445a4dd /src
parentb3073c7afc6d1a4c6c953d7e0d86b0821ed9df41 (diff)
downloadgnunet-711d2d431b27b7232de735c6f96b39cd94dd23c6.tar.gz
gnunet-711d2d431b27b7232de735c6f96b39cd94dd23c6.zip
REST: Remove plugins. Hardcode features
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/include/gnunet_rest_plugin.h21
-rw-r--r--src/meson.build1
-rw-r--r--src/rest-plugin/Makefile.am6
-rw-r--r--src/rest-plugin/gns/Makefile.am61
-rw-r--r--src/rest-plugin/gns/meson.build13
-rwxr-xr-xsrc/rest-plugin/gns/test_plugin_rest_gns.sh76
-rw-r--r--src/rest-plugin/identity/Makefile.am26
-rw-r--r--src/rest-plugin/identity/meson.build11
-rw-r--r--src/rest-plugin/meson.build7
-rw-r--r--src/rest-plugin/namestore/Makefile.am53
-rw-r--r--src/rest-plugin/namestore/meson.build14
-rw-r--r--src/rest-plugin/reclaim/Makefile.am81
-rw-r--r--src/rest-plugin/reclaim/meson.build29
-rw-r--r--src/rest-plugin/rest/Makefile.am37
-rw-r--r--src/rest-plugin/rest/meson.build18
-rw-r--r--src/service/Makefile.am4
-rw-r--r--src/service/meson.build4
-rw-r--r--src/service/rest/Makefile.am18
-rw-r--r--src/service/rest/config_plugin.c (renamed from src/rest-plugin/rest/plugin_rest_config.c)69
-rw-r--r--src/service/rest/config_plugin.h37
-rw-r--r--src/service/rest/copying_plugin.c (renamed from src/rest-plugin/rest/plugin_rest_copying.c)23
-rw-r--r--src/service/rest/copying_plugin.h36
-rw-r--r--src/service/rest/gns_plugin.c (renamed from src/rest-plugin/gns/plugin_rest_gns.c)27
-rw-r--r--src/service/rest/gns_plugin.h36
-rw-r--r--src/service/rest/gnunet-rest-server.c145
-rw-r--r--src/service/rest/identity_plugin.c (renamed from src/rest-plugin/identity/plugin_rest_identity.c)39
-rw-r--r--src/service/rest/identity_plugin.h36
-rw-r--r--src/service/rest/json_reclaim.c (renamed from src/rest-plugin/reclaim/json_reclaim.c)0
-rw-r--r--src/service/rest/json_reclaim.h (renamed from src/rest-plugin/reclaim/json_reclaim.h)0
-rw-r--r--src/service/rest/meson.build26
-rw-r--r--src/service/rest/namestore_plugin.c (renamed from src/rest-plugin/namestore/plugin_rest_namestore.c)34
-rw-r--r--src/service/rest/namestore_plugin.h37
-rw-r--r--src/service/rest/oidc_helper.c (renamed from src/rest-plugin/reclaim/oidc_helper.c)0
-rw-r--r--src/service/rest/oidc_helper.h (renamed from src/rest-plugin/reclaim/oidc_helper.h)0
-rw-r--r--src/service/rest/openid_plugin.c (renamed from src/rest-plugin/reclaim/plugin_rest_openid_connect.c)61
-rw-r--r--src/service/rest/openid_plugin.h36
-rw-r--r--src/service/rest/pabc_plugin.c (renamed from src/rest-plugin/reclaim/plugin_rest_pabc.c)0
-rw-r--r--src/service/rest/reclaim_plugin.c (renamed from src/rest-plugin/reclaim/plugin_rest_reclaim.c)31
-rw-r--r--src/service/rest/reclaim_plugin.h36
40 files changed, 549 insertions, 641 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c0c5309b2..524b989c1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,5 @@ SUBDIRS = \
7 lib \ 7 lib \
8 plugin \ 8 plugin \
9 service \ 9 service \
10 rest-plugin \
11 cli \ 10 cli \
12 contrib 11 contrib
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index 45b391ca1..3a8af5389 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -63,24 +63,13 @@ struct GNUNET_REST_Plugin
63 * e.g. http://hostname:port/name 63 * e.g. http://hostname:port/name
64 */ 64 */
65 char *name; 65 char *name;
66
67 /**
68 * Function to process a REST call
69 *
70 * @param method the HTTP method called
71 * @param url the relative url accessed
72 * @param data the REST data (can be NULL)
73 * @param data_size the length of the data
74 * @param proc the callback for result
75 * @param proc_cls closure for callback
76 * @return GNUNET_YES if the request was processed
77 */
78 enum GNUNET_GenericReturnValue (*process_request)(
79 struct GNUNET_REST_RequestHandle *handle,
80 GNUNET_REST_ResultProcessor proc,
81 void *proc_cls);
82}; 66};
83 67
68typedef enum GNUNET_GenericReturnValue (*GNUNET_REST_ProcessingFunction)(
69 void *plugin,
70 struct GNUNET_REST_RequestHandle *handle,
71 GNUNET_REST_ResultProcessor proc,
72 void *proc_cls);
84 73
85#if 0 /* keep Emacsens' auto-indent happy */ 74#if 0 /* keep Emacsens' auto-indent happy */
86{ 75{
diff --git a/src/meson.build b/src/meson.build
index 0a2dab664..8f8342a4d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,6 +6,5 @@ subdir('include')
6subdir('lib') 6subdir('lib')
7subdir('plugin') 7subdir('plugin')
8subdir('service') 8subdir('service')
9subdir('rest-plugin')
10subdir('cli') 9subdir('cli')
11subdir('contrib') 10subdir('contrib')
diff --git a/src/rest-plugin/Makefile.am b/src/rest-plugin/Makefile.am
deleted file mode 100644
index 3379cb24e..000000000
--- a/src/rest-plugin/Makefile.am
+++ /dev/null
@@ -1,6 +0,0 @@
1SUBDIRS = \
2 rest \
3 identity \
4 namestore \
5 gns \
6 reclaim
diff --git a/src/rest-plugin/gns/Makefile.am b/src/rest-plugin/gns/Makefile.am
deleted file mode 100644
index 48b278df6..000000000
--- a/src/rest-plugin/gns/Makefile.am
+++ /dev/null
@@ -1,61 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4if HAVE_LIBIDN
5 LIBIDN= -lidn
6else
7 LIBIDN=
8endif
9
10if HAVE_LIBIDN2
11 LIBIDN2= -lidn2
12else
13 LIBIDN2=
14endif
15
16USE_VPN = $(top_builddir)/src/service/vpn/libgnunetvpn.la
17
18if USE_COVERAGE
19 AM_CFLAGS = --coverage -O0
20endif
21
22pkgcfgdir = $(pkgdatadir)/config.d/
23
24libexecdir= $(pkglibdir)/libexec/
25
26plugindir = $(libdir)/gnunet
27
28REST_PLUGIN = libgnunet_plugin_rest_gns.la
29
30plugin_LTLIBRARIES = \
31 $(REST_PLUGIN)
32
33
34libgnunet_plugin_rest_gns_la_SOURCES = \
35 plugin_rest_gns.c
36libgnunet_plugin_rest_gns_la_LIBADD = \
37 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
38 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecordjson.la \
39 $(top_builddir)/src/service/gns/libgnunetgns.la \
40 $(top_builddir)/src/service/rest/libgnunetrest.la \
41 $(top_builddir)/src/service/identity/libgnunetidentity.la \
42 $(top_builddir)/src/lib/json/libgnunetjson.la \
43 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
44 $(LTLIBINTL) -ljansson $(MHD_LIBS)
45libgnunet_plugin_rest_gns_la_LDFLAGS = \
46 $(GN_PLUGIN_LDFLAGS)
47libgnunet_plugin_rest_gns_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
48
49
50check_SCRIPTS = \
51 test_plugin_rest_gns.sh
52
53EXTRA_DIST = \
54 test_plugin_rest_gns.sh
55
56if ENABLE_TEST_RUN
57if HAVE_SQLITE
58 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
59 TESTS = $(check_SCRIPTS)
60endif
61endif
diff --git a/src/rest-plugin/gns/meson.build b/src/rest-plugin/gns/meson.build
deleted file mode 100644
index 7a4deffed..000000000
--- a/src/rest-plugin/gns/meson.build
+++ /dev/null
@@ -1,13 +0,0 @@
1shared_module('gnunet_plugin_rest_gns',
2 ['plugin_rest_gns.c'],
3 dependencies: [libgnunetrest_dep,
4 libgnunetgnsrecord_dep,
5 libgnunetgnsrecordjson_dep,
6 libgnunetgns_dep,
7 libgnunetutil_dep,
8 json_dep,
9 mhd_dep],
10 include_directories: [incdir, configuration_inc],
11 install: true,
12 install_dir: get_option('libdir') / 'gnunet')
13
diff --git a/src/rest-plugin/gns/test_plugin_rest_gns.sh b/src/rest-plugin/gns/test_plugin_rest_gns.sh
deleted file mode 100755
index 3bcfb5a08..000000000
--- a/src/rest-plugin/gns/test_plugin_rest_gns.sh
+++ /dev/null
@@ -1,76 +0,0 @@
1#!/bin/sh
2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" INT
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17
18gns_link="http://localhost:7776/gns"
19wrong_link="http://localhost:7776/gnsandmore"
20
21curl_get () {
22 #$1 is link
23 #$2 is grep
24 XURL=`which curl`
25 if [ "" = "$XURL" ]
26 then
27 echo "HTTP client (curl) not found, exiting"
28 exit 77
29 fi
30 sleep 0.5
31 cache="$(${XURL} -v "$1" 2>&1 | grep "$2")"
32 #echo "$cache"
33 if [ "" = "$cache" ]
34 then
35 gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1
36 gnunet-arm -e -c test_gns_lookup.conf
37 echo "Download of $1 using $XURL failed, expected $2"
38 exit 1
39 fi
40}
41TEST_TLD="testtld"
42
43gnunet-arm -s -c test_gns_lookup.conf
44
45curl_get "$gns_link/www.$TEST_TLD" "error"
46
47gnunet-identity -C "$TEST_TLD" -c test_gns_lookup.conf
48sleep 0.5
49curl_get "$gns_link/www.$TEST_TLD" "\[\]"
50
51gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1.1.1.1 -t A -c test_gns_lookup.conf
52
53curl_get "$gns_link/www.$TEST_TLD" "1.1.1.1"
54
55gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1::1 -t AAAA -c test_gns_lookup.conf
56
57curl_get "$gns_link/www.$TEST_TLD" "1::1.*1.1.1.1"
58
59gnunet-namestore -z "$TEST_TLD" -p -a -n www -e 1d -V 1.1.1.2 -t A -c test_gns_lookup.conf
60
61curl_get "$gns_link/www.$TEST_TLD" "1.1.1.2.*1::1.*1.1.1.1"
62curl_get "$gns_link/www.$TEST_TLD?record_type=A" "1.1.1.2.*1.1.1.1"
63curl_get "$gns_link/www.$TEST_TLD?record_type=AAAA" "1::1"
64curl_get "$gns_link/www.$TEST_TLD?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
65
66gnunet-namestore -z "$TEST_TLD" -p -a -n www1 -e 1d -V 1.1.1.1 -t A -c test_gns_lookup.conf
67curl_get "$gns_link/www1.$TEST_TLD" "1.1.1.1"
68
69gnunet-namestore -z "$TEST_TLD" -d -n www1 -c test_gns_lookup.conf
70gnunet-namestore -z "$TEST_TLD" -d -n www -c test_gns_lookup.conf
71
72gnunet-identity -D "$TEST_TLD" -c test_gns_lookup.conf > /dev/null 2>&1
73
74curl_get "$gns_link/www1.$TEST_TLD" "error"
75gnunet-arm -e -c test_gns_lookup.conf
76exit 0
diff --git a/src/rest-plugin/identity/Makefile.am b/src/rest-plugin/identity/Makefile.am
deleted file mode 100644
index bcad0c2dd..000000000
--- a/src/rest-plugin/identity/Makefile.am
+++ /dev/null
@@ -1,26 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4plugindir = $(libdir)/gnunet
5
6if USE_COVERAGE
7 AM_CFLAGS = --coverage -O0
8 XLIB = -lgcov
9endif
10
11plugin_LTLIBRARIES = libgnunet_plugin_rest_identity.la
12
13pkgcfgdir= $(pkgdatadir)/config.d/
14
15libexecdir= $(pkglibdir)/libexec/
16
17libgnunet_plugin_rest_identity_la_SOURCES = \
18 plugin_rest_identity.c
19libgnunet_plugin_rest_identity_la_LIBADD = \
20 $(top_builddir)/src/service/identity/libgnunetidentity.la \
21 $(top_builddir)/src/service/rest/libgnunetrest.la \
22 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
23 $(LTLIBINTL) -ljansson $(MHD_LIBS)
24libgnunet_plugin_rest_identity_la_LDFLAGS = \
25 $(GN_PLUGIN_LDFLAGS)
26libgnunet_plugin_rest_identity_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
diff --git a/src/rest-plugin/identity/meson.build b/src/rest-plugin/identity/meson.build
deleted file mode 100644
index f459918db..000000000
--- a/src/rest-plugin/identity/meson.build
+++ /dev/null
@@ -1,11 +0,0 @@
1shared_module('gnunet_plugin_rest_identity',
2 ['plugin_rest_identity.c'],
3 dependencies: [libgnunetrest_dep,
4 libgnunetidentity_dep,
5 libgnunetutil_dep,
6 json_dep,
7 mhd_dep],
8 include_directories: [incdir, configuration_inc],
9 install: true,
10 install_dir: get_option('libdir') / 'gnunet')
11
diff --git a/src/rest-plugin/meson.build b/src/rest-plugin/meson.build
deleted file mode 100644
index 09cd2ad8c..000000000
--- a/src/rest-plugin/meson.build
+++ /dev/null
@@ -1,7 +0,0 @@
1if get_option('monolith') == false
2 subdir('rest')
3endif
4subdir('identity')
5subdir('namestore')
6subdir('gns')
7subdir('reclaim')
diff --git a/src/rest-plugin/namestore/Makefile.am b/src/rest-plugin/namestore/Makefile.am
deleted file mode 100644
index 93da51dbc..000000000
--- a/src/rest-plugin/namestore/Makefile.am
+++ /dev/null
@@ -1,53 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include $(POSTGRESQL_CPPFLAGS)
3
4plugindir = $(libdir)/gnunet
5
6pkgcfgdir= $(pkgdatadir)/config.d/
7
8libexecdir= $(pkglibdir)/libexec/
9
10sqldir = $(prefix)/share/gnunet/sql/
11
12if USE_COVERAGE
13 AM_CFLAGS = --coverage -O0
14 XLIBS = -lgcov
15endif
16
17
18if ENABLE_TEST_RUN
19AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
20TESTS = \
21 $(check_PROGRAMS) \
22 $(check_SCRIPTS)
23endif
24
25REST_PLUGIN = libgnunet_plugin_rest_namestore.la
26
27plugin_LTLIBRARIES = \
28 $(SQLITE_PLUGIN) \
29 $(POSTGRES_PLUGIN) \
30 $(REST_PLUGIN)
31
32
33libgnunet_plugin_rest_namestore_la_SOURCES = \
34 plugin_rest_namestore.c
35libgnunet_plugin_rest_namestore_la_LIBADD = \
36 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
37 $(top_builddir)/src/service/rest/libgnunetrest.la \
38 $(top_builddir)/src/service/identity/libgnunetidentity.la \
39 $(top_builddir)/src/lib/json/libgnunetjson.la \
40 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
41 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecordjson.la \
42 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
43 $(LTLIBINTL) -ljansson $(MHD_LIBS)
44libgnunet_plugin_rest_namestore_la_LDFLAGS = \
45 $(GN_PLUGIN_LDFLAGS)
46libgnunet_plugin_rest_namestore_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
47
48
49check_SCRIPTS = \
50 test_plugin_rest_namestore.sh
51
52EXTRA_DIST = \
53 $(check_SCRIPTS)
diff --git a/src/rest-plugin/namestore/meson.build b/src/rest-plugin/namestore/meson.build
deleted file mode 100644
index f96e7cd44..000000000
--- a/src/rest-plugin/namestore/meson.build
+++ /dev/null
@@ -1,14 +0,0 @@
1shared_module('gnunet_plugin_rest_namestore',
2 ['plugin_rest_namestore.c'],
3 dependencies: [
4 libgnunetrest_dep,
5 libgnunetgnsrecordjson_dep,
6 libgnunetgnsrecord_dep,
7 libgnunetjson_dep,
8 libgnunetutil_dep,
9 json_dep,
10 mhd_dep],
11 include_directories: [incdir, configuration_inc],
12 install: true,
13 install_dir: get_option('libdir') / 'gnunet')
14
diff --git a/src/rest-plugin/reclaim/Makefile.am b/src/rest-plugin/reclaim/Makefile.am
deleted file mode 100644
index 7bc305bef..000000000
--- a/src/rest-plugin/reclaim/Makefile.am
+++ /dev/null
@@ -1,81 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4 plugindir = $(libdir)/gnunet
5
6if USE_COVERAGE
7 AM_CFLAGS = --coverage -O0
8 XLIB = -lgcov
9endif
10
11
12REST_PLUGIN = \
13 libgnunet_plugin_rest_reclaim.la
14
15if HAVE_JOSE
16REST_PLUGIN += libgnunet_plugin_rest_openid_connect.la
17endif
18
19if HAVE_PABC
20 REST_PLUGIN += libgnunet_plugin_rest_pabc.la
21endif
22
23pkgcfgdir= $(pkgdatadir)/config.d/
24
25libexecdir= $(pkglibdir)/libexec/
26
27plugin_LTLIBRARIES = \
28 $(REST_PLUGIN)
29
30libgnunet_plugin_rest_reclaim_la_SOURCES = \
31 plugin_rest_reclaim.c \
32 json_reclaim.h \
33 json_reclaim.c
34libgnunet_plugin_rest_reclaim_la_LIBADD = \
35 $(top_builddir)/src/service/identity/libgnunetidentity.la \
36 $(top_builddir)/src/service/reclaim/libgnunetreclaim.la \
37 $(top_builddir)/src/lib/json/libgnunetjson.la \
38 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
39 $(top_builddir)/src/service/rest/libgnunetrest.la \
40 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
41 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
42 $(LTLIBINTL) -ljansson $(MHD_LIBS)
43libgnunet_plugin_rest_reclaim_la_LDFLAGS = \
44 $(GN_PLUGIN_LDFLAGS)
45libgnunet_plugin_rest_reclaim_la_CFLAGS = \
46 $(MHD_CFLAGS) $(AM_CFLAGS)
47
48if HAVE_JOSE
49libgnunet_plugin_rest_openid_connect_la_SOURCES = \
50 plugin_rest_openid_connect.c \
51 oidc_helper.h \
52 oidc_helper.c
53libgnunet_plugin_rest_openid_connect_la_LIBADD = \
54 $(top_builddir)/src/service/identity/libgnunetidentity.la \
55 $(top_builddir)/src/service/reclaim/libgnunetreclaim.la \
56 $(top_builddir)/src/service/rest/libgnunetrest.la \
57 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
58 $(top_builddir)/src/service/gns/libgnunetgns.la \
59 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
60 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
61 $(LTLIBINTL) -ljansson -ljose $(MHD_LIBS) \
62 $(LIBGCRYPT_LIBS)
63libgnunet_plugin_rest_openid_connect_la_LDFLAGS = \
64 $(GN_PLUGIN_LDFLAGS)
65libgnunet_plugin_rest_openid_connect_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
66endif
67
68if HAVE_PABC
69libgnunet_plugin_rest_pabc_la_SOURCES = \
70 plugin_rest_pabc.c \
71 $(top_builddir)/src/plugin/reclaim/pabc_helper.c
72libgnunet_plugin_rest_pabc_la_LIBADD = \
73 $(top_builddir)/src/service/reclaim/libgnunetreclaim.la \
74 $(top_builddir)/src/lib/json/libgnunetjson.la \
75 $(top_builddir)/src/service/rest/libgnunetrest.la \
76 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
77 $(LTLIBINTL) -ljansson -lpabc $(MHD_LIBS)
78libgnunet_plugin_rest_pabc_la_LDFLAGS = \
79 $(GN_PLUGIN_LDFLAGS)
80libgnunet_plugin_rest_pabc_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
81endif
diff --git a/src/rest-plugin/reclaim/meson.build b/src/rest-plugin/reclaim/meson.build
deleted file mode 100644
index da4406850..000000000
--- a/src/rest-plugin/reclaim/meson.build
+++ /dev/null
@@ -1,29 +0,0 @@
1shared_module('gnunet_plugin_rest_reclaim',
2 ['plugin_rest_reclaim.c', 'json_reclaim.c'],
3 dependencies: [libgnunetrest_dep,
4 libgnunetidentity_dep,
5 libgnunetreclaim_dep,
6 libgnunetjson_dep,
7 libgnunetutil_dep,
8 json_dep,
9 mhd_dep],
10 include_directories: [incdir, configuration_inc],
11 install: true,
12 install_dir: get_option('libdir') / 'gnunet')
13
14shared_module('gnunet_plugin_rest_openid_connect',
15 ['plugin_rest_openid_connect.c', 'oidc_helper.c'],
16 dependencies: [libgnunetrest_dep,
17 libgnunetreclaim_dep,
18 libgnunetidentity_dep,
19 libgnunetgns_dep,
20 libgnunetutil_dep,
21 jose_dep,
22 gcrypt_dep,
23 json_dep,
24 mhd_dep],
25 include_directories: [incdir, configuration_inc],
26 install: true,
27 install_dir: get_option('libdir') / 'gnunet')
28
29
diff --git a/src/rest-plugin/rest/Makefile.am b/src/rest-plugin/rest/Makefile.am
deleted file mode 100644
index 4f7f834fb..000000000
--- a/src/rest-plugin/rest/Makefile.am
+++ /dev/null
@@ -1,37 +0,0 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4plugindir = $(libdir)/gnunet
5
6pkgcfgdir= $(pkgdatadir)/config.d/
7
8libexecdir= $(pkglibdir)/libexec/
9
10if USE_COVERAGE
11 AM_CFLAGS = --coverage -O0
12 XLIBS = -lgcov
13endif
14
15plugin_LTLIBRARIES = \
16 libgnunet_plugin_rest_copying.la \
17 libgnunet_plugin_rest_config.la
18
19libgnunet_plugin_rest_copying_la_SOURCES = \
20 plugin_rest_copying.c
21libgnunet_plugin_rest_copying_la_LIBADD = \
22 $(top_builddir)/src/service/rest/libgnunetrest.la \
23 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
24 $(LTLIBINTL) $(MHD_LIBS)
25libgnunet_plugin_rest_copying_la_LDFLAGS = \
26 $(GN_PLUGIN_LDFLAGS)
27libgnunet_plugin_rest_copying_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
28
29libgnunet_plugin_rest_config_la_SOURCES = \
30 plugin_rest_config.c
31libgnunet_plugin_rest_config_la_LIBADD = \
32 $(top_builddir)/src/service/rest/libgnunetrest.la \
33 $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIBS) \
34 $(LTLIBINTL) $(MHD_LIBS) -ljansson
35libgnunet_plugin_rest_config_la_LDFLAGS = \
36 $(GN_PLUGIN_LDFLAGS)
37libgnunet_plugin_rest_config_la_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
diff --git a/src/rest-plugin/rest/meson.build b/src/rest-plugin/rest/meson.build
deleted file mode 100644
index 0c7219327..000000000
--- a/src/rest-plugin/rest/meson.build
+++ /dev/null
@@ -1,18 +0,0 @@
1shared_module('gnunet_plugin_rest_config',
2 ['plugin_rest_config.c'],
3 dependencies: [libgnunetrest_dep,
4 libgnunetutil_dep,
5 json_dep,
6 mhd_dep],
7 include_directories: [incdir, configuration_inc],
8 install: true,
9 install_dir: get_option('libdir') / 'gnunet')
10shared_module('gnunet_plugin_rest_copying',
11 ['plugin_rest_copying.c'],
12 dependencies: [libgnunetrest_dep,
13 libgnunetutil_dep,
14 json_dep,
15 mhd_dep],
16 include_directories: [incdir, configuration_inc],
17 install: true,
18 install_dir: get_option('libdir') / 'gnunet')
diff --git a/src/service/Makefile.am b/src/service/Makefile.am
index 809f83a0a..041442725 100644
--- a/src/service/Makefile.am
+++ b/src/service/Makefile.am
@@ -13,7 +13,6 @@ SUBDIRS = \
13 topology \ 13 topology \
14 dns \ 14 dns \
15 identity \ 15 identity \
16 rest \
17 datacache \ 16 datacache \
18 datastore \ 17 datastore \
19 dhtu \ 18 dhtu \
@@ -32,5 +31,6 @@ SUBDIRS = \
32 exit \ 31 exit \
33 pt \ 32 pt \
34 reclaim \ 33 reclaim \
35 messenger 34 messenger \
35 rest
36 36
diff --git a/src/service/meson.build b/src/service/meson.build
index 5923fc8a1..34dd997e2 100644
--- a/src/service/meson.build
+++ b/src/service/meson.build
@@ -2,7 +2,6 @@ subdir('util')
2subdir('arm') 2subdir('arm')
3subdir('statistics') 3subdir('statistics')
4subdir('testing') 4subdir('testing')
5subdir('rest')
6subdir('datacache') 5subdir('datacache')
7subdir('datastore') 6subdir('datastore')
8subdir('peerstore') 7subdir('peerstore')
@@ -31,6 +30,7 @@ subdir('exit')
31subdir('pt') 30subdir('pt')
32subdir('reclaim') 31subdir('reclaim')
33subdir('messenger') 32subdir('messenger')
33subdir('rest')
34 34
35if not get_option('monolith') 35if not get_option('monolith')
36 subdir_done() 36 subdir_done()
@@ -44,6 +44,8 @@ libgnunet = library('gnunet',
44 libgnunetblock_dep, 44 libgnunetblock_dep,
45 libgnunetblockgroup_dep, 45 libgnunetblockgroup_dep,
46 libgnunetgnsrecord_dep, 46 libgnunetgnsrecord_dep,
47 libgnunetgnsrecordjson_dep,
48 jose_dep,
47 libgnunetcurl_dep], 49 libgnunetcurl_dep],
48 c_args: ['-DHAVE_GNUNET_MONOLITH=1'], 50 c_args: ['-DHAVE_GNUNET_MONOLITH=1'],
49 include_directories: [incdir, configuration_inc, exitdir]) 51 include_directories: [incdir, configuration_inc, exitdir])
diff --git a/src/service/rest/Makefile.am b/src/service/rest/Makefile.am
index 401be36f4..072f0a787 100644
--- a/src/service/rest/Makefile.am
+++ b/src/service/rest/Makefile.am
@@ -25,9 +25,25 @@ EXTRA_DIST = \
25 rest.conf 25 rest.conf
26 26
27gnunet_rest_server_SOURCES = \ 27gnunet_rest_server_SOURCES = \
28 gnunet-rest-server.c 28 gnunet-rest-server.c \
29 config_plugin.c \
30 copying_plugin.c \
31 identity_plugin.c \
32 namestore_plugin.c \
33 gns_plugin.c \
34 openid_plugin.c \
35 oidc_helper.c \
36 reclaim_plugin.c json_reclaim.c
29gnunet_rest_server_LDADD = \ 37gnunet_rest_server_LDADD = \
30 $(top_builddir)/src/lib/util/libgnunetutil.la \ 38 $(top_builddir)/src/lib/util/libgnunetutil.la \
39 $(top_builddir)/src/lib/json/libgnunetjson.la \
40 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecordjson.la \
41 $(top_builddir)/src/service/identity/libgnunetidentity.la \
42 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
43 $(top_builddir)/src/service/gns/libgnunetgns.la \
44 $(top_builddir)/src/service/reclaim/libgnunetreclaim.la \
45 libgnunetrest.la \
46 -ljose \
31 $(GN_LIBINTL) $(MHD_LIBS) 47 $(GN_LIBINTL) $(MHD_LIBS)
32gnunet_rest_server_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS) 48gnunet_rest_server_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
33 49
diff --git a/src/rest-plugin/rest/plugin_rest_config.c b/src/service/rest/config_plugin.c
index 826188702..fd0ac011a 100644
--- a/src/rest-plugin/rest/plugin_rest_config.c
+++ b/src/service/rest/config_plugin.c
@@ -40,7 +40,7 @@ struct Plugin
40 const struct GNUNET_CONFIGURATION_Handle *cfg; 40 const struct GNUNET_CONFIGURATION_Handle *cfg;
41}; 41};
42 42
43const struct GNUNET_CONFIGURATION_Handle *cfg; 43const struct GNUNET_CONFIGURATION_Handle *config_cfg;
44 44
45struct RequestHandle 45struct RequestHandle
46{ 46{
@@ -78,6 +78,7 @@ struct RequestHandle
78 * The URL 78 * The URL
79 */ 79 */
80 char *url; 80 char *url;
81
81}; 82};
82 83
83/** 84/**
@@ -184,13 +185,13 @@ get_cont (struct GNUNET_REST_RequestHandle *con_handle,
184 if (strlen (GNUNET_REST_API_NS_CONFIG) == strlen (handle->url)) 185 if (strlen (GNUNET_REST_API_NS_CONFIG) == strlen (handle->url))
185 { 186 {
186 result = json_object (); 187 result = json_object ();
187 GNUNET_CONFIGURATION_iterate (cfg, &add_sections, result); 188 GNUNET_CONFIGURATION_iterate (config_cfg, &add_sections, result);
188 } 189 }
189 else 190 else
190 { 191 {
191 result = json_object (); 192 result = json_object ();
192 section = &handle->url[strlen (GNUNET_REST_API_NS_CONFIG) + 1]; 193 section = &handle->url[strlen (GNUNET_REST_API_NS_CONFIG) + 1];
193 GNUNET_CONFIGURATION_iterate_section_values (cfg, 194 GNUNET_CONFIGURATION_iterate_section_values (config_cfg,
194 section, 195 section,
195 &add_section_contents, 196 &add_section_contents,
196 result); 197 result);
@@ -243,7 +244,7 @@ set_cont (struct GNUNET_REST_RequestHandle *con_handle,
243{ 244{
244 struct RequestHandle *handle = cls; 245 struct RequestHandle *handle = cls;
245 char term_data[handle->rest_handle->data_size + 1]; 246 char term_data[handle->rest_handle->data_size + 1];
246 struct GNUNET_CONFIGURATION_Handle *out = GNUNET_CONFIGURATION_dup (cfg); 247 struct GNUNET_CONFIGURATION_Handle *out = GNUNET_CONFIGURATION_dup (config_cfg);
247 248
248 json_error_t err; 249 json_error_t err;
249 json_t *data_json; 250 json_t *data_json;
@@ -330,7 +331,7 @@ set_cont (struct GNUNET_REST_RequestHandle *con_handle,
330 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 331 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
331 332
332 GNUNET_CONFIGURATION_write (out, cfg_fn); 333 GNUNET_CONFIGURATION_write (out, cfg_fn);
333 cfg = out; 334 config_cfg = out;
334 handle->proc (handle->proc_cls, 335 handle->proc (handle->proc_cls,
335 GNUNET_REST_create_response (NULL), 336 GNUNET_REST_create_response (NULL),
336 MHD_HTTP_OK); 337 MHD_HTTP_OK);
@@ -361,19 +362,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
361} 362}
362 363
363 364
364/** 365enum GNUNET_GenericReturnValue
365 * Function processing the REST call 366REST_config_process_request (void *plugin,
366 * 367 struct GNUNET_REST_RequestHandle *conndata_handle,
367 * @param method HTTP method
368 * @param url URL of the HTTP request
369 * @param data body of the HTTP request (optional)
370 * @param data_size length of the body
371 * @param proc callback function for the result
372 * @param proc_cls closure for @a proc
373 * @return #GNUNET_OK if request accepted
374 */
375static enum GNUNET_GenericReturnValue
376rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
377 GNUNET_REST_ResultProcessor proc, 368 GNUNET_REST_ResultProcessor proc,
378 void *proc_cls) 369 void *proc_cls)
379{ 370{
@@ -383,6 +374,7 @@ rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
383 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CONFIG, &options_cont }, 374 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CONFIG, &options_cont },
384 GNUNET_REST_HANDLER_END 375 GNUNET_REST_HANDLER_END
385 }; 376 };
377 (void) plugin;
386 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 378 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
387 struct GNUNET_REST_RequestHandlerError err; 379 struct GNUNET_REST_RequestHandlerError err;
388 380
@@ -404,6 +396,19 @@ rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
404 return GNUNET_YES; 396 return GNUNET_YES;
405} 397}
406 398
399void
400REST_config_done (struct GNUNET_REST_Plugin *api)
401{
402 struct Plugin *plugin;
403
404 while (NULL != requests_head)
405 cleanup_handle (requests_head);
406 plugin = api->cls;
407 plugin->cfg = NULL;
408 GNUNET_free (api);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONFIG REST plugin is finished\n");
410}
411
407 412
408/** 413/**
409 * Entry point for the plugin. 414 * Entry point for the plugin.
@@ -412,44 +417,22 @@ rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
412 * @return NULL on error, otherwise the plugin context 417 * @return NULL on error, otherwise the plugin context
413 */ 418 */
414void * 419void *
415libgnunet_plugin_rest_config_init (void *cls) 420REST_config_init (const struct GNUNET_CONFIGURATION_Handle *c)
416{ 421{
417 static struct Plugin plugin; 422 static struct Plugin plugin;
418 423
419 cfg = cls; 424 config_cfg = c;
420 struct GNUNET_REST_Plugin *api; 425 struct GNUNET_REST_Plugin *api;
421 426
422 memset (&plugin, 0, sizeof(struct Plugin)); 427 memset (&plugin, 0, sizeof(struct Plugin));
423 plugin.cfg = cfg; 428 plugin.cfg = c;
424 api = GNUNET_new (struct GNUNET_REST_Plugin); 429 api = GNUNET_new (struct GNUNET_REST_Plugin);
425 api->cls = &plugin; 430 api->cls = &plugin;
426 api->name = GNUNET_REST_API_NS_CONFIG; 431 api->name = GNUNET_REST_API_NS_CONFIG;
427 api->process_request = &rest_config_process_request;
428 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CONFIG REST API initialized\n")); 432 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CONFIG REST API initialized\n"));
429 return api; 433 return api;
430} 434}
431 435
432 436
433/**
434 * Exit point from the plugin.
435 *
436 * @param cls the plugin context (as returned by "init")
437 * @return always NULL
438 */
439void *
440libgnunet_plugin_rest_config_done (void *cls)
441{
442 struct GNUNET_REST_Plugin *api = cls;
443 struct Plugin *plugin;
444
445 while (NULL != requests_head)
446 cleanup_handle (requests_head);
447 plugin = api->cls;
448 plugin->cfg = NULL;
449 GNUNET_free (api);
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONFIG REST plugin is finished\n");
451 return NULL;
452}
453
454 437
455/* end of plugin_rest_config.c */ 438/* end of plugin_rest_config.c */
diff --git a/src/service/rest/config_plugin.h b/src/service/rest/config_plugin.h
new file mode 100644
index 000000000..c959a94f2
--- /dev/null
+++ b/src/service/rest/config_plugin.h
@@ -0,0 +1,37 @@
1#include "platform.h"
2#include "gnunet_util_lib.h"
3#include "gnunet_rest_plugin.h"
4
5/**
6 * Function processing the REST call
7 *
8 * @param method HTTP method
9 * @param url URL of the HTTP request
10 * @param data body of the HTTP request (optional)
11 * @param data_size length of the body
12 * @param proc callback function for the result
13 * @param proc_cls closure for @a proc
14 * @return #GNUNET_OK if request accepted
15 */
16enum GNUNET_GenericReturnValue
17REST_config_process_request (void *plugin,
18 struct GNUNET_REST_RequestHandle *conndata_handle,
19 GNUNET_REST_ResultProcessor proc,
20 void *proc_cls);
21
22/**
23 * Entry point for the plugin.
24 *
25 */
26void *
27REST_config_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_config_done (struct GNUNET_REST_Plugin *api);
37
diff --git a/src/rest-plugin/rest/plugin_rest_copying.c b/src/service/rest/copying_plugin.c
index 52783a81a..d907f6729 100644
--- a/src/rest-plugin/rest/plugin_rest_copying.c
+++ b/src/service/rest/copying_plugin.c
@@ -31,7 +31,7 @@
31#define GNUNET_REST_API_NS_COPYING "/copying" 31#define GNUNET_REST_API_NS_COPYING "/copying"
32 32
33#define GNUNET_REST_COPYING_TEXT \ 33#define GNUNET_REST_COPYING_TEXT \
34 "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>" 34 "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
35 35
36/** 36/**
37 * @brief struct returned by the initialization function of the plugin 37 * @brief struct returned by the initialization function of the plugin
@@ -41,8 +41,6 @@ struct Plugin
41 const struct GNUNET_CONFIGURATION_Handle *cfg; 41 const struct GNUNET_CONFIGURATION_Handle *cfg;
42}; 42};
43 43
44const struct GNUNET_CONFIGURATION_Handle *cfg;
45
46struct RequestHandle 44struct RequestHandle
47{ 45{
48 /** 46 /**
@@ -159,8 +157,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
159 * @param proc_cls closure for @a proc 157 * @param proc_cls closure for @a proc
160 * @return #GNUNET_OK if request accepted 158 * @return #GNUNET_OK if request accepted
161 */ 159 */
162static enum GNUNET_GenericReturnValue 160enum GNUNET_GenericReturnValue
163rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, 161REST_copying_process_request (void *plugin,
162 struct GNUNET_REST_RequestHandle *conndata_handle,
164 GNUNET_REST_ResultProcessor proc, 163 GNUNET_REST_ResultProcessor proc,
165 void *proc_cls) 164 void *proc_cls)
166{ 165{
@@ -191,22 +190,20 @@ rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
191 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*" 190 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
192 * @return NULL on error, otherwise the plugin context 191 * @return NULL on error, otherwise the plugin context
193 */ 192 */
194void * 193void*
195libgnunet_plugin_rest_copying_init (void *cls) 194REST_copying_init (const struct GNUNET_CONFIGURATION_Handle *c)
196{ 195{
197 static struct Plugin plugin; 196 static struct Plugin plugin;
198 197
199 cfg = cls;
200 struct GNUNET_REST_Plugin *api; 198 struct GNUNET_REST_Plugin *api;
201 199
202 if (NULL != plugin.cfg) 200 if (NULL != plugin.cfg)
203 return NULL; /* can only initialize once! */ 201 return NULL; /* can only initialize once! */
204 memset (&plugin, 0, sizeof(struct Plugin)); 202 memset (&plugin, 0, sizeof(struct Plugin));
205 plugin.cfg = cfg; 203 plugin.cfg = c;
206 api = GNUNET_new (struct GNUNET_REST_Plugin); 204 api = GNUNET_new (struct GNUNET_REST_Plugin);
207 api->cls = &plugin; 205 api->cls = &plugin;
208 api->name = GNUNET_REST_API_NS_COPYING; 206 api->name = GNUNET_REST_API_NS_COPYING;
209 api->process_request = &rest_copying_process_request;
210 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 207 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
211 _ ("COPYING REST API initialized\n")); 208 _ ("COPYING REST API initialized\n"));
212 return api; 209 return api;
@@ -219,10 +216,9 @@ libgnunet_plugin_rest_copying_init (void *cls)
219 * @param cls the plugin context (as returned by "init") 216 * @param cls the plugin context (as returned by "init")
220 * @return always NULL 217 * @return always NULL
221 */ 218 */
222void * 219void
223libgnunet_plugin_rest_copying_done (void *cls) 220REST_copying_done (struct GNUNET_REST_Plugin *api)
224{ 221{
225 struct GNUNET_REST_Plugin *api = cls;
226 struct Plugin *plugin = api->cls; 222 struct Plugin *plugin = api->cls;
227 223
228 while (NULL != requests_head) 224 while (NULL != requests_head)
@@ -231,7 +227,6 @@ libgnunet_plugin_rest_copying_done (void *cls)
231 GNUNET_free (api); 227 GNUNET_free (api);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "COPYING REST plugin is finished\n"); 229 "COPYING REST plugin is finished\n");
234 return NULL;
235} 230}
236 231
237 232
diff --git a/src/service/rest/copying_plugin.h b/src/service/rest/copying_plugin.h
new file mode 100644
index 000000000..4ba1a2e36
--- /dev/null
+++ b/src/service/rest/copying_plugin.h
@@ -0,0 +1,36 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_copying_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *conndata_handle,
16 GNUNET_REST_ResultProcessor proc,
17 void *proc_cls);
18
19/**
20 * Entry point for the plugin.
21 *
22 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
23 * @return NULL on error, otherwise the plugin context
24 */
25void*
26REST_copying_init (const struct GNUNET_CONFIGURATION_Handle *c);
27
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_copying_done (struct GNUNET_REST_Plugin *api);
diff --git a/src/rest-plugin/gns/plugin_rest_gns.c b/src/service/rest/gns_plugin.c
index 659b77493..0ea89d0cd 100644
--- a/src/rest-plugin/gns/plugin_rest_gns.c
+++ b/src/service/rest/gns_plugin.c
@@ -56,7 +56,7 @@
56/** 56/**
57 * The configuration handle 57 * The configuration handle
58 */ 58 */
59const struct GNUNET_CONFIGURATION_Handle *cfg; 59const struct GNUNET_CONFIGURATION_Handle *gns_cfg;
60 60
61/** 61/**
62 * HTTP methods allows for this plugin 62 * HTTP methods allows for this plugin
@@ -221,7 +221,7 @@ do_error (void *cls)
221 handle->proc (handle->proc_cls, resp, handle->response_code); 221 handle->proc (handle->proc_cls, resp, handle->response_code);
222 json_decref (json_error); 222 json_decref (json_error);
223 GNUNET_free (response); 223 GNUNET_free (response);
224 cleanup_handle(handle); 224 cleanup_handle (handle);
225} 225}
226 226
227 227
@@ -265,7 +265,8 @@ handle_gns_response (void *cls,
265 return; 265 return;
266 } 266 }
267 267
268 result_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (handle->name, rd, rd_count); 268 result_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (handle->name, rd,
269 rd_count);
269 270
270 result = json_dumps (result_obj, 0); 271 result = json_dumps (result_obj, 0);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
@@ -381,10 +382,11 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
381 * @param proc_cls closure for callback function 382 * @param proc_cls closure for callback function
382 * @return GNUNET_OK if request accepted 383 * @return GNUNET_OK if request accepted
383 */ 384 */
384static enum GNUNET_GenericReturnValue 385enum GNUNET_GenericReturnValue
385rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 386REST_gns_process_request (void *plugin,
386 GNUNET_REST_ResultProcessor proc, 387 struct GNUNET_REST_RequestHandle *rest_handle,
387 void *proc_cls) 388 GNUNET_REST_ResultProcessor proc,
389 void *proc_cls)
388{ 390{
389 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 391 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
390 struct GNUNET_REST_RequestHandlerError err; 392 struct GNUNET_REST_RequestHandlerError err;
@@ -426,18 +428,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
426 * @return NULL on error, otherwise the plugin context 428 * @return NULL on error, otherwise the plugin context
427 */ 429 */
428void * 430void *
429libgnunet_plugin_rest_gns_init (void *cls) 431REST_gns_init (const struct GNUNET_CONFIGURATION_Handle *c)
430{ 432{
431 static struct Plugin plugin; 433 static struct Plugin plugin;
432 struct GNUNET_REST_Plugin *api; 434 struct GNUNET_REST_Plugin *api;
433 435
434 cfg = cls; 436 gns_cfg = c;
435 memset (&plugin, 0, sizeof(struct Plugin)); 437 memset (&plugin, 0, sizeof(struct Plugin));
436 plugin.cfg = cfg; 438 plugin.cfg = gns_cfg;
437 api = GNUNET_new (struct GNUNET_REST_Plugin); 439 api = GNUNET_new (struct GNUNET_REST_Plugin);
438 api->cls = &plugin; 440 api->cls = &plugin;
439 api->name = GNUNET_REST_API_NS_GNS; 441 api->name = GNUNET_REST_API_NS_GNS;
440 api->process_request = &rest_process_request;
441 GNUNET_asprintf (&allow_methods, 442 GNUNET_asprintf (&allow_methods,
442 "%s, %s, %s, %s, %s", 443 "%s, %s, %s, %s, %s",
443 MHD_HTTP_METHOD_GET, 444 MHD_HTTP_METHOD_GET,
@@ -445,7 +446,7 @@ libgnunet_plugin_rest_gns_init (void *cls)
445 MHD_HTTP_METHOD_PUT, 446 MHD_HTTP_METHOD_PUT,
446 MHD_HTTP_METHOD_DELETE, 447 MHD_HTTP_METHOD_DELETE,
447 MHD_HTTP_METHOD_OPTIONS); 448 MHD_HTTP_METHOD_OPTIONS);
448 gns = GNUNET_GNS_connect (cfg); 449 gns = GNUNET_GNS_connect (gns_cfg);
449 450
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n")); 451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n"));
451 return api; 452 return api;
@@ -459,7 +460,7 @@ libgnunet_plugin_rest_gns_init (void *cls)
459 * @return always NULL 460 * @return always NULL
460 */ 461 */
461void * 462void *
462libgnunet_plugin_rest_gns_done (void *cls) 463REST_gns_done (void *cls)
463{ 464{
464 struct GNUNET_REST_Plugin *api = cls; 465 struct GNUNET_REST_Plugin *api = cls;
465 struct RequestHandle *request; 466 struct RequestHandle *request;
diff --git a/src/service/rest/gns_plugin.h b/src/service/rest/gns_plugin.h
new file mode 100644
index 000000000..13878c139
--- /dev/null
+++ b/src/service/rest/gns_plugin.h
@@ -0,0 +1,36 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_gns_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *conndata_handle,
16 GNUNET_REST_ResultProcessor proc,
17 void *proc_cls);
18
19/**
20 * Entry point for the plugin.
21 *
22 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
23 * @return NULL on error, otherwise the plugin context
24 */
25void*
26REST_gns_init (const struct GNUNET_CONFIGURATION_Handle *c);
27
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_gns_done (struct GNUNET_REST_Plugin *api);
diff --git a/src/service/rest/gnunet-rest-server.c b/src/service/rest/gnunet-rest-server.c
index 5163c2271..59b997efd 100644
--- a/src/service/rest/gnunet-rest-server.c
+++ b/src/service/rest/gnunet-rest-server.c
@@ -29,6 +29,14 @@
29#include "gnunet_rest_plugin.h" 29#include "gnunet_rest_plugin.h"
30#include "gnunet_mhd_compat.h" 30#include "gnunet_mhd_compat.h"
31 31
32#include "config_plugin.h"
33#include "copying_plugin.h"
34#include "identity_plugin.h"
35#include "namestore_plugin.h"
36#include "gns_plugin.h"
37#include "openid_plugin.h"
38#include "reclaim_plugin.h"
39
32/** 40/**
33 * Default Socks5 listen port. 41 * Default Socks5 listen port.
34 */ 42 */
@@ -54,7 +62,7 @@
54 * After how long do we clean up unused MHD SSL/TLS instances? 62 * After how long do we clean up unused MHD SSL/TLS instances?
55 */ 63 */
56#define MHD_CACHE_TIMEOUT \ 64#define MHD_CACHE_TIMEOUT \
57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 65 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
58 66
59#define GN_REST_STATE_INIT 0 67#define GN_REST_STATE_INIT 0
60#define GN_REST_STATE_PROCESSING 1 68#define GN_REST_STATE_PROCESSING 1
@@ -178,7 +186,12 @@ struct PluginListEntry
178 /** 186 /**
179 * The plugin 187 * The plugin
180 */ 188 */
181 struct GNUNET_REST_Plugin *plugin; 189 void *plugin;
190
191 /**
192 * Request function
193 */
194 GNUNET_REST_ProcessingFunction process_request;
182}; 195};
183 196
184/** 197/**
@@ -240,6 +253,19 @@ static struct AcceptedRequest *req_list_head;
240 */ 253 */
241static struct AcceptedRequest *req_list_tail; 254static struct AcceptedRequest *req_list_tail;
242 255
256
257/**
258 * plugins
259 */
260
261struct GNUNET_REST_Plugin *config_plugin;
262struct GNUNET_REST_Plugin *copying_plugin;
263struct GNUNET_REST_Plugin *identity_plugin;
264struct GNUNET_REST_Plugin *namestore_plugin;
265struct GNUNET_REST_Plugin *gns_plugin;
266struct GNUNET_REST_Plugin *openid_plugin;
267struct GNUNET_REST_Plugin *reclaim_plugin;
268
243/* ************************* Global helpers ********************* */ 269/* ************************* Global helpers ********************* */
244 270
245 271
@@ -294,6 +320,7 @@ cleanup_url_map (void *cls, const struct GNUNET_HashCode *key, void *value)
294 return GNUNET_YES; 320 return GNUNET_YES;
295} 321}
296 322
323
297static void 324static void
298cleanup_handle (struct MhdConnectionHandle *handle) 325cleanup_handle (struct MhdConnectionHandle *handle)
299{ 326{
@@ -323,6 +350,7 @@ cleanup_handle (struct MhdConnectionHandle *handle)
323 GNUNET_free (handle); 350 GNUNET_free (handle);
324} 351}
325 352
353
326static void 354static void
327cleanup_ar (struct AcceptedRequest *ar) 355cleanup_ar (struct AcceptedRequest *ar)
328{ 356{
@@ -334,7 +362,8 @@ cleanup_ar (struct AcceptedRequest *ar)
334 { 362 {
335 GNUNET_NETWORK_socket_free_memory_only_ (ar->sock); 363 GNUNET_NETWORK_socket_free_memory_only_ (ar->sock);
336 } 364 }
337 else { 365 else
366 {
338 GNUNET_NETWORK_socket_close (ar->sock); 367 GNUNET_NETWORK_socket_close (ar->sock);
339 } 368 }
340 ar->sock = NULL; 369 ar->sock = NULL;
@@ -344,6 +373,7 @@ cleanup_ar (struct AcceptedRequest *ar)
344 GNUNET_free (ar); 373 GNUNET_free (ar);
345} 374}
346 375
376
347static int 377static int
348header_iterator (void *cls, 378header_iterator (void *cls,
349 enum MHD_ValueKind kind, 379 enum MHD_ValueKind kind,
@@ -561,9 +591,10 @@ create_response (void *cls,
561 con_handle->state = GN_REST_STATE_PROCESSING; 591 con_handle->state = GN_REST_STATE_PROCESSING;
562 for (ple = plugins_head; NULL != ple; ple = ple->next) 592 for (ple = plugins_head; NULL != ple; ple = ple->next)
563 { 593 {
564 if (GNUNET_YES == ple->plugin->process_request (rest_conndata_handle, 594 if (GNUNET_YES == ple->process_request (ple->plugin,
565 &plugin_callback, 595 rest_conndata_handle,
566 con_handle)) 596 &plugin_callback,
597 con_handle))
567 break; /* Request handled */ 598 break; /* Request handled */
568 } 599 }
569 if (NULL == ple) 600 if (NULL == ple)
@@ -603,8 +634,8 @@ create_response (void *cls,
603 strlen ("chrome-extension://")))) 634 strlen ("chrome-extension://"))))
604 { 635 {
605 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response, 636 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response,
606 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, 637 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
607 origin)); 638 origin));
608 } 639 }
609 } 640 }
610 if (NULL != allow_origins) 641 if (NULL != allow_origins)
@@ -615,9 +646,10 @@ create_response (void *cls,
615 { 646 {
616 if (0 == strncmp (allow_origin, origin, strlen (allow_origin))) 647 if (0 == strncmp (allow_origin, origin, strlen (allow_origin)))
617 { 648 {
618 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response, 649 GNUNET_assert (MHD_NO != MHD_add_response_header (
619 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, 650 con_handle->response,
620 allow_origin)); 651 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
652 allow_origin));
621 break; 653 break;
622 } 654 }
623 allow_origin = strtok (NULL, ","); 655 allow_origin = strtok (NULL, ",");
@@ -628,14 +660,14 @@ create_response (void *cls,
628 if (NULL != allow_credentials) 660 if (NULL != allow_credentials)
629 { 661 {
630 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response, 662 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response,
631 "Access-Control-Allow-Credentials", 663 "Access-Control-Allow-Credentials",
632 allow_credentials)); 664 allow_credentials));
633 } 665 }
634 if (NULL != allow_headers) 666 if (NULL != allow_headers)
635 { 667 {
636 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response, 668 GNUNET_assert (MHD_NO != MHD_add_response_header (con_handle->response,
637 "Access-Control-Allow-Headers", 669 "Access-Control-Allow-Headers",
638 allow_headers)); 670 allow_headers));
639 } 671 }
640 run_mhd_now (); 672 run_mhd_now ();
641 { 673 {
@@ -757,6 +789,7 @@ schedule_httpd ()
757 GNUNET_NETWORK_fdset_destroy (wws); 789 GNUNET_NETWORK_fdset_destroy (wws);
758} 790}
759 791
792
760/** 793/**
761 * Function called when MHD first processes an incoming connection. 794 * Function called when MHD first processes an incoming connection.
762 * Gives us the respective URI information. 795 * Gives us the respective URI information.
@@ -791,7 +824,6 @@ mhd_log_callback (void *cls,
791} 824}
792 825
793 826
794
795/** 827/**
796 * Function called when MHD decides that we are done with a connection. 828 * Function called when MHD decides that we are done with a connection.
797 * 829 *
@@ -823,6 +855,7 @@ mhd_completed_cb (void *cls,
823 *con_cls = NULL; 855 *con_cls = NULL;
824} 856}
825 857
858
826/** 859/**
827 * Function called when MHD connection is opened or closed. 860 * Function called when MHD connection is opened or closed.
828 * 861 *
@@ -886,7 +919,6 @@ mhd_connection_cb (void *cls,
886} 919}
887 920
888 921
889
890/** 922/**
891 * Task run whenever HTTP server operations are pending. 923 * Task run whenever HTTP server operations are pending.
892 * 924 *
@@ -977,10 +1009,15 @@ do_shutdown (void *cls)
977 GNUNET_CONTAINER_DLL_remove (plugins_head, 1009 GNUNET_CONTAINER_DLL_remove (plugins_head,
978 plugins_tail, 1010 plugins_tail,
979 ple); 1011 ple);
980 GNUNET_PLUGIN_unload (ple->libname, ple->plugin);
981 GNUNET_free (ple->libname); 1012 GNUNET_free (ple->libname);
982 GNUNET_free (ple); 1013 GNUNET_free (ple);
983 } 1014 }
1015 REST_config_done (config_plugin);
1016 REST_copying_done (copying_plugin);
1017 REST_identity_done (identity_plugin);
1018 REST_gns_done (gns_plugin);
1019 REST_openid_done (openid_plugin);
1020 REST_reclaim_done (reclaim_plugin);
984 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); 1021 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n");
985 kill_httpd (); 1022 kill_httpd ();
986 GNUNET_free (allow_credentials); 1023 GNUNET_free (allow_credentials);
@@ -1065,28 +1102,30 @@ bind_v6 ()
1065 * @param libname the name of the library loaded 1102 * @param libname the name of the library loaded
1066 * @param lib_ret the object returned by the plugin initializer 1103 * @param lib_ret the object returned by the plugin initializer
1067 */ 1104 */
1068static void 1105static enum GNUNET_GenericReturnValue
1069load_plugin (void *cls, const char *libname, void *lib_ret) 1106setup_plugin (const char *name,
1107 GNUNET_REST_ProcessingFunction proc,
1108 void *plugin_cls)
1070{ 1109{
1071 struct GNUNET_REST_Plugin *plugin = lib_ret;
1072 struct PluginListEntry *ple; 1110 struct PluginListEntry *ple;
1073 1111
1074 if (NULL == lib_ret) 1112 if (NULL == plugin_cls)
1075 { 1113 {
1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1077 "Could not load plugin `%s'\n", 1115 "Could not load plugin\n");
1078 libname); 1116 return GNUNET_SYSERR;
1079 return;
1080 } 1117 }
1081 GNUNET_assert (1 < strlen (plugin->name)); 1118 GNUNET_assert (1 < strlen (name));
1082 GNUNET_assert ('/' == *plugin->name); 1119 GNUNET_assert ('/' == *name);
1083 ple = GNUNET_new (struct PluginListEntry); 1120 ple = GNUNET_new (struct PluginListEntry);
1084 ple->libname = GNUNET_strdup (libname); 1121 ple->libname = GNUNET_strdup (name);
1085 ple->plugin = plugin; 1122 ple->plugin = plugin_cls;
1123 ple->process_request = proc;
1086 GNUNET_CONTAINER_DLL_insert (plugins_head, 1124 GNUNET_CONTAINER_DLL_insert (plugins_head,
1087 plugins_tail, 1125 plugins_tail,
1088 ple); 1126 ple);
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded plugin `%s'\n", libname); 1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded plugin `%s'\n", name);
1128 return GNUNET_OK;
1090} 1129}
1091 1130
1092 1131
@@ -1201,7 +1240,8 @@ run (void *cls,
1201 memset (basic_auth_secret_tmp, 0, 16); 1240 memset (basic_auth_secret_tmp, 0, 16);
1202 if (GNUNET_SYSERR == GNUNET_DISK_fn_read (basic_auth_file, 1241 if (GNUNET_SYSERR == GNUNET_DISK_fn_read (basic_auth_file,
1203 basic_auth_secret_tmp, 1242 basic_auth_secret_tmp,
1204 sizeof (basic_auth_secret_tmp) - 1)) 1243 sizeof (basic_auth_secret_tmp)
1244 - 1))
1205 { 1245 {
1206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1207 "Unable to read basic auth secret file.\n"); 1247 "Unable to read basic auth secret file.\n");
@@ -1330,12 +1370,43 @@ run (void *cls,
1330 GNUNET_SCHEDULER_shutdown (); 1370 GNUNET_SCHEDULER_shutdown ();
1331 return; 1371 return;
1332 } 1372 }
1333/* Load plugins */ 1373 /* Load plugins */
1334 GNUNET_PLUGIN_load_all_in_context (GNUNET_OS_project_data_default (), 1374 // FIXME: Use per-plugin rest plugin structs
1335 "libgnunet_plugin_rest", 1375 struct GNUNET_REST_Plugin *config_plugin = REST_config_init (cfg);
1336 (void *) cfg, 1376 if (GNUNET_OK != setup_plugin (config_plugin->name, &REST_config_process_request, config_plugin))
1337 &load_plugin, 1377 {
1338 NULL); 1378 GNUNET_SCHEDULER_shutdown ();
1379 }
1380 struct GNUNET_REST_Plugin *copying_plugin = REST_copying_init (cfg);
1381 if (GNUNET_OK != setup_plugin (copying_plugin->name, &REST_copying_process_request, copying_plugin))
1382 {
1383 GNUNET_SCHEDULER_shutdown ();
1384 }
1385 struct GNUNET_REST_Plugin *identity_plugin = REST_identity_init (cfg);
1386 if (GNUNET_OK != setup_plugin (identity_plugin->name, &REST_identity_process_request, identity_plugin))
1387 {
1388 GNUNET_SCHEDULER_shutdown ();
1389 }
1390 struct GNUNET_REST_Plugin *namestore_plugin = REST_namestore_init (cfg);
1391 if (GNUNET_OK != setup_plugin (namestore_plugin->name, &REST_namestore_process_request, namestore_plugin))
1392 {
1393 GNUNET_SCHEDULER_shutdown ();
1394 }
1395 struct GNUNET_REST_Plugin *gns_plugin = REST_gns_init (cfg);
1396 if (GNUNET_OK != setup_plugin (gns_plugin->name, &REST_gns_process_request, gns_plugin))
1397 {
1398 GNUNET_SCHEDULER_shutdown ();
1399 }
1400 struct GNUNET_REST_Plugin *openid_plugin = REST_openid_init (cfg);
1401 if (GNUNET_OK != setup_plugin (openid_plugin->name, &REST_openid_process_request, openid_plugin))
1402 {
1403 GNUNET_SCHEDULER_shutdown ();
1404 }
1405 struct GNUNET_REST_Plugin *reclaim_plugin = REST_reclaim_init (cfg);
1406 if (GNUNET_OK != setup_plugin (reclaim_plugin->name, &REST_reclaim_process_request, reclaim_plugin))
1407 {
1408 GNUNET_SCHEDULER_shutdown ();
1409 }
1339 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1410 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1340} 1411}
1341 1412
diff --git a/src/rest-plugin/identity/plugin_rest_identity.c b/src/service/rest/identity_plugin.c
index e7b7f8a9c..f6c9dd792 100644
--- a/src/rest-plugin/identity/plugin_rest_identity.c
+++ b/src/service/rest/identity_plugin.c
@@ -106,7 +106,7 @@
106/** 106/**
107 * The configuration handle 107 * The configuration handle
108 */ 108 */
109const struct GNUNET_CONFIGURATION_Handle *cfg; 109const struct GNUNET_CONFIGURATION_Handle *id_cfg;
110 110
111/** 111/**
112 * HTTP methods allows for this plugin 112 * HTTP methods allows for this plugin
@@ -921,6 +921,7 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle,
921 handle); 921 handle);
922} 922}
923 923
924
924struct ego_sign_data_cls 925struct ego_sign_data_cls
925{ 926{
926 void *data; 927 void *data;
@@ -952,10 +953,10 @@ ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
952 return; 953 return;
953 } 954 }
954 955
955 if ( GNUNET_OK != GNUNET_CRYPTO_eddsa_sign_raw (&(ego->pk.eddsa_key), 956 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_sign_raw (&(ego->pk.eddsa_key),
956 (void *) data, 957 (void *) data,
957 strlen ( (char*) data), 958 strlen ( (char*) data),
958 &sig)) 959 &sig))
959 { 960 {
960 handle->ec = GNUNET_EC_UNKNOWN; 961 handle->ec = GNUNET_EC_UNKNOWN;
961 GNUNET_SCHEDULER_add_now (&do_error, handle); 962 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -980,6 +981,7 @@ ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
980 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 981 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
981} 982}
982 983
984
983/** 985/**
984 * 986 *
985 * @param con_handle the connection handle 987 * @param con_handle the connection handle
@@ -1030,12 +1032,13 @@ ego_sign_data (struct GNUNET_REST_RequestHandle *con_handle,
1030 cls2->data = (void *) GNUNET_strdup (data); 1032 cls2->data = (void *) GNUNET_strdup (data);
1031 cls2->handle = handle; 1033 cls2->handle = handle;
1032 1034
1033 GNUNET_IDENTITY_ego_lookup (cfg, 1035 GNUNET_IDENTITY_ego_lookup (id_cfg,
1034 username, 1036 username,
1035 ego_sign_data_cb, 1037 ego_sign_data_cb,
1036 cls2); 1038 cls2);
1037} 1039}
1038 1040
1041
1039/** 1042/**
1040 * Respond to OPTIONS request 1043 * Respond to OPTIONS request
1041 * 1044 *
@@ -1155,10 +1158,11 @@ list_ego (void *cls,
1155 * @param proc_cls closure for callback function 1158 * @param proc_cls closure for callback function
1156 * @return GNUNET_OK if request accepted 1159 * @return GNUNET_OK if request accepted
1157 */ 1160 */
1158static enum GNUNET_GenericReturnValue 1161enum GNUNET_GenericReturnValue
1159rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1162REST_identity_process_request (void* plugin,
1160 GNUNET_REST_ResultProcessor proc, 1163 struct GNUNET_REST_RequestHandle *rest_handle,
1161 void *proc_cls) 1164 GNUNET_REST_ResultProcessor proc,
1165 void *proc_cls)
1162{ 1166{
1163 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1167 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1164 struct GNUNET_REST_RequestHandlerError err; 1168 struct GNUNET_REST_RequestHandlerError err;
@@ -1218,20 +1222,19 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1218 * @return NULL on error, otherwise the plugin context 1222 * @return NULL on error, otherwise the plugin context
1219 */ 1223 */
1220void * 1224void *
1221libgnunet_plugin_rest_identity_init (void *cls) 1225REST_identity_init (const struct GNUNET_CONFIGURATION_Handle *c)
1222{ 1226{
1223 static struct Plugin plugin; 1227 static struct Plugin plugin;
1224 struct GNUNET_REST_Plugin *api; 1228 struct GNUNET_REST_Plugin *api;
1225 1229
1226 cfg = cls; 1230 id_cfg = c;
1227 if (NULL != plugin.cfg) 1231 if (NULL != plugin.cfg)
1228 return NULL; /* can only initialize once! */ 1232 return NULL; /* can only initialize once! */
1229 memset (&plugin, 0, sizeof(struct Plugin)); 1233 memset (&plugin, 0, sizeof(struct Plugin));
1230 plugin.cfg = cfg; 1234 plugin.cfg = c;
1231 api = GNUNET_new (struct GNUNET_REST_Plugin); 1235 api = GNUNET_new (struct GNUNET_REST_Plugin);
1232 api->cls = &plugin; 1236 api->cls = &plugin;
1233 api->name = GNUNET_REST_API_NS_IDENTITY; 1237 api->name = GNUNET_REST_API_NS_IDENTITY;
1234 api->process_request = &rest_process_request;
1235 GNUNET_asprintf (&allow_methods, 1238 GNUNET_asprintf (&allow_methods,
1236 "%s, %s, %s, %s, %s", 1239 "%s, %s, %s, %s, %s",
1237 MHD_HTTP_METHOD_GET, 1240 MHD_HTTP_METHOD_GET,
@@ -1240,7 +1243,7 @@ libgnunet_plugin_rest_identity_init (void *cls)
1240 MHD_HTTP_METHOD_DELETE, 1243 MHD_HTTP_METHOD_DELETE,
1241 MHD_HTTP_METHOD_OPTIONS); 1244 MHD_HTTP_METHOD_OPTIONS);
1242 state = ID_REST_STATE_INIT; 1245 state = ID_REST_STATE_INIT;
1243 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); 1246 identity_handle = GNUNET_IDENTITY_connect (id_cfg, &list_ego, NULL);
1244 1247
1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); 1248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1246 return api; 1249 return api;
@@ -1253,10 +1256,9 @@ libgnunet_plugin_rest_identity_init (void *cls)
1253 * @param cls the plugin context (as returned by "init") 1256 * @param cls the plugin context (as returned by "init")
1254 * @return always NULL 1257 * @return always NULL
1255 */ 1258 */
1256void * 1259void
1257libgnunet_plugin_rest_identity_done (void *cls) 1260REST_identity_done (struct GNUNET_REST_Plugin *api)
1258{ 1261{
1259 struct GNUNET_REST_Plugin *api = cls;
1260 struct Plugin *plugin = api->cls; 1262 struct Plugin *plugin = api->cls;
1261 struct EgoEntry *ego_entry; 1263 struct EgoEntry *ego_entry;
1262 struct EgoEntry *ego_tmp; 1264 struct EgoEntry *ego_tmp;
@@ -1279,7 +1281,6 @@ libgnunet_plugin_rest_identity_done (void *cls)
1279 GNUNET_free (allow_methods); 1281 GNUNET_free (allow_methods);
1280 GNUNET_free (api); 1282 GNUNET_free (api);
1281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n"); 1283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1282 return NULL;
1283} 1284}
1284 1285
1285 1286
diff --git a/src/service/rest/identity_plugin.h b/src/service/rest/identity_plugin.h
new file mode 100644
index 000000000..0886156c1
--- /dev/null
+++ b/src/service/rest/identity_plugin.h
@@ -0,0 +1,36 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_identity_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *conndata_handle,
16 GNUNET_REST_ResultProcessor proc,
17 void *proc_cls);
18
19/**
20 * Entry point for the plugin.
21 *
22 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
23 * @return NULL on error, otherwise the plugin context
24 */
25void*
26REST_identity_init (const struct GNUNET_CONFIGURATION_Handle *c);
27
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_identity_done (struct GNUNET_REST_Plugin *api);
diff --git a/src/rest-plugin/reclaim/json_reclaim.c b/src/service/rest/json_reclaim.c
index b1ca7a4a5..b1ca7a4a5 100644
--- a/src/rest-plugin/reclaim/json_reclaim.c
+++ b/src/service/rest/json_reclaim.c
diff --git a/src/rest-plugin/reclaim/json_reclaim.h b/src/service/rest/json_reclaim.h
index 613ddf873..613ddf873 100644
--- a/src/rest-plugin/reclaim/json_reclaim.h
+++ b/src/service/rest/json_reclaim.h
diff --git a/src/service/rest/meson.build b/src/service/rest/meson.build
index 316724fdb..347cbb852 100644
--- a/src/service/rest/meson.build
+++ b/src/service/rest/meson.build
@@ -1,6 +1,16 @@
1libgnunetrest_src = ['rest.c'] 1libgnunetrest_src = ['rest.c']
2 2
3gnunetservicerest_src = ['gnunet-rest-server.c'] 3gnunetservicerest_src = ['gnunet-rest-server.c',
4 'config_plugin.c',
5 'copying_plugin.c',
6 'identity_plugin.c',
7 'namestore_plugin.c',
8 'gns_plugin.c',
9 'openid_plugin.c',
10 'oidc_helper.c',
11 'json_reclaim.c',
12 'reclaim_plugin.c',
13 ]
4 14
5configure_file(input : 'rest.conf', 15configure_file(input : 'rest.conf',
6 output : 'rest.conf', 16 output : 'rest.conf',
@@ -30,7 +40,19 @@ libgnunetrest_dep = declare_dependency(link_with : libgnunetrest)
30 40
31executable ('gnunet-rest-server', 41executable ('gnunet-rest-server',
32 gnunetservicerest_src, 42 gnunetservicerest_src,
33 dependencies: [libgnunetrest_dep, libgnunetutil_dep, mhd_dep], 43 dependencies: [libgnunetrest_dep,
44 libgnunetutil_dep,
45 libgnunetidentity_dep,
46 libgnunetgns_dep,
47 libgnunetreclaim_dep,
48 libgnunetnamestore_dep,
49 libgnunetjson_dep,
50 libgnunetgnsrecord_dep,
51 libgnunetgnsrecordjson_dep,
52 json_dep,
53 jose_dep,
54 gcrypt_dep,
55 mhd_dep],
34 include_directories: [incdir, configuration_inc], 56 include_directories: [incdir, configuration_inc],
35 install: true, 57 install: true,
36 install_dir: get_option('libdir') / 'gnunet' / 'libexec') 58 install_dir: get_option('libdir') / 'gnunet' / 'libexec')
diff --git a/src/rest-plugin/namestore/plugin_rest_namestore.c b/src/service/rest/namestore_plugin.c
index 31e78e6dd..8c5b8b824 100644
--- a/src/rest-plugin/namestore/plugin_rest_namestore.c
+++ b/src/service/rest/namestore_plugin.c
@@ -57,7 +57,7 @@
57/** 57/**
58 * The configuration handle 58 * The configuration handle
59 */ 59 */
60const struct GNUNET_CONFIGURATION_Handle *cfg; 60const struct GNUNET_CONFIGURATION_Handle *ns_cfg;
61 61
62/** 62/**
63 * HTTP methods allows for this plugin 63 * HTTP methods allows for this plugin
@@ -333,7 +333,7 @@ do_error (void *cls)
333 struct MHD_Response *resp; 333 struct MHD_Response *resp;
334 json_t *json_error = json_object (); 334 json_t *json_error = json_object ();
335 char *response; 335 char *response;
336 const char* emsg; 336 const char*emsg;
337 int response_code; 337 int response_code;
338 338
339 emsg = GNUNET_ErrorCode_get_hint (handle->ec); 339 emsg = GNUNET_ErrorCode_get_hint (handle->ec);
@@ -788,6 +788,7 @@ import_next_cb (void *cls, enum GNUNET_ErrorCode ec)
788 handle->rd_set_pos += sent_rds; 788 handle->rd_set_pos += sent_rds;
789} 789}
790 790
791
791static void 792static void
792bulk_tx_start (void *cls, enum GNUNET_ErrorCode ec) 793bulk_tx_start (void *cls, enum GNUNET_ErrorCode ec)
793{ 794{
@@ -920,7 +921,7 @@ namestore_import (struct GNUNET_REST_RequestHandle *con_handle,
920 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 921 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
921 922
922 // We need a per-client connection for a transactional bulk import 923 // We need a per-client connection for a transactional bulk import
923 handle->nc = GNUNET_NAMESTORE_connect (cfg); 924 handle->nc = GNUNET_NAMESTORE_connect (ns_cfg);
924 if (NULL == handle->nc) 925 if (NULL == handle->nc)
925 { 926 {
926 handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; 927 handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN;
@@ -932,6 +933,7 @@ namestore_import (struct GNUNET_REST_RequestHandle *con_handle,
932 handle); 933 handle);
933} 934}
934 935
936
935/** 937/**
936 * Handle namestore POST/PUT request 938 * Handle namestore POST/PUT request
937 * 939 *
@@ -1238,10 +1240,11 @@ list_ego (void *cls,
1238 * @param proc_cls closure for callback function 1240 * @param proc_cls closure for callback function
1239 * @return GNUNET_OK if request accepted 1241 * @return GNUNET_OK if request accepted
1240 */ 1242 */
1241static enum GNUNET_GenericReturnValue 1243enum GNUNET_GenericReturnValue
1242rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1244REST_namestore_process_request (void *plugin,
1243 GNUNET_REST_ResultProcessor proc, 1245 struct GNUNET_REST_RequestHandle *rest_handle,
1244 void *proc_cls) 1246 GNUNET_REST_ResultProcessor proc,
1247 void *proc_cls)
1245{ 1248{
1246 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1249 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1247 struct GNUNET_REST_RequestHandlerError err; 1250 struct GNUNET_REST_RequestHandlerError err;
@@ -1291,20 +1294,19 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1291 * @return NULL on error, otherwise the plugin context 1294 * @return NULL on error, otherwise the plugin context
1292 */ 1295 */
1293void * 1296void *
1294libgnunet_plugin_rest_namestore_init (void *cls) 1297REST_namestore_init (const struct GNUNET_CONFIGURATION_Handle *c)
1295{ 1298{
1296 static struct Plugin plugin; 1299 static struct Plugin plugin;
1297 struct GNUNET_REST_Plugin *api; 1300 struct GNUNET_REST_Plugin *api;
1298 1301
1299 cfg = cls; 1302 ns_cfg = c;
1300 if (NULL != plugin.cfg) 1303 if (NULL != plugin.cfg)
1301 return NULL; /* can only initialize once! */ 1304 return NULL; /* can only initialize once! */
1302 memset (&plugin, 0, sizeof(struct Plugin)); 1305 memset (&plugin, 0, sizeof(struct Plugin));
1303 plugin.cfg = cfg; 1306 plugin.cfg = c;
1304 api = GNUNET_new (struct GNUNET_REST_Plugin); 1307 api = GNUNET_new (struct GNUNET_REST_Plugin);
1305 api->cls = &plugin; 1308 api->cls = &plugin;
1306 api->name = GNUNET_REST_API_NS_NAMESTORE; 1309 api->name = GNUNET_REST_API_NS_NAMESTORE;
1307 api->process_request = &rest_process_request;
1308 state = ID_REST_STATE_INIT; 1310 state = ID_REST_STATE_INIT;
1309 GNUNET_asprintf (&allow_methods, 1311 GNUNET_asprintf (&allow_methods,
1310 "%s, %s, %s, %s, %s", 1312 "%s, %s, %s, %s, %s",
@@ -1313,8 +1315,8 @@ libgnunet_plugin_rest_namestore_init (void *cls)
1313 MHD_HTTP_METHOD_PUT, 1315 MHD_HTTP_METHOD_PUT,
1314 MHD_HTTP_METHOD_DELETE, 1316 MHD_HTTP_METHOD_DELETE,
1315 MHD_HTTP_METHOD_OPTIONS); 1317 MHD_HTTP_METHOD_OPTIONS);
1316 ns_handle = GNUNET_NAMESTORE_connect (cfg); 1318 ns_handle = GNUNET_NAMESTORE_connect (ns_cfg);
1317 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); 1319 identity_handle = GNUNET_IDENTITY_connect (ns_cfg, &list_ego, NULL);
1318 1320
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ( 1321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ (
1320 "Namestore REST API initialized\n")); 1322 "Namestore REST API initialized\n"));
@@ -1328,10 +1330,9 @@ libgnunet_plugin_rest_namestore_init (void *cls)
1328 * @param cls the plugin context (as returned by "init") 1330 * @param cls the plugin context (as returned by "init")
1329 * @return always NULL 1331 * @return always NULL
1330 */ 1332 */
1331void * 1333void
1332libgnunet_plugin_rest_namestore_done (void *cls) 1334REST_namestore_done (struct GNUNET_REST_Plugin *api)
1333{ 1335{
1334 struct GNUNET_REST_Plugin *api = cls;
1335 struct Plugin *plugin = api->cls; 1336 struct Plugin *plugin = api->cls;
1336 struct RequestHandle *request; 1337 struct RequestHandle *request;
1337 struct EgoEntry *ego_entry; 1338 struct EgoEntry *ego_entry;
@@ -1357,7 +1358,6 @@ libgnunet_plugin_rest_namestore_done (void *cls)
1357 GNUNET_free (allow_methods); 1358 GNUNET_free (allow_methods);
1358 GNUNET_free (api); 1359 GNUNET_free (api);
1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); 1360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
1360 return NULL;
1361} 1361}
1362 1362
1363 1363
diff --git a/src/service/rest/namestore_plugin.h b/src/service/rest/namestore_plugin.h
new file mode 100644
index 000000000..2bdf77546
--- /dev/null
+++ b/src/service/rest/namestore_plugin.h
@@ -0,0 +1,37 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_namestore_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *
16 conndata_handle,
17 GNUNET_REST_ResultProcessor proc,
18 void *proc_cls);
19
20/**
21 * Entry point for the plugin.
22 *
23 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
24 * @return NULL on error, otherwise the plugin context
25 */
26void*
27REST_namestore_init (const struct GNUNET_CONFIGURATION_Handle *c);
28
29
30/**
31 * Exit point from the plugin.
32 *
33 * @param cls the plugin context (as returned by "init")
34 * @return always NULL
35 */
36void
37REST_namestore_done (struct GNUNET_REST_Plugin *api);
diff --git a/src/rest-plugin/reclaim/oidc_helper.c b/src/service/rest/oidc_helper.c
index a2da7312b..a2da7312b 100644
--- a/src/rest-plugin/reclaim/oidc_helper.c
+++ b/src/service/rest/oidc_helper.c
diff --git a/src/rest-plugin/reclaim/oidc_helper.h b/src/service/rest/oidc_helper.h
index de788fbdb..de788fbdb 100644
--- a/src/rest-plugin/reclaim/oidc_helper.h
+++ b/src/service/rest/oidc_helper.h
diff --git a/src/rest-plugin/reclaim/plugin_rest_openid_connect.c b/src/service/rest/openid_plugin.c
index d0aee043e..a4f082d2a 100644
--- a/src/rest-plugin/reclaim/plugin_rest_openid_connect.c
+++ b/src/service/rest/openid_plugin.c
@@ -242,7 +242,7 @@
242 * How long to wait for a consume in userinfo endpoint 242 * How long to wait for a consume in userinfo endpoint
243 */ 243 */
244#define CONSUME_TIMEOUT GNUNET_TIME_relative_multiply ( \ 244#define CONSUME_TIMEOUT GNUNET_TIME_relative_multiply ( \
245 GNUNET_TIME_UNIT_SECONDS,2) 245 GNUNET_TIME_UNIT_SECONDS,2)
246 246
247/** 247/**
248 * OIDC ignored parameter array 248 * OIDC ignored parameter array
@@ -268,7 +268,7 @@ struct GNUNET_CONTAINER_MultiHashMap *OIDC_cookie_jar_map;
268/** 268/**
269 * The configuration handle 269 * The configuration handle
270 */ 270 */
271const struct GNUNET_CONFIGURATION_Handle *cfg; 271const struct GNUNET_CONFIGURATION_Handle *oid_cfg;
272 272
273/** 273/**
274 * HTTP methods allows for this plugin 274 * HTTP methods allows for this plugin
@@ -905,6 +905,7 @@ read_jwk_from_file (const char *filename)
905 return jwk; 905 return jwk;
906} 906}
907 907
908
908/** 909/**
909 * @brief Write the JWK to file. If unsuccessful emit warning 910 * @brief Write the JWK to file. If unsuccessful emit warning
910 * 911 *
@@ -927,6 +928,7 @@ write_jwk_to_file (const char *filename,
927 return GNUNET_OK; 928 return GNUNET_OK;
928} 929}
929 930
931
930/** 932/**
931 * @brief Generate a new RSA JSON Web Key 933 * @brief Generate a new RSA JSON Web Key
932 * 934 *
@@ -942,6 +944,7 @@ generate_jwk ()
942 return jwk; 944 return jwk;
943} 945}
944 946
947
945/** 948/**
946 * Return the path to the oidc directory path 949 * Return the path to the oidc directory path
947 * 950 *
@@ -954,7 +957,7 @@ get_oidc_dir_path (void *cls)
954 struct RequestHandle *handle = cls; 957 struct RequestHandle *handle = cls;
955 958
956 // Read OIDC directory from config 959 // Read OIDC directory from config
957 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 960 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (oid_cfg,
958 "reclaim-rest-plugin", 961 "reclaim-rest-plugin",
959 "oidc_dir", 962 "oidc_dir",
960 &oidc_directory)) 963 &oidc_directory))
@@ -970,6 +973,7 @@ get_oidc_dir_path (void *cls)
970 return oidc_directory; 973 return oidc_directory;
971} 974}
972 975
976
973/** 977/**
974 * Return the path to the RSA JWK key file 978 * Return the path to the RSA JWK key file
975 * 979 *
@@ -1004,7 +1008,7 @@ login_redirect (void *cls)
1004 struct GNUNET_Buffer buf = { 0 }; 1008 struct GNUNET_Buffer buf = { 0 };
1005 struct RequestHandle *handle = cls; 1009 struct RequestHandle *handle = cls;
1006 1010
1007 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, 1011 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (oid_cfg,
1008 "reclaim-rest-plugin", 1012 "reclaim-rest-plugin",
1009 "address", 1013 "address",
1010 &login_base_url)) 1014 &login_base_url))
@@ -1451,8 +1455,8 @@ code_redirect (void *cls)
1451 { 1455 {
1452 if (GNUNET_OK != 1456 if (GNUNET_OK !=
1453 GNUNET_CRYPTO_public_key_from_string (handle->oidc 1457 GNUNET_CRYPTO_public_key_from_string (handle->oidc
1454 ->login_identity, 1458 ->login_identity,
1455 &pubkey)) 1459 &pubkey))
1456 { 1460 {
1457 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); 1461 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE);
1458 handle->edesc = 1462 handle->edesc =
@@ -1833,7 +1837,7 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1833 1837
1834 if (GNUNET_OK != 1838 if (GNUNET_OK !=
1835 GNUNET_CRYPTO_public_key_from_string (handle->oidc->client_id, 1839 GNUNET_CRYPTO_public_key_from_string (handle->oidc->client_id,
1836 &handle->oidc->client_pkey)) 1840 &handle->oidc->client_pkey))
1837 { 1841 {
1838 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); 1842 handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT);
1839 handle->edesc = GNUNET_strdup ("The client is not authorized to request an " 1843 handle->edesc = GNUNET_strdup ("The client is not authorized to request an "
@@ -1856,7 +1860,8 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1856 } 1860 }
1857 } 1861 }
1858 if (NULL == handle->tld) 1862 if (NULL == handle->tld)
1859 GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle); 1863 GNUNET_CONFIGURATION_iterate_section_values (oid_cfg, "gns", tld_iter,
1864 handle);
1860 if (NULL == handle->tld) 1865 if (NULL == handle->tld)
1861 handle->tld = GNUNET_strdup (handle->oidc->client_id); 1866 handle->tld = GNUNET_strdup (handle->oidc->client_id);
1862 GNUNET_SCHEDULER_add_now (&build_authz_response, handle); 1867 GNUNET_SCHEDULER_add_now (&build_authz_response, handle);
@@ -2085,7 +2090,7 @@ check_authorization (struct RequestHandle *handle,
2085 } 2090 }
2086 2091
2087 // check client password 2092 // check client password
2088 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, 2093 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (oid_cfg,
2089 "reclaim-rest-plugin", 2094 "reclaim-rest-plugin",
2090 "OIDC_CLIENT_HMAC_SECRET", 2095 "OIDC_CLIENT_HMAC_SECRET",
2091 &expected_pass)) 2096 &expected_pass))
@@ -2277,7 +2282,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2277 GNUNET_free (code_verifier); 2282 GNUNET_free (code_verifier);
2278 2283
2279 // create jwt 2284 // create jwt
2280 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, 2285 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (oid_cfg,
2281 "reclaim-rest-plugin", 2286 "reclaim-rest-plugin",
2282 "expiration_time", 2287 "expiration_time",
2283 &expiration_time)) 2288 &expiration_time))
@@ -2295,7 +2300,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2295 } 2300 }
2296 2301
2297 // Check if HMAC or RSA should be used 2302 // Check if HMAC or RSA should be used
2298 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 2303 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (oid_cfg,
2299 "reclaim-rest-plugin", 2304 "reclaim-rest-plugin",
2300 "oidc_json_web_algorithm", 2305 "oidc_json_web_algorithm",
2301 &jwa)) 2306 &jwa))
@@ -2306,7 +2311,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2306 jwa = JWT_ALG_VALUE_RSA; 2311 jwa = JWT_ALG_VALUE_RSA;
2307 } 2312 }
2308 2313
2309 if ( ! strcmp (jwa, JWT_ALG_VALUE_RSA)) 2314 if (! strcmp (jwa, JWT_ALG_VALUE_RSA))
2310 { 2315 {
2311 // Replace for now 2316 // Replace for now
2312 oidc_jwk_path = get_oidc_jwk_path (cls); 2317 oidc_jwk_path = get_oidc_jwk_path (cls);
@@ -2341,10 +2346,10 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2341 (NULL != nonce) ? nonce : NULL, 2346 (NULL != nonce) ? nonce : NULL,
2342 oidc_jwk); 2347 oidc_jwk);
2343 } 2348 }
2344 else if ( ! strcmp (jwa, JWT_ALG_VALUE_HMAC)) 2349 else if (! strcmp (jwa, JWT_ALG_VALUE_HMAC))
2345 { 2350 {
2346 // TODO OPTIONAL acr,amr,azp 2351 // TODO OPTIONAL acr,amr,azp
2347 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 2352 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (oid_cfg,
2348 "reclaim-rest-plugin", 2353 "reclaim-rest-plugin",
2349 "jwt_secret", 2354 "jwt_secret",
2350 &jwt_secret)) 2355 &jwt_secret))
@@ -2708,6 +2713,7 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2708 GNUNET_free (authorization); 2713 GNUNET_free (authorization);
2709} 2714}
2710 2715
2716
2711/** 2717/**
2712 * Responds to /jwks.json 2718 * Responds to /jwks.json
2713 * 2719 *
@@ -2763,6 +2769,7 @@ jwks_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2763 cleanup_handle (handle); 2769 cleanup_handle (handle);
2764} 2770}
2765 2771
2772
2766/** 2773/**
2767 * If listing is enabled, prints information about the egos. 2774 * If listing is enabled, prints information about the egos.
2768 * 2775 *
@@ -2997,10 +3004,11 @@ oidc_config_cors (struct GNUNET_REST_RequestHandle *con_handle,
2997} 3004}
2998 3005
2999 3006
3000static enum GNUNET_GenericReturnValue 3007enum GNUNET_GenericReturnValue
3001rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 3008REST_openid_process_request (void *plugin,
3002 GNUNET_REST_ResultProcessor proc, 3009 struct GNUNET_REST_RequestHandle *rest_handle,
3003 void *proc_cls) 3010 GNUNET_REST_ResultProcessor proc,
3011 void *proc_cls)
3004{ 3012{
3005 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 3013 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
3006 struct GNUNET_REST_RequestHandlerError err; 3014 struct GNUNET_REST_RequestHandlerError err;
@@ -3056,24 +3064,23 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
3056 * @return NULL on error, otherwise the plugin context 3064 * @return NULL on error, otherwise the plugin context
3057 */ 3065 */
3058void * 3066void *
3059libgnunet_plugin_rest_openid_connect_init (void *cls) 3067REST_openid_init (const struct GNUNET_CONFIGURATION_Handle *c)
3060{ 3068{
3061 static struct Plugin plugin; 3069 static struct Plugin plugin;
3062 struct GNUNET_REST_Plugin *api; 3070 struct GNUNET_REST_Plugin *api;
3063 3071
3064 cfg = cls; 3072 oid_cfg = c;
3065 if (NULL != plugin.cfg) 3073 if (NULL != plugin.cfg)
3066 return NULL; /* can only initialize once! */ 3074 return NULL; /* can only initialize once! */
3067 memset (&plugin, 0, sizeof(struct Plugin)); 3075 memset (&plugin, 0, sizeof(struct Plugin));
3068 plugin.cfg = cfg; 3076 plugin.cfg = oid_cfg;
3069 api = GNUNET_new (struct GNUNET_REST_Plugin); 3077 api = GNUNET_new (struct GNUNET_REST_Plugin);
3070 api->cls = &plugin; 3078 api->cls = &plugin;
3071 api->name = GNUNET_REST_API_NS_OIDC; 3079 api->name = GNUNET_REST_API_NS_OIDC;
3072 api->process_request = &rest_identity_process_request; 3080 identity_handle = GNUNET_IDENTITY_connect (oid_cfg, &list_ego, NULL);
3073 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); 3081 gns_handle = GNUNET_GNS_connect (oid_cfg);
3074 gns_handle = GNUNET_GNS_connect (cfg); 3082 idp = GNUNET_RECLAIM_connect (oid_cfg);
3075 idp = GNUNET_RECLAIM_connect (cfg); 3083 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (oid_cfg,
3076 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
3077 "reclaim-rest-plugin", 3084 "reclaim-rest-plugin",
3078 "OIDC_USERINFO_CONSUME_TIMEOUT", 3085 "OIDC_USERINFO_CONSUME_TIMEOUT",
3079 &consume_timeout)) 3086 &consume_timeout))
@@ -3112,7 +3119,7 @@ cleanup_hashmap (void *cls, const struct GNUNET_HashCode *key, void *value)
3112 * @return always NULL 3119 * @return always NULL
3113 */ 3120 */
3114void * 3121void *
3115libgnunet_plugin_rest_openid_connect_done (void *cls) 3122REST_openid_done (void *cls)
3116{ 3123{
3117 struct GNUNET_REST_Plugin *api = cls; 3124 struct GNUNET_REST_Plugin *api = cls;
3118 struct Plugin *plugin = api->cls; 3125 struct Plugin *plugin = api->cls;
diff --git a/src/service/rest/openid_plugin.h b/src/service/rest/openid_plugin.h
new file mode 100644
index 000000000..65545ac66
--- /dev/null
+++ b/src/service/rest/openid_plugin.h
@@ -0,0 +1,36 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_openid_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *conndata_handle,
16 GNUNET_REST_ResultProcessor proc,
17 void *proc_cls);
18
19/**
20 * Entry point for the plugin.
21 *
22 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
23 * @return NULL on error, otherwise the plugin context
24 */
25void*
26REST_openid_init (const struct GNUNET_CONFIGURATION_Handle *c);
27
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_openid_done (struct GNUNET_REST_Plugin *api);
diff --git a/src/rest-plugin/reclaim/plugin_rest_pabc.c b/src/service/rest/pabc_plugin.c
index 4b7d21df3..4b7d21df3 100644
--- a/src/rest-plugin/reclaim/plugin_rest_pabc.c
+++ b/src/service/rest/pabc_plugin.c
diff --git a/src/rest-plugin/reclaim/plugin_rest_reclaim.c b/src/service/rest/reclaim_plugin.c
index b2586109a..677a6a676 100644
--- a/src/rest-plugin/reclaim/plugin_rest_reclaim.c
+++ b/src/service/rest/reclaim_plugin.c
@@ -80,7 +80,7 @@
80/** 80/**
81 * The configuration handle 81 * The configuration handle
82 */ 82 */
83const struct GNUNET_CONFIGURATION_Handle *cfg; 83const struct GNUNET_CONFIGURATION_Handle *rcfg;
84 84
85/** 85/**
86 * HTTP methods allows for this plugin 86 * HTTP methods allows for this plugin
@@ -317,7 +317,8 @@ do_error (void *cls)
317 handle->response_code = MHD_HTTP_BAD_REQUEST; 317 handle->response_code = MHD_HTTP_BAD_REQUEST;
318 } 318 }
319 resp = GNUNET_REST_create_response (json_error); 319 resp = GNUNET_REST_create_response (json_error);
320 GNUNET_assert (MHD_NO != MHD_add_response_header (resp, "Content-Type", "application/json")); 320 GNUNET_assert (MHD_NO != MHD_add_response_header (resp, "Content-Type",
321 "application/json"));
321 handle->proc (handle->proc_cls, resp, handle->response_code); 322 handle->proc (handle->proc_cls, resp, handle->response_code);
322 cleanup_handle (handle); 323 cleanup_handle (handle);
323 GNUNET_free (json_error); 324 GNUNET_free (json_error);
@@ -1316,7 +1317,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
1316 1317
1317 // For now, independent of path return all options 1318 // For now, independent of path return all options
1318 resp = GNUNET_REST_create_response (NULL); 1319 resp = GNUNET_REST_create_response (NULL);
1319 GNUNET_assert (MHD_NO != MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods)); 1320 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1321 "Access-Control-Allow-Methods",
1322 allow_methods));
1320 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 1323 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1321 cleanup_handle (handle); 1324 cleanup_handle (handle);
1322 return; 1325 return;
@@ -1431,10 +1434,10 @@ list_ego (void *cls,
1431} 1434}
1432 1435
1433 1436
1434static enum GNUNET_GenericReturnValue 1437enum GNUNET_GenericReturnValue
1435rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1438REST_reclaim_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1436 GNUNET_REST_ResultProcessor proc, 1439 GNUNET_REST_ResultProcessor proc,
1437 void *proc_cls) 1440 void *proc_cls)
1438{ 1441{
1439 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1442 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1440 struct GNUNET_REST_RequestHandlerError err; 1443 struct GNUNET_REST_RequestHandlerError err;
@@ -1492,20 +1495,19 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1492 * @return NULL on error, otherwise the plugin context 1495 * @return NULL on error, otherwise the plugin context
1493 */ 1496 */
1494void * 1497void *
1495libgnunet_plugin_rest_reclaim_init (void *cls) 1498REST_reclaim_init (struct GNUNET_CONFIGURATION_Handle *c)
1496{ 1499{
1497 static struct Plugin plugin; 1500 static struct Plugin plugin;
1498 struct GNUNET_REST_Plugin *api; 1501 struct GNUNET_REST_Plugin *api;
1499 1502
1500 cfg = cls; 1503 rcfg = c;
1501 if (NULL != plugin.cfg) 1504 if (NULL != plugin.cfg)
1502 return NULL; /* can only initialize once! */ 1505 return NULL; /* can only initialize once! */
1503 memset (&plugin, 0, sizeof(struct Plugin)); 1506 memset (&plugin, 0, sizeof(struct Plugin));
1504 plugin.cfg = cfg; 1507 plugin.cfg = rcfg;
1505 api = GNUNET_new (struct GNUNET_REST_Plugin); 1508 api = GNUNET_new (struct GNUNET_REST_Plugin);
1506 api->cls = &plugin; 1509 api->cls = &plugin;
1507 api->name = GNUNET_REST_API_NS_RECLAIM; 1510 api->name = GNUNET_REST_API_NS_RECLAIM;
1508 api->process_request = &rest_identity_process_request;
1509 GNUNET_asprintf (&allow_methods, 1511 GNUNET_asprintf (&allow_methods,
1510 "%s, %s, %s, %s, %s", 1512 "%s, %s, %s, %s, %s",
1511 MHD_HTTP_METHOD_GET, 1513 MHD_HTTP_METHOD_GET,
@@ -1513,9 +1515,9 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1513 MHD_HTTP_METHOD_PUT, 1515 MHD_HTTP_METHOD_PUT,
1514 MHD_HTTP_METHOD_DELETE, 1516 MHD_HTTP_METHOD_DELETE,
1515 MHD_HTTP_METHOD_OPTIONS); 1517 MHD_HTTP_METHOD_OPTIONS);
1516 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); 1518 identity_handle = GNUNET_IDENTITY_connect (rcfg, &list_ego, NULL);
1517 state = ID_REST_STATE_INIT; 1519 state = ID_REST_STATE_INIT;
1518 idp = GNUNET_RECLAIM_connect (cfg); 1520 idp = GNUNET_RECLAIM_connect (rcfg);
1519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1520 _ ("Identity Provider REST API initialized\n")); 1522 _ ("Identity Provider REST API initialized\n"));
1521 return api; 1523 return api;
@@ -1529,9 +1531,8 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1529 * @return always NULL 1531 * @return always NULL
1530 */ 1532 */
1531void * 1533void *
1532libgnunet_plugin_rest_reclaim_done (void *cls) 1534REST_reclaim_done (struct GNUNET_REST_Plugin *api)
1533{ 1535{
1534 struct GNUNET_REST_Plugin *api = cls;
1535 struct Plugin *plugin = api->cls; 1536 struct Plugin *plugin = api->cls;
1536 struct RequestHandle *request; 1537 struct RequestHandle *request;
1537 struct EgoEntry *ego_entry; 1538 struct EgoEntry *ego_entry;
diff --git a/src/service/rest/reclaim_plugin.h b/src/service/rest/reclaim_plugin.h
new file mode 100644
index 000000000..102fd827e
--- /dev/null
+++ b/src/service/rest/reclaim_plugin.h
@@ -0,0 +1,36 @@
1#include "gnunet_rest_plugin.h"
2/**
3 * Function processing the REST call
4 *
5 * @param method HTTP method
6 * @param url URL of the HTTP request
7 * @param data body of the HTTP request (optional)
8 * @param data_size length of the body
9 * @param proc callback function for the result
10 * @param proc_cls closure for @a proc
11 * @return #GNUNET_OK if request accepted
12 */
13enum GNUNET_GenericReturnValue
14REST_reclaim_process_request (void *plugin,
15 struct GNUNET_REST_RequestHandle *conndata_handle,
16 GNUNET_REST_ResultProcessor proc,
17 void *proc_cls);
18
19/**
20 * Entry point for the plugin.
21 *
22 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
23 * @return NULL on error, otherwise the plugin context
24 */
25void*
26REST_reclaim_init (const struct GNUNET_CONFIGURATION_Handle *c);
27
28
29/**
30 * Exit point from the plugin.
31 *
32 * @param cls the plugin context (as returned by "init")
33 * @return always NULL
34 */
35void
36REST_reclaim_done (struct GNUNET_REST_Plugin *api);