Skip to content

Commit 3a44c44

Browse files
committed
Merge pull request #7 from BenoitZugmeyer/aur-v4-support
Set a default urlpath if it is not returned by the API (fixes #6)
2 parents 4692c67 + 6ae8879 commit 3a44c44

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/aur.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,39 @@ static size_t curl_getdata_cb (void *data, size_t size, size_t nmemb, void *user
283283
static int json_start_map (void *ctx)
284284
{
285285
jsonpkg_t *pkg_json = (jsonpkg_t *) ctx;
286-
if (++(pkg_json->level)>1)
286+
287+
if (pkg_json == NULL)
288+
return 1;
289+
290+
pkg_json->level += 1;
291+
if (pkg_json->level > 1)
287292
pkg_json->pkg = aur_pkg_new();
293+
288294
return 1;
289295
}
290296

291297
static int json_end_map (void *ctx)
292298
{
293299
jsonpkg_t *pkg_json = (jsonpkg_t *) ctx;
294-
if (--(pkg_json->level)==1)
300+
301+
if (pkg_json == NULL)
302+
return 1;
303+
304+
pkg_json->level -= 1;
305+
if (pkg_json->level == 1 && pkg_json->pkg != NULL)
295306
{
307+
// If the urlpath isn't given by the API, build it based on the name. This fixes
308+
// a compatibility issue between AUR v3 and v4 APIs.
309+
if (aur_pkg_get_urlpath(pkg_json->pkg) == NULL)
310+
{
311+
const char *name = aur_pkg_get_name(pkg_json->pkg);
312+
if (name != NULL) {
313+
size_t size = strnlen(name, 200) + 34;
314+
pkg_json->pkg->urlpath = malloc(sizeof(char) * size);
315+
snprintf(pkg_json->pkg->urlpath, size, "/cgit/%s.git/snapshot/master.tar.gz", name);
316+
}
317+
}
318+
296319
switch (config.sort)
297320
{
298321
case S_VOTE:

0 commit comments

Comments
 (0)