1
/****************************************************************************
2
* Copyright (C) 2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Lesser General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
***************************************************************************/
20
constexpr const char* URI::schemeNames[];
22
URI::URI(const QString& other):QString()
23
,m_Parsed(false),m_HeaderType(SchemeType::NONE)
25
m_Stripped = strip(other,m_HeaderType);
26
(*static_cast<QString*>(this)) = m_Stripped ;
29
URI::URI(const URI& o):QString(),m_Parsed(o.m_Parsed),m_Hostname(o.m_Hostname),
30
m_HeaderType(o.m_HeaderType),m_Userinfo(o.m_Userinfo),m_Stripped(o.m_Stripped)
32
(*static_cast<QString*>(this)) = o.m_Stripped;
35
///Strip out <sip:****> from the URI
36
QString URI::strip(const QString& uri, SchemeType& sheme)
40
int start(0),end(uri.size()-1); //Other type of comparisons were too slow
41
if (end > 5 && uri[0] == '<' ) {
43
sheme = uri[1] == 's'?SchemeType::SIP:SchemeType::IAX;
46
else if (uri[5] == ':') {
47
sheme = SchemeType::SIPS;
51
if (end && uri[end] == '>')
54
//TODO there may be a ';' section with arguments, check
56
return uri.mid(start,end-start+1);
59
///Return the domaine of an URI (<sip:12345@example.com>)
60
QString URI::hostname() const
63
const_cast<URI*>(this)->parse();
67
bool URI::hasHostname() const
70
const_cast<URI*>(this)->parse();
71
return !m_Hostname.isEmpty();
74
///Keep a cache of the values to avoid re-parsing them
77
if (indexOf('@') != -1) {
78
const QStringList splitted = split('@');
79
m_Hostname = splitted[1];//splitted[1].left(splitted[1].size())
80
m_Userinfo = splitted[0];
85
QString URI::userinfo() const
88
const_cast<URI*>(this)->parse();
93
* Some feature, like SIP presence, require a properly formatted USI
95
QString URI::fullUri() const
97
return QString("<%1%2>")
98
.arg(schemeNames[static_cast<int>(m_HeaderType == SchemeType::NONE?SchemeType::SIP:m_HeaderType)])
b'\\ No newline at end of file'