Esempio n. 1
0
static void destroy_channel(grpc_exec_ctx *exec_ctx, grpc_channel *channel) {
  size_t i;
  grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CHANNEL(channel));
  for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) {
    GRPC_MDELEM_UNREF(channel->grpc_status_elem[i]);
  }
  GRPC_MDSTR_UNREF(channel->grpc_status_string);
  GRPC_MDSTR_UNREF(channel->grpc_compression_algorithm_string);
  GRPC_MDSTR_UNREF(channel->grpc_encodings_accepted_by_peer_string);
  GRPC_MDSTR_UNREF(channel->grpc_message_string);
  GRPC_MDSTR_UNREF(channel->path_string);
  GRPC_MDSTR_UNREF(channel->authority_string);
  while (channel->registered_calls) {
    registered_call *rc = channel->registered_calls;
    channel->registered_calls = rc->next;
    GRPC_MDELEM_UNREF(rc->path);
    if (rc->authority) {
      GRPC_MDELEM_UNREF(rc->authority);
    }
    gpr_free(rc);
  }
  if (channel->default_authority != NULL) {
    GRPC_MDELEM_UNREF(channel->default_authority);
  }
  grpc_mdctx_unref(channel->metadata_context);
  gpr_mu_destroy(&channel->registered_call_mu);
  gpr_free(channel->target);
  gpr_free(channel);
}
Esempio n. 2
0
static void iam_destroy(grpc_credentials *creds) {
  grpc_iam_credentials *c = (grpc_iam_credentials *)creds;
  grpc_mdelem_unref(c->token_md);
  grpc_mdelem_unref(c->authority_selector_md);
  grpc_mdctx_unref(c->md_ctx);
  gpr_free(c);
}
Esempio n. 3
0
static void test_many_additions(void) {
  grpc_chttp2_hptbl tbl;
  int i;
  char *key;
  char *value;
  grpc_mdctx *mdctx;

  LOG_TEST("test_many_additions");

  mdctx = grpc_mdctx_create();
  grpc_chttp2_hptbl_init(&tbl, mdctx);

  for (i = 0; i < 1000000; i++) {
    gpr_asprintf(&key, "K:%d", i);
    gpr_asprintf(&value, "VALUE:%d", i);
    grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value));
    assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
    gpr_free(key);
    gpr_free(value);
    if (i) {
      gpr_asprintf(&key, "K:%d", i - 1);
      gpr_asprintf(&value, "VALUE:%d", i - 1);
      assert_index(&tbl, 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
      gpr_free(key);
      gpr_free(value);
    }
  }

  grpc_chttp2_hptbl_destroy(&tbl);
  grpc_mdctx_unref(mdctx);
}
Esempio n. 4
0
static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) {
  connector *c = (connector *)con;
  if (gpr_unref(&c->refs)) {
    grpc_mdctx_unref(c->mdctx);
    gpr_free(c);
  }
}
Esempio n. 5
0
static void test_create_many_persistant_metadata(void) {
  grpc_mdctx *ctx;
  char buffer[GPR_LTOA_MIN_BUFSIZE];
  long i;
  grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY);
  grpc_mdelem *md;

  LOG_TEST("test_create_many_persistant_metadata");

  ctx = grpc_mdctx_create();
  /* add phase */
  for (i = 0; i < MANY; i++) {
    gpr_ltoa(i, buffer);
    created[i] = grpc_mdelem_from_strings(ctx, "a", buffer);
  }
  /* verify phase */
  for (i = 0; i < MANY; i++) {
    gpr_ltoa(i, buffer);
    md = grpc_mdelem_from_strings(ctx, "a", buffer);
    GPR_ASSERT(md == created[i]);
    GRPC_MDELEM_UNREF(md);
  }
  /* cleanup phase */
  for (i = 0; i < MANY; i++) {
    GRPC_MDELEM_UNREF(created[i]);
  }
  grpc_mdctx_unref(ctx);

  gpr_free(created);
}
Esempio n. 6
0
static void test_no_op(void) {
  grpc_mdctx *ctx;

  LOG_TEST("test_no_op");

  ctx = grpc_mdctx_create();
  grpc_mdctx_unref(ctx);
}
Esempio n. 7
0
static void fake_oauth2_destroy(grpc_credentials *creds) {
  grpc_fake_oauth2_credentials *c = (grpc_fake_oauth2_credentials *)creds;
  if (c->access_token_md != NULL) {
    grpc_mdelem_unref(c->access_token_md);
  }
  grpc_mdctx_unref(c->md_ctx);
  gpr_free(c);
}
Esempio n. 8
0
static void jwt_destroy(grpc_credentials *creds) {
  grpc_jwt_credentials *c = (grpc_jwt_credentials *)creds;
  grpc_auth_json_key_destruct(&c->key);
  jwt_reset_cache(c);
  gpr_mu_destroy(&c->cache_mu);
  grpc_mdctx_unref(c->md_ctx);
  gpr_free(c);
}
Esempio n. 9
0
static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) {
  connector *c = (connector *)con;
  if (gpr_unref(&c->refs)) {
    grpc_mdctx_unref(c->mdctx);
    /* c->initial_string_buffer does not need to be destroyed */
    gpr_free(c);
  }
}
Esempio n. 10
0
static void oauth2_token_fetcher_destroy(grpc_credentials *creds) {
  grpc_oauth2_token_fetcher_credentials *c =
      (grpc_oauth2_token_fetcher_credentials *)creds;
  if (c->access_token_md != NULL) {
    grpc_mdelem_unref(c->access_token_md);
  }
  gpr_mu_destroy(&c->mu);
  grpc_mdctx_unref(c->md_ctx);
  gpr_free(c);
}
Esempio n. 11
0
static void subchannel_factory_unref(grpc_subchannel_factory *scf) {
  subchannel_factory *f = (subchannel_factory *)scf;
  if (gpr_unref(&f->refs)) {
    GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base,
                                  "subchannel_factory");
    grpc_channel_args_destroy(f->merge_args);
    grpc_mdctx_unref(f->mdctx);
    gpr_free(f);
  }
}
Esempio n. 12
0
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
                                     grpc_subchannel_factory *scf) {
  subchannel_factory *f = (subchannel_factory *)scf;
  if (gpr_unref(&f->refs)) {
    GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, f->master, "subchannel_factory");
    grpc_channel_args_destroy(f->merge_args);
    grpc_mdctx_unref(f->mdctx);
    gpr_free(f);
  }
}
Esempio n. 13
0
static void run_test(void (*test)(), const char *name) {
  gpr_log(GPR_INFO, "RUN TEST: %s", name);
  g_mdctx = grpc_mdctx_create_with_seed(0);
  grpc_chttp2_hpack_compressor_init(&g_compressor, g_mdctx);
  grpc_sopb_init(&g_sopb);
  test();
  grpc_chttp2_hpack_compressor_destroy(&g_compressor);
  grpc_mdctx_unref(g_mdctx);
  grpc_sopb_destroy(&g_sopb);
}
Esempio n. 14
0
static void test_create_channel_stack(void) {
  const grpc_channel_filter filter = {
      call_func, channel_func, sizeof(int), call_init_func, call_destroy_func,
      sizeof(int), channel_init_func, channel_destroy_func, "some_test_filter"};
  const grpc_channel_filter *filters = &filter;
  grpc_channel_stack *channel_stack;
  grpc_call_stack *call_stack;
  grpc_channel_element *channel_elem;
  grpc_call_element *call_elem;
  grpc_arg arg;
  grpc_channel_args chan_args;
  grpc_mdctx *metadata_context;
  int *channel_data;
  int *call_data;

  LOG_TEST_NAME();

  metadata_context = grpc_mdctx_create();

  arg.type = GRPC_ARG_INTEGER;
  arg.key = "test_key";
  arg.value.integer = 42;

  chan_args.num_args = 1;
  chan_args.args = &arg;

  channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1));
  grpc_channel_stack_init(&filters, 1, &chan_args, metadata_context,
                          channel_stack);
  GPR_ASSERT(channel_stack->count == 1);
  channel_elem = grpc_channel_stack_element(channel_stack, 0);
  channel_data = (int *)channel_elem->channel_data;
  GPR_ASSERT(*channel_data == 0);

  call_stack = gpr_malloc(channel_stack->call_stack_size);
  grpc_call_stack_init(channel_stack, NULL, NULL, call_stack);
  GPR_ASSERT(call_stack->count == 1);
  call_elem = grpc_call_stack_element(call_stack, 0);
  GPR_ASSERT(call_elem->filter == channel_elem->filter);
  GPR_ASSERT(call_elem->channel_data == channel_elem->channel_data);
  call_data = (int *)call_elem->call_data;
  GPR_ASSERT(*call_data == 0);
  GPR_ASSERT(*channel_data == 1);

  grpc_call_stack_destroy(call_stack);
  gpr_free(call_stack);
  GPR_ASSERT(*channel_data == 2);

  grpc_channel_stack_destroy(channel_stack);
  gpr_free(channel_stack);

  grpc_mdctx_unref(metadata_context);
}
Esempio n. 15
0
static void destruct_transport(grpc_exec_ctx *exec_ctx,
                               grpc_chttp2_transport *t) {
  size_t i;

  gpr_mu_lock(&t->mu);

  GPR_ASSERT(t->ep == NULL);

  gpr_slice_buffer_destroy(&t->global.qbuf);

  gpr_slice_buffer_destroy(&t->writing.outbuf);
  grpc_chttp2_hpack_compressor_destroy(&t->writing.hpack_compressor);

  gpr_slice_buffer_destroy(&t->parsing.qbuf);
  gpr_slice_buffer_destroy(&t->read_buffer);
  grpc_chttp2_hpack_parser_destroy(&t->parsing.hpack_parser);
  grpc_chttp2_goaway_parser_destroy(&t->parsing.goaway_parser);

  GRPC_MDSTR_UNREF(t->parsing.str_grpc_timeout);

  for (i = 0; i < STREAM_LIST_COUNT; i++) {
    GPR_ASSERT(t->lists[i].head == NULL);
    GPR_ASSERT(t->lists[i].tail == NULL);
  }

  GPR_ASSERT(grpc_chttp2_stream_map_size(&t->parsing_stream_map) == 0);
  GPR_ASSERT(grpc_chttp2_stream_map_size(&t->new_stream_map) == 0);

  grpc_chttp2_stream_map_destroy(&t->parsing_stream_map);
  grpc_chttp2_stream_map_destroy(&t->new_stream_map);
  grpc_connectivity_state_destroy(exec_ctx, &t->channel_callback.state_tracker);

  gpr_mu_unlock(&t->mu);
  gpr_mu_destroy(&t->mu);

  /* callback remaining pings: they're not allowed to call into the transpot,
     and maybe they hold resources that need to be freed */
  while (t->global.pings.next != &t->global.pings) {
    grpc_chttp2_outstanding_ping *ping = t->global.pings.next;
    grpc_exec_ctx_enqueue(exec_ctx, ping->on_recv, 0);
    ping->next->prev = ping->prev;
    ping->prev->next = ping->next;
    gpr_free(ping);
  }

  grpc_mdctx_unref(t->metadata_context);

  gpr_free(t->peer_string);
  gpr_free(t);
}
Esempio n. 16
0
static void test_things_stick_around(void) {
  grpc_mdctx *ctx;
  size_t i, j;
  char *buffer;
  size_t nstrs = 1000;
  grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs);
  size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs);
  grpc_mdstr *test;

  LOG_TEST("test_things_stick_around");

  ctx = grpc_mdctx_create();

  for (i = 0; i < nstrs; i++) {
    gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i);
    strs[i] = grpc_mdstr_from_string(ctx, buffer);
    shuf[i] = i;
    gpr_free(buffer);
  }

  for (i = 0; i < nstrs; i++) {
    GRPC_MDSTR_REF(strs[i]);
    GRPC_MDSTR_UNREF(strs[i]);
  }

  for (i = 0; i < nstrs; i++) {
    size_t p = (size_t)rand() % nstrs;
    size_t q = (size_t)rand() % nstrs;
    size_t temp = shuf[p];
    shuf[p] = shuf[q];
    shuf[q] = temp;
  }

  for (i = 0; i < nstrs; i++) {
    GRPC_MDSTR_UNREF(strs[shuf[i]]);
    for (j = i + 1; j < nstrs; j++) {
      gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]);
      test = grpc_mdstr_from_string(ctx, buffer);
      GPR_ASSERT(test == strs[shuf[j]]);
      GRPC_MDSTR_UNREF(test);
      gpr_free(buffer);
    }
  }

  grpc_mdctx_unref(ctx);
  gpr_free(strs);
  gpr_free(shuf);
}
Esempio n. 17
0
static void destroy_channel(void *p, int ok) {
  grpc_channel *channel = p;
  grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel));
  grpc_mdstr_unref(channel->grpc_status_string);
  grpc_mdstr_unref(channel->grpc_message_string);
  grpc_mdstr_unref(channel->path_string);
  grpc_mdstr_unref(channel->authority_string);
  while (channel->registered_calls) {
    registered_call *rc = channel->registered_calls;
    channel->registered_calls = rc->next;
    grpc_mdelem_unref(rc->path);
    grpc_mdelem_unref(rc->authority);
    gpr_free(rc);
  }
  grpc_mdctx_unref(channel->metadata_context);
  gpr_mu_destroy(&channel->registered_call_mu);
  gpr_free(channel);
}
Esempio n. 18
0
static void test_base64_and_huffman_works(void) {
  grpc_mdctx *ctx;
  grpc_mdstr *str;
  gpr_slice slice1;
  gpr_slice slice2;

  LOG_TEST("test_base64_and_huffman_works");

  ctx = grpc_mdctx_create();
  str = grpc_mdstr_from_string(ctx, "abcdefg");
  slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str);
  slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice);
  GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2));

  gpr_slice_unref(slice2);
  GRPC_MDSTR_UNREF(str);
  grpc_mdctx_unref(ctx);
}
Esempio n. 19
0
static void test_create_string(void) {
  grpc_mdctx *ctx;
  grpc_mdstr *s1, *s2, *s3;

  LOG_TEST("test_create_string");

  ctx = grpc_mdctx_create();
  s1 = grpc_mdstr_from_string(ctx, "hello");
  s2 = grpc_mdstr_from_string(ctx, "hello");
  s3 = grpc_mdstr_from_string(ctx, "very much not hello");
  GPR_ASSERT(s1 == s2);
  GPR_ASSERT(s3 != s1);
  GPR_ASSERT(gpr_slice_str_cmp(s1->slice, "hello") == 0);
  GPR_ASSERT(gpr_slice_str_cmp(s3->slice, "very much not hello") == 0);
  GRPC_MDSTR_UNREF(s1);
  GRPC_MDSTR_UNREF(s2);
  grpc_mdctx_unref(ctx);
  GRPC_MDSTR_UNREF(s3);
}
Esempio n. 20
0
static void test_create_many_ephemeral_metadata(void) {
  grpc_mdctx *ctx;
  char buffer[GPR_LTOA_MIN_BUFSIZE];
  long i;
  size_t mdtab_capacity_before;

  LOG_TEST("test_create_many_ephemeral_metadata");

  ctx = grpc_mdctx_create();
  mdtab_capacity_before = grpc_mdctx_get_mdtab_capacity_test_only(ctx);
  /* add, and immediately delete a bunch of different elements */
  for (i = 0; i < MANY; i++) {
    gpr_ltoa(i, buffer);
    GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", buffer));
  }
  /* capacity should not grow */
  GPR_ASSERT(mdtab_capacity_before ==
             grpc_mdctx_get_mdtab_capacity_test_only(ctx));
  grpc_mdctx_unref(ctx);
}
Esempio n. 21
0
static void test_create_metadata(void) {
  grpc_mdctx *ctx;
  grpc_mdelem *m1, *m2, *m3;

  LOG_TEST("test_create_metadata");

  ctx = grpc_mdctx_create();
  m1 = grpc_mdelem_from_strings(ctx, "a", "b");
  m2 = grpc_mdelem_from_strings(ctx, "a", "b");
  m3 = grpc_mdelem_from_strings(ctx, "a", "c");
  GPR_ASSERT(m1 == m2);
  GPR_ASSERT(m3 != m1);
  GPR_ASSERT(m3->key == m1->key);
  GPR_ASSERT(m3->value != m1->value);
  GPR_ASSERT(gpr_slice_str_cmp(m1->key->slice, "a") == 0);
  GPR_ASSERT(gpr_slice_str_cmp(m1->value->slice, "b") == 0);
  GPR_ASSERT(gpr_slice_str_cmp(m3->value->slice, "c") == 0);
  GRPC_MDELEM_UNREF(m1);
  GRPC_MDELEM_UNREF(m2);
  GRPC_MDELEM_UNREF(m3);
  grpc_mdctx_unref(ctx);
}
Esempio n. 22
0
static void test_spin_creating_the_same_thing(void) {
  grpc_mdctx *ctx;

  LOG_TEST("test_spin_creating_the_same_thing");

  ctx = grpc_mdctx_create();
  GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 0);
  GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 0);

  GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b"));
  GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1);
  GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1);

  GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b"));
  GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1);
  GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1);

  GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b"));
  GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1);
  GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1);

  grpc_mdctx_unref(ctx);
}
Esempio n. 23
0
static void destroy_channel(void *p, int ok) {
  grpc_channel *channel = p;
  size_t i;
  grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel));
  for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) {
    grpc_mdelem_unref(channel->grpc_status_elem[i]);
  }
  grpc_mdstr_unref(channel->grpc_status_string);
  grpc_mdstr_unref(channel->grpc_compression_level_string);
  grpc_mdstr_unref(channel->grpc_message_string);
  grpc_mdstr_unref(channel->path_string);
  grpc_mdstr_unref(channel->authority_string);
  while (channel->registered_calls) {
    registered_call *rc = channel->registered_calls;
    channel->registered_calls = rc->next;
    grpc_mdelem_unref(rc->path);
    grpc_mdelem_unref(rc->authority);
    gpr_free(rc);
  }
  grpc_mdctx_unref(channel->metadata_context);
  gpr_mu_destroy(&channel->registered_call_mu);
  gpr_free(channel);
}
Esempio n. 24
0
static void test_slices_work(void) {
  /* ensure no memory leaks when switching representation from mdstr to slice */
  grpc_mdctx *ctx;
  grpc_mdstr *str;
  gpr_slice slice;

  LOG_TEST("test_slices_work");

  ctx = grpc_mdctx_create();

  str = grpc_mdstr_from_string(
      ctx, "123456789012345678901234567890123456789012345678901234567890");
  slice = gpr_slice_ref(str->slice);
  GRPC_MDSTR_UNREF(str);
  gpr_slice_unref(slice);

  str = grpc_mdstr_from_string(
      ctx, "123456789012345678901234567890123456789012345678901234567890");
  slice = gpr_slice_ref(str->slice);
  gpr_slice_unref(slice);
  GRPC_MDSTR_UNREF(str);

  grpc_mdctx_unref(ctx);
}
Esempio n. 25
0
static void test_vectors(grpc_slice_split_mode mode) {
  grpc_chttp2_hpack_parser parser;
  grpc_mdctx *mdctx = grpc_mdctx_create();

  grpc_chttp2_hpack_parser_init(&parser, mdctx);
  /* D.2.1 */
  test_vector(&parser, mode,
              "400a 6375 7374 6f6d 2d6b 6579 0d63 7573"
              "746f 6d2d 6865 6164 6572",
              "custom-key", "custom-header", NULL);
  /* D.2.2 */
  test_vector(&parser, mode, "040c 2f73 616d 706c 652f 7061 7468", ":path",
              "/sample/path", NULL);
  /* D.2.3 */
  test_vector(&parser, mode,
              "1008 7061 7373 776f 7264 0673 6563 7265"
              "74",
              "password", "secret", NULL);
  /* D.2.4 */
  test_vector(&parser, mode, "82", ":method", "GET", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser, mdctx);
  /* D.3.1 */
  test_vector(&parser, mode,
              "8286 8441 0f77 7777 2e65 7861 6d70 6c65"
              "2e63 6f6d",
              ":method", "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", NULL);
  /* D.3.2 */
  test_vector(&parser, mode, "8286 84be 5808 6e6f 2d63 6163 6865", ":method",
              "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", "cache-control", "no-cache", NULL);
  /* D.3.3 */
  test_vector(&parser, mode,
              "8287 85bf 400a 6375 7374 6f6d 2d6b 6579"
              "0c63 7573 746f 6d2d 7661 6c75 65",
              ":method", "GET", ":scheme", "https", ":path", "/index.html",
              ":authority", "www.example.com", "custom-key", "custom-value",
              NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser, mdctx);
  /* D.4.1 */
  test_vector(&parser, mode,
              "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4"
              "ff",
              ":method", "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", NULL);
  /* D.4.2 */
  test_vector(&parser, mode, "8286 84be 5886 a8eb 1064 9cbf", ":method", "GET",
              ":scheme", "http", ":path", "/", ":authority", "www.example.com",
              "cache-control", "no-cache", NULL);
  /* D.4.3 */
  test_vector(&parser, mode,
              "8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925"
              "a849 e95b b8e8 b4bf",
              ":method", "GET", ":scheme", "https", ":path", "/index.html",
              ":authority", "www.example.com", "custom-key", "custom-value",
              NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser, mdctx);
  parser.table.max_bytes = 256;
  /* D.5.1 */
  test_vector(&parser, mode,
              "4803 3330 3258 0770 7269 7661 7465 611d"
              "4d6f 6e2c 2032 3120 4f63 7420 3230 3133"
              "2032 303a 3133 3a32 3120 474d 546e 1768"
              "7474 7073 3a2f 2f77 7777 2e65 7861 6d70"
              "6c65 2e63 6f6d",
              ":status", "302", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.5.2 */
  test_vector(&parser, mode, "4803 3330 37c1 c0bf", ":status", "307",
              "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.5.3 */
  test_vector(&parser, mode,
              "88c1 611d 4d6f 6e2c 2032 3120 4f63 7420"
              "3230 3133 2032 303a 3133 3a32 3220 474d"
              "54c0 5a04 677a 6970 7738 666f 6f3d 4153"
              "444a 4b48 514b 425a 584f 5157 454f 5049"
              "5541 5851 5745 4f49 553b 206d 6178 2d61"
              "6765 3d33 3630 303b 2076 6572 7369 6f6e"
              "3d31",
              ":status", "200", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:22 GMT", "location",
              "https://www.example.com", "content-encoding", "gzip",
              "set-cookie",
              "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser, mdctx);
  parser.table.max_bytes = 256;
  /* D.6.1 */
  test_vector(&parser, mode,
              "4882 6402 5885 aec3 771a 4b61 96d0 7abe"
              "9410 54d4 44a8 2005 9504 0b81 66e0 82a6"
              "2d1b ff6e 919d 29ad 1718 63c7 8f0b 97c8"
              "e9ae 82ae 43d3",
              ":status", "302", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.6.2 */
  test_vector(&parser, mode, "4883 640e ffc1 c0bf", ":status", "307",
              "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.6.3 */
  test_vector(&parser, mode,
              "88c1 6196 d07a be94 1054 d444 a820 0595"
              "040b 8166 e084 a62d 1bff c05a 839b d9ab"
              "77ad 94e7 821d d7f2 e6c7 b335 dfdf cd5b"
              "3960 d5af 2708 7f36 72c1 ab27 0fb5 291f"
              "9587 3160 65c0 03ed 4ee5 b106 3d50 07",
              ":status", "200", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:22 GMT", "location",
              "https://www.example.com", "content-encoding", "gzip",
              "set-cookie",
              "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);
  grpc_mdctx_unref(mdctx);
}
Esempio n. 26
0
static void test_find(void) {
  grpc_chttp2_hptbl tbl;
  int i;
  char buffer[32];
  grpc_mdctx *mdctx;
  grpc_chttp2_hptbl_find_result r;

  LOG_TEST("test_find");

  mdctx = grpc_mdctx_create();
  grpc_chttp2_hptbl_init(&tbl, mdctx);
  grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "xyz"));
  grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "123"));
  grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "x", "1"));

  r = find_simple(&tbl, "abc", "123");
  GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, "abc", "xyz");
  GPR_ASSERT(r.index == 3 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, "x", "1");
  GPR_ASSERT(r.index == 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, "x", "2");
  GPR_ASSERT(r.index == 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 0);

  r = find_simple(&tbl, "vary", "some-vary-arg");
  GPR_ASSERT(r.index == 59);
  GPR_ASSERT(r.has_value == 0);

  r = find_simple(&tbl, "accept-encoding", "gzip, deflate");
  GPR_ASSERT(r.index == 16);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, "accept-encoding", "gzip");
  GPR_ASSERT(r.index == 16);
  GPR_ASSERT(r.has_value == 0);

  r = find_simple(&tbl, ":method", "GET");
  GPR_ASSERT(r.index == 2);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, ":method", "POST");
  GPR_ASSERT(r.index == 3);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, ":method", "PUT");
  GPR_ASSERT(r.index == 2 || r.index == 3);
  GPR_ASSERT(r.has_value == 0);

  r = find_simple(&tbl, "this-does-not-exist", "");
  GPR_ASSERT(r.index == 0);
  GPR_ASSERT(r.has_value == 0);

  /* overflow the string buffer, check find still works */
  for (i = 0; i < 10000; i++) {
    gpr_ltoa(i, buffer);
    grpc_chttp2_hptbl_add(&tbl,
                          grpc_mdelem_from_strings(mdctx, "test", buffer));
  }

  r = find_simple(&tbl, "abc", "123");
  GPR_ASSERT(r.index == 0);
  GPR_ASSERT(r.has_value == 0);

  r = find_simple(&tbl, "test", "9999");
  GPR_ASSERT(r.index == 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 1);

  r = find_simple(&tbl, "test", "9998");
  GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
  GPR_ASSERT(r.has_value == 1);

  for (i = 0; i < tbl.num_ents; i++) {
    int expect = 9999 - i;
    gpr_ltoa(expect, buffer);

    r = find_simple(&tbl, "test", buffer);
    GPR_ASSERT(r.index == i + 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
    GPR_ASSERT(r.has_value == 1);
  }

  r = find_simple(&tbl, "test", "10000");
  GPR_ASSERT(r.index != 0);
  GPR_ASSERT(r.has_value == 0);

  grpc_chttp2_hptbl_destroy(&tbl);
  grpc_mdctx_unref(mdctx);
}
Esempio n. 27
0
static void test_static_lookup(void) {
  grpc_chttp2_hptbl tbl;
  grpc_mdctx *mdctx;

  mdctx = grpc_mdctx_create();
  grpc_chttp2_hptbl_init(&tbl, mdctx);

  LOG_TEST("test_static_lookup");
  assert_index(&tbl, 1, ":authority", "");
  assert_index(&tbl, 2, ":method", "GET");
  assert_index(&tbl, 3, ":method", "POST");
  assert_index(&tbl, 4, ":path", "/");
  assert_index(&tbl, 5, ":path", "/index.html");
  assert_index(&tbl, 6, ":scheme", "http");
  assert_index(&tbl, 7, ":scheme", "https");
  assert_index(&tbl, 8, ":status", "200");
  assert_index(&tbl, 9, ":status", "204");
  assert_index(&tbl, 10, ":status", "206");
  assert_index(&tbl, 11, ":status", "304");
  assert_index(&tbl, 12, ":status", "400");
  assert_index(&tbl, 13, ":status", "404");
  assert_index(&tbl, 14, ":status", "500");
  assert_index(&tbl, 15, "accept-charset", "");
  assert_index(&tbl, 16, "accept-encoding", "gzip, deflate");
  assert_index(&tbl, 17, "accept-language", "");
  assert_index(&tbl, 18, "accept-ranges", "");
  assert_index(&tbl, 19, "accept", "");
  assert_index(&tbl, 20, "access-control-allow-origin", "");
  assert_index(&tbl, 21, "age", "");
  assert_index(&tbl, 22, "allow", "");
  assert_index(&tbl, 23, "authorization", "");
  assert_index(&tbl, 24, "cache-control", "");
  assert_index(&tbl, 25, "content-disposition", "");
  assert_index(&tbl, 26, "content-encoding", "");
  assert_index(&tbl, 27, "content-language", "");
  assert_index(&tbl, 28, "content-length", "");
  assert_index(&tbl, 29, "content-location", "");
  assert_index(&tbl, 30, "content-range", "");
  assert_index(&tbl, 31, "content-type", "");
  assert_index(&tbl, 32, "cookie", "");
  assert_index(&tbl, 33, "date", "");
  assert_index(&tbl, 34, "etag", "");
  assert_index(&tbl, 35, "expect", "");
  assert_index(&tbl, 36, "expires", "");
  assert_index(&tbl, 37, "from", "");
  assert_index(&tbl, 38, "host", "");
  assert_index(&tbl, 39, "if-match", "");
  assert_index(&tbl, 40, "if-modified-since", "");
  assert_index(&tbl, 41, "if-none-match", "");
  assert_index(&tbl, 42, "if-range", "");
  assert_index(&tbl, 43, "if-unmodified-since", "");
  assert_index(&tbl, 44, "last-modified", "");
  assert_index(&tbl, 45, "link", "");
  assert_index(&tbl, 46, "location", "");
  assert_index(&tbl, 47, "max-forwards", "");
  assert_index(&tbl, 48, "proxy-authenticate", "");
  assert_index(&tbl, 49, "proxy-authorization", "");
  assert_index(&tbl, 50, "range", "");
  assert_index(&tbl, 51, "referer", "");
  assert_index(&tbl, 52, "refresh", "");
  assert_index(&tbl, 53, "retry-after", "");
  assert_index(&tbl, 54, "server", "");
  assert_index(&tbl, 55, "set-cookie", "");
  assert_index(&tbl, 56, "strict-transport-security", "");
  assert_index(&tbl, 57, "transfer-encoding", "");
  assert_index(&tbl, 58, "user-agent", "");
  assert_index(&tbl, 59, "vary", "");
  assert_index(&tbl, 60, "via", "");
  assert_index(&tbl, 61, "www-authenticate", "");

  grpc_chttp2_hptbl_destroy(&tbl);
  grpc_mdctx_unref(mdctx);
}