void cfg_load_global_config_file(void) { json_t *config = NULL; json_error_t err; const char *cfg_file = getenv("WATCHMAN_CONFIG_FILE"); #ifdef WATCHMAN_CONFIG_FILE if (!cfg_file) { cfg_file = WATCHMAN_CONFIG_FILE; } #endif if (!cfg_file || cfg_file[0] == '\0') { return; } if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { return; } config = json_load_file(cfg_file, 0, &err); if (!config) { w_log(W_LOG_ERR, "failed to parse json from %s: %s\n", cfg_file, err.text); return; } global_cfg = config; }
bool w_state_load(void) { json_t *state = NULL; bool result = false; json_error_t err; if (dont_save_state) { return true; } state = json_load_file(watchman_state_file, 0, &err); if (!state) { w_log(W_LOG_ERR, "failed to parse json from %s: %s\n", watchman_state_file, err.text); goto out; } if (!w_root_load_state(state)) { goto out; } result = true; out: if (state) { json_decref(state); } return result; }
static void load_config_file(void) { #ifdef WATCHMAN_CONFIG_FILE json_t *config = NULL; json_error_t err; if (access(WATCHMAN_CONFIG_FILE, R_OK) != 0 && errno == ENOENT) { return; } config = json_load_file(WATCHMAN_CONFIG_FILE, 0, &err); if (!config) { w_log(W_LOG_ERR, "failed to parse json from %s: %s\n", WATCHMAN_CONFIG_FILE, err.text); return; } json_unpack(config, "{s:i}", "settle", &trigger_settle); json_unpack(config, "{s:i}", "recrawl", &recrawl_period); // TODO: default ignore list parsed out here json_decref(config); #endif }
static json_t* LoadJsonFromJFile(JNIEnv* env, jobject jfile, string& fail_desc) { if ( jfile == NULL ) { fail_desc = "null object"; return NULL; } jstring path_jstr = (jstring)env->CallObjectMethod(jfile, gHook.java_io_file_getPath_method); jboolean copyio = false; const char* path_cstr = env->GetStringUTFChars(path_jstr, ©io); string path_str(path_cstr); env->ReleaseStringUTFChars(path_jstr, path_cstr); env->DeleteLocalRef(path_jstr); json_error_t js_err; json_t* js_obj = json_load_file(path_str.c_str(), 0, &js_err); if ( js_obj == NULL ) { char buf[1024]; snprintf(buf, sizeof(buf),"load json file failed:%s at: %d:%d %s. cause:%s", path_str.c_str(), js_err.line, js_err.position,js_err.source, js_err.text); ALOGI("%s",buf); fail_desc = buf; } return js_obj; }
void cfg_load_global_config_file(void) { json_error_t err; const char *cfg_file = getenv("WATCHMAN_CONFIG_FILE"); #ifdef WATCHMAN_CONFIG_FILE if (!cfg_file) { cfg_file = WATCHMAN_CONFIG_FILE; } #endif if (!cfg_file || cfg_file[0] == '\0') { return; } if (!w_path_exists(cfg_file)) { return; } auto config = json_load_file(cfg_file, 0, &err); if (!config) { w_log(W_LOG_ERR, "failed to parse json from %s: %s\n", cfg_file, err.text); return; } auto lockedState = configState.wlock(); lockedState->global_cfg = config; lockedState->global_config_file_path = cfg_file; }
//native Handle:json_load_file_ex(const String:sFilePath[PLATFORM_MAX_PATH], String:sErrorText[], maxlen, &iLine, &iColumn); static cell_t Native_json_load_file_ex(IPluginContext *pContext, const cell_t *params) { // Param 1 char *jsonfile; pContext->LocalToString(params[1], &jsonfile); char filePath[PLATFORM_MAX_PATH]; g_pSM->BuildPath(Path_Game, filePath, sizeof(filePath), jsonfile); json_error_t error; json_t *object = json_load_file(filePath, 0, &error); if(!object) { pContext->StringToLocalUTF8(params[2], params[3], error.text, NULL); cell_t *pLineValue; pContext->LocalToPhysAddr(params[4], &pLineValue); *pLineValue = error.line; cell_t *pColumnValue; pContext->LocalToPhysAddr(params[5], &pColumnValue); *pColumnValue = error.column; return BAD_HANDLE; } Handle_t hndlResult = g_pHandleSys->CreateHandle(htJanssonObject, object, pContext->GetIdentity(), myself->GetIdentity(), NULL); if(hndlResult == BAD_HANDLE) { pContext->ThrowNativeError("Could not create <Object> handle."); } return hndlResult; }
int teamd_config_load(struct teamd_context *ctx) { json_error_t jerror; size_t jflags = JSON_REJECT_DUPLICATES; if (!ctx->config_text && !ctx->config_file) { ctx->config_text = strdup(TEAMD_IMPLICIT_CONFIG); if (!ctx->config_text) return -ENOMEM; } if (ctx->config_text) { if (ctx->config_file) teamd_log_warn("Command line config string is present, ignoring given config file."); ctx->config_json = json_loads(ctx->config_text, jflags, &jerror); } else if (ctx->config_file) { ctx->config_json = json_load_file(ctx->config_file, jflags, &jerror); } if (!ctx->config_json) { teamd_log_err("Failed to parse config: %s on line %d, column %d", jerror.text, jerror.line, jerror.column); return -EIO; } return 0; }
static void file_not_found() { json_t *json; json_error_t error; char *pos; json = json_load_file("/path/to/nonexistent/file.json", 0, &error); if(json) fail("json_load_file returned non-NULL for a nonexistent file"); if(error.line != -1) fail("json_load_file returned an invalid line number"); /* The error message is locale specific, only check the beginning of the error message. */ pos = strchr(error.text, ':'); if(!pos) fail("json_load_file returne an invalid error message"); *pos = '\0'; if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json") != 0) fail("json_load_file returned an invalid error message"); if(json_error_code(&error) != json_error_cannot_open_file) fail("json_load_file returned an invalid error code"); }
int cmd_json(int argc, char **argv) { int i=1, ret=0; cJSON *obj = NULL; char *str = NULL; if(argv[++i]){ obj = json_load_file(argv[i]); } else{ json_usage(); return 0; } if(obj){ printf("json parse OK \n\n"); str = cJSON_Print(obj); if(str){ printf("%s \n", str); free(str); } cJSON_Delete(obj); } else{ printf("json parse failed \n"); } return 0; }
static void load_wrong_args() { json_t *json; json_error_t error; json = json_loads(NULL, 0, &error); if (json) fail("json_loads should return NULL if the first argument is NULL"); json = json_loadb(NULL, 0, 0, &error); if (json) fail("json_loadb should return NULL if the first argument is NULL"); json = json_loadf(NULL, 0, &error); if (json) fail("json_loadf should return NULL if the first argument is NULL"); json = json_loadfd(-1, 0, &error); if (json) fail("json_loadfd should return NULL if the first argument is < 0"); json = json_load_file(NULL, 0, &error); if (json) fail("json_load_file should return NULL if the first argument is NULL"); }
status_t drakvuf_get_function_rva(const char *rekall_profile, const char *function, addr_t *rva) { json_error_t error; json_t *root = json_load_file(rekall_profile, 0, &error); if (!root) { PRINT_DEBUG("Rekall profile error on line %d: %s\n", error.line, error.text); goto err_exit; } if (!json_is_object(root)) { PRINT_DEBUG("Rekall profile: root is not an objet\n"); goto err_exit; } json_t *functions = json_object_get(root, "$FUNCTIONS"); if(!functions) { PRINT_DEBUG("Rekall profile: no functions found\n"); goto err_exit; } json_t *jsymbol = json_object_get(functions, function); if(!jsymbol) { PRINT_DEBUG("Rekall profile: function '%s' not found\n", function); goto err_exit; } *rva = json_integer_value(jsymbol); return VMI_SUCCESS; err_exit: return VMI_FAILURE; }
int main (void) { json_t *root, *value, *persona; json_error_t err; const char *key; void *iter; root = json_load_file("prueba.json", 0, &err); if (root == NULL) { perror("Error: "); fprintf(stderr, "Jansson error: %s %d %d\n", err.text, err.column, err.line); return EXIT_FAILURE; } persona = json_object_get(root, "persona"); if (persona == NULL) return EXIT_FAILURE; iter = json_object_iter(persona); while (iter) { key = json_object_iter_key(iter); value = json_object_iter_value(iter); printf ("key del objeto %s\n", key); iter = json_object_iter_next(persona, iter); } json_decref(root); return EXIT_SUCCESS; }
int Patch::read(const string &file) { jRoot = json_load_file(file.c_str(), 0, &jError); if (!jRoot) { gu_log("[Patch::read] unable to read patch file! Error on line %d: %s\n", jError.line, jError.text); return PATCH_UNREADABLE; } if (!checkObject(jRoot, "root element")) return PATCH_INVALID; init(); /* TODO json_decref also when PATCH_INVALID */ if (!readCommons(jRoot)) return setInvalid(); if (!readColumns(jRoot)) return setInvalid(); if (!readChannels(jRoot)) return setInvalid(); #ifdef WITH_VST if (!readPlugins(jRoot, &masterInPlugins, PATCH_KEY_MASTER_IN_PLUGINS)) return setInvalid(); if (!readPlugins(jRoot, &masterOutPlugins, PATCH_KEY_MASTER_OUT_PLUGINS)) return setInvalid(); #endif json_decref(jRoot); sanitize(); return PATCH_READ_OK; }
struct ast_json *ast_json_load_new_file(const char *path, struct ast_json_error *error) { json_error_t jansson_error = {}; struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error); copy_error(error, &jansson_error); return r; }
int main () { json_t *units, *current_unit, *stats, *targetArea; json_error_t error; const char *unitname; units = json_load_file ("./BattleAbilities.json", 0, &error); if (!units) { /* the error variable contains error information */ printf ("load error \n"); exit (1); } printf ("proceeding %d ablilities...\n", (int)json_object_size (units)); json_object_foreach (units, unitname, current_unit) { json_object_del (current_unit, "damageAnimationType"); /* remove damageAnimationType */ stats = json_object_get (current_unit, "stats"); if (stats) { targetArea = json_object_get (stats, "targetArea"); if (targetArea) json_object_set(targetArea, "aoeOrderDelay", json_real (0.0)); }else printf ("get targetArea error\n"); }
// ------------------------------------------------------------------------------------------------- static le_result_t HandleImportJSON ( le_cfg_IteratorRef_t iterRef, ///< The iterator being written to. const char* filePathPtr ///< Load the JSON from a file at this path. ) // ------------------------------------------------------------------------------------------------- { // Attempt to load JSON file. If it fails to validate, then bail out. json_error_t error; json_t* decodedRootPtr = json_load_file(filePathPtr, 0, &error); if (decodedRootPtr == NULL) { fprintf(stderr, "JSON import error: line: %d, column: %d, position: %d, source: '%s', error: %s", error.line, error.column, error.position, error.source, error.text); return LE_FAULT; } // OK, looks like the JSON loaded, so iterate through it and dump it's contents into the // configTree. le_result_t result = HandleImportJSONIteration(iterRef, decodedRootPtr); json_decref(decodedRootPtr); return result; }
json_t *read_json(const char *filename) { json_error_t err; json_t *ret; ret = json_load_file(filename, JSON_REJECT_DUPLICATES, &err); return ret; }
/* 得到策略信息 */ struct policymsg get_policy_json (char *jsonfile) { struct policymsg policyinfo; int i, size; void *iter; json_t *object; json_t *iter_values; json_error_t error; object = json_object (); /* 读取策略 */ object = json_load_file (jsonfile, 0, &error); policyinfo.size = json_object_size (object); #if 0 //size = json_object_size (object); //printf("size=%d\n", size); /* 取出object中的值 */ //struct policy iter_get_value(json_t *object) char *result; result = json_dumps (object, JSON_PRESERVE_ORDER); printf ("result=%s\n", result); /* 判断读取的jansson类型 */ printf ("判断是什么类型\n"); my_json_type (object); printf ("result_size = %d\n", strlen (result)); #endif //printf("得到策略值\n"); iter = json_object_iter (object); i = 0; while (1) { strcpy (policyinfo.keyword[i], json_object_iter_key (iter)); iter_values = json_object_iter_value (iter); strcpy (policyinfo.keycount[i], json_string_value (iter_values)); //printf("values[%d]=%s\n", i,json_string_value(iter_values[i])); if ((iter = json_object_iter_next (object, iter)) == NULL) { //printf("iterate end\n"); break; } i++; } #if 0 iter = json_object_iter_at (object, "b"); if (iter) { iter_keys[i] = json_object_iter_key (iter); iter_values[i] = json_object_iter_value (iter); printf ("values[%d]=%s\n", i, json_string_value (iter_values[i])); } #endif json_decref (object); return policyinfo; }
static void load_node(DSLink *link, DSNode *node) { json_error_t err; json_t *json = json_load_file("saved_node.json", 0 , &err); if (json) { dslink_node_deserialize(link, node, json); json_decref(json); } }
int main() { const char *data_fname = "fredkins_init-f.json"; json_t *root; json_error_t error; root = json_load_file(data_fname, size_t flags, &error); return 0; }
Status JsonFile::load(const std::string &filename) { json_error_t error; json_t *root = json_load_file(filename.c_str(), loadFlags, &error); if (!root) return ABC_ERROR(ABC_CC_JSONError, error.text); reset(root); return Status(); }
/* high level init */ static SDL_bool init_game(session *s, game_state *gs, char const *root) { int i; json_t *game, *res; char const *path; path = set_path("%s/%s/%s", root, CONF_DIR, GAME_CONF); json_error_t err; game = json_load_file(path, 0, &err); if (*err.text != 0) { fprintf(stderr, "error: in %s:%d: %s\n", path, err.line, err.text); return SDL_FALSE; } i = TTF_Init(); if (i < 0) { fprintf(stderr, "error: could not init font library: %s\n", TTF_GetError()); return SDL_FALSE; } res = json_object_get(game, "resolution"); s->screen.x = json_integer_value(json_array_get(res, 0)); s->screen.y = json_integer_value(json_array_get(res, 1)); i = SDL_Init(SDL_INIT_VIDEO); if (i < 0) { fprintf(stderr, "error: could not init video: %s\n", SDL_GetError()); return SDL_FALSE; } s->w = SDL_CreateWindow("Fridge Filler", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, s->screen.x, s->screen.y, 0); if (!s->w) { fprintf(stderr, "Could not init video: %s\n", SDL_GetError()); return SDL_FALSE; } path = set_path("%s/%s", root, "icon.gif"); SDL_Surface *ico = IMG_Load(path); if (ico) { puts("have icon"); SDL_SetWindowIcon(s->w, ico); SDL_FreeSurface(ico); } s->r = SDL_CreateRenderer(s->w, -1, 0); gs->debug.font = 0; SDL_bool ok = load_config(s, gs, game, root); if (!ok) { return SDL_FALSE; } gs->run = gs->logo.active ? MODE_LOGO : gs->intro.active ? MODE_INTRO : MODE_GAME; clear_game(gs); return SDL_TRUE; }
const char *load_file_format(char str[]) { json_t *root; json_error_t error; root = json_load_file(str,0,&error); if(root == 0) { printf("Não foi possível ler o arquivo, linha %d\n",error.line); exit(1); } json_t * jFormat = json_object_get(root, "fileType"); const char * format = json_string_value(jFormat); return format; }
const int load_config_hasDash(void) { json_t *root; json_error_t error; root = json_load_file("config.json",0,&error); if(root == 0) { printf("Erro no arquivo de configuração, linha %d\n",error.line); exit(1); } json_t *jhasDash = json_object_get(root, "hasDash"); const int hasDash = json_integer_value(jhasDash); return hasDash; }
const double load_config_dashThickness(void) { json_t *root; json_error_t error; root = json_load_file("config.json",0,&error); if(root == 0) { printf("Erro no arquivo de configuração, linha %d\n",error.line); exit(1); } json_t *jglt = json_object_get(root, "dashThickness"); const double dashThickness = json_real_value(jglt); return dashThickness; }
const unsigned int load_graph_type(char str[]) { json_t *root; json_error_t error; root = json_load_file(str,0,&error); if(root == 0) { printf("Não foi possível ler o arquivo, linha %d\n",error.line); exit(1); } json_t *jType = json_object_get(root, "type"); const unsigned int type = json_integer_value(jType); return type; }
const char *load_config_fontFace(void) { json_t *root; json_error_t error; root = json_load_file("config.json",0,&error); if(root == 0) { printf("Não foi possível ler o arquivo, linha %d\n",error.line); exit(1); } json_t * jfontFace = json_object_get(root, "fontFace"); const char * fontFace = json_string_value(jfontFace); return fontFace; }
const char *load_file_name(char str[]) { json_t *root; json_error_t error; root = json_load_file(str,0,&error); if(root == 0) { printf("Não foi possível ler o arquivo, linha %d\n",error.line); exit(1);//remendo } json_t * jfileName = json_object_get(root, "fileName"); const char * fileName = json_string_value(jfileName); return fileName; }
const int load_config_fontSize(void) { json_t *root; json_error_t error; root = json_load_file("config.json",0,&error); if(root == 0) { printf("Erro no arquivo de configuração, linha %d\n",error.line); exit(1); } json_t *jfontSize = json_object_get(root, "fontSize"); const int fontSize = json_integer_value(jfontSize); return fontSize; }
int main() { json_t *json; json_error_t error; json = json_load_file("/path/to/nonexistent/file.json", &error); if(error.line != -1) fail("json_load_file returned an invalid line number"); if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json: No such file or directory") != 0) fail("json_load_file returned an invalid error message"); return 0; }