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

MODULE: First step in downloading fav list...

parent 61e859a8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!130Resolve "Remove json-c"
......@@ -31,15 +31,14 @@
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, "\\\"", "\""); \
} \
}
......@@ -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;
}
......@@ -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);
......
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