]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/libstack/osrf_settings.c
clark knows how to use custom widget filter code now
[Evergreen.git] / OpenSRF / src / libstack / osrf_settings.c
1 #include "osrf_settings.h" 
2
3 osrf_host_config* config = NULL;
4
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);
9         jsonObjectFree(o);
10         return val;
11 }
12
13 jsonObject* osrf_settings_host_value_object(char* format, ...) {
14         VA_LIST_TO_STRING(format);
15         return jsonObjectFindPath(config->config, VA_BUF);
16 }
17
18
19 int osrf_settings_retrieve(char* hostname) {
20
21         if(!config) {
22
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);
30
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);
35                 }
36
37                 osrf_app_session_request_finish( session, req_id );
38                 osrf_app_session_destroy( session );
39
40                 if(!config) {
41                         osrfLogError("Unable to load config for host %s", hostname);
42                         return -1;
43                 }
44         }
45
46         return 0;
47 }
48
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);
53         return c;
54 }
55
56 void osrf_settings_free_host_config(osrf_host_config* c) {
57         if(!c) c = config;
58         if(!c) return;
59         free(c->hostname);
60         jsonObjectFree(c->config);      
61         free(c);
62 }