]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libstack/osrf_system.c
8a43804109c9db31e4d9ae98733807fa231aebc0
[OpenSRF.git] / src / libstack / osrf_system.c
1 #include "opensrf/osrf_system.h"
2
3
4 int osrf_system_bootstrap_client() {
5         // XXX config values 
6         transport_client* client = client_init( "judy", 5222, 0 );
7         char buf[256];
8         memset(buf,0,256);
9         char* host = getenv("HOSTNAME");
10         sprintf(buf, "client_%s_%d", host, getpid() );
11
12         if(client_connect( client, "who","hello_you", buf, 10, AUTH_DIGEST )) {
13                 /* push ourselves into the client cache */
14                 osrf_system_push_transport_client( client, "client" );
15                 return 1;
16         }
17
18         return 0;
19 }
20
21 // -----------------------------------------------------------------------------
22 // Some client caching utility methods
23 transport_client_cache* client_cache;
24
25 void osrf_system_push_transport_client( transport_client* client, char* service ) {
26         if(client == NULL || service == NULL) return;
27         transport_client_cache* new = (transport_client_cache*) safe_malloc(sizeof(transport_client_cache));
28         new->service = strdup(service);
29         new->client = client;
30         if(client_cache == NULL) 
31                 client_cache = new;
32         else {
33                 transport_client_cache* tmp = client_cache->next;
34                 client_cache = new;
35                 new->next = tmp;
36         }
37 }
38
39 transport_client* osrf_system_get_transport_client( char* service ) {
40         if(service == NULL) return NULL;
41         transport_client_cache* cur = client_cache;
42         while(cur != NULL) {
43                 if( !strcmp(cur->service, service)) 
44                         return cur->client;
45                 cur = cur->next;
46         }
47         return NULL;
48 }
49 // -----------------------------------------------------------------------------
50
51