Пример #1
0
int ftp_receive_file(char *filename, char *command)
{
	int rc,state;
	int dtp=E_REFUSE;

	if (ftp_use_port!='Y') { dtp = ftp_passive_connect(); }
/*	if (dtp==E_REFUSE) { dtp = ftp_listen_connect(); } */
	if (dtp==E_REFUSE) { dtp = ftp_port_connect(); }
	if (dtp>=0) {
		rc = news_send_command( fpi, command );
/*		rc=CNbyte_count(dtp);
		fprintf( log, "Pre-Listen CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
*/
		if (CNbyte_count( dtp )==E_LISTEN) {
			if ((state=ftp_listen( dtp ))>=0) {	state = E_NORMAL; }
		} else {
			state = TCP_wait_state( dtp, TESTABLISH, 15 );
		}
		if (state==E_NORMAL) {
			rc = ftp_receive_continuations( fpi, "dummy", FALSE );
			rc = news_receive( dtp, filename, 2 );
		} else {
			fprintf( log, "TCP_wait_state returns %s \n", get_err_text(state));
			rc=CNbyte_count(dtp);
			fprintf( log, "CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
			rc = state;
		}
		TCP_close( dtp, 5 );	/* wait for connection to close */
	} else {
		fprintf( log, "open_connection returns %s \n", get_err_text(dtp));
		rc = dtp;
	}
	return(rc);
}
Пример #2
0
int ftp_quit(void)
{
	int rc;

	rc = news_send_command( fpi, "QUIT" );
	rc = ftp_receive_continuations( fpi, "dummy", FALSE );
	rc = (int16)TCP_close(fpi, 5);	/* close connection locally */
	fpi= NO_CONNECTION;
	return(rc);
}
Пример #3
0
int news_quit()
{
	int rc;

	rc = news_send_command( ncn, "quit" );
	rc = news_receive( ncn, "dummy", FALSE );
	rc = (int16)TCP_close(ncn, 2);	/* close connection locally */
	ncn= NO_CONNECTION;
	return(rc);
}
Пример #4
0
void closedccchat(short temp)
{
if(chan[temp].stat>2){
TCP_close(chan[temp].cn,1);
chan[temp].stat=0;
chan[temp].cn=0;
dowindinfo(chan[temp].win);
chan[temp].win=-1;
strcpy(chan[temp].name,"\0");
}
}
Пример #5
0
int imap_logout(void)
{
	int rc;
	char command[80];

	sprintf( command, "%s LOGOUT", imap_next_id());
	rc = news_send_command( imapi, command );
	rc = imap_receive_continuations( imapi, "dummy", FALSE, command );
	rc = (int16)TCP_close(imapi, 5);	/* close connection locally */
	imapi= NO_CONNECTION;
	return(rc);
}
Пример #6
0
int resetadcc(short num,char swt){
if(dcc[num].dcfh){Fclose(dcc[num].dcfh);dcc[num].dcfh=-1;}
if(dcc[num].cn)TCP_close(dcc[num].cn,1);
if(is_dw_open(dcc[num].dcw) && !swt)wd_close(dcc[num].dcw);
dcc[num].cn=0;
dcc[num].dcfh=-1;
dcc[num].stat=0;
dcc[num].cnt=0;
dcc[num].lack=0;
dcc[num].dir=-1;
return 0;
}
Пример #7
0
static void
cmd_http_accept(CMD_ARGS)
{
	struct http *hp;

	(void)cmd;
	(void)vl;
	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
	AZ(av[1]);
	assert(hp->sfd >= 0);
	TCP_close(&hp->fd);
	vtc_log(vl, 4, "Accepting");
	hp->fd = accept(hp->sfd, NULL, NULL);
	if (hp->fd < 0)
		vtc_log(vl, 0, "Accepted failed: %s", strerror(errno));
	vtc_log(vl, 3, "Accepted socket fd is %d", hp->fd);
}
Пример #8
0
/**
  * @brief  This function implements the tcp_sent LwIP callback (called when ACK
  *         is received from remote host for sent data) 
  * @param  None
  * @retval None
  */
static err_t 
	TCP_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) {
		TCP *es;

		LWIP_UNUSED_ARG(len);

		es = (TCP *)arg;
		
		if (es->tx != NULL) {													/* still got pbufs to send */
				tcp_sent(es->pcb, TCP_sent);
				TCP_send(es->pcb, es);
		} else {																			/* if no more data to send and client closed connection*/
			if (es->state == ES_CLOSING) {
				TCP_close(tpcb, es);
			}
		}
		return ERR_OK;
	}
