Finally a string manipulating boost header was found ;-).
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 11 Aug 2009 07:55:53 +0000 (09:55 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 11 Aug 2009 07:55:53 +0000 (09:55 +0200)
Replaced own insecure to_lower with boost::algorithm::string::to_lower_copy.

src/config.cpp

index 458ed9a..af4308c 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/archive/archive_exception.hpp>
 #include <boost/serialization/export.hpp>
 #include <boost/serialization/shared_ptr.hpp>
+#include <boost/algorithm/string.hpp>
 
 // Following boost macros are needed for serialization of derived classes through a base class pointer (Service *).
 BOOST_CLASS_EXPORT_GUID(ODS, "ODS")
@@ -32,6 +33,7 @@ BOOST_CLASS_EXPORT_GUID(DHS, "DHS")
 
 namespace po = boost::program_options;
 namespace fs = boost::filesystem;
+namespace ba = boost::algorithm;
 
 using namespace std;
 
@@ -258,7 +260,7 @@ int Config::parse_cmd_line(int argc, char *argv[])
             string login = VariablesMap["login"].as<string>();
             string password = VariablesMap["password"].as<string>();
 
-            protocol = to_lower(protocol);
+            protocol = ba::to_lower_copy(protocol);
 
             Service::Ptr service = create_service(protocol,host,login,password);
             if ( service )
@@ -332,23 +334,6 @@ Service::Ptr Config::create_service(const string &protocol,const string &hostnam
 
 
 /**
- * Converts first ten characters of given string to lowercase.
- * @param input String.
- * @return String in lowercase.
- */
-string Config::to_lower(string input) const
-{
-    int i = 0;
-    while ( input[i] && i<10 )
-    {
-        input[i] = tolower(input[i]);
-        i++;
-    }
-    return input;
-}
-
-
-/**
  * Loads a service config file, invoked by load_config_from_files.
  * @param full_filename Filename of the service config file to load.
  * @return 0 if all is fine, -1 otherwise.
@@ -375,7 +360,7 @@ int Config::load_service_config_file(const string& full_filename)
                 string login = vm["login"].as<string>();
                 string password = vm["password"].as<string>();
 
-                protocol = to_lower(protocol);
+                protocol = ba::to_lower_copy(protocol);
 
                 Service::Ptr service = create_service(protocol,host,login,password);
                 if ( service )