[Bugfix][T106BUG-390]fix the lynq-qser-data.xml is empty

Only Configure: No
Affected branch: master
Affected module: data
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I21e89914153c6204407c137887a971ecbde783a8
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-data/lynq-qser-data.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-data/lynq-qser-data.cpp
index 1be825b..138514d 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-data/lynq-qser-data.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-data/lynq-qser-data.cpp
@@ -27,6 +27,7 @@
 #define COPY_XML_RETRY_TIMES 3
 
 static qser_data_call_evt_cb_t s_data_call_cb = NULL;
+static xmlDocPtr apn_table_xml_pdoc = NULL;
 const int apndb_offset = 683;
 
 void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
@@ -385,18 +386,19 @@
 {
     int node_num = 0;
     char temp_buff[12];
-    xmlDocPtr pdoc = NULL;
+    //xmlDocPtr apn_table_xml_pdoc = NULL;
     xmlNodePtr node = NULL;
     xmlNodePtr tmp_node = NULL;
     xmlNodePtr sum_node = NULL;
-    pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
-    if(NULL == pdoc)
+
+//    apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
     {
         LYERRLOG("open xml file error");
         goto FAILED;
     }
     
-    node = xmlDocGetRootElement(pdoc);
+    node = xmlDocGetRootElement(apn_table_xml_pdoc);
     if (NULL == node)
     {
         LYERRLOG("xmlDocGetRootElement() error");
@@ -441,15 +443,16 @@
     xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
     xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
     xmlAddChild(node,tmp_node);
-    xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
-    xmlFreeDoc(pdoc);
+    xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
+   
+//    xmlFreeDoc(apn_table_xml_pdoc);
     return RESULT_OK;
     
     FAILED:
-    if (pdoc)
+    /* if (apn_table_xml_pdoc)
     {
-        xmlFreeDoc(pdoc);
-    }
+        xmlFreeDoc(apn_table_xml_pdoc);
+    }*/
     return RESULT_ERROR;
 }
 
@@ -457,17 +460,17 @@
 {
     int node_num = 0;
     char temp_buff[12];
-    xmlDocPtr pdoc = NULL;
+    //xmlDocPtr apn_table_xml_pdoc = NULL;
     xmlNodePtr node = NULL;
     xmlNodePtr modify_node = NULL;
-    pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
-    if(NULL == pdoc)
+    // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
     {
         LYERRLOG("open xml file error");
         goto FAILED;
     }
     
-    node = xmlDocGetRootElement(pdoc);
+    node = xmlDocGetRootElement(apn_table_xml_pdoc);
     if (NULL == node)
     {
         LYERRLOG("xmlDocGetRootElement() error");
@@ -522,15 +525,15 @@
         modify_node = modify_node->next;
         node_num++;
     }
-    xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
-    xmlFreeDoc(pdoc);
+    xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
+//    xmlFreeDoc(apn_table_xml_pdoc);
     return RESULT_OK;
 
     FAILED:
-    if (pdoc)
-    {
-        xmlFreeDoc(pdoc);
-    }
+    // if (apn_table_xml_pdoc)
+    // {
+    //     xmlFreeDoc(apn_table_xml_pdoc);
+    // }
     return RESULT_ERROR;
 }
 
@@ -538,17 +541,17 @@
 {
     int node_num = 0;
     char temp_buff[12];
-    xmlDocPtr pdoc = NULL;
+    //xmlDocPtr apn_table_xml_pdoc = NULL;
     xmlNodePtr node = NULL;
     xmlNodePtr modify_node = NULL;
-    pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
-    if(NULL == pdoc)
+//    apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
     {
         LYERRLOG("open xml file error");
         goto FAILED;
     }
     
-    node = xmlDocGetRootElement(pdoc);
+    node = xmlDocGetRootElement(apn_table_xml_pdoc);
     if (NULL == node)
     {
         LYERRLOG("xmlDocGetRootElement() error");
@@ -579,15 +582,15 @@
     xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
     xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
     xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
-    xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
-    xmlFreeDoc(pdoc);
+    xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
+//    xmlFreeDoc(apn_table_xml_pdoc);
     return RESULT_OK;
 
     FAILED:
-    if (pdoc)
-    {
-        xmlFreeDoc(pdoc);
-    }
+    // if (apn_table_xml_pdoc)
+    // {
+    //     xmlFreeDoc(apn_table_xml_pdoc);
+    // }
     return RESULT_ERROR;
 }
 
@@ -595,18 +598,18 @@
 int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
 {
     int node_num = 0;
-    xmlDocPtr pdoc = NULL;
+    //xmlDocPtr apn_table_xml_pdoc = NULL;
     xmlNodePtr node = NULL;
     xmlNodePtr modify_node = NULL;
     unsigned char temp = NULL;
-    pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
-    if(NULL == pdoc)
+//    apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
     {
         LYERRLOG("open xml file error");
         goto FAILED;
     }
     
-    node = xmlDocGetRootElement(pdoc);
+    node = xmlDocGetRootElement(apn_table_xml_pdoc);
     if (NULL == node)
     {
         LYERRLOG("xmlDocGetRootElement() error");
@@ -650,34 +653,34 @@
     strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
     strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
     strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
-    xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
-    xmlFreeDoc(pdoc);
+//    xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
+//    xmlFreeDoc(apn_table_xml_pdoc);
     return RESULT_OK;
 
     FAILED:
-    if (pdoc)
-    {
-        xmlFreeDoc(pdoc);
-    }
+    // if (apn_table_xml_pdoc)
+    // {
+    //     xmlFreeDoc(apn_table_xml_pdoc);
+    // }
     return RESULT_ERROR;
 }
 
 int apn_xml_query_list(qser_apn_info_list_s *apn_list)
 {
     int node_num = 0;
-    xmlDocPtr pdoc = NULL;
+    //xmlDocPtr apn_table_xml_pdoc = NULL;
     xmlNodePtr node = NULL;
     xmlNodePtr modify_node = NULL;
     xmlChar *temp_char;
     char temp[64];
-    pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
-    if(NULL == pdoc)
+//    apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
     {
         LYERRLOG("open xml file error");
         goto FAILED;
     }
     
-    node = xmlDocGetRootElement(pdoc);
+    node = xmlDocGetRootElement(apn_table_xml_pdoc);
     if (NULL == node)
     {
         LYERRLOG("xmlDocGetRootElement() error");
@@ -705,15 +708,15 @@
         modify_node = modify_node->next;
     }
     apn_list->cnt = node_num;
-    xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
-    xmlFreeDoc(pdoc);
+//    xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
+//    xmlFreeDoc(apn_table_xml_pdoc);
     return RESULT_OK;
 
     FAILED:
-    if (pdoc)
-    {
-        xmlFreeDoc(pdoc);
-    }
+    // if (apn_table_xml_pdoc)
+    // {
+    //     xmlFreeDoc(apn_table_xml_pdoc);
+    // }
     return RESULT_ERROR;
 }
 
@@ -973,13 +976,22 @@
         return RESULT_ERROR;
     }
     qser_cb_pthread_create();
+    apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
+    if(NULL == apn_table_xml_pdoc)
+    {
+        LYERRLOG("open xml file error");
+        return RESULT_ERROR;
+    }
     return RESULT_OK;
 }
 
 void qser_data_call_destroy(void)
 {
     LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
-    
+    if(apn_table_xml_pdoc)
+    {
+        xmlFreeDoc(apn_table_xml_pdoc);
+    }
     lynq_deinit_data();
     qser_cb_pthread_cancel();
     s_data_call_cb = NULL;