#ifndef stag_h
#define stag_h
#include <map>

typedef enum {
	UNDEFINED	= 0x00,
	HASH		= 0x01,
	STRING		= 0x02,
	INTEGER		= 0x03,
	tagFLOAT	= 0x04,
	tagBOOL		= 0x05,
	BOLL_ARRAY	= 0x06,
	tagBLOB		= 0x07,
	MAX		= 0x08
	} tagType;
typedef enum {
	tNAME		= 0x01,	// string
	tSIZE		= 0x02, // integer
	tTYPE		= 0x03, // string
	tCODEC		= 0x04, // string
	tCOLECTION	= 0x05, // deprecated (integer)
	tPART_PATH	= 0x06,
	tPART_HASH	= 0x07,
	tTRANSFERED	= 0x08,
	tGAP_START	= 0x09,
	tGAP_END	= 0x0A,	// 10
	tDESCRIPTION	= 0x0B, // 11
	tPING		= 0x0C, // 12
	tFAIL		= 0x0D, // 13 (history)
	tPREF		= 0x0E, // 14
	tPORT		= 0x0F,	// 15
	tIP		= 0x10, // 16
	tVERSION	= 0x11,	// 17 Integer
	tTEMPFILE	= 0x12,	// 18 (localname)
	tPRIO		= 0x13, // 19
	tSTATUS		= 0x14, // 20
	tSOURCES	= 0x15, // 21
	tQTime		= 0x16, // 22
	tParts		= 0x17, // 23

	tCompress	= 0x20, // 32
	tUDP_port	= 0x21, // 33
	tUDP_version	= 0x22,
	tP2P_source	= 0x23,
	tComments	= 0x24,
	tExtended	= 0x25
	} tagFeld;

struct sGap {
	size_t	von;
	size_t	bis;
	size_t	val;
	};
typedef std::map<unsigned,struct sGap> tGap_map;
class sTag {
	public:
	tGap_map	gap_map;
static	unsigned  count;
	char	 *loc;
	char	 *name;
	char	 *type;
	char	 *codec;
	char	 *desc;
	char	 *artist;
	char	 *title;
	char	 *album;
	char	 *length;
	char	 *bitrate;
	char	 *temp;
	uint8_t	 *corrupt_dat;
	size_t    corrupt_len;
	uint32_t  size;
	uint32_t  transfered;
	uint32_t  version;
	uint32_t  users;
	uint32_t  files;
	struct in_addr ip;
	uint32_t  gap_start;
	uint32_t  gap_end;
	uint32_t  pref;
	uint32_t  prio;
	unsigned  compress;
	unsigned  dl_prio;
	unsigned  ul_prio;
	unsigned  status;
	time_t	  last_ping;
	size_t	  users_max;
	size_t	  fail;
	uint16_t  port;
	uint16_t  client_udp;
		 sTag ();
		~sTag ();
	};
void 	 dump 			(unsigned char *data, size_t len) ;
uint32_t GET_U4			(unsigned char **buf, size_t *len);
uint16_t GET_U2			(unsigned char **buf, size_t *len);
uint8_t  GET_U1			(unsigned char **buf, size_t *len);
char *   GET_S2_		(unsigned char **buf, size_t *len);
bool     GET_HASH 		(unsigned char **buf, size_t *len, uint8_t *val);
bool     ADD_S2   		(unsigned char **buf, size_t *len, const char    *val);
bool     ADD_F4 		(unsigned char **buf, size_t *len, double   val);
bool     ADD_U4 		(unsigned char **buf, size_t *len, size_t   val);
/*
bool     ADD_U4 		(unsigned char **buf, size_t *len, uint32_t val);
*/
bool     ADD_U2 		(unsigned char **buf, size_t *len, size_t   val);	// assert if to big
bool     ADD_U1 		(unsigned char **buf, size_t *len, uint8_t  val);
bool     ADD_HASH 		(unsigned char **buf, size_t *len, const uint8_t *hash);
bool 	 add_intTag		(unsigned char **buf, size_t *len, const char *key, size_t      val);
bool 	 add_intTag		(unsigned char **buf, size_t *len, uint8_t     key, size_t      val);
bool 	 add_strTag		(unsigned char **buf, size_t *len, const char *key, const char* val);
bool 	 add_strTag		(unsigned char **buf, size_t *len, uint8_t     key, const char* val);
bool 	 add_bobTag		(unsigned char **buf, size_t *len, const char *key, const char* val, size_t count);
bool 	 add_strCmp		(unsigned char **buf, size_t *len, const char *key);
class sTag *parse_tag           (unsigned char  *buf, size_t *len);

#endif
// vim:fdm=marker
	
