/* * * ProLinga-Run * * Copyright (C) 2002-2009 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 #include "Main.hpp" #include "RepositoryCommand.hpp" #include "DataRef.hpp" #include "CmdList.hpp" extern BiAppnPtr biAppnPtr; extern BiRepositoryStatusPtr biRepositoryStatusPtr; /* VariableGroup (G-) */ extern VariableGroupPtr vgrpPtr; /* Table.Record (F-) */ extern TablePtr tablePtr; /* Datastore for List Views */ extern ListStorePtr listStorePtr; void SplitRepositoryTableRecordName(const char *tablerec, char *tableName, char *recName) { const char *string; string = strstr(tablerec, "."); if (string == NULL) { strcpy(tableName, tablerec); strcpy(recName, tableName); } else { strcpy(recName, string + 1); strcpy(tableName, tablerec); tableName[(strlen(tablerec)-strlen(recName)-1)] = '\0'; } } /* Command : */ void CmdRepository(const char **argList, int argHits, bool isMainThread) { char recName[255], tableName[255], tmpValue[255], tmpValue2[255], retValue[255], *interfaceType; char indexValue[255][64], insPath[255], *insValue, *status, storeName[32]; char appnName[32]; short i, insHits; int retStatus; xmlDocPtr docDef, docRes, docReq = NULL; xmlNodePtr curReq = NULL; xmlXPathContextPtr ctxDef, ctxRes; xmlXPathObjectPtr resDef, resRes; GtkListStore *store; GtkTreeIter iter; /* Init */ biRepositoryStatusPtr->setRepositoryStatus(0); /* Get record and table name */ SplitRepositoryTableRecordName(argList[2], tableName, recName); if (strcmp(argList[1], "TEST") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Set Index Details - to be reviewed/automated */ strcpy(indexValue[1], "F-Application."); strcat(indexValue[1], tableName); strcpy(indexValue[2], "F-Type."); strcat(indexValue[2], tableName); strcpy(indexValue[3], "F-Name."); strcat(indexValue[3], tableName); getDataRef(indexValue[1], isMainThread, appnName, false); if (strlen(appnName) == 0) strcpy(appnName, biAppnPtr->getAppn()); /* Test if record can be read */ retStatus = repGet(&docRes, appnName, getDataRef(indexValue[2], isMainThread, retValue, false), getDataRef(indexValue[3], isMainThread, tmpValue, false)); if (retStatus != 0) { biRepositoryStatusPtr->setRepositoryStatus(retStatus); xmlFreeDoc(docRes); xmlFreeDoc(docDef); return; } /* Clean up */ xmlFreeDoc(docRes); xmlFreeDoc(docDef); /*Return*/ return; } else if (strcmp(argList[1], "GET") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Set Index Details - to be reviewed/automated */ strcpy(indexValue[1], "F-Application."); strcat(indexValue[1], tableName); strcpy(indexValue[2], "F-Type."); strcat(indexValue[2], tableName); strcpy(indexValue[3], "F-Name."); strcat(indexValue[3], tableName); getDataRef(indexValue[1], isMainThread, appnName, false); if (strlen(appnName) == 0) strcpy(appnName, biAppnPtr->getAppn()); /* Read Data */ retStatus = repGet(&docRes, appnName, getDataRef(indexValue[2], isMainThread, retValue, false), getDataRef(indexValue[3], isMainThread, tmpValue, false)); if (retStatus != 0) { biRepositoryStatusPtr->setRepositoryStatus(retStatus); xmlFreeDoc(docRes); xmlFreeDoc(docDef); return; } /* Get results and put in table buffer */ retStatus = repReadPutDataRef(docRes, recName, tableName, isMainThread); if (retStatus != 0) { biRepositoryStatusPtr->setRepositoryStatus(retStatus); xmlFreeDoc(docRes); xmlFreeDoc(docDef); return; } /* Move instances (if any) to xml buffer */ retStatus = repReadPutXmlBuffer(docRes, docDef, tableName); /* Create ListStore if object List store */ if (strcmp(getDataRef(indexValue[2], isMainThread, retValue, false), "ListStore") == 0) listStorePtr->loadStore(&listStorePtr, getDataRef(indexValue[3], isMainThread, tmpValue, false), docRes, isMainThread); /* Clean up */ xmlFreeDoc(docRes); xmlFreeDoc(docDef); } else if (strcmp(argList[1], "DELETE") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Set Index Details - to be reviewed/automated */ strcpy(indexValue[1], "F-Application."); strcat(indexValue[1], tableName); strcpy(indexValue[2], "F-Type."); strcat(indexValue[2], tableName); strcpy(indexValue[3], "F-Name."); strcat(indexValue[3], tableName); getDataRef(indexValue[1], isMainThread, appnName, false); if (strlen(appnName) == 0) strcpy(appnName, biAppnPtr->getAppn()); /* Delete Data */ retStatus = repDelete(appnName, getDataRef(indexValue[2], isMainThread, retValue, false), getDataRef(indexValue[3], isMainThread, tmpValue, false)); if (strcmp(getDataRef(indexValue[2], isMainThread, retValue, false), "Logic") == 0) retStatus = repDelete(appnName, "RunControl", getDataRef(indexValue[3], isMainThread, tmpValue, false)); if ( retStatus != 0) biRepositoryStatusPtr->setRepositoryStatus(retStatus); /* Clean up */ xmlFreeDoc(docDef); } else if (strcmp(argList[1], "PUT") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Set Index Details - to be reviewed/automated */ strcpy(indexValue[1], "F-Application."); strcat(indexValue[1], tableName); strcpy(indexValue[2], "F-Type."); strcat(indexValue[2], tableName); strcpy(indexValue[3], "F-Name."); strcat(indexValue[3], tableName); getDataRef(indexValue[1], isMainThread, appnName, false); if (strlen(appnName) == 0) strcpy(appnName, biAppnPtr->getAppn()); /* Create new put request */ retStatus = repWriteRequestShell(&docReq, &curReq, appnName, getDataRef(indexValue[2], isMainThread, tmpValue, false), getDataRef(indexValue[3], isMainThread, tmpValue2, false)); /* Move values from data buffer into req file */ retStatus = repWriteGetDataRef(&docReq, &curReq, recName, tableName, isMainThread); /* Get the contents of the xml buffer */ retStatus = repWriteGetXmlBuffer(&docReq, &curReq, docDef, tableName); /* xmlBufferPtr bufTmp; bufTmp = xmlBufferCreate(); curReq = xmlDocGetRootElement(docReq); xmlNodeDump(bufTmp, docReq, curReq, 0, 1); printf("%s\n", (char *)xmlBufferContent(bufTmp)); xmlBufferFree(bufTmp); */ /* Put to repository */ retStatus = repPut(docReq); if (retStatus != 0) biRepositoryStatusPtr->setRepositoryStatus(10103); /* Clean up request document */ //xmlFreeDoc(docReq); /* Clean up */ xmlFreeDoc(docReq); xmlFreeDoc(docDef); } else if (strcmp(argList[1], "OBJECTLIST") == 0) { /* KEEP THIS COMMAND???? */ /* IF SO CLEAN UP */ /* Get Table Layout Details */ //docDef = RC_Get(appnName, "Table", tableName); docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); //docDef = RC_Get(biAppnPtr->getAppn(), "Table", getDataRef(indexValue[2], isMainThread, retValue, false)); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Set Index Details - to be reviewed/automated */ strcpy(indexValue[1], "F-Application."); strcat(indexValue[1], tableName); strcpy(indexValue[2], "F-Type."); strcat(indexValue[2], tableName); strcpy(indexValue[3], "F-Name."); strcat(indexValue[3], tableName); getDataRef(indexValue[1], isMainThread, appnName, false); if (strlen(appnName) == 0) strcpy(appnName, biAppnPtr->getAppn()); if (strlen(getDataRef(argList[4], isMainThread, tmpValue, false)) == 0) docRes = RC_List(appnName, tableName, "*"); else docRes = RC_List(appnName, tableName, getDataRef(argList[4], isMainThread, tmpValue, false)); /* Init XPath */ xmlXPathInit(); /* 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) { biRepositoryStatusPtr->setRepositoryStatus(10102); return; } resRes = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object)", ctxRes); insHits = (short)xmlXPathCastToNumber(resRes); for (i = 1; i <= insHits; i++) { sprintf(insPath, "/ProLinga/Repository/Command/Object[%d]/@Name", i); resRes = xmlXPathEval((const xmlChar *)insPath, ctxRes); insValue = (char *)xmlXPathCastToString(resRes); //printf("DD is : %s\n", insValue); getDataRef(argList[6], isMainThread, storeName, false); store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); //getDataRef(argList[3], isMainThread, value, false); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, insValue, -1); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } /* Clean up */ xmlFreeDoc(docRes); xmlFreeDoc(docDef); } else if (strcmp(argList[1], "CLEARINSTANCE") == 0) { /* Clear Entry */ retStatus = repClrEntry(tableName, getDataRef(argList[4], isMainThread, tmpValue, false)); } else if (strcmp(argList[1], "PUTINSTANCE") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } /* Put Entry */ retStatus = repPutEntry(getDataRef(argList[4], isMainThread, tmpValue, false), getDataRef(argList[6], isMainThread, tmpValue2, false), recName, tableName, isMainThread); /* Clean up */ xmlFreeDoc(docDef); } else if (strcmp(argList[1], "GETINSTANCE") == 0) { /* Get Table Layout Details */ docDef = RC_Get(biAppnPtr->getAppn(), "Table", tableName); /* Init XPath */ xmlXPathInit(); /* Create XPath environment */ ctxDef = xmlXPathNewContext(docDef); /* Find Out interface type */ resDef = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Table/DataInterfaceType", ctxDef); interfaceType = (char *)xmlXPathCastToString(resDef); if (strcmp(interfaceType, DI_REPOSITORY) != 0) { biRepositoryStatusPtr->setRepositoryStatus(10101); xmlFreeDoc(docDef); return; } retStatus = repGetEntry(getDataRef(argList[4], isMainThread, tmpValue, false), getDataRef(argList[6], isMainThread, tmpValue2, false), recName, tableName, isMainThread); if (retStatus != 0) { biRepositoryStatusPtr->setRepositoryStatus(retStatus); return; } /* Clean up */ xmlFreeDoc(docDef); } else printf("Invalid Repository Option : %s\n", argList[1]); }