Parcourir la source

Add Database for Inform and CheckQueue (phase 1)

                                  Inform : Done

                                  CheckQueue: In progress....

                                  exception handling on json parsing

                                  update database after sending task to cpe
Sasan Torabkheslat il y a 5 ans
Parent
commit
fd42eadffa
3 fichiers modifiés avec 109 ajouts et 105 suppressions
  1. 62 36
      .idea/workspace.xml
  2. 47 41
      main.cpp
  3. 0 28
      soapcwmpService.cpp

+ 62 - 36
.idea/workspace.xml

@@ -13,20 +13,8 @@
   <component name="ChangeListManager">
     <list default="true" id="6938f4e3-b9b8-4c34-bea6-8fc5ace411e6" name="Default Changelist" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/CMakeError.log" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/CMakeError.log" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/CMakeOutput.log" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/CMakeOutput.log" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/DependInfo.cmake" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/DependInfo.cmake" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/depend.make" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/depend.make" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/flags.make" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/flags.make" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/link.txt" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/FDIACS.dir/link.txt" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/Makefile.cmake" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/Makefile.cmake" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/clion-log.txt" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/clion-log.txt" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/cmake-build-debug/FDIACS.cbp" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/FDIACS.cbp" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/soapcwmpService.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/soapcwmpService.cpp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/soapcwmpService.h" beforeDir="false" afterPath="$PROJECT_DIR$/soapcwmpService.h" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/stdsoap2.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/stdsoap2.cpp" afterDir="false" />
     </list>
     <ignored path="$PROJECT_DIR$/cmake-build-debug/" />
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -41,23 +29,34 @@
   </component>
   <component name="FileEditorManager">
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
-      <file pinned="false" current-in-tab="false">
+      <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/main.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="555">
-              <caret line="675" column="26" selection-start-line="675" selection-start-column="26" selection-end-line="675" selection-end-column="26" />
+            <state relative-caret-position="278">
+              <caret line="673" column="20" selection-start-line="673" selection-start-column="20" selection-end-line="673" selection-end-column="20" />
               <folding>
+                <element signature="e#604#788#0" />
+                <element signature="e#790#856#0" />
+                <element signature="e#858#1107#0" />
+                <element signature="e#1109#1140#0" />
+                <element signature="e#5722#6744#0" />
+                <element signature="e#6746#7432#0" />
+                <element signature="e#7434#8491#0" />
+                <element signature="e#8494#10862#0" />
+                <element signature="e#13027#33145#0" />
+                <element signature="e#16266#16299#0" />
+                <element signature="e#25273#25300#0" />
                 <element signature="e#33694#33915#0" />
               </folding>
             </state>
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="true">
+      <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/soapcwmpService.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="353">
-              <caret line="1015" column="30" selection-start-line="1015" selection-start-column="30" selection-end-line="1015" selection-end-column="30" />
+            <state relative-caret-position="594">
+              <caret line="1029" selection-start-line="1029" selection-end-line="1029" />
               <folding>
                 <element signature="e#0#614#0" />
                 <element signature="e#646#784#0" />
@@ -143,7 +142,6 @@
       <find>NO</find>
       <find>NO_DA</find>
       <find>NO_BOD</find>
-      <find>cerr</find>
       <find>No Content Recieved at</find>
       <find>13</find>
       <find>SOAP message expected</find>
@@ -155,6 +153,7 @@
       <find>CheckQueue</find>
       <find>CheckQueue...</find>
       <find>Debug</find>
+      <find>cerr</find>
     </findStrings>
   </component>
   <component name="Git.Settings">
@@ -178,8 +177,8 @@
         <option value="$PROJECT_DIR$/CMakeLists.txt" />
         <option value="$PROJECT_DIR$/stdsoap2.cpp" />
         <option value="$PROJECT_DIR$/soapcwmpService.h" />
-        <option value="$PROJECT_DIR$/main.cpp" />
         <option value="$PROJECT_DIR$/soapcwmpService.cpp" />
+        <option value="$PROJECT_DIR$/main.cpp" />
       </list>
     </option>
   </component>
@@ -281,7 +280,7 @@
       <workItem from="1577725955348" duration="10970000" />
       <workItem from="1577875009389" duration="1490000" />
       <workItem from="1577888800205" duration="3932000" />
-      <workItem from="1578124895054" duration="40197000" />
+      <workItem from="1578124895054" duration="43172000" />
     </task>
     <task id="LOCAL-00001" summary="Disable InfluxDB">
       <created>1572183659791</created>
@@ -311,11 +310,25 @@
       <option name="project" value="LOCAL" />
       <updated>1577620646091</updated>
     </task>
