Пример #1
0
// Set the next local CSeq for a dialog.
UtlBoolean SipDialogMgr::setNextLocalCseq(const UtlString& dialogHandleString,
                                          int nextLocalCseq)
{
   UtlBoolean ret;

   lock();

   // Find the dialog.
   SipDialog* dialog = findDialog(dialogHandleString,
                                  FALSE, // If established only want exact match  dialogs 
                                  TRUE); // If message is from a prior transaction
                                         // when the dialog was in an early state
                                         // allow it to match an established 
                                         // dialog

   if (dialog)
   {
      // If we could find the dialog, set its next local CSeq.
      dialog->setLastLocalCseq(nextLocalCseq);
      ret = TRUE;
   }
   else
   {
      ret = FALSE;
   }

   unlock();

   return ret;
}
Пример #2
0
UtlBoolean SipDialogMgr::getEstablishedDialogHandleFor(const char* earlyDialogHandle,
                                                       UtlString& establishedDialogHandle)
{
    UtlBoolean foundDialog = FALSE;
    UtlString handle(earlyDialogHandle ? earlyDialogHandle : "");
    lock();
    // Looking for an dialog that matches this earlyHandle, if there
    // is not an exact match see if there is an established dialog
    // that matches
    SipDialog* dialog = findDialog(handle,
                                   FALSE, // if established, match early dialog
                                   TRUE); // if early, match established dialog
    if(dialog && !dialog->isInitialDialog())
    {
        dialog->getDialogHandle(establishedDialogHandle);
        foundDialog = TRUE;
    }
    else
    {
        establishedDialogHandle = "";
    }
    unlock();

    return(foundDialog);

}
Пример #3
0
UtlBoolean SipDialogMgr::initialDialogExistsFor(const char* establishedDialogHandle)
{
    UtlBoolean foundDialog = FALSE;
    UtlString handle(establishedDialogHandle ? establishedDialogHandle : "");

    // If we have an established dialog handle
    if(!SipDialog::isInitialDialog(handle))
    {
        lock();
        // Looking for an dialog that matches this handle, if there
        // is not an exact match see if there is an early dialog
        // that matches the given presumably established dialog handle
        SipDialog* dialog = findDialog(handle,
                                       TRUE, // if established, match early dialog
                                       FALSE); // if early, match established dialog

        if(dialog && !dialog->isInitialDialog())
        {
            foundDialog = TRUE;
        }
        unlock();
    }

    return(foundDialog);
}
Пример #4
0
UtlBoolean SipDialogMgr::isNewRemoteTransaction(const SipMessage& message)
{
    UtlBoolean matchesTransaction = FALSE;
    UtlString handle;
    SipDialog::getDialogHandle(message, handle);

    UtlString callId;
    UtlString fromTag;
    UtlString toTag;
    Url fromField;
    Url toField;
    message.getFromUrl(fromField);
    message.getToUrl(toField);
    message.getCallIdField(callId);
    fromField.getFieldParameter("tag", fromTag);
    toField.getFieldParameter("tag", toTag);

    lock();
    // Looking for any dialog that matches this handle
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established, match early dialog
                                   TRUE); // if early, match established dialog

    if(dialog && 
       dialog->isTransactionRemotelyInitiated(callId, fromTag, toTag) &&
       dialog->isNextRemoteCseq(message))
    {
        matchesTransaction = TRUE;
    }

    unlock();
    
    return(matchesTransaction);
}
Пример #5
0
OsStatus XCpCall::handleDropConnection(const AcDropConnectionMsg& rMsg)
{
   if (m_pSipConnection)
   {
      SipDialog sipDialog;
      rMsg.getSipDialog(sipDialog);
      UtlBoolean resFound = FALSE;
      // find connection by sip dialog if call-id is not null
      OsPtrLock<XSipConnection> ptrLock;
      if (sipDialog.getCallId().isNull())
      {
         resFound = getConnection(ptrLock);
      }
      else
      {
         resFound = findConnection(sipDialog, ptrLock);
      }
      if (resFound)
      {
         return ptrLock->dropConnection();
      }
   }
   else
   {
      // we don't have any connection
      requestCallDestruction();
      return OS_SUCCESS;
   }

   return OS_NOT_FOUND;
}
Пример #6
0
UtlBoolean SipDialogMgr::isLastLocalTransaction(const SipMessage& message, 
                                                const char* dialogHandle)
{
    UtlBoolean matchesTransaction = FALSE;
    UtlString handle(dialogHandle ? dialogHandle : "");
    // If the dialog handle was not set, get it from the message
    if(handle.isNull())
    {
        message.getDialogHandle(handle);
    }

    UtlString callId;
    UtlString fromTag;
    UtlString toTag;
    SipDialog::parseHandle(handle, callId, fromTag, toTag);

    lock();
    // Looking for any dialog that matches this handle
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established, match early dialog
                                   TRUE); // if early, match established dialog

    if(dialog && 
       dialog->isTransactionLocallyInitiated(callId, fromTag, toTag) &&
       dialog->isSameLocalCseq(message))
    {
        matchesTransaction = TRUE;
    }

    unlock();
    
    return(matchesTransaction);
}
OsStatus CpNotificationRegister::unsubscribe(CP_NOTIFICATION_TYPE notificationType,
                                             const SipDialog& callbackSipDialog)
{
   OsStatus result = OS_FAILED;

   UtlInt key((int)notificationType);
   UtlSList* pDialogList = dynamic_cast<UtlSList*>(m_register.findValue(&key));
   if (!pDialogList)
   {
      return OS_SUCCESS;
   }

   if (pDialogList)
   {
      UtlSListIterator itor(*pDialogList);

      while (itor())
      {
         SipDialog* pSipDialog = dynamic_cast<SipDialog*>(itor.item());
         if (pSipDialog && pSipDialog->compareDialogs(callbackSipDialog) != SipDialog::DIALOG_MISMATCH)
         {
            pDialogList->destroy(pSipDialog);
         }
      }

      result = OS_SUCCESS;
   }

   return result;
}
Пример #8
0
void startUnregister(const FullMobileId &msid, L3LogicalChannel *chan)
{
	LOG(DEBUG) <<LOGVAR(msid);
	SipDialog *registrar = getRegistrar();
	SipMessage *request = registrar->makeRegisterMsg(SIPDTUnregister,chan,"",msid,NULL);
	SipRegisterTU *reg = new SipRegisterTU(SipRegisterTU::KindUnRegister,registrar,(TranEntryId)0,request);
	delete request;		// sctInitRegisterTransaction made a copy.  Kind of wasteful.
	reg->sctStart();
}
Пример #9
0
void startRegister(TranEntryId tid, const FullMobileId &msid, const string rand, const string sres, L3LogicalChannel *chan) 		// msid is imsi and/or tmsi
{
	LOG(DEBUG) <<LOGVAR(msid)<<LOGVAR(rand)<<LOGVAR(sres);
	// Kinda dumb to fish out the branch from the request, but its ok.
	SipDialog *registrar = getRegistrar();
	SipMessage *request = registrar->makeRegisterMsg(SIPDTRegister,chan,rand,msid,sres.c_str());
	SipRegisterTU *reg = new SipRegisterTU(SipRegisterTU::KindRegister,registrar,tid,request);
	delete request;		// sctInitRegisterTransaction made a copy.  Kind of wasteful.
	reg->sctStart();
}
Пример #10
0
SipDialog* SipDialogMgr::findDialog(UtlString& callId,
                                    UtlString& localTag,
                                    UtlString& remoteTag,
                                    UtlBoolean ifHandleEstablishedFindEarlyDialog,
                                    UtlBoolean ifHandleEarlyFindEstablishedDialog)
{
    SipDialog* dialog = NULL;
    UtlHashBagIterator iterator(mDialogs, &callId);

    // Look at all the dialogs with the same call-id
    while((dialog = (SipDialog*) iterator()))
    {
        // Check for exact match on the dialog handle
        if(dialog->isSameDialog(callId,localTag, remoteTag))
        {
            break;
        }
    }

    // Check if this established dialog handle matches an early dialog
    if(!dialog && ifHandleEstablishedFindEarlyDialog)
    {
        iterator.reset();
        while((dialog = (SipDialog*) iterator()))
        {
            // Check for match on the early dialog for the handle
            if(dialog->isEarlyDialogFor(callId, localTag, remoteTag))
            {
                break;
            }
        }
    }

    // Check if this early dialog handle matches an established dialog
    if(!dialog && ifHandleEarlyFindEstablishedDialog)
    {
        iterator.reset();
        while((dialog = (SipDialog*) iterator()))
        {
            // Check for match on the early dialog for the handle
            if (dialog->wasEarlyDialogFor(callId, localTag, remoteTag))
            {
                break;
            }
        }
    }

    return(dialog);
}
Пример #11
0
void XCpCall::destroySipConnection()
{
   SipDialog sipDialog;
   // get sip dialog of our single connection
   {
      OsLock lock(m_memberMutex);
      if (m_pSipConnection)
      {
         m_pSipConnection->getSipDialog(sipDialog);
      }
   }

   if (!sipDialog.isNull())
   {
      destroySipConnection(sipDialog);
   }
}
Пример #12
0
UtlBoolean SipDialogMgr::setNextLocalTransactionInfo(SipMessage& request,
                                                     const char* method,
                                                     const char* dialogHandle)
{
    UtlBoolean requestSet = FALSE;
    UtlString dialogHandleString(dialogHandle ? dialogHandle : "");
    if(dialogHandleString.isNull())
    {
       SipDialog::getDialogHandle(request, dialogHandleString);
    }

    lock();
    SipDialog* dialog = findDialog(dialogHandleString,
                                   FALSE, // If established only want exact match  dialogs 
                                   TRUE); // If message is from a prior transaction
                                          // when the dialog was in an early state
                                          // allow it to match and established 
                                          // dialog
    if(dialog)
    {
        dialog->setRequestData(request, method);
        requestSet = TRUE;

#ifdef TEST_PRINT
        UtlString dialogDump;
        dialog->toString(dialogDump);
        printf("SipDialogMgr::setNextLocalTransactionInfo dialog:\n%s\n",
               dialogDump.data());
#endif

    }
    else
    {
        OsSysLog::add(FAC_SIP,
                      PRI_WARNING, 
                      "SipDialogMgr::setNextLocalTransactionInfo could not find dialog with handle %s",
                      dialogHandle);
    }

    unlock();

    return(requestSet);
}
Пример #13
0
enum SipDialogMgr::transactionSequence
    SipDialogMgr::isNewRemoteTransaction(const SipMessage& message)
{
    enum transactionSequence ordering;
    UtlString handle;
    message.getDialogHandle(handle);

    UtlString callId;
    UtlString fromTag;
    UtlString toTag;
    SipDialog::parseHandle(handle, callId, fromTag, toTag);

    lock();
    // Looking for any dialog that matches this handle
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established, match early dialog
                                   TRUE); // if early, match established dialog

    if (dialog && 
        dialog->isTransactionRemotelyInitiated(callId, fromTag, toTag))
    {
       int messageCSeq;
       message.getCSeqField(&messageCSeq, NULL);
       int lastRemoteCSeq = dialog->getLastRemoteCseq();
       ordering =
          messageCSeq < lastRemoteCSeq ? OUT_OF_ORDER :
          /** If this message was an exact duplicate of a previous message
           *  (with the same CSeq and branch parameter), it would have been
           *  absorbed earlier in processing.  So we know the branch parameter
           *  is different without having to remember the previous value.
           */
          messageCSeq == lastRemoteCSeq ? LOOPED :
          IN_ORDER;
    }
    else
    {
       ordering = NO_DIALOG;
    }

    unlock();
    
    return ordering;
}
Пример #14
0
UtlBoolean SipDialogMgr::setNextLocalTransactionInfo(SipMessage& request,
                                                     const char* method,
                                                     const char* dialogHandle)
{
    UtlBoolean requestSet = FALSE;
    UtlString dialogHandleString(dialogHandle ? dialogHandle : "");
    if(dialogHandleString.isNull())
    {
        request.getDialogHandle(dialogHandleString);
    }

    lock();
    SipDialog* dialog = findDialog(dialogHandleString,
                                   FALSE, // If established only want exact match dialogs
                                   TRUE); // If message is from a prior transaction
                                          // when the dialog was in an early state
                                          // allow it to match an established
                                          // dialog
    if(dialog)
    {
        dialog->setRequestData(request, method);
        requestSet = TRUE;

#ifdef TEST_PRINT
        UtlString dialogDump;
        dialog->toString(dialogDump);
        OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMgr::setNextLocalTransactionInfo dialog: '%s'",
                      dialogDump.data());
#endif
    }
    else
    {
       OsSysLog::add(FAC_SIP, PRI_ERR, "SipDialogMgr::setNextLocalTransactionInfo dialog not found for handle '%s'",
                     dialogHandle);

       if (OsSysLog::willLog(FAC_SIP, PRI_DEBUG))
       {
          SipDialog* dialog;
          UtlHashBagIterator iterator(mDialogs);
          
          while ((dialog = (SipDialog*) iterator()))
          {
             UtlString callId, localTag, remoteTag;
             dialog->getCallId(callId);
             dialog->getLocalTag(localTag);
             dialog->getRemoteTag(remoteTag);
             OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMgr::setNextLocalTransactionInfo dialog call-id = '%s', local tag = '%s', remote tag = '%s'",
                           callId.data(), localTag.data(), remoteTag.data());
          }
       }
    }

    unlock();

    return(requestSet);
}
Пример #15
0
UtlBoolean SipDialogMgr::initialDialogExists(const char* dialogHandle)
{
    UtlBoolean foundDialog = FALSE;
    UtlString handle(dialogHandle ? dialogHandle : "");
    lock();
    // Looking for an dialog that matches this handle, if there
    // is not an exact match see if there is an early dialog
    // that matches the given presumably established dialog handle
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established, match early dialog
                                   FALSE); // if early, match established dialog

    // We only want early dialogs
    if(dialog && dialog->isInitialDialog())
    {
        foundDialog = TRUE;
    }

    unlock();

    return(foundDialog);
}
Пример #16
0
UtlBoolean SipDialogMgr::updateDialog(const SipMessage& message, 
                                      const char* dialogHandle)
{
    UtlString handle(dialogHandle ? dialogHandle : "");
    // If the dialog handle was not set, get it from the message
    if(handle.isNull())
    {
       SipDialog::getDialogHandle(message, handle);
    }

    lock();
    
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established handle, find early dialog
                                   FALSE); // do not want established dialogs for early handle
    if(dialog)
    {
#ifdef TEST_PRINT
        UtlString dialogDump;
        dialog->toString(dialogDump);
        printf("SipDialogMgr::updateDialog dialog before:\n%s\n",
               dialogDump.data());
#endif

        dialog->updateDialog(message);

#ifdef TEST_PRINT
        dialog->toString(dialogDump);
        printf("SipDialogMgr::updateDialog dialog after:\n%s\n",
               dialogDump.data());
#endif
    }


    unlock();

    return(dialog != NULL);
}
Пример #17
0
int SipDialogMgr::toString(UtlString& dumpString)
{
    int dialogCount = 0;
    dumpString = "";
    UtlString oneDialogDump;
    SipDialog* dialog = NULL;

    UtlHashBagIterator iterator(mDialogs);
    // Look at all the dialogs with the same call-id
    while((dialog = (SipDialog*) iterator()))
    {
        if(dialogCount)
        {
            dumpString.append('\n');
        }
        dialog->toString(oneDialogDump);
        dumpString.append(oneDialogDump);

        dialogCount++;
    }

    return(dialogCount);
}
Пример #18
0
UtlBoolean SipDialogMgr::getInitialDialogHandleFor(const char* establishedDialogHandle, 
                                                   UtlString& earlyDialogHandle)
{
    UtlBoolean foundDialog = FALSE;
    UtlString handle(establishedDialogHandle ? establishedDialogHandle : "");

    lock();
    SipDialog* dialog = findDialog(handle,
                                   TRUE, // if established, match early dialog
                                   FALSE); // if early, match established dialog
    if(dialog)
    {
        dialog->getInitialDialogHandle(earlyDialogHandle);
        foundDialog = TRUE;
    }
    else
    {
        earlyDialogHandle = "";
    }
    unlock();

    return(foundDialog);
}
Пример #19
0
void XCpCall::createSipConnection(const SipDialog& sipDialog, const UtlString& sFullLineUrl)
{
   UtlBoolean bAdded = FALSE;
   {
      OsLock lock(m_memberMutex);
      if (!m_pSipConnection)
      {
         m_pSipConnection = new XSipConnection(m_sId, sipDialog, m_rSipUserAgent, m_rCallControl, sFullLineUrl, m_sBindIpAddress,
            m_sessionTimerExpiration, m_sessionTimerRefresh,
            m_updateSetting, m_100relSetting, m_sdpOfferingMode, m_inviteExpiresSeconds, this, this, m_natTraversalConfig,
            m_pCallEventListener, m_pInfoStatusEventListener, m_pInfoEventListener, m_pSecurityEventListener, m_pMediaEventListener,
            m_pRtpRedirectEventListener);
         bAdded = TRUE;
      }
   }

   if (bAdded)
   {
      onConnectionAddded(sipDialog.getCallId());
   }
}
Пример #20
0
void XCpCall::destroySipConnection(const SipDialog& sSipDialog)
{
   UtlString sSipCallId;
   {
      // check that we really have connection with given sip dialog
      OsLock lock(m_memberMutex);
      if (m_pSipConnection && m_pSipConnection->compareSipDialog(sSipDialog) != SipDialog::DIALOG_MISMATCH)
      {
         // dialog matches
         sSipDialog.getCallId(sSipCallId);
         m_pSipConnection->acquireExclusive();
         delete m_pSipConnection;
         m_pSipConnection = NULL;
      }
   }

   if (!sSipCallId.isNull())
   {
      // we destroyed some connection, notify call stack
      onConnectionRemoved(sSipCallId);
   }
}
Пример #21
0
UtlBoolean DialogEventPublisher::handleMessage(OsMsg& rMsg)
{
   SipDialog sipDialog;
   UtlString sipDialogContent;
   Url requestUrl;
   UtlString entity;
   UtlString* pEntity;
   char dialogId[10];
   SipDialogEvent* pThisCall;
   Dialog* pDialog;
   UtlString localTag, remoteTag;
   Url localIdentity, remoteIdentity;
   Url localTarget, remoteTarget;
   UtlString identity, displayName;
   OsTime receivedTime;
   int numOldContents;
   HttpBody* oldContent[1];

   int length;
   UtlString dialogEvent;
   
   // React to telephony events
   if(rMsg.getMsgSubType()== TaoMessage::EVENT)
   {
      TaoMessage* taoMessage = (TaoMessage*)&rMsg;

      int taoEventId = taoMessage->getTaoObjHandle();
      UtlString argList(taoMessage->getArgList());
      TaoString arg(argList, TAOMESSAGE_DELIMITER);

#ifdef DEBUGGING
      dumpTaoMessageArgs(taoEventId, arg) ;
#endif        
      UtlBoolean localConnection = atoi(arg[TAO_OFFER_PARAM_LOCAL_CONNECTION]);
      UtlString  callId = arg[TAO_OFFER_PARAM_CALLID] ;
      UtlString  address = arg[TAO_OFFER_PARAM_ADDRESS] ;

      switch (taoEventId) 
      {
         case PtEvent::CONNECTION_OFFERED:

            mpCallManager->getSipDialog(callId, address, sipDialog);
#ifdef DEBUGGING            
            sipDialog.toString(sipDialogContent);
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: sipDialog = %s", 
                          sipDialogContent.data());
#endif            
            sipDialog.getRemoteRequestUri(entity);
            
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: Call arrived: callId %s address %s requestUrl %s", 
                          callId.data(), address.data(), entity.data());

            if (entity.isNull())
            {
               OsSysLog::add(FAC_SIP, PRI_WARNING, "DialogEventPublisher:: Call arrived: callId %s address %s without requestUrl", 
                             callId.data(), address.data());
               break;
            }
            else
            {
               requestUrl = Url(entity);
               requestUrl.getIdentity(entity);
            }
               
            // Create a dialog event if has not been created yet
            pThisCall = (SipDialogEvent *) mCalls.findValue(&entity);
            if (pThisCall == NULL)
            {
               pEntity = new UtlString(entity);
               pThisCall = new SipDialogEvent(STATE, entity);
               mCalls.insertKeyAndValue(pEntity, pThisCall);
               OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: insert DialogEvent object %p to the list",
                             pThisCall);
            }

            // Create the dialog element
            sipDialog.getLocalField(localIdentity);
            localIdentity.getFieldParameter("tag", localTag);
   
            sipDialog.getRemoteField(remoteIdentity);
            remoteIdentity.getFieldParameter("tag", remoteTag);
               
            sprintf(dialogId, "%ld", mDialogId);
            mDialogId++;

            pDialog = new Dialog(dialogId, callId, localTag, remoteTag, "recipient");
            pDialog->setState(STATE_EARLY, NULL, NULL);
   
            localIdentity.getIdentity(identity);
            localIdentity.getDisplayName(displayName);
            pDialog->setLocalIdentity(identity, displayName);
   
            remoteIdentity.getIdentity(identity);
            remoteIdentity.getDisplayName(displayName);
            pDialog->setRemoteIdentity(identity, displayName);
   
            sipDialog.getLocalContact(localTarget);
            pDialog->setLocalTarget(localTarget.toString());
   
            sipDialog.getRemoteContact(remoteTarget);
            pDialog->setRemoteTarget(remoteTarget.toString());
               
            pDialog->setDuration(OsDateTime::getSecsSinceEpoch());
   
            pThisCall->insertDialog(pDialog);
   
            // Insert it into the active call list
            pThisCall->buildBody();

            // Send the content to the subscribe server
            if (!mpSipPublishContentMgr->publish(entity.data(), DIALOG_EVENT_TYPE, DIALOG_EVENT_TYPE, 1, (HttpBody**)&pThisCall, 1, numOldContents, oldContent))
            {
               pThisCall->getBytes(&dialogEvent, &length);
               OsSysLog::add(FAC_SIP, PRI_ERR, "DialogEventPublisher:: Call arrived - DialogEvent %s\n was not successfully published to the subscribe server",
                             dialogEvent.data());
            }
                        
            break;

         case PtEvent::CONNECTION_ESTABLISHED:
            if (localConnection) 
            {
               mpCallManager->getSipDialog(callId, address, sipDialog);
#ifdef DEBUGGING            
               sipDialog.toString(sipDialogContent);
               OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: sipDialog = %s", 
                             sipDialogContent.data());
