diff --git a/sflphone-common/src/Makefile.am b/sflphone-common/src/Makefile.am index 0d2b2da9cc12f78d4bf4898061de9359e26a5da6..10d240d25e40a2b237f61cb2dae6d7420bd2de44 100644 --- a/sflphone-common/src/Makefile.am +++ b/sflphone-common/src/Makefile.am @@ -62,7 +62,7 @@ noinst_LTLIBRARIES = libsflphone.la noinst_HEADERS = \ conference.h \ - voiplink.h \ + voiplink.h \ managerimpl.h \ manager.h \ global.h \ diff --git a/sflphone-common/src/sip/Makefile.am b/sflphone-common/src/sip/Makefile.am index 778494b0b6874fdf3e723ee7838905830cfe2cbf..da91f8995061a4fc426fcead66aa4a13e451891a 100644 --- a/sflphone-common/src/sip/Makefile.am +++ b/sflphone-common/src/sip/Makefile.am @@ -3,17 +3,20 @@ include $(top_srcdir)/globals.mak noinst_LTLIBRARIES = libsiplink.la libsiplink_la_SOURCES = \ + Pattern.cpp \ + SdesNegotiator.cpp \ sdp.cpp \ sdpmedia.cpp \ sipaccount.cpp \ sipcall.cpp \ - sipvoiplink.cpp + sipvoiplink.cpp noinst_HEADERS = \ + Pattern.h \ + SdesNegotiator.h \ sdp.h \ sdpmedia.h \ sipaccount.h \ sipcall.h \ - sipvoiplink.h - + sipvoiplink.h \ No newline at end of file diff --git a/sflphone-common/src/util/Pattern.cpp b/sflphone-common/src/sip/Pattern.cpp similarity index 97% rename from sflphone-common/src/util/Pattern.cpp rename to sflphone-common/src/sip/Pattern.cpp index 95186c5d689692cc30c1cf78d00e06e5aa66ebdb..cc62a6871e74db2f49c57a31f5d296227faa9c0f 100644 --- a/sflphone-common/src/util/Pattern.cpp +++ b/sflphone-common/src/sip/Pattern.cpp @@ -23,8 +23,7 @@ namespace sfl { -namespace util { -Pattern::Pattern (const std::string& pattern, const std::string& options = "") : +Pattern::Pattern (const std::string& pattern, const std::string& options) : _pattern (pattern), _ovector (NULL), _ovectorSize (0), @@ -304,11 +303,10 @@ std::vector<std::string> Pattern::split (void) tokenEnd = end(); } - substringSplitted.push_back (_subject.substr (tokenEnd + 1, + substringSplitted.push_back (_subject.substr (tokenEnd + 1, tokenStart - tokenEnd - 1)); - tokenStart - tokenEnd - 1)); return substringSplitted; } } -} + diff --git a/sflphone-common/src/sip/Pattern.h b/sflphone-common/src/sip/Pattern.h new file mode 100644 index 0000000000000000000000000000000000000000..b07c92acddbfd4466710c83fb6ce7e40d38e1383 --- /dev/null +++ b/sflphone-common/src/sip/Pattern.h @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Pierre-Luc Bacon <pierre-luc.bacon@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 __SFL_PATTERN_H__ +#define __SFL_PATTERN_H__ + +#include <stdexcept> +#include <string> +#include <vector> +#include <pcre.h> + +namespace sfl { + + /** + * Exception object that is thrown when + * an error occured while compiling the + * regular expression. + */ + class compile_error : public std::invalid_argument + { + public: + explicit compile_error(const std::string& error) : + std::invalid_argument(error) {} + }; + + /** + * Exception object that is thrown when + * an error occured while mathing a + * pattern to an expression. + */ + class match_error : public std::invalid_argument + { + public: + match_error(const std::string& error) : + std::invalid_argument(error) {} + }; + + /** + * This class implements in its way + * some of the libpcre library. + */ + + class Pattern { + + public: + + /** + * Constructor for a regular expression + * pattern evaluator/matcher. + * + * @param pattern + * The regular expression to + * be used for this instance. + */ + + Pattern(const std::string& pattern, + const std::string& options = ""); + + /** + * Destructor. Pcre pattern gets freed + * here. + */ + ~Pattern(); + + /** + * Assignment operator overloading. + * Set the regular expression + * to be used on subject strings + * and compile the regular expression + * from that string. + * + * @param pattern The new pattern + */ + void operator=(const std::string& pattern) { + _pattern = pattern; + compile(); + } + + void operator=(const char * pattern) { + _pattern = pattern; + compile(); + } + + /** + * Compile the regular expression + * from the pattern that was set for + * this object. + */ + void compile(void); + + /** + * Get the currently set regular expression + * that is used on subject strings + * + * @return The currently set pattern + */ + inline std::string getPattern(void) { return _pattern; } + + /** + * << operator overload. Sets the the subject + * for latter use on the >> operator. + * + * @param subject + * The expression to be evaluated + * by the pattern. + * + */ + void operator<<(const std::string& subject) { + _subject = subject; + } + + /** + * Get the start position of the overall match. + * + * @return the start position of the overall match. + */ + size_t start(void) const; + + /** + * Get the start position of the specified match. + * + * @param groupNumber The capturing group number. + * + * @return the start position of the specified match. + */ + size_t start(unsigned int groupNumber) const; + + /** + * Get the start position of the specified match. + * + * @param groupName The capturing group name. + * + * @return the start position of the specified match. + */ + size_t start(const std::string& groupName) const; + + /** + * Get the end position of the overall match. + * + * @return the end position of the overall match. + */ + size_t end(void) const; + + /** + * Get the end position of the specified match. + * + * @param groupNumber The capturing group number. + * + * @return the end position of the specified match. + */ + size_t end(unsigned int groupNumber) const; + + /** + * Get the end position of the specified match. + * + * @param groupName The capturing group name. + * + * @return the end position of the specified match. + */ + size_t end(const std::string& groupName) const; + + /** + * Get the number of capturing groups in the + * compiled regex. + * + * @return The number of capture groups. + * + * @pre The regular expression should have been + * compiled prior to the execution of this method. + */ + unsigned int getCaptureGroupCount(void); + + /** + * Get the substring matched in a capturing + * group (named or unnamed). + * + * This methods only performs a basic lookup + * inside its internal substring table. Thus, + * matches() should have been called prior to + * this method in order to obtain the desired + * output. + * + * @param groupName The name of the group + * + * @return the substring matched by the + * regular expression designated + * the group name. + */ + std::string group(const std::string& groupName); + + /** + * Get the substring matched in a named group. + * + * This methods only performs a basic lookup + * inside its internal substring table. Thus, + * matches() should have been called prior to + * this method in order to obtain the desired + * output. + * + * @param groupNumber The number of the group. + * + * @return the substring matched by the + * regular expression designated + * the group number. + */ + std::string group(int groupNumber); + + /** + * Similar to python's MatchObject.groups. Get all + * the substrings matched by the capture groups defined + * in the pattern. The complete (implicit) capture group + * is not returned : ie only groups from 1 up to the number + * of groups in the pattern are returned. + * + * @return A vector of stings that were matched by some + * capturing group in the pattern. + * + * @pre The regular expression should have been + * compiled prior to the execution of this method. + */ + std::vector<std::string> groups(void); + + /** + * Try to match the compiled pattern with a + * subject. + * + * @param subject Subject to be matched + * by the pattern. + * + * @return true If the subject matches the pattern, + * false otherwise. + * + * @pre The regular expression should have been + * compiled prior to the execution of this method. + * + * @post The internal substring table will be updated + * with the new matches. Therefore, subsequent + * calls to group may return different results. + */ + bool matches(const std::string& subject) throw(match_error); + + /** + * Try to match the compiled pattern with the implicit + * subject. + * + * @return true If the subject matches the pattern, + * false otherwise. + * + * @pre The regular expression should have been + * compiled prior to the execution of this method. + * + * @post The internal substring table will be updated + * with the new matches. Therefore, subsequent + * calls to group may return different results. + */ + bool matches(void) throw(match_error); + + /** + * Split the subject into a list of substrings. + * + * @return A vector of substrings. + * + * @pre The regular expression should have been + * compiled prior to the execution of this method. + * + * @post The internal subject won't be affected by this + * by this operation. In other words: subject_before = + * subject_after. + */ + std::vector<std::string> split(void); // throw(match_error); + + private: + /** + * The regular expression that represents that pattern. + */ + std::string _pattern; + + /** + * The optional subject string. + */ + std::string _subject; + + /** + * PCRE struct that + * contains the compiled regular + * expression + */ + pcre * _re; + + /** + * The internal output vector used by PCRE. + */ + int * _ovector; + + /** + * The size of the _ovector + */ + int _ovectorSize; + + /** + * Current offset in the _ovector; + */ + + int _offset[2]; + + /** + * The number of substrings matched after calling + * pcre_exec. + */ + int _count; + + /** + * PCRE options for this pattern. + */ + int _options; + + /** + * String representation of the options. + */ + std::string _optionsDescription; + }; +} + + +#endif diff --git a/sflphone-common/src/sip/SdesNegotiator.cpp b/sflphone-common/src/sip/SdesNegotiator.cpp index 74442abafee1aa5ca51b69cfec6e85c31f308b73..f0b837a453684149ae8efbc1ff07494d5e7cae1d 100644 --- a/sflphone-common/src/sip/SdesNegotiator.cpp +++ b/sflphone-common/src/sip/SdesNegotiator.cpp @@ -18,14 +18,14 @@ #include "SdesNegotiator.h" -#include "util/Pattern.h" +#include "Pattern.h" #include <iostream> #include <sstream> #include <algorithm> #include <stdexcept> -using namespace sfl::util; +using namespace sfl; struct CryptoAttribute { std::string tag; @@ -81,7 +81,7 @@ void SdesNegotiator::parse (void) "UNENCRYPTED_SRTCP|" \ "UNAUTHENTICATED_SRTP|" \ "FEC_ORDER=(?P<fecOrder>FEC_SRTP|SRTP_FEC)|" \ - "FEC_KEY=(?P<fecKey>" + keyParamsPattern.getPattern() + ")|" \ + "FEC_KEY=(?P<fecKey>" + keyParamsPattern->getPattern() + ")|" \ "WSH=(?P<wsh>[0-9]{1,2})|" \ "(?<!\\-)[[:graph:]]+))*", "g"); // srtp-session-extension @@ -102,11 +102,11 @@ void SdesNegotiator::parse (void) // Split the line into its component // that we will analyze further down. - generalSyntaxPattern << (*iter); + *generalSyntaxPattern << (*iter); std::vector<std::string> sdesLine; try { - sdesLine = generalSyntaxPattern.split(); + sdesLine = generalSyntaxPattern->split(); if (sdesLine.size() < 3) { throw parse_error ("Missing components in SDES line"); @@ -117,10 +117,10 @@ void SdesNegotiator::parse (void) // Check if the attribute starts with a=crypto // and get the tag for this line - tagPattern << sdesLine.at (0); + *tagPattern << sdesLine.at (0); try { - std::string tag = tagPattern.group ("tag"); + std::string tag = tagPattern->group ("tag"); std::cout << "tag = " << tag << std::endl; } catch (match_error& exception) { throw parse_error ("Error while parsing the tag field"); @@ -128,39 +128,39 @@ void SdesNegotiator::parse (void) // Check if the crypto suite is valid and retreive // its value. - cryptoSuitePattern << sdesLine.at (1); + *cryptoSuitePattern << sdesLine.at (1); try { - std::string cryptoSuite - cryptoSuite = cryptoSuitePattern.group ("cryptoSuite"); + std::string cryptoSuite; + cryptoSuite = cryptoSuitePattern->group ("cryptoSuite"); std::cout << "crypto-suite = " << cryptoSuite << std::endl; } catch (match_error& exception) { throw parse_error ("Error while parsing the crypto-suite field"); } // Parse one or more key-params field. - keyParamsPattern << sdesLine.at (2); + *keyParamsPattern << sdesLine.at (2); try { - while (keyParamsPattern.matches()) { + while (keyParamsPattern->matches()) { std::string srtpKeyMethod; - srtpKeyMethod = keyParamsMatched.group ("srtpKeyMethod"); + srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod"); std::cout << "srtp-key-method = " << srtpKeyMethod << std::endl; std::string srtpKeyInfo; - srtpKeyInfo = keyParamsPattern.group ("srtpKeyInfo"); + srtpKeyInfo = keyParamsPattern->group ("srtpKeyInfo"); std::cout << "srtp-key-info = " << srtpKeyInfo << std::endl; std::string lifetime; - lifetime = keyParamsPattern.group ("lifetime"); + lifetime = keyParamsPattern->group ("lifetime"); std::cout << "lifetime = " << lifetime << std::endl; - std::string mkiValue - mkiValue = keyParamsPattern.group ("mkiValue"); + std::string mkiValue; + mkiValue = keyParamsPattern->group ("mkiValue"); std::cout << "mkiValue = " << mkiValue << std::endl; std::string mkiLength; - mkiLength = keyParamsPattern.group ("mkiLength"); + mkiLength = keyParamsPattern->group ("mkiLength"); std::cout << "mkiLength = " << mkiLength << std::endl; } } catch (match_error& exception) { diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 45876d7ab87c59e33f166690a2aa322087d0dd3a..d4003365bcd6eb18fcb635d53bed99432bb8fcff 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -28,6 +28,7 @@ #include "sipcall.h" #include "sipaccount.h" #include "eventthread.h" +#include "SdesNegotiator.h" #include "dbus/dbusmanager.h" #include "dbus/callmanager.h" @@ -3216,6 +3217,15 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) pjmedia_sdp_attr *attribute; call->getLocalSDP()->get_remote_sdp_crypto_from_offer(remote_sdp, &attribute); + // create remote cryptografic offer + std::vector<std::string> remoteOffer; + + std::string attr(attribute->value.ptr, attribute->value.slen); + + remoteOffer.push_back(attr); + + // sfl::SdesNegotiator sdesnego(sfl::CryptoSuites, remoteOffer); + try { call->setAudioStart (true); call->getAudioRtp()->start(); diff --git a/sflphone-common/src/util/Pattern.h b/sflphone-common/src/util/Pattern.h deleted file mode 100644 index 676ecbd85ef966cdff2456b45ad03b3102aca18b..0000000000000000000000000000000000000000 --- a/sflphone-common/src/util/Pattern.h +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (C) 2009 Savoir-Faire Linux inc. - * Author: Pierre-Luc Bacon <pierre-luc.bacon@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 __SFL_PATTERN_H__ -#define __SFL_PATTERN_H__ - -#include <stdexcept> -#include <string> -#include <vector> -#include <pcre.h> - -namespace sfl { -namespace util { - /** - * Exception object that is thrown when - * an error occured while compiling the - * regular expression. - */ - class compile_error : public std::invalid_argument - { - public: - explicit compile_error(const std::string& error) : - std::invalid_argument(error) {} - }; - - /** - * Exception object that is thrown when - * an error occured while mathing a - * pattern to an expression. - */ - class match_error : public std::invalid_argument - { - public: - match_error(const std::string& error) : - std::invalid_argument(error) {} - }; - - /** - * This class implements in its way - * some of the libpcre library. - */ - - class Pattern { - - public: - - /** - * Constructor for a regular expression - * pattern evaluator/matcher. - * - * @param pattern - * The regular expression to - * be used for this instance. - */ - - Pattern(const std::string& pattern, - const std::string& options); - - /** - * Destructor. Pcre pattern gets freed - * here. - */ - ~Pattern(); - - /** - * Assignment operator overloading. - * Set the regular expression - * to be used on subject strings - * and compile the regular expression - * from that string. - * - * @param pattern The new pattern - */ - void operator=(const std::string& pattern) { - _pattern = pattern; - compile(); - } - - void operator=(const char * pattern) { - _pattern = pattern; - compile(); - } - - /** - * Compile the regular expression - * from the pattern that was set for - * this object. - */ - void compile(void); - - /** - * Get the currently set regular expression - * that is used on subject strings - * - * @return The currently set pattern - */ - inline std::string getPattern(void) { return _pattern; } - - /** - * << operator overload. Sets the the subject - * for latter use on the >> operator. - * - * @param subject - * The expression to be evaluated - * by the pattern. - * - */ - void operator<<(const std::string& subject) { - _subject = subject; - } - - /** - * Get the start position of the overall match. - * - * @return the start position of the overall match. - */ - size_t start(void) const; - - /** - * Get the start position of the specified match. - * - * @param groupNumber The capturing group number. - * - * @return the start position of the specified match. - */ - size_t start(unsigned int groupNumber) const; - - /** - * Get the start position of the specified match. - * - * @param groupName The capturing group name. - * - * @return the start position of the specified match. - */ - size_t start(const std::string& groupName) const; - - /** - * Get the end position of the overall match. - * - * @return the end position of the overall match. - */ - size_t end(void) const; - - /** - * Get the end position of the specified match. - * - * @param groupNumber The capturing group number. - * - * @return the end position of the specified match. - */ - size_t end(unsigned int groupNumber) const; - - /** - * Get the end position of the specified match. - * - * @param groupName The capturing group name. - * - * @return the end position of the specified match. - */ - size_t end(const std::string& groupName) const; - - /** - * Get the number of capturing groups in the - * compiled regex. - * - * @return The number of capture groups. - * - * @pre The regular expression should have been - * compiled prior to the execution of this method. - */ - unsigned int getCaptureGroupCount(void); - - /** - * Get the substring matched in a capturing - * group (named or unnamed). - * - * This methods only performs a basic lookup - * inside its internal substring table. Thus, - * matches() should have been called prior to - * this method in order to obtain the desired - * output. - * - * @param groupName The name of the group - * - * @return the substring matched by the - * regular expression designated - * the group name. - */ - std::string group(const std::string& groupName); - - /** - * Get the substring matched in a named group. - * - * This methods only performs a basic lookup - * inside its internal substring table. Thus, - * matches() should have been called prior to - * this method in order to obtain the desired - * output. - * - * @param groupNumber The number of the group. - * - * @return the substring matched by the - * regular expression designated - * the group number. - */ - std::string group(int groupNumber); - - /** - * Similar to python's MatchObject.groups. Get all - * the substrings matched by the capture groups defined - * in the pattern. The complete (implicit) capture group - * is not returned : ie only groups from 1 up to the number - * of groups in the pattern are returned. - * - * @return A vector of stings that were matched by some - * capturing group in the pattern. - * - * @pre The regular expression should have been - * compiled prior to the execution of this method. - */ - std::vector<std::string> groups(void); - - /** - * Try to match the compiled pattern with a - * subject. - * - * @param subject Subject to be matched - * by the pattern. - * - * @return true If the subject matches the pattern, - * false otherwise. - * - * @pre The regular expression should have been - * compiled prior to the execution of this method. - * - * @post The internal substring table will be updated - * with the new matches. Therefore, subsequent - * calls to group may return different results. - */ - bool matches(const std::string& subject) throw(match_error); - - /** - * Try to match the compiled pattern with the implicit - * subject. - * - * @return true If the subject matches the pattern, - * false otherwise. - * - * @pre The regular expression should have been - * compiled prior to the execution of this method. - * - * @post The internal substring table will be updated - * with the new matches. Therefore, subsequent - * calls to group may return different results. - */ - bool matches(void) throw(match_error); - - /** - * Split the subject into a list of substrings. - * - * @return A vector of substrings. - * - * @pre The regular expression should have been - * compiled prior to the execution of this method. - * - * @post The internal subject won't be affected by this - * by this operation. In other words: subject_before = - * subject_after. - */ - std::vector<std::string> split(void) throw(match_error); - - private: - /** - * The regular expression that represents that pattern. - */ - std::string _pattern; - - /** - * The optional subject string. - */ - std::string _subject; - - /** - * PCRE struct that - * contains the compiled regular - * expression - */ - pcre * _re; - - /** - * The internal output vector used by PCRE. - */ - int * _ovector; - - /** - * The size of the _ovector - */ - int _ovectorSize; - - /** - * Current offset in the _ovector; - */ - - int _offset[2]; - - /** - * The number of substrings matched after calling - * pcre_exec. - */ - int _count; - - /** - * PCRE options for this pattern. - */ - int _options; - - /** - * String representation of the options. - */ - std::string _optionsDescription; - }; -} -} - -#endif