diff --git a/daemon/src/sip/pres_sub_server.cpp b/daemon/src/sip/pres_sub_server.cpp index 640a5d46f1270fd7e4ef3837ae9670e2657773cb..a21672f1af5675beb9105f387284616074a835dc 100644 --- a/daemon/src/sip/pres_sub_server.cpp +++ b/daemon/src/sip/pres_sub_server.cpp @@ -35,11 +35,13 @@ #include "sipvoiplink.h" #include "manager.h" #include "sippresence.h" +#include "client/presencemanager.h" #include "logger.h" #include "pres_sub_server.h" /* Callback called when *server* subscription state has changed. */ -void pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) +void +PresSubServer::pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) { pjsip_rx_data *rdata = event->body.rx_msg.rdata; @@ -51,8 +53,8 @@ void pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) PJ_UNUSED_ARG(event); SIPPresence * pres = Manager::instance().getSipAccount("IP2IP")->getPresence(); pres->lock(); - PresSubServer *presSubServer = (PresSubServer *) pjsip_evsub_get_mod_data(sub, pres->getModId()); - DEBUG("Presence_subscription_server to %s is %s", presSubServer->remote, pjsip_evsub_get_state_name(sub)); + PresSubServer *presSubServer = static_cast<PresSubServer *>(pjsip_evsub_get_mod_data(sub, pres->getModId())); + DEBUG("Presence_subscription_server to %s is %s", presSubServer->remote_, pjsip_evsub_get_state_name(sub)); if (presSubServer) { pjsip_evsub_state state; @@ -70,7 +72,8 @@ void pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) pres->unlock(); } -pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) +pj_bool_t +PresSubServer::pres_on_rx_subscribe_request(pjsip_rx_data *rdata) { pjsip_method *method = &rdata->msg_info.msg->line.req.method; @@ -81,7 +84,6 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) pjsip_dialog *dlg; pjsip_evsub *sub; pjsip_evsub_user pres_cb; - pjsip_tx_data *tdata; pjsip_expires_hdr *expires_hdr; pjsip_status_code st_code; pj_str_t reason; @@ -97,14 +99,14 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) /* debug msg */ std::string name(rdata->msg_info.to->name.ptr, rdata->msg_info.to->name.slen); std::string server(rdata->msg_info.from->name.ptr, rdata->msg_info.from->name.slen); - DEBUG("Incomming pres_on_rx_subscribe_request for %s, name:%s, server:%s." + DEBUG("Incoming pres_on_rx_subscribe_request for %s, name:%s, server:%s." , request.c_str() , name.c_str() , server.c_str()); /* get parents*/ std::string accountId = "IP2IP"; /* this code is only used for IP2IP accounts */ - SIPAccount *acc = (SIPAccount *) Manager::instance().getSipAccount(accountId); + SIPAccount *acc = Manager::instance().getSipAccount(accountId); pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint(); SIPPresence * pres = acc->getPresence(); pres->lock(); @@ -164,7 +166,9 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) /* Create a new PresSubServer server and wait for client approve */ PresSubServer *presSubServer = new PresSubServer(pres, sub, remote, dlg); pjsip_evsub_set_mod_data(sub, pres->getModId(), presSubServer); - pres->reportnewServerSubscriptionRequest(presSubServer); // Notify the client. + // Notify the client. + Manager::instance().getClient()->getPresenceManager()->newServerSubscriptionRequest(presSubServer->remote_); + pres->addPresSubServer(presSubServer); /* Capture the value of Expires header. */ @@ -222,7 +226,7 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) /* Create and send the the first NOTIFY to active subscription: */ pj_str_t stateStr = CONST_PJ_STR(""); - tdata = NULL; + pjsip_tx_data *tdata = NULL; status = pjsip_pres_notify(sub, ev_state, &stateStr, &reason, &tdata); if (status == PJ_SUCCESS) { @@ -260,8 +264,8 @@ pjsip_module PresSubServer::mod_presence_server = { -PresSubServer::PresSubServer(SIPPresence * pres, pjsip_evsub *evsub, char *r, pjsip_dialog *d) - : remote(r) +PresSubServer::PresSubServer(SIPPresence * pres, pjsip_evsub *evsub, const char *remote, pjsip_dialog *d) + : remote_(remote) , pres_(pres) , sub_(evsub) , dlg_(d) @@ -279,20 +283,21 @@ void PresSubServer::setExpires(int ms) expires_ = ms; } -int PresSubServer::getExpires() +int PresSubServer::getExpires() const { return expires_; } -bool PresSubServer::matches(char *s) +bool PresSubServer::matches(const char *s) const { // servers match if they have the same remote uri and the account ID. - return (!(strcmp(remote, s))) ; + return (!(strcmp(remote_, s))) ; } void PresSubServer::approve(bool flag) { approved_ = flag; + DEBUG("Approve Presence_subscription_server for %s: %s.", remote_, flag ? "true" : "false"); // attach the real status data pjsip_pres_set_status(sub_, pres_->getStatus()); } @@ -307,7 +312,7 @@ void PresSubServer::notify() * the user accepted the request. */ if ((pjsip_evsub_get_state(sub_) == PJSIP_EVSUB_STATE_ACTIVE) && (approved_)) { - DEBUG("Notifying %s.", remote); + DEBUG("Notifying %s.", remote_); pjsip_tx_data *tdata; pjsip_pres_set_status(sub_, pres_->getStatus()); diff --git a/daemon/src/sip/pres_sub_server.h b/daemon/src/sip/pres_sub_server.h index 02bcc0ef319b79ad965359ea2e273240ca135e06..bfcd52826a829bf1bd3307cf74947849f42b4372 100644 --- a/daemon/src/sip/pres_sub_server.h +++ b/daemon/src/sip/pres_sub_server.h @@ -49,21 +49,19 @@ class SIPpresence; class PresSubServer { public: - PresSubServer(SIPPresence * pres, pjsip_evsub *evsub, char *r, pjsip_dialog *d); + PresSubServer(SIPPresence * pres, pjsip_evsub *evsub, const char *remote, pjsip_dialog *d); ~PresSubServer(); - /* TODO: add '< >' to URI for consistance*/ - char *remote; /**< Remote URI. */ /* * Acces to the evsub expire variable. * It was recieved in the SUBSCRIBE request. */ void setExpires(int ms); - int getExpires(); + int getExpires() const; /* * Match method * s is the URI (remote) */ - bool matches(char *s); + bool matches(const char *s) const; /* * Allow the subscriber for being notified. */ @@ -73,14 +71,16 @@ class PresSubServer { */ void notify(); - friend void pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event); - friend pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata); - static pjsip_module mod_presence_server; private: + static pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata); + static void pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event); + NON_COPYABLE(PresSubServer); + /* TODO: add '< >' to URI for consistency */ + const char *remote_; /**< Remote URI. */ SIPPresence *pres_; pjsip_evsub *sub_; pjsip_dialog *dlg_; diff --git a/daemon/src/sip/sippresence.cpp b/daemon/src/sip/sippresence.cpp index 27bff0b0b9c8c786c080375d366d5f350f227455..8708f6e61043bc5b6d78af94b2fc3760c276709f 100644 --- a/daemon/src/sip/sippresence.cpp +++ b/daemon/src/sip/sippresence.cpp @@ -203,17 +203,10 @@ void SIPPresence::removePresSubClient(PresSubClient *c) pres_sub_client_list_.remove(c); } - -void SIPPresence::reportnewServerSubscriptionRequest(PresSubServer *s) -{ - Manager::instance().getClient()->getPresenceManager()->newServerSubscriptionRequest(s->remote); -} - void SIPPresence::approvePresSubServer(const std::string& uri, bool flag) { for (const auto & s : pres_sub_server_list_) { if (s->matches((char *) uri.c_str())) { - DEBUG("Approve Presence_subscription_server for %s: %s.", s->remote, flag ? "true" : "false"); s->approve(flag); // return; // 'return' would prevent multiple-time subscribers from spam } @@ -224,7 +217,6 @@ void SIPPresence::approvePresSubServer(const std::string& uri, bool flag) void SIPPresence::addPresSubServer(PresSubServer *s) { if (pres_sub_server_list_.size() < MAX_N_PRES_SUB_SERVER) { - DEBUG("Presence_subscription_server added: %s.", s->remote); pres_sub_server_list_.push_back(s); } else { WARN("Max Presence_subscription_server is reach."); diff --git a/daemon/src/sip/sippresence.h b/daemon/src/sip/sippresence.h index 0612e0fb3b73758470b7bfa7752addb43e6ef889..dffb2f8c4e7bcde07d08855133f3220481f6b2d4 100644 --- a/daemon/src/sip/sippresence.h +++ b/daemon/src/sip/sippresence.h @@ -168,12 +168,6 @@ class SIPPresence { */ void removePresSubClient(PresSubClient *b); - /** - * IP2IP context. - * Report new Subscription to the client, waiting for approval. - * @param s PresenceSubcription pointer. - */ - void reportnewServerSubscriptionRequest(PresSubServer *s); /** * IP2IP context. * Process new subscription based on client decision.