r2692 - in trunk/libmsip: include/libmsip source/dialogs

mikma at minisip.org mikma at minisip.org
Sat Jul 8 18:38:55 CEST 2006


Author: mikma
Date: 2006-07-08 18:38:54 +0200 (Sat, 08 Jul 2006)
New Revision: 2692

Modified:
   trunk/libmsip/include/libmsip/SipDialog.h
   trunk/libmsip/source/dialogs/SipDialog.cxx
Log:
Add a list of SipAuthenticateDigest to the dialog state and implement
updateAuthentications and addAuthorizations in SipDialog, which
update the list from a respons containing WWW-Authenticate or
Proxy-Authenticate headers and add Authorize or Proxy-Authorize headers
to requests within the "dialog".


Modified: trunk/libmsip/include/libmsip/SipDialog.h
===================================================================
--- trunk/libmsip/include/libmsip/SipDialog.h	2006-07-08 16:08:24 UTC (rev 2691)
+++ trunk/libmsip/include/libmsip/SipDialog.h	2006-07-08 16:38:54 UTC (rev 2692)
@@ -47,6 +47,7 @@
 class SipTransaction;
 class SipDialogConfig;
 class SipCommandDispatcher;
+class SipAuthenticationDigest;
 //class SipDialogContainer;
 
 
@@ -112,6 +113,8 @@
 	
 		bool isEarly;
 		bool isEstablished;
+
+		std::list<MRef<SipAuthenticationDigest*> > auths;
 };
 
 
@@ -216,6 +219,18 @@
 		/** Send a Sip message to the transaction layer */
 		void sendSipMessage( MRef<SipMessage*> msg, int queue=HIGH_PRIO_QUEUE );
 
+		/**
+		 * Get all WWW-Authenticate and Proxy-Authenticate headers
+		 * in the response and register in the dialog
+		 */
+		bool updateAuthentications( MRef<SipResponse*> resp );
+
+		/**
+		 * Add Authorize or Proxy-Authorize headers for all
+		 * authentications registered in the dialog.
+		 */
+		void addAuthorizations( MRef<SipRequest*> req );
+
 	protected:
 //		///a list containing all transactions
 //		std::list<MRef<SipTransaction*> > transactions;
@@ -225,6 +240,8 @@
 		
 		MRef<SipCommandDispatcher*> dispatcher;
 
+		bool updateAuthentication( MRef<SipResponse*> resp,
+					   MRef<SipHeaderValueProxyAuthenticate*> auth);
 	private:
 		
 		///the dialog configuration

Modified: trunk/libmsip/source/dialogs/SipDialog.cxx
===================================================================
--- trunk/libmsip/source/dialogs/SipDialog.cxx	2006-07-08 16:08:24 UTC (rev 2691)
+++ trunk/libmsip/source/dialogs/SipDialog.cxx	2006-07-08 16:38:54 UTC (rev 2692)
@@ -34,6 +34,7 @@
 #include<libmsip/SipStack.h>
 #include<libmsip/SipDialogConfig.h>
 #include<libmsip/SipDialog.h>
+#include<libmsip/SipAuthenticationDigest.h>
 //#include<libmsip/SipDialogContainer.h>
 #include<libmutil/dbg.h>
 #include<libmsip/SipSMCommand.h>
@@ -45,6 +46,9 @@
 #include<libmsip/SipHeaderRoute.h>
 #include<libmsip/SipHeaderRAck.h>
 #include<libmsip/SipHeaderRSeq.h>
+#include<libmsip/SipHeaderProxyAuthenticate.h>
+#include<libmsip/SipHeaderProxyAuthorization.h>
+#include<libmsip/SipHeaderWWWAuthenticate.h>
 #include<libmutil/CommandString.h>
 
 using namespace std;
@@ -189,6 +193,12 @@
 
 	addRoute( req );
 
+	// Add authorizations unless an ACK or CANCEL request
+	// which should contain the same authorization headers as the INVITE
+	if( method != "ACK" &&
+	    method != "CANCEL" )
+		addAuthorizations( req );
+
 	return req;
 }
 
@@ -254,7 +264,80 @@
 	dispatcher->enqueueCommand( cmd, queue );
 }
 
+bool SipDialog::updateAuthentication( MRef<SipResponse*> resp,
+				      MRef<SipHeaderValueProxyAuthenticate*> auth){
+	bool changed = false;
 
+	MRef<SipAuthenticationDigest*> challenge;
+	challenge = new SipAuthenticationDigest( auth );
+
+	bool found = false;
+	list<MRef<SipAuthenticationDigest*> >::iterator j;
+
+	for ( j = dialogState.auths.begin();
+	      j != dialogState.auths.end(); j++ ){
+		MRef<SipAuthenticationDigest*> item = *j;
+			
+		if( item->getRealm() == challenge->getRealm() ){
+			item->update( *auth );
+
+			if( item->getStale() )
+				changed = true;
+			found = true;
+		}
+	}
+		
+	if( !found ){
+		dialogState.auths.push_back( challenge );
+
+		string username = getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyUsername;
+		string password = getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyPassword;
+
+		challenge->setCredential( username, password );
+		changed = true;
+	}
+
+	return changed;
+}
+
+bool SipDialog::updateAuthentications( MRef<SipResponse*> resp ){
+	bool changed = false;
+
+	for( int i = 0;; i++ ){
+		MRef<SipHeaderValueWWWAuthenticate*> auth;
+		auth = resp->getHeaderValueWWWAuthenticate( i );
+
+		if( !auth )
+			break;
+
+		changed |= updateAuthentication(resp, *auth);
+	}
+
+	for( int i = 0;; i++ ){
+		MRef<SipHeaderValueProxyAuthenticate*> auth;
+		auth = resp->getHeaderValueProxyAuthenticate( i );
+
+		if( !auth )
+			break;
+
+		changed |= updateAuthentication(resp, auth);
+	}
+
+	return changed;
+}
+
+void SipDialog::addAuthorizations( MRef<SipRequest*> req ){
+	list<MRef<SipAuthenticationDigest*> >::iterator j;
+
+	for ( j = dialogState.auths.begin();
+	      j != dialogState.auths.end(); j++ ){
+		MRef<SipAuthenticationDigest*> digest = *j;
+
+		MRef<SipHeaderValueAuthorization*> authHeader = digest->createAuthorization( req );
+		req->addHeader( new SipHeader( *authHeader ) );
+	}
+}
+
 /*
 Establish a dialog acting as a UAS (receive a request)
 - routeSet = Record-Route header list, direct order



More information about the Minisip-devel mailing list