libcli/util: add tstream_read_pdu_blob_send/recv
[abartlet/samba.git/.git] / libcli / util / tstream.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *
4  *  Copyright (C) Stefan Metzmacher 2009
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef _LIBCLI_UTIL_TSTREAM_H_
21 #define _LIBCLI_UTIL_TSTREAM_H_
22
23 /**
24  * @brief A helper function to read a full PDU from a stream
25  *
26  * This function is designed for simple PDUs and as compat layer
27  * for the Samba4 packet interface.
28  *
29  * tstream_readv_pdu_send() is a more powerful interface,
30  * which is part of the main (non samba specific) tsocket code.
31  *
32  * @param[in] mem_ctx           The memory context for the result.
33  *
34  * @param[in] ev                The event context the operation should work on.
35  *
36  * @param[in] stream            The stream to read data from.
37  *
38  * @param[in] inital_read_size  The initial byte count that is needed to workout
39  *                              the full pdu size.
40  *
41  * @param[in] full_fn           The callback function that will report the size
42  *                              of the full pdu.
43  *
44  * @param[in] full_private      The private data for the callback function.
45  *
46  * @return                      The async request handle. NULL on fatal error.
47  *
48  * @see tstream_read_pdu_blob_recv()
49  * @see tstream_readv_pdu_send()
50  * @see tstream_readv_pdu_queue_send()
51  *
52  */
53 struct tevent_req *tstream_read_pdu_blob_send(TALLOC_CTX *mem_ctx,
54                                 struct tevent_context *ev,
55                                 struct tstream_context *stream,
56                                 size_t inital_read_size,
57                                 NTSTATUS (*full_fn)(void *private_data,
58                                                     DATA_BLOB blob,
59                                                     size_t *packet_size),
60                                 void *full_private);
61 /**
62  * @brief Receive the result of the tstream_read_pdu_blob_send() call.
63  *
64  * @param[in] req       The tevent request from tstream_read_pdu_blob_send().
65  *
66  * @param[in] mem_ctx   The memory context for returned pdu DATA_BLOB.
67  *
68  * @param[in] pdu_blob  The DATA_BLOB with the full pdu.
69  *
70  * @return              The NTSTATUS result, NT_STATUS_OK on success
71  *                      and others on failure.
72  *
73  * @see tstream_read_pdu_blob_send()
74  */
75 NTSTATUS tstream_read_pdu_blob_recv(struct tevent_req *req,
76                                     TALLOC_CTX *mem_ctx,
77                                     DATA_BLOB *pdu_blob);
78
79 #endif /* _LIBCLI_UTIL_TSTREAM_H_ */