int main(int argc, char ** args) { int i; for (i=1; i<argc ;i++) { struct hc_url_s *url = hc_url_init(args[i]); if (url && NULL != hc_url_get_id(url)) { memset(str_id, 0, sizeof(str_id)); buffer2str(hc_url_get_id(url), hc_url_get_id_size(url), str_id, sizeof(str_id)); fputs(str_id, stdout); } else { fputs(bad, stdout); } fputc(' ', stdout); fputs(args[i], stdout); fputc('\n', stdout); if (url) hc_url_clean(url); } fflush(stdout); return 0; }
static GByteArray * _url_2_gba(struct hc_url_s *url) { GByteArray *gba = g_byte_array_new(); if (hc_url_get_id(url)) g_byte_array_append(gba, hc_url_get_id(url), hc_url_get_id_size(url)); return gba; }
static GError* __count_FK (struct sqlx_sqlite3_s *sq3, struct hc_url_s *url, const char *table, guint *count) { gint rc; sqlite3_stmt *stmt = NULL; gchar sql[sizeof(FMT_COUNT)+32]; g_snprintf (sql, sizeof(sql), FMT_COUNT, table); sqlite3_prepare_debug(rc, sq3->db, sql, -1, &stmt, NULL); if (rc != SQLITE_OK) return M1_SQLITE_GERROR(sq3->db, rc); (void) sqlite3_bind_blob(stmt, 1, hc_url_get_id (url), hc_url_get_id_size (url), NULL); guint _count = 0; while (SQLITE_ROW == (rc = sqlite3_step(stmt))) _count += sqlite3_column_int(stmt, 0); GError *err = NULL; if (rc != SQLITE_OK && rc != SQLITE_DONE) err = M1_SQLITE_GERROR(sq3->db, rc); sqlite3_finalize_debug(rc, stmt); if (err) return err; *count = _count; return NULL; }
GError* hc_resolve_reference_service(struct hc_resolver_s *r, struct hc_url_s *url, const gchar *srvtype, gchar ***result) { GError *err; struct hashstr_s *hk; GRID_TRACE2("%s(%s,%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE), srvtype); g_assert(r != NULL); g_assert(url != NULL); g_assert(srvtype != NULL); g_assert(result != NULL); g_assert(*result == NULL); if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS)) return NEWERROR(400, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE)); hk = hashstr_printf("%s|%s|%s", srvtype, hc_url_get(url, HCURL_NSPHYS), hc_url_get(url, HCURL_HEXID)); err = _resolve_reference_service(r, hk, url, srvtype, result); g_free(hk); return err; }
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; }
GError* __destroy_container(struct sqlx_sqlite3_s *sq3, struct hc_url_s *url, gboolean force, gboolean *done) { GError *err = NULL; gint count_actions = 0; struct sqlx_repctx_s *repctx = NULL; EXTRA_ASSERT(sq3 != NULL); EXTRA_ASSERT(sq3->db != NULL); err = sqlx_transaction_begin(sq3, &repctx); if (NULL != err) return err; if (force) { __exec_cid (sq3->db, "DELETE FROM services WHERE cid = ?", hc_url_get_id (url)); count_actions += sqlite3_changes(sq3->db); __exec_cid (sq3->db, "DELETE FROM properties WHERE cid = ?", hc_url_get_id (url)); count_actions += sqlite3_changes(sq3->db); } else { guint count_services = 0, count_properties = 0; /* No forced op, we count the services belonging to the container. */ err = __count_FK(sq3, url, "services", &count_services); if (!err) err = __count_FK(sq3, url, "properties", &count_properties); /* If any service is found, this is an error. */ if (!err && count_services > 0) err = NEWERROR(CODE_USER_INUSE, "User still linked to services"); if (!err && count_properties > 0) err = NEWERROR(CODE_USER_INUSE, "User still has properties"); } if (!err) { __exec_cid(sq3->db, "DELETE FROM users WHERE cid = ?", hc_url_get_id (url)); count_actions += sqlite3_changes(sq3->db); } *done = !err && (count_actions > 0); if (!err && !*done) err = NEWERROR(CODE_USER_NOTFOUND, "User not found"); return sqlx_transaction_end(repctx, err); }
static status_t _get_container_user_properties(gs_grid_storage_t *hc, struct hc_url_s *url, char ***props, gs_error_t **gserr) { GError *gerr = NULL; gboolean rc; addr_info_t *m1 = NULL; GSList *excluded = NULL; gs_container_t *c = gs_get_container(hc, hc_url_get(url, HCURL_USER), 0, gserr); if(!c) return 0; for (;;) { m1 = gs_resolve_meta1v2(hc, hc_url_get_id(url), c->info.name, 1, &excluded, &gerr); if (!m1) { *gserr = gs_error_new(CODE_INTERNAL_ERROR, "No META1 found for [%s]", hc_url_get(url, HCURL_USER)); break; } rc = meta1v2_remote_reference_get_property (m1, &gerr, url, NULL, props); if (!rc) { excluded = g_slist_prepend(excluded, m1); m1=NULL; if (gerr) { if (CODE_IS_NETWORK_ERROR(gerr->code)) { g_error_free(gerr); gerr = NULL; } else { GSERRORCAUSE(gserr, gerr, "Cannot get container user properties"); break; } } } else { break; } } if (excluded) { g_slist_foreach(excluded, addr_info_gclean, NULL); g_slist_free(excluded); } if (m1) g_free(m1); gs_container_free(c); if (gerr) g_error_free(gerr); return rc; }
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)); g_assert(r != NULL); g_assert(url != NULL); g_assert(result != NULL); if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS)) return NEWERROR(400, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE)); return _resolve_meta1(r, url, result); }
static GError * _resolve_service_through_one_m1(const gchar *m1, struct hc_url_s *u, const gchar *s, gchar ***result) { GError *err = NULL; struct addr_info_s ai; GRID_TRACE2("%s(%s,%s,%s)", __FUNCTION__, m1, hc_url_get(u, HCURL_WHOLE), s); meta1_strurl_get_address(m1, &ai); *result = meta1v2_remote_list_reference_services(&ai, &err, hc_url_get(u, HCURL_NS), hc_url_get_id(u), s, _timeout(&rc_resolver_timeout_m1, 30.0), _timeout(&rc_resolver_timeout_m1, 30.0)); g_assert((err!=NULL) ^ (*result!=NULL)); return err; }
static void wrapper(void (*cb)(void)) { gboolean rc = FALSE; GError *err = NULL; g_printerr("\n"); hc_url_set(url, HCURL_REFERENCE, next_name("container")); hc_url_set(url, HCURL_PATH, next_name("content")); g_debug("ROUND with [%s] %s", hc_url_get(url, HCURL_HEXID), hc_url_get(url, HCURL_WHOLE)); rc = meta2_remote_container_create(&addr, timeout, &err, hc_url_get_id(url), hc_url_get(url, HCURL_REFERENCE)); CHECK_RC_ERR(rc, err, "CREATE"); if (cb) cb(); }
static meta2_raw_content_v2_t* generate_v2(void) { meta2_raw_content_v2_t *v2 = g_malloc0(sizeof(*v2)); memcpy(v2->header.container_id, hc_url_get_id(url), sizeof(container_id_t)); g_strlcpy(v2->header.path, hc_url_get(url, HCURL_PATH), sizeof(v2->header.path)); v2->header.nb_chunks = 1; v2->header.size = 0; v2->header.metadata = g_byte_array_new(); v2->header.system_metadata = g_byte_array_new(); meta2_raw_chunk_t *rc = g_malloc0(sizeof(*rc)); l4_address_init_with_url(&(rc->id.addr), "127.0.0.1:6000", NULL); g_strlcpy(rc->id.vol, "/rawx-1", sizeof(rc->id.vol)); rc->metadata = g_byte_array_new(); v2->raw_chunks = g_slist_prepend(v2->raw_chunks, rc); return v2; }
static void test_list_empty(void) { void round(void) { GError *err = NULL; GSList *l; l = meta2_remote_container_list(&addr, timeout, &err, hc_url_get_id(url)); if (!l) { if (err) { g_error("LIST error : %d %s", err->code, err->message); g_assert_not_reached(); } } g_debug("LIST : %u elements", g_slist_length(l)); if (l) { g_slist_foreach(l, chunk_info_gclean, NULL); g_slist_free(l); } }