/* * * ProLinga-Run * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Run. * * ProLinga-Run is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Run is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Run. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RunCommon.h" #include #include #include #include "DataRef.hpp" #include "RepositoryAccess.hpp" extern BiAppnPtr biAppnPtr; #ifndef BUILD_REPOSITORY extern char *repositoryEndPoint; extern int repositoryCompressionLevel; #endif /* Table.Record (F-) */ extern TablePtr tablePtr; xmlDocPtr RC_List(const char *objApplication, const char *objType, const char *objName) { xmlDocPtr docReq, docRes; xmlNodePtr curReq; /* Create RC List */ docReq = xmlNewDoc((const xmlChar *)"1.0"); docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL); curReq = xmlDocGetRootElement(docReq); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"List"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)objApplication); xmlNewProp (curReq, (const xmlChar *)"Type", (const xmlChar *)objType); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)objName); /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } xmlDocPtr RC_Get(const char *objApplication, const char *objType, const char *objName) { xmlDocPtr docReq, docRes; xmlNodePtr curReq; /* Create RC Get */ docReq = xmlNewDoc((const xmlChar *)"1.0"); docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL); curReq = xmlDocGetRootElement(docReq); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"Get"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)objApplication); xmlNewProp (curReq, (const xmlChar *)"Type", (const xmlChar *)objType); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)objName); //printf("!!%s-%s-%s\n", objApplication, objType, objName); /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } xmlDocPtr RC_Delete(const char *objApplication, const char *objType, const char *objName) { xmlDocPtr docReq, docRes; xmlNodePtr curReq; /* Create RC Delete */ docReq = xmlNewDoc((const xmlChar *)"1.0"); docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL); curReq = xmlDocGetRootElement(docReq); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"Delete"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)objApplication); xmlNewProp (curReq, (const xmlChar *)"Type", (const xmlChar *)objType); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)objName); /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } xmlDocPtr RC_Ping(const char *objApplication, const char *objType, const char *objName) { xmlDocPtr docReq, docRes; xmlNodePtr curReq; /* Create RC Ping */ docReq = xmlNewDoc((const xmlChar *)"1.0"); docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL); curReq = xmlDocGetRootElement(docReq); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"Ping"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)objApplication); xmlNewProp (curReq, (const xmlChar *)"Type", (const xmlChar *)objType); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)objName); /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } xmlDocPtr RC_SysInfo(void) { xmlDocPtr docReq, docRes; xmlNodePtr curReq; /* Create RC Ping */ docReq = xmlNewDoc((const xmlChar *)"1.0"); docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL); curReq = xmlDocGetRootElement(docReq); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"SysInfo"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } xmlDocPtr RC_Put(xmlDocPtr docReq) { xmlDocPtr docRes; /* Process Request */ #if BUILD_REPOSITORY docRes = RepositoryAccess(docReq); #else docRes = RepositoryAccess(docReq, repositoryEndPoint, repositoryCompressionLevel); #endif /* Return */ return docRes; } int repReadPutDataRef(const xmlDocPtr docRes, const char *recName, const char *tableName, bool isMainThread) { xmlDocPtr docRec; xmlNodePtr curTmp; xmlXPathContextPtr ctxRes, ctxRec; xmlXPathObjectPtr resRes, resRec; xmlBufferPtr bufTmp; char *insValue; char insPath[255], drefValue[255]; short i, insHits; /* Init XPath */ // xmlXPathInit(); /* Create XPath environments */ // ctxRes = xmlXPathNewContext(docRes); /* Find Out Status */ // resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/@Status", ctxRes); // rcStatus = (char *)xmlXPathCastToString(resRes); // if ( strcmp(rcStatus, "Ok") != 0) // return 10102; /* Get Dictionary Names */ docRec = RC_Get(biAppnPtr->getAppn(), "Record", recName); /* Init XPath */ //xmlXPathInit(); // bufTmp = xmlBufferCreate(); // curTmp = xmlDocGetRootElement(docRec); // xmlNodeDump(bufTmp, docRec, curTmp, 0, 1); // printf("%s\n", (char *)xmlBufferContent(bufTmp)); // xmlBufferFree(bufTmp); /* Create XPath environments */ ctxRes = xmlXPathNewContext(docRes); ctxRec = xmlXPathNewContext(docRec); resRec = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry)", ctxRec); insHits = (short)xmlXPathCastToNumber(resRec); /* i=4 -> Skip application, type and name since they have to be set already anyway */ for (i = 4; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry[%d]/DataDictionaryName", i); resRec = xmlXPathEval((const xmlChar *)insPath, ctxRec); insValue = (char *)xmlXPathCastToString(resRec); //printf("DD is : %s\n", insValue); /* Get Value */ sprintf(insPath, "/ProLinga/Repository/Command/Object/%s/%s", tableName, insValue); resRes = xmlXPathEval((const xmlChar *)insPath, ctxRes); sprintf(drefValue, "F-%s.%s", insValue, tableName); /* Assign value to DataRef */ /* Find out if text or node */ curTmp = resRes->nodesetval->nodeTab[0]; curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if (xmlStrcmp(curTmp->name, (const xmlChar *)"text")) break; curTmp = curTmp->next; } if (curTmp == NULL) { //printf("NO NODE ... F-%s.%s\n", insValue, tableName); putDataRef(drefValue, (char *)xmlXPathCastToString(resRes), 0, isMainThread); } else { //printf("NODE ... F-%s.%s\n", insValue, tableName); bufTmp = xmlBufferCreate(); xmlNodeDump(bufTmp, docRes, curTmp, 0, 1); //printf("%s\n", (char *)xmlBufferContent(bufTmp)); putDataRef(drefValue, (char *)xmlBufferContent(bufTmp), 0, isMainThread); xmlBufferFree(bufTmp); // printf("%s\n", getDataRef(tmpValue, isMainThread, retBigValue, false)); } } /* Return */ return 0; } int repReadPutXmlBuffer(const xmlDocPtr docRes, const xmlDocPtr docDef, const char *tableName) { xmlDocPtr docTable; xmlNodePtr curTable, curTmp; xmlXPathContextPtr ctxRes, ctxDef; xmlXPathObjectPtr resRes, resDef; char *insValue, insPath[255], tmpValue[255]; short i, insHits; /* Init XPath */ xmlXPathInit(); /* Create XPath environments */ ctxRes = xmlXPathNewContext(docRes); ctxDef = xmlXPathNewContext(docDef); /* Reset xml instance buffer */ docTable = tablePtr->getDocBuffer(&tablePtr, tableName); if (docTable != NULL) xmlFreeDoc(docTable); /* Create empty xml doc */ docTable = xmlNewDoc((const xmlChar *)"1.0"); docTable->children = xmlNewDocNode(docTable, NULL, (const xmlChar *)"ProLinga", NULL); curTable = xmlDocGetRootElement(docTable); /* Get reiterate records */ resDef = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry)", ctxDef); insHits = (short)xmlXPathCastToNumber(resDef); for (i = 1; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry[%d]/@Reiterate", i); resDef = xmlXPathEval((const xmlChar *)insPath, ctxDef); insValue = (char *)xmlXPathCastToString(resDef); if (strcmp(insValue, "True") == 0) { /* Position Node Pointer to root */ curTable = xmlDocGetRootElement(docTable); /* Get Record Name */ sprintf(insPath, "/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry[%d]/RecordName", i); resDef = xmlXPathEval((const xmlChar *)insPath, ctxDef); insValue = (char *)xmlXPathCastToString(resDef); // if ( (strcmp(tableName,"PickList") == 0 ) | // (strcmp(tableName,"VariableGroup") == 0 ) | // (strcmp(tableName,"Index") == 0 ) | // (strcmp(tableName,"Table") == 0 ) | // (strcmp(tableName,"Record") == 0 ) ) // { /* Add occurrence tag */ sprintf(tmpValue,"Occurrences%s", insValue); curTable = xmlNewTextChild (curTable, NULL, (const xmlChar *)tmpValue, (const xmlChar *)""); /* Copy reiterate records */ sprintf(insPath, "/ProLinga/Repository/Command/Object/%s/Occurrences%s", tableName, insValue); // } // else // { // /* Add instance tag */ // strcpy(tmpValue, insValue); // if (insValue[(strlen(insValue) -1 )] == 'x') // strcat(tmpValue, "es"); // else // strcat(tmpValue, "s"); // curTable = xmlNewTextChild (curTable, NULL, (const xmlChar *)tmpValue, (const xmlChar *)""); // // /* Copy reiterate records */ // if (insValue[(strlen(insValue) -1 )] == 'x') // sprintf(insPath, "/ProLinga/Repository/Command/Object/%s/%ses", tableName, insValue); // else // sprintf(insPath, "/ProLinga/Repository/Command/Object/%s/%ss", tableName, insValue); // } resRes = xmlXPathEval((const xmlChar *)insPath, ctxRes); if (xmlIsBlankNode(resRes->nodesetval->nodeTab[0]->xmlChildrenNode)== 1); { curTmp = resRes->nodesetval->nodeTab[0]->xmlChildrenNode; while (curTmp != NULL) { if (xmlNodeIsText(curTmp) == 0) break; curTmp = curTmp->next; } if (curTmp != NULL) xmlAddChild(curTable, xmlCopyNodeList(curTmp)); } } } /* Store xml document */ tablePtr->putDocBuffer(&tablePtr, tableName, docTable); /* Clean up */ xmlFreeDoc(docTable); /* Return */ return 0; } int repWriteRequestShell(xmlDocPtr *docReq, xmlNodePtr *curReq, const char *appnName, const char *objType, const char *objName) { /* Format Document */ *docReq = xmlNewDoc((const xmlChar *)"1.0"); (*docReq)->children = xmlNewDocNode(*docReq, NULL, (const xmlChar *)"ProLinga", NULL); *curReq = xmlDocGetRootElement(*docReq); *curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)"Repository", (const xmlChar *)""); xmlNewProp (*curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0"); *curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)""); xmlNewProp (*curReq, (const xmlChar *)"Name", (const xmlChar *)"Put"); xmlNewProp (*curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); *curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp (*curReq, (const xmlChar *)"Application", (const xmlChar *)appnName); xmlNewProp (*curReq, (const xmlChar *)"Type", (const xmlChar *)objType); xmlNewProp (*curReq, (const xmlChar *)"Name", (const xmlChar *)objName); //*curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)tableName, (const xmlChar *)""); *curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)objType, (const xmlChar *)""); /* Return */ return 0; } int repWriteGetDataRef(xmlDocPtr *docReq, xmlNodePtr *curReq, char *recName, const char *tableName, const bool isMainThread) { xmlDocPtr docRec, docParse; xmlNodePtr curParse, curTmp; xmlBufferPtr bufTmp; xmlXPathContextPtr ctxRec; xmlXPathObjectPtr resRec; short insHits, i; int len, j; char tmpValue[255], insPath[255], *retBigValue, *insValue, screenName[64]; bool checkXML = false; /* Get Dictionary Names */ docRec = RC_Get(biAppnPtr->getAppn(), "Record", recName); /* Init XPath */ xmlXPathInit(); ctxRec = xmlXPathNewContext(docRec); resRec = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry)", ctxRec); insHits = (short)xmlXPathCastToNumber(resRec); /* i=4 -> Skip application, type and name since they have to be set already anyway */ for (i = 4; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry[%d]/DataDictionaryName", i); resRec = xmlXPathEval((const xmlChar *)insPath, ctxRec); insValue = (char *)xmlXPathCastToString(resRec); sprintf(tmpValue, "F-%s.%s", insValue, tableName); //printf("WRITEDD is : %s value is %s\n", insValue, getDataRef(tmpValue, isMainThread, retValue, false)); // getDataRef(tmpValue, isMainThread, retBigValue, false); retBigValue = getDataRef(tmpValue, isMainThread, retBigValue, true); if (retBigValue == NULL) { retBigValue = new char[2]; strcpy(retBigValue, ""); } /* First check if content may be XML */ len = strlen(retBigValue); for (j=0;j<=len;j++) { if ( ( retBigValue[j] == ' ') || (retBigValue[j] == '\n') || (retBigValue[j] == '\t') ) { /* continue */ } else { if (retBigValue[j] == '<') checkXML = true; else checkXML = false; break; } } /* FIX ME: Only allow XML Subsets for glade documents in Screens */ if (strcmp(tableName, "Screen") != 0) checkXML = false; if (checkXML == true) { /* If content XML store as XML, otherwise store as CDATA */ docParse = xmlParseMemory(retBigValue, strlen(retBigValue)); if (docParse != NULL) { curParse = xmlDocGetRootElement(docParse); /* Check if screen/glade file */ curTmp = curParse; while (curTmp != NULL) { if ((!xmlStrcmp(curTmp->name, (const xmlChar *)"glade-interface"))) { curTmp = curTmp->xmlChildrenNode; while (curTmp != NULL) { if ((!xmlStrcmp(curTmp->name, (const xmlChar *)"widget"))) { getDataRef("F-Name.Screen", isMainThread, screenName, false); xmlSetProp(curTmp, (const xmlChar *)"id", (const xmlChar *)screenName); /* Update Data Ref */ bufTmp = xmlBufferCreate(); xmlNodeDump(bufTmp, docParse, curParse, 0, 1); //printf("%s\n", (char *)xmlBufferContent(bufTmp)); putDataRef(tmpValue, (char *)xmlBufferContent(bufTmp), 0, isMainThread); xmlBufferFree(bufTmp); } curTmp = curTmp->next; } break; } curTmp = curTmp->next; } *curReq = xmlNewTextChild (*curReq, NULL, (const xmlChar *)insValue, (const xmlChar *)""); xmlAddChild(*curReq, xmlCopyNodeList(curParse)); *curReq = (*curReq)->parent; xmlFreeDoc(docParse); } else xmlNewTextChild (*curReq, NULL, (const xmlChar *)insValue, (const xmlChar *)retBigValue); } else xmlNewTextChild (*curReq, NULL, (const xmlChar *)insValue, (const xmlChar *)retBigValue); /* Clean up */ delete retBigValue; } /*Return */ return 0; } int repWriteGetXmlBuffer(xmlDocPtr *docReq, xmlNodePtr *curReq, const xmlDocPtr docDef, const char *tableName) { xmlDocPtr docTable; xmlNodePtr curTable, curTmp; xmlXPathContextPtr ctxTable, ctxDef; xmlXPathObjectPtr resTable, resDef; char insPath[255], tmpValue[255]; char *insValue; short i, insHits; /* Get xml document */ docTable = tablePtr->getDocBuffer(&tablePtr, tableName); /* xmlBufferPtr bufTmp; bufTmp = xmlBufferCreate(); curTable = xmlDocGetRootElement(docTable); xmlNodeDump(bufTmp, docTable, curTable, 0, 1); printf("%s\n", (char *)xmlBufferContent(bufTmp)); xmlBufferFree(bufTmp); */ /* Get XPath context */ ctxTable = xmlXPathNewContext(docTable); ctxDef = xmlXPathNewContext(docDef); /* Get the reiterate records */ resDef = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry)", ctxDef); insHits = (short)xmlXPathCastToNumber(resDef); for (i = 1; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry[%d]/@Reiterate", i); resDef = xmlXPathEval((const xmlChar *)insPath, ctxDef); insValue = (char *)xmlXPathCastToString(resDef); if (strcmp(insValue, "True") == 0) { /* Get Record Name */ sprintf(insPath, "/ProLinga/Repository/Command/Object/Table/OccurrencesTableRecordEntry/TableRecordEntry[%d]/RecordName", i); resDef = xmlXPathEval((const xmlChar *)insPath, ctxDef); insValue = (char *)xmlXPathCastToString(resDef); // if ( (strcmp(tableName,"PickList") == 0 ) | // (strcmp(tableName,"VariableGroup") == 0 ) | // (strcmp(tableName,"Index") == 0 ) | // (strcmp(tableName,"Table") == 0 ) | // (strcmp(tableName,"Record") == 0 ) ) // { /* Get instances HACK */ sprintf(insPath, "/ProLinga/Occurrences%s", insValue); resTable = xmlXPathEval((const xmlChar *)insPath, ctxTable); /* Empty node */ sprintf(tmpValue, "Occurrences%s", insValue); // } // else // { // /* Get instances HACK */ // if (insValue[(strlen(insValue) -1 )] == 'x') // sprintf(insPath, "/ProLinga/%ses", insValue); // else // sprintf(insPath, "/ProLinga/%ss", insValue); // resTable = xmlXPathEval((const xmlChar *)insPath, ctxTable); // // /* Empty node */ // strcpy(tmpValue, insValue); // if (insValue[(strlen(insValue) -1 )] == 'x') // strcat(tmpValue, "es"); // else // strcat(tmpValue, "s"); // } curTmp = xmlNewTextChild (*curReq, NULL, (const xmlChar *)tmpValue, (const xmlChar *)""); if (xmlIsBlankNode(resTable->nodesetval->nodeTab[0]->xmlChildrenNode)== 1) { curTable = resTable->nodesetval->nodeTab[0]->xmlChildrenNode; while (curTable != NULL) { if (xmlNodeIsText(curTable) == 0) break; curTable = curTable->next; } if (curTable != NULL) { xmlAddChild(curTmp, xmlCopyNodeList(curTable)); } } } } /* Clean up */ xmlFreeDoc(docTable); /* Return */ return 0; } int repPut(const xmlDocPtr docReq) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; char *status; int retStatus = 0; /* Put to repository */ docRes = RC_Put(docReq); /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Find Out Status */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/@Status", ctxRes); status = (char *)xmlXPathCastToString(resRes); if ( strcmp(status, "Ok") != 0) retStatus = 10103; /* Clean up */ xmlFreeDoc(docRes); /* Return */ return retStatus; } int repDelete(const char *objAppn, const char *objType, const char *objName) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; char *status; int retStatus = 0; /* Delete Data */ docRes = RC_Delete(objAppn, objType, objName); /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Find Out Status */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/@Status", ctxRes); status = (char *)xmlXPathCastToString(resRes); if ( strcmp(status, "Ok") != 0) retStatus = 10105; /* Clean up */ xmlFreeDoc(docRes); /* Return */ return retStatus; } int repSysInfoSetting(const char *setting, char *retValue) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; char *rcStatus, tmpValue[255]; int retStatus = 0; docRes = RC_SysInfo(); /* Create XPath environments */ ctxRes = xmlXPathNewContext(docRes); /* Find Out Status */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/@Status", ctxRes); rcStatus = (char *)xmlXPathCastToString(resRes); if ( strcmp(rcStatus, "Ok") != 0) retStatus = 10102; else { sprintf(tmpValue, "/ProLinga/Repository/Command/%s", setting); resRes = xmlXPathEval((const xmlChar *)tmpValue, ctxRes); strcpy(retValue, (char *)xmlXPathCastToString(resRes)); } /* Return */ return retStatus; } int repGet(xmlDocPtr *docRes, const char *objAppn, const char *objType, const char *objName) { xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; char *rcStatus; int retStatus = 0; *docRes = RC_Get(objAppn, objType, objName); /* Create XPath environments */ ctxRes = xmlXPathNewContext(*docRes); /* Find Out Status */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/@Status", ctxRes); rcStatus = (char *)xmlXPathCastToString(resRes); if ( strcmp(rcStatus, "Ok") != 0) retStatus = 10102; return retStatus; } int repClrEntry(const char *tableName, const char *instance) { xmlDocPtr docTable; xmlNodePtr curTable; xmlXPathContextPtr ctxTable; xmlXPathObjectPtr resTable; char insLabel[255], insPath[255]; /* Note get instance xml document */ docTable = tablePtr->getDocBuffer(&tablePtr, tableName); /* Init XPath */ //xmlXPathInit(); /* Create XPath context */ ctxTable = xmlXPathNewContext(docTable); /* Locate instances */ sprintf(insLabel, "%s", instance); sprintf(insPath, "/ProLinga/%s", insLabel); resTable = xmlXPathEval((const xmlChar *)insPath, ctxTable); if (resTable->nodesetval == NULL || resTable->nodesetval->nodeNr == 0) { /* Nothing */ } else //if (xmlIsBlankNode(resTable->nodesetval->nodeTab[0])== 0) { /* Free node list */ //xmlFreeNodeList(resTable->nodesetval->nodeTab[0]); //printf("not empty\n"); curTable = resTable->nodesetval->nodeTab[0]; while (curTable != NULL) { if (xmlNodeIsText(curTable) == 0) break; curTable = curTable->next; } xmlUnlinkNode(curTable); xmlFreeNodeList(curTable); } /* Add empty instance tag */ curTable = xmlDocGetRootElement(docTable); xmlNewTextChild (curTable, NULL, (const xmlChar *)insLabel, (const xmlChar *)""); /* Store xml document */ tablePtr->putDocBuffer(&tablePtr, tableName, docTable); /* Clean up */ xmlFreeDoc(docTable); /* Return */ return 0; } int repPutEntry(const char *keyValue, const char *sequenceNo, const char *recName, const char *tableName, const bool isMainThread) { xmlDocPtr docTable, docRec; xmlNodePtr curTable; xmlXPathContextPtr ctxTable, ctxRec; xmlXPathObjectPtr resTable, resRec; short i, insHits; int seqNo; const char *tmpValueWork = NULL; char insPath[255], *retBigValue, *tmpValue = NULL; char *insValue; /* Get XML buffer document */ docTable = tablePtr->getDocBuffer(&tablePtr, tableName); /* Get XPath context */ ctxTable = xmlXPathNewContext(docTable); /* Get Dictionary Names */ docRec = RC_Get(biAppnPtr->getAppn(), "Record", recName); /* Get XPath context */ ctxRec = xmlXPathNewContext(docRec); resRec = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry)", ctxRec); insHits = (short)xmlXPathCastToNumber(resRec); /* Set SequenceNo */ seqNo = atoi(sequenceNo); /* Add base entry if needed in xml buffer */ sprintf(insPath, "/ProLinga/%s", keyValue); resTable = xmlXPathEval((const xmlChar *)insPath, ctxTable); if (resTable->nodesetval == NULL || resTable->nodesetval->nodeNr == 0) { curTable = xmlDocGetRootElement(docTable); xmlNewTextChild (curTable, NULL, (const xmlChar *)keyValue, (const xmlChar *)""); } /* Find out if record exist */ sprintf(insPath, "/ProLinga/%s/%s[@SequenceNo=\"%d\"]", keyValue, recName, seqNo); resTable = xmlXPathEval((const xmlChar *)insPath, ctxTable); if (resTable->nodesetval == NULL || resTable->nodesetval->nodeNr == 0) { /* Do nothing */ } else { /* Remove current sub-node list */ curTable = resTable->nodesetval->nodeTab[0]; while (curTable != NULL) { if (xmlNodeIsText(curTable) == 0) break; curTable = curTable->next; } /* remove node */ xmlUnlinkNode(curTable); xmlFreeNodeList(curTable); } /* Add entry */ curTable = xmlDocGetRootElement(docTable); curTable = curTable->xmlChildrenNode; while (curTable != NULL) { if ((!xmlStrcmp(curTable->name, (const xmlChar *)keyValue))) break; //if (xmlNodeIsText(curTable) == 0) // break; curTable = curTable->next; } curTable = xmlNewTextChild (curTable, NULL, (const xmlChar *)recName, (const xmlChar *)""); xmlNewProp (curTable, (const xmlChar *)"SequenceNo", (const xmlChar *)sequenceNo); /* Loop through datadictionaries */ for (i = 1; i <= insHits; i++) { /* Get Dictionary Name */ sprintf(insPath, "/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry[%d]/DataDictionaryName", i); resRec = xmlXPathEval((const xmlChar *)insPath, ctxRec); insValue = (char *)xmlXPathCastToString(resRec); /* Get value from data ref */ tmpValue = new char[255]; sprintf(tmpValue, "F-%s.%s.%s", insValue, tableName, recName); // getDataRef(tmpValue, isMainThread, retBigValue, false); tmpValueWork = tmpValue; retBigValue = getDataRef(tmpValueWork, isMainThread, retBigValue, true); if (retBigValue == NULL) { retBigValue = new char[2]; strcpy(retBigValue, ""); } /* Clean Up */ if (tmpValue != NULL) delete tmpValue; /* Write to xml buffer */ /* Temp HACK */ if (strcmp(insValue, "Default") == 0) xmlNewProp(curTable, (const xmlChar *)insValue, (const xmlChar *)retBigValue); else if (strcmp(insValue, "Primary") == 0) xmlNewProp(curTable, (const xmlChar *)insValue, (const xmlChar *)retBigValue); else if (strcmp(insValue, "Reiterate") == 0) xmlNewProp(curTable, (const xmlChar *)insValue, (const xmlChar *)retBigValue); else xmlNewTextChild (curTable, NULL, (const xmlChar *)insValue, (const xmlChar *)retBigValue); /* Clean up */ delete retBigValue; } /* bufTmp = xmlBufferCreate(); xmlNodeDump(bufTmp, docTable, curTable, 0, 1); printf("%s\n", (char *)xmlBufferContent(bufTmp)); xmlBufferFree(bufTmp); */ /* Store xml document */ tablePtr->putDocBuffer(&tablePtr, tableName, docTable); /* Clean up */ xmlFreeDoc(docRec); xmlFreeDoc(docTable); /* Return */ return 0; } int repGetEntry(const char *keyValue, const char *sequenceNo, const char *recName, const char *tableName, const bool isMainThread) { xmlDocPtr docRes, docRec; xmlXPathContextPtr ctxRes, ctxRec; xmlXPathObjectPtr resRes, resRec; short i, insHits; char insPath[255], tmpValue[255]; char *insValue; int seqNo; /* Note get instance xml document */ docRes = tablePtr->getDocBuffer(&tablePtr, tableName); /* Init XPath */ //xmlXPathInit(); /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get Dictionary Names */ docRec = RC_Get(biAppnPtr->getAppn(), "Record", recName); /* Init XPath */ //xmlXPathInit(); ctxRec = xmlXPathNewContext(docRec); resRec = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry)", ctxRec); insHits = (short)xmlXPathCastToNumber(resRec); /* Go through DataDictionaries */ for (i = 1; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object/Record/OccurrencesDataDictionaryEntry/DataDictionaryEntry[%d]/DataDictionaryName", i); resRec = xmlXPathEval((const xmlChar *)insPath, ctxRec); insValue = (char *)xmlXPathCastToString(resRec); //printf("DD is : %s\n", insValue); /* Get Values */ seqNo = atoi(sequenceNo); /* Temp HACK */ if (strcmp(insValue, "Default") == 0) sprintf(insPath, "/ProLinga/%s/%s[@SequenceNo=\"%d\"]/@%s", keyValue, recName, seqNo, insValue); else if (strcmp(insValue, "Primary") == 0) sprintf(insPath, "/ProLinga/%s/%s[@SequenceNo=\"%d\"]/@%s", keyValue, recName, seqNo, insValue); else if (strcmp(insValue, "Reiterate") == 0) sprintf(insPath, "/ProLinga/%s/%s[@SequenceNo=\"%d\"]/@%s", keyValue, recName, seqNo, insValue); else sprintf(insPath, "/ProLinga/%s/%s[@SequenceNo=\"%d\"]/%s", keyValue, recName, seqNo, insValue); resRes = xmlXPathEval((const xmlChar *)insPath, ctxRes); if (resRes->nodesetval == NULL) { xmlFreeDoc(docRes); xmlFreeDoc(docRec); return 10104; } /* Assign value to DataRef */ sprintf(tmpValue, "F-%s.%s.%s", insValue, tableName, recName); putDataRef(tmpValue, (char *)xmlXPathCastToString(resRes), 0, isMainThread); } /* Clean up */ xmlFreeDoc(docRes); xmlFreeDoc(docRec); /* Return */ return 0; }