Commit 319bde2a authored by Tristan Matthews's avatar Tristan Matthews

HookPreference: cleanup

parent 0fe52b0a
......@@ -34,6 +34,7 @@
#include "config/yamlemitter.h"
#include "config/yamlnode.h"
#include "hooks/urlhook.h"
#include "sip/sip_utils.h"
#include <sstream>
#include "global.h"
#include <cassert>
......@@ -275,9 +276,12 @@ void HookPreference::unserialize(const Conf::MappingNode *map)
map->getValue(urlSipFieldKey, &urlSipField_);
}
void HookPreference::run(const std::string &header)
void HookPreference::runHook(pjsip_msg *msg)
{
UrlHook::runAction(urlCommand_, header);
if (sipEnabled_) {
std::string header(sip_utils::fetchHeaderValue(msg, urlSipField_));
UrlHook::runAction(urlCommand_, header);
}
}
AudioPreference::AudioPreference() :
......
......@@ -328,10 +328,11 @@ class AddressbookPreference : public Serializable {
bool business_;
bool home_;
bool mobile_;
};
class pjsip_msg;
class HookPreference : public Serializable {
public:
HookPreference();
......@@ -349,9 +350,7 @@ class HookPreference : public Serializable {
}
std::map<std::string, std::string> toMap() const;
bool getSipEnabled() const { return sipEnabled_; }
std::string getUrlSipField() const { return urlSipField_; }
void run(const std::string &header);
void runHook(pjsip_msg *msg);
private:
bool iax2Enabled_;
......
......@@ -14,7 +14,9 @@ libsiplink_la_SOURCES = \
sdp.h \
sipaccount.h \
sipcall.h \
sipvoiplink.h
sipvoiplink.h \
sip_utils.cpp \
sip_utils.h
libsiplink_la_CXXFLAGS = \
@PCRE_LIBS@
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
*
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "sip_utils.h"
#include "pj/string.h"
#include "pjsip/sip_msg.h"
std::string
sip_utils::fetchHeaderValue(pjsip_msg *msg, const std::string &field)
{
pj_str_t name = pj_str((char*) field.c_str());
pjsip_generic_string_hdr *hdr = static_cast<pjsip_generic_string_hdr*>(pjsip_msg_find_hdr_by_name(msg, &name, NULL));
if (!hdr)
return "";
std::string value(hdr->hvalue.ptr, hdr->hvalue.slen);
size_t pos = value.find("\n");
if (pos != std::string::npos)
return value.substr(0, pos);
else
return "";
}
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
*
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef SIP_UTILS_H_
#define SIP_UTILS_H_
#include <string>
class pjsip_msg;
namespace sip_utils {
/**
* Helper function to parser header from incoming sip messages
* @return Header from SIP message
*/
std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field);
}
#endif // SIP_UTILS_H_
......@@ -89,11 +89,6 @@ static std::map<std::string, std::string> transferCallID;
*/
void setCallMediaLocal(SIPCall* call, const std::string &localIP);
/**
* Helper function to parser header from incoming sip messages
*/
std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field);
static pj_caching_pool pool_cache, *cp_ = &pool_cache;
static pj_pool_t *pool_;
static pjsip_endpoint *endpt_;
......@@ -306,10 +301,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata)
return true;
}
if (Manager::instance().hookPreference.getSipEnabled()) {
std::string header_value(fetchHeaderValue(rdata->msg_info.msg, Manager::instance().hookPreference.getUrlSipField()));
Manager::instance().hookPreference.run(header_value);
}
Manager::instance().hookPreference.runHook(rdata->msg_info.msg);
SIPCall* call = new SIPCall(Manager::instance().getNewCallID(), Call::INCOMING, cp_);
Manager::instance().associateCallToAccount(call->getCallId(), account_id);
......@@ -2113,25 +2105,6 @@ void setCallMediaLocal(SIPCall* call, const std::string &localIP)
call->setLocalAudioPort(callLocalAudioPort);
call->getLocalSDP()->setLocalPublishedAudioPort(callLocalExternAudioPort);
}
std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field)
{
pj_str_t name = pj_str((char*) field.c_str());
pjsip_generic_string_hdr *hdr = static_cast<pjsip_generic_string_hdr*>(pjsip_msg_find_hdr_by_name(msg, &name, NULL));
if (!hdr)
return "";
std::string value(hdr->hvalue.ptr, hdr->hvalue.slen);
size_t pos = value.find("\n");
if (pos != std::string::npos)
return value.substr(0, pos);
else
return "";
}
} // end anonymous namespace
std::vector<std::string> SIPVoIPLink::getAllIpInterfaceByName()
......
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