moved C code to a unified logging framework which currently supports syslogging and...
[OpenSRF.git] / src / jserver / osrf_chat_main.c
1 #include "osrf_chat.h"
2 #include "opensrf/osrfConfig.h"
3 #include <stdio.h>
4 #include "opensrf/log.h"
5 #include <syslog.h>
6
7
8 int main( int argc, char* argv[] ) {
9
10         if( argc < 3 ) {
11                 fprintf( stderr, "Usage: %s <config_file> <config_context>\n", argv[0] );
12                 exit(0);
13         }
14
15         osrfConfig* cfg = osrfConfigInit( argv[1], argv[2] );
16
17         init_proc_title( argc, argv );
18         set_proc_title( "ChopChop" );
19
20         char* domain            = osrfConfigGetValue(cfg, "/domain");
21         char* secret            = osrfConfigGetValue(cfg, "/secret");
22         char* sport                     = osrfConfigGetValue(cfg, "/port");
23         char* s2sport           = osrfConfigGetValue(cfg, "/s2sport");
24         char* listenaddr        = osrfConfigGetValue(cfg, "/listen_address");
25         char* llevel            = osrfConfigGetValue(cfg, "/loglevel");
26         char* lfile                     = osrfConfigGetValue(cfg, "/logfile");
27
28         if(!(domain && secret && sport && listenaddr && llevel && lfile && s2sport)) {
29                 fprintf(stderr, "Configuration error for ChopChop - missing key ingredient\n");
30                 return -1;
31         }
32
33         int port = atoi(sport);
34         int s2port = atoi(s2sport);
35         int level = atoi(llevel);
36         //log_init(level, lfile);
37         osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "chopchop", level);
38         osrfLogSetSyslogFacility(LOG_LOCAL2);
39
40         fprintf(stderr, "Attempting to launch ChopChop with:\n"
41                         "domain: %s\nport: %s\nlisten address: %s\nlog level: %s\nlog file: %s\n",
42                         domain, sport, listenaddr, llevel, lfile );
43
44         osrfChatServer* server = osrfNewChatServer(domain, secret, s2port);
45
46         if( osrfChatServerConnect( server, port, s2port, listenaddr ) != 0 ) {
47                 osrfLogError("ChopChop unable to bind to port %d on %s", port, listenaddr);
48                 return -1;
49         }
50
51         daemonize();
52         osrfChatServerWait( server );
53
54         osrfChatServerFree( server );
55         osrfConfigFree(cfg);
56
57         return 0;
58
59 }
60