static GError * _resolve_meta1(struct hc_resolver_s *r, struct hc_url_s *u, gchar ***result) { struct hashstr_s *hk; GError *err = NULL; GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(u, HCURL_WHOLE)); hk = hashstr_printf("meta1|%s|%.4s", hc_url_get(u, HCURL_NSPHYS), hc_url_get(u, HCURL_HEXID)); /* Try to hit the cache */ if (!(*result = hc_resolver_get_cached(r, r->csm0.cache, hk))) { /* get a meta0, then store it in the cache */ gchar **m0urlv = NULL; err = _resolve_meta0(r, hc_url_get(u, HCURL_NSPHYS), &m0urlv); if (err != NULL) g_prefix_error(&err, "M0 resolution error: "); else { err = _resolve_m1_through_many_m0(m0urlv, hc_url_get_id(u), result); if (!err) hc_resolver_store(r, r->csm0.cache, hk, *result); g_strfreev(m0urlv); } } g_free(hk); return err; }
GError* hc_resolve_reference_directory(struct hc_resolver_s *r, struct hc_url_s *url, gchar ***result) { GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE)); EXTRA_ASSERT(r != NULL); EXTRA_ASSERT(url != NULL); EXTRA_ASSERT(result != NULL); if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS)) return NEWERROR(CODE_BAD_REQUEST, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE)); GError *err = NULL; gchar **m1v = NULL, **m0v = NULL; if (!(err = _resolve_meta0(r, hc_url_get(url, HCURL_NS), &m0v))) err = _resolve_meta1(r, url, &m1v); if (err) { if (m0v) g_strfreev (m0v); if (m1v) g_strfreev (m1v); return err; } *result = g_malloc0(sizeof(gchar*) * (g_strv_length(m0v) + g_strv_length(m1v) + 1)); gchar **d = *result; for (gchar **p=m0v; *p ;++p) { *(d++) = *p; } g_free (m0v); // pointers reused for (gchar **p=m1v; *p ;++p) { *(d++) = *p; } g_free (m1v); // pointers reused return NULL; }