Subject: spring cleaning step #1

spring cleaning step #1

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 17 Apr 2010 13:08:30 +0200 (CEST)

Hey

I started going through the clang-analyzer report Joachim Strömbergson posted,
only to realize that a bunch of the warnings there are artifacts of some
internal designs we could fix up all over. So I decided I'll postpone analyzer
work and do some general cleanups first.

I'll introduce a new internal function set named

  _libssh2_store_u32
  _libssh2_store_u64
  _libssh2_store_str

That can be used all through the library to build binary outgoing packets.
Using these instead of the current approach removes hundreds of lines from
the library while at the same time greatly enhances readability. I've not yet
fully converted everything to use these functions.

I've converted LOTS of 'unsigned long' to 'size_t' where data/string lengths
are dealt with internally. This is The Right Thing and it will help us make
the transition to our size_t-polished API later on as well.

I'm removing the PACKET_* error codes. They were originally introduced as a
set of separate error codes from the transport layer, but having its own set
of errors turned out to be very awkward and they were then converted into a
set of #defines that simply maps them to the global libssh2 error codes
instead. Now, I'l take the next logical step and simply replace the PACKET_*
defines with the actual LIBSSH2_ERROR_* defines. It will increase readability
and decrease confusion.

I'll appreciate some extra eyeballs on the builds after I've pushed this
monster:

$ git diff --stat
  Makefile.inc | 2 +-
  src/agent.c | 20 ++--
  src/channel.c | 280 ++++++++++++++++-------------------------------
  src/hostkey.c | 20 ++--
  src/keepalive.c | 2 +-
  src/kex.c | 28 +++---
  src/libgcrypt.c | 4 +-
  src/libssh2_priv.h | 156 +++++++++-----------------
  src/misc.c | 21 ++++-
  src/misc.h | 7 +
  src/openssl.c | 4 +-
  src/openssl.h | 4 +-
  src/packet.c | 62 +++++-----
  src/publickey.c | 40 ++++----
  src/scp.c | 34 +++---
  src/session.c | 37 ++----
  src/sftp.c | 291 ++++++++++++++++++-------------------------------
  src/transport.c | 62 +++++-----
  src/transport.h | 1 +
  src/userauth.c | 310 ++++++++++++++++------------------------------------
  tests/ssh2.sh | 2 +-
  21 files changed, 524 insertions(+), 863 deletions(-)

-- 
  / daniel.haxx.se

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-04-17