r3572 - in trunk/libmsip: include/libmsip source source/transactions

erik at minisip.org erik at minisip.org
Wed Apr 16 14:58:22 CEST 2008


Author: erik
Date: 2008-04-16 14:58:22 +0200 (Wed, 16 Apr 2008)
New Revision: 3572

Modified:
   trunk/libmsip/include/libmsip/SipStack.h
   trunk/libmsip/source/SipLayerTransaction.cxx
   trunk/libmsip/source/SipLayerTransaction.h
   trunk/libmsip/source/SipStack.cxx
   trunk/libmsip/source/SipStackInternal.cxx
   trunk/libmsip/source/SipStackInternal.h
   trunk/libmsip/source/transactions/SipTransaction.cxx
   trunk/libmsip/source/transactions/SipTransaction.h
   trunk/libmsip/source/transactions/SipTransactionInviteClient.cxx
   trunk/libmsip/source/transactions/SipTransactionInviteServer.cxx
   trunk/libmsip/source/transactions/SipTransactionNonInviteClient.cxx
   trunk/libmsip/source/transactions/SipTransactionNonInviteServer.cxx
Log:

 - Added createClientTransaction()
    . In some applications, it can be useful to know the transaction ID
      of a newly created transaction.
 - Created SipTransaction::getTransactionId()
    . We calculated the transaction ID in many places as
      branch+CSeqMethod. Now there is a method to do it in a
      single place in the code.




Modified: trunk/libmsip/include/libmsip/SipStack.h
===================================================================
--- trunk/libmsip/include/libmsip/SipStack.h	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/include/libmsip/SipStack.h	2008-04-16 12:58:22 UTC (rev 3572)
@@ -275,6 +275,22 @@
 		void enqueueTimeout(MRef<SipDialog*> receiver, const SipSMCommand &cmd);
 		void enqueueCommand(const SipSMCommand &cmd, int queue=LOW_PRIO_QUEUE);
 
+		/**
+		 * Creates a client transaction, and lets it start handling
+		 * a request.
+		 *
+		 * This allows the TU to know the branch parameter that 
+		 * a request will have.
+		 *
+		 * NOTE: A UA should NOT need to use this method. Only in
+		 * special cases, the UA (or dialog layer, to be more
+		 * specific), needs to know about the transaction ID of a
+		 * newly created transaction.
+		 *
+		 * @return Transaction id of newly created transaction.
+		 */
+		std::string createClientTransaction(MRef<SipRequest*>);
+
 		void setCallback(MRef<CommandReceiver*> callback);	//Rename to setMessageRouterCallback?
 		MRef<CommandReceiver*> getCallback();	
 		void setConfCallback(MRef<CommandReceiver*> callback); // Hack to make the conference calling work - should not be here FIXME

Modified: trunk/libmsip/source/SipLayerTransaction.cxx
===================================================================
--- trunk/libmsip/source/SipLayerTransaction.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/SipLayerTransaction.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -48,6 +48,26 @@
 		(*i).second->freeStateMachine();
 }
 
