Ejemplo n.º 1
0
static void
convert_pango_to_docbook(GString *str)
{
    replace_tag(str, "i", "emphasis");
    replace_tag(str, "sup", "superscript");
    replace_tag(str, "sub", "subscript");
}
Ejemplo n.º 2
0
ST_FUNC ST_Error ST_APE_setDisc(ST_APE *tag, int v) {
    char tmp[32];

    snprintf(tmp, 32, "%d", v);
    return replace_tag(tag, "disc", (uint8_t *)tmp, strlen(tmp), 0,
                       ST_TextEncoding_UTF8);
}
Ejemplo n.º 3
0
ST_FUNC ST_Error ST_APE_setComment(ST_APE *tag, const uint8_t *v, size_t len,
                                   ST_TextEncoding e) {
    return replace_tag(tag, "comment", v, len, 0, e);
}
Ejemplo n.º 4
0
ST_FUNC ST_Error ST_APE_setGenre(ST_APE *tag, const uint8_t *v, size_t len,
                                 ST_TextEncoding e) {
    return replace_tag(tag, "genre", v, len, 0, e);
}
Ejemplo n.º 5
0
/*------------------------------------------------------------------------
 * The received header must contain the word "GET" or "POST" to be 
 * considered a valid request.
 * With HTTP 1.1 where the connection is left open, the header I send
 * should include content length. With HTTP 1.0 you can just close the
 * connection after sending the page and the browser knows its done. 
 *
 * The HTTP protocol specification is at http://www.w3.org/Protocols/ 
 *------------------------------------------------------------------------
 */
ushort http_server(uchar *inbuf, ushort header_len, ushort tcp_len,
		   uchar nr, uchar resend)
{
	static uint	counter=0;
	uint	content_length;
	uint	data_len;
	uchar 	*ptr;
	uchar 	*tcp_data;

	if (http_debug == DEBUG)
		printf("\n\n%s************ tcp_len = %d ************%d\n",
			__func__,tcp_len,http_state);
	else
		if ((counter++ % 100) == 0)
			printf(".");
		    	
	/* Make sure this is a valid connection */
	if (nr == NO_CONNECTION) 
		return 0;
	
	/* Compute start of TCP data */
	
	/* Save first 20 chars and seq number just in case
	 * we need to re-generate page
	 * TODO: if post, then save switch state infomation
	 * If this is a resend, set sequence number to what it was
	 * the last time we sent this
	 */
	if (!resend) {
		tcp_data = inbuf + ETHER_IP_HLEN + header_len;
		memcpy(conxn[nr].query, tcp_data, 20);
		conxn[nr].old_sequence = conxn[nr].my_sequence;
	} else {
		tcp_data = inbuf;
		conxn[nr].my_sequence = conxn[nr].old_sequence;   
	}

	if (http_debug == DEBUG)
		printf("#1> http_state = %d......\n",http_state);

	/* Pre-porcess HTTP state change. */
	switch (http_state) {
	case HTTP_START:
		if ( (strstr((const char *)tcp_data, "GET") != NULL) && 
		     ((strstr((const char *)tcp_data, "index") != NULL) || 
		      (strstr((const char *)tcp_data, "/ ") != NULL)) )
			http_state = HTTP_GET;
		else if ( (strstr((const char *)tcp_data, "POST") != NULL) )
			http_state = HTTP_POST;
		break;

	case HTTP_GET:
		if ( (strstr((const char *)tcp_data, "POST") != NULL) )
			http_state = HTTP_POST;
		break;
		
	case HTTP_UPLOAD:  /* process the situation of network disconnection */
		if ( (strstr((const char *)tcp_data, "GET") != NULL) && 
		     ((strstr((const char *)tcp_data, "index") != NULL) || 
		      (strstr((const char *)tcp_data, "/ ") != NULL)) )
			http_state = HTTP_GET;
		break;
	}
	
	switch (http_state) {
	case HTTP_START:
		break;
		
	case HTTP_GET:
	      	/* send download page to HTTP client */
		http_send_ok(nr, web_page, 200, "OK");
		break;

	case HTTP_POST:
		if (http_parse_post(tcp_data, &content_length)) {
			http_state = HTTP_START;
			return 1;
		} else {
			post_info.upload_len = content_length;
			post_info.data_len = 0;
			post_info.buf = (uchar *)upgrade_buffer;
			http_state = HTTP_HEAD_DATA;
		}

		if (http_parse_mime(tcp_data, tcp_len - header_len, nr) == 0)
			http_state = HTTP_UPLOAD;
		break;

	case HTTP_HEAD_DATA:
		post_info.rcv_len = tcp_len - header_len;

		if (http_check_filename(tcp_data)) {
			http_send_error(nr, 400, "Bad Request",
				"No upload file name to be slected !");
			http_state = HTTP_START;
			return 1;			
		}
		
		ptr = (uchar *)strstr((const char *)tcp_data, c_headerend);
		ptr = ptr + strlen(c_headerend); /* upload file start pointer */
		
		data_len = tcp_len - header_len - (ptr - tcp_data );
		post_info.data_len = data_len;
		memcpy(post_info.buf, ptr, data_len);

		http_state = HTTP_UPLOAD;
		break;

	case HTTP_UPLOAD:
		post_info.rcv_len += tcp_len - header_len;

		if (http_debug == DEBUG) {
			printf("post_info.rcv_len=%d  post_info.upload_len=%d\n"
				,post_info.rcv_len,post_info.upload_len);
		}
		
		if (post_info.rcv_len >= post_info.upload_len) {
			/* To check the last packet if contains image data. */
			/* 6-byte include two "--" and one \r\n */
			/* 8-byte include two "--" and two \r\n */
			if ((tcp_len - header_len) > (strlen(boundary_code)+6)) 
				data_len = tcp_len - header_len - \
						strlen(boundary_code) - 8;
			else
				data_len = 0;

			if (http_check_image(post_info.buf, post_info.data_len)) {
				http_send_error(nr, 400, "Bad Request",
						 "File format is invalid !");
				http_state = HTTP_START;
				return (1);
			} else {			
				memset(text, 0x00, sizeof(text));
#ifdef CONFIG_MTD_CORTINA_CS752X_NAND
				sprintf(text,"%d", 5 + post_info.data_len/(1024*1000));
#else
				sprintf(text,"%d", 10 + post_info.data_len/(1024*100));
#endif
				replace_tag((uchar *)upgrade200_1, "TAG:NUM1", text);
	
				http_send_ok(nr, upgrade200_1, 200, "OK");	

				if (do_upgrade_image(post_info.buf, post_info.data_len)) {
					http_state = HTTP_START;
					return 0;
				} else {
					http_state = HTTP_REBOOT;
					break;
				}
			}

		} else {
			data_len = tcp_len - header_len;
			memcpy((void *)&post_info.buf[post_info.data_len], tcp_data, data_len);
			post_info.data_len += data_len;
		}
			
		break;

	case HTTP_REBOOT:
		if ( (strstr((const char *)tcp_data, "GET") != NULL) && 
		     (strstr((const char *)tcp_data, "reboot") != NULL) ) {    	
			http_state = HTTP_START;
			http_send_ok(nr, reboot200, 200, "OK");
			/* 
			 * Reserved time for tx those packets that queue 
			 * in packet buffer before system reset.
			 */
			udelay(500);
			do_reset(NULL, 0, 0, NULL);
		}
		break;

	default:
		printf("HTTP State Error ! %d\n", http_state);
		break;
	}

	if (http_debug == DEBUG)
		printf("#2> http_state = %d......\n",http_state);
	
	return 0;
}