Exemple #1
0
/* Simple...								*/
void conn_disconnect( conn_t *conn )
{
	if( conn->proto == PROTO_FTP && !conn->proxy )
		ftp_disconnect( conn->ftp );
	else
		http_disconnect( conn->http );
	conn->fd = -1;
}
Exemple #2
0
void* http_run_thread(void *http_t_as_void) {
	http_t *http = (http_t*) http_t_as_void;

	http_run(http);
	http_disconnect(http);

	draw_commands();
	draw_url_input();
	select_form();
}
Exemple #3
0
/* Simple... */
void conn_disconnect(conn_t *conn)
{
	if (conn->proto == PROTO_FTP && !conn->proxy)
		ftp_disconnect(conn->ftp);
	else
		http_disconnect(conn->http);
#if WIN32
	conn->fd = INVALID_SOCKET;
#else
	conn->fd = -1;
#endif
}
int main(void) {
	http_ctx_t ctx;

	if(false == http_connect(&ctx, "http://board.raidrush.ws/forumdisplay.php")) {
		printf("unable to connect to remote host.\r\n");
		return -1;
	}

	http_option_set(&ctx, LIBNET_HTTP_OPT_PARAM, "f=13");
	http_execute(&ctx);
	http_disconnect(&ctx);

	printf("\r\nLast Error: %s (%d)\n", libnet_str_error(libnet_error_get()), libnet_error_get());

	return 0;
}
int 
dav_disconnect(HTTP_CONNECTION **connection)
{
	return http_disconnect(connection) == HT_OK;
}
int crawler_crawl(link_crawler_t *crawler, char *url, list_t *link_list)
{
    http_url_t http_url;
    int status = CRAWLER_NULL;
    if(http_url_parse_s(&http_url, url) == URL_RECOGNIZED) {
        int port = strlen(http_url.port) != 0 ? atoi(http_url.port) : 80;
        char path[4096] = {""};
        strlen(http_url.search) == 0 ? sprintf(path, "%s", http_url.path) : sprintf(path, "%s?%s", http_url.path, http_url.search);

        if(http_connect(&crawler->http_client, http_url.host, port) == CONNECT_OK) {
            int ecode, response_status;
            const char *page = NULL;
            printf("%s\n", url);
            ecode = http_do_get(&crawler->http_client, path);
            switch(ecode) {
            case RESPONSE_OK:
                response_status = http_response_status(&crawler->http_client);
                if(response_status == HTTP_OK) {
                    /* get entity_body pointer */
                    page = http_response_body(&crawler->http_client);
                    /* extrack link from buffer and save link into list*/
                    if(page != NULL) {
                        extract_absolute_link_s(page, link_list, url);
                        status = CRAWLER_OK;
                    } else {
                        status = CRAWLER_NULL;
                        fprintf(stderr, "Request %s:%d%s failed, response body is null.\n",
                                crawler->http_client.connection.host,
                                crawler->http_client.connection.port, path);
                    }
                } else {
                    fprintf(stderr, "Request %s:%d%s failed, Status code: %d.\n",
                            crawler->http_client.connection.host,
                            crawler->http_client.connection.port, path, response_status);
                    status = CRAWLER_NONEED;
                }
                break;
            case RESPONSE_OVERFLOW:
                fprintf(stderr, "Request %s:%d%s do_get receive overflow.\n",
                        crawler->http_client.connection.host,
                        crawler->http_client.connection.port, path);
                status = CRAWLER_OVERFLOW;
                break;
            case RESPONSE_FAILED:
                fprintf(stderr, "Request %s:%d%s do_get receive break.\n",
                        crawler->http_client.connection.host,
                        crawler->http_client.connection.port, path);
                status = CRAWLER_BREAK;
                break;
            case RESPONSE_TIMEOUT:
                fprintf(stderr, "Request %s:%d%s do_get receive timeout.\n",
                        crawler->http_client.connection.host,
                        crawler->http_client.connection.port, path);
                status = CRAWLER_TIMEOUT;
                break;
            case REQUEST_FAILED:
                fprintf(stderr, "Request %s:%d%s do_get request failed.\n",
                        http_url.host, port, path);
                status = CRAWLER_FAILED;
                break;
            default:
                fprintf(stderr, "Unknown ecode %d.\n", ecode);
                status = CRAWLER_UNKNOWN;
                break;
            }
            http_disconnect(&crawler->http_client);
        } else {
            fprintf(stderr, "Http connect %s:%d failed.\n", http_url.host, port);
            status = CRAWLER_UNREACH;
        }
    } else {
        fprintf(stderr, "Unrecognize url: %s\n", url);
        status = CRAWLER_UNKNOWN;
    }
    return status;
}
Exemple #7
0
void httpServer_run(uint8_t seqnum)
{
	uint8_t s;	// socket number
	uint16_t len;
	uint32_t gettime = 0;

#ifdef _HTTPSERVER_DEBUG_
	uint8_t destip[4] = {0, };
	uint16_t destport = 0;
#endif

	http_request = (st_http_request *)pHTTP_RX;		// Structure of HTTP Request
	parsed_http_request = (st_http_request *)pHTTP_TX;

	// Get the H/W socket number
	s = getHTTPSocketNum(seqnum);

	/* HTTP Service Start */
	switch(getSn_SR(s))
	{
		case SOCK_ESTABLISHED:
			// Interrupt clear
			if(getSn_IR(s) & Sn_IR_CON)
			{
				setSn_IR(s, Sn_IR_CON);
			}

			// HTTP Process states
			switch(HTTPSock_Status[seqnum].sock_status)
			{

				case STATE_HTTP_IDLE :
					if ((len = getSn_RX_RSR(s)) > 0)
					{
						if (len > DATA_BUF_SIZE) len = DATA_BUF_SIZE;
						len = recv(s, (uint8_t *)http_request, len);

						*(((uint8_t *)http_request) + len) = '\0';

						parse_http_request(parsed_http_request, (uint8_t *)http_request);
#ifdef _HTTPSERVER_DEBUG_
						getSn_DIPR(s, destip);
						destport = getSn_DPORT(s);
						printf("\r\n");
						printf("> HTTPSocket[%d] : HTTP Request received ", s);
						printf("from %d.%d.%d.%d : %d\r\n", destip[0], destip[1], destip[2], destip[3], destport);
#endif
#ifdef _HTTPSERVER_DEBUG_
						printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE\r\n", s);
#endif
						// HTTP 'response' handler; includes send_http_response_header / body function
						http_process_handler(s, parsed_http_request);

						gettime = get_httpServer_timecount();
						// Check the TX socket buffer for End of HTTP response sends
						while(getSn_TX_FSR(s) != (getSn_TXBUF_SIZE(s)*1024))
						{
							if((get_httpServer_timecount() - gettime) > 3)
							{
#ifdef _HTTPSERVER_DEBUG_
								printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE: TX Buffer clear timeout\r\n", s);
#endif
								break;
							}
						}

						if(HTTPSock_Status[seqnum].file_len > 0) HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_INPROC;
						else HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE; // Send the 'HTTP response' end
					}
					break;

				case STATE_HTTP_RES_INPROC :
					/* Repeat: Send the remain parts of HTTP responses */
#ifdef _HTTPSERVER_DEBUG_
					printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_INPROC\r\n", s);
#endif
					// Repeatedly send remaining data to client
					send_http_response_body(s, 0, http_response, 0, 0);

					if(HTTPSock_Status[seqnum].file_len == 0) HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE;
					break;

				case STATE_HTTP_RES_DONE :
#ifdef _HTTPSERVER_DEBUG_
					printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_DONE\r\n", s);
#endif
					// Socket file info structure re-initialize
					HTTPSock_Status[seqnum].file_len = 0;
					HTTPSock_Status[seqnum].file_offset = 0;
					HTTPSock_Status[seqnum].file_start = 0;
					HTTPSock_Status[seqnum].sock_status = STATE_HTTP_IDLE;

//#ifdef _USE_SDCARD_
//					f_close(&fs);
//#endif
#ifdef _USE_WATCHDOG_
					HTTPServer_WDT_Reset();
#endif
					http_disconnect(s);
					break;

				default :
					break;
			}
			break;

		case SOCK_CLOSE_WAIT:
#ifdef _HTTPSERVER_DEBUG_
		printf("> HTTPSocket[%d] : ClOSE_WAIT\r\n", s);	// if a peer requests to close the current connection
#endif
			disconnect(s);
			break;

		case SOCK_CLOSED:
#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : CLOSED\r\n", s);
#endif
			if(socket(s, Sn_MR_TCP, HTTP_SERVER_PORT, 0x00) == s)    /* Reinitialize the socket */
			{
#ifdef _HTTPSERVER_DEBUG_
				printf("> HTTPSocket[%d] : OPEN\r\n", s);
#endif
			}
			break;

		case SOCK_INIT:
			listen(s);
			break;

		case SOCK_LISTEN:
			break;

		default :
			break;

	} // end of switch

#ifdef _USE_WATCHDOG_
	HTTPServer_WDT_Reset();
#endif
}
Exemple #8
0
void httpServer_run(uint8_t seqnum)
{
    uint8_t s;	// socket number
    int16_t len;
    //uint32_t gettime = 0;	// 20150828 ## Eric removed

    uint8_t ret = 0;

#ifdef _HTTPSERVER_DEBUG_
    uint8_t destip[4] = {0, };
    uint16_t destport = 0;
#endif

    http_request = (st_http_request *)pHTTP_RX;		// Structure of HTTP Request
    parsed_http_request = (st_http_request *)pHTTP_TX;

    // Get the H/W socket number
    s = getHTTPSocketNum(seqnum);

    /* HTTP Service Start */
    switch(getSn_SR(s))
    {
    case SOCK_ESTABLISHED:
        // Interrupt clear
        if(getSn_IR(s) & Sn_IR_CON)
        {
            setSn_IR(s, Sn_IR_CON);
        }

        // HTTP Process states
        switch(HTTPSock_Status[seqnum].sock_status)
        {

        case STATE_HTTP_IDLE :
            if ((len = getSn_RX_RSR(s)) > 0)
            {
                if (len > DATA_BUF_SIZE) len = DATA_BUF_SIZE;

                // ## 20150828, Eric / Bongjun Hur added
                if ((len = recv(s, (uint8_t *)http_request, len)) < 0) break;	// Exception handler

                ////////////////////////////////////////////////////////////////////////////////
                // Todo; User defined custom command handler (userHandler.c)
                ret = custom_command_handler((uint8_t *)http_request);
                ////////////////////////////////////////////////////////////////////////////////

                if(ret > 0) // Custom command handler
                {
                    // Todo: Users can change this parts for custom function added
                    //if(ret == COMMAND_SUCCESS)		send(s, (uint8_t *)"CMDOK", 5);
                    //else if(ret == COMMAND_ERROR)	send(s, (uint8_t *)"CMDERROR", 8);

                    HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE;
                }
                else // HTTP process handler
                {
                    *(((uint8_t *)http_request) + len) = '\0';	// End of string (EOS) marker
                    parse_http_request(parsed_http_request, (uint8_t *)http_request);
#ifdef _HTTPSERVER_DEBUG_
                    getSn_DIPR(s, destip);
                    destport = getSn_DPORT(s);
                    printf("\r\n");
                    printf("> HTTPSocket[%d] : HTTP Request received ", s);
                    printf("from %d.%d.%d.%d : %d\r\n", destip[0], destip[1], destip[2], destip[3], destport);
#endif

#ifdef _HTTPSERVER_DEBUG_
                    printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE\r\n", s);
#endif
                    // HTTP 'response' handler; includes send_http_response_header / body function
                    http_process_handler(s, parsed_http_request);

                    /*
                    							// ## 20150828 Eric removed
                    							gettime = get_httpServer_timecount();
                    							// Check the TX socket buffer for End of HTTP response sends
                    							while(getSn_TX_FSR(s) != (getSn_TXBUF_SIZE(s)*1024))
                    							{
                    								if((get_httpServer_timecount() - gettime) > 3)
                    								{
                    #ifdef _HTTPSERVER_DEBUG_
                    									printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE: TX Buffer clear timeout\r\n", s);
                    #endif
                    									break;
                    								}
                    							}
                    */

                    if(HTTPSock_Status[seqnum].file_len > 0) HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_INPROC;
                    else HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE; // Send the 'HTTP response' end
                }
            }
            break;


        case STATE_HTTP_RES_INPROC :
            /* Repeat: Send the remain parts of HTTP responses */
#ifdef _HTTPSERVER_DEBUG_
            printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_INPROC\r\n", s);
#endif
            // Repeatedly send remaining data to client
            send_http_response_body(s, 0, http_response, 0, 0);

            if(HTTPSock_Status[seqnum].file_len == 0) HTTPSock_Status[seqnum].sock_status = STATE_HTTP_RES_DONE;
            break;

        case STATE_HTTP_RES_DONE :
#ifdef _HTTPSERVER_DEBUG_
            printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_DONE\r\n", s);
#endif
            // Socket file info structure re-initialize
            HTTPSock_Status[seqnum].file_len = 0;
            HTTPSock_Status[seqnum].file_offset = 0;
            HTTPSock_Status[seqnum].file_start = 0;
            HTTPSock_Status[seqnum].sock_status = STATE_HTTP_IDLE;

//#ifdef _USE_SDCARD_
//					f_close(&fs);
//#endif
#ifdef _USE_WATCHDOG_
            HTTPServer_WDT_Reset();
#endif
            http_disconnect(s);
            break;

        default :
            break;
        }
        break;

    case SOCK_CLOSE_WAIT:
#ifdef _HTTPSERVER_DEBUG_
        printf("> HTTPSocket[%d] : ClOSE_WAIT\r\n", s);	// if a peer requests to close the current connection
#endif
        //disconnect(s);
        http_disconnect(s);
        break;

    case SOCK_INIT:
        listen(s);
        break;

    case SOCK_LISTEN:
        break;

    case SOCK_SYNSENT:
    //case SOCK_SYNSENT_M:
    case SOCK_SYNRECV:
        //case SOCK_SYNRECV_M:
        break;

    case SOCK_CLOSED:
    default :
#ifdef _HTTPSERVER_DEBUG_
        printf("> HTTPSocket[%d] : CLOSED\r\n", s);
#endif
        if(socket(s, Sn_MR_TCP, HTTP_SERVER_PORT, 0x00) == s)    /* Reinitialize the socket */
        {
#ifdef _HTTPSERVER_DEBUG_
            printf("> HTTPSocket[%d] : OPEN\r\n", s);
#endif
        }
        break;
    } // end of switch

#ifdef _USE_WATCHDOG_
    HTTPServer_WDT_Reset();
#endif
}
Exemple #9
0
static int
	http_connect_helper(HTTP_CONNECTION **connection, const char *host, short port, const char *username, const char *password, int lazy)
{
	unsigned int ipaddr = 0;
	struct hostent *hostinfo = NULL;
	HTTP_CONNECTION *new_connection = NULL;
	if(connection == NULL)
	{
		return HT_INVALID_ARGUMENT;
	}
	*connection = NULL;
	if(connection == NULL || host == NULL)
	{
		return HT_INVALID_ARGUMENT;
	}
	new_connection = (HTTP_CONNECTION *) _http_allocator(_http_allocator_user_data, 0, sizeof(HTTP_CONNECTION));
	memset(new_connection, 0, sizeof(HTTP_CONNECTION));
	new_connection->read_count = new_connection->read_index = 0;
	new_connection->address.sin_family = AF_INET;
	new_connection->address.sin_port = htons(port);
	if(username != NULL && password != NULL)
	{
		new_connection->auth_info = (HTTP_AUTH_INFO *) _http_allocator(_http_allocator_user_data, 0, sizeof(HTTP_AUTH_INFO));
		if(new_connection->auth_info == NULL)
		{
			http_disconnect(&new_connection);
			return HT_MEMORY_ERROR;
		}
		memset(new_connection->auth_info, 0, sizeof(HTTP_AUTH_INFO));
		http_add_auth_parameter(new_connection->auth_info, "username", username);
		http_add_auth_parameter(new_connection->auth_info, "password", password);
	}
	if((ipaddr = inet_addr(host)) != INADDR_NONE)
	{
		memcpy(&new_connection->address.sin_addr, &ipaddr, sizeof(struct in_addr));
	}
	else
	{
		hostinfo = (struct hostent *) gethostbyname(host);
		if(hostinfo == NULL)
		{
			return HT_HOST_UNAVAILABLE;
		}
		memcpy(&new_connection->address.sin_addr, hostinfo->h_addr, 4);
	}
	new_connection->host = wd_strdup(host);
	if(new_connection->host == NULL)
	{
		http_disconnect(&new_connection);
		return HT_MEMORY_ERROR;
	}
	if (!lazy)
	{
		new_connection->socketd = socket(AF_INET, SOCK_STREAM, 0);
		if(new_connection->socketd == INVALID_SOCKET)
		{
			http_disconnect(&new_connection);
			return HT_RESOURCE_UNAVAILABLE;
		}
		if(connect(new_connection->socketd, (struct sockaddr *) &new_connection->address, sizeof(struct sockaddr_in)) != 0)
		{
			http_disconnect(&new_connection);
			return HT_NETWORK_ERROR;
		}
		socket_setnonblocking(new_connection->socketd);
	}
	else
	{
		new_connection->socketd = INVALID_SOCKET;
	}
	new_connection->lazy = lazy;
	new_connection->persistent = HT_TRUE;
	new_connection->status = HT_OK;
	*connection = new_connection;
	return HT_OK;
}
Exemple #10
0
int main() {
	int logi, ch, y, x;

	display_log_type = INFO;
	log_init(&log);
	log_register_message_callback(&log, message_logged);

	current_action = NO_ACTION;

	initscr();
	create_windows();
	cdk_screen = initCDKScreen(log_window);
	log_swindow = newCDKSwindow(cdk_screen, 0, 0, log_lines, log_cols, "", 255, 0, 0);

	draw_stdscr();
	draw_url_input();
	draw_commands();

	select_form();

	raw();
	noecho();
	keypad(stdscr, TRUE);

	while ((ch = wgetch(input_window)) != '' || current_action & CANCEL_SHOWING)
		if (ch == KEY_LEFT)
			form_driver(url_form, REQ_LEFT_CHAR);
		else if (ch == KEY_RIGHT)
			form_driver(url_form, REQ_RIGHT_CHAR);
		else if (ch == KEY_BACKSPACE || ch == 127) {
			getyx(input_window, y, x);

			if (x == FIELD_START + 1) {
				form_driver(url_form, REQ_SCR_HBHALF);
				form_driver(url_form, REQ_END_LINE);
			}

			form_driver(url_form, REQ_LEFT_CHAR);
			form_driver(url_form, REQ_DEL_CHAR);
		} else if (ch == KEY_DC)
			form_driver(url_form, REQ_DEL_CHAR);
		else if (ch == KEY_HOME)
			form_driver(url_form, REQ_BEG_FIELD);
		else if (ch == KEY_END)
			form_driver(url_form, REQ_END_FIELD);
		else if (ch == KEY_UP || ch == KEY_DOWN)
			injectCDKSwindow(log_swindow, ch);
		else if (ch == '')
			cleanCDKSwindow(log_swindow);
		else if (ch == '	')
			change_display_log_type(INFO);
		else if (ch == '')
			change_display_log_type(DETAILS);
		else if (ch == '\n' && current_action & URL_INPUTTING) {
			int ret;

			form_driver(url_form, REQ_END_FIELD);
			form_driver(url_form, 'a');
			form_driver(url_form, REQ_VALIDATION);
			strncpy(url, field_buffer(url_field[0], 0), FIELD_BUF_SIZE);
			url[FIELD_BUF_SIZE - 1] = '\0';
			*strrchr(url, 'a') = '\0';

			http_url_init(&http_url);
			if (ret = http_url_parse(&http_url, url)) {
				char *message;

				switch (ret) {
					case INVALID_SERVER_AUTHORITY:
						message = "Invalid server authority";
						break;
					case INVALID_SCHEME:
						message = "Invalid scheme";
						break;
					case INVALID_PORT:
						message = "Invalid port";
						break;
					default:
						message = "Invalid URI";
						break;
				}

				log_printf(&log, INFO, "http_url_parse", "%s", message);

				draw_url_input();
				draw_commands();
			} else {
				draw_method_selection();
				draw_cancel();
			}
		} else if (tolower(ch) == 'g' && current_action & METHOD_SELECTING) {
			http_init(&http, &http_url, GET, NULL, 0, 3, &log);
			pthread_create(&http_thread, NULL, http_run_thread, &http);
			draw_cancel();
		} else if (tolower(ch) == 'h' && current_action & METHOD_SELECTING) {
			http_init(&http, &http_url, HEAD, NULL, 0, 3, &log);
			pthread_create(&http_thread, NULL, http_run_thread, &http);
			draw_cancel();
		} else if (tolower(ch) == 'p' && current_action & METHOD_SELECTING) {
			draw_post_input();
			draw_cancel();
			select_form();
		} else if (ch == '\n' && current_action & POST_INPUTTING) {
			form_driver(url_form, REQ_END_FIELD);
			form_driver(url_form, 'a');
			form_driver(url_form, REQ_VALIDATION);
			strncpy(post, field_buffer(url_field[0], 0), FIELD_BUF_SIZE);
			post[FIELD_BUF_SIZE - 1] = '\0';
			*strrchr(post, 'a') = '\0';

			http_init(&http, &http_url, POST, post, strlen(post), 3, &log);
			pthread_create(&http_thread, NULL, http_run_thread, &http);
			draw_cancel();
		} else if (ch == '\n' && current_action & FILE_INPUTTING) {
			form_driver(url_form, REQ_END_FIELD);
			form_driver(url_form, 'a');
			form_driver(url_form, REQ_VALIDATION);
			strncpy(file, field_buffer(url_field[0], 0), FIELD_BUF_SIZE);
			file[FIELD_BUF_SIZE - 1] = '\0';
			*strrchr(file, 'a') = '\0';

			pthread_mutex_lock(&input_mutex);
			inputted = 1;
			pthread_cond_broadcast(&input_cond);
			pthread_mutex_unlock(&input_mutex);
		} else if ((ch == 'y' || ch == 'Y') && current_action & OVERWRITE_INPUTTING) {
			do_overwrite = 1;

			pthread_mutex_lock(&input_mutex);
			inputted = 1;
			pthread_cond_broadcast(&input_cond);
			pthread_mutex_unlock(&input_mutex);
		} else if ((ch == 'n' || ch == 'N') && current_action & OVERWRITE_INPUTTING) {
			do_overwrite = 0;
			
			pthread_mutex_lock(&input_mutex);
			inputted = 1;
			pthread_cond_broadcast(&input_cond);
			pthread_mutex_unlock(&input_mutex);
		}else if (ch == '') {
			if (http.status != DISCONNECTED)
				http_disconnect(&http);
			draw_url_input();
			draw_commands();
			select_form();
		} else
			form_driver(url_form, ch);

	delete_input_form();
	destroyCDKSwindow(log_swindow);
	destroyCDKScreen(cdk_screen);
	endwin();

	pthread_mutex_destroy(&input_mutex);
	pthread_cond_destroy(&input_cond);

	return 0;
}
int main(int argc, char **argv)
{
    char *host = "125.211.218.8";
   char *path = "/techqq/zt/2007/firacn/topic_html/xsm.htm";
   /*
   char *host = "10.205.42.139";
   char *path = "/techqq/a/20090423/000378.htm";
char *path = "/techqq/a/20120111/000508.htm";
char *path = "/techqq/a/20121008/000013.htm";
    char *path = "/techqq/wlyx.htm";
    char *path = "/techqq/index.html";
    char *path = "/techqq/a/20121008/000048.htm";
10.205.42.139:80/techqq/a/20090423/000378.htm
*/
    const char *body_ptr;
    int status;
    http_client_t http_client1;
    http_connect(&http_client1, host, 80);
    http_do_get(&http_client1, path);
    status = http_response_status(&http_client1);
    body_ptr = http_response_body(&http_client1);
    printf("---------------------Status-----------------------\n");
    printf("%d\n", status);
    printf("---------------------Body-----------------------\n");
    printf("%p\n", body_ptr);
    printf("%s\n", body_ptr);
    http_disconnect(&http_client1);

/*
    status = http_response_status(&http_client1);
    body_ptr = http_response_body(&http_client1);
*/
/*
    printf("---------------------Status-----------------------\n");
    printf("%d\n", status);
    printf("---------------------Body-----------------------\n");
    printf("%s\n", body_ptr);
*/
/*


    http_client_t http_client2;
    http_connect(&http_client2, "ufp.umeng.com", 80);
    http_do_get(&http_client2, "/login");

    status = http_response_status(&http_client2);
    body_ptr = http_response_body(&http_client2);

    printf("---------------------Status-----------------------\n");
    printf("%d\n", status);
    printf("---------------------Body-----------------------\n");
    printf("%s\n", body_ptr);
    http_disconnect(&http_client2);


    http_client_t http_client3;
    http_connect(&http_client3, "blog.umeng.com", 80);
    http_do_get(&http_client3, "/index.php/category/products/");

    status = http_response_status(&http_client3);
    body_ptr = http_response_body(&http_client3);

    printf("---------------------Status-----------------------\n");
    printf("%d\n", status);
    printf("---------------------Body-----------------------\n");
    printf("%s\n", body_ptr);
    http_disconnect(&http_client3);
*/

}
/* HTTP Server Run */
void httpServer_run(uint16_t server_port)
{
	int8_t sock; 			// HW socket number
	uint8_t sock_status;	// HW socket status
	int8_t seqnum; 			// Sequence number
	int16_t len;
	
#ifdef _HTTPSERVER_DEBUG_
	uint8_t destip[4] = {0, };	// Destination IP address
	uint16_t destport = 0;		// Destination Port number
#endif
	
	sock = getAvailableHTTPSocketNum(); // Get the H/W socket number
	if(sock < 0) return; // HW socket allocation failed
	
	seqnum = getHTTPSequenceNum(sock);
	
	http_request = (st_http_request *)httpserver.recvbuf;		// HTTP Request Structure
	parsed_http_request = (st_http_request *)http_req;
	//parsed_http_request = (st_http_request *)httpserver.sendbuf; // old
	
	/* Web Service Start */
	sock_status = getSn_SR(sock);
	switch(sock_status)
	{
		case SOCK_ESTABLISHED:
			// Interrupt clear
			if(getSn_IR(sock) & Sn_IR_CON)
			{
				setSn_IR(sock, Sn_IR_CON);
			}

			// HTTP Process states
			switch(HTTPSock[seqnum].status)
			{
				case STATE_HTTP_IDLE :
					if ((len = getSn_RX_RSR(sock)) > 0)
					{
						if (len > DATA_BUF_SIZE) len = DATA_BUF_SIZE;
						if ((len = recv(sock, (uint8_t *)http_request, len)) < 0) break;	// Exception handler
						
						*(((uint8_t *)http_request) + len) = '\0';	// End of string (EOS) marker
						
						parse_http_request(parsed_http_request, (uint8_t *)http_request);

#ifdef _HTTPSERVER_DEBUG_
						printf("> HTTP Request START ==========\r\n");
						printf("%s", (uint8_t *)http_request);
						printf("> HTTP Request END ============\r\n");
#endif
						
#ifdef _HTTPSERVER_DEBUG_
						getSn_DIPR(sock, destip);
						destport = getSn_DPORT(sock);
						printf("\r\n");
						printf("> HTTPSocket[%d] : HTTP Request received ", sock);
						printf("from %d.%d.%d.%d : %d\r\n", destip[0], destip[1], destip[2], destip[3], destport);
#endif

#ifdef _HTTPSERVER_DEBUG_
						printf("> HTTPSocket[%d] : [State] STATE_HTTP_REQ_DONE\r\n", sock);
#endif
						// HTTP 'response' handler; includes send_http_response_header / body function
						http_process_handler(sock, parsed_http_request);

						if(HTTPSock[seqnum].file_len > 0) HTTPSock[seqnum].status = STATE_HTTP_RES_INPROC;
						else HTTPSock[seqnum].status = STATE_HTTP_RES_DONE; // Send the 'HTTP response' end
						
					}
					break;


				case STATE_HTTP_RES_INPROC :
					/* Repeat: Send the remain parts of HTTP responses */
#ifdef _HTTPSERVER_DEBUG_
					printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_INPROC\r\n", sock);
#endif
					// Repeatedly send remaining data to client
					send_http_response_body(sock, http_response, 0);

					if(HTTPSock[seqnum].file_len == 0) HTTPSock[seqnum].status = STATE_HTTP_RES_DONE;
					break;

				case STATE_HTTP_RES_DONE :
#ifdef _HTTPSERVER_DEBUG_
					printf("> HTTPSocket[%d] : [State] STATE_HTTP_RES_DONE\r\n", sock);
#endif
					// Socket file info structure re-initialize
					HTTPSock[seqnum].file_len = 0;
					HTTPSock[seqnum].file_offset = 0;
					HTTPSock[seqnum].file_start = 0;
					HTTPSock[seqnum].status = STATE_HTTP_IDLE;
					
#ifdef _USE_WATCHDOG_
					HTTPServer_WDT_Reset();
#endif
					http_disconnect(sock);
					break;

				default :
					break;
			}
			break;

		case SOCK_CLOSE_WAIT:
#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : ClOSE_WAIT\r\n", sock);	// if a peer requests to close the current connection
#endif
			// Socket file info structure re-initialize: HTTP connection 'close'
			HTTPSock[seqnum].file_len = 0;
			HTTPSock[seqnum].file_offset = 0;
			HTTPSock[seqnum].file_start = 0;
			HTTPSock[seqnum].status = STATE_HTTP_IDLE;
			
			http_disconnect(sock);
			break;

		case SOCK_INIT:
			listen(sock);
			break;

		case SOCK_LISTEN:
			break;

		case SOCK_SYNSENT:
		//case SOCK_SYNSENT_M:
		case SOCK_SYNRECV:
		//case SOCK_SYNRECV_M:
			break;

		case SOCK_CLOSED:
#ifdef _HTTPSERVER_DEBUG_
			//printf("> HTTPSocket[%d] : CLOSED\r\n", sock);
#endif
			if(server_port == 0) server_port = HTTP_SERVER_PORT;
			if(socket(sock, Sn_MR_TCP, server_port, 0x00) == sock) // Init / Reinitialize the socket
			{
#ifdef _HTTPSERVER_DEBUG_
				printf("> HTTPSocket[%d] : SERVER OPEN, Port: %d\r\n", sock, server_port);
#endif
				;
			}
			break;

		default :
			break;
	} // end of switch

#ifdef _USE_WATCHDOG_
	HTTPServer_WDT_Reset();
#endif
}