File: Buffer.h

package info (click to toggle)
mysecureshell 2.00%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 888 kB
  • sloc: ansic: 7,421; sh: 700; perl: 264; makefile: 116
file content (75 lines) | stat: -rw-r--r-- 2,717 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
MySecureShell permit to add restriction to modified sftp-server
when using MySecureShell as shell.
Copyright (C) 2007-2014 MySecureShell Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation (version 2)

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _BUFFER_H_
#define _BUFFER_H_

#include "Sftp.h"

typedef struct	sBuffer
{
  unsigned char	*data;
  u_int32_t	length;
  u_int32_t	read;
  u_int32_t	size;
  u_int32_t	fastClean;
}		tBuffer;

#define	DEFAULT_GROW		256
#define	BufferHandleSize	6 //sizeof(int32) + 1 char + '\0'

/*@null@*/ tBuffer	*BufferNew();
void	BufferClean(tBuffer *b);
void	BufferDelete(tBuffer *b);
void	BufferGrow(tBuffer *b, u_int32_t toAdd);
void	BufferReadData(tBuffer *b, u_int32_t size);

void	BufferPutInt8(tBuffer *b, u_int8_t nb);
void	BufferPutInt16(tBuffer *b, u_int16_t nb);
void	BufferPutInt32(tBuffer *b, u_int32_t nb);
void	BufferPutInt64(tBuffer *b, u_int64_t nb);
void	BufferPutHandle(tBuffer *b, int h);
void	BufferPutString(tBuffer *b, const char *data);
void	BufferPutRawData(tBuffer *b, const void *data, u_int32_t size);

u_int8_t	BufferGetInt8(tBuffer *b);
u_int32_t	BufferGetInt32(tBuffer *b);
u_int64_t	BufferGetInt64(tBuffer *b);
int		BufferGetHandle(tBuffer *b);
char		*BufferGetString(tBuffer *b);
char		*BufferGetData(tBuffer *b, u_int32_t *size);

#define BufferSetFastClean(_D, _STATE) (_D)->fastClean = _STATE
#define BufferEnsureFreeCapacity(_D, _INT32) { if (((_D)->length + _INT32) > (_D)->size) BufferGrow(_D, _INT32); }

#define BufferPutData(_D, _DATA, _SIZE) { BufferPutInt32(_D, _SIZE); BufferPutRawData(_D, _DATA, _SIZE); }
#define BufferPutPacket(_D, _S)	BufferPutData((_D), (_S)->data, (_S)->length)

#define BufferPutInt8FAST(_D, _INT8) (_D)->data[(_D)->length++] = _INT8;
#define BufferGetInt8FAST(_D) (u_int8_t )(_D)->data[(_D)->read++]


#define BufferGetReadPointer(_D) &(_D)->data[(_D)->read]
#define BufferIncrCurrentReadPosition(_D, _V) (_D)->read += _V
#define BufferGetWritePointer(_D) &(_D)->data[(_D)->length]
#define BufferGetCurrentWritePosition(_D) (_D)->length
#define BufferSetCurrentWritePosition(_D, _V) (_D)->length = _V
#define BufferIncrCurrentWritePosition(_D, _V) (_D)->length += _V

#endif //_BUFFER_H_