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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* common.h: EPG2VDR plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __COMMON_H
#define __COMMON_H
#include <stdint.h> // uint_64_t
#include <stdlib.h>
#include <string>
#include <openssl/md5.h> // MD5_*
#ifdef VDR_PLUGIN
# include <vdr/tools.h>
#endif
#ifdef USELIBXML
# include <libxslt/transform.h>
# include <libxslt/xsltutils.h>
# include <libexslt/exslt.h>
#endif
//***************************************************************************
//
//***************************************************************************
#ifndef VDR_PLUGIN
inline long min(long a, long b) { return a < b ? a : b; }
inline long max(long a, long b) { return a > b ? a : b; }
#endif
enum Misc
{
success = 0,
done = success,
fail = -1,
na = -1,
ignore = -2,
all = -3,
abrt = -4,
yes = 1,
on = 1,
off = 0,
no = 0,
TB = 1,
sizeMd5 = 2 * MD5_DIGEST_LENGTH,
sizeUuid = 36,
tmeSecondsPerMinute = 60,
tmeSecondsPerHour = tmeSecondsPerMinute * 60,
tmeSecondsPerDay = 24 * tmeSecondsPerHour
};
//***************************************************************************
// Tell
//***************************************************************************
void tell(int eloquence, const char* format, ...);
//***************************************************************************
// MemoryStruct for curl callbacks
//***************************************************************************
struct MemoryStruct
{
MemoryStruct() { memory = 0; clear(); }
~MemoryStruct() { clear(); }
// data
char* memory;
size_t size;
// tag attribute
char tag[100]; // the tag to be compared
char name[100]; // content name (filename)
int headerOnly;
int isEmpty() { return memory == 0; }
void clear()
{
free(memory);
memory = 0;
size = 0;
*tag = 0;
*name = 0;
headerOnly = no;
}
};
//***************************************************************************
// Tools
//***************************************************************************
unsigned int getHostId();
const char* getHostName();
const char* getFirstIp();
#ifdef USEUUID
const char* getUniqueId();
#endif
void removeChars(std::string& str, const char* ignore);
void removeCharsExcept(std::string& str, const char* except);
void removeWord(std::string& pattern, std::string word);
void prepareCompressed(std::string& pattern);
char* rTrim(char* buf);
char* lTrim(char* buf);
char* allTrim(char* buf);
char* sstrcpy(char* dest, const char* src, int max);
std::string num2Str(int num);
std::string l2pTime(time_t t);
std::string ms2Dur(uint64_t t);
const char* c2s(char c, char* buf);
int fileExists(const char* path);
int fileSize(const char* path);
int createLink(const char* link, const char* dest, int force);
int isLink(const char* path);
int isEmpty(const char* str);
int removeFile(const char* filename);
int chkDir(const char* path);
#ifdef USELIBXML
xsltStylesheetPtr loadXSLT(const char* name, const char* path, int utf8);
#endif
#ifdef USEMD5
typedef char md5Buf[sizeMd5+TB];
typedef char md5;
int createMd5(const char* buf, md5* md5);
int createMd5OfFile(const char* path, const char* name, md5* md5);
#endif
//***************************************************************************
// Zip
//***************************************************************************
int gunzip(MemoryStruct* zippedData, MemoryStruct* unzippedData);
void tellZipError(int errorCode, const char* op, const char* msg);
#ifdef USELIBARCHIVE
int unzip(const char* file, const char* filter, char*& buffer,
int& size, char* entryName);
#endif
#ifdef VDR_PLUGIN
//***************************************************************************
// Log Duration
//***************************************************************************
class LogDuration
{
public:
LogDuration(const char* aMessage, int aLogLevel = 2);
~LogDuration();
void show(const char* label = "");
protected:
char message[1000];
uint64_t durationStart;
int logLevel;
};
#endif
//***************************************************************************
#endif //___COMMON_H
|