static void check_values(const test_entry* input, size_t num_entries,
                         grpc_slice_hash_table* table) {
  for (size_t i = 0; i < num_entries; ++i) {
    grpc_slice key = grpc_slice_from_static_string(input[i].key);
    char* actual = grpc_slice_hash_table_get(table, key);
    GPR_ASSERT(actual != NULL);
    GPR_ASSERT(strcmp(actual, input[i].value) == 0);
    grpc_slice_unref(key);
  }
}
Exemple #2
0
void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx,
                                   const grpc_slice_hash_table* table,
                                   grpc_slice path) {
  void* value = grpc_slice_hash_table_get(table, path);
  // If we didn't find a match for the path, try looking for a wildcard
  // entry (i.e., change "/service/method" to "/service/*").
  if (value == NULL) {
    char* path_str = grpc_slice_to_c_string(path);
    const char* sep = strrchr(path_str, '/') + 1;
    const size_t len = (size_t)(sep - path_str);
    char* buf = gpr_malloc(len + 2);  // '*' and NUL
    memcpy(buf, path_str, len);
    buf[len] = '*';
    buf[len + 1] = '\0';
    grpc_slice wildcard_path = grpc_slice_from_copied_string(buf);
    gpr_free(buf);
    value = grpc_slice_hash_table_get(table, wildcard_path);
    grpc_slice_unref_internal(exec_ctx, wildcard_path);
    gpr_free(path_str);
  }
  return value;
}
static void check_non_existent_value(const char* key_string,
                                     grpc_slice_hash_table* table) {
  grpc_slice key = grpc_slice_from_static_string(key_string);
  GPR_ASSERT(grpc_slice_hash_table_get(table, key) == NULL);
  grpc_slice_unref(key);
}