]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/libstack/osrf_system.c
new json api changes
[working/Evergreen.git] / OpenSRF / src / libstack / osrf_system.c
1 #include "osrf_system.h"
2
3 transport_client* __osrfGlobalTransportClient;
4
5 transport_client* osrf_system_get_transport_client() {
6         return __osrfGlobalTransportClient;
7 }
8
9 int osrf_system_bootstrap_client( char* config_file, char* contextnode ) {
10         return osrf_system_bootstrap_client_resc(config_file, contextnode, NULL);
11 }
12
13 int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) {
14
15         if( !( config_file && contextnode ) && ! osrfConfigHasDefaultConfig() )
16                 fatal_handler("No Config File Specified\n" );
17
18         if( config_file ) {
19                 osrfConfigCleanup();
20                 osrfConfig* cfg = osrfConfigInit( config_file, contextnode );
21                 osrfConfigSetDefaultConfig(cfg);
22         }
23
24
25         char* log_file          = osrfConfigGetValue( NULL, "/logfile");
26         char* log_level = osrfConfigGetValue( NULL, "/loglevel" );
27         osrfStringArray* arr = osrfNewStringArray(8);
28         osrfConfigGetValueList(NULL, arr, "/domains/domain");
29         char* username          = osrfConfigGetValue( NULL, "/username" );
30         char* password          = osrfConfigGetValue( NULL, "/passwd" );
31         char* port                      = osrfConfigGetValue( NULL, "/port" );
32         char* unixpath          = osrfConfigGetValue( NULL, "/unixpath" );
33
34         char* domain = osrfStringArrayGetString( arr, 0 ); /* just the first for now */
35         osrfStringArrayFree(arr);
36
37
38         int llevel = 0;
39         int iport = 0;
40         if(port) iport = atoi(port);
41         if(log_level) llevel = atoi(log_level);
42
43         log_init( llevel, log_file );
44
45         info_handler("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
46
47         transport_client* client = client_init( domain, iport, unixpath, 0 );
48
49         char* host = getenv("HOSTNAME");
50
51         if(!resource) resource = "";
52         int len = strlen(resource) + 256;
53         char buf[len];
54         memset(buf,0,len);
55         snprintf(buf, len - 1, "opensrf_%s_%s_%d", resource, host, getpid() );
56         
57         if(client_connect( client, username, password, buf, 10, AUTH_DIGEST )) {
58                 /* child nodes will leak the parents client... but we can't free
59                         it without disconnecting the parents client :( */
60                 __osrfGlobalTransportClient = client;
61         }
62
63         free(log_level);
64         free(log_file);
65         free(username);
66         free(password);
67         free(port);     
68         free(unixpath);
69
70         if(__osrfGlobalTransportClient)
71                 return 1;
72
73         return 0;
74 }
75
76 int osrf_system_disconnect_client() {
77         client_disconnect( __osrfGlobalTransportClient );
78         client_free( __osrfGlobalTransportClient );
79         __osrfGlobalTransportClient = NULL;
80         return 0;
81 }
82
83 int osrf_system_shutdown() {
84         osrfConfigCleanup();
85         osrf_system_disconnect_client();
86         osrf_settings_free_host_config(NULL);
87         log_free();
88         return 1;
89 }
90
91
92
93