Skip to content
Snippets Groups Projects
Commit 3f302130 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Merge branch 'url_hook'

parents 61ec6b7c 35ea93aa
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,8 @@ AC_CONFIG_FILES([src/Makefile \
src/dbus/Makefile \
src/plug-in/audiorecorder/Makefile \
src/plug-in/Makefile \
src/plug-in/test/Makefile])
src/plug-in/test/Makefile \
src/hooks/Makefile])
dnl Unitary test section
AC_CONFIG_FILES([test/Makefile])
......
......@@ -33,7 +33,7 @@ main (int argc, char *argv[])
gtk_init (&argc, &argv);
g_print("%s\n", PACKAGE_STRING);
g_print("Copyright (c) 2005 2006 2007 2008 Savoir-faire Linux Inc.\n");
g_print("Copyright (c) 2005 2006 2007 2008 2009 Savoir-faire Linux Inc.\n");
g_print("This is free software. You may redistribute copies of it under the terms of\n\
the GNU General Public License Version 3 <http://www.gnu.org/licenses/gpl.html>.\n\
There is NO WARRANTY, to the extent permitted by law.\n\n");
......
......@@ -13,7 +13,7 @@ IAXSOURCES =
IAXHEADERS =
endif
SUBDIRS = audio config dbus plug-in
SUBDIRS = audio config dbus plug-in hooks
# Add here the cpp files to be build with sflphone
sflphoned_SOURCES = \
......@@ -83,6 +83,7 @@ libsflphone_la_LIBADD = \
./config/libconfig.la \
./plug-in/libplugin.la \
./plug-in/audiorecorder/libaudiorecorder.la \
./hooks/libhooks.la \
$(IAX_LIBS)
libsflphone_la_SOURCES =
......@@ -32,7 +32,7 @@
#include <map>
#include <vector>
#define SFLPHONED_VERSION "0.9.3" /** Version number */
#define SFLPHONED_VERSION "0.9.4" /** Version number */
#define HOMEDIR (getenv ("HOME")) /** Home directory */
......@@ -135,7 +135,7 @@ static const SOUND_FORMAT INT32 = 0x8;
#define DEFAULT_SIP_PORT 5060
#define HOOK_DEFAULT_SIP_FIELD "X-Call-url"
#define HOOK_DEFAULT_SIP_FIELD "X-sflphone-url"
#define HOOK_DEFAULT_URL_COMMAND "x-www-browser"
......
SUBDIRS =
noinst_LTLIBRARIES = libhooks.la
libhooks_la_SOURCES = \
urlhook.cpp urlhook.h
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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.
*/
#include "urlhook.h"
#include <iostream>
UrlHook::UrlHook () { }
UrlHook::~UrlHook () { }
void UrlHook::addAction (std::string field_value, std::string command){
std::string command_bg;
/* Execute the command in the background to not block the application */
command_bg = command + " " + field_value + "&" ;
/* Execute a system call */
RUN_COMMAND (command_bg.c_str());
}
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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.
*/
#ifndef URL_HOOK_H
#define URL_HOOK_H
#include <string>
#include <stdlib.h>
#define RUN_COMMAND(command) system(command);
class UrlHook {
public:
/**
* Constructor
*/
UrlHook ();
/**
* Destructor
*/
~UrlHook ();
void addAction (std::string, std::string);
private:
};
#endif // URL_HOOK_H
......@@ -51,6 +51,8 @@ bool setCallAudioLocal(SIPCall* call, std::string localIP, bool stun, std::strin
void handle_incoming_options (pjsip_rx_data *rxdata);
std::string fetch_header_value (pjsip_msg *msg, std::string field);
/*
* The global pool factory
*/
......@@ -77,6 +79,11 @@ pjsip_module _mod_ua;
pj_thread_t *thread;
pj_thread_desc desc;
/*
* Url hook instance
*/
UrlHook *urlhook;
/**
* Get the number of voicemail waiting in a SIP message
*/
......@@ -171,6 +178,8 @@ SIPVoIPLink* SIPVoIPLink::_instance = NULL;
// to get random number for RANDOM_PORT
srand (time(NULL));
urlhook = new UrlHook ();
/* Start pjsip initialization step */
init();
}
......@@ -1943,6 +1952,19 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e
return true;
}
/******************************************* URL HOOK *********************************************/
std::string header_value;
header_value = fetch_header_value (rdata->msg_info.msg, Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD));
if (header_value!=""){
urlhook->addAction (header_value,
Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND));
}
/************************************************************************************************/
// Generate a new call ID for the incoming call!
id = Manager::instance().getNewCallID();
call = new SIPCall(id, Call::Incoming, _pool);
......@@ -2534,4 +2556,31 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e
return true;
}
std::string fetch_header_value (pjsip_msg *msg, std::string field) {
pj_str_t name;
pjsip_generic_string_hdr * hdr;
std::string value, url;
size_t pos;
std::cout << "fetch header value" << std::endl;
/* Convert the field name into pjsip type */
name = pj_str ((char*)field.c_str());
/* Get the header value and convert into string*/
hdr = (pjsip_generic_string_hdr*) pjsip_msg_find_hdr_by_name (msg, &name, NULL);
if (!hdr)
return "";
value = hdr->hvalue.ptr;
if ( (pos=value.find ("\n")) == std::string::npos) {
return "";
}
url = value.substr (0, pos);
return url;
}
......@@ -23,6 +23,7 @@
#define SIPVOIPLINK_H
#include "voiplink.h"
#include "hooks/urlhook.h"
//////////////////////////////
/* PJSIP imports */
......
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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.
*/
// Cppunit import
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <assert.h>
/*
* @file hooksTest.cpp
* @brief Regroups unitary tests related to the hooks.
*/
#ifndef _HOOKS_TEST_
#define _HOOKS_TEST_
class HooksTest : public CppUnit::TestCase {
/**
* Use cppunit library macros to add unit test the factory
*/
CPPUNIT_TEST_SUITE (HooksTest);
CPPUNIT_TEST ();
CPPUNIT_TEST_SUITE_END();
public:
HooksTest() : CppUnit::TestCase("Hooks implementation Tests") {}
/*
* Code factoring - Common resources can be initialized here.
* This method is called by unitcpp before each test
*/
void setUp();
/*
* Code factoring - Common resources can be released here.
* This method is called by unitcpp after each test
*/
inline void tearDown ();
void testUnloadPlugins ();
private:
};
/* Register our test module */
CPPUNIT_TEST_SUITE_REGISTRATION (HooksTest);
#
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment