1
#include <rutil/Log.hxx>
2
#include <rutil/Logger.hxx>
3
#include <rutil/DnsUtil.hxx>
4
#include <rutil/BaseException.hxx>
5
#include <rutil/XMLCursor.hxx>
6
#include <rutil/WinLeakCheck.hxx>
11
#define RESIPROCATE_SUBSYSTEM Subsystem::TEST
13
void sleepSeconds(unsigned int seconds)
23
main (int argc, char** argv)
30
struct sockaddr_in localAddr, servAddr;
35
ErrLog(<< "usage: " << argv[0] <<" <server> <port> <initiator> <destination> <anchor 0|1>");
39
h = gethostbyname(argv[1]);
42
ErrLog(<< "unknown host " << argv[1]);
46
servAddr.sin_family = h->h_addrtype;
47
memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
48
servAddr.sin_port = htons(atoi(argv[2]));
51
sd = socket(AF_INET, SOCK_STREAM, 0);
54
ErrLog(<< "cannot open socket");
58
// bind to any local interface/port
59
localAddr.sin_family = AF_INET;
60
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
61
localAddr.sin_port = 0;
63
rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr));
66
ErrLog(<<"error binding locally");
71
rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));
74
ErrLog(<< "error connecting");
81
" <Initiator>" + Data(argv[3]) + "</Initiator>\r\n"
82
" <Destination>" + Data(argv[4]) + "</Destination>\r\n"
83
" <AnchorCall>" + Data(argv[5][0] == '0' ? "false" : "true") + "</AnchorCall>\r\n"
85
"</ClickToCall>\r\n");
86
rc = send(sd, request.c_str(), request.size(), 0);
89
ErrLog(<< "error sending");
94
char readBuffer[8000];
97
rc = recv(sd, (char*)&readBuffer, sizeof(readBuffer), 0);
100
ErrLog(<< "error receiving");
107
Data response(Data::Borrow, (const char*)&readBuffer, rc);
108
InfoLog(<< "Received response: \r\n" << response.c_str());
109
ParseBuffer pb(response);
113
if(xml.nextSibling())
119
if(xml.getTag() == "Result")
121
XMLCursor::AttributeMap attribs = xml.getAttributes();
122
XMLCursor::AttributeMap::iterator it = attribs.find("Code");
123
if(it != attribs.end())
125
unsigned long statusCode = it->second.convertUnsignedLong();
126
if(statusCode >= 200 && statusCode < 300)
128
it = attribs.find("Leg");
129
if(it != attribs.end())
131
if(it->second == "Destination")
133
// Successfully connected to destination - break out
138
else if(statusCode >=300)
140
// Failed - break out
146
} while(xml.nextSibling());
154
InfoLog(<< "xmlrpcclient done.");
157
/* ====================================================================
159
Copyright (c) 2009, SIP Spectrum, Inc.
162
Redistribution and use in source and binary forms, with or without
163
modification, are permitted provided that the following conditions are
166
1. Redistributions of source code must retain the above copyright
167
notice, this list of conditions and the following disclaimer.
169
2. Redistributions in binary form must reproduce the above copyright
170
notice, this list of conditions and the following disclaimer in the
171
documentation and/or other materials provided with the distribution.
173
3. Neither the name of SIP Spectrum nor the names of its contributors
174
may be used to endorse or promote products derived from this
175
software without specific prior written permission.
177
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
179
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
180
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
181
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
182
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
183
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
184
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
185
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
186
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
187
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
189
==================================================================== */