Added json support.
r1192 | ffr | 2006-10-26 10:59:03 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
b22211eaf7
commit
c9408a9b45
@@ -632,7 +632,10 @@ struct json_object *mkJSON_Object(SConnection *pCon, char *pBuffer, int iOut)
|
|||||||
json_object_object_add(msg_json, "flag", json_object_new_string(pCode[iOut]));
|
json_object_object_add(msg_json, "flag", json_object_new_string(pCode[iOut]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (iOut == eStatus || iOut == eError || iOut == eWarning) {
|
if (iOut == eValue || iOut == eEvent) {
|
||||||
|
tmp_json = json_tokener_parse(pBuffer);
|
||||||
|
if (is_error(msg_json)) { linenum = __LINE__; goto reporterr; }
|
||||||
|
} else {
|
||||||
/* Strip \r and \n */
|
/* Strip \r and \n */
|
||||||
for (pBufferFrom=pBufferTo=pBuffer; ; pBufferFrom++) {
|
for (pBufferFrom=pBufferTo=pBuffer; ; pBufferFrom++) {
|
||||||
if (*pBufferFrom == '\r' || *pBufferFrom == '\n')
|
if (*pBufferFrom == '\r' || *pBufferFrom == '\n')
|
||||||
@@ -644,9 +647,6 @@ struct json_object *mkJSON_Object(SConnection *pCon, char *pBuffer, int iOut)
|
|||||||
}
|
}
|
||||||
tmp_json = json_object_new_string(pBuffer);
|
tmp_json = json_object_new_string(pBuffer);
|
||||||
if (is_error(msg_json)) { linenum = __LINE__; goto reporterr; }
|
if (is_error(msg_json)) { linenum = __LINE__; goto reporterr; }
|
||||||
} else {
|
|
||||||
tmp_json = json_tokener_parse(pBuffer);
|
|
||||||
if (is_error(msg_json)) { linenum = __LINE__; goto reporterr; }
|
|
||||||
}
|
}
|
||||||
json_object_object_add(msg_json, "data", tmp_json);
|
json_object_object_add(msg_json, "data", tmp_json);
|
||||||
return msg_json;
|
return msg_json;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ static int scriptUpdate = -1;
|
|||||||
static hdbUpdateTask taskData;
|
static hdbUpdateTask taskData;
|
||||||
enum formatStyle {plain, cli, json};
|
enum formatStyle {plain, cli, json};
|
||||||
char *formatName[] = {"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);
|
pDynString formatClientValue(char *name, hdbValue hVal, int children);
|
||||||
@@ -1409,14 +1409,33 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|||||||
pDynString parData = NULL;
|
pDynString parData = NULL;
|
||||||
char error[512], oriPath[512];;
|
char error[512], oriPath[512];;
|
||||||
int i, status;
|
int i, status;
|
||||||
|
int pathArg = 1, fmtArg=1;
|
||||||
|
char *usage ="ERROR:valid arguments are [-json] nodepath";
|
||||||
|
|
||||||
if(argc < 2) {
|
/*XXX
|
||||||
SCWrite(pCon,"ERROR: need path to node to print",eError);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SCWrite(pCon,usage,eError);
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
strncpy(oriPath,argv[1], 511);
|
strncpy(oriPath,argv[pathArg], 511);
|
||||||
targetNode = locateSICSNode(pSics,pCon,argv[1]);
|
targetNode = locateSICSNode(pSics,pCon,argv[pathArg]);
|
||||||
if(targetNode == NULL){
|
if(targetNode == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1616,14 +1635,32 @@ static pDynString formatJSONList(pHdb node){
|
|||||||
static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||||
int argc, char *argv[]){
|
int argc, char *argv[]){
|
||||||
pHdb node = NULL;
|
pHdb node = NULL;
|
||||||
int pathArg = 1;
|
|
||||||
pDynString listData = NULL;
|
pDynString listData = NULL;
|
||||||
|
int pathArg = 1, fmtArg=1;
|
||||||
|
char *usage ="ERROR:valid arguments are [-json] nodepath";
|
||||||
|
|
||||||
if(argc < 2) {
|
/*XXX
|
||||||
SCWrite(pCon,"ERROR: need path to node to print",eError);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SCWrite(pCon,usage,eError);
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*XXX
|
||||||
if(strchr(argv[1],'-') != NULL){
|
if(strchr(argv[1],'-') != NULL){
|
||||||
pathArg = 2;
|
pathArg = 2;
|
||||||
if(argc < 3){
|
if(argc < 3){
|
||||||
@@ -1631,20 +1668,20 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
node = locateSICSNode(pSics,pCon,argv[pathArg]);
|
node = locateSICSNode(pSics,pCon,argv[pathArg]);
|
||||||
if(node == NULL){
|
if(node == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strtolower(argv[1]);
|
strtolower(argv[pathArg]);
|
||||||
if (argc == 3) {
|
/*XXX if (argc == 3) {
|
||||||
if(strcmp(argv[1],"-val") == 0){
|
if(strcmp(argv[1],"-val") == 0){
|
||||||
listData = formatListWithVal(node);
|
listData = formatListWithVal(node);
|
||||||
} else if(strcmp(argv[1],"-cli") == 0 || currFmtStyle == cli){
|
} else if(strcmp(argv[1],"-cli") == 0 || currFmtStyle == cli){
|
||||||
listData = formatClientList(node);
|
listData = formatClientList(node);
|
||||||
}
|
}
|
||||||
} else {
|
} else { */
|
||||||
switch (currFmtStyle) {
|
switch (currFmtStyle) {
|
||||||
case cli:
|
case cli:
|
||||||
listData = formatClientList(node);
|
listData = formatClientList(node);
|
||||||
@@ -1656,7 +1693,7 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|||||||
default:
|
default:
|
||||||
listData = formatPlainList(node);
|
listData = formatPlainList(node);
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
if(listData == NULL){
|
if(listData == NULL){
|
||||||
SCWrite(pCon,"ERROR: failed to format list",
|
SCWrite(pCon,"ERROR: failed to format list",
|
||||||
eError);
|
eError);
|
||||||
@@ -1682,19 +1719,44 @@ static int AutoNotifyHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|||||||
int argc, char *argv[]){
|
int argc, char *argv[]){
|
||||||
pHdb node = NULL;
|
pHdb node = NULL;
|
||||||
int id, status;
|
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) {
|
if(argc < 3) {
|
||||||
SCWrite(pCon,"ERROR: need path and id in order to add notify",
|
SCWrite(pCon,"ERROR: need path and id in order to add notify",
|
||||||
eError);
|
eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
node = locateSICSNode(pSics,pCon,argv[1]);
|
node = locateSICSNode(pSics,pCon,argv[pathArg]);
|
||||||
if(node == NULL){
|
if(node == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = atoi(argv[2]);
|
id = atoi(argv[idArg]);
|
||||||
|
|
||||||
status = InstallSICSNotify(node, pCon, id, 1);
|
status = InstallSICSNotify(node, pCon, id, 1);
|
||||||
if(status == 1){
|
if(status == 1){
|
||||||
|
|||||||
Reference in New Issue
Block a user