⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogeventpublisher.cpp

📁 基于sipfoundy 公司开发的sipx协议API
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// // // Copyright (C) 2005 SIPfoundry Inc.// Licensed by SIPfoundry under the LGPL license.// // Copyright (C) 2005 Pingtel Corp.// Licensed to SIPfoundry under a Contributor Agreement.// // $$////////////////////////////////////////////////////////////////////////////// SYSTEM INCLUDES// APPLICATION INCLUDES#include <cp/DialogEventPublisher.h>#include <tao/TaoMessage.h>#include <tao/TaoString.h>#include <cp/CallManager.h>#include <net/SipDialog.h>#include <net/SipPublishContentMgr.h>#include <os/OsFS.h>#include <os/OsDateTime.h>// EXTERNAL FUNCTIONS// EXTERNAL VARIABLES// CONSTANTS#define TAO_OFFER_PARAM_CALLID             0#define TAO_OFFER_PARAM_ADDRESS            2#define TAO_OFFER_PARAM_LOCAL_CONNECTION   6#define STATE "full"//#define DEBUGGING 1// STATIC VARIABLE INITIALIZATIONS/* //////////////////////////// PUBLIC //////////////////////////////////// *//* ============================ CREATORS ================================== */// ConstructorDialogEventPublisher::DialogEventPublisher(CallManager* callManager,                                           SipPublishContentMgr* contentMgr){   mpCallManager = callManager;   mpSipPublishContentMgr = contentMgr;   mDialogId = 0;}//DestructorDialogEventPublisher::~DialogEventPublisher(){}/* ============================ MANIPULATORS ============================== */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;   UtlString failCallId;   OsTime receivedTime;   int numOldContents;   HttpBody* oldContent[1];   UtlString remoteRequestUri;   UtlString temp;   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              OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage TaoMessage args %d",arg.getCnt());      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:            OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage CONNECTION_OFFERED");            mpCallManager->getSipDialog(callId, address, sipDialog);#ifdef DEBUGGING                        sipDialog.toString(sipDialogContent);            OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage sipDialog = '%s'",                           sipDialogContent.data());#endif                        sipDialog.getRemoteRequestUri(remoteRequestUri);            getEntity(remoteRequestUri, entity);                        OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage Call arrived: callId '%s' address '%s' requestUri '%s'",                           callId.data(), address.data(), entity.data());            if (entity.isNull())            {               OsSysLog::add(FAC_SIP, PRI_WARNING, "DialogEventPublisher::handleMessage 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::handleMessage 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:            OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage CONNECTION_ESATBLISHED");                     if (localConnection)             {               mpCallManager->getSipDialog(callId, address, sipDialog);#ifdef DEBUGGING                           sipDialog.toString(sipDialogContent);               OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage sipDialog = %s",                              sipDialogContent.data());#endif                           sipDialog.getRemoteRequestUri(remoteRequestUri);               getEntity(remoteRequestUri, entity);                              OsSysLog::add(FAC_SIP, PRI_DEBUG, "DialogEventPublisher::handleMessage 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::handleMessage 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);                  OsSysLog::add(FAC_SIP, PRI_DEBUG,                                "DialogEventPublisher::handleMessage inserting entity '%s'",                                entity.data());               }                              // 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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -