File: Decoder.h

package info (click to toggle)
nzbget 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,628 kB
  • sloc: cpp: 45,725; sh: 3,747; makefile: 53
file content (119 lines) | stat: -rw-r--r-- 3,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 *  This file is part of nzbget
 *
 *  Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
 *  Copyright (C) 2007-2008 Andrei Prygounkov <hugbug@users.sourceforge.net>
 *
 *  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * $Revision: 198 $
 * $Date: 2008-07-29 22:32:23 +0200 (Di, 29 Jul 2008) $
 *
 */


#ifndef DECODER_H
#define DECODER_H

class Decoder
{
public:
	enum EStatus
	{
		eUnknownError,
		eFinished,
		eArticleIncomplete,
		eCrcError,
		eInvalidSize,
		eNoBinaryData
	};

	enum EFormat
	{
		efUnknown,
		efYenc,
		efUx,
	};

	static const char* FormatNames[];

protected:
	const char*				m_szSrcFilename;
	const char*				m_szDestFilename;
	char*					m_szArticleFilename;

public:
							Decoder();
	virtual					~Decoder();
	virtual EStatus			Check() = 0;
	virtual void			Clear();
	virtual bool			Write(char* buffer, int len, FILE* outfile) = 0;
	void					SetSrcFilename(const char* szSrcFilename) { m_szSrcFilename = szSrcFilename; }
	void					SetDestFilename(const char* szDestFilename) { m_szDestFilename = szDestFilename; }
	const char*				GetArticleFilename() { return m_szArticleFilename; }
	static EFormat			DetectFormat(const char* buffer, int len);
};

class YDecoder: public Decoder
{
protected:
	static unsigned int		crc_tab[256];
	bool					m_bBegin;
	bool					m_bPart;
	bool					m_bBody;
	bool					m_bEnd;
	bool					m_bCrc;
	unsigned long			m_lExpectedCRC;
	unsigned long			m_lCalculatedCRC;
	unsigned long			m_iBegin;
	unsigned long			m_iEnd;
	unsigned long			m_iSize;
	unsigned long			m_iEndSize;
	bool					m_bAutoSeek;
	bool					m_bNeedSetPos;
	bool					m_bCrcCheck;

	unsigned int			DecodeBuffer(char* buffer);
	static void				crc32gentab();
	unsigned long			crc32m(unsigned long startCrc, unsigned char *block, unsigned int length);

public:
							YDecoder();
	virtual EStatus			Check();
	virtual void			Clear();
	virtual bool			Write(char* buffer, int len, FILE* outfile);
	void					SetAutoSeek(bool bAutoSeek) { m_bAutoSeek = m_bNeedSetPos = bAutoSeek; }
	void					SetCrcCheck(bool bCrcCheck) { m_bCrcCheck = bCrcCheck; }

	static void				Init();
	static void				Final();
};

class UDecoder: public Decoder
{
private:
	bool					m_bBody;
	bool					m_bEnd;

	unsigned int			DecodeBuffer(char* buffer, int len);

public:
							UDecoder();
	virtual EStatus			Check();
	virtual void			Clear();
	virtual bool			Write(char* buffer, int len, FILE* outfile);
};

#endif