diff --git a/Makefile.msvc b/Makefile.msvc index 75d4d7f..4e4640a 100644 --- a/Makefile.msvc +++ b/Makefile.msvc @@ -15,7 +15,7 @@ LN = link LDFLAGS = /nologo /subsystem:console /incremental:no /machine:I386 DLFLAGS = /DLL DLSUFFICS = .dll -LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libeay32MT.lib ssleay32MT.lib +LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib LIBEXT = .lib LNOUT = /out: EXESUFFICS = .exe diff --git a/Makefile.msvc64 b/Makefile.msvc64 index d21f9de..4ce8745 100644 --- a/Makefile.msvc64 +++ b/Makefile.msvc64 @@ -15,7 +15,7 @@ LN = link LDFLAGS = /nologo /subsystem:console /incremental:no /machine:x64 DLFLAGS = /DLL DLSUFFICS = .dll -LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libeay32MT.lib ssleay32MT.lib +LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib LIBEXT = .lib LNOUT = /out: EXESUFFICS = .exe diff --git a/src/3proxy.c b/src/3proxy.c index ba35112..977814d 100644 --- a/src/3proxy.c +++ b/src/3proxy.c @@ -45,8 +45,12 @@ struct counter_header { } cheader = {"3CF", (time_t)0}; struct counter_record { +#ifndef NOPSTDINT + uint64_t traf64; +#else unsigned long traf; unsigned long trafgb; +#endif time_t cleared; time_t updated; } crecord; @@ -465,7 +469,11 @@ void dumpcounters(struct trafcount *tlin, int counterd){ if(cfp){ for(tl = tlin; cfp && tl; tl = tl->next){ if(tl->type >= conf.countertype) +#ifndef NOPSTDINT + fprintf(cfp, "%05d %020"PRINTF_INT64_MODIFIER"u%s%s\n", tl->number, tl->traf64, tl->comment?" #" : "", tl->comment? tl->comment : ""); +#else fprintf(cfp, "%05d %010lu %010lu%s%s\n", tl->number, tl->trafgb, tl->traf, tl->comment?" #" : "", tl->comment? tl->comment : ""); +#endif } fclose(cfp); } @@ -480,16 +488,24 @@ void dumpcounters(struct trafcount *tlin, int counterd){ lseek(counterd, sizeof(struct counter_header) + (tl->number - 1) * sizeof(struct counter_record), SEEK_SET); +#ifndef NOPSTDINT + crecord.traf64 = tl->traf64; +#else crecord.traf = tl->traf; crecord.trafgb = tl->trafgb; +#endif crecord.cleared = tl->cleared; crecord.updated = tl->updated; write(counterd, &crecord, sizeof(struct counter_record)); } if(tl->type!=NEVER && timechanged(tl->cleared, conf.time, tl->type)){ tl->cleared = conf.time; +#ifndef NOPSTDINT + tl->traf64 = 0; +#else tl->traf = 0; tl->trafgb = 0; +#endif } } } @@ -1534,10 +1550,15 @@ static int h_ace(int argc, unsigned char **argv){ sscanf((char *)argv[1], "%u", &tl->number); sscanf((char *)argv[3], "%lu", &lim); + tl->type = getrotate(*argv[2]); +#ifndef NOPSTDINT + tl->traflim64 = ((uint64_t)lim)*(1024*1024); + if(!tl->traflim64) { +#else tl->traflimgb = (lim/(1024*4)); tl->traflim = ((lim - (tl->traflimgb*(1024*4)))*(1024*1024)); - tl->type = getrotate(*argv[2]); if(!tl->traflim && !tl->traflimgb) { +#endif fprintf(stderr, "Wrong traffic limit specified, line %d\n", linenum); return(6); } @@ -1547,8 +1568,12 @@ static int h_ace(int argc, unsigned char **argv){ SEEK_SET); memset(&crecord, 0, sizeof(struct counter_record)); read(conf.counterd, &crecord, sizeof(struct counter_record)); +#ifndef NOPSTDINT + tl->traf64 = crecord.traf64; +#else tl->traf = crecord.traf; tl->trafgb = crecord.trafgb; +#endif tl->cleared = crecord.cleared; tl->updated = crecord.updated; #ifdef _MAX__TIME64_T diff --git a/src/auth.c b/src/auth.c index 8b22b11..b2a9d44 100644 --- a/src/auth.c +++ b/src/auth.c @@ -115,7 +115,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l len += sprintf((char *)buf + len, "\r\n"); if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != (int)strlen((char *)buf)) return 31; +#ifndef NOPSTDINT + param->statssrv64+=len; +#else param->statssrv+=len; +#endif param->nwrites++; if((res = sockgetlinebuf(param, SERVER,buf,13,'\n',conf.timeouts[CHAIN_TO])) < 13) return 32; @@ -152,7 +156,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) < len){ return 41; } +#ifndef NOPSTDINT + param->statssrv64+=len; +#else param->statssrv+=len; +#endif param->nwrites++; if((len = sockgetlinebuf(param, SERVER, buf, (redir->type == R_SOCKS4B)? 3:8, EOF, conf.timeouts[CHAIN_TO])) != ((redir->type == R_SOCKS4B)? 3:8)){ return 42; @@ -175,7 +183,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l if(socksend(param->remsock, buf, 3, conf.timeouts[CHAIN_TO]) != 3){ return 51; } +#ifndef NOPSTDINT + param->statssrv64+=len; +#else param->statssrv+=len; +#endif param->nwrites++; if(sockgetlinebuf(param, SERVER, buf, 2, EOF, conf.timeouts[CHAIN_TO]) != 2){ return 52; @@ -197,7 +209,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l if(socksend(param->remsock, buf, inbuf, conf.timeouts[CHAIN_TO]) != inbuf){ return 51; } +#ifndef NOPSTDINT + param->statssrv64+=inbuf; +#else param->statssrv+=inbuf; +#endif param->nwrites++; if(sockgetlinebuf(param, SERVER, buf, 2, EOF, 60) != 2){ return 55; @@ -227,7 +243,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l if(socksend(param->remsock, buf, len, conf.timeouts[CHAIN_TO]) != len){ return 51; } +#ifndef NOPSTDINT + param->statssrv64+=len; +#else param->statssrv+=len; +#endif param->nwrites++; if(sockgetlinebuf(param, SERVER, buf, 4, EOF, conf.timeouts[CHAIN_TO]) != 4){ return 57; @@ -553,9 +573,13 @@ void trafcountfunc(struct clientparam *param){ countout = 1; continue; } +#ifndef NOPSTDINT + tc->traf64 += param->statssrv64; +#else val = tc->traf + param->statssrv; if(val < tc->traf) tc->trafgb++; tc->traf = val; +#endif time(&t); tc->updated = t; } @@ -567,9 +591,13 @@ void trafcountfunc(struct clientparam *param){ if(tc->ace->action != COUNTOUT) { continue; } +#ifndef NOPSTDINT + tc->traf64 += param->statscli64; +#else val = tc->traf + param->statscli; if(val < tc->traf) tc->trafgb++; tc->traf = val; +#endif time(&t); tc->updated = t; } @@ -596,6 +624,11 @@ int alwaysauth(struct clientparam * param){ continue; } +#ifndef NOPSTDINT + if(tc->traflim64 <= tc->traf64) return 10; + param->trafcountfunc = conf.trafcountfunc; + param->maxtrafin64 = tc->traflim64 - tc->traf64; +#else if((tc->traflimgb < tc->trafgb) || ((tc->traflimgb == tc->trafgb) && (tc->traflim < tc->traf)) ) return 10; @@ -605,6 +638,7 @@ int alwaysauth(struct clientparam * param){ if(!param->maxtrafin || param->maxtrafin > maxtraf) param->maxtrafin = maxtraf; } if((tc->trafgb > tc->traflimgb) || (tc->trafgb == tc->traflimgb && tc->traf >= tc->traflim)) param->maxtrafin = 1; +#endif } } if(countout)for(tc = conf.trafcounter; tc; tc = tc->next) { @@ -615,6 +649,11 @@ int alwaysauth(struct clientparam * param){ continue; } +#ifndef NOPSTDINT + if(tc->traflim64 <= tc->traf64) return 10; + param->trafcountfunc = conf.trafcountfunc; + param->maxtrafout64 = tc->traflim64 - tc->traf64; +#else if((tc->traflimgb < tc->trafgb) || ((tc->traflimgb == tc->trafgb) && (tc->traflim < tc->traf)) ) return 10; @@ -624,6 +663,7 @@ int alwaysauth(struct clientparam * param){ if(!param->maxtrafout || param->maxtrafout > maxtraf) param->maxtrafout = maxtraf; } if((tc->trafgb > tc->traflimgb) || (tc->trafgb == tc->traflimgb && tc->traf >= tc->traflim)) param->maxtrafout = 1; +#endif } } @@ -1089,12 +1129,20 @@ unsigned long udpresolve(unsigned char * name, unsigned *retttl, struct clientpa so._closesocket(sock); continue; } +#ifndef NOPSTDINT + if(param) param->statscli64 += len; +#else if(param) param->statscli += len; +#endif len = sockrecvfrom(sock, sinsp, buf, 4096, 15000); so._shutdown(sock, SHUT_RDWR); so._closesocket(sock); if(len <= 13) continue; +#ifndef NOPSTDINT + if(param) param->statssrv64 += len; +#else if(param) param->statssrv += len; +#endif if(*(unsigned short *)buf != nquery)continue; if((na = buf[7] + (((unsigned short)buf[6])<<8)) < 1) { return 0; diff --git a/src/common.c b/src/common.c index a2fc23a..694c973 100644 --- a/src/common.c +++ b/src/common.c @@ -287,7 +287,11 @@ void clearstat(struct clientparam * param) { param->time_start = (time_t)tv.tv_sec; param->msec_start = (tv.tv_usec / 1000); #endif +#ifndef NOPSTDINT + param->statscli64 = param->statssrv64 = param->nreads = param->nwrites = +#else param->statscli = param->statssrv = param->nreads = param->nwrites = +#endif param->nconnects = 0; } @@ -378,10 +382,17 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char i+=10; break; case 'b': +#ifndef NOPSTDINT + i+=sprintf((char *)buf+i, "%u", delay?(unsigned)(param->statscli64 * 1000./delay):0); + break; + case 'B': + i+=sprintf((char *)buf+i, "%u", delay?(unsigned)(param->statssrv64 * 1000./delay):0); +#else i+=sprintf((char *)buf+i, "%u", delay?(unsigned)(param->statscli * 1000./delay):0); break; case 'B': i+=sprintf((char *)buf+i, "%u", delay?(unsigned)(param->statssrv * 1000./delay):0); +#endif break; case 'D': i+=sprintf((char *)buf+i, "%u", delay); @@ -478,11 +489,19 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char i += (int)strlen((char *)buf+i); break; case 'I': +#ifndef NOPSTDINT + sprintf((char *)buf+i, "%"PRINTF_INT64_MODIFIER"u", param->statssrv64); + i += (int)strlen((char *)buf+i); + break; + case 'O': + sprintf((char *)buf+i, "%"PRINTF_INT64_MODIFIER"u", param->statscli64); +#else sprintf((char *)buf+i, "%lu", param->statssrv); i += (int)strlen((char *)buf+i); break; case 'O': sprintf((char *)buf+i, "%lu", param->statscli); +#endif i += (int)strlen((char *)buf+i); break; case 'h': diff --git a/src/datatypes.c b/src/datatypes.c index 24d5420..a99f7d5 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -8,6 +8,13 @@ #include "proxy.h" +#ifndef NOPSTDINT +static void pr_unsigned64(struct node *node, CBFUNC cbf, void*cb){ + char buf[32]; + if(node->value)(*cbf)(cb, buf, sprintf(buf, "%"PRINTF_INT64_MODIFIER"u", *(uint64_t *)node->value)); +} +#endif + static void pr_integer(struct node *node, CBFUNC cbf, void*cb){ char buf[16]; if(node->value)(*cbf)(cb, buf, sprintf(buf, "%d", *(int *)node->value)); @@ -446,13 +453,55 @@ static void * ef_trafcounter_type(struct node * node){ return &((struct trafcount *)node->value) -> type; } +#ifndef NOPSTDINT +static void * ef_trafcounter_traffic64(struct node * node){ + return &((struct trafcount *)node->value) -> traf64; +} +static void * ef_trafcounter_limit64(struct node * node){ + return &((struct trafcount *)node->value) -> traflim64; +} +static void * ef_client_maxtrafin64(struct node * node){ + return &((struct clientparam *)node->value) -> maxtrafin64; +} + +static void * ef_client_maxtrafout64(struct node * node){ + return &((struct clientparam *)node->value) -> maxtrafout64; +} + +static void * ef_client_bytesin64(struct node * node){ + return &((struct clientparam *)node->value) -> statssrv64; +} + +static void * ef_client_bytesout64(struct node * node){ + return &((struct clientparam *)node->value) -> statscli64; +} + +#else + static void * ef_trafcounter_traffic(struct node * node){ return &((struct trafcount *)node->value) -> traf; } - static void * ef_trafcounter_limit(struct node * node){ return &((struct trafcount *)node->value) -> traflim; } +static void * ef_client_maxtrafin(struct node * node){ + return &((struct clientparam *)node->value) -> maxtrafin; +} +static void * ef_client_maxtrafout(struct node * node){ + return &((struct clientparam *)node->value) -> maxtrafout; +} + +static void * ef_client_bytesin(struct node * node){ + return &((struct clientparam *)node->value) -> statssrv; +} + +static void * ef_client_bytesout(struct node * node){ + return &((struct clientparam *)node->value) -> statscli; +} + + +#endif + static void * ef_trafcounter_cleared(struct node * node){ return &((struct trafcount *)node->value) -> cleared; @@ -573,14 +622,6 @@ static void * ef_client_next(struct node * node){ return ((struct clientparam *)node->value) -> next; } -static void * ef_client_maxtrafin(struct node * node){ - return &((struct clientparam *)node->value) -> maxtrafin; -} - -static void * ef_client_maxtrafout(struct node * node){ - return &((struct clientparam *)node->value) -> maxtrafout; -} - static void * ef_client_type(struct node * node){ int service = ((struct clientparam *)node->value) -> service; return (service>=0 && service < 15)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown"; @@ -641,14 +682,6 @@ static void * ef_client_cliport(struct node * node){ return &((struct clientparam *)node->value) -> sinc.sin_port; } -static void * ef_client_bytesin(struct node * node){ - return &((struct clientparam *)node->value) -> statssrv; -} - -static void * ef_client_bytesout(struct node * node){ - return &((struct clientparam *)node->value) -> statscli; -} - static void * ef_client_pwtype(struct node * node){ return &((struct clientparam *)node->value) -> pwtype; } @@ -742,8 +775,15 @@ static struct property prop_trafcounter[] = { {prop_trafcounter + 2, "ace", ef_trafcounter_ace, TYPE_ACE, "traffic to count"}, {prop_trafcounter + 3, "number", ef_trafcounter_number, TYPE_UNSIGNED, "counter number"}, {prop_trafcounter + 4, "type", ef_trafcounter_type, TYPE_ROTATION, "rotation type"}, + + +#ifndef NOPSTDINT + {prop_trafcounter + 5, "traffic", ef_trafcounter_traffic64, TYPE_UNSIGNED64, "counter value"}, + {prop_trafcounter + 6, "limit", ef_trafcounter_limit64, TYPE_UNSIGNED64, "counter limit"}, +#else {prop_trafcounter + 5, "traffic", ef_trafcounter_traffic, TYPE_TRAFFIC, "counter value"}, {prop_trafcounter + 6, "limit", ef_trafcounter_limit, TYPE_TRAFFIC, "counter limit"}, +#endif {prop_trafcounter + 7, "cleared", ef_trafcounter_cleared, TYPE_DATETIME, "last rotated"}, {prop_trafcounter + 8, "updated", ef_trafcounter_updated, TYPE_DATETIME, "last updated"}, {prop_trafcounter + 9, "comment", ef_trafcounter_comment, TYPE_STRING, "counter comment"}, @@ -795,11 +835,18 @@ static struct property prop_client[] = { {prop_client + 15, "srvport", ef_client_srvport, TYPE_PORT, "target server port"}, {prop_client + 16, "reqip", ef_client_reqip, TYPE_IP, "requested server ip"}, {prop_client + 17, "reqport", ef_client_reqport, TYPE_PORT, "requested server port"}, +#ifndef NOPSTDINT + {prop_client + 18, "bytesin", ef_client_bytesin64, TYPE_UNSIGNED64, "bytes from server to client"}, + {prop_client + 19, "bytesout", ef_client_bytesout64, TYPE_UNSIGNED64, "bytes from client to server"}, + {prop_client + 20, "maxtrafin", ef_client_maxtrafin64, TYPE_UNSIGNED64, "maximum traffic allowed for download"}, + {prop_client + 21, "maxtrafout", ef_client_maxtrafout64, TYPE_UNSIGNED64, "maximum traffic allowed for upload"}, +#else {prop_client + 18, "bytesin", ef_client_bytesin, TYPE_UNSIGNED, "bytes from server to client"}, {prop_client + 19, "bytesout", ef_client_bytesout, TYPE_UNSIGNED, "bytes from client to server"}, - {prop_client + 20, "pwtype", ef_client_pwtype, TYPE_INTEGER, "type of client password"}, - {prop_client + 21, "maxtrafin", ef_client_maxtrafin, TYPE_UNSIGNED, "maximum traffic allowed for download"}, - {prop_client + 22, "maxtrafout", ef_client_maxtrafout, TYPE_UNSIGNED, "maximum traffic allowed for upload"}, + {prop_client + 20, "maxtrafin", ef_client_maxtrafin, TYPE_UNSIGNED, "maximum traffic allowed for download"}, + {prop_client + 21, "maxtrafout", ef_client_maxtrafout, TYPE_UNSIGNED, "maximum traffic allowed for upload"}, +#endif + {prop_client + 22, "pwtype", ef_client_pwtype, TYPE_INTEGER, "type of client password"}, {NULL, "next", ef_client_next, TYPE_CLIENT, "next"} @@ -810,6 +857,7 @@ struct datatype datatypes[64] = { {"short", NULL, pr_short, NULL}, {"char", NULL, pr_char, NULL}, {"unsigned", NULL, pr_unsigned, NULL}, + {"unsigned64", NULL, pr_unsigned64, NULL}, {"traffic", NULL, pr_traffic, NULL}, {"port", NULL, pr_port, NULL}, {"ip", NULL, pr_ip, NULL}, diff --git a/src/dnspr.c b/src/dnspr.c index 1e008ff..661a668 100644 --- a/src/dnspr.c +++ b/src/dnspr.c @@ -147,13 +147,21 @@ void * dnsprchild(struct clientparam* param) { if(socksendto(param->remsock, ¶m->sins, buf, i, conf.timeouts[SINGLEBYTE_L]*1000) != i){ RETURN(820); } +#ifndef NOPSTDINT + param->statscli64 += i; +#else param->statscli += i; +#endif param->nwrites++; len = sockrecvfrom(param->remsock, ¶m->sins, buf, BUFSIZE, 15000); if(len <= 13) { RETURN(821); } +#ifndef NOPSTDINT + param->statssrv64 += len; +#else param->statssrv += len; +#endif param->nreads++; if(buf[6] || buf[7]){ if(socksendto(param->clisock, ¶m->sinc, buf, len, conf.timeouts[SINGLEBYTE_L]*1000) != len){ diff --git a/src/ftp.c b/src/ftp.c index 710c65b..de5a51b 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -33,7 +33,11 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) { if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){ return 703; } +#ifndef NOPSTDIN + param->statscli64 += (int)strlen(buf); +#else param->statscli += (int)strlen(buf); +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, len - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } @@ -50,7 +54,11 @@ int ftplogin(struct clientparam *param, char *nbuf, int *innbuf) { if((int)socksend(param->remsock, (unsigned char *)buf, res, conf.timeouts[STRING_S]) != (int)strlen(buf)){ return 705; } - param->statscli += res; +#ifndef NOPSTDIN + param->statscli64 += res; +#else + param->statscli += res; +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, len - 1, '\n', conf.timeouts[STRING_L])) > 0){ buf[i] = 0; @@ -81,7 +89,11 @@ int ftpcd(struct clientparam *param, unsigned char* path, char *nbuf, int *innbu if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){ return 711; } +#ifndef NOPSTDIN + param->statscli64 += (int)strlen(buf); +#else param->statscli += (int)strlen(buf); +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ if(nbuf && innbuf && inbuf + i < *innbuf && i > 6) { @@ -114,7 +126,11 @@ int ftpsyst(struct clientparam *param, unsigned char *buf, unsigned len){ if(socksend(param->remsock, (unsigned char *)"SYST\r\n", 6, conf.timeouts[STRING_S]) != 6){ return 721; } - param->statscli+=6; +#ifndef NOPSTDIN + param->statscli64 += 6; +#else + param->statscli += 6; +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, buf, len - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } @@ -133,7 +149,11 @@ int ftppwd(struct clientparam *param, unsigned char *buf, unsigned len){ if(socksend(param->remsock, (unsigned char *)"PWD\r\n", 5, conf.timeouts[STRING_S]) != 5){ return 731; } +#ifndef NOPSTDIN + param->statscli64 += 5; +#else param->statscli += 5; +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, buf, len - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } @@ -158,7 +178,11 @@ int ftptype(struct clientparam *param, unsigned char* f_type){ if((int)socksend(param->remsock, (unsigned char *)buf, (int)strlen(buf), conf.timeouts[STRING_S]) != (int)strlen(buf)){ return 741; } +#ifndef NOPSTDIN + param->statscli64 += (int)strlen(buf); +#else param->statscli += (int)strlen(buf); +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } @@ -179,7 +203,11 @@ SOCKET ftpdata(struct clientparam *param){ if(socksend(param->remsock, (unsigned char *)"PASV\r\n", 6, conf.timeouts[STRING_S]) != 6){ return INVALID_SOCKET; } - param->statscli+=6; +#ifndef NOPSTDIN + param->statscli64 += 6; +#else + param->statscli += 6; +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } @@ -217,7 +245,11 @@ SOCKET ftpcommand(struct clientparam *param, unsigned char * command, unsigned c so._closesocket(s); return INVALID_SOCKET; } +#ifndef NOPSTDIN + param->statscli64 += (int)strlen(buf); +#else param->statscli += (int)strlen(buf); +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, (unsigned char *)buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L])) > 0 && (i < 3 || !isnumber(*buf) || buf[3] == '-')){ } diff --git a/src/ftppr.c b/src/ftppr.c index 90f18c0..28d695e 100644 --- a/src/ftppr.c +++ b/src/ftppr.c @@ -276,7 +276,11 @@ param->srv->logfunc(param,buf); buf[i++] = '\r'; buf[i++] = '\n'; if(socksend(param->remsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (811);} - param->statscli += i; +#ifndef NOPSTDINT + param->statscli64+=(i); +#else + param->statscli+=(i); +#endif param->nwrites++; while((i = sockgetlinebuf(param, SERVER, buf, BUFSIZE, '\n', conf.timeouts[STRING_L])) > 0){ if(socksend(param->ctrlsock, buf, i, conf.timeouts[STRING_S])!=i) {RETURN (812);} @@ -287,9 +291,15 @@ param->srv->logfunc(param,buf); } sasize = sizeof(struct sockaddr_in); if(so._getpeername(param->ctrlsock, (struct sockaddr *)¶m->sinc, &sasize)){RETURN(819);} +#ifndef NOPSTDINT + if(req && (param->statscli64 || param->statssrv64)){ + (*param->srv->logfunc)(param, (unsigned char *)req); + } +#else if(req && (param->statscli || param->statssrv)){ (*param->srv->logfunc)(param, (unsigned char *)req); } +#endif } CLEANRET: @@ -308,7 +318,11 @@ CLEANRET: } sasize = sizeof(struct sockaddr_in); so._getpeername(param->ctrlsock, (struct sockaddr *)¶m->sinc, &sasize); +#ifndef NOPSTDINT + if(param->res != 0 || param->statscli64 || param->statssrv64 ){ +#else if(param->res != 0 || param->statscli || param->statssrv ){ +#endif (*param->srv->logfunc)(param, (unsigned char *)((req && (param->res > 802))? req:NULL)); } if(req) myfree(req); diff --git a/src/icqpr.c b/src/icqpr.c index a319da6..e1a315d 100644 --- a/src/icqpr.c +++ b/src/icqpr.c @@ -109,7 +109,11 @@ static void addbuffer(int increment, struct clientparam * param, unsigned char * if(len > 0) { *length_p += len; param->nreads++; +#ifndef NOPSTDINT + param->statssrv64 += len; +#else param->statssrv += len; +#endif } return; } @@ -437,18 +441,29 @@ void * icqprchild(struct clientparam* param) { if(greet){ if(socksend(param->remsock, tmpsend, 10, conf.timeouts[STRING_S])!=10) {RETURN (1105);} +#ifndef NOPSTDINT + param->statscli64 += 10; +#else param->statscli += 10; +#endif } if(readflap(param, SERVER, tmpsend, 1024)) {RETURN (1111);} +#ifndef NOPSTDINT + param->statssrv64 += (ntohs(((struct flap_header *)tmpsend)->size) + 6); +#else param->statssrv += (ntohs(((struct flap_header *)tmpsend)->size) + 6); +#endif mystate.srvseq = ntohs(((struct flap_header *)tmpsend)->seq) + 1; mystate.seq = 1; len = ntohs(flap->size) + 6; if((res=handledatfltcli(param, &buf, &buflen, offset, &len))!=PASS) RETURN(res); if(socksend(param->remsock, buf+offset, len, conf.timeouts[STRING_S])!=(ntohs(flap->size)+6)) {RETURN (1106);} offset = 0; +#ifndef NOPSTDINT + param->statscli64 += len; +#else param->statscli += len; - +#endif @@ -466,7 +481,11 @@ void * icqprchild(struct clientparam* param) { len = ntohs(flap->size) + 6; if((res=handledatfltcli(param, &buf, &buflen, offset, &len))!=PASS) RETURN(res); if(socksend(param->remsock, buf+offset, len, conf.timeouts[STRING_S])!=len) {RETURN (1115);} +#ifndef NOPSTDINT + param->statscli64 += len; +#else param->statscli += len; +#endif offset = 0; } if(logintype != ICQCOOKIE) { diff --git a/src/msnpr.c b/src/msnpr.c index be8e006..1ff1391 100644 --- a/src/msnpr.c +++ b/src/msnpr.c @@ -173,15 +173,22 @@ void * msnprchild(struct clientparam* param) { if(!sec){ len = (int)strlen(verstr); if(socksend(param->remsock, verstr, len, conf.timeouts[STRING_S])!= len) {RETURN (1207);} +#ifndef NOPSTDINT + param->statscli64 += len; +#else param->statscli += len; - +#endif myfree(verstr); verstr = mystrdup(buf); len = sockgetlinebuf(param, SERVER, buf, 240, '\n', conf.timeouts[STRING_S]); if(len < 10) RETURN(1208); +#ifndef NOPSTDINT + param->statssrv64 += len; +#else param->statssrv += len; +#endif strcpy(buf, verstr); } @@ -191,7 +198,11 @@ void * msnprchild(struct clientparam* param) { if(socksend(param->remsock, buf, len, conf.timeouts[STRING_S])!= len) {RETURN (1207);} +#ifndef NOPSTDINT + param->statscli64 += len; +#else param->statscli += len; +#endif if(sec){ RETURN(sockmap(param, conf.timeouts[CONNECTION_L])); diff --git a/src/plugins/TrafficPlugin/TrafficPlugin.c b/src/plugins/TrafficPlugin/TrafficPlugin.c index a745112..1347fe4 100644 --- a/src/plugins/TrafficPlugin/TrafficPlugin.c +++ b/src/plugins/TrafficPlugin/TrafficPlugin.c @@ -179,7 +179,11 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) { int port; int rule = 0; struct trafcorrect * starttrafcorrect = firsttrafcorrect; - int statssrv_before, statscli_before; +#ifndef NOPSTDINT + uint64_t statssrv_before, statscli_before; +#else + unsigned long statssrv_before, statscli_before; +#endif int ok = 0; for (;starttrafcorrect != NULL; starttrafcorrect = starttrafcorrect->next) { port = starttrafcorrect->port; @@ -187,8 +191,13 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) { if (starttrafcorrect->p_service == S_NOSERVICE) g_s = param->service; if (starttrafcorrect->port <= 0) port = myhtons(param->sins.sin_port); +#ifndef NOPSTDINT + statssrv_before = param->statssrv64; + statscli_before = param->statscli64; +#else statssrv_before = param->statssrv; statscli_before = param->statscli; +#endif rule++; if (((g_s == param->service) && (port == myhtons(param->sins.sin_port))) || ( ((starttrafcorrect->type == UDP) && @@ -201,21 +210,40 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) { /* фильтр подошёл. можно изменять значение траффика домножаем на число */ if (starttrafcorrect->type == MULTIPLAY) { +#ifndef NOPSTDINT + param->statssrv64 = (unsigned)((double)param->statssrv64 *starttrafcorrect->coeff); + param->statscli64 = (unsigned)((double)param->statscli64 * starttrafcorrect->coeff); +#else param->statssrv = (unsigned)((double)param->statssrv *starttrafcorrect->coeff); param->statscli = (unsigned)((double)param->statscli * starttrafcorrect->coeff); +#endif } /* с учётом пакетов */ if (starttrafcorrect->type == IPCORRECT) { if (starttrafcorrect->con_type == TCP) { +#ifndef NOPSTDINT + param->statssrv64+=(param->nreads + 3*param->nconnects)*starttrafcorrect->psize; + param->statscli64+=(param->nwrites + 3*param->nconnects)*starttrafcorrect->psize; +#else param->statssrv+=(param->nreads + 3*param->nconnects)*starttrafcorrect->psize; param->statscli+=(param->nwrites + 3*param->nconnects)*starttrafcorrect->psize; +#endif } else { +#ifndef NOPSTDINT + param->statssrv64+=param->nreads*starttrafcorrect->psize; + param->statscli64+=param->nwrites*starttrafcorrect->psize; +#else param->statssrv+=param->nreads*starttrafcorrect->psize; param->statscli+=param->nwrites*starttrafcorrect->psize; +#endif } } if (DBGLEVEL == 1) { - fprintf(stdout, "Port=%hd; Before: srv=%d, cli=%d; After: srv=%ld, cli=%ld; nreads=%ld; nwrites=%ld; Rule=%d\n",myhtons(param->sins.sin_port), statssrv_before, statscli_before, param->statssrv, param->statscli,param->nreads,param->nwrites,rule); +#ifndef NOPSTDINT + fprintf(stdout, "Port=%hd; Before: srv=%"PRINTF_INT64_MODIFIER"d, cli=%"PRINTF_INT64_MODIFIER"d; After: srv=%"PRINTF_INT64_MODIFIER"d, cli=%"PRINTF_INT64_MODIFIER"d; nreads=%ld; nwrites=%ld; Rule=%d\n",myhtons(param->sins.sin_port), statssrv_before, statscli_before, param->statssrv64, param->statscli64,param->nreads,param->nwrites,rule); +#else + fprintf(stdout, "Port=%hd; Before: srv=%lu, cli=%lu; After: srv=%lu, cli=%lu; nreads=%ld; nwrites=%ld; Rule=%d\n",myhtons(param->sins.sin_port), statssrv_before, statscli_before, param->statssrv, param->statscli,param->nreads,param->nwrites,rule); +#endif } ok = 1; break; diff --git a/src/pop3p.c b/src/pop3p.c index b9a06a1..f5ac9b7 100644 --- a/src/pop3p.c +++ b/src/pop3p.c @@ -43,7 +43,11 @@ void * pop3pchild(struct clientparam* param) { socksend(param->remsock, param->extusername, (int)strlen((char *)param->extusername), conf.timeouts[STRING_S]) <= 0 || socksend(param->remsock, (unsigned char *)"\r\n", 2, conf.timeouts[STRING_S])!=2) {RETURN(623);} +#ifndef NOPSTDINT + param->statscli64 += (uint64_t)(strlen((char *)param->extusername) + 7); +#else param->statscli += (int)(strlen((char *)param->extusername) + 7); +#endif param->nwrites++; RETURN (sockmap(param, 180)); CLEANRET: diff --git a/src/proxy.c b/src/proxy.c index 834cae3..b09176b 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -217,7 +217,11 @@ void * proxychild(struct clientparam* param) { unsigned char *ftpbase=NULL; unsigned char username[1024]; int keepalive = 0; +#ifndef NOPSTDINT + uint64_t contentlength64 = 0; +#else unsigned long contentlength = 0; +#endif int hascontent =0; int isconnect = 0; int redirect = 0; @@ -388,6 +392,16 @@ for(;;){ while( (i = sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, '\n', conf.timeouts[STRING_S])) > 2){ if(i> 15 && (!strncasecmp((char *)(buf), "content-length", 14))){ buf[i]=0; +#ifndef NOPSTDINT + sscanf((char *)buf + 15, "%"PRINTF_INT64_MODIFIER"u", &contentlength64); + } + } + while( contentlength64 > 0 && (i = sockgetlinebuf(param, CLIENT, buf, (BUFSIZE < contentlength64)? BUFSIZE - 1:(int)contentlength64, '\n', conf.timeouts[STRING_S])) > 0){ + if ((uint64_t)i > contentlength64) break; + contentlength64-=i; + } + contentlength64 = 0; +#else sscanf((char *)buf + 15, "%lu", &contentlength); } } @@ -396,6 +410,7 @@ for(;;){ contentlength-=i; } contentlength = 0; +#endif if(param->password)myfree(param->password); param->password = myalloc(32); param->pwtype = 2; @@ -492,11 +507,19 @@ for(;;){ if(!sb)continue; ++sb; while(isspace(*sb))sb++; +#ifndef NOPSTDINT + sscanf(sb, "%"PRINTF_INT64_MODIFIER"u",&contentlength64); + if(param->maxtrafout64 && (param->maxtrafout64 < param->statscli64 || contentlength64 > param->maxtrafout64 - param->statscli64)){ + RETURN(10); + } + if(param->ndatfilterscli > 0 && contentlength64 > 0) continue; +#else sscanf(sb, "%lu",&contentlength); if(param->maxtrafout && (param->maxtrafout < param->statscli || (unsigned)contentlength > param->maxtrafout - param->statscli)){ RETURN(10); } if(param->ndatfilterscli > 0 && contentlength > 0) continue; +#endif } inbuf += i; if((bufsize - inbuf) < LINESIZE){ @@ -527,19 +550,34 @@ for(;;){ RETURN(0); } if(action != PASS) RETURN(517); +#ifndef NOPSTDINT + if(param->ndatfilterscli > 0 && contentlength64 > 0){ + uint64_t newlen64; + newlen64 = sockfillbuffcli(param, (unsigned long)contentlength64, CONNECTION_S); + if(newlen64 == contentlength64) { +#else if(param->ndatfilterscli > 0 && contentlength > 0){ unsigned long newlen; newlen = sockfillbuffcli(param, contentlength, CONNECTION_S); if(newlen == contentlength) { +#endif action = handledatfltcli(param, ¶m->clibuf, ¶m->clibufsize, 0, ¶m->cliinbuf); if(action == HANDLED){ RETURN(0); } if(action != PASS) RETURN(517); +#ifndef NOPSTDINT + contentlength64 = param->cliinbuf; +#else contentlength = param->cliinbuf; +#endif param->ndatfilterscli = 0; } +#ifndef NOPSTDINT + sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRINTF_INT64_MODIFIER"u\r\n", contentlength64); +#else sprintf((char*)buf+strlen((char *)buf), "Content-Length: %lu\r\n", contentlength); +#endif } #endif @@ -619,7 +657,11 @@ for(;;){ socksend(param->clisock, (unsigned char *)proxy_stringtable[8], (int)strlen(proxy_stringtable[8]), conf.timeouts[STRING_S]); s = param->remsock; param->remsock = ftps; +#ifndef NOPSTDINT + if((param->operation == FTP_PUT) && (contentlength64 > 0)) param->waitclient64 = contentlength64; +#else if((param->operation == FTP_PUT) && (contentlength > 0)) param->waitclient = contentlength; +#endif res = sockmap(param, conf.timeouts[CONNECTION_L]); if (res == 99) res = 0; so._closesocket(ftps); @@ -821,7 +863,11 @@ for(;;){ if(socksend(param->remsock, req , (res = (int)strlen((char *)req)), conf.timeouts[STRING_L]) != res) { RETURN(518); } +#ifndef NOPSTDINT + param->statscli64 += res; +#else param->statscli += res; +#endif param->nwrites++; } inbuf = 0; @@ -853,11 +899,27 @@ for(;;){ if ((res = socksend(param->remsock, buf+reqlen, (int)strlen((char *)buf+reqlen), conf.timeouts[STRING_S])) != (int)strlen((char *)buf+reqlen)) { RETURN(518); } +#ifndef NOPSTDINT + param->statscli64 += res; +#else param->statscli += res; +#endif param->nwrites++; if(param->bandlimfunc) { sleeptime = param->bandlimfunc(param, 0, (int)strlen((char *)buf)); } +#ifndef NOPSTDINT + if(contentlength64 > 0){ + param->nolongdatfilter = 0; + param->waitclient64 = contentlength64; + res = sockmap(param, conf.timeouts[CONNECTION_S]); + param->waitclient64 = 0; + if(res != 99) { + RETURN(res); + } + } + contentlength64 = 0; +#else if(contentlength > 0){ param->nolongdatfilter = 0; param->waitclient = contentlength; @@ -868,6 +930,7 @@ for(;;){ } } contentlength = 0; +#endif inbuf = 0; ckeepalive = keepalive; res = 0; @@ -900,13 +963,21 @@ for(;;){ if(!sb)continue; ++sb; while(isspace(*sb))sb++; +#ifndef NOPSTDINT + sscanf(sb, "%"PRINTF_INT64_MODIFIER"u", &contentlength64); +#else sscanf(sb, "%lu", &contentlength); +#endif hascontent = 1; if(param->unsafefilter && param->ndatfilterssrv > 0) { hascontent = 2; continue; } +#ifndef NOPSTDINT + if(param->maxtrafin64 && (param->maxtrafin64 < param->statssrv64 || contentlength64 + param->statssrv64 > param->maxtrafin64)){ +#else if(param->maxtrafin && (param->maxtrafin < param->statssrv || (unsigned)contentlength > param->maxtrafin - param->statssrv)){ +#endif RETURN(10); } } @@ -935,7 +1006,11 @@ for(;;){ } if((res == 304 || res == 204) && !hascontent){ hascontent = 1; +#ifndef NOPSTDINT + contentlength64 = 0; +#else contentlength = 0; +#endif } if(param->bandlimfunc) { int st1; @@ -959,6 +1034,27 @@ for(;;){ param->nolongdatfilter = 0; +#ifndef NOPSTDINT + if (conf.filtermaxsize && contentlength64 > (uint64_t)conf.filtermaxsize) { + param->nolongdatfilter = 1; + } + else if(param->unsafefilter && param->ndatfilterssrv > 0 && contentlength64 > 0 && param->operation != HTTP_HEAD && res != 204 && res != 304){ + uint64_t newlen; + newlen = (uint64_t)sockfillbuffsrv(param, (unsigned long) contentlength64, CONNECTION_S); + if(newlen == contentlength64) { + action = handledatfltsrv(param, ¶m->srvbuf, ¶m->srvbufsize, 0, ¶m->srvinbuf); + param->nolongdatfilter = 1; + if(action == HANDLED){ + RETURN(0); + } + if(action != PASS) RETURN(517); + contentlength64 = param->srvinbuf; + sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRINTF_INT64_MODIFIER"u\r\n", contentlength64); + hascontent = 1; + } + } + if (contentlength64 > 0 && hascontent != 1) ckeepalive = 0; +#else if (conf.filtermaxsize && contentlength > (unsigned long)conf.filtermaxsize) { param->nolongdatfilter = 1; } @@ -978,6 +1074,7 @@ for(;;){ } } if (contentlength > 0 && hascontent != 1) ckeepalive = 0; +#endif #else #endif if(!isconnect || param->operation){ @@ -996,7 +1093,11 @@ for(;;){ RETURN(521); } } +#ifndef NOPSTDINT + if((param->chunked || contentlength64 > 0) && param->operation != HTTP_HEAD && res != 204 && res != 304) { +#else if((param->chunked || contentlength > 0) && param->operation != HTTP_HEAD && res != 204 && res != 304) { +#endif do { if(param->chunked){ char smallbuf[32]; @@ -1021,18 +1122,32 @@ for(;;){ break; } smallbuf[i] = 0; +#ifndef NOPSTDINT + contentlength64 = 0; + sscanf(smallbuf, "%"PRINTF_INT64_MODIFIER"x", &contentlength64); + if(contentlength64 == 0) { +#else contentlength = 0; sscanf(smallbuf, "%lx", &contentlength); if(contentlength == 0) { +#endif param->chunked = 2; } } if(param->chunked != 2){ +#ifndef NOPSTDINT + param->waitserver64 = contentlength64; +#else param->waitserver = contentlength; +#endif if((res = sockmap(param, conf.timeouts[CONNECTION_S])) != 98){ RETURN(res); } +#ifndef NOPSTDINT + param->waitserver64 = 0; +#else param->waitserver = 0; +#endif } } while(param->chunked); } @@ -1045,8 +1160,11 @@ for(;;){ else if(!hascontent && !param->chunked) { RETURN(sockmap(param, conf.timeouts[CONNECTION_S])); } +#ifndef NOPSTDINT + contentlength64 = 0; +#else contentlength = 0; - +#endif REQUESTEND: if((!ckeepalive || !keepalive) && param->remsock != INVALID_SOCKET){ diff --git a/src/pstdint.h b/src/pstdint.h index 81e2cc9..00fc1fc 100644 --- a/src/pstdint.h +++ b/src/pstdint.h @@ -797,4 +797,4 @@ int main () { return EXIT_SUCCESS; } -#endif \ No newline at end of file +#endif diff --git a/src/smtpp.c b/src/smtpp.c index 8c8b635..f736119 100644 --- a/src/smtpp.c +++ b/src/smtpp.c @@ -191,7 +191,11 @@ void * smtppchild(struct clientparam* param) { ul = param->extip; i = sprintf(buf, "EHLO [%lu.%lu.%lu.%lu]\r\n", ((ul&0xFF000000)>>24), ((ul&0x00FF0000)>>16), ((ul&0x0000FF00)>>8), ((ul&0x000000FF))); if(socksend(param->remsock, buf, i, conf.timeouts[STRING_S])!= i) {RETURN(673);} +#ifndef NOPSTDINT + param->statscli64+=i; +#else param->statscli+=i; +#endif param->nwrites++; login = 0; do { @@ -209,26 +213,42 @@ void * smtppchild(struct clientparam* param) { } if ((login & 1)) { socksend(param->remsock, "AUTH LOGIN\r\n", 12, conf.timeouts[STRING_S]); - param->statscli+=12; +#ifndef NOPSTDINT + param->statscli64+=12; +#else + param->statscli+=12; +#endif param->nwrites++; i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]); if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(680);} en64(param->extusername, buf, (int)strlen(param->extusername)); socksend(param->remsock, buf, (int)strlen(buf), conf.timeouts[STRING_S]); socksend(param->remsock, "\r\n", 2, conf.timeouts[STRING_S]); - param->statscli+=(i+2); +#ifndef NOPSTDINT + param->statscli64+=(i+2); +#else + param->statscli+=(i+2); +#endif param->nwrites+=2; i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]); if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(681);} en64(param->extpassword, buf, (int)strlen(param->extpassword)); socksend(param->remsock, buf, (int)strlen(buf), conf.timeouts[STRING_S]); socksend(param->remsock, "\r\n", 2, conf.timeouts[STRING_S]); - param->statscli+=(i+2); +#ifndef NOPSTDINT + param->statscli64+=(i+2); +#else + param->statscli+=(i+2); +#endif param->nwrites+=2; } else if((login & 2)){ socksend(param->remsock, "AUTH PLAIN\r\n", 12, conf.timeouts[STRING_S]); - param->statscli+=12; +#ifndef NOPSTDINT + param->statscli64+=(12); +#else + param->statscli+=(12); +#endif param->nwrites++; i = sockgetlinebuf(param, SERVER, buf, sizeof(buf) - 1, '\n', conf.timeouts[STRING_L]); if(i<4 || strncasecmp((char *)buf, "334", 3)) {RETURN(682);} @@ -243,7 +263,11 @@ void * smtppchild(struct clientparam* param) { i = (int)strlen(buf); socksend(param->remsock, buf, i, conf.timeouts[STRING_S]); socksend(param->remsock, "\r\n", 2, conf.timeouts[STRING_S]); - param->statscli+=(i+2); +#ifndef NOPSTDINT + param->statscli64+=(i+2); +#else + param->statscli+=(i+2); +#endif param->nwrites+=2; } if(command) { diff --git a/src/sockgetchar.c b/src/sockgetchar.c index f7d74c5..c507b6b 100644 --- a/src/sockgetchar.c +++ b/src/sockgetchar.c @@ -126,7 +126,11 @@ int sockfillbuffsrv(struct clientparam * param, unsigned long size, int timeosec if((len = sockrecvfrom(param->remsock, ¶m->sinc, param->srvbuf + param->srvinbuf, (param->srvbufsize - param->srvinbuf) < size? param->srvbufsize - param->srvinbuf:size, timeosec*1000)) > 0){ param->srvinbuf += len; param->nreads++; +#ifndef NOPSTDINT + param->statssrv64 += len; +#else param->statssrv += len; +#endif } return param->srvinbuf; } @@ -152,7 +156,11 @@ int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec){ param->srvinbuf = len; param->srvoffset = 1; param->nreads++; +#ifndef NOPSTDINT + param->statssrv64 += len; +#else param->statssrv += len; +#endif return (int)*param->srvbuf; } diff --git a/src/sockmap.c b/src/sockmap.c index 3b3dfcc..a039322 100644 --- a/src/sockmap.c +++ b/src/sockmap.c @@ -13,7 +13,11 @@ int sockmap(struct clientparam * param, int timeo){ int res=0; +#ifndef NOPSTDINT + uint64_t sent=0, received=0; +#else unsigned sent=0, received=0; +#endif SASIZETYPE sasize; struct pollfd fds[2]; int sleeptime = 0, stop = 0; @@ -32,12 +36,20 @@ int sockmap(struct clientparam * param, int timeo){ #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "Starting sockets mapping"); #endif +#ifndef NOPSTDINT + if(!param->waitclient64){ +#else if(!param->waitclient){ +#endif if(!param->srvbuf && (!(param->srvbuf=myalloc(bufsize)) || !(param->srvbufsize = bufsize))){ return (21); } } +#ifndef NOPSTDINT + if(!param->waitserver64){ +#else if(!param->waitserver){ +#endif if(!param->clibuf && (!(param->clibuf=myalloc(bufsize)) || !(param->clibufsize = bufsize))){ return (21); } @@ -69,6 +81,16 @@ int sockmap(struct clientparam * param, int timeo){ while (!stop&&!conf.timetoexit){ sasize = sizeof(struct sockaddr_in); +#ifndef NOPSTDINT + if((param->maxtrafin64 && param->statssrv64 >= param->maxtrafin64) || (param->maxtrafout64 && param->statscli64 >= param->maxtrafout64)){ + return (10); + } + if((param->srv->logdumpsrv && (param->statssrv64 > param->srv->logdumpsrv)) || + (param->srv->logdumpcli && (param->statscli64 > param->srv->logdumpcli))) + (*param->srv->logfunc)(param, NULL); + fds[0].events = fds[1].events = 0; + if(param->srvinbuf > param->srvoffset && !param->waitclient64) { +#else if((param->maxtrafin && param->statssrv >= param->maxtrafin) || (param->maxtrafout && param->statscli >= param->maxtrafout)){ return (10); } @@ -77,25 +99,38 @@ int sockmap(struct clientparam * param, int timeo){ (*param->srv->logfunc)(param, NULL); fds[0].events = fds[1].events = 0; if(param->srvinbuf > param->srvoffset && !param->waitclient) { +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "will send to client"); #endif fds[0].events |= POLLOUT; } +#ifndef NOPSTDINT + if((param->srvbufsize - param->srvinbuf) > minsize && !param->waitclient64 && (!param->waitserver64 ||(received + param->srvinbuf - param->srvoffset < param->waitserver64))) { +#else if((param->srvbufsize - param->srvinbuf) > minsize && !param->waitclient && (!param->waitserver ||(received + param->srvinbuf - param->srvoffset < param->waitserver))) { +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "Will recv from server"); #endif fds[1].events |= POLLIN; } +#ifndef NOPSTDINT + if(param->cliinbuf > param->clioffset && !param->waitserver64) { +#else if(param->cliinbuf > param->clioffset && !param->waitserver) { +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "Will send to server"); #endif fds[1].events |= POLLOUT; } +#ifndef NOPSTDINT + if((param->clibufsize - param->cliinbuf) > minsize && !param->waitserver64 &&(!param->srv->singlepacket || param->service != S_UDPPM) ) { +#else if((param->clibufsize - param->cliinbuf) > minsize && !param->waitserver &&(!param->srv->singlepacket || param->service != S_UDPPM) ) { +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "Will recv from client"); #endif @@ -128,7 +163,11 @@ int sockmap(struct clientparam * param, int timeo){ if(param->bandlimfunc) { sleeptime = (*param->bandlimfunc)(param, param->srvinbuf - param->srvoffset, 0); } +#ifndef NOPSTDINT + res = so._sendto(param->clisock, param->srvbuf + param->srvoffset,(!param->waitserver64 || (param->waitserver64 - received) > (param->srvinbuf - param->srvoffset))? param->srvinbuf - param->srvoffset : (int)(param->waitserver64 - received), 0, (struct sockaddr*)¶m->sinc, sasize); +#else res = so._sendto(param->clisock, param->srvbuf + param->srvoffset,(!param->waitserver || ((unsigned)param->waitserver - received) > (param->srvinbuf - param->srvoffset))? param->srvinbuf - param->srvoffset : param->waitserver - received, 0, (struct sockaddr*)¶m->sinc, sasize); +#endif if(res < 0) { if(errno != EAGAIN) return 96; continue; @@ -136,7 +175,11 @@ int sockmap(struct clientparam * param, int timeo){ param->srvoffset += res; received += res; if(param->srvoffset == param->srvinbuf) param->srvoffset = param->srvinbuf = 0; +#ifndef NOPSTDINT + if(param->waitserver64 && param->waitserver64<= received){ +#else if(param->waitserver && param->waitserver<= received){ +#endif return (98); } if(param->service == S_UDPPM && param->srv->singlepacket) { @@ -153,17 +196,26 @@ int sockmap(struct clientparam * param, int timeo){ sl1 = (*param->bandlimfunc)(param, 0, param->cliinbuf - param->clioffset); if(sl1 > sleeptime) sleeptime = sl1; } +#ifndef NOPSTDINT + res = so._sendto(param->remsock, param->clibuf + param->clioffset, (!param->waitclient64 || (param->waitclient64 - sent) > (param->cliinbuf - param->clioffset))? param->cliinbuf - param->clioffset : (int)(param->waitclient64 - sent), 0, (struct sockaddr*)¶m->sins, sasize); +#else res = so._sendto(param->remsock, param->clibuf + param->clioffset, (!param->waitclient || ((unsigned)param->waitclient - sent) > (param->cliinbuf - param->clioffset))? param->cliinbuf - param->clioffset : param->waitclient - sent, 0, (struct sockaddr*)¶m->sins, sasize); +#endif if(res < 0) { if(errno != EAGAIN) return 97; continue; } param->clioffset += res; - sent += res; - param->statscli += res; - param->nwrites++; if(param->clioffset == param->cliinbuf) param->clioffset = param->cliinbuf = 0; + sent += res; + param->nwrites++; +#ifndef NOPSTDINT + param->statscli64 += res; + if(param->waitclient64 && param->waitclient64<= sent) { +#else + param->statscli += res; if(param->waitclient && param->waitclient<= sent) { +#endif return (99); } } @@ -215,7 +267,11 @@ int sockmap(struct clientparam * param, int timeo){ } param->srvinbuf += res; param->nreads++; +#ifndef NOPSTDINT + param->statssrv64 += res; +#else param->statssrv += res; +#endif if(!param->nolongdatfilter){ action = handledatfltsrv(param, ¶m->srvbuf, ¶m->srvbufsize, param->srvinbuf - res, ¶m->srvinbuf); if(action == HANDLED){ @@ -237,26 +293,42 @@ int sockmap(struct clientparam * param, int timeo){ #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "finished with mapping"); #endif +#ifndef NOPSTDINT + while(!param->waitclient64 && param->srvinbuf > param->srvoffset && param->clisock != INVALID_SOCKET){ +#else while(!param->waitclient && param->srvinbuf > param->srvoffset && param->clisock != INVALID_SOCKET){ +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "flushing buffer to client"); #endif res = socksendto(param->clisock, ¶m->sinc, param->srvbuf + param->srvoffset, param->srvinbuf - param->srvoffset, conf.timeouts[STRING_S] * 1000); if(res > 0){ param->srvoffset += res; +#ifndef NOPSTDINT + param->statssrv64 += res; +#else param->statssrv += res; +#endif if(param->srvoffset == param->srvinbuf) param->srvoffset = param->srvinbuf = 0; } else break; } +#ifndef NOPSTDINT + while(!param->waitserver64 && param->cliinbuf > param->clioffset && param->remsock != INVALID_SOCKET){ +#else while(!param->waitserver && param->cliinbuf > param->clioffset && param->remsock != INVALID_SOCKET){ +#endif #if DEBUGLEVEL > 2 (*param->srv->logfunc)(param, "flushing buffer to server"); #endif res = socksendto(param->remsock, ¶m->sins, param->clibuf + param->clioffset, param->cliinbuf - param->clioffset, conf.timeouts[STRING_S] * 1000); if(res > 0){ param->clioffset += res; +#ifndef NOPSTDINT + param->statscli64 += res; +#else param->statscli += res; +#endif if(param->cliinbuf == param->clioffset) param->cliinbuf = param->clioffset = 0; } else break; diff --git a/src/socks.c b/src/socks.c index ca3e5b7..e53250b 100644 --- a/src/socks.c +++ b/src/socks.c @@ -339,7 +339,11 @@ fflush(stderr); param->res = 467; break; } +#ifndef NOPSTDINT + param->statscli64+=(len - i); +#else param->statscli+=(len - i); +#endif param->nwrites++; #if SOCKSTRACE > 1 fprintf(stderr, "UDP packet relayed from client to %s:%hu size %d, header %d\n", @@ -366,7 +370,11 @@ fflush(stderr); param->res = 468; break; } +#ifndef NOPSTDINT + param->statssrv64+=len; +#else param->statssrv+=len; +#endif param->nreads++; memcpy(buf+4, &tsin.sin_addr.s_addr, 4); memcpy(buf+8, &tsin.sin_port, 2); diff --git a/src/structures.h b/src/structures.h index 52d8dee..a6e964f 100644 --- a/src/structures.h +++ b/src/structures.h @@ -6,6 +6,9 @@ #include #include #include +#ifndef NOPSTDINT +#include "pstdint.h" +#endif #ifdef __cplusplus extern "C" { #endif @@ -257,10 +260,15 @@ struct trafcount { struct ace *ace; unsigned number; ROTATION type; +#ifndef NOPSTDINT + uint64_t traf64; + uint64_t traflim64; +#else unsigned long traf; unsigned long trafgb; unsigned long traflim; unsigned long traflimgb; +#endif char * comment; int disabled; time_t cleared; @@ -377,8 +385,13 @@ struct clientparam { int res, status; +#ifndef NOPSTDINT + uint64_t waitclient64, + waitserver64; +#else unsigned waitclient, waitserver; +#endif int pwtype, threadid, weight, @@ -402,16 +415,28 @@ struct clientparam { srvoffset, clibufsize, srvbufsize, - msec_start, + msec_start; +#ifndef NOPSTDINT + uint64_t + maxtrafin64, + maxtrafout64; +#else + unsigned maxtrafin, maxtrafout; - +#endif struct sockaddr_in sinc, sins, req; +#ifndef NOPSTDINT + uint64_t statscli64, + statssrv64; +#else unsigned long statscli, - statssrv, + statssrv; +#endif + unsigned long nreads, nwrites, nconnects, @@ -634,6 +659,7 @@ typedef enum { TYPE_SHORT, TYPE_CHAR, TYPE_UNSIGNED, + TYPE_UNSIGNED64, TYPE_TRAFFIC, TYPE_PORT, TYPE_IP, diff --git a/src/webadmin.c b/src/webadmin.c index ad47b52..516a04b 100644 --- a/src/webadmin.c +++ b/src/webadmin.c @@ -475,6 +475,18 @@ void * adminchild(struct clientparam* param) { ); } else { +#ifndef NOPSTDINT + inbuf += sprintf(buf+inbuf, + "%"PRINTF_INT64_MODIFIER"u" + "MB%s" + "%"PRINTF_INT64_MODIFIER"u" + "%s", + cp->traflim64, + rotations[cp->type], + cp->traf64, + cp->cleared?ctime(&cp->cleared):"never" + ); +#else inbuf += sprintf(buf+inbuf, "%.3f" "MB%s" @@ -485,6 +497,7 @@ void * adminchild(struct clientparam* param) { (1024.0 * (float)cp->trafgb) + (float)cp->traf/1048576.0, cp->cleared?ctime(&cp->cleared):"never" ); +#endif inbuf += sprintf(buf + inbuf, "%s" "%i"