void
VBE_ClosedFd(struct sess *sp)
{
	struct backend *bp;

	CHECK_OBJ_NOTNULL(sp->vbe, VBE_CONN_MAGIC);
	CHECK_OBJ_NOTNULL(sp->vbe->backend, BACKEND_MAGIC);
	assert(sp->vbe->fd >= 0);

	bp = sp->vbe->backend;

	WSL(sp->wrk, SLT_BackendClose, sp->vbe->fd, "%s", bp->vcl_name);
	TCP_close(&sp->vbe->fd);
	VBE_DropRefConn(bp);
	sp->vbe->backend = NULL;
	VBE_ReleaseConn(sp->vbe);
	sp->vbe = NULL;
}
Пример #10
0
int close_socket(int cn)
	{
	int tstat,i,j;
	char out[80];

	tstat = (int)TCP_close(cn, 0);
	  /**/ sprintf(out, "%s", get_err_text(tstat));
	wind_set(win.handle, WF_INFO, (short)((long)out>>16), (short)(out), NULL,
 NULL);/**/
		sprintf(out, "Closing connection");
		wind_set(win.handle, WF_INFO, (short)((long)out>>16), (short)(out), NULL, NULL);
		menu_ienable(menu_ptr,OpenHostO,1);
		menu_ienable(menu_ptr,CloseC,0);
		menu_ienable(menu_ptr,OpenLocalL,1);
for (i=0;i<=10000;i++)
	{for (j=0; j<=100;j++);}
	return (tstat);
}
Пример #11
0
int resetdccs(){
short temp=9;
while(temp>-1){
if(dcc[temp].dcfh){Fclose(dcc[temp].dcfh);dcc[temp].dcfh=-1;}
if(dcc[temp].cn)TCP_close(dcc[temp].cn,1);
strcpy(dcc[temp].avec,"\0");
strcpy(dcc[temp].fname,"\0");

dcc[temp].cn=0;
dcc[temp].dcfh=-1;
dcc[temp].stat=0;
dcc[temp].cnt=0;
dcc[temp].lack=0;
dcc[temp].dir=-1;
temp--;
}

return 0;
}
Пример #12
0
/**
  * @brief  This function is the implementation for tcp_recv LwIP callback
  * @param  arg: pointer on a argument for the tcp_pcb connection
  * @param  tpcb: pointer on the tcp_pcb connection
  * @param  pbuf: pointer on the received pbuf
  * @param  err: error information regarding the reveived pbuf
  * @retval err_t: error code
  */
static err_t 
	TCP_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) {
		err_t ret_err;
		TCP *es;

		LWIP_ASSERT("arg != NULL",arg != NULL);
		
		es = (TCP *)arg;
		
		if (p == NULL) {															/* if we receive an empty tcp frame from client => close connection */  
			es->state = ES_CLOSING;											/* remote host closed connection */
			if (es->tx == NULL) {
				TCP_close(tpcb, es); 											/* we're done sending, close connection */
			} else {																		/* we're not done yet */
				tcp_sent(tpcb, TCP_sent); 								/* send remaining data*/
				TCP_send(tpcb, es);												/* acknowledge received packet */
			}
			ret_err = ERR_OK;
		} else if(err != ERR_OK) { 										/* else : a non empty frame was received from client but for some reason err != ERR_OK */
			if (p != NULL) {
				es->tx = NULL;
				pbuf_free(p); /* free received pbuf*/
			}
			ret_err = err;
		} else if(es->state == ES_ACCEPTED) { 				/* first data chunk in p->payload */
			es->state = ES_RECEIVED;
			es->rx = p;																	/* store reference to incoming pbuf (chain) */
			ret_err = ERR_OK;
		} else if (es->state == ES_RECEIVED) {
			if (es->rx)
				pbuf_chain(es->rx,p);
			else
				es->rx = p;
			ret_err = ERR_OK;
		} else { 																			/* data received when connection already closed */
			tcp_recved(tpcb, p->tot_len);								/* Acknowledge data reception */
			es->tx = NULL;
			pbuf_free(p);																/* free pbuf and do nothing */
			ret_err = ERR_OK;
		}
		return ret_err;
	}
