| 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 The function which will report the size of the full pdu. |
| 25 |
* |
| 26 |
* @param[in] stream The tstream_context to operate on |
| 27 |
* |
| 28 |
* @param[in] private_data Some private data which could be used. |
| 29 |
* |
| 30 |
* @param[in] blob The received blob to get the size from. |
| 31 |
* |
| 32 |
* @param[out] packet_size The pointer to store the size of the full pdu. |
| 33 |
* |
| 34 |
* @return NT_STATUS_OK on success, STATUS_MORE_ENTRIES if there |
| 35 |
* are more entries. |
| 36 |
*/ |
| 37 |
typedef NTSTATUS tstream_read_pdu_blob_full_fn_t(struct tstream_context *stream, |
| 38 |
void *private_data, |
| 39 |
DATA_BLOB blob, |
| 40 |
size_t *packet_size); |
| 41 |
|
| 42 |
/** |
| 43 |
* @brief A helper function to read a full PDU from a stream |
| 44 |
* |
| 45 |
* This function is designed for simple PDUs and as compat layer |
| 46 |
* for the Samba4 packet interface. |
| 47 |
* |
| 48 |
* tstream_readv_pdu_send() is a more powerful interface, |
| 49 |
* which is part of the main (non samba specific) tsocket code. |
| 50 |
* |
| 51 |
* @param[in] mem_ctx The memory context for the result. |
| 52 |
* |
| 53 |
* @param[in] ev The event context the operation should work on. |
| 54 |
* |
| 55 |
* @param[in] stream The stream to read data from. |
| 56 |
* |
| 57 |
* @param[in] initial_read_size The initial byte count that is needed to workout |
| 58 |
* the full pdu size. |
| 59 |
* |
| 60 |
* @param[in] full_fn The callback function that will report the size |
| 61 |
* of the full pdu. |
| 62 |
* |
| 63 |
* @param[in] full_private The private data for the callback function. |
| 64 |
* |
| 65 |
* @return The async request handle. NULL on fatal error. |
| 66 |
* |
| 67 |
* @see tstream_read_pdu_blob_recv() |
| 68 |
* @see tstream_readv_pdu_send() |
| 69 |
* @see tstream_readv_pdu_queue_send() |
| 70 |
* |
| 71 |
*/ |
| 72 |
struct tevent_req *tstream_read_pdu_blob_send(TALLOC_CTX *mem_ctx, |
| 73 |
struct tevent_context *ev, |
| 74 |
struct tstream_context *stream, |
| 75 |
size_t initial_read_size, |
| 76 |
tstream_read_pdu_blob_full_fn_t *full_fn, |
| 77 |
void *full_private); |
| 78 |
/** |
| 79 |
* @brief Receive the result of the tstream_read_pdu_blob_send() call. |
| 80 |
* |
| 81 |
* @param[in] req The tevent request from tstream_read_pdu_blob_send(). |
| 82 |
* |
| 83 |
* @param[in] mem_ctx The memory context for returned pdu DATA_BLOB. |
| 84 |
* |
| 85 |
* @param[in] pdu_blob The DATA_BLOB with the full pdu. |
| 86 |
* |
| 87 |
* @return The NTSTATUS result, NT_STATUS_OK on success |
| 88 |
* and others on failure. |
| 89 |
* |
| 90 |
* @see tstream_read_pdu_blob_send() |
| 91 |
*/ |
| 92 |
NTSTATUS tstream_read_pdu_blob_recv(struct tevent_req *req, |
| 93 |
TALLOC_CTX *mem_ctx, |
| 94 |
DATA_BLOB *pdu_blob); |
| 95 |
|
| 96 |
/** |
| 97 |
* @brief Get a PDU size with a 32 bit size header field |
| 98 |
* |
| 99 |
* Work out if a packet is complete for protocols that use a 32 bit |
| 100 |
* network byte order length. |
| 101 |
* |
| 102 |
* @see tstream_read_pdu_blob_send() |
| 103 |
* @see tstream_read_pdu_blob_recv() |
| 104 |
*/ |
| 105 |
NTSTATUS tstream_full_request_u32(struct tstream_context *stream, |
| 106 |
void *private_data, |
| 107 |
DATA_BLOB blob, size_t *size); |
| 108 |
|
| 109 |
/** |
| 110 |
* @brief Get a PDU size with a 16 bit size header field |
| 111 |
* |
| 112 |
* Work out if a packet is complete for protocols that use a 16 bit |
| 113 |
* network byte order length. |
| 114 |
* |
| 115 |
* @see tstream_read_pdu_blob_send() |
| 116 |
* @see tstream_read_pdu_blob_recv() |
| 117 |
*/ |
| 118 |
NTSTATUS tstream_full_request_u16(struct tstream_context *stream, |
| 119 |
void *private_data, |
| 120 |
DATA_BLOB blob, size_t *size); |
| 121 |
|
| 122 |
|
| 123 |
#endif /* _LIBCLI_UTIL_TSTREAM_H_ */ |