Example #1
0
	/// 문자열 치환
	void replace(const char* niddle, const char* changeTo)
	{
		int pos = find(niddle);
		if(pos < 0)
			return;

		FastString<MaxSize> destStr;

		int begin = 0;
		int end = pos;
		int lenNiddle = strlen(niddle);

		while(end >= 0)
		{
			destStr.append(&buf[begin], end-begin);
			destStr.append(changeTo);
			begin = end+lenNiddle;
			end = find(niddle, begin);
		}

		// 뒤에 남은 부분 붙여 넣기
		if(begin < static_cast<int>(size()))
		{
			destStr.append(&buf[begin], size()-begin);
		}

		assign(destStr);
	}
Example #2
0
    // Convert UTF8 FastString to a wide char string
    ReadOnlyUnicodeString convert(const FastString & string)
    {
        // Create some space for the UCS-2 string
        ReadOnlyUnicodeString ret(0, string.getLength() + 1);
        ReadOnlyUnicodeString::CharType * data = const_cast<ReadOnlyUnicodeString::CharType *>(ret.getData());
        if (!data) return ret;

        ReadOnlyUnicodeString::CharType * dest = data;

        // Direct access to the buffer (don't bound check for every access)
        const uint8 * buffer = (const uint8*)string;
        for (int i = 0; i < string.getLength();)
        {
            // Get the current char
            const uint8 c = buffer [i++];

            // Check for UTF8 code
            if ((c & 0x80) != 0)
            {
                // The data is in the 7 low bits
                uint32 dataMask = 0x7f;
                // The count bit mask
                uint32 bitCountMask = 0x40;
                // The consumption count
                int charCount = 0;

                while ((c & bitCountMask) != 0 && bitCountMask)
                {
                    ++charCount;
                    dataMask >>= 1; bitCountMask >>= 1;
                }

                // Get the few bits remaining here
                int n = (c & dataMask);

                // Then extract the remaining bits
                while (--charCount >= 0 && i < string.getLength())
                {
                    const uint8 extra = buffer[i];
                    // Make sure it's a valid UTF8 encoding
                    if ((extra & 0xc0) != 0x80) break;

                    // Store the new bits too
                    n <<= 6; n |= (extra & 0x3f);
                    ++i;
                }

                *dest++ = (ReadOnlyUnicodeString::CharType)n;
            }
            else // Append the char as-is
Example #3
0
int main(int argc,char* argv[])
{
	if (argc != 3)
	{
		cerr << "Usage: " << argv[0] << " <-s|-n|-S|-N> <email>" << endl;
		exit(-1);
	}

	int feed_type = 0;
	if (string(argv[1]) == "-s") feed_type = FEED_SPAM;
	else if (string(argv[1]) == "-n") feed_type = FEED_HAM;
	else if (string(argv[1]) == "-S") feed_type = UN_FEED_SPAM;
	else if (string(argv[1]) == "-N") feed_type = UN_FEED_HAM;
	else { cerr << "Usage: " << argv[0] << " <-s|-n|-S|-N> <email>" << endl; exit(-1); }

	FastString email_data = get_file_content(argv[2]);
        MimeMessage msg(email_data);

        FastString charset="";
	FastString plain = "";
	FastString html = "";
	FastString subject="";


	set<string> result;
	CFenci myFenci;
	myFenci.setDict("/usr/local/etc/dict_chs.utf8.xdb");
	myFenci.setRule("/usr/local/etc/rules.utf8.ini");
	myFenci.setCharset("utf-8");
	myFenci.setIgnoreSign();

	/* parse subject */
	msg.getSubject(subject,charset);
	myFenci.getFenciResult(format_to_check(subject.c_str(),charset.c_str()),result);

	/* parse plain */
        msg.getTextPlain(plain,charset);
	myFenci.getFenciResult(format_to_check(subject.c_str(),charset.c_str()),result);	

	/* parse html */
	msg.getTextHtml(html,charset);
	string html_to_check = get_text_from_html(html.c_str());
	myFenci.getFenciResult(format_to_check(html_to_check,charset.c_str()),result);

	/* connect redis */
	CRedis myRedis("127.0.0.1",6379);
	const int CONNECT_TIMEOUT = 1;
	myRedis.setTimeout(CONNECT_TIMEOUT);
	if (false == myRedis.Connect())	
	{
		cerr << myRedis.getError() << endl;
		return -1;
	}

	/* feed spam */
	if (feed_type == FEED_SPAM)
	{
		for (set<string>::iterator it = result.begin(); it != result.end(); ++it)
		{
			string buffer = myRedis.Get(*it);
			if (buffer != "")
			{
				CDataParse myData(buffer," ");
				vector<string> ret = myData.getVector();
				ret[0] = my_int2str((my_str2int(ret[0]) + 1));
				myData.setVector(ret);
				if (false == myRedis.Set(*it,myData.getString()))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
			else
			{
				if (false == myRedis.Set(*it,"1 0"))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
		}
	}

	/* feed ham */
	if (feed_type == FEED_HAM)
	{
		for (set<string>::iterator it = result.begin(); it != result.end(); ++it)
		{
			string buffer = myRedis.Get(*it);
			if (buffer != "")
			{
				CDataParse myData(buffer," ");
				vector<string> ret = myData.getVector();
				ret[1] = my_int2str((my_str2int(ret[1]) + 1));
				myData.setVector(ret);
				if (false == myRedis.Set(*it,myData.getString()))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
			else
			{
				if (false == myRedis.Set(*it,"0 1"))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
		}
	}

	/* unfeed spam */
	if (feed_type == UN_FEED_SPAM)
	{
		for (set<string>::iterator it = result.begin(); it != result.end(); ++it)
		{
			string buffer = myRedis.Get(*it);
			if (buffer != "")
			{
				CDataParse myData(buffer," ");
				vector<string> ret = myData.getVector();
				if (my_str2int(ret[0]) > 0) ret[0] = my_int2str(my_str2int(ret[0]) - 1);
				myData.setVector(ret);
				if (false == myRedis.Set(*it,myData.getString()))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
		}
	}

	/* unfeed ham */
	if (feed_type == UN_FEED_HAM)
	{
		for (set<string>::iterator it = result.begin(); it != result.end(); ++it)
		{
			string buffer = myRedis.Get(*it);
			if (buffer != "")
			{
				CDataParse myData(buffer," ");
				vector<string> ret = myData.getVector();
				if (my_str2int(ret[1]) > 0) ret[1] = my_int2str(my_str2int(ret[1]) - 1);
				myData.setVector(ret);
				if (false == myRedis.Set(*it,myData.getString()))
				{
					cerr << myRedis.getError() << endl;
					return -1;
				}
			}
		}
	}

	/* close redis */
	myRedis.Close();

	exit(0);
}
Example #4
0
	int append(const FastString<SrcMaxSize>& value)
	{
		return append(value.c_str(), value.size());
	}