summaryrefslogtreecommitdiff
path: root/src/sbearssl/sbearssl_sni_policy_init.c
blob: 3446f35b8cfcc43c38796386e4ef612321d3fd15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ISC license. */

#include <string.h>

#include <bearssl.h>

#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/avltree.h>

#include <s6-networking/sbearssl.h>
#include "sbearssl-internal.h"

static void *sbearssl_sni_policy_node_dtok (uint32_t d, void *data)
{
  sbearssl_sni_policy_context *pol = data ;
  return pol->storage.s + genalloc_s(sbearssl_sni_policy_node, &pol->mapga)[d].servername ;
}

static int sbearssl_sni_policy_node_cmp (void const *a, void const *b, void *data)
{
  (void)data ;
  return strcmp((char const *)a, (char const *)b) ;
}

void sbearssl_sni_policy_init (sbearssl_sni_policy_context *pol)
{
  avltree_init(&pol->map, 3, 3, 8, &sbearssl_sni_policy_node_dtok, &sbearssl_sni_policy_node_cmp, pol) ;
  pol->mapga = genalloc_zero ;
  pol->certga = genalloc_zero ;
  pol->storage = stralloc_zero ;
  pol->vtable = &sbearssl_sni_policy_vtable ;
}