XmlErr XmlProfile::XmlParseFile(char *path) { struct stat fileStat; if(!path) return XML_BADARGS; stat(path,&fileStat); FILE *inFile=NULL; XmlErr err; cTag=NULL; if(fileStat.st_size>0) { char *buffer; inFile=fopen(path,"r"); if(inFile) { if(!fileLock(inFile)) { error("Can't lock %s for opening ",path); return -1; } buffer=(char *)malloc(fileStat.st_size+1); fread(buffer,1,fileStat.st_size,inFile); buffer[fileStat.st_size]=0; err=XmlParseBuffer(buffer); free(buffer); fileUnlock(inFile); fclose(inFile); } else { error("Can't open xmlfile %s",path); return -1; } } }
static void test_cwmp_session_create_addobject(abts_case *tc, void *data) { cwmp_t * cwmp = (cwmp_t*)data; pool_t * pool = pool_create(POOL_DEFAULT_SIZE); xmldoc_t * doc, *newdoc; char * message = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns=\"urn:dslforum-org:cwmp-1-0\"><SOAP-ENV:Header><cwmp:ID soap:mustUnderstand=\"1\">1234</cwmp:ID></SOAP-ENV:Header> \ <SOAP-ENV:Body><cwmp:AddObject><ObjectName>InternetGatewayDevice.WANDevice.</ObjectName><ParameterKey></ParameterKey></cwmp:AddObject></SOAP-ENV:Body></SOAP-ENV:Envelope>" ; printf("create session\n"); cwmp_session_t * session = cwmp_session_create(cwmp); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); pool_create(POOL_DEFAULT_SIZE); printf("open session \n"); cwmp_session_open(session); cwmp_uint32_t msglength = strlen(message); size_t len; char *xmlbuf = pool_palloc(pool, msglength+32); len = sprintf(xmlbuf,"<cwmp>"); strncpy(xmlbuf + len, message, msglength); strcpy(xmlbuf + len + msglength, "</cwmp>"); // strcat(xmlbuf, "</cwmp>"); // xmlbuf[len+msglength+7] = '\0'; printf("agent analyse xml: \n%s", xmlbuf); doc = XmlParseBuffer(pool, xmlbuf); ASSERT_NOTNULL(doc); newdoc = cwmp_session_create_addobject_response_message(session, doc, pool); cwmp_write_doc_to_chunk(newdoc, session->writers, pool); cwmp_chunk_print(session->writers); pool_destroy(pool); }
static void test_cwmp_session_create_getparameternames(abts_case *tc, void *data) { cwmp_t * cwmp = (cwmp_t*)data; pool_t * pool = pool_create(POOL_DEFAULT_SIZE); xmldoc_t * doc, *newdoc; char * message = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns=\"urn:dslforum-org:cwmp-1-0\"><SOAP-ENV:Header><cwmp:ID>129479899093788892</cwmp:ID><cwmp:NoMoreRequests>0</cwmp:NoMoreRequests></SOAP-ENV:Header><SOAP-ENV:Body><cwmp:GetParameterNames><ParameterPath>InternetGatewayDevice.</ParameterPath><NextLevel>1</NextLevel></cwmp:GetParameterNames></SOAP-ENV:Body></SOAP-ENV:Envelope>" ; cwmp_session_t * session = cwmp_session_create(cwmp); cwmp_session_open(session); cwmp_uint32_t msglength = strlen(message); size_t len; char *xmlbuf = pool_palloc(pool, msglength+32); len = sprintf(xmlbuf,"<cwmp>"); strncpy(xmlbuf + len, message, msglength); strcpy(xmlbuf + len + msglength, "</cwmp>"); printf("agent analyse xml: \n%s", xmlbuf); doc = XmlParseBuffer(pool, xmlbuf); ASSERT_NOTNULL(doc); newdoc = cwmp_session_create_getparameternames_response_message(session, doc, pool); cwmp_write_doc_to_chunk(newdoc, session->writers, pool); cwmp_chunk_print(session->writers); pool_destroy(pool); }
int cwmp_agent_analyse_session(cwmp_session_t * session) { pool_t * doctmppool = NULL; char * xmlbuf; cwmp_uint32_t len; xmldoc_t * doc; char * method; xmldoc_t * newdoc = NULL; int rc; static char * xml_fault = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns=\"urn:dslforum-org:cwmp-1-0\"><SOAP-ENV:Body SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" id=\"_0\"><SOAP-ENV:Fault>Error Message</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>"; cwmp_uint32_t msglength = cwmp_chunk_length(session->readers); if (msglength<= 0) { session->newdata = CWMP_NO; cwmp_log_debug("analyse receive length is 0"); goto eventcheck; // return CWMP_ERROR; } doctmppool = pool_create(POOL_DEFAULT_SIZE); xmlbuf = pool_palloc(doctmppool, msglength+32); len = sprintf(xmlbuf,"<cwmp>"); cwmp_chunk_copy(xmlbuf + len, session->readers, msglength); strcpy(xmlbuf+len+msglength, "</cwmp>"); cwmp_log_debug("agent analyse xml: \n%s", xmlbuf); doc = XmlParseBuffer(doctmppool, xmlbuf); if (!doc) { cwmp_log_debug("analyse create doc null\n"); cwmp_chunk_write_string(session->writers, xml_fault, TRstrlen(xml_fault), session->envpool); goto finished; } method = cwmp_get_rpc_method_name(doc); cwmp_log_debug("analyse method is: %s\n", method); cwmp_chunk_clear(session->writers); pool_clear(session->envpool); if (TRstrcmp(method, CWMP_RPC_GETRPCMETHODS) == 0) { newdoc = cwmp_session_create_getrpcmethods_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_INFORMRESPONSE) == 0) { newdoc = NULL; } else if (TRstrcmp(method, CWMP_RPC_GETPARAMETERNAMES) == 0) { newdoc = cwmp_session_create_getparameternames_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_GETPARAMETERVALUES) == 0) { newdoc = cwmp_session_create_getparametervalues_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_SETPARAMETERVALUES) == 0) { newdoc = cwmp_session_create_setparametervalues_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_DOWNLOAD) == 0) { newdoc = cwmp_session_create_download_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_UPLOAD) == 0) { newdoc = cwmp_session_create_upload_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_TRANSFERCOMPLETERESPONSE) == 0) { newdoc = NULL; } else if (TRstrcmp(method, CWMP_RPC_REBOOT) == 0) { newdoc = cwmp_session_create_reboot_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_ADDOBJECT) == 0) { newdoc = cwmp_session_create_addobject_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_DELETEOBJECT) == 0) { newdoc = cwmp_session_create_deleteobject_response_message(session, doc, doctmppool); } else if (TRstrcmp(method, CWMP_RPC_FACTORYRESET) == 0) { newdoc = cwmp_session_create_factoryreset_response_message(session, doc, doctmppool); } else { //check event queue //newdoc = cwmp_session_create_event_response_message(session, doc, doctmppool); } cwmp_t * cwmp = session->cwmp; if(newdoc == NULL) { cwmp_log_debug("agent analyse newdoc is null. "); eventcheck: { cwmp_log_debug("agent analyse begin check global event, %d", cwmp->event_global.event_flag); //check global event for transfercomplete if(cwmp->event_global.event_flag & EVENT_REBOOT_TRANSFERCOMPLETE_FLAG) { cwmp->event_global.event_flag &= ~EVENT_REBOOT_TRANSFERCOMPLETE_FLAG; if(!doctmppool) { doctmppool = pool_create(POOL_DEFAULT_SIZE); } event_code_t ec; ec.event = INFORM_TRANSFERCOMPLETE; TRstrncpy(ec.command_key, cwmp->event_global.event_key, COMMAND_KEY_LEN); ec.fault_code = cwmp->event_global.fault_code; ec.start = cwmp->event_global.start; ec.end = cwmp->event_global.end; newdoc = cwmp_session_create_transfercomplete_message(session, &ec, doctmppool); } } } cwmp_log_debug("newdoc %p, msglength: %d", newdoc, msglength ); if((newdoc != NULL) || (newdoc == NULL && msglength != 0)) // || (newdoc == NULL && msglength == 0 && session->retry_count < 2)) { session->newdata = CWMP_YES; cwmp_write_doc_to_chunk(newdoc, session->writers, session->envpool); rc = CWMP_OK; } else { rc = CWMP_ERROR; } finished: if(doctmppool != NULL) { pool_destroy(doctmppool); } return rc; }