bool XMLWrapper::nodeDump(xmlNodePtr node, std::string &content, bool trim) { content.clear(); if (!mDocument) { return false; } if (!node) { return false; } bool result = false; xmlBufferPtr buffer = xmlBufferCreate(); if (buffer) { xmlOutputBufferPtr outputBuffer = xmlOutputBufferCreateBuffer(buffer, NULL); if (outputBuffer) { xmlNodeDumpOutput(outputBuffer, mDocument, node, 0, 0, "UTF8"); xmlOutputBufferClose(outputBuffer); outputBuffer = NULL; result = convertToString(buffer->content, content); if (result && trim) { trimString(content); } } xmlBufferFree(buffer); buffer = NULL; } return result; }
void closeFile() { mXPath.clear(); // This section writes to file std::ofstream fileStream; if(!mStream) { fileStream.open(mXMLFilePath.c_str()); mStream = &fileStream; } xmlBufferPtr buffer = xmlBufferCreate(); xmlOutputBuffer * outputBuffer = xmlOutputBufferCreateBuffer(buffer, NULL); xmlSaveFormatFileTo(outputBuffer, mXMLDocument, "utf-8", 1); *mStream << buffer->content; xmlBufferFree(buffer); if(fileStream.is_open()) { fileStream.close(); mStream = NULL; } xmlFreeDoc(mXMLDocument); xmlCleanupParser(); if(mHeavyDataWriter->getMode() == XdmfHeavyDataWriter::Default) { mHeavyDataWriter->closeFile(); } };
static bool hidrd_xml_snk_flush(hidrd_snk *snk) { bool result = false; hidrd_xml_snk_inst *xml_snk = (hidrd_xml_snk_inst *)snk; bool valid; xmlBufferPtr xml_buf = NULL; xmlOutputBufferPtr xml_out_buf = NULL; void *new_buf; size_t new_size; XML_ERR_FUNC_BACKUP_DECL; free(xml_snk->err); xml_snk->err = strdup(""); XML_ERR_FUNC_SET(&xml_snk->err); /* Break any unfinished groups */ if (!xml_snk_group_break_branch(snk)) goto cleanup; /* Validate the document, if the schema is specified */ if (*xml_snk->schema != '\0' && (!xml_validate(&valid, xml_snk->doc, xml_snk->schema) || !valid)) goto cleanup; /* Create an XML buffer */ xml_buf = xmlBufferCreate(); if (xml_buf == NULL) goto cleanup; /* Create an XML output buffer from the generic buffer */ xml_out_buf = xmlOutputBufferCreateBuffer(xml_buf, NULL); if (xml_out_buf == NULL) goto cleanup; /* Format XML from the document */ if (xmlSaveFormatFileTo(xml_out_buf, xml_snk->doc, NULL, xml_snk->format) < 0) goto cleanup; /* xml_out_buf is closed by xmlSaveFormatFileTo */ xml_out_buf = NULL; /* Retrieve resulting size */ new_size = xmlBufferLength(xml_buf); /* If we have a location for the buffer pointer */ if (snk->pbuf != NULL) { /* Retention and update the buffer */ new_buf = realloc(*snk->pbuf, new_size); if (new_size > 0 && new_buf == NULL) XML_ERR_CLNP("failed to retention the output buffer"); memcpy(new_buf, xmlBufferContent(xml_buf), new_size); /* Update the buffer pointer */ *snk->pbuf = new_buf; } /* Output size */ if (snk->psize != NULL) *snk->psize = new_size; result = true; cleanup: if (xml_out_buf != NULL) xmlOutputBufferClose(xml_out_buf); if (xml_buf != NULL) xmlBufferFree(xml_buf); XML_ERR_FUNC_RESTORE; return result; }
int cpdSendCpPositionResponseToModem(pCPD_CONTEXT pCpd) { int result = 0; xmlDoc *pDoc; xmlBuffer *pXmlBuffer; xmlOutputBuffer *pOutBuffer; int sendMultipleResponses = CPD_NOK; CPD_LOG(CPD_LOG_ID_TXT , "\n %u: %s(%u)\n", getMsecTime(), __FUNCTION__, pCpd->request.dbgStats.posRequestId); LOGD("%u: %s(%u)", getMsecTime(), __FUNCTION__, pCpd->request.dbgStats.posRequestId); CPD_LOG(CPD_LOG_ID_TXT , "\n Location : %f, %f, %d", pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.coordinate.longitude, pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.coordinate.latitude.degrees, pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.altitude.height ); LOGD("Rx Location : %f, %f, %d", pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.coordinate.longitude, pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.coordinate.latitude.degrees, pCpd->response.location.location_parameters.shape_data.point_alt_uncertellipse.altitude.height ); CPD_LOG(CPD_LOG_ID_TXT | CPD_LOG_ID_CONSOLE, "\n TTFF : %u, %u, %u, %u, %u", (pCpd->response.dbgStats.posReceivedFromGps1 - pCpd->response.dbgStats.posRequestedFromGps), pCpd->response.dbgStats.posRequestedByNetwork, pCpd->response.dbgStats.posRequestedFromGps, pCpd->response.dbgStats.posReceivedFromGps1, pCpd->response.dbgStats.posReceivedFromGps ); LOGD("TTFF : %u, %u, %u, %u, %u", (pCpd->response.dbgStats.posReceivedFromGps1 - pCpd->response.dbgStats.posRequestedFromGps), pCpd->response.dbgStats.posRequestedByNetwork, pCpd->response.dbgStats.posRequestedFromGps, pCpd->response.dbgStats.posReceivedFromGps1, pCpd->response.dbgStats.posReceivedFromGps ); /* is this contignous-reporting mode? */ if (pCpd->request.posMeas.flag == POS_MEAS_RRC) { if (pCpd->request.posMeas.posMeas_u.rrc_meas.rep_crit.period_rep_crit.rep_amount == 0){ sendMultipleResponses = CPD_OK; } } pDoc = xmlNewDoc((xmlChar *) "1.0"); pXmlBuffer = xmlBufferCreate(); pOutBuffer = xmlOutputBufferCreateBuffer(pXmlBuffer, NULL); /* Create the XML document from data */ if (pCpd->response.flag == RESPONSE_FLAG_POS_MEAS) { result = cpdXmlFormatLocation(pCpd, pDoc); } else if (pCpd->response.flag == RESPONSE_FLAG_GPS_MEAS) { result = cpdXmlFormatMeasurements(pCpd, pDoc); } if (result == CPD_OK) { /* Convert XML Document into pXmlBuffer */ xmlSaveFormatFileTo(pOutBuffer, pDoc, "utf-8", 1); CPD_LOG(CPD_LOG_ID_TXT, "\r\npOutBuffer["); CPD_LOG_DATA(CPD_LOG_ID_TXT | CPD_LOG_ID_XML_TX, (char *)pXmlBuffer->content ,strlen((char *)pXmlBuffer->content)); CPD_LOG(CPD_LOG_ID_XML_TX, "\r\n"); CPD_LOG(CPD_LOG_ID_TXT, "]\r\n"); /* Send response to the modem */ CPD_LOG(CPD_LOG_ID_TXT , "\n %u: %u, dT=%u, alreadySent=%d, sendMultipleResponses = %d\n", getMsecTime(), pCpd->modemInfo.sendingCPOSat, getMsecDt(pCpd->modemInfo.sendingCPOSat), pCpd->modemInfo.sentCPOSok, sendMultipleResponses); if ((pCpd->modemInfo.sentCPOSok != CPD_OK) || (sendMultipleResponses == CPD_OK)) { CPD_LOG(CPD_LOG_ID_TXT , "\n %u: %u!= 0\n", getMsecTime(), pCpd->modemInfo.sendingCPOSat); if (getMsecDt(pCpd->modemInfo.sendingCPOSat) >= 1000UL) { pCpd->modemInfo.sendingCPOSat = getMsecTime(); pCpd->modemInfo.haveResponse = 0; pCpd->modemInfo.responseValue = CPD_ERROR; result = cpdSendCposResponse(pCpd, (char *)pXmlBuffer->content); if (result == CPD_OK) { usleep(50 * MODEM_POOL_INTERVAL); /* wait for modem response, which comes in in another thread */ if ((pCpd->modemInfo.haveResponse != 0) && (pCpd->modemInfo.responseValue == AT_RESPONSE_OK)) { pCpd->request.status.nResponsesSent++; pCpd->modemInfo.sentCPOSok = CPD_OK; pCpd->systemMonitor.processingRequest = CPD_NOK; pCpd->request.status.responseSentToModemAt = getMsecTime(); if (cpdIsNumberOfResponsesSufficientForRequest(pCpd) == CPD_OK) { cpdSendAbortToGps(pCpd); } } else { result = CPD_NOK; } } CPD_LOG(CPD_LOG_ID_TXT , "\n %u: cpdSendCposResponse() = %d, Modem: %d, %d, CPOSsent=%d", getMsecTime(), result, pCpd->modemInfo.haveResponse, pCpd->modemInfo.responseValue, pCpd->modemInfo.sentCPOSok); } else { CPD_LOG(CPD_LOG_ID_TXT , "\n %u:Not sending response to modem, dT=%u\n", getMsecTime(), getMsecDt(pCpd->modemInfo.sendingCPOSat)); } } } xmlBufferFree(pXmlBuffer); /* Release allocated resoucrs */ xmlFreeDoc(pDoc); //xmlOutputBufferClose(pOutBuffer); CPD_LOG(CPD_LOG_ID_TXT, "\r\n %u: END %s() = %d", getMsecTime(), __FUNCTION__, result); LOGD("%u: END %s() = %d", getMsecTime(), __FUNCTION__, result); return result; }