From 11e9d382995da9fc2c0342abcc52623cc8a80781 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Thu, 26 Jun 2014 16:25:19 +0930 Subject: [PATCH] Rename config 'rhizome.api.restful' to 'api.restful' --- conf_schema.h | 36 ++++++++++--------- httpd.c | 6 ++-- .../servaldna/ServerControl.java | 4 +-- meshms_restful.c | 4 +-- rhizome_restful.c | 4 +-- tests/meshmsrestful | 14 ++++---- tests/rhizomerestful | 10 +++--- 7 files changed, 41 insertions(+), 37 deletions(-) diff --git a/conf_schema.h b/conf_schema.h index 52b701e6..15f49adb 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -384,15 +384,6 @@ STRUCT(rhizome_direct) SUB_STRUCT(peerlist, peer,) END_STRUCT -STRUCT(user) -STRING(50, password, "", str,, "Authentication password") -END_STRUCT - -ARRAY(userlist,) -KEY_STRING(25, str) -VALUE_SUB_STRUCT(user) -END_ARRAY(10) - STRUCT(rhizome_api_addfile) STRING(64, uri_path, "", absolute_path,, "URI path for HTTP add-file request") ATOM(struct in_addr, allow_host, hton_in_addr(INADDR_LOOPBACK), in_addr,, "IP address of host allowed to make HTTP add-file request") @@ -401,15 +392,8 @@ ATOM(sid_t, default_author, SID_ANY, sid,, "Author of ad ATOM(rhizome_bk_t, bundle_secret_key, RHIZOME_BK_NONE, rhizome_bk,, "Secret key of add-file bundle to try if sender not given") END_STRUCT -STRUCT(rhizome_api_restful) -SUB_STRUCT(userlist, users,) -ATOM(uint32_t, newsince_timeout, 60, uint32_time_interval,, "Time to block while reporting new bundles") -ATOM(uint32_t, newsince_poll_ms, 2000, uint32_nonzero,, "Database poll interval while blocked reporting new bundles") -END_STRUCT - STRUCT(rhizome_api) SUB_STRUCT(rhizome_api_addfile, addfile,) -SUB_STRUCT(rhizome_api_restful, restful,) END_STRUCT STRUCT(rhizome_http) @@ -490,6 +474,25 @@ KEY_ATOM(unsigned, uint) VALUE_NODE_STRUCT(network_interface, network_interface) END_ARRAY(10) +STRUCT(user) +STRING(50, password, "", str,, "Authentication password") +END_STRUCT + +ARRAY(userlist,) +KEY_STRING(25, str) +VALUE_SUB_STRUCT(user) +END_ARRAY(10) + +STRUCT(api_restful) +SUB_STRUCT(userlist, users,) +ATOM(uint32_t, newsince_timeout, 60, uint32_time_interval,, "Time to block while reporting new bundles") +ATOM(uint32_t, newsince_poll_ms, 2000, uint32_nonzero,, "Database poll interval while blocked reporting new bundles") +END_STRUCT + +STRUCT(api) +SUB_STRUCT(api_restful, restful,) +END_STRUCT + // The top level. STRUCT(main) NODE_STRUCT(interface_list, interfaces, interface_list,) @@ -504,4 +507,5 @@ SUB_STRUCT(rhizome, rhizome,) SUB_STRUCT(directory, directory,) SUB_STRUCT(olsr, olsr,) SUB_STRUCT(host_list, hosts,) +SUB_STRUCT(api, api,) END_STRUCT diff --git a/httpd.c b/httpd.c index 52e86271..97d0f7d1 100644 --- a/httpd.c +++ b/httpd.c @@ -333,9 +333,9 @@ static int is_authorized(const struct http_client_authorization *auth) if (auth->scheme != BASIC) return 0; unsigned i; - for (i = 0; i != config.rhizome.api.restful.users.ac; ++i) { - if ( strcmp(config.rhizome.api.restful.users.av[i].key, auth->credentials.basic.user) == 0 - && strcmp(config.rhizome.api.restful.users.av[i].value.password, auth->credentials.basic.password) == 0 + for (i = 0; i != config.api.restful.users.ac; ++i) { + if ( strcmp(config.api.restful.users.av[i].key, auth->credentials.basic.user) == 0 + && strcmp(config.api.restful.users.av[i].value.password, auth->credentials.basic.password) == 0 ) return 1; } diff --git a/java/org/servalproject/servaldna/ServerControl.java b/java/org/servalproject/servaldna/ServerControl.java index 30a6cdc4..902eec9e 100644 --- a/java/org/servalproject/servaldna/ServerControl.java +++ b/java/org/servalproject/servaldna/ServerControl.java @@ -99,11 +99,11 @@ public class ServerControl { * RESTful interface. The authorisation must then be supplied to the restful client * object before requests can be made. */ - String restfulPassword = ServalDCommand.getConfigItem("rhizome.api.restful.users." + restfulUsername + ".password"); + String restfulPassword = ServalDCommand.getConfigItem("api.restful.users." + restfulUsername + ".password"); if (restfulPassword == null) { restfulPassword = new BigInteger(130, new SecureRandom()).toString(32); ServalDCommand.configActions( - ServalDCommand.ConfigAction.set, "rhizome.api.restful.users." + restfulUsername + ".password", restfulPassword, + ServalDCommand.ConfigAction.set, "api.restful.users." + restfulUsername + ".password", restfulPassword, ServalDCommand.ConfigAction.sync ); } diff --git a/meshms_restful.c b/meshms_restful.c index bffd57f0..25a18e09 100644 --- a/meshms_restful.c +++ b/meshms_restful.c @@ -341,7 +341,7 @@ static int restful_meshms_newsince_messagelist_json(httpd_request *r, const char return 404; } r->u.msglist.token_offset = r->ui64; - r->u.msglist.end_time = gettime_ms() + config.rhizome.api.restful.newsince_timeout * 1000; + r->u.msglist.end_time = gettime_ms() + config.api.restful.newsince_timeout * 1000; http_request_response_generated(&r->http, 200, CONTENT_TYPE_JSON, restful_meshms_messagelist_json_content); return 1; } @@ -402,7 +402,7 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr r->u.msglist.token_which_ply = r->u.msglist.latest_which_ply; r->u.msglist.token_offset = r->u.msglist.latest_offset; meshms_message_iterator_close(&r->u.msglist.iter); - time_ms_t wake_at = now + config.rhizome.api.restful.newsince_poll_ms; + time_ms_t wake_at = now + config.api.restful.newsince_poll_ms; if (wake_at > r->u.msglist.end_time) wake_at = r->u.msglist.end_time; http_request_pause_response(&r->http, wake_at); diff --git a/rhizome_restful.c b/rhizome_restful.c index baa9863d..2ffcdecc 100644 --- a/rhizome_restful.c +++ b/rhizome_restful.c @@ -115,7 +115,7 @@ int restful_rhizome_newsince(httpd_request *r, const char *remainder) r->u.rhlist.rowcount = 0; bzero(&r->u.rhlist.cursor, sizeof r->u.rhlist.cursor); r->u.rhlist.cursor.rowid_since = rowid; - r->u.rhlist.end_time = gettime_ms() + config.rhizome.api.restful.newsince_timeout * 1000; + r->u.rhlist.end_time = gettime_ms() + config.api.restful.newsince_timeout * 1000; http_request_response_generated(&r->http, 200, CONTENT_TYPE_JSON, restful_rhizome_bundlelist_json_content); return 1; } @@ -163,7 +163,7 @@ static int restful_rhizome_bundlelist_json_content_chunk(struct http_request *hr r->u.rhlist.phase = LIST_END; return 1; } - time_ms_t wake_at = now + config.rhizome.api.restful.newsince_poll_ms; + time_ms_t wake_at = now + config.api.restful.newsince_poll_ms; if (wake_at > r->u.rhlist.end_time) wake_at = r->u.rhlist.end_time; http_request_pause_response(&r->http, wake_at); diff --git a/tests/meshmsrestful b/tests/meshmsrestful index 64cbb325..967c504b 100755 --- a/tests/meshmsrestful +++ b/tests/meshmsrestful @@ -33,9 +33,9 @@ setup() { set_instance +A set_meshms_config executeOk_servald config \ - set rhizome.api.restful.users.harry.password potter \ - set rhizome.api.restful.users.ron.password weasley \ - set rhizome.api.restful.users.hermione.password grainger + set api.restful.users.harry.password potter \ + set api.restful.users.ron.password weasley \ + set api.restful.users.hermione.password grainger set_extra_config if [ -z "$IDENTITY_COUNT" ]; then create_single_identity @@ -288,8 +288,8 @@ doc_MeshmsListMessagesNewSince="HTTP RESTful list MeshMS messages in one convers setup_MeshmsListMessagesNewSince() { IDENTITY_COUNT=2 set_extra_config() { - executeOk_servald config set rhizome.api.restful.newsince_timeout 1s \ - set rhizome.api.restful.newsince_poll_ms 500 + executeOk_servald config set api.restful.newsince_timeout 1s \ + set api.restful.newsince_poll_ms 500 } setup meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<><>>A<<>' @@ -340,8 +340,8 @@ doc_MeshmsListMessagesNewSinceArrival="HTTP RESTful list newly arriving MeshMS m setup_MeshmsListMessagesNewSinceArrival() { IDENTITY_COUNT=2 set_extra_config() { - executeOk_servald config set rhizome.api.restful.newsince_timeout 60s \ - set rhizome.api.restful.newsince_poll_ms 500 + executeOk_servald config set api.restful.newsince_timeout 60s \ + set api.restful.newsince_poll_ms 500 } setup meshms_add_messages $SIDA1 $SIDA2 '><>A>' diff --git a/tests/rhizomerestful b/tests/rhizomerestful index 180aea31..e007ba66 100755 --- a/tests/rhizomerestful +++ b/tests/rhizomerestful @@ -34,9 +34,9 @@ setup() { set_instance +A set_rhizome_config executeOk_servald config \ - set rhizome.api.restful.users.harry.password potter \ - set rhizome.api.restful.users.ron.password weasley \ - set rhizome.api.restful.users.hermione.password grainger + set api.restful.users.harry.password potter \ + set api.restful.users.ron.password weasley \ + set api.restful.users.hermione.password grainger set_extra_config if [ -z "$IDENTITY_COUNT" ]; then create_single_identity @@ -201,8 +201,8 @@ test_RhizomeList() { doc_RhizomeNewSince="HTTP RESTful list Rhizome bundles since token as JSON" setup_RhizomeNewSince() { set_extra_config() { - executeOk_servald config set rhizome.api.restful.newsince_timeout 60s \ - set rhizome.api.restful.newsince_poll_ms 500 + executeOk_servald config set api.restful.newsince_timeout 60s \ + set api.restful.newsince_poll_ms 500 } setup add_bundles 0 5