/***************************************************************************
 *   Copyright (C) 2004 by yunfan                                          *
 *   yunfan_zg@163.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef LIBEVAUTIL_H
#define LIBEVAUTIL_H

#include <string>
#include "md5.h"
#define KEY_LENGTH 16
#define QQ_SMILEY_AMOUNT 96

/** Visual Studio .NET 2002/2003 Additional Definitions */
#ifdef WIN32
#pragma warning(disable: 4309 4800)
typedef unsigned int uint;
typedef unsigned char uint8_t;
#include <malloc.h>
#endif

// this class provides some utilities, like md5 function and parse text smiley into ready to send smiley code.

class EvaUtil{
public:
	EvaUtil();
	// the following 2 functions alway return 16 bytes due to the protocol used by QQ
	static char *doMd5(char *in, int len);
	static char *doMd5Md5(char *in, int len);
	
	static std::string smileyToText(const char smileyCode);     // get text description of the smiley code
	static char textToSmiley(const std::string &textTag);      // get smiley code of the text description
	static int textToFileIndex(const std::string &textTag);  // get the file name in integer of the smiley text description	
	static std::string fileIndexToText( const int fileIndex);
	static std::string convertToSend(const std::string &text);
	static void initMap();
	
	static std::string customSmileyToText(const char *buf, int *smileyLength);
	
	static void calcSuns(const unsigned short level, int *suns, int *moons, int *stars);
        typedef struct textMap{
		//char gb[5];             // chinese charactor not supported, cuz only few people use them
		char en[16];
		char py[16];
	} textMap;
private:	
	static char md5Buf[KEY_LENGTH];
	static textMap map[QQ_SMILEY_AMOUNT];
	static const char smileyMap[QQ_SMILEY_AMOUNT];
	static int smileyToFileIndex( const char smileyCode);
	
};

#endif
 
