diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-12-05 22:50:33 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-01-09 23:55:25 +0100 |
commit | f405849b49614254f42eb3ee6147434458978623 (patch) | |
tree | ecf06af8ba1b049504957d4e2797ead26c81ec3e /src/client.cpp | |
parent | f5172d4fcc10be73b72c1033cf9357a4dfe3544d (diff) | |
download | mana-f405849b49614254f42eb3ee6147434458978623.tar.gz mana-f405849b49614254f42eb3ee6147434458978623.tar.bz2 mana-f405849b49614254f42eb3ee6147434458978623.tar.xz mana-f405849b49614254f42eb3ee6147434458978623.zip |
Made the client able to remove the port from update urls.
Resolves: Mana-Mantis #381.
Reviewed-by: Ablu.
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/src/client.cpp b/src/client.cpp index 642d9376..2d4ac8cc 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1267,47 +1267,31 @@ void Client::initConfiguration() */ void Client::initUpdatesDir() { - std::stringstream updates; - // If updatesHost is currently empty, fill it from config file if (mUpdateHost.empty()) - { mUpdateHost = config.getStringValue("updatehost"); - } - // Don't go out of range int he next check - if (mUpdateHost.length() < 2) + // Exit on empty update host. + if (mUpdateHost.empty()) return; - // Remove any trailing slash at the end of the update host - if (!mUpdateHost.empty() && mUpdateHost.at(mUpdateHost.size() - 1) == '/') - mUpdateHost.resize(mUpdateHost.size() - 1); + logger->log("Setting update host: %s", mUpdateHost.c_str()); - // Parse out any "http://" or "ftp://", and set the updates directory - size_t pos; - pos = mUpdateHost.find("://"); - if (pos != mUpdateHost.npos) - { - if (pos + 3 < mUpdateHost.length() && !mUpdateHost.empty()) - { - updates << "updates/" << mUpdateHost.substr(pos + 3); - mUpdatesDir = updates.str(); - } - else - { - logger->log("Error: Invalid update host: %s", mUpdateHost.c_str()); - errorMessage = strprintf(_("Invalid update host: %s"), - mUpdateHost.c_str()); - mState = STATE_ERROR; - } - } - else + std::string updateHost = getHostNameFromURL(mUpdateHost); + + // Exit on a wrong update host. + if (updateHost.length() < 2) { - logger->log("Warning: no protocol was specified for the update host"); - updates << "updates/" << mUpdateHost; - mUpdatesDir = updates.str(); + // Show the original updateHostname in the error message. + errorMessage = strprintf(_("Invalid update host: %s"), + mUpdateHost.c_str()); + mState = STATE_ERROR; + return; } + mUpdateHost = updateHost; + mUpdatesDir = "updates/" + mUpdateHost; + ResourceManager *resman = ResourceManager::getInstance(); // Verify that the updates directory exists. Create if necessary. @@ -1330,13 +1314,17 @@ void Client::initUpdatesDir() { logger->log("Error: %s can't be made, but doesn't exist!", newDir.c_str()); - errorMessage = _("Error creating updates directory!"); + errorMessage = + strprintf(_("Error creating updates directory!\n(%s)"), + newDir.c_str()); mState = STATE_ERROR; } #else logger->log("Error: %s/%s can't be made, but doesn't exist!", mLocalDataDir.c_str(), mUpdatesDir.c_str()); - errorMessage = _("Error creating updates directory!"); + errorMessage = + strprintf(_("Error creating updates directory!\n(%s/%s)"), + mLocalDataDir.c_str(), mUpdatesDir.c_str()); mState = STATE_ERROR; #endif } |