1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | Packet handling
|
---|
4 | Copyright (C) Volker Lendecke 2007
|
---|
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 | /*
|
---|
21 | * A packet context is a wrapper around a bidirectional file descriptor,
|
---|
22 | * hiding the handling of individual requests.
|
---|
23 | */
|
---|
24 |
|
---|
25 | struct packet_context;
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * Initialize a packet context. The fd is given to the packet context, meaning
|
---|
29 | * that it is automatically closed when the packet context is freed.
|
---|
30 | */
|
---|
31 | struct packet_context *packet_init(TALLOC_CTX *mem_ctx, int fd);
|
---|
32 |
|
---|
33 | /*
|
---|
34 | * Pull data from the fd
|
---|
35 | */
|
---|
36 | NTSTATUS packet_fd_read(struct packet_context *ctx);
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Sync read, wait for the next chunk
|
---|
40 | */
|
---|
41 | NTSTATUS packet_fd_read_sync(struct packet_context *ctx,
|
---|
42 | struct timeval *timeout);
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * Handle an incoming packet:
|
---|
46 | * Return False if none is available
|
---|
47 | * Otherwise return True and store the callback result in *status
|
---|
48 | * Callback must either talloc_move or talloc_free buf
|
---|
49 | */
|
---|
50 | bool packet_handler(struct packet_context *ctx,
|
---|
51 | bool (*full_req)(const uint8_t *buf,
|
---|
52 | size_t available,
|
---|
53 | size_t *length,
|
---|
54 | void *private_data),
|
---|
55 | NTSTATUS (*callback)(uint8_t *buf, size_t length,
|
---|
56 | void *private_data),
|
---|
57 | void *private_data,
|
---|
58 | NTSTATUS *status);
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * How many bytes of outgoing data do we have pending?
|
---|
62 | */
|
---|
63 | size_t packet_outgoing_bytes(struct packet_context *ctx);
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Push data to the fd
|
---|
67 | */
|
---|
68 | NTSTATUS packet_fd_write(struct packet_context *ctx);
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * Sync flush all outgoing bytes
|
---|
72 | */
|
---|
73 | NTSTATUS packet_flush(struct packet_context *ctx);
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Send a list of DATA_BLOBs
|
---|
77 | *
|
---|
78 | * Example: packet_send(ctx, 2, data_blob_const(&size, sizeof(size)),
|
---|
79 | * data_blob_const(buf, size));
|
---|
80 | */
|
---|
81 | NTSTATUS packet_send(struct packet_context *ctx, int num_blobs, ...);
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * Get the packet context's file descriptor
|
---|
85 | */
|
---|
86 | int packet_get_fd(struct packet_context *ctx);
|
---|