*** empty log message ***
This commit is contained in:
110
sicsobj.c
110
sicsobj.c
@ -6,10 +6,15 @@
|
||||
* Mark Koennecke, July 2007
|
||||
*/
|
||||
#include <sics.h>
|
||||
#include <tcl.h>
|
||||
#include "assert.h"
|
||||
#include "ifile.h"
|
||||
#include "sicsobj.h"
|
||||
#include "dynstring.h"
|
||||
#include "macro.h"
|
||||
#include "sicshipadaba.h"
|
||||
|
||||
extern int decodeSICSPriv(char *txt); /* from access.c */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void DefaultKill(void *data){
|
||||
return;
|
||||
@ -92,10 +97,104 @@ static int invokeOBJFunction(pSICSOBJ object, pHdb commandNode, SConnection *pCo
|
||||
SCWrite(pCon,"ERROR: internal error, function not found",eError);
|
||||
return 0;
|
||||
}
|
||||
status = pFunc(object, pCon, parArray,count);
|
||||
status = pFunc(object, pCon, commandNode, parArray,count);
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int ScriptObjFunc(pSICSOBJ obj, SConnection *pCon, pHdb commandNode,
|
||||
pHdb par[], int nCount){
|
||||
int status, i;
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
Tcl_DString com;
|
||||
char value[256];
|
||||
pDynString val = NULL;
|
||||
char *pPtr = NULL;
|
||||
|
||||
memset(value,0,256);
|
||||
GetHdbProperty(commandNode,"priv",value,256);
|
||||
status = decodeSICSPriv(value);
|
||||
if(!SCMatchRights(pCon,status)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(GetHdbProperty(commandNode,"script",value,256) != 1){
|
||||
SCWrite(pCon,"ERROR: script property not configured on this node",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Tcl_DStringInit(&com);
|
||||
Tcl_DStringAppend(&com,value,strlen(value));
|
||||
for(i = 0; i < nCount; i++){
|
||||
val = formatValue(par[i]->value);
|
||||
if(val != NULL){
|
||||
Tcl_DStringAppend(&com," ", 1);
|
||||
pPtr = GetCharArray(val);
|
||||
Tcl_DStringAppend(&com,pPtr,strlen(pPtr));
|
||||
DeleteDynString(val);
|
||||
}
|
||||
}
|
||||
|
||||
MacroPush(pCon);
|
||||
pTcl = InterpGetTcl(pServ->pSics);
|
||||
status = Tcl_Eval(pTcl,Tcl_DStringValue(&com));
|
||||
Tcl_DStringFree(&com);
|
||||
MacroPop();
|
||||
|
||||
if(status == TCL_OK){
|
||||
SCWrite(pCon,Tcl_GetStringResult(pTcl),eValue);
|
||||
return 1;
|
||||
} else {
|
||||
SCWrite(pCon,Tcl_GetStringResult(pTcl),eError);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int MakeScriptFunc(pSICSOBJ self, SConnection *pCon,
|
||||
int argc, char *argv[]){
|
||||
char path[512], *pPtr = NULL;
|
||||
pHdb parent = NULL, node = NULL;
|
||||
hdbValue func;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,
|
||||
"ERROR: not enough arguments: obj makescriptfunc path script priv",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!SCMatchRights(pCon,usMugger)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
strncpy(path,argv[2],511);
|
||||
pPtr = strrchr(path,'/');
|
||||
if(pPtr == NULL){
|
||||
/* no hierarchy */
|
||||
parent = self->objectNode;
|
||||
node = MakeHipadabaNode(path,HIPFUNC,1);
|
||||
} else {
|
||||
/* hierarchy */
|
||||
*pPtr = '\0';
|
||||
parent = GetHipadabaNode(self->objectNode,path);
|
||||
pPtr++;
|
||||
node = MakeHipadabaNode(pPtr,HIPFUNC,1);
|
||||
}
|
||||
if(parent == NULL || node == NULL){
|
||||
SCWrite(pCon,"ERROR: root path error or out of memory",eError);
|
||||
return 0;
|
||||
}
|
||||
node->value.v.obj = ScriptObjFunc;
|
||||
SetHdbProperty(node,"script",argv[3]);
|
||||
SetHdbProperty(node,"priv",argv[4]);
|
||||
AppendHipadabaCallback(node,HCBSET,MakeSICSFuncCallback(self));
|
||||
AddHipadabaChild(parent,node,pCon);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int InvokeSICSOBJ(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pSICSOBJ self = NULL;
|
||||
@ -106,7 +205,7 @@ int InvokeSICSOBJ(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
self = (pSICSOBJ)pData;
|
||||
assert(self != NULL);
|
||||
|
||||
if(argc < 1){
|
||||
if(argc < 2){
|
||||
SCWrite(pCon,"ERROR: Nothing to process",eError);
|
||||
return -1;
|
||||
}
|
||||
@ -114,10 +213,15 @@ int InvokeSICSOBJ(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
if(parNode != NULL && parNode->value.dataType == HIPFUNC){
|
||||
status = invokeOBJFunction(self, parNode, pCon, argc-2, &argv[2]);
|
||||
} else {
|
||||
status = ProcessSICSHdbPar(self->objectNode,pCon, argv[0],
|
||||
strncpy(buffer,argv[0],130);
|
||||
strcat(buffer," ");
|
||||
status = ProcessSICSHdbPar(self->objectNode,pCon, buffer,
|
||||
argc-1,&argv[1]);
|
||||
}
|
||||
if(status == -1){
|
||||
if(strcmp(argv[1],"makescriptfunc") == 0) {
|
||||
return MakeScriptFunc(self,pCon,argc,argv);
|
||||
}
|
||||
snprintf(buffer,131,"ERROR: no command or parameter found for key: %s",
|
||||
argv[1]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
|
Reference in New Issue
Block a user