/*
*
* 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 "Main.hpp"
#include
#include
#include
#include
#include "RunShare.hpp"
#include "LogicCommandDef.hpp"
#include "LogicCommands.hpp"
#include "DataRef.hpp"
#include "Logic.hpp"
#include "Thread.hpp"
#include "BuiltIn.hpp"
#include "CmdList.hpp"
#include "InitRunEnvironment.hpp"
/* Global settings */
pthread_t mainThreadId;
int RunRunLogic(const char *objSvc, const char *objAppn, const char *objName, const char *format, xmlDocPtr *docRespRun, char **externalError)
{
xmlDocPtr docParse;
xmlNodePtr cur = NULL, curRespRun;
char *argList[255], tmpValue[255], *resValue, *resContents;
int resType, resLength ;
bool isMainThread = true;
/* Set Main thread */
mainThreadId = pthread_self();
*docRespRun = xmlNewDoc((const xmlChar *)"1.0");
(*docRespRun)->children = xmlNewDocNode(*docRespRun, NULL, (const xmlChar *)"Response", NULL);
curRespRun = xmlDocGetRootElement(*docRespRun);
/* Run Logic */
biAppnPtr->setAppn((char *)objAppn);
argList[1] = (char *)objName;
CmdCall(argList, 1, isMainThread, false);
/* Get Response */
resType = lcResponsePtr->getResponseType();
resValue = lcResponsePtr->getResponseValue();
if (resType == LC_RESPONSE_TYPE_DATAREF)
{
resContents = getDataRef(resValue, isMainThread, tmpValue, false);
resLength = strlen(resContents);
if (strcmp(format, "XML") == 0)
{
/* Parse contents */
docParse = xmlParseMemory(resContents, resLength);
if (docParse == NULL)
{
/* ERROR */
printf("Error parsing file\n");
}
cur = xmlDocGetRootElement(docParse);
}
else
{
cur = xmlNewCDataBlock(*docRespRun, (const xmlChar *)resContents, resLength);
}
}
else if (resType == LC_RESPONSE_TYPE_FILE)
{
}
else if (resType == LC_RESPONSE_TYPE_TEXT)
{
resContents = textPtr->getValue(&textPtr, getDataRef(resValue, isMainThread, tmpValue, false));
resLength = strlen(resContents);
if (strcmp(format, "XML") == 0)
{
/* Parse contents */
docParse = xmlParseMemory(resContents, resLength);
if (docParse == NULL)
{
/* ERROR */
printf("Error parsing file\n");
}
cur = xmlDocGetRootElement(docParse);
}
else
{
cur = xmlNewCDataBlock(*docRespRun, (const xmlChar *)resContents, resLength);
}
}
else if (resType == LC_RESPONSE_TYPE_XML)
{
}
if (cur != NULL)
xmlAddChild(curRespRun, cur);
/* Clean up environment */
/* Clear all buffers, lists and stacks */
ResetBuffers();
ResetStores();
ResetScreenStack();
/* Reset built-in functions */
ResetBuiltIns();
// biAppnPtr->setAppn(XB_APPN_DEV);
/* Reset Logic Command buffers */
ResetLogicCommandBuffers();
/* Return */
return 0;
}