FreeTDS API: include/freetds/tds/stream.h Source File

FreeTDS API

Loading...
Searching...
No Matches
stream.h
1/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 2013 Frediano Ziglio
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef _tdsguard_a5iqP6Ed7kDGP9L1OvOL7W_
21#define _tdsguard_a5iqP6Ed7kDGP9L1OvOL7W_
22
23#ifndef _tdsguard_hfOrWb5znoUCWdBPoNQvqN_
24#error Include tds.h first
25#endif
26
27#include <stdio.h> /* FILE * */
28#include <freetds/tds/iconv.h> /* TDS_ICONV_DIRECTION */
29#include <freetds/pushvis.h>
30
32 typedef struct tds_input_stream {
37 int (*read)(struct tds_input_stream *stream, void *ptr, size_t len);
38} TDSINSTREAM;
39
41 typedef struct tds_output_stream {
43 int (*write)(struct tds_output_stream *stream, size_t len);
52 char *buffer;
53 size_t buf_len;
54} TDSOUTSTREAM;
55
59 typedef struct tds_fileout_stream
60{
61 TDSOUTSTREAM stream;
62 FILE *fp;
63 char block[4096];
66 int buff_mode;
67} TDSFILEOUTSTREAM;
68
69void tds_fileout_stream_init(TDSFILEOUTSTREAM * s, FILE * fp, int buff_mode);
70
71TDSRET tds_fileout_stream_flush(TDSFILEOUTSTREAM * s);
72TDSRET tds_fileout_stream_put(TDSFILEOUTSTREAM * s, void const *src, size_t n);
73
75TDSRET tds_convert_stream(TDSSOCKET * tds, TDSICONV * char_conv, TDS_ICONV_DIRECTION direction,
76 TDSINSTREAM * istream, TDSOUTSTREAM *ostream);
78TDSRET tds_copy_stream(TDSINSTREAM * istream, TDSOUTSTREAM * ostream);
79
80/* Additional streams */
81
83 typedef struct tds_datain_stream {
84 TDSINSTREAM stream;
85 size_t wire_size;
86 TDSSOCKET *tds;
87} TDSDATAINSTREAM;
88
89void tds_datain_stream_init(TDSDATAINSTREAM * stream, TDSSOCKET * tds, size_t wire_size);
90
92 typedef struct tds_dataout_stream {
93 TDSOUTSTREAM stream;
94 TDSSOCKET *tds;
95 size_t written;
96} TDSDATAOUTSTREAM;
97
98void tds_dataout_stream_init(TDSDATAOUTSTREAM * stream, TDSSOCKET * tds);
99
101 typedef struct tds_staticin_stream {
102 TDSINSTREAM stream;
103 const char *buffer;
104 size_t buf_left;
105} TDSSTATICINSTREAM;
106
107void tds_staticin_stream_init(TDSSTATICINSTREAM * stream, const void *ptr, size_t len);
108
112 typedef struct tds_staticout_stream {
113 TDSOUTSTREAM stream;
114} TDSSTATICOUTSTREAM;
115
116void tds_staticout_stream_init(TDSSTATICOUTSTREAM * stream, void *ptr, size_t len);
117
119 typedef struct tds_dynamic_stream {
120 TDSOUTSTREAM stream;
122 void **buf;
124 size_t allocated;
126 size_t size;
127} TDSDYNAMICSTREAM;
128
129TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM * stream, void **ptr, size_t allocated);
130
131/* input stream to read a file with option to terminate the read
132 * when a delimiter sequence is read
133 */
134 typedef struct tds_file_stream
135{
137 TDSINSTREAM stream;
138
140 FILE *f;
141
145 char *cbuf;
147 size_t cpos;
148
150 size_t term_len;
151} TDSFILESTREAM;
152
153TDSRET tds_file_stream_init(TDSFILESTREAM * stream, FILE * f);
154TDSRET tds_file_stream_set_terminator(TDSFILESTREAM * stream, const char *term, size_t term_len);
155TDSRET tds_file_stream_destroy(TDSFILESTREAM * stream);
156
157#include <freetds/popvis.h>
158
159#endif
tds_file_stream_set_terminator
TDSRET tds_file_stream_set_terminator(TDSFILESTREAM *stream, const char *term, size_t term_len)
Sets the terminator and also performs an initial population of the circular buffer.
Definition bulk.c:1488
tds_socket
Information for a server connection.
Definition tds.h:1190
tdsiconvinfo
Definition iconv.h:98
tds_input_stream
define a stream of data used for input
Definition stream.h:32
tds_input_stream::read
int(* read)(struct tds_input_stream *stream, void *ptr, size_t len)
read some data Return 0 if end of stream Return <0 if error (actually not defined)
Definition stream.h:37
tds_output_stream
define a stream of data used for output
Definition stream.h:41
tds_output_stream::buffer
char * buffer
write buffer.
Definition stream.h:52
tds_output_stream::write
int(* write)(struct tds_output_stream *stream, size_t len)
write len bytes from buffer, return <0 if error or len
Definition stream.h:43
tds_fileout_stream
Output stream that writes to file.
Definition stream.h:60
tds_fileout_stream::buff_mode
int buff_mode
How to buffer the data – _IONBF, _IOLBF or _IOFBF (default).
Definition stream.h:66
tds_datain_stream
input stream to read data from tds protocol
Definition stream.h:83
tds_datain_stream::wire_size
size_t wire_size
bytes still to read
Definition stream.h:85
tds_dataout_stream
output stream to write data to tds protocol
Definition stream.h:92
tds_staticin_stream
input stream to read data from a static buffer
Definition stream.h:101
tds_staticout_stream
output stream to write data to a static buffer.
Definition stream.h:112
tds_dynamic_stream
output stream to write data to a dynamic buffer
Definition stream.h:119
tds_dynamic_stream::buf
void ** buf
where is stored the pointer
Definition stream.h:122
tds_dynamic_stream::size
size_t size
size of data inside buffer
Definition stream.h:126
tds_dynamic_stream::allocated
size_t allocated
currently allocated buffer
Definition stream.h:124
tds_file_stream
Definition stream.h:135
tds_file_stream::cbuf
char * cbuf
Circular input buffer followed by 2 copies of the terminator so that we can easily "memcmp" the circu...
Definition stream.h:145
tds_file_stream::f
FILE * f
file to read from
Definition stream.h:140
tds_file_stream::term_len
size_t term_len
terminator length in bytes – cbuf length is 3*term_len
Definition stream.h:150
tds_file_stream::stream
TDSINSTREAM stream
common fields, must be the first field
Definition stream.h:137
tds_file_stream::cpos
size_t cpos
Offset in circular buffer of last-read character.
Definition stream.h:147
tds_dynamic_stream_init
TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM *stream, void **ptr, size_t allocated)
Initialize a dynamic output stream.
Definition stream.c:354
tds_copy_stream
TDSRET tds_copy_stream(TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream to another.
Definition stream.c:163
tds_convert_stream
TDSRET tds_convert_stream(TDSSOCKET *tds, TDSICONV *char_conv, TDS_ICONV_DIRECTION direction, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream converting characters.
Definition stream.c:71
tds_staticout_stream_init
void tds_staticout_stream_init(TDSSTATICOUTSTREAM *stream, void *ptr, size_t len)
Initialize an output stream for write into a static allocated buffer.
Definition stream.c:313
tds_dataout_stream_init
void tds_dataout_stream_init(TDSDATAOUTSTREAM *stream, TDSSOCKET *tds)
Initialize a data output stream.
Definition stream.c:244
tds_staticin_stream_init
void tds_staticin_stream_init(TDSSTATICINSTREAM *stream, const void *ptr, size_t len)
Initialize an input stream for read from a static allocated buffer.
Definition stream.c:286
tds_datain_stream_init
void tds_datain_stream_init(TDSDATAINSTREAM *stream, TDSSOCKET *tds, size_t wire_size)
Initialize a data input stream.
Definition stream.c:204