1 #include "osrf_settings.h"
3 osrf_host_config* config = NULL;
5 char* osrf_settings_host_value(char* format, ...) {
6 VA_LIST_TO_STRING(format);
7 jsonObject* o = jsonObjectFindPath(config->config, VA_BUF);
8 char* val = jsonObjectToSimpleString(o);
13 jsonObject* osrf_settings_host_value_object(char* format, ...) {
14 VA_LIST_TO_STRING(format);
15 return jsonObjectFindPath(config->config, VA_BUF);
19 int osrf_settings_retrieve(char* hostname) {
23 osrf_app_session* session = osrf_app_client_session_init("opensrf.settings");
24 jsonObject* params = jsonNewObject(NULL);
25 jsonObjectPush(params, jsonNewObject(hostname));
26 int req_id = osrf_app_session_make_req(
27 session, params, "opensrf.settings.host_config.get", 1, NULL );
28 osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 60 );
29 jsonObjectFree(params);
31 if(omsg && omsg->_result_content) {
32 config = osrf_settings_new_host_config(hostname);
33 config->config = jsonObjectClone(omsg->_result_content);
34 osrf_message_free(omsg);
37 osrf_app_session_request_finish( session, req_id );
38 osrf_app_session_destroy( session );
41 osrfLogError( OSRF_LOG_MARK, "Unable to load config for host %s", hostname);
49 osrf_host_config* osrf_settings_new_host_config(char* hostname) {
50 if(!hostname) return NULL;
51 osrf_host_config* c = safe_malloc(sizeof(osrf_host_config));
52 c->hostname = strdup(hostname);
56 void osrf_settings_free_host_config(osrf_host_config* c) {
60 jsonObjectFree(c->config);