diff --git a/src/base/json.c b/src/base/json.c index 5b321937b94bade15bbe3c2b361db24d8ec91375..1721faa37acdd1ca57b1ba9a4ede0a27fef23fa5 100644 --- a/src/base/json.c +++ b/src/base/json.c @@ -31,19 +31,18 @@ len = (end - str); \ is_paren = 1; \ } else \ - len = strcspn(str, __JSON_SPACE __JSON_BEGIN __JSON_END); \ + len = strcspn(str, __JSON_SPACE); \ if (level == asked_level && len < LKT_LINE_MAX - 1) \ strncpy(dest, str, len); \ str += len; \ /* Also decode '\"' => '"' */ \ if (is_paren) { \ ++str; \ - __replace(key, "\\\"", "\""); \ - __replace(val, "\\\"", "\""); \ + __replace(dest, "\\\"", "\""); \ } \ } -#define __SKIP_NEXT_JSON(str, len) \ +#define __SKIP_NEXT_JSON(str, len) \ { \ int is_paren = 0; \ if (str[0] == __JSON_SEP) { \ @@ -62,6 +61,10 @@ } else \ len = strcspn(str, __JSON_SPACE __JSON_BEGIN __JSON_END); \ str += len; \ + /* Also decode '\"' => '"' */ \ + if (is_paren) { \ + ++str; \ + } \ } /* WARN: strlen(from) >= strlen(to) */ @@ -101,6 +104,8 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use char key[LKT_LINE_MAX]; char val[LKT_LINE_MAX]; + LOG_DEBUG("JSON", "Begin parsing of json"); + for (;;) { size_t len = 0; __SKIP_JSON(str); @@ -113,8 +118,10 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use /* End of a block */ else if ((len = strspn(str, __JSON_END))) { - if (level == asked_level) + if (level == asked_level) { + LOG_DEBUG("JSON", "Completion call for json object"); call(NULL, NULL, 1, user); + } str += len; level -= len; } @@ -169,7 +176,7 @@ json_parse_get_count(const char *str, int asked_level) } if (level <= 0) - return len; + return ret_len; } return -1; } diff --git a/src/module/module_repo.c b/src/module/module_repo.c index 7528a12305202dad297e975aa31f38453ebac4af..e3e254bfd224a0f34290e12aba2dc990c532937c 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -62,13 +62,6 @@ struct module_repo_internal { char *get_fav_json; const uint64_t version; - /* Worker threads */ - struct worker_pool workers; - pthread_mutex_t mtx; /* Protect the updating field */ - // *INDENT-OFF* - volatile unsigned int updating : REPO_UPDATE_TYPE_COUNT; /* The correct size */ - // *INDENT-ON* - /* The database and the queue */ struct queue *queue; volatile sqlite3 *db; @@ -78,6 +71,13 @@ struct module_repo_internal { * - len: the length of the string, not its size (which is PATH_MAX) * - kara: the kara structure, which contains all the data to create the filename */ void (*craft_filename)(char str[PATH_MAX], size_t, struct kara *); + + /* Worker threads */ + // *INDENT-OFF* + volatile unsigned int updating : REPO_UPDATE_TYPE_COUNT; /* The correct size */ + // *INDENT-ON* + pthread_mutex_t mtx; /* Protect the updating field */ + struct worker_pool workers; }; struct __uri { @@ -517,12 +517,10 @@ end_no_lock: } static void -__handle_fav_list_internal(const char UNUSED *key, const char *val, int comp, void *user) +__handle_fav_list_internal(const char UNUSED *key, const char *val, int UNUSED comp, void *user) { - if (comp) { - /* Already processed because we only want one line */ + if (val) return; - } struct __uri *uri = (struct __uri *) user; uri->uri.id = strtol(val, NULL, 0); @@ -575,17 +573,16 @@ __handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size) } static void -__worker_import_favorites_internal(const char UNUSED *key, const char *val, int comp, void *user) +__worker_import_favorites_internal(const char UNUSED *k, const char *val, int UNUSED c, void *user) { - if (comp) { - /* Already processed, only want one line of JSON */ + if (val == NULL) return; - } struct module_repo_internal *repo = (struct module_repo_internal *) user; char fav[LKT_LINE_MAX]; safe_strncpy(fav, val, LKT_LINE_MAX); /* TODO: Add a way to use the workers to do this for each fav list */ + LOG_INFO("REPO", "Processing favorite list: %s", fav); __handle_fav_list(repo, fav, LKT_LINE_MAX); } @@ -605,9 +602,8 @@ __worker_import_favorites(void *__repo) pthread_exit(NULL); } LOG_INFO("REPO", "Finished to dl favorite lists"); - size_t len = json_parse_get_count(json, 1); - json_parse(json, 1, __worker_import_favorites_internal, (void *) repo); - + size_t len = json_parse_get_count(json, 2); + json_parse(json, 2, __worker_import_favorites_internal, (void *) repo); free(json); LOG_INFO("REPO", "Finished to deal with %ld favorite lists", len);