Re: [OpenSIPStack] Simple Sample for Subscribe
Brought to you by:
joegenbaclor
From: Joegen E. B. <jo...@pl...> - 2006-06-19 12:51:23
|
Martin, Try getting the latest code from CVS or get the daily code snapshot from http://www.opensipstack.org/current/snapshot/opensipstack.tar.gz. SetEvent() has only been recently added. Martin Hillmeier wrote: > Hi Joegen, > > I get some compile errors with the sample code below: > > 1. 'Event' : undeclared identifier > 2. 'SetEvent' : is not a member of 'SIPParser::SIPMessage' > > What do I wrong? > > > Thanks for your help. > > > > > -----Ursprüngliche Nachricht----- > Von: Joegen E. Baclor [mailto:jo...@pl...] > Gesendet: Montag, 19. Juni 2006 12:37 > An: Martin Hillmeier > Cc: Opensipstack Mailing List (ope...@li...) > Betreff: Re: [OpenSIPStack] Simple Sample for Subscribe > > Hi Martin, > > Subscribe and Notify will be part of the RFC3265Session* files. These > files are yet to be checked into the CVS head when support for PUBLISH > and PIDF are finished. I am expecting new development on this subject > within the next couple of weeks. > > As for constructing and sending a SUBSCRIBE, I have attached a sample > code that demonstrates creation and sending of SUBSCRIBE using the stack > > //////////////////////////////////////////////////////////////////////// > ///////////////////// > > > SIPStack sipStack; > sipStack.AddTransport( SIPTransport::UDP, "", 5060); > > SIPURI uri( "sip:som...@ex..." ); > PIPSocket::Address targetAddress; WORD targetPort; > > if( SIPTransport::Resolve( uri, targetAddress, targetPort ) ) { > std::cerr << uri << " does not resolve to an IP Address" << > std::endl; } > > SIPMessage subscribe; > BOOL willUseProxy = FALSE; > > /// create the request line > RequestLine requestLine; > requestLine.SetMethod( "SUBSCRIBE" ); > requestLine.SetRequestURI( uri.AsString() ); subscribe.SetStartLine( > requestLine ); > > Via via; > PIPSocket::Address viaHost; > WORD viaPort; > SIPTransportManager * transportManager = > sipStack.GetTransportManager(); if( > !transportManager->GetListenerAddress( > SIPTransport::UDP, targetAddress, viaHost, viaPort )) > return; > > via.SetAddress( viaHost.AsString() ); > via.SetPort( viaPort ); > via.SetBranch( ParserTools::GenBranchParameter() ); via.AddParameter( > "rport", "" ); subscribe.AppendVia( via ); > > /// Set From header > From from; > SIPURI fromURI( "sip:so...@ex..." ); from.SetURI( > fromURI ); from.AddParameter( "tag", ParserTools::GenTagParameter() ); > > subscribe.SetFrom( from ); > > /// Set To header > To to; > to.SetURI( uri ); > subscribe.SetTo( to ); > > /// Set the call Id > CallId callId; > callId.SetHeaderBody( "call-id-123456" ); subscribe.SetCallId( callId > ); > > /// Set the CSeq > CSeq cSeq; > cSeq.SetMethod( "SUBSCRIBE" ); > cSeq.SetSequence( 4711 ); > subscribe.SetCSeq( cSeq ); > > /// Set the contact > SIPURI contactURI = fromURI; > contactURI.SetHost( via.GetURI().GetHost() ); contactURI.SetPort( > via.GetURI().GetPort() ); > > ContactURI contact( contactURI, "My Display Name" ); > subscribe.AppendContact( contact ); > > Event event( "presence" ); > subscribe.SetEvent( event ); > > TransactionId transactionId; > sipStack.FindTransactionAndAddEvent( subscribe, transactionId, FALSE ); > > while( TRUE ) > { > SIPStackEvent * event = sipStack.ReadEvent(); > if( event->GetType() == SIPStackEvent::Final ) > break; > else if( event->GetType() == SIPStackEvent::Message ) > { > SIPMessage msg = ((SIPMessageArrival*)event)->GetMessage(); > if( !msg.IsRequest() ) > { > /// we got a response > std::cout << msg << std::endl; > if( msg.GetStatusCode() >= 200 ) > break; > } > } > } > > sipStack.Terminate(); > > //////////////////////////////////////////////////////////////////////// > ////////////////////// > > > > Martin Hillmeier wrote: > >> Hi, >> >> can somebody give me a simple sample (few lines of code) how I can >> send a SUBSCRIBE with opensipstack. I'm a newbie and have no idea how >> to do. >> >> >> Thanks in advance >> >> Martin Hillmeier >> ---------------------------------------------------------------------- >> -- >> >> _______________________________________________ >> opensipstack-devel mailing list >> ope...@li... >> https://lists.sourceforge.net/lists/listinfo/opensipstack-devel >> >> > > > > > > > |