Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
1721f75c
Vérifiée
Valider
1721f75c
rédigé
Il y a 5 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Use defined function to not reinvent the wheel
parent
d06a35a8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!76
Database update from FS
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/net/downloader.c
+10
-36
10 ajouts, 36 suppressions
src/net/downloader.c
avec
10 ajouts
et
36 suppressions
src/net/downloader.c
+
10
−
36
Voir le fichier @
1721f75c
...
@@ -66,8 +66,8 @@ repo_new(struct lkt_repo *const repo_, const char *name_, const char *url_, vola
...
@@ -66,8 +66,8 @@ repo_new(struct lkt_repo *const repo_, const char *name_, const char *url_, vola
.
base_url
=
url_
,
.
base_url
=
url_
,
.
get_id_json
=
GET_ID_JSON
,
.
get_id_json
=
GET_ID_JSON
,
.
get_id_file
=
GET_ID_FILE
,
.
get_id_file
=
GET_ID_FILE
,
.
get_all_json
=
DEFAULT_URL
"/api_karas.php"
,
// TODO
.
get_all_json
=
DEFAULT_URL
"/api_karas.php"
,
// TODO
FIXME
.
kara_dir
=
"/home/kara/"
,
// TODO
.
kara_dir
=
"/home/kara/"
,
// TODO
FIXME
.
version
=
1
,
.
version
=
1
,
/* The db */
/* The db */
...
@@ -137,11 +137,9 @@ int
...
@@ -137,11 +137,9 @@ int
__json_sync
(
struct
lkt_repo
*
const
repo
,
struct
json_object
**
json
)
__json_sync
(
struct
lkt_repo
*
const
repo
,
struct
json_object
**
json
)
{
{
RETURN_UNLESS
(
json
,
"Invalid argument"
,
1
);
RETURN_UNLESS
(
json
,
"Invalid argument"
,
1
);
CURL
*
curl_handle
;
CURL
*
curl_handle
;
CURLcode
res
;
CURLcode
res
;
int
ret
=
1
;
int
ret
=
1
;
struct
memory
file
=
{
struct
memory
file
=
{
.
mem
=
NULL
,
.
mem
=
NULL
,
.
size
=
0
.
.
size
=
0
.
...
@@ -170,14 +168,12 @@ err:
...
@@ -170,14 +168,12 @@ err:
int
int
repo_get_id
(
struct
lkt_repo
*
const
repo
,
const
uint64_t
id
,
struct
kara_metadata
*
mdt
)
repo_get_id
(
struct
lkt_repo
*
const
repo
,
const
uint64_t
id
,
struct
kara_metadata
*
mdt
)
{
{
RETURN_UNLESS
(
mdt
,
"Invalid argument"
,
1
);
CURL
*
curl_handle
;
CURL
*
curl_handle
;
CURLcode
res
;
CURLcode
res
;
struct
json_object
*
jobj
,
*
field
;
struct
json_object
*
jobj
,
*
field
;
int
ret
=
1
,
err
=
0
;
int
ret
=
1
,
err
=
0
;
char
url
[
URL_MAX_LEN
];
char
url
[
URL_MAX_LEN
];
RETURN_UNLESS
(
mdt
,
"Invalid argument"
,
1
);
struct
memory
file
=
{
struct
memory
file
=
{
.
mem
=
NULL
,
.
mem
=
NULL
,
.
size
=
0
,
.
size
=
0
,
...
@@ -203,41 +199,19 @@ repo_get_id(struct lkt_repo *const repo, const uint64_t id, struct kara_metadata
...
@@ -203,41 +199,19 @@ repo_get_id(struct lkt_repo *const repo, const uint64_t id, struct kara_metadata
/* Read the json. */
/* Read the json. */
jobj
=
json_tokener_parse
(
file
.
mem
);
jobj
=
json_tokener_parse
(
file
.
mem
);
if
(
json_object_object_get_ex
(
jobj
,
"message"
,
&
field
))
{
if
(
json_object_object_get_ex
(
jobj
,
"message"
,
&
field
))
{
LOG_ERROR
(
"Kara with id %lu not found, message is: %s"
,
id
,
json_object_get_string
(
field
));
LOG_ERROR
(
"Kara with id %lu not found, message is: %s"
,
id
,
json_object_get_string
(
field
));
goto
err
;
goto
err
;
}
}
LOG_INFO
(
"Got kara with id %lu"
,
id
);
LOG_INFO
(
"Got kara with id %lu"
,
id
);
err
|=
safe_json_get_string
(
jobj
,
"song_name"
,
mdt
->
song_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"song_name"
,
mdt
->
song_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"source_name"
,
mdt
->
source_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"source_name"
,
mdt
->
source_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"category"
,
mdt
->
category
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"category"
,
mdt
->
category
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"language"
,
mdt
->
language
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"language"
,
mdt
->
language
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"author_name"
,
mdt
->
author_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"author_name"
,
mdt
->
author_name
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"song_type"
,
mdt
->
song_type
,
LEKTOR_TAG_MAX
);
err
|=
safe_json_get_string
(
jobj
,
"song_type"
,
mdt
->
song_type
,
LEKTOR_TAG_MAX
);
GOTO_IF
(
err
||
safe_json_get_int32
(
jobj
,
"song_number"
,
&
mdt
->
song_number
),
"Invalid json"
,
err
);
errno
=
0
;
if
(
!
json_object_object_get_ex
(
jobj
,
"song_number"
,
&
field
))
{
LOG_ERROR
(
"%s"
,
"No object with key 'song_number' in json, error"
);
goto
err
;
}
mdt
->
song_number
=
json_object_get_int
(
field
);
if
(
errno
==
EINVAL
)
{
LOG_ERROR
(
"%s"
,
"Invalid integer for field with key 'song_number'"
);
goto
err
;
}
if
(
mdt
->
song_number
==
INT32_MAX
||
mdt
->
song_number
==
INT32_MIN
)
{
LOG_ERROR
(
"Out of bound int32_t '%d' for field with key 'song_number'"
,
mdt
->
song_number
);
goto
err
;
}
ret
=
0
;
ret
=
0
;
err:
err:
json_object_put
(
jobj
);
/* Delete object. */
json_object_put
(
jobj
);
/* Delete object. */
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter