summaryrefslogtreecommitdiff
path: root/src/libtipidee/tipidee_response_header_preparebuiltin.c
blob: 56978c79b4ab859eafda47d42aecf4c0a2225213 (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
/* ISC license. */

#include <stdint.h>
#include <string.h>

#include <tipidee/response.h>

int tipidee_response_header_preparebuiltin (tipidee_response_header *tab, uint32_t n, char const *s, size_t len)
{
  size_t pos = 0 ;
  for (uint32_t i = 0 ; i < n ; i++)
  {
    char const *next ;
    tab[i].key = s + pos ;
    next = memchr(s + pos, 0, len - pos) ;
    if (!next) return 0 ;
    pos = next - s ;
    if (pos++ >= len) return 0 ;
    tab[i].options = (uint8_t)s[pos] ;
    if (pos++ >= len) return 0 ;
    if (tab[i].options & 0x80) tab[i].value = 0 ;
    else
    {
      tab[i].value = s + pos ;
      next = memchr(s + pos, 0, len - pos) ;
      if (!next) return 0 ;
      pos = next - s ;
      if (pos++ >= len) return 0 ;
    }
  }
  return pos == len ;
}