Skip to content
Extraits de code Groupes Projets
Vérifiée Valider bc2f9fff rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MODULE: One more function should works and use the json parser [no-build]

parent d725c3bc
Branches
Aucune étiquette associée trouvée
1 requête de fusion!130Resolve "Remove json-c"
...@@ -80,6 +80,12 @@ struct module_repo_internal { ...@@ -80,6 +80,12 @@ struct module_repo_internal {
void (*craft_filename)(char str[PATH_MAX], size_t, struct kara *); void (*craft_filename)(char str[PATH_MAX], size_t, struct kara *);
}; };
struct __uri {
char *fav;
struct module_repo_internal *repo;
struct lkt_uri uri;
};
struct __memory { struct __memory {
void *mem; void *mem;
size_t size; size_t size;
...@@ -510,10 +516,27 @@ end_no_lock: ...@@ -510,10 +516,27 @@ end_no_lock:
pthread_exit(NULL); pthread_exit(NULL);
} }
static void
__handle_fav_list_internal(const char UNUSED *key, const char *val, int comp, void *user)
{
if (comp) {
/* Already processed because we only want one line */
return;
}
struct __uri *uri = (struct __uri *) user;
uri->uri.id = strtol(val, NULL, 0);
if (!database_plt_add_uri(uri->repo->db, uri->fav, &uri->uri)) {
LOG_ERROR("REPO", "Failed to add kara %ld to playlist %s", uri->uri.id, uri->fav);
return;
}
}
static inline void static inline void
__handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size) __handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size)
{ {
struct json_object *json, *item_json = NULL; char *json;
char fav_url[LKT_LINE_MAX]; char fav_url[LKT_LINE_MAX];
char *fav_origin = NULL; char *fav_origin = NULL;
...@@ -537,32 +560,19 @@ __handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size) ...@@ -537,32 +560,19 @@ __handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size)
} }
database_plt_touch(repo->db, fav); database_plt_touch(repo->db, fav);
struct lkt_uri uri = { struct __uri uri = {
.fav = fav,
.repo = repo,
.uri = {
.type = uri_id, .type = uri_id,
.is_int = true, .is_int = true,
},
}; };
size_t len = json_object_array_length(json), i; size_t len = json_parse_get_count(json, 1);
long id; json_parse(json, 1, __handle_fav_list_internal, (void *) &uri);
for (i = 0; i < len; ++i) {
item_json = json_object_array_get_idx(json, i);
if (item_json == NULL) {
LOG_ERROR("REPO", "There is no kara at index %ld in fav list %s", i, fav);
continue;
}
if (__safe_json_get_long(item_json, "id", &id)) {
LOG_ERROR("REPO", "Failed to get the id of the kara in fav list %s", fav_origin);
continue;
}
uri.id = id;
if (!database_plt_add_uri(repo->db, fav, &uri)) {
LOG_ERROR("REPO", "Failed to add kara %ld to playlist %s", id, fav);
continue;
}
}
LOG_INFO("REPO", "Finished importing fav list '%s' as '%s'", fav_origin, fav); LOG_INFO("REPO", "Finished importing fav list '%s' as '%s'", fav_origin, fav);
json_object_put(json); free(json);
} }
static void * static void *
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter