Ticket #13315: 0002-Use-QUrl-internally-in-MythCoreContext-GenMythURL.patch

File 0002-Use-QUrl-internally-in-MythCoreContext-GenMythURL.patch, 2.7 KB (added by ijc, 14 months ago)

[PATCH 2/2] Use QUrl internally in MythCoreContext::GenMythURL

  • mythtv/libs/libmythbase/mythcorecontext.cpp

    From afa933405bf8c43044b2982287b67e0206c5d1e6 Mon Sep 17 00:00:00 2001
    From: Ian Campbell <ijc@hellion.org.uk>
    Date: Sat, 8 Dec 2018 09:32:07 +0000
    Subject: [PATCH 2/2] Use QUrl internally in MythCoreContext::GenMythURL
    
    This ensures that everything is properly escaped.
    
    Really the use of QUrl should be extended right up through the call chain but
    that is a much bigger change and is left for another time.
    
    Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
    ---
     mythtv/libs/libmythbase/mythcorecontext.cpp | 31 ++++++++-------------
     1 file changed, 11 insertions(+), 20 deletions(-)
    
    diff --git a/mythtv/libs/libmythbase/mythcorecontext.cpp b/mythtv/libs/libmythbase/mythcorecontext.cpp
    index c90b34a699..66efa590c6 100644
    a b QString MythCoreContext::GenMythURL(QString host, QString port, QString path, QS 
    753753
    754754QString MythCoreContext::GenMythURL(QString host, int port, QString path, QString storageGroup)
    755755{
    756     QString ret;
     756    QUrl ret;
    757757
    758     QString m_storageGroup;
    759758    QString m_host;
    760     QString m_port;
    761759
    762760    QHostAddress addr(host);
    763761    if (!addr.isNull())
    QString MythCoreContext::GenMythURL(QString host, int port, QString path, QStrin 
    767765                                          "(ID). This is invalid.").arg(host).arg(path));
    768766    }
    769767
    770 
    771     if (!storageGroup.isEmpty())
    772         m_storageGroup = storageGroup + "@";
    773 
    774768    m_host = host;
    775769
    776770    // Basically if it appears to be an IPv6 IP surround the IP with [] otherwise don't bother
    777771    if (!addr.isNull() && addr.protocol() == QAbstractSocket::IPv6Protocol)
    778772        m_host = "[" + addr.toString().toLower() + "]";
    779773
     774    ret.setScheme("myth");
     775    if (!storageGroup.isEmpty())
     776        ret.setUserName(storageGroup);
     777    ret.setHost(m_host);
    780778    if (port > 0 && port != 6543)
    781         m_port = QString(":%1").arg(port);
    782     else
    783         m_port = "";
    784 
    785     QString seperator = "/";
    786     if (path.startsWith("/"))
    787         seperator = "";
    788 
    789     // IPv6 addresses may contain % followed by a digit which causes .arg()
    790     // to fail, so use append instead.
    791     ret = QString("myth://").append(m_storageGroup).append(m_host).append(m_port).append(seperator).append(path);
     779        ret.setPort(port);
     780  if (!path.startsWith("/"))
     781          path = QString("/") + path;
     782    ret.setPath(path);
    792783
    793784#if 0
    794785    LOG(VB_GENERAL, LOG_DEBUG, LOC +
    795         QString("GenMythURL returning %1").arg(ret));
     786        QString("GenMythURL returning %1").arg(ret.toString()));
    796787#endif
    797788
    798     return ret;
     789    return ret.toString();
    799790}
    800791
    801792QString MythCoreContext::GetMasterHostPrefix(const QString &storageGroup,