Пример #13
0
/**
  * @brief  This function implements the tcp_poll LwIP callback function
  * @param  arg: pointer on argument passed to callback
  * @param  tpcb: pointer on the tcp_pcb for the current tcp connection
  * @retval err_t: error code
  */
static err_t 
	TCP_poll(void *arg, struct tcp_pcb *tpcb) {
		err_t ret_err;
		TCP *es;

		es = (TCP *)arg;
		if (es != NULL) {
			if (es->tx != NULL) { 											/* there is a remaining pbuf (chain) , try to send data */
				TCP_send(tpcb, es);
			} else {																		/* no remaining pbuf (chain)  */
				if (es->state == ES_CLOSING) {
					TCP_close(tpcb, es);										/*  close tcp connection */
				}
			}
			ret_err = ERR_OK;
		} else {
			tcp_abort(tpcb);														/* nothing to be done */
			ret_err = ERR_ABRT;
		}
		return ret_err;
	}
Пример #14
0
void test01(WORD testNo, char *testName, BYTE tcpNotUdp, DWORD *blockSizes, WORD blockSizesCount)
{
    DWORD start = getTicks();

    //----------
    out_test_header(testNo, testName);          // show test header
    
    //----------
    // find out the largest block size
    int i;
    int maxBlockSize = 0;

    for(i=0; i<blockSizesCount; i++) {
        if(maxBlockSize < (int)blockSizes[i]) {      // if current max block size is smaller than this block size, store it
            maxBlockSize = blockSizes[i];
        }
    }
    //----------
    // open socket
    int handle;
    
    if(tcpNotUdp) {
        handle = TCP_open(SERVER_ADDR, SERVER_PORT_START, 0, maxBlockSize);
    } else {
        handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4);
    }
    
    if(handle < 0) {
        out_result_string(0, "TCP/UDP open() failed");
        return;
    }

    //----------
    // if TCP (not UDP), wait for connected state
    if(tcpNotUdp) {
        // wait until connected
        int res;

        while(1) {
            res = TCP_wait_state(handle, TESTABLISH, 1);
        
            if(res == E_NORMAL) {
                break;
            }

            DWORD now = getTicks();
            if((now - start) > 5*200) {
                out_result_string(0, "TCP_wait_state() timeout");
                goto test01close;
            }
        }
        
        if(res != E_NORMAL) {
            out_result_error_string(0, res, "TCP_wait_state() failed");
            goto test01close;
        }
    }
    
    //---------------------
    int res;
    
    for(i=0; i<blockSizesCount; i++) {
        res = sendAndReceive(tcpNotUdp, blockSizes[i], handle, 1);
    
        if(!res) {                              // if single block-send-and-receive operation failed, quit and close
            goto test01close;
        }
    }
    
    //---------------------
    
    out_result(1);                              // success!
    
