From 099942376b4ff1cf03aec3653f1033beac627744 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Fri, 13 Sep 2013 16:03:40 -0400
Subject: [PATCH] * #29736: sippresence: fixed more warnings, cleanup

---
 daemon/src/sip/pres_sub_client.cpp | 33 ++++++++++++---------
 daemon/src/sip/pres_sub_client.h   | 46 +++++++++++-------------------
 daemon/src/sip/sipvoiplink.cpp     |  3 +-
 3 files changed, 37 insertions(+), 45 deletions(-)

diff --git a/daemon/src/sip/pres_sub_client.cpp b/daemon/src/sip/pres_sub_client.cpp
index 87a511c4f1..d896eae1ba 100644
--- a/daemon/src/sip/pres_sub_client.cpp
+++ b/daemon/src/sip/pres_sub_client.cpp
@@ -43,6 +43,7 @@
 #include <pjsip-simple/evsub.h>
 #include <unistd.h>
 
+#include "array_size.h"
 #include "pres_sub_client.h"
 #include "sipaccount.h"
 #include "sippresence.h"
@@ -54,9 +55,10 @@
 
 #define PRES_TIMER 300 // 5min
 
-static int modId; // used to extract data structure from event_subscription
+int PresSubClient::modId_ = 0; // used to extract data structure from event_subscription
 
-void pres_client_timer_cb(pj_timer_heap_t * /*th*/, pj_timer_entry *entry)
+void
+PresSubClient::pres_client_timer_cb(pj_timer_heap_t * /*th*/, pj_timer_entry *entry)
 {
     /* TODO : clean*/
     PresSubClient *c = (PresSubClient *) entry->user_data;
@@ -65,7 +67,8 @@ void pres_client_timer_cb(pj_timer_heap_t * /*th*/, pj_timer_entry *entry)
 }
 
 /* Callback called when *client* subscription state has changed. */
-void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
+void
+PresSubClient::pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
 {
     PJ_UNUSED_ARG(event);
 
@@ -74,7 +77,7 @@ void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
      *   lock, which we are currently holding!
      */
 
-    PresSubClient *pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
+    PresSubClient *pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId_);
 
     if (pres_client) {
         pres_client->incLock();
@@ -146,7 +149,7 @@ void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
                          * into pending state.
                          */
                         const pjsip_sub_state_hdr *sub_hdr;
-                        pj_str_t sub_state = {(char *) "Subscription-State", 18 };
+                        pj_str_t sub_state = CONST_PJ_STR("Subscription-State");
                         const pjsip_msg *msg;
 
                         msg = event->body.tsx_state.src.rdata->msg_info.msg;
@@ -181,7 +184,7 @@ void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
             pres_client->status_.info_cnt = 0;
             pres_client->dlg_ = NULL;
             pres_client->rescheduleTimer(PJ_FALSE, 0);
-            pjsip_evsub_set_mod_data(sub, modId, NULL);
+            pjsip_evsub_set_mod_data(sub, modId_, NULL);
         }
 
         pres_client->decLock();
@@ -189,7 +192,8 @@ void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event)
 }
 
 /* Callback when transaction state has changed. */
-void pres_client_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_event *event)
+void
+PresSubClient::pres_client_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_event *event)
 {
 
     PresSubClient *pres_client;
@@ -199,7 +203,7 @@ void pres_client_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pj
      *   a dialog attached to it, lock_pres_client() will use the dialog
      *   lock, which we are currently holding!
      */
-    pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
+    pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId_);
 
     if (!pres_client) {
         return;
@@ -243,14 +247,15 @@ void pres_client_evsub_on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pj
 }
 
 /* Callback called when we receive NOTIFY */
-static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
+void
+PresSubClient::pres_client_evsub_on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
 {
 
     /* Note: #937: no need to acuire PJSUA_LOCK here. Since the pres_client has
      *   a dialog attached to it, lock_pres_client() will use the dialog
      *   lock, which we are currently holding!
      */
-    PresSubClient *pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId);
+    PresSubClient *pres_client = (PresSubClient *) pjsip_evsub_get_mod_data(sub, modId_);
 
     if (!pres_client) {
         WARN("Couldn't extract pres_client from ev_sub.");
@@ -371,7 +376,8 @@ void PresSubClient::reportPresence()
 }
 
 
-pj_status_t PresSubClient::updateSubscription()
+pj_status_t
+PresSubClient::updateSubscription()
 {
 
     if (!monitor_) {
@@ -405,7 +411,7 @@ pj_status_t PresSubClient::updateSubscription()
             WARN("Unable to unsubscribe presence", retStatus);
         }
 
-        pjsip_evsub_set_mod_data(sub_, modId, NULL);   // Not interested with further events
+        pjsip_evsub_set_mod_data(sub_, modId_, NULL);   // Not interested with further events
 
         return PJ_SUCCESS;
     }
@@ -481,8 +487,7 @@ pj_status_t PresSubClient::updateSubscription()
 
 
     /* FIXME : not sure this is acceptable */
-    modId = pres_->getModId();
-    pjsip_evsub_set_mod_data(sub_, modId, this);
+    pjsip_evsub_set_mod_data(sub_, modId_, this);
 
     status = pjsip_pres_initiate(sub_, -1, &tdata);
 
diff --git a/daemon/src/sip/pres_sub_client.h b/daemon/src/sip/pres_sub_client.h
index 5aaadac96f..d173182bf2 100644
--- a/daemon/src/sip/pres_sub_client.h
+++ b/daemon/src/sip/pres_sub_client.h
@@ -44,23 +44,6 @@
 
 class SIPPresence;
 
-/**
- * Transaction functions of event subscription client side.
- */
-static void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
-static void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
-        pjsip_transaction *tsx,
-        pjsip_event *event);
-static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
-        pjsip_rx_data *rdata,
-        int *p_st_code,
-        pj_str_t **p_st_text,
-        pjsip_hdr *res_hdr,
-        pjsip_msg_body **p_body);
-static void pres_client_timer_cb(pj_timer_heap_t *th,
-                                 pj_timer_entry *entry);
-
-
 class PresSubClient {
 
     public:
@@ -112,18 +95,6 @@ class PresSubClient {
         std::string getLineStatus();
 
 
-        friend void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
-        friend void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
-                pjsip_transaction *tsx,
-                pjsip_event *event);
-        friend void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
-                pjsip_rx_data *rdata,
-                int *p_st_code,
-                pj_str_t **p_st_text,
-                pjsip_hdr *res_hdr,
-                pjsip_msg_body **p_body);
-        friend void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
-
         /**
          * TODO: explain this:
          */
@@ -137,6 +108,22 @@ class PresSubClient {
     private:
 
         NON_COPYABLE(PresSubClient);
+
+        /**
+         * Transaction functions of event subscription client side.
+         */
+        static void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
+        static void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
+                pjsip_transaction *tsx,
+                pjsip_event *event);
+        static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
+                pjsip_rx_data *rdata,
+                int *p_st_code,
+                pj_str_t **p_st_text,
+                pjsip_hdr *res_hdr,
+                pjsip_msg_body **p_body);
+        static void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
+
         /**
          * Plan a retry or a renew a subscription.
          * @param reschedule    Allow for reschedule.
@@ -177,6 +164,7 @@ class PresSubClient {
         pj_timer_entry   timer_;        /**< Resubscription timer */
         void            *user_data_;        /**< Application data. */
         int lock_count_;
+        static int modId_; // used to extract data structure from event_subscription
 };
 
 #endif    /*  PRES_SUB_CLIENT_H */
diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp
index 7d83590bdc..71a85ea8ef 100644
--- a/daemon/src/sip/sipvoiplink.cpp
+++ b/daemon/src/sip/sipvoiplink.cpp
@@ -1581,12 +1581,11 @@ SIPVoIPLink::SIPStartCall(SIPCall *call)
               "calling %s", toUri.c_str());
         return false;
     }
-// aol
+
     pj_str_t subj_hdr_name = CONST_PJ_STR("Subject");
     pjsip_hdr* subj_hdr = (pjsip_hdr*) pjsip_parse_hdr(dialog->pool, &subj_hdr_name, (char *) "Phone call", 10, NULL);
 
     pj_list_push_back(&dialog->inv_hdr, subj_hdr);
-// aol
 
     if (pjsip_inv_create_uac(dialog, call->getLocalSDP()->getLocalSdpSession(), 0, &call->inv) != PJ_SUCCESS) {
         ERROR("Unable to create invite session for user agent client");
-- 
GitLab