Index: libmsn-4.0-beta8/msn/soap.h
===================================================================
--- libmsn-4.0-beta8.orig/msn/soap.h
+++ libmsn-4.0-beta8/msn/soap.h
@@ -35,6 +35,8 @@
 #include <vector>
 #include <map>
 
+#include "xmlParser.h"
+
 #include "libmsn_export.h"
 
 namespace MSN
@@ -205,6 +207,8 @@ public:
 
         void changeDisplayName(std::string newDisplayName);
         void parseChangeDisplayNameResponse(std::string);
+    
+        Soap* manageSoapRedirect(XMLNode response1, soapAction action);
 
         virtual void dispatchCommand(std::vector<std::string> &) {};
         virtual void connect(const std::string &, unsigned int) {};
Index: libmsn-4.0-beta8/msn/soap.cpp
===================================================================
--- libmsn-4.0-beta8.orig/msn/soap.cpp
+++ libmsn-4.0-beta8/msn/soap.cpp
@@ -314,25 +314,17 @@ namespace MSN {
 
     void Soap::parseGetTicketsResponse(std::string response)
     {
-          XMLNode domTree = XMLNode::parseString( response.c_str() );
-        if(http_response_code == "301" )
+        XMLNode response1 = XMLNode::parseString( response.c_str() );
+        if(http_response_code == "301")
         {
-            const char *preferredHostName = domTree.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[AUTH] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->getTickets(this->passport, this->password, this->policy);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, AUTH);
+            soapConnection->getTickets(this->passport, this->password, this->policy);
             return;
         }
 
           // get the header information from the DOM
-          XMLNode tokens = domTree.getChildNode("S:Envelope").getChildNode("S:Body").getChildNode("wst:RequestSecurityTokenResponseCollection");
-          const char *reason = domTree.getChildNode("S:Envelope").getChildNode("S:Fault").getChildNode("faultcode").getText();
+          XMLNode tokens = response1.getChildNode("S:Envelope").getChildNode("S:Body").getChildNode("wst:RequestSecurityTokenResponseCollection");
+          const char *reason = response1.getChildNode("S:Envelope").getChildNode("S:Fault").getChildNode("faultcode").getText();
           if(reason)
           {
             std::string reason1(reason);
@@ -345,7 +337,7 @@ namespace MSN {
             }
             if(reason1 == "psf:Redirect")
             {
-                const char *newurl = domTree.getChildNode("S:Envelope").getChildNode("S:Fault").getChildNode("psf:redirectUrl").getText();
+                const char *newurl = response1.getChildNode("S:Envelope").getChildNode("S:Fault").getChildNode("psf:redirectUrl").getText();
                 Soap *soapConnection = new Soap(notificationServer);
 
                 std::string newurl1(newurl);
@@ -465,22 +457,14 @@ namespace MSN {
     void Soap::parseEnableContactOnAddressBookResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[ENABLE_CONTACT_ON_ADDRESSBOOK] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->enableContactOnAddressBook(this->contactId, this->tempPassport, this->myDisplayName);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, ENABLE_CONTACT_ON_ADDRESSBOOK);
+            soapConnection->enableContactOnAddressBook(this->contactId, this->tempPassport, this->myDisplayName);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -561,22 +545,14 @@ namespace MSN {
     void Soap::parseDelContactFromAddressBookResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DEL_CONTACT_FROM_ADDRESSBOOK] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->delContactFromAddressBook(this->contactId, this->tempPassport);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, DEL_CONTACT_FROM_ADDRESSBOOK);
+            soapConnection->delContactFromAddressBook(this->contactId, this->tempPassport);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -668,22 +644,14 @@ namespace MSN {
     void Soap::parseDisableContactFromAddressBookResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DISABLE_CONTACT_ON_ADDRESSBOOK] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->disableContactFromAddressBook(this->contactId, this->tempPassport);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, DISABLE_CONTACT_ON_ADDRESSBOOK);
+            soapConnection->disableContactFromAddressBook(this->contactId, this->tempPassport);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -782,18 +750,11 @@ namespace MSN {
     void Soap::parseAddContactToAddressBookResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[ADD_CONTACT_TO_ADDRESSBOOK] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->addContactToAddressBook(this->tempPassport, this->tempDisplayName);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, ADD_CONTACT_TO_ADDRESSBOOK);
+            soapConnection->addContactToAddressBook(this->tempPassport, this->tempDisplayName);
             return;
         }
 
@@ -887,22 +848,14 @@ namespace MSN {
     void Soap::parseAddContactToGroupResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[ADD_CONTACT_TO_GROUP] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->addContactToGroup(this->groupId, this->contactId);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, ADD_CONTACT_TO_GROUP);
+            soapConnection->addContactToGroup(this->groupId, this->contactId);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1002,22 +955,14 @@ namespace MSN {
     void Soap::parseAddGroupResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[ADD_GROUP] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->addGroup(this->groupName);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, ADD_GROUP);
+            soapConnection->addGroup(this->groupName);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1101,22 +1046,14 @@ namespace MSN {
     void Soap::parseDelGroupResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DEL_GROUP] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->delGroup(this->groupId);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, DEL_GROUP);
+            soapConnection->delGroup(this->groupId);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1205,22 +1142,14 @@ namespace MSN {
     void Soap::parseRenameGroupResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[RENAME_GROUP] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->renameGroup(this->groupId, this->groupName);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, RENAME_GROUP);
+            soapConnection->renameGroup(this->groupId, this->groupName);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1308,22 +1237,14 @@ namespace MSN {
     void Soap::parseDelContactFromGroupResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DEL_CONTACT_FROM_GROUP] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->delContactFromGroup(this->groupId, this->contactId);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, DEL_CONTACT_FROM_GROUP);
+            soapConnection->delContactFromGroup(this->groupId, this->contactId);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1439,18 +1360,11 @@ namespace MSN {
     void Soap::parseAddContactToListResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
-        if(http_response_code == "301" )
-        {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
 
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[ADD_CONTACT_TO_LIST] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->addContactToList(this->tempPassport, this->tempList);
-            }
+        if(http_response_code == "301")
+        {
+            Soap *soapConnection = manageSoapRedirect(response1, ADD_CONTACT_TO_LIST);
+            soapConnection->addContactToList(this->tempPassport, this->tempList);
             return;
         }
 
@@ -1570,22 +1484,14 @@ namespace MSN {
     void Soap::parseRemoveContactFromListResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
-        if(http_response_code == "301" )
-        {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
 
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DEL_CONTACT_FROM_LIST] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->removeContactFromList(this->tempPassport, this->tempList);
-            }
+        if(http_response_code == "301")
+        {
+            Soap *soapConnection = manageSoapRedirect(response1, DEL_CONTACT_FROM_LIST);
+            soapConnection->removeContactFromList(this->tempPassport, this->tempList);
             return;
         }
 
-
         XMLNode version = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("Version");
         const char *ver = version.getText();
         if(ver)
@@ -1694,20 +1600,11 @@ namespace MSN {
         XMLNode response1 = XMLNode::parseString(response.c_str());
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[GET_LISTS] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->getLists(this->listInfo);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, GET_LISTS);
+            soapConnection->getLists(this->listInfo);
             return;
         }
 
-
         XMLNode Services = response1.getChildNode("soap:Envelope").getChildNode("soap:Body").getChildNode("FindMembershipResponse").getChildNode("FindMembershipResult").getChildNode("Services");
 
         int nServices = Services.nChildNode("Service");
@@ -1854,16 +1751,8 @@ namespace MSN {
         XMLNode response1 = XMLNode::parseString(response.c_str());
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[GET_ADDRESS_BOOK] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->getAddressBook(this->listInfo);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, GET_ADDRESS_BOOK);
+            soapConnection->getAddressBook(this->listInfo);
             return;
         }
 
@@ -2060,20 +1949,11 @@ namespace MSN {
         XMLNode response1 = XMLNode::parseString(response.c_str());
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[RETRIEVE_OIM] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->getOIM(this->oim_id, this->markAsRead);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, RETRIEVE_OIM);
+            soapConnection->getOIM(this->oim_id, this->markAsRead);
             return;
         }
 
-
         const char* msg = response1.getChildNode("soap:Envelope").getChildNode("soap:Body").getChildNode("GetMessageResponse").getChildNode("GetMessageResult").getText();
         if(msg)
         {
@@ -2145,18 +2025,11 @@ namespace MSN {
     void Soap::parseDeleteOIMResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
+
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[DELETE_OIM] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->deleteOIM(this->oim_id);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, DELETE_OIM);
+            soapConnection->deleteOIM(this->oim_id);
             return;
         }
 
