aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/http/http_buffer.h
blob: 5c7569b9e3cce5c562e71d6604749ab46dbcc225 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (c) 2022 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SRC_PLUGINS_HTTP_HTTP_BUFFER_H_
#define SRC_PLUGINS_HTTP_HTTP_BUFFER_H_

#include <svm/svm_fifo.h>

#define HTTP_BUFFER_DATA_SZ 24

typedef enum http_buffer_type_
{
  HTTP_BUFFER_FIFO,
  HTTP_BUFFER_PTR,
} http_buffer_type_t;

typedef struct http_buffer_vft_ http_buffer_vft_t;

typedef struct http_buffer_
{
  http_buffer_vft_t *vft;
  u8 data[HTTP_BUFFER_DATA_SZ];
} http_buffer_t;

struct http_buffer_vft_
{
  void (*init) (http_buffer_t *, void *data, u32 len);
  void (*free) (http_buffer_t *);
  svm_fifo_seg_t *(*get_segs) (http_buffer_t *, u32 max_len, u32 *n_segs);
  int (*drain) (http_buffer_t *, u32 len);
  u8 (*is_drained) (http_buffer_t *);
};

void http_buffer_init (http_buffer_t *hb, http_buffer_type_t type,
		       svm_fifo_t *f, u32 data_len);

static inline void
http_buffer_free (http_buffer_t *hb)
{
  if (hb->vft)
    hb->vft->free (hb);
}

static inline svm_fifo_seg_t *
http_buffer_get_segs (http_buffer_t *hb, u32 max_len, u32 *n_segs)
{
  return hb->vft->get_segs (hb, max_len, n_segs);
}

static inline int
http_buffer_drain (http_buffer_t *hb, u32 len)
{
  return hb->vft->drain (hb, len);
}

static inline u8
http_buffer_is_drained (http_buffer_t *hb)
{
  return hb->vft->is_drained (hb);
}

#endif /* SRC_PLUGINS_HTTP_HTTP_BUFFER_H_ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */