vdr  2.0.6
config.h
Go to the documentation of this file.
1 /*
2  * config.h: Configuration file handling
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: config.h 2.76.1.7 2014/03/22 11:00:00 kls Exp $
8  */
9 
10 #ifndef __CONFIG_H
11 #define __CONFIG_H
12 
13 #include <arpa/inet.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <time.h>
18 #include <unistd.h>
19 #include "i18n.h"
20 #include "font.h"
21 #include "tools.h"
22 
23 // VDR's own version number:
24 
25 #define VDRVERSION "2.0.6"
26 #define VDRVERSNUM 20006 // Version * 10000 + Major * 100 + Minor
27 
28 // The plugin API's version number:
29 
30 #define APIVERSION "2.0.6"
31 #define APIVERSNUM 20006 // Version * 10000 + Major * 100 + Minor
32 
33 // When loading plugins, VDR searches them by their APIVERSION, which
34 // may be smaller than VDRVERSION in case there have been no changes to
35 // VDR header files since the last APIVERSION. This allows compiled
36 // plugins to work with newer versions of the core VDR as long as no
37 // VDR header files have changed.
38 
39 // The MainMenuHook Patch's version number:
40 #define MAINMENUHOOKSVERSION "1.0.1"
41 #define MAINMENUHOOKSVERSNUM 10001 // Version * 10000 + Major * 100 + Minor
42 
43 #define MAXPRIORITY 99
44 #define MINPRIORITY (-MAXPRIORITY)
45 #define LIVEPRIORITY 0 // priority used when selecting a device for live viewing
46 #define TRANSFERPRIORITY (LIVEPRIORITY - 1) // priority used for actual local Transfer Mode
47 #define IDLEPRIORITY (MINPRIORITY - 1) // priority of an idle device
48 #define MAXLIFETIME 99
49 #define DEFINSTRECTIME 180 // default instant recording time (minutes)
50 
51 #define TIMERMACRO_TITLE "TITLE"
52 #define TIMERMACRO_EPISODE "EPISODE"
53 
54 #define MINOSDWIDTH 480
55 #define MAXOSDWIDTH 1920
56 #define MINOSDHEIGHT 324
57 #define MAXOSDHEIGHT 1200
58 
59 #define MaxFileName NAME_MAX // obsolete - use NAME_MAX directly instead!
60 #define MaxSkinName 16
61 #define MaxThemeName 16
62 
63 // Basically VDR works according to the DVB standard, but there are countries/providers
64 // that use other standards, which in some details deviate from the DVB standard.
65 // This makes it necessary to handle things differently in some areas, depending on
66 // which standard is actually used. The following macros are used to distinguish
67 // these cases (make sure to adjust cMenuSetupDVB::standardComplianceTexts accordingly
68 // when adding a new standard):
69 
70 #define STANDARD_DVB 0
71 #define STANDARD_ANSISCTE 1
72 
73 typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2)
74 
75 class cSVDRPhost : public cListObject {
76 private:
77  struct in_addr addr;
79 public:
80  cSVDRPhost(void);
81  bool Parse(const char *s);
82  bool IsLocalhost(void);
83  bool Accepts(in_addr_t Address);
84  };
85 
87 private:
88  int size;
89  int *array;
90 public:
91  cSatCableNumbers(int Size, const char *s = NULL);
93  int Size(void) const { return size; }
94  int *Array(void) { return array; }
95  bool FromString(const char *s);
96  cString ToString(void);
97  int FirstDeviceIndex(int DeviceIndex) const;
103  };
104 
105 template<class T> class cConfig : public cList<T> {
106 private:
107  char *fileName;
109  void Clear(void)
110  {
111  free(fileName);
112  fileName = NULL;
113  cList<T>::Clear();
114  }
115 public:
116  cConfig(void) { fileName = NULL; }
117  virtual ~cConfig() { free(fileName); }
118  const char *FileName(void) { return fileName; }
119  bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false)
120  {
122  if (FileName) {
123  free(fileName);
124  fileName = strdup(FileName);
125  allowComments = AllowComments;
126  }
127  bool result = !MustExist;
128  if (fileName && access(fileName, F_OK) == 0) {
129  isyslog("loading %s", fileName);
130  FILE *f = fopen(fileName, "r");
131  if (f) {
132  char *s;
133  int line = 0;
134  cReadLine ReadLine;
135  result = true;
136  while ((s = ReadLine.Read(f)) != NULL) {
137  line++;
138  if (allowComments) {
139  char *p = strchr(s, '#');
140  if (p)
141  *p = 0;
142  }
143  stripspace(s);
144  if (!isempty(s)) {
145  T *l = new T;
146  if (l->Parse(s))
147  this->Add(l);
148  else {
149  esyslog("ERROR: error in %s, line %d", fileName, line);
150  delete l;
151  result = false;
152  }
153  }
154  }
155  fclose(f);
156  }
157  else {
158  LOG_ERROR_STR(fileName);
159  result = false;
160  }
161  }
162  if (!result)
163  fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
164  return result;
165  }
166  bool Save(void)
167  {
168  bool result = true;
169  T *l = (T *)this->First();
170  cSafeFile f(fileName);
171  if (f.Open()) {
172  while (l) {
173  if (!l->Save(f)) {
174  result = false;
175  break;
176  }
177  l = (T *)l->Next();
178  }
179  if (!f.Close())
180  result = false;
181  }
182  else
183  result = false;
184  return result;
185  }
186  };
187 
188 class cNestedItem : public cListObject {
189 private:
190  char *text;
192 public:
193  cNestedItem(const char *Text, bool WithSubItems = false);
194  virtual ~cNestedItem();
195  virtual int Compare(const cListObject &ListObject) const;
196  const char *Text(void) const { return text; }
198  void AddSubItem(cNestedItem *Item);
199  void SetText(const char *Text);
200  void SetSubItems(bool On);
201  };
202 
203 class cNestedItemList : public cList<cNestedItem> {
204 private:
205  char *fileName;
206  bool Parse(FILE *f, cList<cNestedItem> *List, int &Line);
207  bool Write(FILE *f, cList<cNestedItem> *List, int Indent = 0);
208 public:
209  cNestedItemList(void);
210  virtual ~cNestedItemList();
211  void Clear(void);
212  bool Load(const char *FileName);
213  bool Save(void);
214  };
215 
216 class cSVDRPhosts : public cConfig<cSVDRPhost> {
217 public:
218  bool LocalhostOnly(void);
219  bool Acceptable(in_addr_t Address);
220  };
221 
222 extern cNestedItemList Folders;
225 extern cSVDRPhosts SVDRPhosts;
226 
227 class cSetupLine : public cListObject {
228 private:
229  char *plugin;
230  char *name;
231  char *value;
232 public:
233  cSetupLine(void);
234  cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL);
235  virtual ~cSetupLine();
236  virtual int Compare(const cListObject &ListObject) const;
237  const char *Plugin(void) { return plugin; }
238  const char *Name(void) { return name; }
239  const char *Value(void) { return value; }
240  bool Parse(char *s);
241  bool Save(FILE *f);
242  };
243 
244 class cSetup : public cConfig<cSetupLine> {
245  friend class cPlugin; // needs to be able to call Store()
246 private:
247  void StoreLanguages(const char *Name, int *Values);
248  bool ParseLanguages(const char *Value, int *Values);
249  bool Parse(const char *Name, const char *Value);
250  cSetupLine *Get(const char *Name, const char *Plugin = NULL);
251  void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false);
252  void Store(const char *Name, int Value, const char *Plugin = NULL);
253  void Store(const char *Name, double &Value, const char *Plugin = NULL);
254 public:
255  // Also adjust cMenuSetup (menu.c) when adding parameters here!
268  char NameInstantRecord[NAME_MAX + 1];
270  int LnbSLOF;
273  int DiSEqC;
297  int UseVps;
312  double OSDAspect;
319  double FontOsdSizeP;
320  double FontSmlSizeP;
321  double FontFixSizeP;
335  int ResumeID;
346  cSetup(void);
347  cSetup& operator= (const cSetup &s);
348  bool Load(const char *FileName);
349  bool Save(void);
350  };
351 
352 extern cSetup Setup;
353 
354 #endif //__CONFIG_H
cConfig(void)
Definition: config.h:116
int AntiAlias
Definition: config.h:315
cSetupLine * Get(const char *Name, const char *Plugin=NULL)
Definition: config.c:488
double OSDHeightP
Definition: config.h:310
bool Parse(FILE *f, cList< cNestedItem > *List, int &Line)
Definition: config.c:184
cNestedItemList Folders
Definition: config.c:274
cString DeviceBondings
Definition: config.h:345
int CurrentChannel
Definition: config.h:336
bool isempty(const char *s)
Definition: tools.c:248
const char * Text(void) const
Definition: config.h:196
int StandardCompliance
Definition: config.h:277
int MultiSpeedMode
Definition: config.h:330
cSetupLine(void)
Definition: config.c:306
double OSDWidthP
Definition: config.h:310
cNestedItemList Commands
Definition: config.c:275
bool Close(void)
Definition: tools.c:1603
char * plugin
Definition: config.h:229
char * name
Definition: config.h:230
double FontFixSizeP
Definition: config.h:321
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:1945
const char * Name(void)
Definition: plugin.h:34
bool Parse(const char *s)
Definition: config.c:34
int UseVps
Definition: config.h:297
char * stripspace(char *s)
Definition: tools.c:176
bool Write(FILE *f, cList< cNestedItem > *List, int Indent=0)
Definition: config.c:213
double FontOsdSizeP
Definition: config.h:319
bool Open(void)
Definition: tools.c:1593
void Store(const char *Name, const char *Value, const char *Plugin=NULL, bool AllowMultiple=false)
Definition: config.c:499
#define I18N_MAX_LANGUAGES
Definition: i18n.h:18
char * text
Definition: config.h:190
int DefaultPriority
Definition: config.h:293
const char * Name(void)
Definition: config.h:238
int ZapTimeout
Definition: config.h:289
int PausePriority
Definition: config.h:294
Definition: plugin.h:20
virtual ~cConfig()
Definition: config.h:117
cNestedItemList RecordingCommands
Definition: config.c:276
#define esyslog(a...)
Definition: tools.h:34
int MinUserInactivity
Definition: config.h:328
int FontFixSize
Definition: config.h:324
char FontSml[MAXFONTNAME]
Definition: config.h:317
int AlwaysSortFoldersFirst
Definition: config.h:301
#define LOG_ERROR_STR(s)
Definition: tools.h:39
bool Save(void)
Definition: config.c:690
int EPGLanguages[I18N_MAX_LANGUAGES+1]
Definition: config.h:284
bool Load(const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
Definition: config.h:119
Definition: tools.h:479
int PauseLifetime
Definition: config.h:294
int MarkInstantRecord
Definition: config.h:267
void SetSubItems(bool On)
Definition: config.c:162
int RecordingDirs
Definition: config.h:299
int UseSubtitle
Definition: config.h:296
#define MAXFONTNAME
Definition: font.h:17
const char * Plugin(void)
Definition: config.h:237
int OSDTop
Definition: config.h:311
int EPGLinger
Definition: config.h:287
int ShowReplayMode
Definition: config.h:331
int MenuKeyCloses
Definition: config.h:266
void SetText(const char *Text)
Definition: config.c:156
virtual ~cSetupLine()
Definition: config.c:318
int ColorKey2
Definition: config.h:303
cString ToString(void)
Definition: config.c:107
int ShowInfoOnChSwitch
Definition: config.h:262
int CurrentDolby
Definition: config.h:338
const char * FileName(void)
Definition: config.h:118
bool LocalhostOnly(void)
Definition: config.c:282
int ChannelsWrap
Definition: config.h:340
char * Read(FILE *f)
Definition: tools.c:1329
int ChannelEntryTimeout
Definition: config.h:290
virtual void Clear(void)
Definition: tools.c:2018
cSatCableNumbers(int Size, const char *s=NULL)
Definition: config.c:69
#define MaxSkinName
Definition: config.h:60
char * fileName
Definition: config.h:205
int LnbFrequLo
Definition: config.h:271
int EmergencyExit
Definition: config.h:342
int TimeTransponder
Definition: config.h:276
bool Parse(char *s)
Definition: config.c:340
void AddSubItem(cNestedItem *Item)
Definition: config.c:148
virtual ~cNestedItem()
Definition: config.c:137
int NumberKeysForChars
Definition: config.h:302
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
Definition: config.c:325
int InitialVolume
Definition: config.h:339
char * value
Definition: config.h:231
uint32_t in_addr_t
Definition: config.h:73
char * fileName
Definition: config.h:107
void Clear(void)
Definition: config.c:227
int SubtitleFgTransparency
Definition: config.h:283
int ChannelInfoPos
Definition: config.h:308
bool Save(void)
Definition: config.h:166
#define MaxThemeName
Definition: config.h:61
double OSDLeftP
Definition: config.h:310
bool Parse(const char *Name, const char *Value)
Definition: config.c:580
bool FromString(const char *s)
Definition: config.c:81
cSVDRPhost(void)
Definition: config.c:28
char FontOsd[MAXFONTNAME]
Definition: config.h:316
int LnbSLOF
Definition: config.h:270
bool IsLocalhost(void)
Definition: config.c:57
int SVDRPTimeout
Definition: config.h:288
void Clear(void)
Definition: config.h:109
const char * Value(void)
Definition: config.h:239
int SubtitleLanguages[I18N_MAX_LANGUAGES+1]
Definition: config.h:281
int FoldersInTimerMenu
Definition: config.h:300
int TimeSource
Definition: config.h:275
cList< cNestedItem > * SubItems(void)
Definition: config.h:197
int EPGScanTimeout
Definition: config.h:285
int SubtitleOffset
Definition: config.h:282
int VideoFormat
Definition: config.h:305
int PauseKeyHandling
Definition: config.h:295
Definition: config.h:244
in_addr_t mask
Definition: config.h:78
int OSDLeft
Definition: config.h:311
bool Accepts(in_addr_t Address)
Definition: config.c:62
int SplitEditedFiles
Definition: config.h:326
int ColorKey3
Definition: config.h:303
int MinEventTimeout
Definition: config.h:328
int __BeginData__
Definition: config.h:256
int LnbFrequHi
Definition: config.h:272
cNestedItem(const char *Text, bool WithSubItems=false)
Definition: config.c:131
int ProgressDisplayTime
Definition: config.h:333
int RcRepeatDelay
Definition: config.h:291
int InstantRecordTime
Definition: config.h:269
int MaxVideoFileSize
Definition: config.h:325
cSVDRPhosts SVDRPhosts
Definition: config.c:280
int ChannelInfoTime
Definition: config.h:309
int __EndData__
Definition: config.h:343
int PrimaryDVB
Definition: config.h:261
int SetSystemTime
Definition: config.h:274
int VpsMargin
Definition: config.h:298
void StoreLanguages(const char *Name, int *Values)
Definition: config.c:545
int UseDolbyDigital
Definition: config.h:307
cSetup Setup
Definition: config.c:372
T * First(void) const
Definition: tools.h:482
char FontFix[MAXFONTNAME]
Definition: config.h:318
int FirstDeviceIndex(int DeviceIndex) const
Returns the first device index (starting at 0) that uses the same sat cable number as the device with...
Definition: config.c:116
int MarginStop
Definition: config.h:278
int ShowChannelNamesWithSource
Definition: config.h:341
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
Definition: config.c:143
int WarEagleIcons
Definition: config.h:260
virtual ~cNestedItemList()
Definition: config.c:179
int AudioLanguages[I18N_MAX_LANGUAGES+1]
Definition: config.h:279
int ColorKey1
Definition: config.h:303
bool Load(const char *FileName)
Definition: config.c:520
time_t NextWakeupTime
Definition: config.h:329
double OSDAspect
Definition: config.h:312
int PauseOnMarkSet
Definition: config.h:334
int UpdateChannels
Definition: config.h:306
bool ParseLanguages(const char *Value, int *Values)
Definition: config.c:564
#define I18N_MAX_LOCALE_LEN
Definition: i18n.h:17
bool Save(FILE *f)
Definition: config.c:365
int DelTimeshiftRec
Definition: config.h:327
int TimeoutRequChInfo
Definition: config.h:263
cList< cNestedItem > * subItems
Definition: config.h:191
#define isyslog(a...)
Definition: tools.h:35
double FontSmlSizeP
Definition: config.h:320
cSetup(void)
Definition: config.c:374
int EPGBugfixLevel
Definition: config.h:286
cSetup & operator=(const cSetup &s)
Definition: config.c:480
int CurrentVolume
Definition: config.h:337
int FontOsdSize
Definition: config.h:322
int UseSmallFont
Definition: config.h:314
cNestedItemList(void)
Definition: config.c:174
int ColorKey0
Definition: config.h:303
bool Acceptable(in_addr_t Address)
Definition: config.c:293
int * array
Definition: config.h:89
struct in_addr addr
Definition: config.h:77
int MenuScrollWrap
Definition: config.h:265
bool Load(const char *FileName)
Definition: config.c:234
int MenuScrollPage
Definition: config.h:264
char NameInstantRecord[NAME_MAX+1]
Definition: config.h:268
int * Array(void)
Definition: config.h:94
int OSDHeight
Definition: config.h:311
int FontSmlSize
Definition: config.h:323
bool allowComments
Definition: config.h:108
int DisplaySubtitles
Definition: config.h:280
int VideoDisplayFormat
Definition: config.h:304
int OSDWidth
Definition: config.h:311
char OSDTheme[MaxThemeName]
Definition: config.h:259
cString InitialChannel
Definition: config.h:344
char OSDSkin[MaxSkinName]
Definition: config.h:258
bool Save(void)
Definition: config.c:258
int OSDMessageTime
Definition: config.h:313
int MarginStart
Definition: config.h:278
int Size(void) const
Definition: config.h:93
char OSDLanguage[I18N_MAX_LOCALE_LEN]
Definition: config.h:257
int SubtitleBgTransparency
Definition: config.h:283
int ResumeID
Definition: config.h:335
int RcRepeatDelta
Definition: config.h:292
~cSatCableNumbers()
Definition: config.c:76
Definition: tools.h:166
int DefaultLifetime
Definition: config.h:293
int ShowRemainingTime
Definition: config.h:332
double OSDTopP
Definition: config.h:310
int DiSEqC
Definition: config.h:273