#endif            
               sipDialog.getRemoteRequestUri(entity);

               OsSysLog::add(FAC_SIP, PRI_DEBUG, "Call connected: callId %s address %s with request %s",
                             callId.data(), address.data(), entity.data());

               if (entity.isNull())
               {
                  OsSysLog::add(FAC_SIP, PRI_WARNING, "DialogEventPublisher:: Call connected: callId %s address %s without requestUrl", 
                                callId.data(), address.data());
                  break;
               }
               else
               {
                  requestUrl = Url(entity);
                  requestUrl.getIdentity(entity);
               }
               
               pThisCall = (SipDialogEvent *) mCalls.findValue(&entity);
               if (pThisCall == NULL)
               {
                  pEntity = new UtlString(entity);
                  pThisCall = new SipDialogEvent(STATE, entity);
   
                  // Insert it into the active call list
                  mCalls.insertKeyAndValue(pEntity, pThisCall);
               }
               
               // Get the new callId because it might be changed
               sipDialog.getCallId(callId);

               pDialog = pThisCall->getDialog(callId);
               // Update the dialog content if exist
               if (pDialog)
               {
                  sipDialog.getLocalField(localIdentity);
                  localIdentity.getFieldParameter("tag", localTag);
   
                  sipDialog.getRemoteField(remoteIdentity);
                  remoteIdentity.getFieldParameter("tag", remoteTag);
               
                  pDialog->setTags(localTag, remoteTag);
   
                  sipDialog.getLocalContact(localTarget);
                  pDialog->setLocalTarget(localTarget.toString());
   
                  sipDialog.getRemoteContact(remoteTarget);
                  pDialog->setRemoteTarget(remoteTarget.toString());
   
                  pDialog->setState(STATE_CONFIRMED, NULL, NULL);
               }
               else
               {
                  // Create a new dialog element
                  sipDialog.getLocalField(localIdentity);
                  localIdentity.getFieldParameter("tag", localTag);
   
                  sipDialog.getRemoteField(remoteIdentity);
                  remoteIdentity.getFieldParameter("tag", remoteTag);
               
                  sprintf(dialogId, "%ld", mDialogId);
                  mDialogId++;
   
                  pDialog = new Dialog(dialogId, callId, localTag, remoteTag, "recipient");
                  pDialog->setState(STATE_CONFIRMED, NULL, NULL);
   
                  localIdentity.getIdentity(identity);
                  localIdentity.getDisplayName(displayName);
                  pDialog->setLocalIdentity(identity, displayName);
   
                  remoteIdentity.getIdentity(identity);
                  remoteIdentity.getDisplayName(displayName);
                  pDialog->setRemoteIdentity(identity, displayName);
   
                  sipDialog.getLocalContact(localTarget);
                  pDialog->setLocalTarget(localTarget.toString());
   
                  sipDialog.getRemoteContact(remoteTarget);
                  pDialog->setRemoteTarget(remoteTarget.toString());
   
                  pDialog->setDuration(OsDateTime::getSecsSinceEpoch());
   
                  pThisCall->insertDialog(pDialog);
               }
                   
               pThisCall->buildBody();

               // Publish the content to the subscribe server
               if (!mpSipPublishContentMgr->publish(entity.data(), DIALOG_EVENT_TYPE, DIALOG_EVENT_TYPE, 1, (HttpBody**)&pThisCall, 1, numOldContents, oldContent))
               {
                  pThisCall->getBytes(&dialogEvent, &length);
                  OsSysLog::add(FAC_SIP, PRI_ERR, "DialogEventPublisher:: Call connected - DialogEvent %s\n was not successfully published to the subscribe server",
                                dialogEvent.data());
               }
            }

            break;
            
         case PtEvent::CONNECTION_DISCONNECTED:
            if (!localConnection) 
            {
               mpCallManager->getSipDialog(callId, address, sipDialog);
#ifdef DEBUGGING            
               sipDialog.toString(sipDialogContent);
               OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: sipDialog = %s", 
                             sipDialogContent.data());
