void JSON_Append_array(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT json;
	C_TEXT node;
	C_TEXT returnValue;
	
	json.fromParamAtIndex(pParams, 1);
	node.fromParamAtIndex(pParams, 2);
	
	JSONNODE *n = _fromHex(json);
	
	if(n){
		std::wstring nodeName;
		_copyString(node, nodeName);

		JSONNODE *_node = json_new(JSON_NODE);
		
		json_set_name(_node, nodeName.c_str());
		json_cast(_node, JSON_ARRAY);
		json_push_back(n, _node);
		
		_toHex(_node, returnValue);
	}
	
	returnValue.setReturn(pResult);
}
/**
 * Builds Native Libjson Node tree recusively
 * \param pANode A SettingsAPI's Node.
 * \return libjson's equivalent to SettingNode including children. 
 *          If parentAbstractNode is null, then empty native node is returned
 */
JSONNODE* buildNativeJSONTreeNode(SNI* pANode) {
    if (pANode == NULL) {
        return json_new(identifyNodeType(SNI::TYPE_OBJECT));
    }

    JSONNODE* pNNode = json_new(identifyNodeType(pANode->getType()));
    json_set_name(pNNode, pANode->getKey().c_str());

    switch (pANode->getType()) {
        case SNI::TYPE_VALUE:
        {
            json_set_a(pNNode, pANode->readString().c_str());
            break;
        }
        case SNI::TYPE_OBJECT:
        case SNI::TYPE_ARRAY:
        {
            std::vector<SNI*> children = pANode->getChildren();
            std::vector<SNI*>::iterator it = children.begin();
            while (it != children.end()) {
                SNI* cANode = *it;
                JSONNODE* cNChild = buildNativeJSONTreeNode(cANode);
                json_insert(pNNode, json_end(pNNode), cNChild);
                ++it;
            }
            break;
        }
        default:
            // Node is undefined type.
            break;
    }
    return pNNode;
}
void JSON_Append_bool_array(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT json;
	C_TEXT node;
	ARRAY_BOOLEAN values;
	C_TEXT returnValue;
	
	json.fromParamAtIndex(pParams, 1);
	node.fromParamAtIndex(pParams, 2);
	values.fromParamAtIndex(pParams, 3);
	
	JSONNODE *n = _fromHex(json);
	
	if(n){
		std::wstring nodeName;
		_copyString(node, nodeName);
		
		JSONNODE *_node = json_new(JSON_ARRAY);
		json_set_name(_node, nodeName.c_str());
		
		for (unsigned int i = 1; i < values.getSize(); ++i) {
			json_push_back(_node, json_new_b(L"", values.getBooleanValueAtIndex(i)));
		}
		
		json_push_back(n, _node);
		_toHex(_node, returnValue);
	}
	
	returnValue.setReturn(pResult);
}
Ejemplo n.º 4
0
bool admJson::addNode(const char *nodeName)
{
    JSONNODE *n = json_new(JSON_NODE);    
    cookies.push_back((void *)n);
    json_set_name(n,nodeName);
    cookie=(void *)n;
    return true;
}
Ejemplo n.º 5
0
JSONNODE* json_wlparam_format(wlp_descr_t* wlp) {
	JSONNODE* wlp_node = json_new(JSON_NODE);

	json_set_name(wlp_node, wlp->name);

	switch(wlp->type) {
	case WLP_BOOL:
		json_push_back(wlp_node, json_new_a("type", "bool"));
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_b("default", wlp->defval.b));
		break;
	case WLP_INTEGER:
		json_push_back(wlp_node, json_new_a("type", "integer"));
		if(wlp->range.range) {
			json_push_back(wlp_node, json_new_i("min", wlp->range.i_min));
			json_push_back(wlp_node, json_new_i("max", wlp->range.i_max));
		}
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_i("default", wlp->defval.i));
		break;
	case WLP_FLOAT:
		json_push_back(wlp_node, json_new_a("type", "float"));
		if(wlp->range.range) {
			json_push_back(wlp_node, json_new_f("min", wlp->range.d_min));
			json_push_back(wlp_node, json_new_f("max", wlp->range.d_max));
		}
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_f("default", wlp->defval.f));
		break;
	case WLP_SIZE:
		json_push_back(wlp_node, json_new_a("type", "size"));
		if(wlp->range.range) {
			json_push_back(wlp_node, json_new_i("min", wlp->range.sz_min));
			json_push_back(wlp_node, json_new_i("max", wlp->range.sz_max));
		}
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_i("default", wlp->defval.sz));
		break;
	case WLP_RAW_STRING:
		json_push_back(wlp_node, json_new_a("type", "string"));
		json_push_back(wlp_node, json_new_i("len", wlp->range.str_length));
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_a("default", wlp->defval.s));
		break;
	case WLP_STRING_SET:
		json_push_back(wlp_node, json_new_a("type", "strset"));
		json_push_back(wlp_node, json_wlparam_strset_format(wlp));
		if(wlp->defval.enabled)
			json_push_back(wlp_node, json_new_i("default", wlp->defval.ssi));
		break;
	}

	json_push_back(wlp_node, json_new_i("flags", wlp->flags));
	json_push_back(wlp_node, json_new_a("description", wlp->description));

	return wlp_node;
}
Ejemplo n.º 6
0
void Json::SetValue(JSONNODE* node, const string& key, const vector<string>& array)
{
	if(node == NULL)
		node = mpRootNode;

	JSONNODE* c = json_new(JSON_ARRAY);
	json_set_name(c, key.c_str());
	for(size_t i = 0; i < array.size(); i++)
	{
		json_push_back(c, json_new_a(NULL, array[i].c_str()));
	}
	json_push_back(node, c);
}
Ejemplo n.º 7
0
JSONNODE* json_wlparam_format_all(wlp_descr_t* wlp) {
	JSONNODE* node = json_new(JSON_NODE);
	JSONNODE* wlp_node = NULL;

	json_set_name(node, "params");

	while(wlp->type != WLP_NULL) {
		wlp_node = json_wlparam_format(wlp);

		json_push_back(node, wlp_node);
		wlp++;
	}

	return node;
}
void JSON_SET_NAME(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT json;
	C_TEXT name;
	
	json.fromParamAtIndex(pParams, 1);
	name.fromParamAtIndex(pParams, 2);
	
	JSONNODE *n = _fromHex(json);
	
	if(n){
		std::wstring w;
		_copyString(name, w);
		json_set_name(n, w.c_str());	
	}
}
Ejemplo n.º 9
0
/**
 * Gets the current CPM reading as
 * { "cpm": {
 *     "value": val,      // Actual value
 *     "valid": boolean,  // Valid flag
 *     "raw": val,        // Uncompensated value
 *     "cpm30": val       // 30 second window
 *      }
 *  }
 *
 *  See Geiger.cpp for a more in-depth explanation of
 *  raw and compensated CPM values.
 */
void cmd_cpm(char *line) {

  JSONNODE *n = json_new(JSON_NODE);
  JSONNODE *reading = json_new(JSON_NODE);
  json_set_name(reading, "cpm");
  json_push_back(reading, json_new_f("value", system_geiger->get_cpm_deadtime_compensated()));
  json_push_back(reading, json_new_b("valid", system_geiger->is_cpm_valid()));
  json_push_back(reading, json_new_f("raw", system_geiger->get_cpm()));
  json_push_back(reading, json_new_f("cpm30", system_geiger->get_cpm30()));
  json_push_back(n, reading);
  json_char *jc = json_write_formatted(n);
  serial_write_string(jc);
  json_free(jc);
  json_delete(n);

}
Ejemplo n.º 10
0
static JSONNODE* json_wlparam_strset_format(wlp_descr_t* wlp) {
	JSONNODE* node = json_new(JSON_ARRAY);
	JSONNODE* el;
	int i;
	char* str;

	json_set_name(node, "strset");

	for(i = 0; i < wlp->range.ss_num; ++i) {
		str = wlp->range.ss_strings[i];

		el = json_new(JSON_STRING);
		json_set_a(el, str);

		json_push_back(node, el);
	}

	return node;
}
Ejemplo n.º 11
0
/**
 * Displays status of log area: records used, total records
 * and logging interval (in seconds)
 */
void cmd_logstatus(char *line) {
  JSONNODE *n = json_new(JSON_NODE);
  JSONNODE *n2 = json_new(JSON_NODE);
  json_set_name(n2, "logstatus");
  json_push_back(n2, json_new_i("used", flashstorage_log_currentrecords()));
  json_push_back(n2, json_new_i("total", flashstorage_log_maxrecords()));
  const char *sloginter = flashstorage_keyval_get("LOGINTERVAL");
  uint32_t c = 0;
  if(sloginter != 0) {
    sscanf(sloginter, "%"PRIu32"", &c);
  } else {
    c = 30 * 60;
  }
  json_push_back(n2, json_new_i("interval", c));
  json_push_back(n, n2);
  json_char *jc = json_write_formatted(n);
  serial_write_string(jc);
  json_free(jc);
  json_delete(n);
}
void JSON_Append_node(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT json;
	C_TEXT node;
	C_TEXT nodeText;	
	C_TEXT returnValue;
	
	json.fromParamAtIndex(pParams, 1);
	node.fromParamAtIndex(pParams, 2);
	nodeText.fromParamAtIndex(pParams, 3);
	
	JSONNODE *n = _fromHex(json);
	
	if(n){
		std::wstring nodeName;
		_copyString(node, nodeName);
		
		JSONNODE *_node;
		
		if(!nodeText.getUTF16Length()){
			_node = json_new(JSON_NODE);
		}else{
			std::wstring w;
			_copyString(nodeText, w);
			_node = json_parse(w.c_str());
		}
		
		if(_node){
			json_set_name(_node, nodeName.c_str());
			json_push_back(n, _node);
		}
		
		_toHex(_node, returnValue);
	}
	
	returnValue.setReturn(pResult);
}
void JSON_Append_text_array(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT json;
	C_TEXT node;
	ARRAY_TEXT values;
	C_TEXT returnValue;
	
	json.fromParamAtIndex(pParams, 1);
	node.fromParamAtIndex(pParams, 2);
	values.fromParamAtIndex(pParams, 3);
	
	JSONNODE *n = _fromHex(json);
	
	if(n){
		std::wstring nodeName;
		_copyString(node, nodeName);
		
		JSONNODE *_node = json_new(JSON_ARRAY);
		json_set_name(_node, nodeName.c_str());
		
		for (unsigned int i = 1; i < values.getSize(); ++i) {
			CUTF16String s;
			values.copyUTF16StringAtIndex(&s, i);
			C_TEXT t;
			t.setUTF16String(&s);
			std::wstring valueText;
			_copyString(t, valueText);
			json_push_back(_node, json_new_a(L"", valueText.c_str()));
		}
		
		json_push_back(n, _node);
		_toHex(_node, returnValue);
	}	
	
	returnValue.setReturn(pResult);
}