2 #include "opensrf/osrfConfig.h"
4 #include "opensrf/log.h"
8 int main( int argc, char* argv[] ) {
11 fprintf( stderr, "Usage: %s <config_file> <config_context>\n", argv[0] );
15 osrfConfig* cfg = osrfConfigInit( argv[1], argv[2] );
17 fprintf( stderr, "Unable to load configuration file %s\n", argv[1] );
21 init_proc_title( argc, argv );
22 set_proc_title( "ChopChop" );
24 char* domain = osrfConfigGetValue(cfg, "/domain");
25 char* secret = osrfConfigGetValue(cfg, "/secret");
26 char* sport = osrfConfigGetValue(cfg, "/port");
27 char* s2sport = osrfConfigGetValue(cfg, "/s2sport");
28 char* listenaddr = osrfConfigGetValue(cfg, "/listen_address");
29 char* llevel = osrfConfigGetValue(cfg, "/loglevel");
30 char* lfile = osrfConfigGetValue(cfg, "/logfile");
31 char* facility = osrfConfigGetValue(cfg, "/syslog");
34 fputs( "No domain specified in configuration file\n", stderr );
37 fputs( "No secret specified in configuration file\n", stderr );
40 fputs( "No port specified in configuration file\n", stderr );
43 fputs( "No listen_address specified in configuration file\n", stderr );
46 fputs( "No loglevel specified in configuration file\n", stderr );
49 fputs( "No logfile specified in configuration file\n", stderr );
52 fputs( "No s2sport specified in configuration file\n", stderr );
54 if(!(domain && secret && sport && listenaddr && llevel && lfile && s2sport)) {
55 fprintf(stderr, "Configuration error for ChopChop - missing key ingredient\n");
59 int port = atoi(sport);
60 int s2port = atoi(s2sport);
61 int level = atoi(llevel);
63 if(!strcmp(lfile, "syslog")) {
64 osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "chopchop", level );
65 osrfLogSetSyslogFacility(osrfLogFacilityToInt(facility));
68 osrfLogInit( OSRF_LOG_TYPE_FILE, "chopchop", level );
69 osrfLogSetFile( lfile );
72 fprintf(stderr, "Attempting to launch ChopChop with:\n"
73 "domain: %s\nport: %s\nlisten address: %s\nlog level: %s\nlog file: %s\n",
74 domain, sport, listenaddr, llevel, lfile );
76 osrfChatServer* server = osrfNewChatServer(domain, secret, s2port);
78 if( osrfChatServerConnect( server, port, s2port, listenaddr ) != 0 ) {
79 osrfLogError( OSRF_LOG_MARK, "ChopChop unable to bind to port %d on %s", port, listenaddr);
84 osrfChatServerWait( server );
86 osrfChatServerFree( server );