summaryrefslogtreecommitdiff
path: root/src/libtipidee/tipidee_response_header_preparebuiltin.c
blob: a04b6669fd0054b77a40b6c7414ef5e2ddfb40d7 (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
/* 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 ;
    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 ;
}