Skip to content
Snippets Groups Projects
Commit 057054f6 authored by David Garcia Quintas's avatar David Garcia Quintas
Browse files

Added grpc_uri_get_query_arg per comments.

parent e3a49f82
No related branches found
No related tags found
No related merge requests found
......@@ -281,6 +281,18 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) {
return uri;
}
const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) {
GPR_ASSERT(key != NULL);
if (key[0] == '\0') return NULL;
for (size_t i = 0; i < uri->num_query_parts; ++i) {
if (0 == strcmp(key, uri->query_parts[i])) {
return uri->query_parts_values[i];
}
}
return NULL;
}
void grpc_uri_destroy(grpc_uri *uri) {
if (!uri) return;
gpr_free(uri->scheme);
......
......@@ -53,6 +53,10 @@ typedef struct {
/** parse a uri, return NULL on failure */
grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors);
/** return the part of a query string after the '=' in "?key=xxx&...", or NULL
* if key is not present */
const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key);
/** destroy a uri */
void grpc_uri_destroy(grpc_uri *uri);
......
......@@ -80,6 +80,11 @@ static void test_query_parts() {
GPR_ASSERT(0 == strcmp("", uri->query_parts[3]));
GPR_ASSERT(NULL == uri->query_parts_values[3]);
GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "a"));
GPR_ASSERT(0 == strcmp("B", grpc_uri_get_query_arg(uri, "b")));
GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "c")));
GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, ""));
GPR_ASSERT(0 == strcmp("frag", uri->fragment));
grpc_uri_destroy(uri);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment