Added json support.

r1192 | ffr | 2006-10-26 10:59:03 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
Ferdi Franceschini
2006-10-26 10:59:03 +10:00
committed by Douglas Clowes
parent b22211eaf7
commit c9408a9b45
2 changed files with 84 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ static int scriptUpdate = -1;
static hdbUpdateTask taskData;
enum formatStyle {plain, cli, json};
char *formatName[] = {"plain", "cli", "json"};
static enum formatStyle currFmtStyle=plain;
static enum formatStyle currFmtStyle=json;
pDynString formatClientValue(char *name, hdbValue hVal, int children);
@@ -1409,14 +1409,33 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
pDynString parData = NULL;
char error[512], oriPath[512];;
int i, status;
int pathArg = 1, fmtArg=1;
char *usage ="ERROR:valid arguments are [-json] nodepath";
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError);
/*XXX
switch (argc) {
case 2:
pathArg = 1;
currFmtStyle = plain;
break;
case 3:
pathArg = 2;
if(strcmp(argv[1],"-json") == 0){
currFmtStyle = json;
} else {
SCWrite(pCon,usage,eError);
return 0;
}
break;
default:
SCWrite(pCon,usage,eError);
return 0;
break;
}
*/
strncpy(oriPath,argv[1], 511);
targetNode = locateSICSNode(pSics,pCon,argv[1]);
strncpy(oriPath,argv[pathArg], 511);
targetNode = locateSICSNode(pSics,pCon,argv[pathArg]);
if(targetNode == NULL){
return 0;
}
@@ -1616,14 +1635,32 @@ static pDynString formatJSONList(pHdb node){
static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb node = NULL;
int pathArg = 1;
pDynString listData = NULL;
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError);
int pathArg = 1, fmtArg=1;
char *usage ="ERROR:valid arguments are [-json] nodepath";
/*XXX
switch (argc) {
case 2:
pathArg = 1;
currFmtStyle = plain;
break;
case 3:
pathArg = 2;
if(strcmp(argv[1],"-json") == 0){
currFmtStyle = json;
} else {
SCWrite(pCon,usage,eError);
return 0;
}
break;
default:
SCWrite(pCon,usage,eError);
return 0;
break;
}
*/
/*XXX
if(strchr(argv[1],'-') != NULL){
pathArg = 2;
if(argc < 3){
@@ -1631,20 +1668,20 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0;
}
}
*/
node = locateSICSNode(pSics,pCon,argv[pathArg]);
if(node == NULL){
return 0;
}
strtolower(argv[1]);
if (argc == 3) {
strtolower(argv[pathArg]);
/*XXX if (argc == 3) {
if(strcmp(argv[1],"-val") == 0){
listData = formatListWithVal(node);
} else if(strcmp(argv[1],"-cli") == 0 || currFmtStyle == cli){
listData = formatClientList(node);
}
} else {
} else { */
switch (currFmtStyle) {
case cli:
listData = formatClientList(node);
@@ -1656,7 +1693,7 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
default:
listData = formatPlainList(node);
}
}
//}
if(listData == NULL){
SCWrite(pCon,"ERROR: failed to format list",
eError);
@@ -1682,19 +1719,44 @@ static int AutoNotifyHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb node = NULL;
int id, status;
int pathArg = 1, idArg=2;
char *usage ="ERROR:valid arguments are [-json] nodepath id";
switch (argc) {
case 3:
pathArg = 1;
idArg = 2;
currFmtStyle = json;
break;
case 4:
/* pathArg = 2;
idArg = 3;
if(strcmp(argv[1],"-json") == 0){
currFmtStyle = json;
} else {
SCWrite(pCon,usage,eError);
return 0;
}*/
break;
default:
SCWrite(pCon,usage,eError);
return 0;
break;
}
/*XXX
if(argc < 3) {
SCWrite(pCon,"ERROR: need path and id in order to add notify",
eError);
return 0;
}
node = locateSICSNode(pSics,pCon,argv[1]);
*/
node = locateSICSNode(pSics,pCon,argv[pathArg]);
if(node == NULL){
return 0;
}
id = atoi(argv[2]);
id = atoi(argv[idArg]);
status = InstallSICSNotify(node, pCon, id, 1);
if(status == 1){