|
reSIProcate/stack
9694
|
00001 #include "resip/stack/SipStack.hxx" 00002 #include "resip/stack/Transport.hxx" 00003 #include "resip/stack/Uri.hxx" 00004 #include "rutil/Logger.hxx" 00005 00006 #include "rutil/DataStream.hxx" 00007 00008 #include <sys/socket.h> 00009 #include <netinet/in.h> 00010 #include <arpa/inet.h> 00011 00012 00013 using namespace resip; 00014 using namespace std; 00015 00016 #define RESIPROCATE_SUBSYSTEM Subsystem::APP 00017 #define CRLF "\r\n" 00018 00019 char *registerMessage = 00020 "REGISTER sip:test.com SIP/2.0" CRLF 00021 "Via: SIP/2.0/UDP client.test.com:5060;branch=z9hG4bK-kcD23" CRLF 00022 "Max-Forwards: 70" CRLF 00023 "From: Me <sip:user@test.com>;tag=62e0154b" CRLF 00024 "To: You <sip:you@other.com>" CRLF 00025 "Call-ID: b7e6fb02f0e8413d" CRLF 00026 "CSeq: 1 REGISTER" CRLF 00027 "Contact: <sip:me@123.123.123.123>" CRLF 00028 "Content-Length: 0" CRLF CRLF; 00029 00030 00031 char *inviteMessage = 00032 "INVITE sip:B@127.0.0.1 SIP/2.0" CRLF 00033 "Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK0000" CRLF 00034 "Max-Forwards: 70" CRLF 00035 "From: A <sip:A@127.0.0.1>;tag=12345" CRLF 00036 "To: B <sip:B@127.0.0.1>" CRLF 00037 "Call-ID: 0123456789@127.0.0.1" CRLF 00038 "CSeq: 1 INVITE" CRLF 00039 "Contact: <sip:A@127.0.0.1>" CRLF 00040 "Content-Length: 0" CRLF CRLF; 00041 00042 int 00043 main(int argc, char *argv[]) 00044 { 00045 char* message = inviteMessage; 00046 00047 Log::initialize(Log::Cout, Log::Debug, argv[0]); 00048 00049 InfoLog( << "Starting up, making stack"); 00050 00051 SipStack *theStack = new SipStack(); 00052 theStack->addTransport(UDP, 5060); 00053 00054 int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 00055 00056 // create address to send to 00057 struct sockaddr_in sa; 00058 00059 sa.sin_family = PF_INET; 00060 sa.sin_addr.s_addr = inet_addr("127.0.0.1"); 00061 sa.sin_port = htons(5060); 00062 00063 DebugLog(<<"size="<<strlen(message) << endl << "message= " << endl << message ); 00064 00065 // send the test message to the stack 00066 int err = sendto(fd, message, strlen(message), 0, (struct sockaddr*) & sa, sizeof(sa)); 00067 00068 DebugLog(<<"errno="<<errno); 00069 00070 assert (err == strlen(message)); 00071 00072 00073 int count=0; 00074 while (1) 00075 { 00076 FdSet fdReadSet; 00077 00078 theStack->buildFdSet(fdReadSet); 00079 00080 fdReadSet.select(1000); 00081 00082 theStack->process(fdReadSet); 00083 SipMessage* sipMessage = theStack->receive(); 00084 00085 if (sipMessage) 00086 { 00087 count++; 00088 assert (count == 1); 00089 00090 // InfoLog( << "got message " << *sipMessage); 00091 cout << "to header is " << sipMessage->header(h_To) << endl; 00092 cout << "to user is " << sipMessage->header(h_To).uri().user() << endl; 00093 cout << "cseq sequence is " << sipMessage->header(h_CSeq).sequence() << endl; 00094 cout << "cseq method is " << sipMessage->header(h_CSeq).method() << endl; 00095 cout << "contact header is " << sipMessage->header(h_Contacts).front() << endl; 00096 cout << "contact uri " << sipMessage->header(h_Contacts).front().uri().user() << endl; 00097 cout << "request line " << sipMessage->header(h_RequestLine) << endl; 00098 cout << "request line uri user" << sipMessage->header(h_RequestLine).uri().user() << endl; 00099 } 00100 00101 usleep(20); 00102 } 00103 00104 return 0; 00105 00106 } 00107 /* ==================================================================== 00108 * The Vovida Software License, Version 1.0 00109 * 00110 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00111 * 00112 * Redistribution and use in source and binary forms, with or without 00113 * modification, are permitted provided that the following conditions 00114 * are met: 00115 * 00116 * 1. Redistributions of source code must retain the above copyright 00117 * notice, this list of conditions and the following disclaimer. 00118 * 00119 * 2. Redistributions in binary form must reproduce the above copyright 00120 * notice, this list of conditions and the following disclaimer in 00121 * the documentation and/or other materials provided with the 00122 * distribution. 00123 * 00124 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00125 * and "Vovida Open Communication Application Library (VOCAL)" must 00126 * not be used to endorse or promote products derived from this 00127 * software without prior written permission. For written 00128 * permission, please contact vocal@vovida.org. 00129 * 00130 * 4. Products derived from this software may not be called "VOCAL", nor 00131 * may "VOCAL" appear in their name, without prior written 00132 * permission of Vovida Networks, Inc. 00133 * 00134 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00135 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00136 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00137 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00138 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00139 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00140 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00141 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00142 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00143 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00145 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00146 * DAMAGE. 00147 * 00148 * ==================================================================== 00149 * 00150 * This software consists of voluntary contributions made by Vovida 00151 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00152 * Inc. For more information on Vovida Networks, Inc., please see 00153 * <http://www.vovida.org/>. 00154 * 00155 */
1.7.5.1