Hello,
For monitoring of the total count of transferred data during the connection
tto the server, we created patch that added two functions:
libssh2_session_recv_data(LIBSSH2_SESSION *session) and
libssh2_session_recv_data(LIBSSH2_SESSION *session).
In this patch was added to session structure two counters (datatype long
long)
Incrementation of these counters is performed at
_libssh2_recv/_libssh2_send.
where was added next input parameter - current session.

My question: is this patch correct and applicable and could't it cause any
problems in future?
diff -Naur libssh2-1.4.3/include/libssh2.h libssh2-1.4.3_datacount/include/libssh2.h
--- libssh2-1.4.3/include/libssh2.h	2013-11-20 10:04:02.985780814 +0100
+++ libssh2-1.4.3_datacount/include/libssh2.h	2013-11-22 13:15:10.870131905 +0100
@@ -241,10 +241,10 @@
 /* I/O callbacks */
 #define LIBSSH2_RECV_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
                                               void *buffer, size_t length, \
-                                              int flags, void **abstract)
+                                              int flags, void **abstract, LIBSSH2_SESSION *session)
 #define LIBSSH2_SEND_FUNC(name)  ssize_t name(libssh2_socket_t socket, \
                                               const void *buffer, size_t length,\
-                                              int flags, void **abstract)
+                                              int flags, void **abstract, LIBSSH2_SESSION *session)
 
 /* libssh2_session_callback_set() constants */
 #define LIBSSH2_CALLBACK_IGNORE             0
@@ -329,9 +329,9 @@
 #define LIBSSH2_HOSTKEY_HASH_SHA1                           2
 
 /* Hostkey Types */
-#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN          0
-#define LIBSSH2_HOSTKEY_TYPE_RSA          1
-#define LIBSSH2_HOSTKEY_TYPE_DSS          2
+#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN			    0
+#define LIBSSH2_HOSTKEY_TYPE_RSA			    1
+#define LIBSSH2_HOSTKEY_TYPE_DSS			    2
 
 /* Disconnect Codes (defined by SSH protocol) */
 #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT          1
@@ -1159,6 +1159,12 @@
 LIBSSH2_API int libssh2_send (LIBSSH2_SESSION *session,
                                         int *seconds_to_next);
 
+LIBSSH2_API long long 
+libssh2_session_recv_data(LIBSSH2_SESSION *session);
+
+LIBSSH2_API long long
+libssh2_session_send_data(LIBSSH2_SESSION *session);
+
 /* NOTE NOTE NOTE
    libssh2_trace() has no function in builds that aren't built with debug
    enabled
diff -Naur libssh2-1.4.3/src/libssh2_priv.h libssh2-1.4.3_datacount/src/libssh2_priv.h
--- libssh2-1.4.3/src/libssh2_priv.h	2013-11-14 10:15:24.000000000 +0100
+++ libssh2-1.4.3_datacount/src/libssh2_priv.h	2013-11-22 13:37:21.543860697 +0100
@@ -184,9 +184,9 @@
                       (channel), &(channel)->abstract)
 
 #define LIBSSH2_SEND_FD(session, fd, buffer, length, flags) \
-    session->send(fd, buffer, length, flags, &session->abstract)
+    session->send(fd, buffer, length, flags, &session->abstract, session)
 #define LIBSSH2_RECV_FD(session, fd, buffer, length, flags) \
-    session->recv(fd, buffer, length, flags, &session->abstract)
+    session->recv(fd, buffer, length, flags, &session->abstract, session)
 
 #define LIBSSH2_SEND(session, buffer, length, flags)  \
     LIBSSH2_SEND_FD(session, session->socket_fd, buffer, length, flags)
@@ -810,6 +810,8 @@
     int keepalive_want_reply;
     time_t keepalive_last_sent;
     unsigned int keepalive_count;
+    long long recv_data;
+    long long send_data;
 };
 
 /* session.state bits */
@@ -1001,9 +1003,9 @@
 #define SSH_OPEN_RESOURCE_SHORTAGE           4
 
 ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer,
-                      size_t length, int flags, void **abstract);
+                      size_t length, int flags, void **abstract, LIBSSH2_SESSION *session);
 ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer,
-                      size_t length, int flags, void **abstract);
+                      size_t length, int flags, void **abstract, LIBSSH2_SESSION *session);
 
 #define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
                                    waiting for more data to arrive */
diff -Naur libssh2-1.4.3/src/misc.c libssh2-1.4.3_datacount/src/misc.c
--- libssh2-1.4.3/src/misc.c	2011-08-25 19:59:47.000000000 +0200
+++ libssh2-1.4.3_datacount/src/misc.c	2013-11-22 11:25:39.000000000 +0100
@@ -94,7 +94,7 @@
  * Replacement for the standard recv, return -errno on failure.
  */
 ssize_t
-_libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, int flags, void **abstract)
+_libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, int flags, void **abstract, LIBSSH2_SESSION *session)
 {
     ssize_t rc = recv(sock, buffer, length, flags);
 #ifdef WIN32
@@ -117,6 +117,7 @@
             return -errno;
     }
 #endif
+    session->recv_data += rc;
     return rc;
 }
 
@@ -126,7 +127,7 @@
  */
 ssize_t
 _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length,
-              int flags, void **abstract)
+              int flags, void **abstract, LIBSSH2_SESSION *session)
 {
     ssize_t rc = send(sock, buffer, length, flags);
 #ifdef WIN32
@@ -143,6 +144,7 @@
     if (rc < 0 )
         return -errno;
 #endif
+    session->send_data += rc;
     return rc;
 }
 
diff -Naur libssh2-1.4.3/src/session.c libssh2-1.4.3_datacount/src/session.c
--- libssh2-1.4.3/src/session.c	2012-07-25 01:03:27.000000000 +0200
+++ libssh2-1.4.3_datacount/src/session.c	2013-11-22 11:28:00.000000000 +0100
@@ -1749,3 +1749,20 @@
 
     return (const char *) session->remote.banner;
 }
+
+LIBSSH2_API long long 
+libssh2_session_recv_data(LIBSSH2_SESSION *session)
+{
+    long long recv;
+    recv = session->recv_data;
+    session->recv_data = 0;
+    return recv;
+}
+
+LIBSSH2_API long long
+libssh2_session_send_data(LIBSSH2_SESSION *session){
+    long long send;
+    send = session->send_data;
+    session->send_data = 0;
+    return send;
+}
\ No newline at end of file

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to