📄 linepresencemonitor.cpp
字号:
{ result = OS_SUCCESS; } else { result = OS_FAILED; } } else { // Use XML-RPC to communicate with the sipX dialog monitor XmlRpcRequest request(mRemoteServer, "removeExtension"); request.addParam(&mGroupName); UtlString contact = lineUrl->toString(); request.addParam(&contact); XmlRpcResponse response; if (request.execute(response)) { result = OS_SUCCESS; } else { result = OS_FAILED; } } UtlString contact; lineUrl->getUserId(contact); mDialogSubscribeList.destroy(&contact); mLock.release(); return result;}OsStatus LinePresenceMonitor::subscribeDialog(UtlSList& list){ OsStatus result = OS_FAILED; mLock.acquire(); UtlSListIterator iterator(list); LinePresenceBase* line; while ((line = dynamic_cast <LinePresenceBase *> (iterator())) != NULL) { subscribeDialog(line); } mLock.release(); return result;}OsStatus LinePresenceMonitor::unsubscribeDialog(UtlSList& list){ OsStatus result = OS_FAILED; mLock.acquire(); UtlSListIterator iterator(list); LinePresenceBase* line; while ((line = dynamic_cast <LinePresenceBase *> (iterator())) != NULL) { unsubscribeDialog(line); } mLock.release(); return result;}OsStatus LinePresenceMonitor::subscribePresence(LinePresenceBase* line){ OsStatus result = OS_FAILED; mLock.acquire(); Url* lineUrl = line->getUri(); OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::subscribePresence subscribing presence for line %s", lineUrl->toString().data()); // Send out the SUBSCRIBE to the presence server UtlString contactId, resourceId; lineUrl->getUserId(contactId); if (!mPresenceServer.isNull()) { resourceId = contactId + mPresenceServer; OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::subscribePresence Sending out the SUBSCRIBE to contact %s", resourceId.data()); UtlString toUrl; lineUrl->toString(toUrl); UtlString fromUri = "linePresenceMonitor@" + mDomainName; UtlString dialogHandle; UtlBoolean status = mpSipSubscribeClient->addSubscription(resourceId.data(), PRESENCE_EVENT_TYPE, fromUri.data(), toUrl.data(), mContact.data(), DEFAULT_REFRESH_INTERVAL, (void *) this, LinePresenceMonitor::subscriptionStateCallback, LinePresenceMonitor::notifyEventCallback, dialogHandle); if (!status) { OsSysLog::add(FAC_SIP, PRI_ERR, "LinePresenceMonitor::subscribePresence Subscription failed to contact %s.", resourceId.data()); } else { mDialogHandleList.insertKeyAndValue(new UtlString(contactId), new UtlString(dialogHandle)); } } // Insert the line to the Subscribe Map mPresenceSubscribeList.insertKeyAndValue(new UtlString(contactId), new UtlVoidPtr(line)); mLock.release(); return result;}OsStatus LinePresenceMonitor::unsubscribePresence(LinePresenceBase* line){ OsStatus result = OS_FAILED; mLock.acquire(); Url* lineUrl = line->getUri(); if (lineUrl == NULL) { return OS_FAILED; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::unsubscribePresence unsubscribing presence for line %s", lineUrl->toString().data()); // Remove the line from the Subscribe Map UtlString contact; lineUrl->getUserId(contact); if (!mPresenceServer.isNull()) { UtlBoolean status = true; UtlString* dialogHandle = dynamic_cast <UtlString *> (mDialogHandleList.findValue(&contact)); if (dialogHandle != NULL) { UtlBoolean status = mpSipSubscribeClient->endSubscription(dialogHandle->data()); if (!status) { OsSysLog::add(FAC_SIP, PRI_ERR, "LinePresenceMonitor::unsubscribePresence Unsubscription failed for %s.", contact.data()); } } mDialogHandleList.destroy(&contact); } mPresenceSubscribeList.destroy(&contact); mLock.release(); return result;}OsStatus LinePresenceMonitor::subscribePresence(UtlSList& list){ OsStatus result = OS_FAILED; mLock.acquire(); UtlSListIterator iterator(list); LinePresenceBase* line; while ((line = dynamic_cast <LinePresenceBase *> (iterator())) != NULL) { subscribePresence(line); } mLock.release(); return result;}OsStatus LinePresenceMonitor::unsubscribePresence(UtlSList& list){ OsStatus result = OS_FAILED; mLock.acquire(); UtlSListIterator iterator(list); LinePresenceBase* line; while ((line = dynamic_cast <LinePresenceBase *> (iterator())) != NULL) { unsubscribePresence(line); } mLock.release(); return result;}void LinePresenceMonitor::subscriptionStateCallback(SipSubscribeClient::SubscriptionState newState, const char* earlyDialogHandle, const char* dialogHandle, void* applicationData, int responseCode, const char* responseText, long expiration, const SipMessage* subscribeResponse){ OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::subscriptionStateCallback is called with responseCode = %d (%s)", responseCode, responseText); } void LinePresenceMonitor::notifyEventCallback(const char* earlyDialogHandle, const char* dialogHandle, void* applicationData, const SipMessage* notifyRequest){ // Receive the notification and process the message LinePresenceMonitor* pThis = (LinePresenceMonitor *) applicationData; pThis->handleNotifyMessage(notifyRequest);}void LinePresenceMonitor::handleNotifyMessage(const SipMessage* notifyMessage){ Url fromUrl; notifyMessage->getFromUrl(fromUrl); UtlString contact; fromUrl.getUserId(contact); contact += mPresenceServer; OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::handleNotifyMessage receiving a notify message from %s", contact.data()); const HttpBody* notifyBody = notifyMessage->getBody(); if (notifyBody) { UtlString messageContent; int bodyLength; notifyBody->getBytes(&messageContent, &bodyLength); // Parse the content and store it in a SipPresenceEvent object SipPresenceEvent* sipPresenceEvent = new SipPresenceEvent(contact, messageContent); UtlString id; NetMd5Codec::encode(contact, id); Tuple* tuple = sipPresenceEvent->getTuple(id); if (tuple != NULL) { UtlString status; tuple->getStatus(status); Url contactUrl(contact); if (status.compareTo(STATUS_CLOSE) == 0) { setStatus(contactUrl, StateChangeNotifier::SIGN_OUT); } else { setStatus(contactUrl, StateChangeNotifier::SIGN_IN); } } else { OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::handleNotifyMessage unable to find matching tuple for: %s", contact.data()); } delete sipPresenceEvent; } else { OsSysLog::add(FAC_SIP, PRI_DEBUG, "LinePresenceMonitor::handleNotifyMessage receiving an empty notify body from %s", contact.data()); }}/* ============================ INQUIRY =================================== *//* //////////////////////////// PROTECTED ///////////////////////////////// *//* //////////////////////////// PRIVATE /////////////////////////////////// *//* ============================ FUNCTIONS ================================= */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -