reSIProcate/repro  9694
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
repro::RegSyncServer Class Reference

#include <RegSyncServer.hxx>

Inheritance diagram for repro::RegSyncServer:
Inheritance graph
[legend]
Collaboration diagram for repro::RegSyncServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RegSyncServer (resip::InMemorySyncRegDb *regDb, int port, resip::IpVersion version)
virtual ~RegSyncServer ()
virtual void sendResponse (unsigned int connectionId, unsigned int requestId, const resip::Data &responseData, unsigned int resultCode, const resip::Data &resultText)
virtual void sendRegistrationModifiedEvent (unsigned int connectionId, const resip::Uri &aor)
virtual void sendRegistrationModifiedEvent (unsigned int connectionId, const resip::Uri &aor, const resip::ContactList &contacts)

Protected Member Functions

virtual void handleRequest (unsigned int connectionId, unsigned int requestId, const resip::Data &request)
virtual void onAorModified (const resip::Uri &aor, const resip::ContactList &contacts)
virtual void onInitialSyncAor (unsigned int connectionId, const resip::Uri &aor, const resip::ContactList &contacts)

Private Member Functions

void handleInitialSyncRequest (unsigned int connectionId, unsigned int requestId, resip::XMLCursor &xml)
void streamContactInstanceRecord (std::stringstream &ss, const resip::ContactInstanceRecord &rec)

Private Attributes

resip::InMemorySyncRegDbmRegDb

Detailed Description

Definition at line 16 of file RegSyncServer.hxx.


Constructor & Destructor Documentation

RegSyncServer::RegSyncServer ( resip::InMemorySyncRegDb regDb,
int  port,
resip::IpVersion  version 
)

Definition at line 25 of file RegSyncServer.cxx.

                                                :
   XmlRpcServerBase(port, version),
   mRegDb(regDb)
{
   assert(mRegDb);
   mRegDb->setHandler(this);
}
RegSyncServer::~RegSyncServer ( ) [virtual]

Definition at line 35 of file RegSyncServer.cxx.

{
   mRegDb->setHandler(0);
}

Member Function Documentation

void RegSyncServer::handleInitialSyncRequest ( unsigned int  connectionId,
unsigned int  requestId,
resip::XMLCursor xml 
) [private]

Definition at line 116 of file RegSyncServer.cxx.

{
   InfoLog(<< "RegSyncServer::handleInitialSyncRequest");

   // Check for correct Version
   unsigned int version = 0;
   if(xml.firstChild())
   {
      if(isEqualNoCase(xml.getTag(), "request"))
      {
         if(xml.firstChild())
         {
            if(isEqualNoCase(xml.getTag(), "version"))
            {
               if(xml.firstChild())
               {
                  version = xml.getValue().convertUnsignedLong();
                  xml.parent();
               }
            }
            xml.parent();
         }
      }
      xml.parent();
   }

   if(version == REGSYNC_VERSION)
   {
      mRegDb->initialSync(connectionId);
      sendResponse(connectionId, requestId, Data::Empty, 200, "Initial Sync Completed.");
   }
   else
   {
      sendResponse(connectionId, requestId, Data::Empty, 505, "Version not supported.");
   }
}
void RegSyncServer::handleRequest ( unsigned int  connectionId,
unsigned int  requestId,
const resip::Data request 
) [protected, virtual]

Implements repro::XmlRpcServerBase.

Definition at line 89 of file RegSyncServer.cxx.

{
   DebugLog (<< "RegSyncServer::handleRequest:  connectionId=" << connectionId << ", requestId=" << requestId << ", request=" << request);

   try
   {
      ParseBuffer pb(request);
      XMLCursor xml(pb);

      if(isEqualNoCase(xml.getTag(), "InitialSync"))
      {
         handleInitialSyncRequest(connectionId, requestId, xml);
      }
      else 
      {
         WarningLog(<< "RegSyncServer::handleRequest: Received XML message with unknown method: " << xml.getTag());
         sendResponse(connectionId, requestId, Data::Empty, 400, "Unknown method");
      }
   }
   catch(resip::BaseException& e)
   {
      WarningLog(<< "RegSyncServer::handleRequest: ParseException: " << e);
      sendResponse(connectionId, requestId, Data::Empty, 400, "Parse error");
   }
}
void RegSyncServer::onAorModified ( const resip::Uri aor,
const resip::ContactList contacts 
) [protected, virtual]

Implements resip::InMemorySyncRegDbHandler.

Definition at line 192 of file RegSyncServer.cxx.

{
   sendRegistrationModifiedEvent(0, aor, contacts);
}
void RegSyncServer::onInitialSyncAor ( unsigned int  connectionId,
const resip::Uri aor,
const resip::ContactList contacts 
) [protected, virtual]

Implements resip::InMemorySyncRegDbHandler.

Definition at line 198 of file RegSyncServer.cxx.

{
   sendRegistrationModifiedEvent(connectionId, aor, contacts);
}
void RegSyncServer::sendRegistrationModifiedEvent ( unsigned int  connectionId,
const resip::Uri aor 
) [virtual]

Definition at line 54 of file RegSyncServer.cxx.

{
   ContactList contacts;

   mRegDb->getContacts(aor, contacts);
   sendRegistrationModifiedEvent(connectionId, aor, contacts);
}
void RegSyncServer::sendRegistrationModifiedEvent ( unsigned int  connectionId,
const resip::Uri aor,
const resip::ContactList contacts 
) [virtual]

Definition at line 63 of file RegSyncServer.cxx.

{
   std::stringstream ss;
   bool infoFound = false;

   ss << "<reginfo>" << Symbols::CRLF;
   ss << "   <aor>" << Data::from(aor).xmlCharDataEncode() << "</aor>" << Symbols::CRLF;
   ContactList::const_iterator cit = contacts.begin();
   for(; cit != contacts.end(); cit++)
   {
      const ContactInstanceRecord& rec = *cit;
      if(!rec.mReceivedFrom.onlyUseExistingConnection)
      {
          streamContactInstanceRecord(ss, rec);
          infoFound = true;
      }
   }
   ss << "</reginfo>" << Symbols::CRLF;

   if(infoFound)
   {
      sendEvent(connectionId, ss.str().c_str());
   }
}
void RegSyncServer::sendResponse ( unsigned int  connectionId,
unsigned int  requestId,
const resip::Data responseData,
unsigned int  resultCode,
const resip::Data resultText 
) [virtual]

Definition at line 41 of file RegSyncServer.cxx.

{
   std::stringstream ss;
   ss << Symbols::CRLF << responseData << "    <Result Code=\"" << resultCode << "\"";
   ss << ">" << resultText.xmlCharDataEncode() << "</Result>" << Symbols::CRLF;
   XmlRpcServerBase::sendResponse(connectionId, requestId, ss.str().c_str(), resultCode >= 200 /* isFinal */);
}
void RegSyncServer::streamContactInstanceRecord ( std::stringstream &  ss,
const resip::ContactInstanceRecord rec 
) [private]

Definition at line 154 of file RegSyncServer.cxx.

{
    UInt64 now = Timer::getTimeSecs();

    ss << "   <contactinfo>" << Symbols::CRLF;
    ss << "      <contacturi>" << Data::from(rec.mContact.uri()).xmlCharDataEncode() << "</contacturi>" << Symbols::CRLF;
    // If contact is expired or removed, then pass expires time as 0, otherwise send number of seconds until expirey
    ss << "      <expires>" << (((rec.mRegExpires == 0) || (rec.mRegExpires <= now)) ? 0 : (rec.mRegExpires-now)) << "</expires>" << Symbols::CRLF;
    ss << "      <lastupdate>" << now-rec.mLastUpdated << "</lastupdate>" << Symbols::CRLF;
    if(rec.mReceivedFrom.getPort() != 0)
    {
        resip::Data binaryFlowToken;
        Tuple::writeBinaryToken(rec.mReceivedFrom,binaryFlowToken);            
        ss << "      <receivedfrom>" << binaryFlowToken.base64encode() << "</receivedfrom>" << Symbols::CRLF;
    }
    if(rec.mPublicAddress.getType() != UNKNOWN_TRANSPORT)
    {
        resip::Data binaryFlowToken;
        Tuple::writeBinaryToken(rec.mPublicAddress,binaryFlowToken);            
        ss << "      <publicaddress>" << binaryFlowToken.base64encode() << "</publicaddress>" << Symbols::CRLF;
    }
    NameAddrs::const_iterator naIt = rec.mSipPath.begin();
    for(; naIt != rec.mSipPath.end(); naIt++)
    {
        ss << "      <sippath>" << Data::from(naIt->uri()).xmlCharDataEncode() << "</sippath>" << Symbols::CRLF;
    }
    if(!rec.mInstance.empty())
    {
        ss << "      <instance>" << rec.mInstance.xmlCharDataEncode() << "</instance>" << Symbols::CRLF;
    }
    if(rec.mRegId != 0)
    {
        ss << "      <regid>" << rec.mRegId << "</regid>" << Symbols::CRLF;
    }
    ss << "   </contactinfo>" << Symbols::CRLF;
}

Member Data Documentation

Definition at line 46 of file RegSyncServer.hxx.


The documentation for this class was generated from the following files: