Beispiel #1
0
static void composite_call_metadata_cb(grpc_exec_ctx *exec_ctx, void *user_data,
                                       grpc_credentials_md *md_elems,
                                       size_t num_md,
                                       grpc_credentials_status status) {
  grpc_composite_call_credentials_metadata_context *ctx =
      (grpc_composite_call_credentials_metadata_context *)user_data;
  if (status != GRPC_CREDENTIALS_OK) {
    ctx->cb(exec_ctx, ctx->user_data, NULL, 0, status);
    return;
  }

  /* Copy the metadata in the context. */
  if (num_md > 0) {
    size_t i;
    for (i = 0; i < num_md; i++) {
      grpc_credentials_md_store_add(ctx->md_elems, md_elems[i].key,
                                    md_elems[i].value);
    }
  }

  /* See if we need to get some more metadata. */
  if (ctx->creds_index < ctx->composite_creds->inner.num_creds) {
    grpc_call_credentials *inner_creds =
        ctx->composite_creds->inner.creds_array[ctx->creds_index++];
    grpc_call_credentials_get_request_metadata(
        exec_ctx, inner_creds, ctx->pollset, ctx->auth_md_context,
        composite_call_metadata_cb, ctx);
    return;
  }

  /* We're done!. */
  ctx->cb(exec_ctx, ctx->user_data, ctx->md_elems->entries,
          ctx->md_elems->num_entries, GRPC_CREDENTIALS_OK);
  composite_call_md_context_destroy(ctx);
}
Beispiel #2
0
static void test_add_to_empty_md_store(void) {
    grpc_credentials_md_store *store = grpc_credentials_md_store_create(0);
    const char *key_str = "hello";
    const char *value_str = "there blah blah blah blah blah blah blah";
    gpr_slice key = gpr_slice_from_copied_string(key_str);
    gpr_slice value = gpr_slice_from_copied_string(value_str);
    grpc_credentials_md_store_add(store, key, value);
    GPR_ASSERT(store->num_entries == 1);
    GPR_ASSERT(gpr_slice_cmp(key, store->entries[0].key) == 0);
    GPR_ASSERT(gpr_slice_cmp(value, store->entries[0].value) == 0);
    gpr_slice_unref(key);
    gpr_slice_unref(value);
    grpc_credentials_md_store_unref(store);
}