コード例 #1
0
ファイル: node_methods.c プロジェクト: greenpdx/round
bool round_node_getregistry(RoundNode* node, const char* key, 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_GET_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_rpc_setparamsobject(reqObj, paramsObj);

  // Request

  RoundJSONObject* resObj = NULL;
  bool isSuccess = round_node_postmessage(node, reqObj, &resObj, err);

  // Get result

  if (isSuccess) {
    RoundJSONObject* resultObj;
    if (round_json_rpc_getparamsobject(reqObj, &resultObj)) {
      const char* keyValue;
      if (round_json_map_getstring(paramsObj, ROUND_SYSTEM_METHOD_PARAM_KEY, &keyValue)) {
        *value = round_strdup(keyValue);
      }
    }
  }

  // Delete objects

  if (resObj) {
    round_json_object_delete(resObj);
  }
  round_json_object_delete(reqObj);

  return isSuccess;
}
コード例 #2
0
ファイル: string_func.c プロジェクト: cybergarage/round
bool round_strloc(const char* str, char** buf)
{
  if (!buf)
    return false;

  if (*buf) {
    free(*buf);
    *buf = NULL;
  }

  if (!str)
    return true;

  *buf = round_strdup(str);

  return true;
}
コード例 #3
0
ファイル: json_object.c プロジェクト: cybergarage/round
bool round_json_object_tostringwithoption(RoundJSONObject* obj, RoundOption opt, const char** str)
{
  const char* jsonObjStr;

  if (!obj)
    return false;

  round_json_object_clearcaches(obj);

  if (round_json_object_isstring(obj)) {
    round_json_object_getstring(obj, &jsonObjStr);
    obj->cachedStr = round_strdup(jsonObjStr);
    *str = obj->cachedStr;
    return true;
  }

#if defined(ROUND_USE_JSON_PARSER_JANSSON)
  if (!obj->jsonObj)
    return false;

  int dumpOpt = 0;
  if (!(opt & RoundJSONOptionFormatCompact)) {
    dumpOpt |= JSON_INDENT(2);
  }
  if ((opt & RoundJSONOptionFormatSort)) {
    dumpOpt |= JSON_PRESERVE_ORDER;
  }

  obj->cachedStr = json_dumps(obj->jsonObj, dumpOpt);
  if (!obj->cachedStr)
    return false;

  *str = obj->cachedStr;
  return true;
#else
  return false;
#endif
}