vdr  2.0.2
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.2 2013/04/27 10:18: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.0.2"
26 #define VDRVERSNUM 20002 // Version * 10000 + Major * 100 + Minor
27 
28 // The plugin API's version number:
29 
30 #define APIVERSION "2.0.0"
31 #define APIVERSNUM 20000 // 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 
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 {
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;
226 extern cSVDRPhosts SVDRPhosts;
227 
228 class cSetupLine : public cListObject {
229 private:
230  char *plugin;
231  char *name;
232  char *value;
233 public:
234  cSetupLine(void);
235  cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL);
236  virtual ~cSetupLine();
237  virtual int Compare(const cListObject &ListObject) const;
238  const char *Plugin(void) { return plugin; }
239  const char *Name(void) { return name; }
240  const char *Value(void) { return value; }
241  bool Parse(char *s);
242  bool Save(FILE *f);
243  };
244 
245 class cSetup : public cConfig<cSetupLine> {
246  friend class cPlugin; // needs to be able to call Store()
247 private:
248  void StoreLanguages(const char *Name, int *Values);
249  bool ParseLanguages(const char *Value, int *Values);
250  bool Parse(const char *Name, const char *Value);
251  cSetupLine *Get(const char *Name, const char *Plugin = NULL);
252  void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false);
253  void Store(const char *Name, int Value, const char *Plugin = NULL);
254  void Store(const char *Name, double &Value, const char *Plugin = NULL);
255 public:
256  // Also adjust cMenuSetup (menu.c) when adding parameters here!
268  char NameInstantRecord[NAME_MAX + 1];
270  int LnbSLOF;
273  int DiSEqC;
298  int UseVps;
313  double OSDAspect;
320  double FontOsdSizeP;
321  double FontSmlSizeP;
322  double FontFixSizeP;
337  int ResumeID;
348  cSetup(void);
349  cSetup& operator= (const cSetup &s);
350  bool Load(const char *FileName);
351  bool Save(void);
352  };
353 
354 extern cSetup Setup;
355 
356 #endif //__CONFIG_H
357