test01close:
    if(tcpNotUdp) {
        res = TCP_close(handle, 0, 0);          // close
    } else {
        res = UDP_close(handle);                // close
    }
    
    if(res != E_NORMAL) {
        out_result_error_string(0, res, "TCP/UDP close() failed");
    }
}
Пример #15
0
int ftp_send_file(char *filename, char *command)
{
	int rc,state,x;
	size_t bytes,total=0,timeout;
	char buff[512];
	FILE *fid;
	int dtp=E_REFUSE;

	if (ftp_use_port!='Y') { dtp = ftp_passive_connect(); }
/*	if (dtp==E_REFUSE) { dtp = ftp_listen_connect(); } */
	if (dtp==E_REFUSE) { dtp = ftp_port_connect(); }
	if (dtp>=0) {
		rc= ftp_allocate(filename);
		rc= news_send_command( fpi, command );
/*		rc=CNbyte_count(dtp);
		fprintf( log, "Pre-Listen CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
*/
		if (CNbyte_count( dtp )==E_LISTEN) {
			if ((state=ftp_listen( dtp ))>=0) { state = E_NORMAL; }
		} else {
			state = TCP_wait_state( dtp, TESTABLISH, 15 );
		}
		if (state==E_NORMAL) {
			rc = ftp_receive_continuations( fpi, "dummy", FALSE );
			fid = fopen( filename, "rb" );
			if (fid!=NULL) {
				while ((bytes=fread( buff, 1, 512, fid))>0) {
					timeout=clock()+max_to*CLK_TCK;	/* timeout */
					do {
						x = TCP_send( dtp, buff, (int16)bytes );
						if (x!=0) {
							if (clock()>timeout) {
								if (x==E_OBUFFULL) { bytes=-FTP_OBUFF_SIZE; }
								x=E_CNTIMEOUT;
							}
						}
						if (handle_escape_events()==27) { x=E_USERTIMEOUT; }
 
					/*	if (Bconstat(2)==-1 && (Bconin(2) & 0xFF)==27) { /* Esc key */
					/*		x=E_USERTIMEOUT; } */
					} while (x==E_OBUFFULL);	/* retry if 'Output Buffer full */
					total+=bytes;
					browser->msg_status(8, total);
					if (x<0) {
						fprintf( log, "TCP_send returns %s \n", get_err_text(x));
						browser->msg_status(0, x);
						break;
					}
				}
				fclose( fid );
			}
		} else {
			fprintf( log, "TCP_wait_state returns %s \n", get_err_text(state));
			rc=CNbyte_count(dtp);
			fprintf( log, "CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
			rc = state;
		}
		TCP_close( dtp, 5 );	/* wait for connection to close */
	} else {
		fprintf( log, "open_connection returns %s \n", get_err_text(dtp));
		rc = dtp;
	}
	return(rc);
}
Пример #16
0
static void waitRequests(void)
{
	int16 cnId, state;
	int16 nInQueue;
	int toggle, proceed=1;


	do {				/* listen again */
		if( (cnId = TCP_open(0, LPR_LOC_PORT, 0, tcpBuffSize)) <= 0 ) {
			uiPrintf(uiH, uiPrERR, "waitRequests|TCP_open");
			return;
		}
	
	    if ( (state = TCP_wait_state(cnId, TLISTEN, 30)) < 0 ) {
	        uiPrintf(uiH, uiPrERR, "waitRequests|%s", get_err_text(state));
			return;
	    }
	
	
		toggle = 10;	/* every ten waits look also for an AES message */
		while ( (nInQueue = CNbyte_count(cnId)) != E_EOF ) {	/* poll for input */
	
			/* listening or no data yet cause us to wait */
			if (nInQueue == E_LISTEN || nInQueue == 0 || nInQueue == E_NODATA) {
				if (--toggle>0) {
					uiYield(uiH, YIELDMS);
				} else {
					WORD	msgbuff[8];
					WORD	event;		/* Ergebnis mit Ereignissen */
					WORD	mx, my,		/* Mauskoordinaten */
							mbutton, 	/* Mausknopf */
							mkstate,	/* keyb shift status for mouse button */
							mclicks; 	/* Anzahl Mausklicks */
					UWORD	keycode; 	/* scancode + asciicode */

					toggle=10;
					event = evnt_multi(
						MU_MESAG | MU_TIMER,
						0, 0, 0,
						0, 0, 0, 0, 0,
						0, 0, 0, 0, 0,
						msgbuff,
					  	YIELDMS, 0,
						&mx, &my,
						&mbutton, &mkstate,
						&keycode, &mclicks);

					if ( (event & MU_MESAG) && msgbuff[0] == AP_TERM ) {
						proceed=0;		/* no more new connections */
						break;			/* end listening */
					}
				}

			} else {

				if (nInQueue > 0) {			/* otherwise there is valid data */
					NDB* ndb;
		
					if ( (ndb = CNget_NDB(cnId)) != NULL ) {
						dispatchD(cnId, ndb);
					} else {
				        uiPrintf(uiH, uiPrERR, "waitRequests|get_NDB");
						break;
					}
		
				} else {					/* catch other errors */
					uiPrintf(uiH, uiPrERR, "waitRequests|%s", get_err_text(nInQueue));
					break;
				}	/* if valid data */

			}	/* if any data */
	
		}	/* while wait for a request */
	
	
		TCP_close(cnId, TIMEOUT, NULL);	/* disconnect */

	} while (proceed);	/* while new connection shall be done */


}	/* waitRequests */