示例#1
0
string csstidy::unicode(string& istring,int& i)
{
	++i;
	string add = "";
	bool replaced = false;
	
	while(i < istring.length() && (ctype_xdigit(istring[i]) || ctype_space(istring[i])) && add.length()< 6)
	{
		add += istring[i];

		if(ctype_space(istring[i]))
		{
			break;
		}
		i++;
	}

	if(hexdec(add) > 47 && hexdec(add) < 58 || hexdec(add) > 64 && hexdec(add) < 91 || hexdec(add) > 96 && hexdec(add) < 123)
	{
		string msg = "Replaced unicode notation: Changed \\" + rtrim(add) + " to ";
		add = static_cast<int>(hexdec(add));
		msg += add;
		log(msg,Information);
		replaced = true;
	}
	else
	{
		add = trim("\\" + add);
	}

	if(ctype_xdigit(istring[i+1]) && ctype_space(istring[i]) && !replaced || !ctype_space(istring[i]))
	{
		i--;
	}
	
	if(add != "\\" || !settings["remove_bslash"] || in_str_array(tokens,istring[i+1]))
	{
		return add;
	}
	if(add == "\\")
	{
		log("Removed unnecessary backslash",Information);
	}
	return "";
}
示例#2
0
文件: uws_http.c 项目: codesaler/uws
int write_response(pConnInfo conn_info, struct response* header_body) {/*{{{*/
    int res;
    setblocking(conn_info->clientfd);

    char *accept_encoding; 
    //compress--start--

    if((header_body->content_len > 0) &&
        uws_config.http.gzip && 
        in_str_array(uws_config.http.gzip_types, get_header_param("Content-Type", header_body->header)) >= 0 &&
        (accept_encoding = get_header_param("Accept-Encoding", conn_info->request_header)) &&
        strstr(accept_encoding, "gzip") != NULL
        ) {

        size_t src_len = header_body->content_len;
        size_t dst_len;
        char *dst_buff;
        gzcompress(&dst_buff, &dst_len, header_body->content, src_len);

        char *content_len = itoa(dst_len);
        add_header_param("Content-Length", content_len, header_body->header);
        uws_free(content_len);
        add_header_param("Content-Encoding", "gzip", header_body->header);
        uws_free(header_body->content);
        header_body->content = dst_buff;
        header_body->content_len = dst_len;
    }

    char* header_str = str_response_header(header_body->header);
    size_t header_len = strlen(header_str);

    res = write(conn_info->clientfd, header_str, header_len);
    uws_free(header_str);

    if(res == -1) return -1;
    res = write(conn_info->clientfd, HEADER_SEP, strlen(HEADER_SEP));
    if(res == -1) return -1;
    res = writen(conn_info->clientfd, header_body->content, header_body->content_len);
    if(res == -1) {return -1;}
    return 0;
}/*}}}*/
示例#3
0
bool csstidy::is_token(string& istring,const int i)
{
	return (in_str_array(tokens,istring[i]) && !escaped(istring,i));
}