Corrected implementation of GnuDIP HTTP update protocol.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 21 Jun 2010 11:06:09 +0000 (13:06 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 21 Jun 2010 11:06:09 +0000 (13:06 +0200)
src/service_gnudip.cpp
src/service_gnudip.hpp

index 8c332c5..4f757e2 100644 (file)
@@ -97,11 +97,11 @@ map<string,string> ServiceGnudip::parse_initial_request(const string& curl_data)
     map<string,string> response;
 
     // regex for salt
-    boost::regex expr_salt("<meta name=\"salt\" content=\"(.*)\">");
+    boost::regex expr_salt("<meta name=\"salt\" content=\"([^\"]*)\"");
     // regex for time
-    boost::regex expr_time("<meta name=\"time\" content=\"(.*)\">");
+    boost::regex expr_time("<meta name=\"time\" content=\"([^\"]*)\"");
     // regex for sign
-    boost::regex expr_sign("<meta name=\"sign\" content=\"(.*)\">");
+    boost::regex expr_sign("<meta name=\"sign\" content=\"([^\"]*)\"");
 
     boost::smatch matches;
 
@@ -149,6 +149,35 @@ map<string,string> ServiceGnudip::parse_initial_request(const string& curl_data)
 
 
 /**
+ * Parses the data received from the update request, which should contain the return code.
+ * @param curl_data The complete received curl data.
+ * @return A string containing the return code of the update request.
+ */
+string ServiceGnudip::parse_return_code(const string& curl_data) const
+{
+    string return_code;
+
+    // regex for return code
+    boost::regex expr_retc("<meta name=\"retc\" content=\"([^\"]*)\"");
+    boost::smatch matches;
+
+    // Get the return code out of received http data
+    if ( boost::regex_search(curl_data,matches,expr_retc) )
+    {
+        return_code = matches[1].str();
+        get_logger()->print_regex_match(expr_retc.str(),matches[1].str());
+    }
+    else
+    {
+        get_logger()->print_no_regex_match(expr_retc.str(),curl_data);
+        return return_code;
+    }
+
+    return return_code;
+}
+
+
+/**
  * Get the assembled update url.
  * @param salt Salt from the initial request
  * @param time Time from the initial request
@@ -170,7 +199,9 @@ string ServiceGnudip::assemble_update_url(const string& salt, const string& curr
         url.append("&user=");
         url.append(get_login());
         url.append("&domn=");
-        url.append(get_hostname());
+        string fqhn = get_hostname();
+        string domain = fqhn.substr(fqhn.find('.')+1);
+        url.append(domain);
         url.append("&pass=");
         url.append(secret);
         url.append("&reqc=0&addr=");
@@ -274,7 +305,8 @@ int ServiceGnudip::perform_update(const std::string& ip)
             if ( http_status_code == 200 )
             {
                 // parse the update request return code
-                string update_return_code = HTTPHelp->get_curl_data();
+                curl_data = HTTPHelp->get_curl_data();
+                string update_return_code = parse_return_code(curl_data);
                 if ( update_return_code == "0" )
                 {
                     return 0;
index 3c61aaf..885ed54 100644 (file)
@@ -39,6 +39,7 @@ private:
     std::string assemble_base_url(const std::string& gnudip_server) const;
     std::map<std::string,std::string> parse_initial_request(const std::string& curl_data) const;
     std::string assemble_update_url(const std::string& salt, const std::string& curr_time, const std::string& sign, const std::string& secret, const std::string& ip) const;
+    std::string parse_return_code(const std::string& curl_data) const;
 
 public: