summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-05-10 12:58:06 +0800
committerIru Cai <mytbk920423@gmail.com>2018-05-10 14:16:42 +0800
commit4937c80cb0b5747fe5983d24c83fc61c796b6882 (patch)
tree9f08957117c5cfb2db9f4fbf6e1070696cbe52d6
parentee01dfc0653ab814bc56eb7ad84a62b6bf162060 (diff)
downloadfqterm-4937c80cb0b5747fe5983d24c83fc61c796b6882.tar.xz
kill FQTermSSHBuffer
-rw-r--r--src/protocol/CMakeLists.txt2
-rw-r--r--src/protocol/internal/buffer.h2
-rw-r--r--src/protocol/internal/fqterm_ssh1_packet.cpp1
-rw-r--r--src/protocol/internal/fqterm_ssh2_packet.cpp1
-rw-r--r--src/protocol/internal/fqterm_ssh_buffer.cpp258
-rw-r--r--src/protocol/internal/fqterm_ssh_buffer.h80
-rw-r--r--src/protocol/internal/fqterm_ssh_packet.cpp1
-rw-r--r--src/protocol/internal/fqterm_ssh_packet.h1
8 files changed, 2 insertions, 344 deletions
diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt
index 7a3ad8e..5c98fa7 100644
--- a/src/protocol/CMakeLists.txt
+++ b/src/protocol/CMakeLists.txt
@@ -29,7 +29,6 @@ set(internal_SRCS
internal/crc32.h
internal/fqterm_serialization.h
internal/fqterm_ssh_auth.h
- internal/fqterm_ssh_buffer.h
internal/fqterm_ssh_const.h
internal/fqterm_ssh_kex.h
internal/fqterm_ssh2_kex.h
@@ -40,7 +39,6 @@ set(internal_SRCS
internal/fqterm_ssh_types.h
internal/crc32.cpp
internal/fqterm_ssh_auth.cpp
- internal/fqterm_ssh_buffer.cpp
internal/fqterm_ssh_kex.cpp
internal/fqterm_ssh2_kex.cpp
internal/fqterm_ssh_packet.cpp
diff --git a/src/protocol/internal/buffer.h b/src/protocol/internal/buffer.h
index 971f21c..0e0b635 100644
--- a/src/protocol/internal/buffer.h
+++ b/src/protocol/internal/buffer.h
@@ -24,6 +24,8 @@
#include <stdint.h>
#include <string.h>
+#define SSH_BUFFER_MAX 10000000
+
#ifdef __cplusplus
extern "C" {
#endif /* } */
diff --git a/src/protocol/internal/fqterm_ssh1_packet.cpp b/src/protocol/internal/fqterm_ssh1_packet.cpp
index 4398e3f..5c2ed46 100644
--- a/src/protocol/internal/fqterm_ssh1_packet.cpp
+++ b/src/protocol/internal/fqterm_ssh1_packet.cpp
@@ -19,7 +19,6 @@
***************************************************************************/
#include "fqterm_trace.h"
-#include "fqterm_ssh_buffer.h"
#include "fqterm_ssh1_packet.h"
#include "fqterm_serialization.h"
diff --git a/src/protocol/internal/fqterm_ssh2_packet.cpp b/src/protocol/internal/fqterm_ssh2_packet.cpp
index 0069c84..983ad3c 100644
--- a/src/protocol/internal/fqterm_ssh2_packet.cpp
+++ b/src/protocol/internal/fqterm_ssh2_packet.cpp
@@ -19,7 +19,6 @@
***************************************************************************/
#include "fqterm_trace.h"
-#include "fqterm_ssh_buffer.h"
#include "fqterm_ssh2_packet.h"
#include "fqterm_serialization.h"
diff --git a/src/protocol/internal/fqterm_ssh_buffer.cpp b/src/protocol/internal/fqterm_ssh_buffer.cpp
deleted file mode 100644
index 9775891..0000000
--- a/src/protocol/internal/fqterm_ssh_buffer.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/***************************************************************************
- * fqterm, a terminal emulator for both BBS and *nix. *
- * Copyright (C) 2008 fqterm development group. *
- * *
- * 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; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * 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., *
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. *
- ***************************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <vector>
-
-#include "fqterm_trace.h"
-#include "fqterm_ssh_buffer.h"
-#include "fqterm_serialization.h"
-
-namespace FQTerm {
-//==============================================================================
-// FQTermSSHBuffer
-//==============================================================================
-
-FQTermSSHBuffer::FQTermSSHBuffer(int size) {
- alloc_size_ = size;
- buffer_size_ = 0;
- offset_ = 0;
- buffer_ = new u_char[alloc_size_];
-}
-
-FQTermSSHBuffer::~FQTermSSHBuffer() {
- delete [] buffer_;
- offset_ = 0;
- buffer_size_ = 0;
- alloc_size_ = 0;
-}
-
-void FQTermSSHBuffer::ensure(int len) {
- if (len <= (alloc_size_ - (offset_ + buffer_size_))) {
- return ;
- } else {
- alloc_size_ = buffer_size_ + len;
- rebuffer();
- }
-}
-
-void FQTermSSHBuffer::rebuffer() {
- u_char *newBuffer;
- newBuffer = new u_char[alloc_size_];
- memset(newBuffer, 0, alloc_size_);
- memcpy(newBuffer, buffer_ + offset_, buffer_size_);
- delete [] buffer_;
- buffer_ = newBuffer;
- offset_ = 0;
-}
-
-void FQTermSSHBuffer::clear() {
- memset(buffer_, 0, alloc_size_);
- offset_ = 0;
- buffer_size_ = 0;
-}
-
-void FQTermSSHBuffer::consume(int len) {
- if (len > buffer_size_) {
- len = buffer_size_;
- }
-
- offset_ += len;
- buffer_size_ -= len;
-}
-
-void FQTermSSHBuffer::putRawData(const char *data, int len) {
- if (len < 0) {
- FQ_TRACE("sshbuffer", 0) << "Write data error.";
- }
-
- ensure(len);
- memcpy((buffer_ + offset_ + buffer_size_), data, len);
- buffer_size_ += len;
-}
-
-void FQTermSSHBuffer::getRawData(char *data, int len) {
- if (len <= buffer_size_ && len >= 0) {
- memcpy(data, buffer_ + offset_, len);
- consume(len);
- } else {
- FQ_TRACE("sshbuffer", 0) << "Read too many data: " << len << " bytes.";
- }
-}
-
-//==============================================================================
-// Store an BIGNUM in the buffer with a 2-byte msb first bit count, followed by
-// (bits+7)/8 bytes of binary data, msb first.
-//==============================================================================
-
-void FQTermSSHBuffer::putSSH1BN(BIGNUM *bignum) {
- int bits = BN_num_bits(bignum);
- int bin_size = (bits + 7) / 8;
- u_char *buf = new u_char[bin_size];
- int oi;
- u_char msg[2];
-
- // Get the value of in binary
- oi = BN_bn2bin(bignum, buf);
- if (oi != bin_size) {
- FQ_TRACE("sshbuffer", 0) << "BN_bn2bin() failed: oi = " << oi
- << " != bin_size." << bin_size;
- }
-
- // Store the number of bits in the buffer in two bytes, msb first
- htonu16(msg, bits);
- putRawData((char*)msg, 2);
- // Store the binary data.
- putRawData((char*)buf, oi);
-
- memset(buf, 0, bin_size);
- delete [] buf;
-}
-
-//==============================================================================
-// Retrieves a BIGNUM from the buffer.
-//==============================================================================
-
-void FQTermSSHBuffer::getSSH1BN(BIGNUM *bignum) {
- int bits, bytes;
- u_char buf[2];
- u_char *bin;
-
- // Get the number for bits.
- getRawData((char*)buf, 2);
- bits = ntohu16(buf);
- // Compute the number of binary bytes that follow.
- bytes = (bits + 7) / 8;
- if (bytes > 8 *1024) {
- FQ_TRACE("sshbuffer", 0) << "Can't handle BN of size " << bytes;
- return ;
- }
- if (len() < bytes) {
- FQ_TRACE("sshbuffer", 0) << "The input buffer is too small.";
- return ;
- }
- bin = data();
- BN_bin2bn(bin, bytes, bignum);
- consume(bytes);
-}
-
-u_short FQTermSSHBuffer::getWord() {
- u_char buf[2];
- u_short data;
-
- getRawData((char*)buf, 2);
- data = ntohu16(buf);
- return data;
-}
-
-void FQTermSSHBuffer::putWord(u_short data) {
- u_char buf[2];
-
- htonu16(buf, data);
- putRawData((char*)buf, 2);
-}
-
-u_int FQTermSSHBuffer::getInt() {
- u_char buf[4];
- u_int data;
- getRawData((char*)buf, 4);
- data = ntohu32(buf);
- return data;
-}
-
-void FQTermSSHBuffer::putInt(u_int data) {
- u_char buf[4];
-
- htonu32(buf, data);
- putRawData((char*)buf, 4);
-}
-
-//==============================================================================
-// Return a character from the buffer (0-255).
-//==============================================================================
-
-u_char FQTermSSHBuffer::getByte() {
- u_char ch;
-
- getRawData((char*) &ch, 1);
- return ch;
-}
-
-//==============================================================================
-// Stores a character in the buffer.
-//==============================================================================
-
-void FQTermSSHBuffer::putByte(int data) {
- u_char ch = data;
-
- putRawData((char*) &ch, 1);
-}
-
-//==============================================================================
-// Stores an arbitrary binary string in the buffer.
-//==============================================================================
-
-void FQTermSSHBuffer::putString(const char *str, int len) {
- if (str == NULL) {
- FQ_TRACE("sshbuffer", 0) << "Can't put a null pointer string.";
- return ;
- }
-
- if (len < 0) {
- len = strlen(str);
- }
-
- putInt(len);
- putRawData(str, len);
-}
-
-//==============================================================================
-// Return an arbitrary binary string from the buffer. The string cannot be
-// longer than 256k. The returned value points to memory allocated with new;
-// It is the responsibility of the calling function to free the data.
-//==============================================================================
-
-void *FQTermSSHBuffer::getString(int *length) {
- u_char *data;
- u_int len;
-
- // Get the length.
- len = getInt();
- if ((long)len > buffer_size_) {
- FQ_TRACE("sshbuffer", 0)
- << "String length " << len
- << " is greater than buffer size " << buffer_size_;
- return 0;
- }
- // Allocate space for the string. Add one byte for a null character.
- data = new u_char[len + 1];
- // Get the string.
- getRawData((char*)data, len);
- // Append a null character to make processing easier.
- data[len] = 0;
- if (length != NULL) {
- *length = len;
- }
- // return the length of the string.
- return data;
-}
-
-} // namespace FQTerm
diff --git a/src/protocol/internal/fqterm_ssh_buffer.h b/src/protocol/internal/fqterm_ssh_buffer.h
deleted file mode 100644
index 0525557..0000000
--- a/src/protocol/internal/fqterm_ssh_buffer.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/***************************************************************************
- * fqterm, a terminal emulator for both BBS and *nix. *
- * Copyright (C) 2008 fqterm development group. *
- * *
- * 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; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * 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., *
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. *
- ***************************************************************************/
-
-#ifndef FQTERM_SSH_BUFFER_H
-#define FQTERM_SSH_BUFFER_H
-
-#include <openssl/bn.h>
-#include <string.h>
-
-#include "fqterm_ssh_types.h"
-
-namespace FQTerm {
-
-#define SSH_BUFFER_MAX 10000000
-
-class FQTermSSHBuffer {
- private:
- u_char *buffer_;
- int offset_;
- int buffer_size_;
- int alloc_size_;
-
- void ensure(int len);
- void rebuffer();
-
- public:
- FQTermSSHBuffer(int size);
- ~FQTermSSHBuffer();
-
- u_char *data() const {
- return buffer_ + offset_;
- }
-
- int len() const {
- return buffer_size_;
- }
-
- void consume(int len);
-
- void clear();
-
- void putRawData(const char *data, int len);
- void getRawData(char *data, int len);
-
- void putSSH1BN(BIGNUM *bignum);
- void getSSH1BN(BIGNUM *bignum);
-
- void putInt(u_int data);
- u_int getInt();
-
- void putWord(u_short data);
- u_short getWord();
-
- void putByte(int data);
- u_char getByte();
-
- void putString(const char *str, int len = -1);
- void *getString(int *length = NULL);
-};
-
-} // namespace FQTerm
-
-#endif //FQTERM_SSH_BUFFER
diff --git a/src/protocol/internal/fqterm_ssh_packet.cpp b/src/protocol/internal/fqterm_ssh_packet.cpp
index 5db2385..af6bbc8 100644
--- a/src/protocol/internal/fqterm_ssh_packet.cpp
+++ b/src/protocol/internal/fqterm_ssh_packet.cpp
@@ -19,7 +19,6 @@
***************************************************************************/
#include "fqterm_trace.h"
-#include "fqterm_ssh_buffer.h"
#include "fqterm_ssh_packet.h"
#include "fqterm_ssh_const.h"
diff --git a/src/protocol/internal/fqterm_ssh_packet.h b/src/protocol/internal/fqterm_ssh_packet.h
index edc031f..806918e 100644
--- a/src/protocol/internal/fqterm_ssh_packet.h
+++ b/src/protocol/internal/fqterm_ssh_packet.h
@@ -26,7 +26,6 @@
#include <QObject>
#include "fqterm_ssh_types.h"
-#include "fqterm_ssh_buffer.h"
#include "ssh_mac.h"
#include "fqterm_serialization.h"
#include "ssh_cipher.h"