2
* This file is part of nzbget
4
* Copyright (C) 2007-2009 Andrei Prygounkov <hugbug@users.sourceforge.net>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
* $Date: 2009-05-31 00:18:31 +0200 (Sun, 31 May 2009) $
37
extern int optind, opterr;
39
int getopt(int argc, char *argv[], char *optstring);
46
struct _finddata_t m_FindData;
51
struct dirent* m_pFindData;
55
DirBrowser(const char* szPath);
64
static char* BaseFileName(const char* filename);
65
static void NormalizePathSeparators(char* szPath);
66
static bool LoadFileIntoBuffer(const char* szFileName, char** pBuffer, int* pBufferLength);
67
static bool SetFileSize(const char* szFilename, int iSize);
68
static void MakeValidFilename(char* szFilename, char cReplaceChar, bool bAllowSlashes);
69
static bool MoveFile(const char* szSrcFilename, const char* szDstFilename);
70
static bool FileExists(const char* szFilename);
71
static bool DirectoryExists(const char* szDirFilename);
72
static bool CreateDirectory(const char* szDirFilename);
73
static bool ForceDirectories(const char* szPath);
74
static long long FileSize(const char* szFilename);
75
static long long FreeDiskSize(const char* szPath);
76
static bool DirEmpty(const char* szDirFilename);
77
static bool RenameBak(const char* szFilename, const char* szBakPart, bool bRemoveOldExtension, char* szNewNameBuf, int iNewNameBufSize);
79
static bool ExpandHomePath(const char* szFilename, char* szBuffer, int iBufSize);
80
static void ExpandFileName(const char* szFilename, char* szBuffer, int iBufSize);
82
static void FormatFileSize(char* szBuffer, int iBufLen, long long lFileSize);
85
* Split command line int arguments.
86
* Uses spaces and single quotation marks as separators.
87
* Returns bool if sucessful or false if bad escaping was detected.
88
* Parameter "argv" may be NULL if only a syntax check is needed.
89
* Parsed parameters returned in Array "argv", which contains at least one element.
90
* The last element in array is NULL.
91
* Restrictions: the number of arguments is limited to 100 and each arguments must
92
* be maximum 1024 chars long.
93
* If these restrictions are exceeded, only first 100 arguments and only first 1024
94
* for each argument are returned (the functions still returns "true").
96
static bool SplitCommandLine(const char* szCommandLine, char*** argv);
98
static long long JoinInt64(unsigned long Hi, unsigned long Lo);
99
static void SplitInt64(long long Int64, unsigned long* Hi, unsigned long* Lo);
102
* Int64ToFloat converts Int64 to float.
103
* Simple (float)Int64 does not work on all compilers,
104
* for example on ARM for NSLU2 (unslung).
106
static float Int64ToFloat(long long Int64);
108
static unsigned int DecodeBase64(char* szInputBuffer, int iInputBufferLength, char* szOutputBuffer);
111
* Encodes string to be used as content of xml-tag.
112
* Returns new string allocated with malloc, it need to be freed by caller.
114
static char* XmlEncode(const char* raw);
117
* Decodes string from xml.
118
* The string is decoded on the place overwriting the content of raw-data.
120
static void XmlDecode(char* raw);
123
* Returns pointer to tag-content and length of content in iValueLength
124
* The returned pointer points to the part of source-string, no additional strings are allocated.
126
static const char* XmlFindTag(const char* szXml, const char* szTag, int* pValueLength);
129
* Parses tag-content into szValueBuf.
131
static bool XmlParseTagValue(const char* szXml, const char* szTag, char* szValueBuf, int iValueBufSize, const char** pTagEnd);
134
* Creates JSON-string by replace the certain characters with escape-sequences.
135
* Returns new string allocated with malloc, it need to be freed by caller.
137
static char* JsonEncode(const char* raw);
140
* Decodes JSON-string.
141
* The string is decoded on the place overwriting the content of raw-data.
143
static void JsonDecode(char* raw);
146
* Returns pointer to field-content and length of content in iValueLength
147
* The returned pointer points to the part of source-string, no additional strings are allocated.
149
static const char* JsonFindField(const char* szJsonText, const char* szFieldName, int* pValueLength);
152
* Returns pointer to field-content and length of content in iValueLength
153
* The returned pointer points to the part of source-string, no additional strings are allocated.
155
static const char* JsonNextValue(const char* szJsonText, int* pValueLength);
158
* Returns program version and revision number as string formatted like "0.7.0-r295".
159
* If revision number is not available only version is returned ("0.7.0").
161
static const char* VersionRevision() { return VersionRevisionBuf; };
164
* Initialize buffer for program version and revision number.
165
* This function must be called during program initialization before any
166
* call to "VersionRevision()".
168
static void InitVersionRevision();
170
static char VersionRevisionBuf[40];