bool round_script_registry2json(RoundRegistry* reg, RoundJSONObject* jsonMap) { if (!jsonMap) return false; const char *val; if (!round_registry_getstring(reg, &val)) return false; round_json_map_setstring(jsonMap, ROUND_SYSTEM_METHOD_PARAM_KEY, round_registry_getkey(reg)); round_json_map_setstring(jsonMap, ROUND_SYSTEM_METHOD_PARAM_VALUE, val); return true; }
bool round_node_setmethod(RoundNode* node, const char* lang, const char* name, const char* code, RoundEncodeType encType, RoundError* err) { if (!node || !lang || !name || !code) return false; // Create request RoundJSONObject* reqObj = round_json_rpc_request_new(); if (!reqObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); return false; } round_json_rpc_setmethod(reqObj, ROUND_SYSTEM_METHOD_SET_METHOD); // Set params RoundJSONObject* paramsObj = round_json_map_new(); if (!paramsObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); round_json_object_delete(reqObj); return false; } round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_LANGUAGE, lang); round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_NAME, name); round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_CODE, code); switch (encType) { case RoundEncodeBase64: round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_ENCODE, ROUND_SYSTEM_METHOD_PARAM_BASE64); break; default: break; } round_json_rpc_setparamsobject(reqObj, paramsObj); // Request RoundJSONObject* resObj = NULL; bool isSuccess = round_node_postmessage(node, reqObj, &resObj, err); // Delete objects if (resObj) { round_json_object_delete(resObj); } round_json_object_delete(reqObj); return isSuccess; }
bool round_node_setregistry(RoundNode* node, const char* key, const char* value, RoundError* err) { if (!node || !key || !value) return false; // Create request RoundJSONObject* reqObj = round_json_rpc_request_new(); if (!reqObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); return false; } round_json_rpc_setmethod(reqObj, ROUND_SYSTEM_METHOD_SET_REGISTRY); // Set params RoundJSONObject* paramsObj = round_json_map_new(); if (!paramsObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); round_json_object_delete(reqObj); return false; } round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_KEY, key); round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_VALUE, value); round_json_rpc_setparamsobject(reqObj, paramsObj); // Request RoundJSONObject* resObj = NULL; bool isSuccess = round_node_postmessage(node, reqObj, &resObj, err); // Delete objects if (resObj) { round_json_object_delete(resObj); } round_json_object_delete(reqObj); return isSuccess; }
bool round_system_method_getregistry(RoundLocalNode* node, RoundJSONObject* params, RoundJSONObject** resultMap, RoundError* err) { const char* key, *val; RoundRegistry* reg; if (!round_json_object_ismap(params)) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INVALID_PARAMS); return false; } if (!round_json_map_getstring(params, ROUND_SYSTEM_METHOD_PARAM_KEY, &key)) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INVALID_PARAMS); return false; } reg = round_local_node_getregistry(node, key); if (!reg) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INVALID_PARAMS); return false; } *resultMap = round_json_map_new(); if (!(*resultMap)) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); return false; } if (!round_registry_getstring(reg, &val)) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); return false; } round_json_map_setstring((*resultMap), ROUND_SYSTEM_METHOD_PARAM_KEY, key); round_json_map_setstring((*resultMap), ROUND_SYSTEM_METHOD_PARAM_VALUE, val); round_json_map_setinteger((*resultMap), ROUND_SYSTEM_METHOD_PARAM_TS, round_registry_getts(reg)); round_json_map_setinteger((*resultMap), ROUND_SYSTEM_METHOD_PARAM_LTS, round_registry_getlts(reg)); return true; }
bool round_json_rpc_seterror(RoundJSONObject* mapObj, RoundError* err) { if (!round_json_object_ismap(mapObj)) return false; RoundJSONObject* errMap = round_json_map_new(); if (!errMap) return false; round_json_map_setinteger(errMap, ROUND_JSON_RPC_CODE, round_error_getdetailcode(err)); round_json_map_setstring(errMap, ROUND_JSON_RPC_MESSAGE, round_error_getdetailmessage(err)); round_json_map_setobject(mapObj, ROUND_JSON_RPC_ERROR, errMap); round_json_object_delete(errMap); return false; }
bool round_node_removemethod(RoundNode* node, const char* name, RoundError* err) { if (!node || !name) return false; // Create request RoundJSONObject* reqObj = round_json_rpc_request_new(); if (!reqObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); return false; } round_json_rpc_setmethod(reqObj, ROUND_SYSTEM_METHOD_REMOVE_METHOD); // Set params RoundJSONObject* paramsObj = round_json_map_new(); if (!paramsObj) { round_error_setjsonrpcerrorcode(err, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR); round_json_object_delete(reqObj); return false; } round_json_map_setstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_NAME, name); round_json_rpc_setparamsobject(reqObj, paramsObj); // Request RoundJSONObject* resObj = NULL; bool isSuccess = round_node_postmessage(node, reqObj, &resObj, err); // Delete objects if (resObj) { round_json_object_delete(resObj); } round_json_object_delete(reqObj); return isSuccess; }