-    <option name="localTasksCounter" value="5" />
+    <task id="LOCAL-00005" summary="Add Database for Inform and CheckQueue (phase 1)&#10;&#10;Inform : Done&#10;&#10;CheckQueue: In progress....">
+      <created>1578234091498</created>
+      <option name="number" value="00005" />
+      <option name="presentableId" value="LOCAL-00005" />
+      <option name="project" value="LOCAL" />
+      <updated>1578234091499</updated>
+    </task>
+    <task id="LOCAL-00006" summary="Add Database for Inform and CheckQueue (phase 1)&#10;&#10;Inform : Done&#10;&#10;CheckQueue: In progress....&#10;&#10;exception handling on json parsing">
+      <created>1578234461233</created>
+      <option name="number" value="00006" />
+      <option name="presentableId" value="LOCAL-00006" />
+      <option name="project" value="LOCAL" />
+      <updated>1578234461233</updated>
+    </task>
+    <option name="localTasksCounter" value="7" />
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="298731000" />
+    <option name="totallyTimeSpent" value="301706000" />
   </component>
   <component name="TodoView" selected-index="3">
     <todo-panel id="selected-file">
@@ -389,7 +402,9 @@
     <MESSAGE value="Add Download Response (not completed)" />
     <MESSAGE value="Add Download Response (completed)" />
     <MESSAGE value="Add Database for Inform and CheckQueue (phase 1)&#10;&#10;Inform : Done&#10;&#10;CheckQueue: In progress...." />
-    <option name="LAST_COMMIT_MESSAGE" value="Add Database for Inform and CheckQueue (phase 1)&#10;&#10;Inform : Done&#10;&#10;CheckQueue: In progress...." />
+    <MESSAGE value="Add Database for Inform and CheckQueue (phase 1)&#10;&#10;Inform : Done&#10;&#10;CheckQueue: In progress....&#10;&#10;exception handling on json parsing" />
+    <MESSAGE value="Add Database for Inform and CheckQueue (phase 1)&#10;                                  &#10;                                  Inform : Done&#10;                                  &#10;                                  CheckQueue: In progress....&#10;                                  &#10;                                  exception handling on json parsing&#10;                                  &#10;                                  update database after sending task to cpe" />
+    <option name="LAST_COMMIT_MESSAGE" value="Add Database for Inform and CheckQueue (phase 1)&#10;                                  &#10;                                  Inform : Done&#10;                                  &#10;                                  CheckQueue: In progress....&#10;                                  &#10;                                  exception handling on json parsing&#10;                                  &#10;                                  update database after sending task to cpe" />
     <option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
     <option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
     <option name="REARRANGE_BEFORE_PROJECT_COMMIT" value="true" />
@@ -776,20 +791,10 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/main.cpp">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="555">
-          <caret line="675" column="26" selection-start-line="675" selection-start-column="26" selection-end-line="675" selection-end-column="26" />
-          <folding>
-            <element signature="e#33694#33915#0" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/soapcwmpService.cpp">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="353">
-          <caret line="1015" column="30" selection-start-line="1015" selection-start-column="30" selection-end-line="1015" selection-end-column="30" />
+        <state relative-caret-position="594">
+          <caret line="1029" selection-start-line="1029" selection-end-line="1029" />
           <folding>
             <element signature="e#0#614#0" />
             <element signature="e#646#784#0" />
@@ -840,6 +845,27 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/main.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="278">
+          <caret line="673" column="20" selection-start-line="673" selection-start-column="20" selection-end-line="673" selection-end-column="20" />
+          <folding>
+            <element signature="e#604#788#0" />
+            <element signature="e#790#856#0" />
+            <element signature="e#858#1107#0" />
+            <element signature="e#1109#1140#0" />
+            <element signature="e#5722#6744#0" />
+            <element signature="e#6746#7432#0" />
+            <element signature="e#7434#8491#0" />
+            <element signature="e#8494#10862#0" />
+            <element signature="e#13027#33145#0" />
+            <element signature="e#16266#16299#0" />
+            <element signature="e#25273#25300#0" />
+            <element signature="e#33694#33915#0" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
   </component>
   <component name="masterDetails">
     <states>

+ 47 - 41
main.cpp

@@ -575,48 +575,12 @@ int cwmpService::Reboot(struct _cwmp__Reboot *cwmp__Reboot,
                         struct _cwmp__RebootResponse *cwmp__RebootResponse) { return SOAP_OK; }
 
 
-std::string escape_json(const std::string &s) {
-    std::ostringstream o;
-    for (auto c = s.cbegin(); c != s.cend(); c++) {
-        switch (*c) {
-            case '"':
-                o << "\\\"";
-                break;
-            case '\\':
-                o << "\\\\";
-                break;
-            case '\b':
-                o << "\\b";
-                break;
-            case '\f':
-                o << "\\f";
-                break;
-            case '\n':
-                o << "\\n";
-                break;
-            case '\r':
-                o << "\\r";
-                break;
-            case '\t':
-                o << "\\t";
-                break;
-            default:
-                if ('\x00' <= *c && *c <= '\x1f') {
-                    o << "\\u"
-                      << std::hex << std::setw(4) << std::setfill('0') << (int) *c;
-                } else {
-                    o << *c;
-                }
-        }
-    }
-    return o.str();
-}
 
 int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) {
 
-    std::cerr << "IP: " << soap->host << std::endl;
+//    std::cerr << "IP: " << soap->host << std::endl;
     soap->error = 0;
-    std::string IMSI{}, s;
+    std::string IMSI{}, s, id;
     const char *_actionParameters = "";
     int action{0};
     /*
@@ -632,22 +596,31 @@ int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) {
     json actionParameters = {};
     mysqlpp::Connection conn(false);
     mysqlpp::Query query = conn.query();
+    mysqlpp::Query _query = conn.query();
     try {
         conn.connect(DATABASE, HOST, USER, PASSWORD, PORT);
         query
-                << "select d.IMSI , t.action , t.ActionParameters from TaskList as t join Device_List as d on t.IMSI=d.IMSI where d.IP='"
-                << soap->host << "' and t.response is null order by id limit 1;";
+                << "select t.id, d.IMSI , t.action , t.ActionParameters from TaskList as t join Device_List as d on t.IMSI=d.IMSI where d.IP='"
+                << soap->host << "' and t.response is null and t.Active=0 order by id limit 1;";
         mysqlpp::StoreQueryResult result = query.store();
+        if (result.size() == 0)
+            return soap->error = 204;
         mysqlpp::StoreQueryResult::const_iterator it;
         for (it = result.begin(); it != result.end(); ++it) {
             mysqlpp::Row row = *it;
+            strValue << row["id"];
+            strValue >> id;
             strValue << row["IMSI"];
             strValue >> IMSI;
             action = row["action"];
             _actionParameters = row["ActionParameters"];
         }
+//        std::cerr<<"Size of result+: "<<result.size()<<std::endl;
         s = std::string(_actionParameters);
 
+        _query << "update TaskList set Active=1 where id='" << id << "';";
+        _query.execute();
+
     } catch (mysqlpp::BadQuery er) { // handle any connection or
         std::cerr << "Error on CPE with IP: " << soap->host << " :" << er.what() << std::endl;
     }
@@ -655,7 +628,7 @@ int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) {
     actionParameters = json::parse(s);
     if (action == 1) {
         try {
-            std::cerr << actionParameters.dump(4) << std::endl;
+//            std::cerr << actionParameters.dump(4) << std::endl;
             int DelaySeconds = 1;
             std::string str = actionParameters["FileType"];
             char *FileType = new char[str.length() + 1];
@@ -688,4 +661,37 @@ int cwmpService::CheckQueue(struct soap *soap, cwmpService *cwmpService1) {
 //                           std::__cxx11::string(), std::__cxx11::string());
 //    return soap_closesock(soap);
     return soap->error = 204;
+}
+
+
+int cwmpService::CustomeDownloadResponse(struct soap *pSoap, cwmpService *pService) {
+
+    std::cerr << "Upgrade Response recieved." << std::endl;
+    soap->error = 0;
+    mysqlpp::Connection conn(false);
+    mysqlpp::Query _query = conn.query();
+    _query << "update TaskList set Active=1 where id='" << "';";
+    _query.execute();
+//    struct _cwmp__DownloadResponse cwmp__downloadResponse;
+//    if ((soap->mode & SOAP_IO_LENGTH)) {
+//        if (soap_envelope_begin_out(soap)
+//            || soap_putheader(soap)
+//            || soap_body_begin_out(soap)
+//            || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
+//            || soap_body_end_out(soap)
+//            || soap_envelope_end_out(soap))
+//            return soap->error;
+//    };
+//    if (soap_end_count(soap)
+//        || soap_response(soap, SOAP_OK)
+//        || soap_envelope_begin_out(soap)
+//        || soap_putheader(soap)
+//        || soap_body_begin_out(soap)
+//        || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
+//        || soap_body_end_out(soap)
+//        || soap_envelope_end_out(soap)
+//        || soap_end_send(soap))
+//        return soap->error;
+    soap->keep_alive = 0;
+    return soap_closesock(soap);
 }

+ 0 - 28
soapcwmpService.cpp

@@ -1028,31 +1028,3 @@ int cwmpService::CustomeDownload(struct soap *pSoap, cwmpService *pService, int
     return soap_closesock(soap);
 }
 
-
-int cwmpService::CustomeDownloadResponse(struct soap *pSoap, cwmpService *pService) {
-
-    std::cerr << "Upgrade Response recieved." << std::endl;
-    soap->error = 0;
-//    struct _cwmp__DownloadResponse cwmp__downloadResponse;
-//    if ((soap->mode & SOAP_IO_LENGTH)) {
-//        if (soap_envelope_begin_out(soap)
-//            || soap_putheader(soap)
-//            || soap_body_begin_out(soap)
-//            || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
-//            || soap_body_end_out(soap)
-//            || soap_envelope_end_out(soap))
-//            return soap->error;
-//    };
-//    if (soap_end_count(soap)
-//        || soap_response(soap, SOAP_OK)
-//        || soap_envelope_begin_out(soap)
-//        || soap_putheader(soap)
-//        || soap_body_begin_out(soap)
-//        || soap_put__cwmp__DownloadResponse(soap, &cwmp__downloadResponse, "cwmp:DownloadResponse", "")
-//        || soap_body_end_out(soap)
-//        || soap_envelope_end_out(soap)
-//        || soap_end_send(soap))
-//        return soap->error;
-    soap->keep_alive = 0;
-    return soap_closesock(soap);
-}