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);
17 const char * msg = "config pointer is NULL";
18 fprintf( stderr, "osrf_settings_host_value_object: %s\n", msg );
19 osrfLogError( OSRF_LOG_MARK, msg );
23 return jsonObjectFindPath(config->config, VA_BUF);
27 int osrf_settings_retrieve(char* hostname) {
31 osrf_app_session* session = osrf_app_client_session_init("opensrf.settings");
32 jsonObject* params = jsonNewObject(NULL);
33 jsonObjectPush(params, jsonNewObject(hostname));
34 int req_id = osrf_app_session_make_req(
35 session, params, "opensrf.settings.host_config.get", 1, NULL );
36 osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 60 );
37 jsonObjectFree(params);
39 if(omsg && omsg->_result_content) {
40 config = osrf_settings_new_host_config(hostname);
41 config->config = jsonObjectClone(omsg->_result_content);
42 osrf_message_free(omsg);
45 osrf_app_session_request_finish( session, req_id );
46 osrf_app_session_destroy( session );
49 osrfLogError( OSRF_LOG_MARK, "Unable to load config for host %s", hostname);
57 osrf_host_config* osrf_settings_new_host_config(char* hostname) {
58 if(!hostname) return NULL;
59 osrf_host_config* c = safe_malloc(sizeof(osrf_host_config));
60 c->hostname = strdup(hostname);
64 void osrf_settings_free_host_config(osrf_host_config* c) {
68 jsonObjectFree(c->config);