• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

include/libssh/buffer.h

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 #include "libssh/libssh.h"
00026 /*
00027  * Describes a buffer state
00028  * [XXXXXXXXXXXXDATA PAYLOAD       XXXXXXXXXXXXXXXXXXXXXXXX]
00029  * ^            ^                  ^                       ^]
00030  * \_data points\_pos points here  \_used points here |    /
00031  *   here                                          Allocated
00032  */
00033 struct ssh_buffer_struct {
00034     char *data;
00035     uint32_t used;
00036     uint32_t allocated;
00037     uint32_t pos;
00038 };
00039 
00040 LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
00041 LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
00042 LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
00043 LIBSSH_API ssh_buffer ssh_buffer_new(void);
00044 int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
00045 int buffer_add_u8(ssh_buffer buffer, uint8_t data);
00046 int buffer_add_u16(ssh_buffer buffer, uint16_t data);
00047 int buffer_add_u32(ssh_buffer buffer, uint32_t data);
00048 int buffer_add_u64(ssh_buffer buffer, uint64_t data);
00049 int buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
00050 int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
00051 int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
00052 int buffer_reinit(ssh_buffer buffer);
00053 
00054 /* buffer_get_rest returns a pointer to the current position into the buffer */
00055 void *buffer_get_rest(ssh_buffer buffer);
00056 /* buffer_get_rest_len returns the number of bytes which can be read */
00057 uint32_t buffer_get_rest_len(ssh_buffer buffer);
00058 
00059 /* buffer_read_*() returns the number of bytes read, except for ssh strings */
00060 int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
00061 int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
00062 int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
00063 
00064 uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
00065 /* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
00066 ssh_string buffer_get_ssh_string(ssh_buffer buffer);
00067 /* gets a string out of a SSH-1 mpint */
00068 ssh_string buffer_get_mpint(ssh_buffer buffer);
00069 /* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
00070 uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
00071 uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
00072 
00073 #endif /* BUFFER_H_ */

Generated by  doxygen 1.7.1