vdr  1.7.31
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.53 2012/09/15 11:51:54 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 "1.7.31"
26 #define VDRVERSNUM 10731 // Version * 10000 + Major * 100 + Minor
27 
28 // The plugin API's version number:
29 
30 #define APIVERSION "1.7.31"
31 #define APIVERSNUM 10731 // Version * 10000 + Major * 100 + Minor
32 
33 #define JUMPPLAYVERSNUM 100
34 
35 // When loading plugins, VDR searches them by their APIVERSION, which
36 // may be smaller than VDRVERSION in case there have been no changes to
37 // VDR header files since the last APIVERSION. This allows compiled
38 // plugins to work with newer versions of the core VDR as long as no
39 // VDR header files have changed.
40 
41 #define MAXPRIORITY 99
42 #define MINPRIORITY (-MAXPRIORITY)
43 #define LIVEPRIORITY 0 // priority used when selecting a device for live viewing
44 #define TRANSFERPRIORITY (LIVEPRIORITY - 1) // priority used for actual local Transfer Mode
45 #define IDLEPRIORITY (MINPRIORITY - 1) // priority of an idle device
46 #define MAXLIFETIME 99
47 #define DEFINSTRECTIME 180 // default instant recording time (minutes)
48 
49 #define MINOSDWIDTH 480
50 #define MAXOSDWIDTH 1920
51 #define MINOSDHEIGHT 324
52 #define MAXOSDHEIGHT 1200
53 
54 // The MainMenuHook Patch's version number:
55 #define MAINMENUHOOKSVERSION "1.0.1"
56 #define MAINMENUHOOKSVERSNUM 10001 // Version * 10000 + Major * 100 + Minor
57 
58 #define MaxFileName 256
59 #define MaxSkinName 16
60 #define MaxThemeName 16
61 
62 // Basically VDR works according to the DVB standard, but there are countries/providers
63 // that use other standards, which in some details deviate from the DVB standard.
64 // This makes it necessary to handle things differently in some areas, depending on
65 // which standard is actually used. The following macros are used to distinguish
66 // these cases (make sure to adjust cMenuSetupDVB::standardComplianceTexts accordingly
67 // when adding a new standard):
68 
69 #define STANDARD_DVB 0
70 #define STANDARD_ANSISCTE 1
71 
72 typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2)
73 
74 class cSVDRPhost : public cListObject {
75 private:
76  struct in_addr addr;
78 public:
79  cSVDRPhost(void);
80  bool Parse(const char *s);
81  bool IsLocalhost(void);
82  bool Accepts(in_addr_t Address);
83  };
84 
86 private:
87  int size;
88  int *array;
89 public:
90  cSatCableNumbers(int Size, const char *s = NULL);
92  int Size(void) const { return size; }
93  int *Array(void) { return array; }
94  bool FromString(const char *s);
95  cString ToString(void);
96  int FirstDeviceIndex(int DeviceIndex) const;
102  };
103 
104 template<class T> class cConfig : public cList<T> {
105 private:
106  char *fileName;
108  void Clear(void)
109  {
110  free(fileName);
111  fileName = NULL;
112  cList<T>::Clear();
113  }
114 public:
115  cConfig(void) { fileName = NULL; }
116  virtual ~cConfig() { free(fileName); }
117  const char *FileName(void) { return fileName; }
118  bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false)
119  {
121  if (FileName) {
122  free(fileName);
123  fileName = strdup(FileName);
124  allowComments = AllowComments;
125  }
126  bool result = !MustExist;
127  if (fileName && access(fileName, F_OK) == 0) {
128  isyslog("loading %s", fileName);
129  FILE *f = fopen(fileName, "r");
130  if (f) {
131  char *s;
132  int line = 0;
133  cReadLine ReadLine;
134  result = true;
135  while ((s = ReadLine.Read(f)) != NULL) {
136  line++;
137  if (allowComments) {
138  char *p = strchr(s, '#');
139  if (p)
140  *p = 0;
141  }
142  stripspace(s);
143  if (!isempty(s)) {
144  T *l = new T;
145  if (l->Parse(s))
146  this->Add(l);
147  else {
148  esyslog("ERROR: error in %s, line %d", fileName, line);
149  delete l;
150  result = false;
151  }
152  }
153  }
154  fclose(f);
155  }
156  else {
158  result = false;
159  }
160  }
161  if (!result)
162  fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
163  return result;
164  }
165  bool Save(void)
166  {
167  bool result = true;
168  T *l = (T *)this->First();
169  cSafeFile f(fileName);
170  if (f.Open()) {
171  while (l) {
172  if (!l->Save(f)) {
173  result = false;
174  break;
175  }
176  l = (T *)l->Next();
177  }
178  if (!f.Close())
179  result = false;
180  }
181  else
182  result = false;
183  return result;
184  }
185  };
186 
187 class cNestedItem : public cListObject {
188 private:
189  char *text;
191 public:
192  cNestedItem(const char *Text, bool WithSubItems = false);
193  virtual ~cNestedItem();
194  virtual int Compare(const cListObject &ListObject) const;
195  const char *Text(void) const { return text; }
197  void AddSubItem(cNestedItem *Item);
198  void SetText(const char *Text);
199  void SetSubItems(bool On);
200  };
201 
202 class cNestedItemList : public cList<cNestedItem> {
203 private:
204  char *fileName;
205  bool Parse(FILE *f, cList<cNestedItem> *List, int &Line);
206  bool Write(FILE *f, cList<cNestedItem> *List, int Indent = 0);
207 public:
208  cNestedItemList(void);
209  virtual ~cNestedItemList();
210  void Clear(void);
211  bool Load(const char *FileName);
212  bool Save(void);
213  };
214 
215 class cSVDRPhosts : public cConfig<cSVDRPhost> {
216 public:
217  bool LocalhostOnly(void);
218  bool Acceptable(in_addr_t Address);
219  };
220 
221 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!
269  int LnbSLOF;
272  int DiSEqC;
295  int UseVps;
309  double OSDAspect;
316  double FontOsdSizeP;
317  double FontSmlSizeP;
318  double FontFixSizeP;
332  int ResumeID;
333  int JumpPlay;
334  int PlayJump;
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