void sqlx_name_dup (struct sqlx_name_mutable_s *dst, const struct sqlx_name_s *src) { EXTRA_ASSERT(dst != NULL && src != NULL); oio_str_replace (&dst->ns, src->ns); oio_str_replace (&dst->base, src->base); oio_str_replace (&dst->type, src->type); }
static int _parse_oldurl(struct oio_url_s *url, const char *str) { struct oio_requri_s ruri = {NULL, NULL, NULL, NULL}; // Purify the url size_t len = strlen (str); char *tmp = g_alloca (len+1); do { char *p = tmp; for (; *str && *str == '/' ;++str) {} // skip the leading slashes if (*str) { // Copy the NS for (; *str && *str != '/' ;++str) *(p++) = *str; } if (*str) *(p++) = '/'; // Copy a single separator for (; *str && *str == '/' ;++str) {} // skip separators if (*str) strcpy(p, str); // Copy what remains } while (0); if (oio_requri_parse (tmp, &ruri)) { // Parse the path gchar **path_tokens = g_strsplit (ruri.path, "/", 3); if (path_tokens) { if (path_tokens[0]) { oio_str_reuse (&url->ns, path_tokens[0]); oio_str_replace (&url->account, HCURL_DEFAULT_ACCOUNT); if (path_tokens[1]) { oio_str_reuse (&url->user, path_tokens[1]); oio_str_replace (&url->type, HCURL_DEFAULT_TYPE); if (path_tokens[2]) oio_str_reuse (&url->path, path_tokens[2]); } } g_free (path_tokens); } if (ruri.query_tokens) { // Parse the options for (gchar **p=ruri.query_tokens; *p ;++p) _add_option(url, *p); } } oio_requri_clear (&ruri); return _check_parsed_url (url); }
static void test_replace (void) { gchar *s0 = g_strdup ("A"); oio_str_replace (&s0, "B"); g_assert (!strcmp(s0, "B")); oio_str_clean (&s0); g_assert (s0 == NULL); }
static void test_replace(void) { gchar *s0 = g_strdup(""); gchar *s1 = g_strdup(""); oio_str_replace(&s0, s1); g_assert(0 == g_strcmp0(s0, s1)); g_free(s0); g_free(s1); }
static GError * http_manage_request(struct req_ctx_s *r) { gboolean finalized = 0; int code = HTTP_CODE_INTERNAL_ERROR; gchar *msg = NULL, *access = NULL; GTree *headers = NULL; const gchar *content_type = "octet/stream"; GBytes *body = NULL; void subject (const char *id) { oio_str_replace (&r->uid, id); }
static GError * __get_container_service2(struct sqlx_sqlite3_s *sq3, struct oio_url_s *url, struct compound_type_s *ct, struct meta1_backend_s *m1, enum m1v2_getsrv_e mode, gchar ***result, gboolean *renewed) { GError *err = NULL; struct meta1_service_url_s **used = NULL; enum service_update_policy_e policy; guint replicas; struct service_update_policies_s *pol; if (!(pol = meta1_backend_get_svcupdate(m1))) return NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "Bad NS/Policy pair"); policy = service_howto_update(pol, ct->baretype); replicas = service_howmany_replicas(pol, ct->baretype); replicas = (replicas > 0 ? replicas : 1); // Patches the constraint on the service type (if not set in the request) // by the constraint set in the NS-wide storage policy. compound_type_update_arg(ct, pol, FALSE); /* This special "tag" is used for services types that are to be linked * to containers belonging to other services (e.g. there is a container * for each rawx in the special "_RDIR" account). It tells the load * balancer to compare the location of linked service against the * location of the container owner. */ if (ct->req.k && !strcmp(ct->req.k, NAME_TAGNAME_USER_IS_SERVICE) && (!ct->req.v || !ct->req.v[0])) { oio_str_replace(&(ct->req.v), oio_url_get(url, OIOURL_USER)); } err = __get_container_all_services(sq3, url, ct->type, &used); if (NULL != err) { g_prefix_error(&err, "Preliminary lookup error : "); return err; } if (used && !*used) { g_free(used); used = NULL; } if (used && (mode != M1V2_GETSRV_RENEW)) { /* Only keep the services UP, if not forced to renew */ struct meta1_service_url_s **up = __get_services_up(m1, used); if (up && *up) { *result = pack_urlv(up); meta1_service_url_cleanv(up); meta1_service_url_cleanv(used); return NULL; } meta1_service_url_cleanv(up); } if (used && (mode == M1V2_GETSRV_REUSE || policy == SVCUPD_KEEP)) { /* Services used but unavailable, but we are told to reuse */ *result = pack_urlv(used); meta1_service_url_cleanv(used); return err; } /* No service available, poll a new one */ struct meta1_service_url_s *m1_url = NULL; gint seq = urlv_get_max_seq(used); seq = (seq<0 ? 1 : seq+1); if (NULL != (m1_url = __poll_services(m1, replicas, ct, seq, used, &err))) { if (mode != M1V2_GETSRV_DRYRUN) { if (NULL == err) { if (policy == SVCUPD_REPLACE) err = __delete_service(sq3, url, ct->type); if (NULL == err) err = __save_service(sq3, url, m1_url, TRUE); } } if (!err && result) { struct meta1_service_url_s **unpacked = expand_url(m1_url); *result = pack_urlv(unpacked); meta1_service_url_cleanv(unpacked); if (renewed) *renewed = TRUE; } g_free(m1_url); } meta1_service_url_cleanv(used); return err; }
void oio_ext_set_reqid (const char *reqid) { struct oio_ext_local_s *l = _local_ensure (); oio_str_replace (&l->reqid, reqid); }
void set_status(int c, const gchar *m) { EXTRA_ASSERT(m != NULL); code = c; oio_str_replace (&msg, m); }
GError * oio_proxy_call_content_link (CURL *h, struct oio_url_s *u, const char *id) { struct http_ctx_s i = { .headers = NULL, .body = _gs_vprintf("{\"id\":\"%s\"}", id) }; GString *http_url = _curl_content_url (u, "link"); GError *err = _proxy_call (h, "POST", http_url->str, &i, NULL); g_string_free (http_url, TRUE); g_string_free (i.body, TRUE); return err; } GError * oio_proxy_call_content_prepare (CURL *h, struct oio_url_s *u, gsize size, gboolean autocreate, struct oio_proxy_content_prepare_out_s *out) { gchar *hdrin[] = { PROXYD_HEADER_MODE, autocreate ? "autocreate" : NULL, NULL }; struct http_ctx_s i = { .headers = hdrin, .body = _gs_vprintf ("{\"size\":%"G_GSIZE_FORMAT",\"autocreate\":%s}", size, autocreate ? "true" : "false") }; struct http_ctx_s o = { .headers = g_malloc0(sizeof(void*)), .body = out ? out->body : NULL }; GString *http_url = _curl_content_url (u, "prepare"); GError *err = _proxy_call (h, "POST", http_url->str, &i, &o); if (!err && out && o.headers) { for (gchar **p=o.headers; *p && *(p+1) ;p+=2) { if (!g_ascii_strcasecmp(*p, "ns-chunk-size")) oio_str_replace (&out->header_chunk_size, *(p+1)); else if (!g_ascii_strcasecmp(*p, "content-meta-version")) oio_str_replace (&out->header_version, *(p+1)); else if (!g_ascii_strcasecmp(*p, "content-meta-id")) oio_str_replace (&out->header_content, *(p+1)); else if (!g_ascii_strcasecmp(*p, "content-meta-policy")) oio_str_replace (&out->header_stgpol, *(p+1)); else if (!g_ascii_strcasecmp(*p, "content-meta-mime-type")) oio_str_replace (&out->header_mime_type, *(p+1)); else if (!g_ascii_strcasecmp(*p, "content-meta-chunk-method")) oio_str_replace (&out->header_chunk_method, *(p+1)); } } g_string_free (http_url, TRUE); g_string_free(i.body, TRUE); if (o.headers) g_strfreev (o.headers); return err; } GError * oio_proxy_call_content_create (CURL *h, struct oio_url_s *u, struct oio_proxy_content_create_in_s *in, GString *out) { GString *http_url = _curl_content_url (u, "create"); if (in->content) { g_string_append (http_url, "&id="); g_string_append_uri_escaped (http_url, in->content, NULL, TRUE); } gchar *hdrin[] = { g_strdup(PROXYD_HEADER_PREFIX "content-meta-id"), g_strdup_printf("%s", in->content), g_strdup(PROXYD_HEADER_PREFIX "content-meta-version"), g_strdup_printf("%"G_GINT64_FORMAT, in->version), g_strdup(PROXYD_HEADER_PREFIX "content-meta-length"), g_strdup_printf("%"G_GSIZE_FORMAT, in->size), g_strdup(PROXYD_HEADER_PREFIX "content-meta-hash"), g_strdup_printf("%s", in->hash), g_strdup(PROXYD_HEADER_PREFIX "content-meta-policy"), g_strdup_printf("%s", "NONE"), NULL }; struct http_ctx_s i = { .headers = hdrin, .body = in ? in->chunks : NULL }; struct http_ctx_s o = { .headers = NULL, .body = out }; GError *err = _proxy_call (h, "POST", http_url->str, &i, &o); _ptrv_free_content (i.headers); g_string_free (http_url, TRUE); return err; } GError * oio_proxy_call_content_list (CURL *h, struct oio_url_s *u, GString *out, const char *prefix, const char *marker, const char *end, guint max, char delim) { GString *http_url = _curl_container_url (u, "list"); if (prefix) _append (http_url, '&', "prefix", prefix); if (marker) _append (http_url, '&', "marker", marker); if (end) _append (http_url, '&', "end", end); if (max) g_string_append_printf (http_url, "&max=%u", max); if (delim) g_string_append_printf (http_url, "&delimiter=%c", delim); struct http_ctx_s o = { .headers = NULL, .body = out }; GError *err = _proxy_call (h, "GET", http_url->str, NULL, &o); g_strfreev (o.headers); g_string_free(http_url, TRUE); return err; } GError * oio_proxy_call_reference_show (CURL *h, struct oio_url_s *u, const char *t, GString *out) { GString *http_url = _curl_reference_url (u, "show"); if (t) _append(http_url, '&', "type", t); struct http_ctx_s o = { .headers = NULL, .body = out }; GError *err = _proxy_call (h, "GET", http_url->str, NULL, &o); g_strfreev (o.headers); g_string_free(http_url, TRUE); return err; }