~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to apps/ichat-gw/jabberconnector/ichat-gw-jc.cxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <signal.h>
 
2
#include <iostream>
 
3
#include <assert.h>
 
4
 
 
5
#include "JabberComponent.hxx"
 
6
 
 
7
using namespace gateway;
 
8
using namespace std;
 
9
 
 
10
void sleepSeconds(unsigned int seconds)
 
11
{
 
12
#ifdef WIN32
 
13
   Sleep(seconds*1000);
 
14
#else
 
15
   sleep(seconds);
 
16
#endif
 
17
}
 
18
 
 
19
JabberComponent* g_component;
 
20
 
 
21
static void
 
22
signalHandler(int signo)
 
23
{
 
24
   //std::cerr << "Shutting down" << endl;
 
25
   g_component->stop();
 
26
}
 
27
 
 
28
int 
 
29
main (int argc, char** argv)
 
30
{
 
31
#ifndef _WIN32
 
32
   if ( signal( SIGPIPE, SIG_IGN) == SIG_ERR)
 
33
   {
 
34
      cerr << "Couldn't install signal handler for SIGPIPE" << endl;
 
35
      exit(-1);
 
36
   }
 
37
#endif
 
38
 
 
39
   if ( signal( SIGINT, signalHandler ) == SIG_ERR )
 
40
   {
 
41
      cerr << "Couldn't install signal handler for SIGINT" << endl;
 
42
      exit( -1 );
 
43
   }
 
44
 
 
45
   if ( signal( SIGTERM, signalHandler ) == SIG_ERR )
 
46
   {
 
47
      cerr << "Couldn't install signal handler for SIGTERM" << endl;
 
48
      exit( -1 );
 
49
   }
 
50
 
 
51
   if(argc != 11 || std::string(argv[0]) != std::string("ichat-gw"))
 
52
   {
 
53
      cerr << "argc=" << argc << ", argv[0]=" << argv[0] << endl;
 
54
      cerr << "Jabber connector process must not be launched manually, it is launched automatically from the main ichat-gw program." << endl;
 
55
      exit(-1);
 
56
   }
 
57
 
 
58
#if defined(WIN32)
 
59
   WORD wVersionRequested = MAKEWORD( 2, 2 );
 
60
   WSADATA wsaData;
 
61
   int err = WSAStartup( wVersionRequested, &wsaData );
 
62
   if ( err != 0 ) 
 
63
   {
 
64
      // could not find a usable WinSock DLL
 
65
      cerr << "Could not load winsock" << endl;
 
66
      assert(0); 
 
67
      exit(1);
 
68
   }    
 
69
#endif
 
70
 
 
71
   unsigned int jabberConnectorIPCPort = atoi(argv[1]);
 
72
   unsigned int gatewayIPCPort = atoi(argv[2]);
 
73
 
 
74
   g_component = new JabberComponent(jabberConnectorIPCPort,
 
75
                                     gatewayIPCPort,
 
76
                                     argv[3],   // Jabber server
 
77
                                     argv[4],   // Jabber component name
 
78
                                     argv[5],   // Jabber component password
 
79
                                     atoi(argv[6]),   // Jabber component port 
 
80
                                     atoi(argv[7]),   // Jabber server ping duration 
 
81
                                     argv[8],   // Jabber control username 
 
82
                                     argv[9]);  // IPPort Data blob
 
83
 
 
84
 
 
85
   g_component->run();
 
86
 
 
87
   g_component->join();
 
88
   delete g_component;
 
89
 
 
90
   cout << "ichat-gw-jc is shutdown." << endl;
 
91
   sleepSeconds(2);
 
92
}
 
93
 
 
94
 
 
95
/* ====================================================================
 
96
 
 
97
 Copyright (c) 2009, SIP Spectrum, Inc.
 
98
 All rights reserved.
 
99
 
 
100
 Redistribution and use in source and binary forms, with or without
 
101
 modification, are permitted provided that the following conditions are 
 
102
 met:
 
103
 
 
104
 1. Redistributions of source code must retain the above copyright 
 
105
    notice, this list of conditions and the following disclaimer. 
 
106
 
 
107
 2. Redistributions in binary form must reproduce the above copyright
 
108
    notice, this list of conditions and the following disclaimer in the
 
109
    documentation and/or other materials provided with the distribution. 
 
110
 
 
111
 3. Neither the name of SIP Spectrum nor the names of its contributors 
 
112
    may be used to endorse or promote products derived from this 
 
113
    software without specific prior written permission. 
 
114
 
 
115
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
116
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
117
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 
118
 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 
119
 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
120
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
121
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
122
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
123
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
124
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
125
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
126
 
 
127
 ==================================================================== */
 
128