static void http_ws_handle_message(http_connection *c,ws_frame *msg){

	if(c->cgi.function!=NULL){

		//put frame on argument
		c->cgi.argument=(void *)msg;
		//call cgi
		int r = c->cgi.function(c);
		int sent = http_transmit(c);

		if(r==HTTP_WS_CGI_DONE){
			//we should close the socket
			c->cgi.done=1;

			if(sent==0){
				//we should active close it now as no data was sent, so there will be no further callback
				//TODO send close frame instead of hard closing
				espconn_disconnect(c->espConnection);
				http_process_free_connection(c);	
			}
		}

		
	}

}
void ICACHE_FLASH_ATTR http_ws_push_bin(http_connection *c,char *msg,size_t msgLen){

	ws_frame frame;
	ws_output_frame(&frame,WS_BINARY,msg,msgLen);
	ws_write_frame(&frame,ws_output_write_function,c);
	http_transmit(c);
	
}
示例#3
0
// Called after cgi execution to flush any data
void ICACHE_FLASH_ATTR http_send_response(http_connection * conn){

	NODE_DBG("http_send_response");
	int sent = http_transmit(conn);

	//any data sent?
	if(sent == 0){
		//if there was no data sent and cgi is done, we should destroy the connection
		if (conn->cgi.done==1) { 
			NODE_DBG("Conn %p is done. Closing.", conn->espConnection);
			espconn_disconnect(conn->espConnection);
			http_process_free_connection(conn);				
			return; 
		}

	}	

}
示例#4
0
// Called after cgi execution to flush any data
void http_send_response(http_connection * conn)
{
	HTTP_DBG("http_send_response\n");
	int sent = http_transmit(conn);

	//any data sent?
	if(sent == 0)
	{
		HTTP_DBG("\tno data sent\n");
		//if there was no data sent and cgi is done, we should destroy the connection
		if (conn->cgi.done==1)
		{
			HTTP_DBG("\t\tConn %p is done. Closing.\n", conn->espConnection);
			espconn_disconnect(conn->espConnection);
			http_process_free_connection(conn);
			return;
		}
	}
}
static int ICACHE_FLASH_ATTR http_ws_cgi_execute(http_connection * c){

	NODE_DBG("http_ws_cgi_execute c =%p",c);

	if(!c->handshake_ok)
	{
		int r = http_ws_handle_connect(c);
		if(r==HTTP_WS_CGI_DONE)
			c->cgi.done=1; //mark for destruction
		
		http_transmit(c);
	}
	else{

		if(c->body.data==NULL){

			if(c->state==HTTPD_STATE_WS_DATA_SENT){
				if(data_sent_callback!=NULL)
					data_sent_callback(c);					
			}
			
		}
		else if(c->state==HTTPD_STATE_WS_DATA){

			NODE_DBG("websocket frame size %d",c->body.len);

			ws_frame frame;
			ws_parse_frame(&frame,c->body.data,c->body.len);


			switch(frame.TYPE){

				case WS_INVALID:
					NODE_DBG("\treceived invalid frame");
					break;
				case WS_PING:
					//send ping
					ws_output_frame(&frame,WS_PING,"PING",strlen("PING"));
					ws_write_frame(&frame,ws_output_write_function,c);
					http_transmit(c);
				case WS_CLOSE:
					//send close back
					ws_output_frame(&frame,WS_PING,"\0\0",2);
					ws_write_frame(&frame,ws_output_write_function,c);
					http_transmit(c);
					//mark as done
					c->cgi.done=1;
					break;
				case WS_TEXT:
				case WS_BINARY:
					http_ws_handle_message(c,&frame);
					break;
				case WS_CONTINUATION:
					break; // TODO: Implement continuation logic

			}		


		}
		else if(c->state == HTTPD_STATE_WS_CLIENT_DISCONNECT){

			if(client_disconnected_callback!=NULL)
				client_disconnected_callback(c);
		}

		return 1;

	}

}