summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authorJakub Sławiński2004-01-09 18:48:31 +0100
committerJoshua Judson Rosen2014-07-17 21:14:55 +0200
commitc691251feaffa310a51e0c2255eefc6b42f0e728 (patch)
treef7202a10873641aad3c93850948ec3d969c97735 /network.c
parentv0.5.2 (diff)
downloadapf-c691251feaffa310a51e0c2255eefc6b42f0e728.tar.gz
v0.5.3
- Added: client password identification (weak) - Added: sigint intercepting and server closing - Modified: communication between server and client - Added: 'nossl' and 'nozlib' modes - Added: zlib support - Lightly Modified: verbose mode - Modified/Added: help screen and long options support
Diffstat (limited to 'network.c')
-rw-r--r--network.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/network.c b/network.c
index 59e14a9..2c7862b 100644
--- a/network.c
+++ b/network.c
@@ -19,9 +19,12 @@
*/
#include "network.h"
+#include "activefor.h"
+#include "stats.h"
#include <string.h>
#include <errno.h>
#include <signal.h>
+#include <zlib.h>
static void
sig_alrm(int signo)
@@ -255,3 +258,93 @@ readn(int fd, unsigned char* buf, int amount)
return amount;
}
+
+int
+send_message(char type, clifd fd, unsigned char* buf, int amount)
+{
+ unsigned long clen;
+ int length;
+ static unsigned char bufor[9000];
+ clen = 8995;
+ length = amount - 5;
+ if (TYPE_IS_ZLIB(type)) {
+ memcpy(bufor, buf, 5);
+ if (amount > 5) {
+ compress(&bufor[5], &clen, &buf[5], length);
+ if (clen < length) {
+ length = clen;
+ TYPE_SET_COMP(length);
+ bufor[3] = length >> 8; /* high bits of message length */
+ bufor[4] = length; /* low bits of message length */
+ addtocg(amount-5 - clen);
+ }
+ }
+ if (TYPE_IS_SSL(type)) {
+ if (TYPE_IS_COMP(length)) {
+ return SSL_writen(fd.ssl, bufor, clen+5);
+ }
+ else {
+ return SSL_writen(fd.ssl, buf, amount);
+ }
+ }
+ else {
+ if (TYPE_IS_COMP(length)) {
+ return writen(fd.commfd, bufor, clen+5);
+ }
+ else {
+ return writen(fd.commfd, buf, amount);
+ }
+ }
+ }
+ else {
+ if (TYPE_IS_SSL(type)) {
+ return SSL_writen(fd.ssl, buf, amount);
+ }
+ else {
+ return writen(fd.commfd, buf, amount);
+ }
+ }
+}
+
+int
+get_message(char type, clifd fd, unsigned char* buf, int amount)
+{
+ int length;
+ unsigned long elen;
+ static unsigned char bufor[9000];
+ if (amount == -5) {
+ if (TYPE_IS_SSL(type)) {
+ return SSL_read(fd.ssl, buf, 5);
+ }
+ else {
+ return read(fd.commfd, buf, 5);
+ }
+ }
+ if (TYPE_IS_ZLIB(type)) {
+ if (TYPE_IS_SSL(type)) {
+ length = SSL_readn(fd.ssl, bufor, amount&0xBFFF);
+ }
+ else {
+ length = readn(fd.commfd, bufor, amount&0xBFFF);
+ }
+ if (length <= 0) return length;
+ elen = 8096;
+ if (TYPE_IS_COMP(amount)) {
+ uncompress(buf, &elen, bufor, length);
+ }
+ else {
+ memcpy(buf, bufor, length);
+ elen = length;
+ }
+ return elen;
+ }
+ else
+ {
+ if (TYPE_IS_SSL(type)) {
+ return SSL_readn(fd.ssl, buf, amount);
+ }
+ else {
+ return readn(fd.commfd, buf, amount);
+ }
+ }
+}