int mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp) { size_t fvc, i; char **fvp; char **fvcopy; int rc = mu_url_sget_fvpairs (url, &fvc, &fvp); if (rc) return rc; fvcopy = calloc (fvc + 1, sizeof (fvcopy[0])); if (!fvcopy) return errno; for (i = 0; i < fvc; i++) { if (!(fvcopy[i] = strdup (fvp[i]))) { mu_argcv_free (i, fvcopy); return errno; } } fvcopy[i] = NULL; *pfvc = fvc; *pfvp = fvcopy; return 0; }
int mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv) { size_t qargc, i; char **qargv; char **qcopy; int rc = mu_url_sget_fvpairs (url, &qargc, &qargv); if (rc) return rc; qcopy = calloc (qargc + 1, sizeof (qcopy[0])); if (!qcopy) return errno; for (i = 0; i < qargc; i++) { if (!(qcopy[i] = strdup (qargv[i]))) { mu_argcv_free (i, qcopy); return errno; } } qcopy[i] = NULL; *qc = qargc; *qv = qcopy; return 0; }
int mu_url_sget_param (const mu_url_t url, const char *param, const char **val) { size_t fvc; char **fvp; int status = mu_url_sget_fvpairs (url, &fvc, &fvp); if (status) return status; if (fvc) { size_t i; for (i = 0; i < fvc; i++) { const char *p; char *q; for (p = param, q = fvp[i]; *p && *q && *p == *q; p++, q++) ; if (*p == 0) { if (*q == 0) { if (val) *val = q; return 0; } else if (*q == '=') { if (val) *val = q + 1; return 0; } } } } return MU_ERR_NOENT; }