@@ -2210,23 +2083,15 @@ namespace MSN {
     void Soap::parseGetMailDataResponse(std::string response)
     {
         XMLNode response1 = XMLNode::parseString(response.c_str());
-        if(http_response_code == "301" )
-        {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
 
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[RETRIEVE_OIM_MAIL_DATA] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->getMailData();
-            }
+        if(http_response_code == "301")
+        {
+            Soap *soapConnection = manageSoapRedirect(response1, RETRIEVE_OIM_MAIL_DATA);
+            soapConnection->getMailData();
             return;
         }
 
-
-            // oh my god! xml text as a field of a xml node! I cant believe it!
+        // oh my god! xml text as a field of a xml node! I cant believe it!
         std::string maildata = response1.getChildNode("soap:Envelope").getChildNode("soap:Body").getChildNode("GetMetadataResponse").getChildNode("MD").createXMLString(false);
         if(maildata.empty())
             return; // TODO - raise an error
@@ -2334,18 +2199,11 @@ namespace MSN {
         OIM oim = this->oim;
         // probably we need to generate a new lockkey
         XMLNode response1 = XMLNode::parseString(response.c_str());
-        if(http_response_code == "301" )
-        {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
 
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[GENERATE_LOCKKEY] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->generateLockkey(this->oim);
-            }
+        if(http_response_code == "301")
+        {
+            Soap *soapConnection = manageSoapRedirect(response1, GENERATE_LOCKKEY);
+            soapConnection->generateLockkey(this->oim);
             return;
         }
 
@@ -2463,18 +2321,11 @@ namespace MSN {
     {
         OIM oim = this->oim;
         XMLNode response1 = XMLNode::parseString(response.c_str());
-        if(http_response_code == "301" )
-        {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
 
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[SEND_OIM] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->sendOIM(this->oim, this->lockkey);
-            }
+        if(http_response_code == "301")
+        {
+            Soap *soapConnection = manageSoapRedirect(response1, SEND_OIM);
+            soapConnection->sendOIM(this->oim, this->lockkey);
             return;
         }
 
@@ -2561,16 +2412,8 @@ namespace MSN {
         XMLNode response1 = XMLNode::parseString(response.c_str());
         if(http_response_code == "301" )
         {
-            const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
-            if(preferredHostName)
-            {
-                Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
-
-                std::string newdomain(preferredHostName);
-                soapConnection->actionDomains[CHANGE_DISPLAYNAME] = newdomain;
-                soapConnection->setMBI(mbi);
-                soapConnection->changeDisplayName(this->tempDisplayName);
-            }
+            Soap *soapConnection = manageSoapRedirect(response1, CHANGE_DISPLAYNAME);
+            soapConnection->changeDisplayName(this->tempDisplayName);
             return;
         }
 
@@ -2598,7 +2441,7 @@ namespace MSN {
                 return;
 
             http_header_response = this->readBuffer.substr(0,this->readBuffer.find("\r\n\r\n") + 4);
-                Message::Headers headers = Message::Headers(http_header_response);
+            Message::Headers headers = Message::Headers(http_header_response);
             this->response_length = decimalFromString(headers["Content-Length"]);
 
             this->http_response_code = splitString(http_header_response.substr(0,http_header_response.find("\r\n"))," ")[1];
@@ -2683,6 +2526,34 @@ namespace MSN {
         delete this;
     }
 
+    Soap* Soap::manageSoapRedirect(XMLNode response1, soapAction action)
+    {
+        Soap *soapConnection = new Soap(notificationServer, sitesToAuthList);
+        Message::Headers headers = Message::Headers(http_header_response);
+        std::string newdomain;
+        std::string location = headers["Location"];
+
+        const char *preferredHostName = response1.getChildNode("soap:Envelope").getChildNode("soap:Header").getChildNode("ServiceHeader").getChildNode("PreferredHostName").getText();
+        if(preferredHostName)
+        {
+            std::string newdomain(preferredHostName);
+            soapConnection->actionDomains[action] = newdomain;
+        }
+
+        if (location.size())
+        {
+            std::string newurl1(location);
+            std::vector<std::string> a = splitString(newurl1, "/");
+            std::string newdomain = splitString(a[1], "/")[0];
+            soapConnection->actionDomains[action] = newdomain;
+            std::vector<std::string> postpath = splitString(newurl1, newdomain);
+            soapConnection->actionPOSTURLs[action] = postpath[1];
+        }
+        soapConnection->setMBI(mbi);
+
+        return soapConnection;
+    }
+
     void Soap::disconnect()
     {
     }
