libssh 0.4.8
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2009 by Aris Adamantiadis 00005 * 00006 * The SSH Library is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * The SSH Library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with the SSH Library; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 * MA 02111-1307, USA. 00020 */ 00021 00022 #ifndef BUFFER_H_ 00023 #define BUFFER_H_ 00024 00025 /* Describes a buffer state */ 00026 struct ssh_buffer_struct { 00027 char *data; 00028 uint32_t used; 00029 uint32_t allocated; 00030 uint32_t pos; 00031 }; 00032 00033 int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string); 00034 int buffer_add_u8(ssh_buffer buffer, uint8_t data); 00035 int buffer_add_u16(ssh_buffer buffer, uint16_t data); 00036 int buffer_add_u32(ssh_buffer buffer, uint32_t data); 00037 int buffer_add_u64(ssh_buffer buffer, uint64_t data); 00038 int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len); 00039 int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len); 00040 int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source); 00041 int buffer_reinit(ssh_buffer buffer); 00042 00043 /* buffer_get_rest returns a pointer to the current position into the buffer */ 00044 void *buffer_get_rest(ssh_buffer buffer); 00045 /* buffer_get_rest_len returns the number of bytes which can be read */ 00046 uint32_t buffer_get_rest_len(ssh_buffer buffer); 00047 00048 /* buffer_read_*() returns the number of bytes read, except for ssh strings */ 00049 int buffer_get_u8(ssh_buffer buffer, uint8_t *data); 00050 int buffer_get_u32(ssh_buffer buffer, uint32_t *data); 00051 int buffer_get_u64(ssh_buffer buffer, uint64_t *data); 00052 00053 uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen); 00054 /* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */ 00055 ssh_string buffer_get_ssh_string(ssh_buffer buffer); 00056 /* gets a string out of a SSH-1 mpint */ 00057 ssh_string buffer_get_mpint(ssh_buffer buffer); 00058 /* buffer_pass_bytes acts as if len bytes have been read (used for padding) */ 00059 uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len); 00060 uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len); 00061 00062 #endif /* BUFFER_H_ */