libssh: buffer.h Source File

libssh 0.10.4 The SSH library

buffer.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef BUFFER_H_
22#define BUFFER_H_
23
24#include <stdarg.h>
25
26#include "libssh/libssh.h"
27
28#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
29
30void ssh_buffer_set_secure(ssh_buffer buffer);
31int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
32int ssh_buffer_add_u8(ssh_buffer buffer, uint8_t data);
33int ssh_buffer_add_u16(ssh_buffer buffer, uint16_t data);
34int ssh_buffer_add_u32(ssh_buffer buffer, uint32_t data);
35int ssh_buffer_add_u64(ssh_buffer buffer, uint64_t data);
36
37int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len);
38
39void *ssh_buffer_allocate(struct ssh_buffer_struct *buffer, uint32_t len);
40int ssh_buffer_allocate_size(struct ssh_buffer_struct *buffer, uint32_t len);
41int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
42 const char *format,
43 size_t argc,
44 va_list ap);
45int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
46 const char *format,
47 size_t argc,
48 ...);
49#define ssh_buffer_pack(buffer, format, ...) \
50 _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
51
52int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
53 const char *format, size_t argc,
54 va_list ap);
55int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
56 const char *format,
57 size_t argc,
58 ...);
59#define ssh_buffer_unpack(buffer, format, ...) \
60 _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
61
62int ssh_buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
63int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
64
65/* buffer_read_*() returns the number of bytes read, except for ssh strings */
66uint32_t ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
67uint32_t ssh_buffer_get_u32(ssh_buffer buffer, uint32_t *data);
68uint32_t ssh_buffer_get_u64(ssh_buffer buffer, uint64_t *data);
69
70/* ssh_buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
71 ssh_string ssh_buffer_get_ssh_string(ssh_buffer buffer);
72
73/* ssh_buffer_pass_bytes acts as if len bytes have been read (used for padding) */
74uint32_t ssh_buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
75uint32_t ssh_buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
76
77#endif /* BUFFER_H_ */
ssh_buffer_validate_length
int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len)
Validates that the given length can be obtained from the buffer.
Definition: buffer.c:748
ssh_buffer_allocate_size
int ssh_buffer_allocate_size(struct ssh_buffer_struct *buffer, uint32_t len)
Ensure the buffer has at least a certain preallocated size.
Definition: buffer.c:340
ssh_buffer_set_secure
void ssh_buffer_set_secure(ssh_buffer buffer)
Sets the buffer as secure.
Definition: buffer.c:176
ssh_buffer_struct
Definition: buffer.c:47
ssh_string_struct
Definition: string.h:29