/[resiprocate]/main/resip/stack/test/testSipStackInvite.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testSipStackInvite.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (show annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 9 months ago) by dworley
File MIME type: text/plain
File size: 5369 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 #include "resip/stack/SipStack.hxx"
2 #include "resip/stack/Transport.hxx"
3 #include "resip/stack/Uri.hxx"
4 #include "rutil/Logger.hxx"
5
6 #include "rutil/DataStream.hxx"
7
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
11
12
13 using namespace resip;
14 using namespace std;
15
16 #define RESIPROCATE_SUBSYSTEM Subsystem::APP
17 #define CRLF "\r\n"
18
19 char *registerMessage =
20 "REGISTER sip:test.com SIP/2.0" CRLF
21 "Via: SIP/2.0/UDP client.test.com:5060;branch=z9hG4bK-kcD23" CRLF
22 "Max-Forwards: 70" CRLF
23 "From: Me <sip:user@test.com>;tag=62e0154b" CRLF
24 "To: You <sip:you@other.com>" CRLF
25 "Call-ID: b7e6fb02f0e8413d" CRLF
26 "CSeq: 1 REGISTER" CRLF
27 "Contact: <sip:me@123.123.123.123>" CRLF
28 "Content-Length: 0" CRLF CRLF;
29
30
31 char *inviteMessage =
32 "INVITE sip:B@127.0.0.1 SIP/2.0" CRLF
33 "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK0000" CRLF
34 "Max-Forwards: 70" CRLF
35 "From: A <sip:A@127.0.0.1>;tag=12345" CRLF
36 "To: B <sip:B@127.0.0.1>" CRLF
37 "Call-ID: 0123456789@127.0.0.1" CRLF
38 "CSeq: 1 INVITE" CRLF
39 "Contact: <sip:A@127.0.0.1>" CRLF
40 "Content-Length: 0" CRLF CRLF;
41
42 int
43 main(int argc, char *argv[])
44 {
45 char* message = inviteMessage;
46
47 Log::initialize(Log::Cout, Log::Debug, argv[0]);
48
49 InfoLog( << "Starting up, making stack");
50
51 SipStack *theStack = new SipStack();
52 theStack->addTransport(UDP, 5060);
53
54 int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
55
56 // create address to send to
57 struct sockaddr_in sa;
58
59 sa.sin_family = PF_INET;
60 sa.sin_addr.s_addr = inet_addr("127.0.0.1");
61 sa.sin_port = htons(5060);
62
63 DebugLog(<<"size="<<strlen(message) << endl << "message= " << endl << message );
64
65 // send the test message to the stack
66 int err = sendto(fd, message, strlen(message), 0, (struct sockaddr*) & sa, sizeof(sa));
67
68 DebugLog(<<"errno="<<errno);
69
70 assert (err == strlen(message));
71
72
73 int count=0;
74 while (1)
75 {
76 FdSet fdReadSet;
77
78 theStack->buildFdSet(fdReadSet);
79
80 fdReadSet.select(1000);
81
82 theStack->process(fdReadSet);
83 SipMessage* sipMessage = theStack->receive();
84
85 if (sipMessage)
86 {
87 count++;
88 assert (count == 1);
89
90 // InfoLog( << "got message " << *sipMessage);
91 cout << "to header is " << sipMessage->header(h_To) << endl;
92 cout << "to user is " << sipMessage->header(h_To).uri().user() << endl;
93 cout << "cseq sequence is " << sipMessage->header(h_CSeq).sequence() << endl;
94 cout << "cseq method is " << sipMessage->header(h_CSeq).method() << endl;
95 cout << "contact header is " << sipMessage->header(h_Contacts).front() << endl;
96 cout << "contact uri " << sipMessage->header(h_Contacts).front().uri().user() << endl;
97 cout << "request line " << sipMessage->header(h_RequestLine) << endl;
98 cout << "request line uri user" << sipMessage->header(h_RequestLine).uri().user() << endl;
99 }
100
101 usleep(20);
102 }
103
104 return 0;
105
106 }
107 /* ====================================================================
108 * The Vovida Software License, Version 1.0
109 *
110 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
111 *
112 * Redistribution and use in source and binary forms, with or without
113 * modification, are permitted provided that the following conditions
114 * are met:
115 *
116 * 1. Redistributions of source code must retain the above copyright
117 * notice, this list of conditions and the following disclaimer.
118 *
119 * 2. Redistributions in binary form must reproduce the above copyright
120 * notice, this list of conditions and the following disclaimer in
121 * the documentation and/or other materials provided with the
122 * distribution.
123 *
124 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
125 * and "Vovida Open Communication Application Library (VOCAL)" must
126 * not be used to endorse or promote products derived from this
127 * software without prior written permission. For written
128 * permission, please contact vocal@vovida.org.
129 *
130 * 4. Products derived from this software may not be called "VOCAL", nor
131 * may "VOCAL" appear in their name, without prior written
132 * permission of Vovida Networks, Inc.
133 *
134 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
135 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
136 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
137 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
138 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
139 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
140 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
141 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
142 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
143 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
145 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
146 * DAMAGE.
147 *
148 * ====================================================================
149 *
150 * This software consists of voluntary contributions made by Vovida
151 * Networks, Inc. and many individuals on behalf of Vovida Networks,
152 * Inc. For more information on Vovida Networks, Inc., please see
153 * <http://www.vovida.org/>.
154 *
155 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27