Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsstream.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  *
59  * wsstream.h
60  *
61  * Author: Markku Rossi <mtr@iki.fi>
62  *
63  * Copyright (c) 1999-2000 WAPIT OY LTD.
64  * All rights reserved.
65  *
66  * Generic input / output stream.
67  *
68  */
69 
70 #ifndef WSSTREAM_H
71 #define WSSTREAM_H
72 
73 /********************* Types and definitions ****************************/
74 
75 /* The generic input / output stream that is capable of handling
76  ISO/IEC-10646 characters. */
77 
78 #define WS_STREAM_BUFFER_SIZE 1024
79 
80 /* Do IO to the stream instance `context'. When reading, the function
81  must read at most `buflen' characters to the buffer `buf' and it
82  must return the number of characters read. When writing, the
83  buffer `buf' has `buflen' characters and the function must return
84  the number of characters written. In both operations, if the
85  function reads or writes less that `buflen' characters, the EOF is
86  assumed to been seen in the stream. */
87 typedef size_t (*WsStreamIOProc)(void *context, WsUInt32 *buf, size_t buflen);
88 
89 /* Flush all buffered data of the stream instance `context'. The
90  function returns WS_TRUE if the flushing was successful or WS_FALSE
91  otherwise. */
92 typedef WsBool (*WsStreamFlushProc)(void *context);
93 
94 /* Close the stream instance `context'. */
95 typedef void (*WsStreamCloseProc)(void *context);
96 
97 /* A stream handle. */
99 {
100  /* The method functions of this stream. */
104 
105  /* The stream instance context. */
106  void *context;
107 
108  /* The current buffered contents of the stream. */
110  size_t buffer_pos;
112 
113  /* The possible put-back character. */
116 };
117 
118 typedef struct WsStreamRec WsStream;
119 
120 /********************* Stream access functions **************************/
121 
122 /* Get a character from the stream `stream'. The character is
123  returned in `ch_return'. The function returns WS_FALSE if the end
124  of stream has been encountered. */
125 WsBool ws_stream_getc(WsStream *stream, WsUInt32 *ch_return);
126 
127 /* Put the character `ch' back to the stream `stream'. */
128 void ws_stream_ungetc(WsStream *stream, WsUInt32 ch);
129 
130 /* Flush all buffered data to the stream back-end. */
132 
133 /* Close the stream `stream'. */
134 void ws_stream_close(WsStream *stream);
135 
136 /********************* Constructors for different streams ***************/
137 
138 /* A generic constructor to create the actual WsStream from the
139  context and from the method functions. The function returns NULL
140  if the stream creation failed. */
143 
144 /* Create a new file stream to the file handle `fp'. The argument
145  `output' specifies whether the stream is an output or an input
146  stream, respectively. The argument `close' specifies whether the
147  file handle `fp' is closed when the stream is closed. It is
148  basicly a good idea to set this argument to WS_FALSE when wrapping
149  the system streams (stdin, stdout, stderr) in a WsStream. The
150  function returns NULL if the stream could not be created. */
151 WsStream *ws_stream_new_file(FILE *fp, WsBool output, WsBool close);
152 
153 /* Create a new data input stream for `data_len' bytes of ISO-8859/1
154  data in `data'. The function returns NULL if the stream could not
155  be created. */
156 WsStream *ws_stream_new_data_input(const unsigned char *data, size_t data_len);
157 
158 #endif /* not WSSTREAM_H */
WsUInt32 buffer[WS_STREAM_BUFFER_SIZE]
Definition: wsstream.h:109
void ws_stream_ungetc(WsStream *stream, WsUInt32 ch)
Definition: wsstream.c:101
WsBool ws_stream_flush(WsStream *stream)
Definition: wsstream.c:108
Definition: parse.c:65
unsigned long WsUInt32
Definition: wsint.h:122
#define WS_STREAM_BUFFER_SIZE
Definition: wsstream.h:78
WsStream * ws_stream_new(void *context, WsStreamIOProc io, WsStreamFlushProc flush, WsStreamCloseProc close)
Definition: wsstream.c:126
WsStream * ws_stream_new_data_input(const unsigned char *data, size_t data_len)
void ws_stream_close(WsStream *stream)
Definition: wsstream.c:117
WsBool ungetch_valid
Definition: wsstream.h:114
size_t data_in_buffer
Definition: wsstream.h:111
WsStreamIOProc io
Definition: wsstream.h:101
WsBool ws_stream_getc(WsStream *stream, WsUInt32 *ch_return)
Definition: wsstream.c:74
size_t buffer_pos
Definition: wsstream.h:110
WsStreamCloseProc close
Definition: wsstream.h:103
void * context
Definition: wsstream.h:106
size_t(* WsStreamIOProc)(void *context, WsUInt32 *buf, size_t buflen)
Definition: wsstream.h:87
WsStreamFlushProc flush
Definition: wsstream.h:102
WsBool
Definition: wsint.h:128
WsStream * ws_stream_new_file(FILE *fp, WsBool output, WsBool close)
WsUInt32 ungetch
Definition: wsstream.h:115
void(* WsStreamCloseProc)(void *context)
Definition: wsstream.h:95
WsBool(* WsStreamFlushProc)(void *context)
Definition: wsstream.h:92
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.