#endif            
               sipDialog.getLocalContact(requestUrl);
               requestUrl.getIdentity(entity);

               OsSysLog::add(FAC_SIP, PRI_DEBUG, "Call dropped: %s address %s with entity %s",
                             callId.data(), address.data(), entity.data());

               if (entity.isNull())
               {
                  OsSysLog::add(FAC_SIP, PRI_WARNING, "DialogEventPublisher:: Call dropped: callId %s address %s without requestUrl", 
                                callId.data(), address.data());
                  break;
               }
               
               // Get the new callId because it might be changed
               sipDialog.getCallId(callId);

               // Remove the call from the pool and clean up the call
               pThisCall = (SipDialogEvent *) mCalls.findValue(&entity);
               if (pThisCall)
               {
                  pDialog = pThisCall->getDialog(callId);
                  if (pDialog)
                  {
                     pDialog->setState(STATE_TERMINATED, NULL, NULL);
                   
                     pThisCall->buildBody();

                     // Publish the content to the subscribe server
                     if (!mpSipPublishContentMgr->publish(entity.data(), DIALOG_EVENT_TYPE, DIALOG_EVENT_TYPE, 1, (HttpBody**)&pThisCall, 1, numOldContents, oldContent))
                     {
                        pThisCall->getBytes(&dialogEvent, &length);
                        OsSysLog::add(FAC_SIP, PRI_ERR, "DialogEventPublisher:: Call dropped - DialogEvent %s\n was not successfully published to the subscribe server",
                                      dialogEvent.data());
                     }
                       
                     // Remove the dialog from the dialog event package
                     pDialog = pThisCall->removeDialog(pDialog);
                     delete pDialog;
                  }
                  
                  if (pThisCall->isEmpty())
                  {
                     // Unpublisher the content from the subscribe server
                     if (!mpSipPublishContentMgr->unpublish(entity.data(), DIALOG_EVENT_TYPE, DIALOG_EVENT_TYPE, 1, numOldContents, oldContent))
                     {
                        pThisCall->getBytes(&dialogEvent, &length);
                        OsSysLog::add(FAC_SIP, PRI_ERR, "DialogEventPublisher:: Call dropped - DialogEvent %s\n was not successfully unpublished to the subscribe server",
                                      dialogEvent.data());
                     }
                     
                     UtlContainable *foundValue;
                     mCalls.removeKeyAndValue(pEntity, foundValue);
                     if (foundValue)
                     {
                        OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher:: remove DialogEvent object %p from the list",
                                      pThisCall);
                        pThisCall = (SipDialogEvent *) foundValue;
                        delete pThisCall;
                        delete pEntity;
                     }
                  }
               }
               else
               {
                  OsSysLog::add(FAC_SIP, PRI_ERR, "DialogEventPublisher:: Call dropped - no entity %s founded in the active call list",
                                entity.data());
               }
            }

            break;
            
         case PtEvent::CONNECTION_FAILED:
            OsSysLog::add(FAC_SIP, PRI_WARNING, "Connection failed on call: %s", callId.data());

            break;
      }
   }
   return(TRUE);
}