blob: ff14a0146641be5c996441fb0bbbb6065642e13b [file] [log] [blame]
adamdunkelsa2f3c422004-09-12 20:24:53 +00001/*
2 * Copyright (c) 2004, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: uipbuf.h,v 1.3 2004/09/12 20:24:56 adamdunkels Exp $
34 */
adamdunkels56807862004-08-09 20:50:11 +000035/**
36 * \file
37 * uIP data buffering helper functions.
38 * \author
39 * Adam Dunkels <adam@sics.se>
40 *
41 */
42
43#ifndef __UIPBUF_H__
44#define __UIPBUF_H__
45
46#include "uip.h"
47
48/**
49 * \defgroup uipbuf uIP data buffering helper library.
50 *
51 * The event driven API that uIP uses can be tricky to use when
52 * dealing with incoming TCP data. The data can be split over any
53 * number of incoming segments and uIP does not provide any stream
54 * abstraction by itself. To remedy this, the uIP data buffering
55 * helper library provides a set of functions that make buffering data
56 * easier.
57 *
58 * The data buffering library provides a structure that holds a
59 * pointer to a buffer and the state of the buffer, as well as a set
60 * of functions for manipulating the buffer state. The functions are
61 * intended to facilitate buffering of both data that is of a known
62 * size and data that is terminated by a specified byte.
63 *
64 * @{
65 */
66
67/**
68 * Return value of the buffering functions that indicates that a
69 * buffer was not filled by incoming data.
70 *
71 * \hideinitializer
72 */
73#define UIPBUF_NOT_FULL 0
74#define UIPBUF_NOT_FOUND 0
75
76/**
77 * Return value of the buffering functions that indicates that a
78 * buffer was completely filled by incoming data.
79 *
80 * \hideinitializer
81 */
82#define UIPBUF_FULL 1
83
84/**
85 * Return value of the buffering functions that indicates that an
86 * end-marker byte was found.
87 *
88 * \hideinitializer
89 */
90#define UIPBUF_FOUND 2
91
92/**
93 * The structure that holds the state of a uIP buffer.
94 *
95 * This structure holds the state of a uIP buffer. The structure has
96 * no user-visible elements, but is used through the functions
97 * provided by the library.
98 *
99 * \hideinitializer
100 */
101struct uipbuf_buffer {
102 u8_t *ptr, *buffer;
103 unsigned short left, bufsize;
104};
105
106/**
107 * Set up a new uIP buffer structure.
108 *
109 * This function is used for setting up a uIP buffer structure with a
110 * specified size. The function should be called the first time a uIP
111 * buffer is used. The caller must provide the memory for holding the
112 * buffered bytes and the size of the buffer memory.
113 *
114 * \param buf A pointer to a uipbuf_buffer structure that is to be
115 * initialized.
116 *
117 * \param bufptr A pointer to the memory for holding the buffered
118 * data.
119 *
120 * \param size The size of the buffer memory.
121 *
122 */
123void uipbuf_setup(struct uipbuf_buffer *buf,
124 u8_t *bufptr, u16_t size);
125
126/**
127 * Buffer data until the buffer is full.
128 *
129 * This function puts data into the buffer, but no more than the
130 * buffer can hold.
131 *
132 * \param buf A pointer to the ::uipbuf_buffer structure that holds
133 * the state of the buffer.
134 *
135 * \param dataptr A pointer to the data that is to be buffered.
136 *
137 * \param datalen The length of the data that is to be buffered.
138 *
139 * \return If the buffer was not filled, the value UIPBUF_NOT_FULL
140 * is returned. If the buffer was filled, the number of bytes that
141 * could not be buffered is returned. If the buffer was exactly filled
142 * with the data, the value of 0 is returned.
143 *
144 */
145u8_t uipbuf_bufdata(struct uipbuf_buffer *buf, u16_t len,
146 u8_t **dataptr, u16_t *datalen);
147
148/**
149 * Buffer data until a specific character is found or the buffer is full.
150 *
151 * This function puts data into the buffer until a specific marker
152 * byte is found. The marker byte is put into the buffer at the end of
153 * the data.
154 *
155 * \param buf A pointer to the ::uipbuf_buffer structure that holds
156 * the state of the buffer.
157 *
158 * \param dataptr A pointer to the data that is to be buffered.
159 *
160 * \param datalen The length of the data that is to be buffered.
161 *
162 * \param byte The end-marker byte that indicates the end of the data
163 * that is to be buffered.
164 *
165 * \return This function returns the number of protruding bytes after
166 * the end-marker byte, if the marker was found. If the marker was not
167 * found and all of the data was buffered, the value of
168 * UIPBUF_NOT_FOUND is returned. If the marker was not found, but the
169 * data made the buffer fill up, the value of UIPBUF_FULL is returned.
170 *
171 */
adamdunkelse1b53842004-08-14 21:56:55 +0000172u8_t uipbuf_bufto(struct uipbuf_buffer *buf, u8_t endmarker,
173 u8_t **dataptr, u16_t *datalen);
adamdunkels56807862004-08-09 20:50:11 +0000174
175u16_t uipbuf_len(struct uipbuf_buffer *buf);
176
177/** @} */
178
179#endif /* __UIPBUF_H__ */