vdr  2.2.0
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 3.21 2015/02/13 15:39:08 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.2.0"
26 #define VDRVERSNUM 20200 // Version * 10000 + Major * 100 + Minor
27 
28 // The plugin API's version number:
29 
30 #define APIVERSION "2.2.0"
31 #define APIVERSNUM 20200 // 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 #define MAXPRIORITY 99
40 #define MINPRIORITY (-MAXPRIORITY)
41 #define LIVEPRIORITY 0 // priority used when selecting a device for live viewing
42 #define TRANSFERPRIORITY (LIVEPRIORITY - 1) // priority used for actual local Transfer Mode
43 #define IDLEPRIORITY (MINPRIORITY - 1) // priority of an idle device
44 #define MAXLIFETIME 99
45 #define DEFINSTRECTIME 180 // default instant recording time (minutes)
46 
47 #define TIMERMACRO_TITLE "TITLE"
48 #define TIMERMACRO_EPISODE "EPISODE"
49 
50 // The MainMenuHook Patch's version number:
51 #define MAINMENUHOOKSVERSION "1.0.1"
52 #define MAINMENUHOOKSVERSNUM 10001 // Version * 10000 + Major * 100 + Minor
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 #define STANDARD_NORDIG 2
73 
74 typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2)
75 
76 class cSVDRPhost : public cListObject {
77 private:
78  struct in_addr addr;
80 public:
81  cSVDRPhost(void);
82  bool Parse(const char *s);
83  bool IsLocalhost(void);
84  bool Accepts(in_addr_t Address);
85  };
86 
88 private:
89  int size;
90  int *array;
91 public:
92  cSatCableNumbers(int Size, const char *s = NULL);
94  int Size(void) const { return size; }
95  int *Array(void) { return array; }
96  bool FromString(const char *s);
97  cString ToString(void);
98  int FirstDeviceIndex(int DeviceIndex) const;
104  };
105 
106 template<class T> class cConfig : public cList<T> {
107 private:
108  char *fileName;
110  void Clear(void)
111  {
112  free(fileName);
113  fileName = NULL;
114  cList<T>::Clear();
115  }
116 public:
117  cConfig(void) { fileName = NULL; }
118  virtual ~cConfig() { free(fileName); }
119  const char *FileName(void) { return fileName; }
120  bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false)
121  {
123  if (FileName) {
124  free(fileName);
125  fileName = strdup(FileName);
126  allowComments = AllowComments;
127  }
128  bool result = !MustExist;
129  if (fileName && access(fileName, F_OK) == 0) {
130  isyslog("loading %s", fileName);
131  FILE *f = fopen(fileName, "r");
132  if (f) {
133  char *s;
134  int line = 0;
135  cReadLine ReadLine;
136  result = true;
137  while ((s = ReadLine.Read(f)) != NULL) {
138  line++;
139  if (allowComments) {
140  char *p = strchr(s, '#');
141  if (p)
142  *p = 0;
143  }
144  stripspace(s);
145  if (!isempty(s)) {
146  T *l = new T;
147  if (l->Parse(s))
148  this->Add(l);
149  else {
150  esyslog("ERROR: error in %s, line %d", fileName, line);
151  delete l;
152  result = false;
153  }
154  }
155  }
156  fclose(f);
157  }
158  else {
159  LOG_ERROR_STR(fileName);
160  result = false;
161  }
162  }
163  if (!result)
164  fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
165  return result;
166  }
167  bool Save(void)
168  {
169  bool result = true;
170  T *l = (T *)this->First();
171  cSafeFile f(fileName);
172  if (f.Open()) {
173  while (l) {
174  if (!l->Save(f)) {
175  result = false;
176  break;
177  }
178  l = (T *)l->Next();
179  }
180  if (!f.Close())
181  result = false;
182  }
183  else
184  result = false;
185  return result;
186  }
187  };
188 
189 class cNestedItem : public cListObject {
190 private:
191  char *text;
193 public:
194  cNestedItem(const char *Text, bool WithSubItems = false);
195  virtual ~cNestedItem();
196  virtual int Compare(const cListObject &ListObject) const;
197  const char *Text(void) const { return text; }
198  cList<cNestedItem> *SubItems(void) { return subItems; }
199  void AddSubItem(cNestedItem *Item);
200  void SetText(const char *Text);
201  void SetSubItems(bool On);
202  };
203 
204 class cNestedItemList : public cList<cNestedItem> {
205 private:
206  char *fileName;
207  bool Parse(FILE *f, cList<cNestedItem> *List, int &Line);
208  bool Write(FILE *f, cList<cNestedItem> *List, int Indent = 0);
209 public:
210  cNestedItemList(void);
211  virtual ~cNestedItemList();
212  void Clear(void);
213  bool Load(const char *FileName);
214  bool Save(void);
215  };
216 
217 class cSVDRPhosts : public cConfig<cSVDRPhost> {
218 public:
219  bool LocalhostOnly(void);
220  bool Acceptable(in_addr_t Address);
221  };
222 
223 extern cNestedItemList Folders;
227 extern cSVDRPhosts SVDRPhosts;
228 
229 class cSetupLine : public cListObject {
230 private:
231  char *plugin;
232  char *name;
233  char *value;
234 public:
235  cSetupLine(void);
236  cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL);
237  virtual ~cSetupLine();
238  virtual int Compare(const cListObject &ListObject) const;
239  const char *Plugin(void) { return plugin; }
240  const char *Name(void) { return name; }
241  const char *Value(void) { return value; }
242  bool Parse(char *s);
243  bool Save(FILE *f);
244  };
245 
246 class cSetup : public cConfig<cSetupLine> {
247  friend class cPlugin; // needs to be able to call Store()
248 private:
249  void StoreLanguages(const char *Name, int *Values);
250  bool ParseLanguages(const char *Value, int *Values);
251  bool Parse(const char *Name, const char *Value);
252  cSetupLine *Get(const char *Name, const char *Plugin = NULL);
253  void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false);
254  void Store(const char *Name, int Value, const char *Plugin = NULL);
255  void Store(const char *Name, double &Value, const char *Plugin = NULL);
256 public:
257  // Also adjust cMenuSetup (menu.c) when adding parameters here!
259  char OSDLanguage[I18N_MAX_LOCALE_LEN];
260  char OSDSkin[MaxSkinName];
261  char OSDTheme[MaxThemeName];
269  char NameInstantRecord[NAME_MAX + 1];
271  int LnbSLOF;
274  int DiSEqC;
276  int SiteLat;
277  int SiteLon;
285  int MarginStart, MarginStop;
286  int AudioLanguages[I18N_MAX_LANGUAGES + 1];
289  int SubtitleLanguages[I18N_MAX_LANGUAGES + 1];
291  int SubtitleFgTransparency, SubtitleBgTransparency;
292  int EPGLanguages[I18N_MAX_LANGUAGES + 1];
301  int DefaultPriority, DefaultLifetime;
302  int PausePriority, PauseLifetime;
305  int UseVps;
311  int ColorKey0, ColorKey1, ColorKey2, ColorKey3;
318  double OSDLeftP, OSDTopP, OSDWidthP, OSDHeightP;
319  int OSDLeft, OSDTop, OSDWidth, OSDHeight;
320  double OSDAspect;
324  char FontOsd[MAXFONTNAME];
325  char FontSml[MAXFONTNAME];
326  char FontFix[MAXFONTNAME];
327  double FontOsdSizeP;
328  double FontSmlSizeP;
329  double FontFixSizeP;
337  int MinEventTimeout, MinUserInactivity;
353  int ResumeID;
366  cSetup(void);
367  cSetup& operator= (const cSetup &s);
368  bool Load(const char *FileName);
369  bool Save(void);
370  };
371 
372 extern cSetup Setup;
373 
374 #endif //__CONFIG_H
cConfig(void)
Definition: config.h:117
int AntiAlias
Definition: config.h:323
cNestedItemList Folders
Definition: config.c:274
cString DeviceBondings
Definition: config.h:365
int DumpNaluFill
Definition: config.h:336
int CurrentChannel
Definition: config.h:354
bool isempty(const char *s)
Definition: tools.c:297
const char * Text(void) const
Definition: config.h:197
int StandardCompliance
Definition: config.h:284
int MultiSpeedMode
Definition: config.h:339
double OSDWidthP
Definition: config.h:318
cNestedItemList Commands
Definition: config.c:275
bool Close(void)
Definition: tools.c:1672
char * plugin
Definition: config.h:231
char * name
Definition: config.h:232
double FontFixSizeP
Definition: config.h:329
cNestedItemList TimerCommands
Definition: config.c:277
const char * Name(void)
Definition: plugin.h:34
bool Parse(const char *s)
Definition: config.c:34
int UseVps
Definition: config.h:305
char * stripspace(char *s)
Definition: tools.c:201
double FontOsdSizeP
Definition: config.h:327
bool Open(void)
Definition: tools.c:1662
#define I18N_MAX_LANGUAGES
Definition: i18n.h:18
char * text
Definition: config.h:191
int DefaultPriority
Definition: config.h:301
const char * Name(void)
Definition: config.h:240
int ZapTimeout
Definition: config.h:297
int PausePriority
Definition: config.h:302
int AdaptiveSkipPrevNext
Definition: config.h:350
Definition: plugin.h:20
virtual ~cConfig()
Definition: config.h:118
cNestedItemList RecordingCommands
Definition: config.c:276
#define esyslog(a...)
Definition: tools.h:34
int MinUserInactivity
Definition: config.h:337
int FontFixSize
Definition: config.h:332
int AlwaysSortFoldersFirst
Definition: config.h:309
int SkipEdited
Definition: config.h:345
#define LOG_ERROR_STR(s)
Definition: tools.h:39
bool Load(const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
Definition: config.h:120
Definition: tools.h:489
int MarkInstantRecord
Definition: config.h:268
int RecordingDirs
Definition: config.h:307
int UseSubtitle
Definition: config.h:304
#define MAXFONTNAME
Definition: font.h:17
const char * Plugin(void)
Definition: config.h:239
int EPGLinger
Definition: config.h:295
int ShowReplayMode
Definition: config.h:340
int MenuKeyCloses
Definition: config.h:267
int ShowInfoOnChSwitch
Definition: config.h:263
int CurrentDolby
Definition: config.h:358
const char * FileName(void)
Definition: config.h:119
int ChannelsWrap
Definition: config.h:360
char * Read(FILE *f)
Definition: tools.c:1398
int ChannelEntryTimeout
Definition: config.h:298
virtual void Clear(void)
Definition: tools.c:2087
#define MaxSkinName
Definition: config.h:60
char * fileName
Definition: config.h:206
int LnbFrequLo
Definition: config.h:272
int SkipSecondsRepeat
Definition: config.h:352
int SkipSeconds
Definition: config.h:351
int EmergencyExit
Definition: config.h:362
int TimeTransponder
Definition: config.h:283
int NumberKeysForChars
Definition: config.h:310
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: tools.h:460
int InitialVolume
Definition: config.h:359
int UsePositioner
Definition: config.h:275
char * value
Definition: config.h:233
uint32_t in_addr_t
Definition: config.h:74
char * fileName
Definition: config.h:108
int AdaptiveSkipAlternate
Definition: config.h:349
int SubtitleFgTransparency
Definition: config.h:291
int ChannelInfoPos
Definition: config.h:316
bool Save(void)
Definition: config.h:167
#define MaxThemeName
Definition: config.h:61
cSVDRPhost(void)
Definition: config.c:28
int LnbSLOF
Definition: config.h:271
int PositionerSwing
Definition: config.h:279
bool IsLocalhost(void)
Definition: config.c:57
int SVDRPTimeout
Definition: config.h:296
int PauseAtLastMark
Definition: config.h:346
void Clear(void)
Definition: config.h:110
int AdaptiveSkipTimeout
Definition: config.h:348
const char * Value(void)
Definition: config.h:241
int FoldersInTimerMenu
Definition: config.h:308
int TimeSource
Definition: config.h:282
int PauseOnMarkJump
Definition: config.h:344
cList< cNestedItem > * SubItems(void)
Definition: config.h:198
int EPGScanTimeout
Definition: config.h:293
int SubtitleOffset
Definition: config.h:290
int VideoFormat
Definition: config.h:313
int PauseKeyHandling
Definition: config.h:303
int SiteLon
Definition: config.h:277
Definition: config.h:246
int PositionerLastLon
Definition: config.h:280
in_addr_t mask
Definition: config.h:79
bool Accepts(in_addr_t Address)
Definition: config.c:62
int SplitEditedFiles
Definition: config.h:334
int ColorKey3
Definition: config.h:311
int __BeginData__
Definition: config.h:258
int LnbFrequHi
Definition: config.h:273
int ProgressDisplayTime
Definition: config.h:342
int RcRepeatDelay
Definition: config.h:299
int InstantRecordTime
Definition: config.h:270
int MaxVideoFileSize
Definition: config.h:333
cSVDRPhosts SVDRPhosts
Definition: config.c:281
int ChannelInfoTime
Definition: config.h:317
int __EndData__
Definition: config.h:363
int PrimaryDVB
Definition: config.h:262
int SetSystemTime
Definition: config.h:281
int VpsMargin
Definition: config.h:306
int UseDolbyDigital
Definition: config.h:315
cSetup Setup
Definition: config.c:373
int MarginStop
Definition: config.h:285
int ShowChannelNamesWithSource
Definition: config.h:361
time_t NextWakeupTime
Definition: config.h:338
double OSDAspect
Definition: config.h:320
int PauseOnMarkSet
Definition: config.h:343
int UpdateChannels
Definition: config.h:314
#define I18N_MAX_LOCALE_LEN
Definition: i18n.h:17
int DelTimeshiftRec
Definition: config.h:335
int TimeoutRequChInfo
Definition: config.h:264
cList< cNestedItem > * subItems
Definition: config.h:192
#define isyslog(a...)
Definition: tools.h:35
double FontSmlSizeP
Definition: config.h:328
int EPGBugfixLevel
Definition: config.h:294
int CurrentVolume
Definition: config.h:355
int FontOsdSize
Definition: config.h:330
int UseSmallFont
Definition: config.h:322
int PositionerSpeed
Definition: config.h:278
int * array
Definition: config.h:90
struct in_addr addr
Definition: config.h:78
int MenuScrollWrap
Definition: config.h:266
int MenuScrollPage
Definition: config.h:265
int * Array(void)
Definition: config.h:95
int SupportTeletext
Definition: config.h:288
int AdaptiveSkipInitial
Definition: config.h:347
int FontSmlSize
Definition: config.h:331
bool allowComments
Definition: config.h:109
int DisplaySubtitles
Definition: config.h:287
int VideoDisplayFormat
Definition: config.h:312
int VolumeLinearize
Definition: config.h:357
int OSDWidth
Definition: config.h:319
cString InitialChannel
Definition: config.h:364
int VolumeSteps
Definition: config.h:356
int OSDMessageTime
Definition: config.h:321
int SiteLat
Definition: config.h:276
Definition: runvdr.c:107
int Size(void) const
Definition: config.h:94
int ResumeID
Definition: config.h:353
int RcRepeatDelta
Definition: config.h:300
Definition: tools.h:168
int ShowRemainingTime
Definition: config.h:341
int DiSEqC
Definition: config.h:274