1 #include "osrf_system.h"
3 transport_client* global_client;
4 char* system_config = NULL;
5 char* config_context = NULL;
6 char* bootstrap_config = NULL;
8 transport_client* osrf_system_get_transport_client() {
13 char* osrf_get_config_context() {
14 return config_context;
17 char* osrf_get_bootstrap_config() {
18 return bootstrap_config;
21 int osrf_system_bootstrap_client( char* config_file, char* contextnode ) {
22 return osrf_system_bootstrap_client_resc(config_file, contextnode, NULL);
25 int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) {
27 if( !config_file || !contextnode )
28 fatal_handler("No Config File Specified\n" );
30 config_context = strdup(contextnode);
31 bootstrap_config = strdup(config_file);
33 debug_handler("Bootstrapping client with config %s and context node %s", config_file, contextnode);
35 config_reader_init( "opensrf.bootstrap", config_file );
37 char* log_file = config_value( "opensrf.bootstrap", "//%s/logfile", contextnode );
38 char* log_level = config_value( "opensrf.bootstrap", "//%s/loglevel", contextnode );
39 char* domain = config_value( "opensrf.bootstrap", "//%s/domains/domain1", contextnode ); /* just the first for now */
40 char* username = config_value( "opensrf.bootstrap", "//%s/username", contextnode );
41 char* password = config_value( "opensrf.bootstrap", "//%s/passwd", contextnode );
42 char* port = config_value( "opensrf.bootstrap", "//%s/port", contextnode );
43 char* unixpath = config_value( "opensrf.bootstrap", "//%s/unixpath", contextnode );
47 if(port) iport = atoi(port);
48 if(log_level) llevel = atoi(log_level);
50 log_init( llevel, log_file );
52 info_handler("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
54 transport_client* client = client_init( domain, iport, unixpath, 0 );
56 char* host = getenv("HOSTNAME");
58 if(!resource) resource = "";
59 int len = strlen(resource) + 256;
62 snprintf(buf, len - 1, "opensrf_%s_%s_%d", resource, host, getpid() );
64 if(client_connect( client, username, password, buf, 10, AUTH_DIGEST )) {
65 /* child nodes will leak the parents client... but we can't free
66 it without disconnecting the parents client :( */
67 global_client = client;
84 int osrf_system_disconnect_client() {
85 client_disconnect( global_client );
86 client_free( global_client );
91 int osrf_system_shutdown() {
93 osrf_system_disconnect_client();
94 //free(system_config);
95 //free(config_context);
96 osrf_settings_free_host_config(NULL);