|
37 | 37 | #include <openssl/ssl.h>
|
38 | 38 | #include <openssl/pem.h>
|
39 | 39 |
|
| 40 | +#include "xbps/fmt.h" |
40 | 41 | #include "xbps_api_impl.h"
|
41 | 42 |
|
42 | 43 | /**
|
@@ -193,6 +194,65 @@ repo_open_remote(struct xbps_repo *repo)
|
193 | 194 | return rv;
|
194 | 195 | }
|
195 | 196 |
|
| 197 | +static int |
| 198 | +repo_fmt(FILE *fp, const struct xbps_fmt_var *var, void *data) |
| 199 | +{ |
| 200 | + struct xbps_handle *xhp = data; |
| 201 | + const char *arch; |
| 202 | + |
| 203 | + if (xhp->target_arch) |
| 204 | + arch = xhp->target_arch; |
| 205 | + else |
| 206 | + arch = xhp->native_arch; |
| 207 | + |
| 208 | + if (strcmp(var->name, "arch") == 0) { |
| 209 | + return xbps_fmt_print_string(var, arch, 0, fp); |
| 210 | + } |
| 211 | + return 0; |
| 212 | +} |
| 213 | + |
| 214 | +char * |
| 215 | +xbps_repo_format(struct xbps_handle *xhp, const char *url) |
| 216 | +{ |
| 217 | + struct xbps_fmt *fmt = NULL; |
| 218 | + FILE *fmt_stream; |
| 219 | + char *fmt_buf; |
| 220 | + size_t len; |
| 221 | + int r; |
| 222 | + |
| 223 | + assert(xhp); |
| 224 | + assert(url); |
| 225 | + |
| 226 | + if (!strstr(url, "{arch}")) |
| 227 | + return strdup(url); |
| 228 | + |
| 229 | + xbps_dbg_printf("Processing templated repository: %s\n", url); |
| 230 | + |
| 231 | + fmt_stream = open_memstream(&fmt_buf, &len); |
| 232 | + if (!fmt_stream) { |
| 233 | + xbps_error_printf("failed to open buffer: %s\n", strerror(errno)); |
| 234 | + goto fmtout; |
| 235 | + } |
| 236 | + fmt = xbps_fmt_parse(url); |
| 237 | + if (!fmt) { |
| 238 | + xbps_error_printf("failed to parse format for repo '%s': %s\n", url, strerror(errno)); |
| 239 | + goto fmtout; |
| 240 | + } |
| 241 | + r = xbps_fmt(fmt, repo_fmt, xhp, fmt_stream); |
| 242 | + if (r < 0) { |
| 243 | + xbps_error_printf("failed to format repo '%s': %s\n", url, strerror(-r)); |
| 244 | + goto fmtout; |
| 245 | + } |
| 246 | + fflush(fmt_stream); |
| 247 | + return fmt_buf; |
| 248 | + |
| 249 | +fmtout: |
| 250 | + fclose(fmt_stream); |
| 251 | + xbps_fmt_free(fmt); |
| 252 | + free(fmt_buf); |
| 253 | + return NULL; |
| 254 | +} |
| 255 | + |
196 | 256 | static struct xbps_repo *
|
197 | 257 | repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
198 | 258 | {
|
|
0 commit comments