Commit e1c4e140 authored by Tristan Matthews's avatar Tristan Matthews

* #29736: sippresence: fix warnings, use PJ_CONST_STR macro

parent 3efc8da6
...@@ -36,4 +36,8 @@ ...@@ -36,4 +36,8 @@
((sizeof(a) / sizeof(*(a))) / \ ((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
/* Only use this macro with string literals or character arrays, will not work
* as expected with char pointers */
#define CONST_PJ_STR(X) {(char *) (X), ARRAYSIZE(X) - 1}
#endif // ARRAY_SIZE_H_ #endif // ARRAY_SIZE_H_
...@@ -176,7 +176,7 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) ...@@ -176,7 +176,7 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata)
presSubServer->setExpires(-1); presSubServer->setExpires(-1);
st_code = (pjsip_status_code) 200; st_code = (pjsip_status_code) 200;
reason = pj_str("OK"); reason = CONST_PJ_STR("OK");
pj_bzero(&msg_data, sizeof(msg_data)); pj_bzero(&msg_data, sizeof(msg_data));
pj_list_init(&msg_data.hdr_list); pj_list_init(&msg_data.hdr_list);
pjsip_media_type_init(&msg_data.multipart_ctype, NULL, NULL); pjsip_media_type_init(&msg_data.multipart_ctype, NULL, NULL);
...@@ -208,20 +208,20 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata) ...@@ -208,20 +208,20 @@ pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata)
// fake temporary status // fake temporary status
pjrpid_element rpid = { pjrpid_element rpid = {
PJRPID_ELEMENT_TYPE_PERSON, PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"), CONST_PJ_STR("20"),
PJRPID_ACTIVITY_UNKNOWN, PJRPID_ACTIVITY_UNKNOWN,
pj_str("Your subscription was received and waits for approval.") CONST_PJ_STR("Your subscription was received and waits for approval.")
}; };
pjsip_pres_status fake_status_data; pjsip_pres_status fake_status_data;
pj_bzero(&fake_status_data, sizeof(pjsip_pres_status)); pj_bzero(&fake_status_data, sizeof(pjsip_pres_status));
fake_status_data.info_cnt = 1; fake_status_data.info_cnt = 1;
fake_status_data.info[0].basic_open = false; fake_status_data.info[0].basic_open = false;
fake_status_data.info[0].id = pj_str("0"); /* todo: tuplie_id*/ fake_status_data.info[0].id = CONST_PJ_STR("0"); /* todo: tuplie_id*/
pj_memcpy(&fake_status_data.info[0].rpid, &rpid, sizeof(pjrpid_element)); pj_memcpy(&fake_status_data.info[0].rpid, &rpid, sizeof(pjrpid_element));
pjsip_pres_set_status(sub, &fake_status_data); pjsip_pres_set_status(sub, &fake_status_data);
/* Create and send the the first NOTIFY to active subscription: */ /* Create and send the the first NOTIFY to active subscription: */
pj_str_t stateStr = pj_str(""); pj_str_t stateStr = CONST_PJ_STR("");
tdata = NULL; tdata = NULL;
status = pjsip_pres_notify(sub, ev_state, &stateStr, &reason, &tdata); status = pjsip_pres_notify(sub, ev_state, &stateStr, &reason, &tdata);
......
...@@ -40,12 +40,13 @@ ...@@ -40,12 +40,13 @@
#include <pjsip/sip_module.h> #include <pjsip/sip_module.h>
#include "src/noncopyable.h" #include "src/noncopyable.h"
#include "src/array_size.h"
extern pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata); extern pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata);
static pjsip_module mod_presence_server = { static pjsip_module mod_presence_server = {
NULL, NULL, /* prev, next. */ NULL, NULL, /* prev, next. */
pj_str("mod-presence-server"), /* Name. */ CONST_PJ_STR("mod-presence-server"), /* Name. */
-1, /* Id */ -1, /* Id */
PJSIP_MOD_PRIORITY_DIALOG_USAGE, PJSIP_MOD_PRIORITY_DIALOG_USAGE,
NULL, /* load() */ NULL, /* load() */
......
...@@ -112,7 +112,7 @@ void SIPPresence::updateStatus(bool status, const std::string &note) ...@@ -112,7 +112,7 @@ void SIPPresence::updateStatus(bool status, const std::string &note)
pjrpid_element rpid = { pjrpid_element rpid = {
PJRPID_ELEMENT_TYPE_PERSON, PJRPID_ELEMENT_TYPE_PERSON,
pj_str("20"), CONST_PJ_STR("20"),
PJRPID_ACTIVITY_UNKNOWN, PJRPID_ACTIVITY_UNKNOWN,
pj_str((char *) note.c_str()) pj_str((char *) note.c_str())
}; };
...@@ -128,7 +128,7 @@ void SIPPresence::updateStatus(bool status, const std::string &note) ...@@ -128,7 +128,7 @@ void SIPPresence::updateStatus(bool status, const std::string &note)
pj_bzero(&pres_status_data_, sizeof(pres_status_data_)); pj_bzero(&pres_status_data_, sizeof(pres_status_data_));
pres_status_data_.info_cnt = 1; pres_status_data_.info_cnt = 1;
pres_status_data_.info[0].basic_open = status; pres_status_data_.info[0].basic_open = status;
pres_status_data_.info[0].id = pj_str("0"); /* todo: tuplie_id*/ pres_status_data_.info[0].id = CONST_PJ_STR("0"); /* todo: tuplie_id*/
pj_memcpy(&pres_status_data_.info[0].rpid, &rpid, sizeof(pjrpid_element)); pj_memcpy(&pres_status_data_.info[0].rpid, &rpid, sizeof(pjrpid_element));
/* "contact" field is optionnal */ /* "contact" field is optionnal */
} }
...@@ -265,7 +265,7 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data) ...@@ -265,7 +265,7 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data)
{ {
if (tdata->msg->type == PJSIP_REQUEST_MSG) { if (tdata->msg->type == PJSIP_REQUEST_MSG) {
const pj_str_t STR_USER_AGENT = pj_str("User-Agent"); const pj_str_t STR_USER_AGENT = CONST_PJ_STR("User-Agent");
std::string useragent(acc_->getUserAgentName()); std::string useragent(acc_->getUserAgentName());
pj_str_t pJuseragent = pj_str((char*) useragent.c_str()); pj_str_t pJuseragent = pj_str((char*) useragent.c_str());
pjsip_hdr *h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, &STR_USER_AGENT, &pJuseragent); pjsip_hdr *h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, &STR_USER_AGENT, &pJuseragent);
...@@ -288,8 +288,8 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data) ...@@ -288,8 +288,8 @@ void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data)
if (msg_data->content_type.slen && msg_data->msg_body.slen) { if (msg_data->content_type.slen && msg_data->msg_body.slen) {
pjsip_msg_body *body; pjsip_msg_body *body;
pj_str_t type = pj_str("application"); const pj_str_t type = CONST_PJ_STR("application");
pj_str_t subtype = pj_str("pidf+xml"); const pj_str_t subtype = CONST_PJ_STR("pidf+xml");
body = pjsip_msg_body_create(tdata->pool, &type, &subtype, &msg_data->msg_body); body = pjsip_msg_body_create(tdata->pool, &type, &subtype, &msg_data->msg_body);
tdata->msg->body = body; tdata->msg->body = body;
} }
...@@ -436,7 +436,7 @@ pj_status_t ...@@ -436,7 +436,7 @@ pj_status_t
SIPPresence::pres_publish(SIPPresence *pres) SIPPresence::pres_publish(SIPPresence *pres)
{ {
pj_status_t status; pj_status_t status;
const pj_str_t STR_PRESENCE = pj_str("presence"); const pj_str_t STR_PRESENCE = CONST_PJ_STR("presence");
SIPAccount * acc = pres->getAccount(); SIPAccount * acc = pres->getAccount();
pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint(); pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint();
......
...@@ -553,23 +553,23 @@ SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), sipAccountMap_(), ...@@ -553,23 +553,23 @@ SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), sipAccountMap_(),
TRY(pjsip_inv_usage_init(endpt_, &inv_cb)); TRY(pjsip_inv_usage_init(endpt_, &inv_cb));
static const pj_str_t allowed[] = { static const pj_str_t allowed[] = {
{(char *) "INFO", 4}, CONST_PJ_STR("INFO"),
{(char *) "REGISTER", 8}, CONST_PJ_STR("REGISTER"),
{(char *) "OPTIONS", 7}, CONST_PJ_STR("OPTIONS"),
{(char *) "MESSAGE", 7}, CONST_PJ_STR("MESSAGE"),
{(char *) "INVITE", 6}, CONST_PJ_STR("INVITE"),
{(char *) "ACK", 3}, CONST_PJ_STR("ACK"),
{(char *) "BYE", 3}, CONST_PJ_STR("BYE"),
{(char *) "NOTIFY",6}, CONST_PJ_STR("NOTIFY"),
{(char *) "PUBLISH",7}, CONST_PJ_STR("PUBLISH"),
{(char *) "CANCEL",6}}; CONST_PJ_STR("CANCEL")};
pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ALLOW, NULL, PJ_ARRAY_SIZE(allowed), allowed); pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ALLOW, NULL, PJ_ARRAY_SIZE(allowed), allowed);
static const pj_str_t text_plain = { (char*) "text/plain", 10 }; static const pj_str_t text_plain = CONST_PJ_STR("text/plain");
pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, NULL, 1, &text_plain); pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, NULL, 1, &text_plain);
static const pj_str_t accepted = { (char*) "application/sdp", 15 }; static const pj_str_t accepted = CONST_PJ_STR("application/sdp");
pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, NULL, 1, &accepted); pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, NULL, 1, &accepted);
DEBUG("pjsip version %s for %s initialized", pj_get_version(), PJ_OS_NAME); DEBUG("pjsip version %s for %s initialized", pj_get_version(), PJ_OS_NAME);
...@@ -746,7 +746,7 @@ void SIPVoIPLink::sendRegister(Account *a) ...@@ -746,7 +746,7 @@ void SIPVoIPLink::sendRegister(Account *a)
pj_list_init(&hdr_list); pj_list_init(&hdr_list);
std::string useragent(account->getUserAgentName()); std::string useragent(account->getUserAgentName());
pj_str_t pJuseragent = pj_str((char*) useragent.c_str()); pj_str_t pJuseragent = pj_str((char*) useragent.c_str());
const pj_str_t STR_USER_AGENT = { (char*) "User-Agent", 10 }; const pj_str_t STR_USER_AGENT = CONST_PJ_STR("User-Agent");
pjsip_generic_string_hdr *h = pjsip_generic_string_hdr_create(pool_, &STR_USER_AGENT, &pJuseragent); pjsip_generic_string_hdr *h = pjsip_generic_string_hdr_create(pool_, &STR_USER_AGENT, &pJuseragent);
pj_list_push_back(&hdr_list, (pjsip_hdr*) h); pj_list_push_back(&hdr_list, (pjsip_hdr*) h);
...@@ -1444,10 +1444,6 @@ SIPVoIPLink::getCurrentAudioCodecNames(Call *call) const ...@@ -1444,10 +1444,6 @@ SIPVoIPLink::getCurrentAudioCodecNames(Call *call) const
} }
} }
/* Only use this macro with string literals or character arrays, will not work
* as expected with char pointers */
#define CONST_PJ_STR(X) {(char *) (X), ARRAYSIZE(X) - 1}
namespace { namespace {
void sendSIPInfo(const SIPCall &call, const char *const body, const char *const subtype) void sendSIPInfo(const SIPCall &call, const char *const body, const char *const subtype)
{ {
...@@ -1586,8 +1582,8 @@ SIPVoIPLink::SIPStartCall(SIPCall *call) ...@@ -1586,8 +1582,8 @@ SIPVoIPLink::SIPStartCall(SIPCall *call)
return false; return false;
} }
// aol // aol
pj_str_t subj_hdr_name = pj_str("Subject"); pj_str_t subj_hdr_name = CONST_PJ_STR("Subject");
pjsip_hdr* subj_hdr = (pjsip_hdr*) pjsip_parse_hdr(dialog->pool, &subj_hdr_name, "Phone call", 10, NULL); 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); pj_list_push_back(&dialog->inv_hdr, subj_hdr);
// aol // aol
...@@ -2242,7 +2238,7 @@ void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata) ...@@ -2242,7 +2238,7 @@ void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata)
if (currentCall == NULL) if (currentCall == NULL)
return; return;
static const pj_str_t str_refer_to = { (char*) "Refer-To", 8}; static const pj_str_t str_refer_to = CONST_PJ_STR("Refer-To");
pjsip_generic_string_hdr *refer_to = static_cast<pjsip_generic_string_hdr*> pjsip_generic_string_hdr *refer_to = static_cast<pjsip_generic_string_hdr*>
(pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL)); (pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment