Rename config 'rhizome.api.restful' to 'api.restful'

This commit is contained in:
Andrew Bettison 2014-06-26 16:25:19 +09:30
parent 20af8a9477
commit 11e9d38299
7 changed files with 41 additions and 37 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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
);
}

View File

@ -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);

View File

@ -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);

View File

@ -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<>><>>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>'

View File

@ -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