예제 #1
0
Dialog* SipDialogEvent::getDialogByDialogId(UtlString& dialogId)
{
   mLock.acquire();
   UtlSListIterator dialogIterator(mDialogs);
   Dialog* pDialog;
   UtlString foundDialogId, foundCallId, foundLocalTag, foundRemoteTag,
      foundDirection;
   while ((pDialog = (Dialog *) dialogIterator()))
   {
      pDialog->getDialog(foundDialogId,
                         foundCallId,
                         foundLocalTag,
                         foundRemoteTag,
                         foundDirection);

      if (foundDialogId.compareTo(dialogId) == 0)
      {
         Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                       "SipDialogEvent::getDialog found Dialog = %p for dialogId = '%s'",
                       pDialog, dialogId.data());

         mLock.release();
         return pDialog;
      }
   }

   Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                 "SipDialogEvent::getDialog could not find the Dialog for dialogId = '%s'",
                 dialogId.data());
   mLock.release();
   return NULL;
}
예제 #2
0
Dialog* SipDialogEvent::getDialog(UtlString& callId,
                                  UtlString& localTag,
                                  UtlString& remoteTag)
{
   mLock.acquire();
   UtlSListIterator dialogIterator(mDialogs);
   Dialog* pDialog;
   UtlString foundDialogId, foundCallId, foundLocalTag, foundRemoteTag,
      foundDirection;
   while ((pDialog = (Dialog *) dialogIterator()))
   {
      pDialog->getDialog(foundDialogId,
                         foundCallId,
                         foundLocalTag,
                         foundRemoteTag,
                         foundDirection);

      if (foundCallId.compareTo(callId) == 0 &&
          foundLocalTag.compareTo(localTag) == 0 &&
          (foundRemoteTag.isNull() ||
           foundRemoteTag.compareTo(remoteTag) == 0))
      {
         Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                       "SipDialogEvent::getDialog found Dialog = %p for callId = '%s', local tag = '%s', remote tag = '%s'",
                       pDialog,
                       callId.data(), localTag.data(), remoteTag ? remoteTag.data() : "(none)");

         mLock.release();
         return pDialog;
      }
   }

   Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                 "SipDialogEvent::getDialog could not find the Dialog for callId = '%s', local tag = '%s', remote tag = '%s'",
                 callId.data(),
                 localTag ? localTag.data() : "(none)",
                 remoteTag ? remoteTag.data() : "(none)");
   mLock.release();
   return NULL;
}
예제 #3
0
void SipDialogEvent::buildBody(int* version) const
{
   UtlString dialogEvent;
   UtlString singleLine;

   // Construct the xml document of dialog event
   dialogEvent = UtlString(XML_VERSION_1_0);

   // Dialog Information Structure
   dialogEvent.append(BEGIN_DIALOG_INFO);

   if (version)
   {
      // Generate the body with the recorded version.
      char buffer[20];
      sprintf(buffer, "%d", mVersion);
      dialogEvent.append(VERSION_EQUAL);
      singleLine = DOUBLE_QUOTE + UtlString(buffer) + DOUBLE_QUOTE;
      dialogEvent += singleLine;
      // Return the XML version.
      *version = mVersion;
   }
   else
   {
      // Generate the body with the substitution placeholder.
      dialogEvent.append(VERSION_EQUAL
                         DOUBLE_QUOTE VERSION_PLACEHOLDER DOUBLE_QUOTE);
   }

   dialogEvent.append(STATE_EQUAL);
   singleLine = DOUBLE_QUOTE + mDialogState + DOUBLE_QUOTE;
   dialogEvent += singleLine;

   dialogEvent.append(ENTITY_EQUAL);
   singleLine = DOUBLE_QUOTE;
   XmlEscape(singleLine, mEntity);
   singleLine += DOUBLE_QUOTE;
   dialogEvent += singleLine;
   dialogEvent.append(END_LINE);

   // Take the lock (we will be modifying the state even though 'this'
   // is read-only).
   (const_cast <SipDialogEvent*> (this))->mLock.acquire();

   // Dialog elements
   UtlSListIterator dialogIterator(mDialogs);
   Dialog* pDialog;
   while ((pDialog = (Dialog *) dialogIterator()))
   {
      UtlString b;
      ssize_t l;
      pDialog->getBytes(b, l);
      dialogEvent.append(b);
   }

   // End of dialog-info element
   dialogEvent.append(END_DIALOG_INFO);

   // Update body text (even though 'this' is read-only).
   (const_cast <SipDialogEvent*> (this))->mBody = dialogEvent;
   (const_cast <SipDialogEvent*> (this))->bodyLength = dialogEvent.length();
   // mVersion is not updated, as that is used only to record
   // the version of parsed events.

   (const_cast <SipDialogEvent*> (this))->mLock.release();

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipDialogEvent::buildBody Dialog content = \n%s",
                 mBody.data());
}
예제 #4
0
void SipDialogEvent::buildBody(int& version) const
{
    UtlString dialogEvent;
    UtlString singleLine;
    char buffer[20];
    char durationBuffer[20];

    // Return the XML version.
    version = mVersion;

    // Construct the xml document of dialog event
    dialogEvent = UtlString(XML_VERSION_1_0);

    // Dialog Information Structure
    dialogEvent.append(BEGIN_DIALOG_INFO);

    Url entityUri(mEntity);
    sprintf(buffer, "%d", mVersion);

    dialogEvent.append(VERSION_EQUAL);
    singleLine = DOUBLE_QUOTE + UtlString(buffer) + DOUBLE_QUOTE;
    dialogEvent += singleLine;

    dialogEvent.append(STATE_EQUAL);
    singleLine = DOUBLE_QUOTE + mDialogState + DOUBLE_QUOTE;
    dialogEvent += singleLine;

    dialogEvent.append(ENTITY_EQUAL);
    singleLine = DOUBLE_QUOTE + entityUri.toString() + DOUBLE_QUOTE;
    dialogEvent += singleLine;
    dialogEvent.append(END_LINE);

    // Take the lock (we will be modifying the state even though 'this'
    // is read-only).
    ((SipDialogEvent*)this)->mLock.acquire();

    // Dialog elements
    UtlSListIterator dialogIterator(mDialogs);
    Dialog* pDialog;
    while ((pDialog = (Dialog *) dialogIterator()))
    {
        UtlString id, callId, localTag, remoteTag, direction;
        pDialog->getDialog(id, callId, localTag, remoteTag, direction);

        dialogEvent.append(BEGIN_DIALOG);
        singleLine = DOUBLE_QUOTE + id + DOUBLE_QUOTE;
        dialogEvent += singleLine;
        if (!callId.isNull())
        {
            dialogEvent.append(CALL_ID_EQUAL);
            singleLine = DOUBLE_QUOTE + callId + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }

        if (!localTag.isNull())
        {
            dialogEvent.append(LOCAL_TAG_EQUAL);
            singleLine = DOUBLE_QUOTE + localTag + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }

        if (!remoteTag.isNull())
        {
            dialogEvent.append(REMOTE_TAG_EQUAL);
            singleLine = DOUBLE_QUOTE + remoteTag + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }

        if (!direction.isNull())
        {
            dialogEvent.append(DIRECTION_EQUAL);
            singleLine = DOUBLE_QUOTE + direction + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }
        dialogEvent.append(END_LINE);

        // State element
        UtlString state, event, code;
        pDialog->getState(state, event, code);

        dialogEvent.append(BEGIN_STATE);
        if (!event.isNull())
        {
            dialogEvent.append(EVENT_EQUAL);
            singleLine = DOUBLE_QUOTE + event + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }

        if (!code.isNull())
        {
            dialogEvent.append(CODE_EQUAL);
            singleLine = DOUBLE_QUOTE + code + DOUBLE_QUOTE;
            dialogEvent += singleLine;
        }

        // End of state element
        singleLine = END_BRACKET + state + END_STATE;
        dialogEvent += singleLine;

        // Duration element
        int duration = pDialog->getDuration();
        if (duration !=0)
        {
            duration = OsDateTime::getSecsSinceEpoch() - pDialog->getDuration();
            sprintf(durationBuffer, "%d", duration);
            dialogEvent += BEGIN_DURATION + UtlString(durationBuffer) + END_DURATION;
        }

        // Local element
        UtlString identity, displayName, target;
        pDialog->getLocalIdentity(identity, displayName);
        pDialog->getLocalTarget(target);

        dialogEvent.append(BEGIN_LOCAL);
        if (!identity.isNull())
        {
            dialogEvent.append(BEGIN_IDENTITY);
            if (!displayName.isNull())
            {
                NameValueTokenizer::frontBackTrim(&displayName, "\"");
                dialogEvent.append(DISPLAY_EQUAL);
                singleLine = DOUBLE_QUOTE + displayName + DOUBLE_QUOTE;
                dialogEvent += singleLine;
            }

            singleLine = END_BRACKET + identity + END_IDENTITY;
            dialogEvent += singleLine;
        }

        if (!target.isNull() && target.compareTo("sip:") != 0)
        {
            singleLine = BEGIN_TARTGET + target + END_TARGET;
            dialogEvent += singleLine;
        }

        // End of local element
        dialogEvent.append(END_LOCAL);

        // Remote element
        pDialog->getRemoteIdentity(identity, displayName);
        pDialog->getRemoteTarget(target);

        dialogEvent.append(BEGIN_REMOTE);
        if (!identity.isNull())
        {
            dialogEvent.append(BEGIN_IDENTITY);
            if (!displayName.isNull())
            {
                NameValueTokenizer::frontBackTrim(&displayName, "\"");
                dialogEvent.append(DISPLAY_EQUAL);
                singleLine = DOUBLE_QUOTE + displayName + DOUBLE_QUOTE;
                dialogEvent += singleLine;
            }

            singleLine = END_BRACKET + identity + END_IDENTITY;
            dialogEvent += singleLine;
        }

        if (!target.isNull() && target.compareTo("sip:") != 0)
        {
            singleLine = BEGIN_TARTGET + target + END_TARGET;
            dialogEvent += singleLine;
        }

        // End of remote element
        dialogEvent.append(END_REMOTE);

        // End of dialog element
        dialogEvent.append(END_DIALOG);
    }

    // End of dialog-info element
    dialogEvent.append(END_DIALOG_INFO);

    // Update body text and version number (even though 'this' is read-only).
    ((SipDialogEvent*)this)->mBody = dialogEvent;
    ((SipDialogEvent*)this)->bodyLength = dialogEvent.length();
    ((SipDialogEvent*)this)->mVersion++;

    ((SipDialogEvent*)this)->mLock.release();

    OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogEvent::buildBody Dialog content = \n%s",
                  mBody.data());
}