Added grpc_uri_get_query_arg per comments.

pull/6034/head
David Garcia Quintas 9 years ago
parent e3a49f82c4
commit 057054f665
  1. 12
      src/core/lib/client_config/uri_parser.c
  2. 4
      src/core/lib/client_config/uri_parser.h
  3. 5
      test/core/client_config/uri_parser_test.c

@ -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);
}

Loading…
Cancel
Save