return repo->appdata->baseurl;
}
+static char* pakfire_repo_url_replace(PakfireRepo repo, const char* url) {
+ if (!url)
+ return NULL;
+
+ const char* arch = pakfire_get_arch(repo->pakfire);
+ const char* name = pakfire_repo_get_name(repo);
+
+ const struct replacement {
+ const char* pattern;
+ const char* replacement;
+ } replacements[] = {
+ { "%{name}", name },
+ { "%{arch}", arch },
+ { NULL, NULL },
+ };
+
+ char* buffer = strdup(url);
+ if (!buffer)
+ return NULL;
+
+ for (const struct replacement* repl = replacements; repl->pattern; repl++) {
+ char* r = pakfire_string_replace(
+ buffer, repl->pattern, repl->replacement);
+ free(buffer);
+
+ // Break on any errors
+ if (!r)
+ return NULL;
+
+ // Free the old buffer and continue working with the new data
+ buffer = r;
+ }
+
+#ifdef ENABLE_DEBUG
+ if (strcmp(url, buffer) != 0) {
+ DEBUG(repo->pakfire, "Repository URL updated:");
+ DEBUG(repo->pakfire, " From: %s\n", url);
+ DEBUG(repo->pakfire, " To : %s\n", buffer);
+ }
+#endif
+
+ return buffer;
+}
+
PAKFIRE_EXPORT int pakfire_repo_set_baseurl(PakfireRepo repo, const char* baseurl) {
if (repo->appdata->baseurl)
free(repo->appdata->baseurl);
- if (baseurl)
- repo->appdata->baseurl = strdup(baseurl);
- else
- repo->appdata->baseurl = NULL;
+ // Store URL
+ repo->appdata->baseurl = pakfire_repo_url_replace(repo, baseurl);
+ if (!repo->appdata->baseurl)
+ return 1;
return 0;
}
if (repo->appdata->mirrorlist_url)
free(repo->appdata->mirrorlist_url);
- if (url)
- repo->appdata->mirrorlist_url = strdup(url);
- else
- repo->appdata->mirrorlist_url = NULL;
+ // Store URL
+ repo->appdata->mirrorlist_url = pakfire_repo_url_replace(repo, url);
+ if (!repo->appdata->mirrorlist_url)
+ return 1;
return 0;
}