+string SipLayerTransaction::createClientTransaction( MRef<SipRequest*> req ){
+
+	MRef<SipTransaction*> newTransaction;
+
+	newTransaction = SipTransaction::create(dispatcher->getSipStackInternal(), 
+			req, 
+			true, 
+			handleAck);
+
+	if (newTransaction){
+		addTransaction(newTransaction);
+		bool handled = newTransaction->handleCommand( SipSMCommand(*req, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer));
+		if (!handled){
+			cerr <<"ERROR: TransactionLayer::defaultCommandHandler: Transaction refused command: "<<req<<endl;
+		}
+		return newTransaction->getTransactionId();
+	}
+	return "";
+}
+
 bool SipLayerTransaction::defaultCommandHandler(const SipSMCommand &cmd){
 	
 	MRef<SipTransaction*> newTransaction;
@@ -96,7 +116,7 @@
 
 void SipLayerTransaction::addTransaction(MRef<SipTransaction*> t){
 	massert(t->getBranch().size()>0);
-	transactions[t->getBranch()+t->getCSeqMethod()]=t;
+	transactions[t->getTransactionId()]=t;
 }
 
 void SipLayerTransaction::removeTransaction(string tid){

Modified: trunk/libmsip/source/SipLayerTransaction.h
===================================================================
--- trunk/libmsip/source/SipLayerTransaction.h	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/SipLayerTransaction.h	2008-04-16 12:58:22 UTC (rev 3572)
@@ -36,6 +36,7 @@
 class SipCommandDispatcher;
 class SipTransaction;
 class SipLayerTransport;
+class SipRequest;
 
 class SipLayerTransaction: public SipSMCommandReceiver{
 	public:
@@ -65,6 +66,15 @@
 		virtual std::string getMemObjectType() const {return "SipLayerTransaction";}
 		
 		virtual bool handleCommand(const SipSMCommand &cmd);
+
+		/**
+		 * Creates client transaction, and let's it start handle
+		 * request.
+		 *
+		 * @return transaction ID (branch) of the newly created
+		 * 	transaction.
+		 */
+		std::string createClientTransaction( MRef<SipRequest*> req );
 		
 	private:
 		void addTransaction(MRef<SipTransaction*> t);

Modified: trunk/libmsip/source/SipStack.cxx
===================================================================
--- trunk/libmsip/source/SipStack.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/SipStack.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -189,3 +189,7 @@
 std::string SipStack::getStackStatusDebugString(){
 	return STACK->getStackStatusDebugString();
 }
+
+std::string SipStack::createClientTransaction(MRef<SipRequest*> req){
+	return STACK->createClientTransaction(req);
+}

Modified: trunk/libmsip/source/SipStackInternal.cxx
===================================================================
--- trunk/libmsip/source/SipStackInternal.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/SipStackInternal.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -572,3 +572,7 @@
 	return dispatcher->getLayerTransport()->getLocalSipPort( transport );
 
 }
+
+std::string SipStackInternal::createClientTransaction(MRef<SipRequest*> req){
+	return dispatcher->getLayerTransaction()->createClientTransaction(req);
+}

Modified: trunk/libmsip/source/SipStackInternal.h
===================================================================
--- trunk/libmsip/source/SipStackInternal.h	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/SipStackInternal.h	2008-04-16 12:58:22 UTC (rev 3572)
@@ -103,6 +103,8 @@
 
 		void free();
 
+		std::string createClientTransaction(MRef<SipRequest*>);
+
 	protected:
 		void startSipServers();
 		void startSipsServers();

Modified: trunk/libmsip/source/transactions/SipTransaction.cxx
===================================================================
--- trunk/libmsip/source/transactions/SipTransaction.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransaction.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -128,7 +128,7 @@
 {
 		//Notify the TU that the transaction is terminated
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::transaction_layer);
 		
@@ -150,7 +150,7 @@
 
 void SipTransaction::handleTimeout(const string &c){
         SipSMCommand cmd(
-			CommandString(getBranch()+getCSeqMethod(),c),
+			CommandString(getTransactionId(),c),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::transaction_layer);
         dispatcher->enqueueTimeout( this, cmd);
@@ -222,7 +222,7 @@
 
 bool SipTransaction::handleCommand(const SipSMCommand &command){
 #ifdef DEBUG_OUTPUT
-	mdbg("signaling/sip") << "SipTransaction:handleCommand: branch <"<< getBranch()<< "> got command "<<command<<endl;
+	mdbg("signaling/sip") << "SipTransaction:handleCommand: tid<"<< getTransactionId()<< "> got command "<<command<<endl;
 #endif
         if (! (command.getDestination()==SipSMCommand::transaction_layer
 				/*|| command.getDestination()==SipSMCommand::ANY*/)){

Modified: trunk/libmsip/source/transactions/SipTransaction.h
===================================================================
--- trunk/libmsip/source/transactions/SipTransaction.h	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransaction.h	2008-04-16 12:58:22 UTC (rev 3572)
@@ -90,6 +90,8 @@
 		
 		std::string getBranch();
 		void setBranch(std::string branch);
+
+		std::string getTransactionId(){ return getBranch() + getCSeqMethod(); }
 				
 		void send(MRef<SipMessage*>  pack, bool addVia, std::string branch=""); // if not specified branch, use the attribute one - ok in most cases.
 		void setSocket(Socket * sock);

Modified: trunk/libmsip/source/transactions/SipTransactionInviteClient.cxx
===================================================================
--- trunk/libmsip/source/transactions/SipTransactionInviteClient.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransactionInviteClient.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -231,11 +231,10 @@
 		cancelTimeout("timerA");
 		cancelTimeout("timerB");
 		
-		SipSMCommand cmd( 
-			CommandString( 
-				callId, 
-				SipCommandString::transport_error
-				), 
+		CommandString terr( callId, SipCommandString::transport_error) ;
+		terr["tid"] = getTransactionId();
+
+		SipSMCommand cmd( terr, 
 			SipSMCommand::transaction_layer, 
 			SipSMCommand::dialog_layer
 			);
@@ -243,7 +242,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 
 		SipSMCommand cmdterminated(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -281,7 +280,7 @@
 		//dialog->dialogState.updateState( (MRef<SipResponse*>((SipResponse *)*command.getCommandPacket()) ) );
 		
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -343,7 +342,7 @@
 		//dialog->dialogState.updateState( (MRef<SipResponse*>((SipResponse *)*command.getCommandPacket()) ) );
 		
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -417,7 +416,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 
 		SipSMCommand cmdterminated(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -435,7 +434,7 @@
 				SipSMCommand::transaction_layer,
 				SipSMCommand::transaction_layer)){
 	    SipSMCommand cmd(
-		    CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+		    CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 		    SipSMCommand::transaction_layer,
 		    SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );

Modified: trunk/libmsip/source/transactions/SipTransactionInviteServer.cxx
===================================================================
--- trunk/libmsip/source/transactions/SipTransactionInviteServer.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransactionInviteServer.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -254,7 +254,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 
 		SipSMCommand cmdterminated(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -283,7 +283,7 @@
 		send(command.getCommandPacket(), false);
 
 		SipSMCommand cmd(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
@@ -386,7 +386,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 
 		SipSMCommand cmdterminated(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -409,7 +409,7 @@
 				SipSMCommand::transaction_layer))
 	{
 		SipSMCommand cmd(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );

Modified: trunk/libmsip/source/transactions/SipTransactionNonInviteClient.cxx
===================================================================
--- trunk/libmsip/source/transactions/SipTransactionNonInviteClient.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransactionNonInviteClient.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -162,7 +162,7 @@
 		dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE);
 
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE);
@@ -276,7 +276,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 
 		SipSMCommand cmdterminated(
-				CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+				CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 				SipSMCommand::transaction_layer,
 				SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -348,7 +348,7 @@
 				SipSMCommand::transaction_layer,
 				SipSMCommand::transaction_layer)){
 		SipSMCommand cmd(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );

Modified: trunk/libmsip/source/transactions/SipTransactionNonInviteServer.cxx
===================================================================
--- trunk/libmsip/source/transactions/SipTransactionNonInviteServer.cxx	2008-04-07 14:40:02 UTC (rev 3571)
+++ trunk/libmsip/source/transactions/SipTransactionNonInviteServer.cxx	2008-04-16 12:58:22 UTC (rev 3572)
@@ -200,7 +200,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );
 		
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE);
@@ -252,7 +252,7 @@
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE);
 		
 		SipSMCommand cmdterminated(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmdterminated, HIGH_PRIO_QUEUE );
@@ -274,7 +274,7 @@
 				SipSMCommand::transaction_layer,
 				SipSMCommand::transaction_layer)){
 		SipSMCommand cmd(
-			CommandString( getBranch()+getCSeqMethod(), SipCommandString::transaction_terminated),
+			CommandString( getTransactionId(), SipCommandString::transaction_terminated),
 			SipSMCommand::transaction_layer,
 			SipSMCommand::dispatcher);
 		dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE );



More information about the Minisip-devel mailing list