static void _container_single_prop_to_headers (struct req_args_s *args, const char *pk, gchar *v) { if (!g_ascii_strcasecmp(pk, "sys.container_name")) { oio_str_reuse (&v, g_uri_escape_string (v, NULL, FALSE)); args->rp->add_header(PROXYD_HEADER_PREFIX "container-meta-name", v); } else if (!g_ascii_strcasecmp(pk, "sys.container_size")) { args->rp->add_header(PROXYD_HEADER_PREFIX "container-meta-size", v); } else if (!g_ascii_strcasecmp(pk, "sys.m2vers")) { args->rp->add_header(PROXYD_HEADER_PREFIX "container-meta-seq", v); } else if (!g_ascii_strcasecmp(pk, "sys.namespace")) { args->rp->add_header(PROXYD_HEADER_PREFIX "container-meta-ns", v); } else if (g_str_has_prefix(pk, "sys.")) { gchar *k = g_strdup_printf(PROXYD_HEADER_PREFIX "container-meta-sys-%s", pk + sizeof("sys.") - 1); _purify_header(k); oio_str_reuse (&v, g_uri_escape_string (v, NULL, FALSE)); args->rp->add_header(k, v); g_free(k); } else if (g_str_has_prefix(pk, "user.")) { gchar *k = g_strdup_printf(PROXYD_HEADER_PREFIX "container-meta-user-%s", pk + sizeof("user.") - 1); _purify_header(k); oio_str_reuse (&v, g_uri_escape_string (v, NULL, FALSE)); args->rp->add_header(k, v); g_free(k); } else { gchar *k = g_strdup_printf(PROXYD_HEADER_PREFIX "container-meta-x-%s", pk); _purify_header(k); oio_str_reuse (&v, g_uri_escape_string (v, NULL, FALSE)); args->rp->add_header(k, v); g_free(k); } }
void oio_str_replace(gchar **dst, const gchar *src) { if (src) oio_str_reuse(dst, g_strdup(src)); else oio_str_reuse(dst, NULL); }
void access_tail (const char *fmt, ...) { va_list args; va_start(args, fmt); gchar *s = g_strdup_vprintf (fmt, args); va_end(args); oio_str_reuse (&access, s); }
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_reuse(void) { gchar *s0 = g_strdup(""); gchar *s1 = g_strdup(""); oio_str_reuse(&s0, s1); g_assert(s0 == s1); g_free(s1); }
static void test_reuse (void) { gchar *s0 = g_strdup ("A"), *s1 = g_strdup ("B"); oio_str_reuse (&s0, s1); g_assert (s0 == s1); oio_str_clean (&s1); g_assert (s1 == NULL); }
static GError* _list (const char *target, GByteArray *request, struct list_result_s *out, gchar ***out_properties) { GError *err = NULL; GTree *props = NULL; gboolean _cb(gpointer ctx, MESSAGE reply) { (void) ctx; /* Extract replied aliases */ GSList *l = NULL; GError *e = metautils_message_extract_body_encoded(reply, FALSE, &l, bean_sequence_decoder); if (e) { GRID_DEBUG("Callback error : %s", e->message); err = e; return FALSE; } out->beans = metautils_gslist_precat (out->beans, l); /* Extract list flags */ e = metautils_message_extract_boolean (reply, NAME_MSGKEY_TRUNCATED, FALSE, &out->truncated); if (e) g_clear_error (&e); gchar *tok = NULL; tok = metautils_message_extract_string_copy (reply, NAME_MSGKEY_NEXTMARKER); oio_str_reuse (&out->next_marker, tok); /* Extract properties and merge them into the temporary TreeSet. */ if (out_properties) { gchar **names = metautils_message_get_field_names (reply); for (gchar **n=names ; n && *n ;++n) { if (!g_str_has_prefix (*n, NAME_MSGKEY_PREFIX_PROPERTY)) continue; g_tree_replace (props, g_strdup((*n) + sizeof(NAME_MSGKEY_PREFIX_PROPERTY) - 1), metautils_message_extract_string_copy(reply, *n)); } if (names) g_strfreev (names); } return TRUE; }
static gchar* get_fullpath(struct zk_manager_s *manager, gchar *subdir, gchar* name) { gchar * result; if (subdir) result = g_strdup_printf("%s/%s",manager->zk_dir,subdir); else result = g_strdup(manager->zk_dir); if ( name ) { struct sqlx_name_s n = {"", "", ""}; n.base = name; struct hashstr_s *key = sqliterepo_hash_name(&n); oio_str_reuse (&result, g_strdup_printf("%s/%s", result, hashstr_str(key))); g_free(key); } return result; }
gboolean oio_requri_parse (const char *str, struct oio_requri_s *uri) { if (!str || !uri) return FALSE; gchar *pq = strchr (str, '?'); gchar *pa = pq ? strchr (pq, '#') : strchr (str, '#'); // Extract the main components if (pq || pa) uri->path = g_strndup (str, (pq ? pq : pa) - str); else uri->path = g_strdup (str); if (pq) { if (pa) uri->query = g_strndup (pq + 1, pa - pq); else uri->query = g_strdup (pq + 1); } else uri->query = g_strdup(""); if (pa) uri->fragment = g_strdup (pa + 1); else uri->fragment = g_strdup(""); // Split and unescape the query components if (uri->query) uri->query_tokens = g_strsplit(uri->query, "&", -1); else uri->query_tokens = g_malloc0(sizeof(void*)); for (gchar **p=uri->query_tokens; p && *p ;++p) oio_str_reuse (p, g_uri_unescape_string (*p, NULL)); return TRUE; }
static int _parse_url(struct oio_url_s *url, const char *str) { inline void _replace (gchar **pp, const char *s) { oio_str_reuse (pp, g_uri_unescape_string (s, NULL)); }