diff --git a/source/bforce/TODO_netspool b/source/bforce/TODO_netspool index cabee2b..01ad5bb 100644 --- a/source/bforce/TODO_netspool +++ b/source/bforce/TODO_netspool @@ -2,3 +2,7 @@ tx_zmodem rx_zmodem hydra binkp_transfer + + + all of then do use p_tx_readfile + \ No newline at end of file diff --git a/source/bfutil/netspool.c b/source/bforce/netspool.c similarity index 52% rename from source/bfutil/netspool.c rename to source/bforce/netspool.c index 39e3504..cf3a085 100644 --- a/source/bfutil/netspool.c +++ b/source/bforce/netspool.c @@ -8,41 +8,41 @@ #include #include -const char *RHOST = "::ffff:172.31.251.3"; +#include "netspool.h" + +const char *RHOST = "172.31.251.3"; const char *RPORT = "24555"; -#define STRBUF (1024) -void readstr(int s, char *buf, int len) { +int readstr(int s, char *buf, int len) { char c=0; int r; while(1) { r=recv(s, &c, 1, 0); if(r==0){ puts("remote socket shutdown"); - exit(-3); + return -3; } if(r==-1){ puts("error reading string"); printf("%d %s\n", errno, strerror(errno)); - exit(-3); + return -3; } if(c=='\n') { *buf=0; - return; + break; } *buf++=c; - if(c=='\n') - return; len--; if(!len) { puts("string buffer overflow"); - exit(-3); + return -3; } } + return 0; } -void sendstr(int s, const char *buf) { +int sendstr(int s, const char *buf) { int l = strlen(buf); int c; char nl='\n'; @@ -51,11 +51,11 @@ void sendstr(int s, const char *buf) { if(c==-1){ puts("error sending string"); printf("%d %s\n", errno, strerror(errno)); - exit(-3); + return -3; } if(c==0){ puts("zero send: may loop infinitely"); - exit(-3); + return -3; } l-=c; } @@ -63,15 +63,132 @@ void sendstr(int s, const char *buf) { if(c==-1){ puts("error sending string"); printf("%d %s\n", errno, strerror(errno)); - exit(-3); + return -3; } if(c==0){ puts("zero send: may loop infinitely"); - exit(-3); + return -3; } + return 0; +} + + + +void netspool_start(s_netspool_state *state, const char *host, const char *port, const char *address, const char *password) +{ + int s, r; + struct addrinfo hint; + struct addrinfo *addrs, *a; + char strbuf[STRBUF]; + + s = socket(AF_INET6, SOCK_STREAM, 0); + state->socket = s; + if( s==-1 ) + { + state->state = NS_ERROR; + state->error = "socket error"; + return; + } + + memset(&hint, 0, sizeof(struct addrinfo)); + hint.ai_socktype = SOCK_STREAM; + hint.ai_family = PF_INET6; + hint.ai_flags = AI_V4MAPPED; + + r = getaddrinfo(host, port!=NULL? port: "24555", &hint, &addrs); + + if( r ) { + state->state = NS_ERROR; + state->error = gai_error(r); + return; + } + + a=addrs; + r=-1; + while(a) { + r = connect(s, a->ai_addr, a->ai_addrlen); + if(r==-1) { + printf("%d %s\n", errno, strerror(errno)); + } else { + break; + } + a=a->ai_next; + } + freeaddrinfo(addrs); + + if(r==-1) { + state->state = NS_ERROR; + state->error = "could not connect\n" + return; + } + + r = readstr(s, strbuf, STRBUF); + if( r ) { state->state = NS_ERROR; state->error = "IO error"; } + puts(strbuf); + + snprintf(strbuf, STRBUF, "ADDRESS %s", address); + r = sendstr(s, strbuf); + if( r ) { state->state = NS_ERROR; state->error = "IO error"; } + + snprintf(strbuf, STRBUF, "PASSWORD %s", password); + r = sendstr(s, strbuf); + if( r ) { state->state = NS_ERROR; state->error = "IO error"; } + + state->state = NS_READY; +} + +void netspool_query(s_netspool_state *state, const char *what) +{ + int r = sendstr(state->socket, "GET ALL"); + if( r ) { + state->state = NS_ERROR; + state->error = "IO error"; + return; + } + state->state = NS_RECEIVING; +} + +void netspool_receive(s_netspool_state *state) +{ + char strbuf[STRBUF]; + int r; + + r = readstr(s, strbuf, STRBUF); + if( r ) { state->state = NS_ERROR; state->error = "IO error"; return; } + puts(strbuf); + if(strcmp(strbuf, "QUEUE EMPTY")==0) { + state->state = NS_READY; + return; + } + + if(strncmp(strbuf, "FILENAME ", 9)==0) { + strcpy(filename, strbuf+9); + puts(filename); + } else { + state->state = NS_ERROR; + state->error = "expected filename or queue empty" + return; + } + + r = readstr(s, strbuf, STRBUF); + if( r ) { state->state = NS_ERROR; state->error = "IO error"; return; } + if(strncmp(strbuf, "BINARY ", 7)==0) { + /*if(filename[0]==0) { + puts("no filename"); + exit(-5); + } */ + sscanf(strbuf+7, "%Lu", &state->length); + printf("length=%Lu\n", state->length); + state->state = NS_RECVFILE; + } else { + state->state = NS_ERROR; + state->error = "expected binary" + return; + } } +/* void savefile(const char *fn, unsigned long long l, int s) { char BUF[STRBUF]; @@ -105,64 +222,15 @@ void savefile(const char *fn, unsigned long long l, int s) close(f); } + void main() { - int s, r; - struct addrinfo hint; - struct addrinfo *addrs, *a; - char strbuf[STRBUF]; char filename[STRBUF]; unsigned long long length; - s = socket(AF_INET6, SOCK_STREAM, 0); - - memset(&hint, 0, sizeof(struct addrinfo)); - hint.ai_socktype = SOCK_STREAM; - r = getaddrinfo(RHOST, RPORT, &hint, &addrs); - if( r ) { - puts(gai_strerror(r)); - exit(-1); - } - - a=addrs; - r=-1; - while(a) { - r = connect(s, a->ai_addr, a->ai_addrlen); - if(r==-1) { - printf("%d %s\n", errno, strerror(errno)); - } else { - break; - } - a=a->ai_next; - } - if(r==-1) { - printf("could not connect\n"); - exit(-2); - } - freeaddrinfo(addrs); - readstr(s, strbuf, STRBUF); - puts(strbuf); - sendstr(s, "ADDRESS 2:111/11"); - sendstr(s, "PASSWORD 123"); - sendstr(s, "GET ALL"); filename[0]=0; while(1) { - readstr(s, strbuf, STRBUF); - puts(strbuf); - if(strcmp(strbuf, "QUEUE EMPTY")==0) break; - if(strncmp(strbuf, "FILENAME ", 9)==0) { - strcpy(filename, strbuf+9); - puts(filename); - continue; - } - if(strncmp(strbuf, "BINARY ", 7)==0) { - if(filename[0]==0) { - puts("no filename"); - exit(-5); - } - sscanf(strbuf+7, "%Lu", &length); - printf("length=%Lu\n", length); savefile(filename, length, s); sprintf(strbuf, "DONE %s", filename); sendstr(s, strbuf); @@ -178,3 +246,4 @@ void main() { close(s); } +*/ diff --git a/source/bforce/prot_common.c b/source/bforce/prot_common.c index fe36cb9..ba9237d 100644 --- a/source/bforce/prot_common.c +++ b/source/bforce/prot_common.c @@ -40,13 +40,15 @@ const char *Protocols[] = * Return value: * Zero value on success and non-zero if nothing to send */ -static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_fsqueue *q) +static int prot_get_next_file(s_filelist **dest, s_protinfo *pi) { s_filelist *ptrl = NULL; s_filelist *best = NULL; + s_fsqueue *q = &state.queue; *dest = NULL; - + + /* local queue */ for( ptrl = q->fslist; ptrl; ptrl = ptrl->next ) if( ptrl->status == STATUS_WILLSEND ) { @@ -97,6 +99,44 @@ static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_fsqueue *q) return 0; } + /* network queue */ +#ifdef NETSPOOL + + if(state.netspool.state == NS_NOTINIT) { + char password[9]; + char address[300]; + char *host = conf_string(cf_netspool_host); + char *port = conf_string(cf_netspool_port); + if(host==NULL) { + state.netspool.state = NS_UNCONF; + } else { + snprintf(address, 299, state.node.addr.point? "%d:%d/%d.%d": "%d.%d.%d", + state.node.addr.zone, state.node.addr.net, + state.node.addr.node, state.node.addr.point); + if(state.protected) { + session_get_password(state.node.addr, password, 8); + } else { + password[0] = 0; + } + netspool_start(&state.netspool, host, port, address, password); + } + } + + if(state.netspool_state == NS_READY) { + netspool_query(&state.netspool, "ALL"); + } + + if(state.netspool_state == NS_RECEIVING) { + netspool_receive(&state.netspool); + } + + if(state.netspool_state == NS_RECVFILE) { + *dest = NULL; + return 0; + } + +#endif + return 1; } @@ -159,7 +199,7 @@ int p_tx_fopen(s_protinfo *pi) return 1; get_next_file: - if( prot_get_next_file(&ptrl, pi, &state.queue) || !ptrl ) + if( prot_get_next_file(&ptrl, pi) || !ptrl ) return 1; /* Mark this file as "processed" */ diff --git a/source/include/confread.h b/source/include/confread.h index 7f9e899..547d89c 100644 --- a/source/include/confread.h +++ b/source/include/confread.h @@ -271,7 +271,10 @@ typedef enum { cf_debug_level, #endif cf_split_inbound, - cf_netspool, +#ifdef NETSPOOL + cf_netspool_host, + cf_netspool_port, +#endif BFORCE_NUMBER_OF_KEYWORDS } bforce_config_keyword; diff --git a/source/include/netspool.h b/source/include/netspool.h new file mode 100644 index 0000000..7c5be8d --- /dev/null +++ b/source/include/netspool.h @@ -0,0 +1,20 @@ + + +#define NS_NOTINIT (0) +#define NS_UNCONF (1) +#define NS_ERROR (2) +#define NS_READY (3) +#define NS_RECEIVING (4) +#define NS_RECVFILE (5) +#define NS_CLOSED (6) + +#define STRBUF (1024) + +typedef struct { + int state; + char *error; + int socket; + int filename[STRBUF]; + unsigned long long length; +} s_netspool_state; + diff --git a/source/include/session.h b/source/include/session.h index f67d1fb..f1ed013 100644 --- a/source/include/session.h +++ b/source/include/session.h @@ -22,6 +22,10 @@ #include "outbound.h" #include "prot_common.h" +#ifdef NETSPOOL +#include "netspool.h" +#endif + typedef enum session { SESSION_UNKNOWN, SESSION_FTSC, @@ -155,6 +159,9 @@ const s_modemport *modemport; s_falist *mailfor; /* Remote valid addresses */ s_fsqueue queue; /* Send files queue */ +#ifdef NETSPOOL + s_netspool_state netspool; +#endif }; typedef struct state s_state; @@ -194,7 +201,7 @@ int session_check_addr(s_faddr addr); int session_get_password(s_faddr addr, char *buffer, size_t buflen); int session_remote_lookup(s_sysaddr *addrs, int anum); void session_remote_log_status(void); -int session_check_password(s_faddr addr, const char *passwd); +/*int session_check_password(s_faddr addr, const char *passwd); seems not used*/ int session_set_inbound(void); void session_set_freqs_status(void); void session_set_send_options(void);