Fix 'occurred' typo
[bpdyndnsd] / src / util.cpp
index 8b795fc..8aa5bd9 100644 (file)
@@ -7,9 +7,10 @@
  * @license GPLv2
 */
 
-#include "util.h"
+#include "util.hpp"
 
 #include <sstream>
+#include <iomanip>
 #include <openssl/evp.h>
 #include <boost/algorithm/string.hpp>
 
@@ -46,7 +47,6 @@ std::string compute_md5_digest(std::string data)
     if ( EVP_DigestInit_ex(&mdctx, md, NULL) == 0 )
     {
         EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-        EVP_cleanup();  /*lint !e534 */
         throw std::invalid_argument("Could not set up digest context correctly");
     }
 
@@ -54,7 +54,6 @@ std::string compute_md5_digest(std::string data)
     if ( data.empty() )
     {
         EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-        EVP_cleanup();  /*lint !e534 */
         throw std::invalid_argument("Passed data is empty");
     }
 
@@ -62,7 +61,6 @@ std::string compute_md5_digest(std::string data)
     if ( EVP_DigestUpdate(&mdctx, data.c_str(), data.size()) == 0 )
     {
         EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-        EVP_cleanup();  /*lint !e534 */
         throw std::invalid_argument("Could not hash data into digest context");
     }
 
@@ -70,7 +68,6 @@ std::string compute_md5_digest(std::string data)
     if ( EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0 )
     {
         EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-        EVP_cleanup();  /*lint !e534 */
         throw std::invalid_argument("Could not retrieve digest value");
     }
 
@@ -78,13 +75,11 @@ std::string compute_md5_digest(std::string data)
     if ( (md_len == 0) || (EVP_MD_CTX_size(&mdctx) == 0) )
     {
         EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-        EVP_cleanup();  /*lint !e534 */
         throw std::invalid_argument("Retrieved invalid digest value");
     }
 
     // Internal cleanup of the digest content.
     EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
-    EVP_cleanup();  /*lint !e534 */
 
     // Convert md5 digest C string to hex.
     std::ostringstream oss_digest_md5_hex;
@@ -92,7 +87,8 @@ std::string compute_md5_digest(std::string data)
     {
         // We have to do a static cast to an decimal representation, cause otherwise ostringstream would interpret
         // the stream as a character and output the character representation of the hex value.
-        oss_digest_md5_hex << std::hex << static_cast<unsigned short>(md_value[i]);
+        oss_digest_md5_hex << std::nouppercase << std::setw(2) << std::setfill('0')
+                           << std::hex << static_cast<int>(static_cast<unsigned char>(md_value[i]));
     }
 
     return oss_digest_md5_hex.str();
@@ -101,24 +97,9 @@ std::string compute_md5_digest(std::string data)
 
 /**
  * Get the status code from the given data.
- * @param data The data containing the status code at front, limited by " ".
- * @return The parsed status code.
- */
-std::string parse_status_code(std::string data)
-{
-    std::list<std::string> tokens;
-    boost::algorithm::split(tokens,data,boost::is_any_of(" "));
-    if ( tokens.empty() )
-        return "";
-    return tokens.front();
-}
-
-
-/**
- * Get the status code from the given data.
- * @param data The data containing the status code at front, limited by " ".
+ * @param data The data containing the status code at front, limited by delimiter.
  * @param delimiter The delimiter to use.
- * @return The parsed status code.
+ * @return The parsed status code
  */
 std::string parse_status_code(std::string data, std::string delimiter)
 {