vdr  1.7.27
config.h
Go to the documentation of this file.
00001 /*
00002  * config.h: Configuration file handling
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: config.h 2.45 2012/03/11 10:41:44 kls Exp $
00008  */
00009 
00010 #ifndef __CONFIG_H
00011 #define __CONFIG_H
00012 
00013 #include <arpa/inet.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <time.h>
00018 #include <unistd.h>
00019 #include "i18n.h"
00020 #include "font.h"
00021 #include "tools.h"
00022 
00023 // VDR's own version number:
00024 
00025 #define VDRVERSION  "1.7.27"
00026 #define VDRVERSNUM   10727  // Version * 10000 + Major * 100 + Minor
00027 
00028 // The plugin API's version number:
00029 
00030 #define APIVERSION  "1.7.27"
00031 #define APIVERSNUM   10727  // Version * 10000 + Major * 100 + Minor
00032 
00033 #define JUMPPLAYVERSNUM 100
00034 
00035 // When loading plugins, VDR searches them by their APIVERSION, which
00036 // may be smaller than VDRVERSION in case there have been no changes to
00037 // VDR header files since the last APIVERSION. This allows compiled
00038 // plugins to work with newer versions of the core VDR as long as no
00039 // VDR header files have changed.
00040 
00041 #define LIEMIKUUTIO  134
00042  
00043 #define MAXPRIORITY       99
00044 #define MINPRIORITY       (-MAXPRIORITY)
00045 #define LIVEPRIORITY      0                  // priority used when selecting a device for live viewing
00046 #define TRANSFERPRIORITY  (LIVEPRIORITY - 1) // priority used for actual local Transfer Mode
00047 #define IDLEPRIORITY      (MINPRIORITY - 1)  // priority of an idle device
00048 #define MAXLIFETIME       99
00049 
00050 #define MINOSDWIDTH   480
00051 #define MAXOSDWIDTH  1920
00052 #define MINOSDHEIGHT  324
00053 #define MAXOSDHEIGHT 1200
00054 
00055 // The MainMenuHook Patch's version number:
00056 #define MAINMENUHOOKSVERSION "1.0.1"
00057 #define MAINMENUHOOKSVERSNUM 10001  // Version * 10000 + Major * 100 + Minor
00058 
00059 #define MaxFileName 256
00060 #define MaxSkinName 16
00061 #define MaxThemeName 16
00062 
00063 typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2)
00064 
00065 class cSVDRPhost : public cListObject {
00066 private:
00067   struct in_addr addr;
00068   in_addr_t mask;
00069 public:
00070   cSVDRPhost(void);
00071   bool Parse(const char *s);
00072   bool IsLocalhost(void);
00073   bool Accepts(in_addr_t Address);
00074   };
00075 
00076 class cSatCableNumbers {
00077 private:
00078   int size;
00079   int *array;
00080 public:
00081   cSatCableNumbers(int Size, const char *s = NULL);
00082   ~cSatCableNumbers();
00083   int Size(void) const { return size; }
00084   int *Array(void) { return array; }
00085   bool FromString(const char *s);
00086   cString ToString(void);
00087   int FirstDeviceIndex(int DeviceIndex) const;
00093   };
00094 
00095 template<class T> class cConfig : public cList<T> {
00096 private:
00097   char *fileName;
00098   bool allowComments;
00099   void Clear(void)
00100   {
00101     free(fileName);
00102     fileName = NULL;
00103     cList<T>::Clear();
00104   }
00105 public:
00106   cConfig(void) { fileName = NULL; }
00107   virtual ~cConfig() { free(fileName); }
00108   const char *FileName(void) { return fileName; }
00109   bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false)
00110   {
00111     cConfig<T>::Clear();
00112     if (FileName) {
00113        free(fileName);
00114        fileName = strdup(FileName);
00115        allowComments = AllowComments;
00116        }
00117     bool result = !MustExist;
00118     if (fileName && access(fileName, F_OK) == 0) {
00119        isyslog("loading %s", fileName);
00120        FILE *f = fopen(fileName, "r");
00121        if (f) {
00122           char *s;
00123           int line = 0;
00124           cReadLine ReadLine;
00125           result = true;
00126           while ((s = ReadLine.Read(f)) != NULL) {
00127                 line++;
00128                 if (allowComments) {
00129                    char *p = strchr(s, '#');
00130                    if (p)
00131                       *p = 0;
00132                    }
00133                 stripspace(s);
00134                 if (!isempty(s)) {
00135                    T *l = new T;
00136                    if (l->Parse(s))
00137                       this->Add(l);
00138                    else {
00139                       esyslog("ERROR: error in %s, line %d", fileName, line);
00140                       delete l;
00141                       result = false;
00142                       }
00143                    }
00144                 }
00145           fclose(f);
00146           }
00147        else {
00148           LOG_ERROR_STR(fileName);
00149           result = false;
00150           }
00151        }
00152     if (!result)
00153        fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
00154     return result;
00155   }
00156   bool Save(void)
00157   {
00158     bool result = true;
00159     T *l = (T *)this->First();
00160     cSafeFile f(fileName);
00161     if (f.Open()) {
00162        while (l) {
00163              if (!l->Save(f)) {
00164                 result = false;
00165                 break;
00166                 }
00167              l = (T *)l->Next();
00168              }
00169        if (!f.Close())
00170           result = false;
00171        }
00172     else
00173        result = false;
00174     return result;
00175   }
00176   };
00177 
00178 class cNestedItem : public cListObject {
00179 private:
00180   char *text;
00181   cList<cNestedItem> *subItems;
00182 public:
00183   cNestedItem(const char *Text, bool WithSubItems = false);
00184   virtual ~cNestedItem();
00185   virtual int Compare(const cListObject &ListObject) const;
00186   const char *Text(void) const { return text; }
00187   cList<cNestedItem> *SubItems(void) { return subItems; }
00188   void AddSubItem(cNestedItem *Item);
00189   void SetText(const char *Text);
00190   void SetSubItems(bool On);
00191   };
00192 
00193 class cNestedItemList : public cList<cNestedItem> {
00194 private:
00195   char *fileName;
00196   bool Parse(FILE *f, cList<cNestedItem> *List, int &Line);
00197   bool Write(FILE *f, cList<cNestedItem> *List, int Indent = 0);
00198 public:
00199   cNestedItemList(void);
00200   virtual ~cNestedItemList();
00201   void Clear(void);
00202   bool Load(const char *FileName);
00203   bool Save(void);
00204   };
00205 
00206 class cSVDRPhosts : public cConfig<cSVDRPhost> {
00207 public:
00208   bool LocalhostOnly(void);
00209   bool Acceptable(in_addr_t Address);
00210   };
00211 
00212 extern cNestedItemList Folders;
00213 extern cNestedItemList Commands;
00214 extern cNestedItemList RecordingCommands;
00215 extern cNestedItemList TimerCommands;
00216 extern cSVDRPhosts SVDRPhosts;
00217 
00218 class cSetupLine : public cListObject {
00219 private:
00220   char *plugin;
00221   char *name;
00222   char *value;
00223 public:
00224   cSetupLine(void);
00225   cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL);
00226   virtual ~cSetupLine();
00227   virtual int Compare(const cListObject &ListObject) const;
00228   const char *Plugin(void) { return plugin; }
00229   const char *Name(void) { return name; }
00230   const char *Value(void) { return value; }
00231   bool Parse(char *s);
00232   bool Save(FILE *f);
00233   };
00234 
00235 class cSetup : public cConfig<cSetupLine> {
00236   friend class cPlugin; // needs to be able to call Store()
00237 private:
00238   void StoreLanguages(const char *Name, int *Values);
00239   bool ParseLanguages(const char *Value, int *Values);
00240   bool Parse(const char *Name, const char *Value);
00241   cSetupLine *Get(const char *Name, const char *Plugin = NULL);
00242   void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false);
00243   void Store(const char *Name, int Value, const char *Plugin = NULL);
00244   void Store(const char *Name, double &Value, const char *Plugin = NULL);
00245 public:
00246   // Also adjust cMenuSetup (menu.c) when adding parameters here!
00247   int __BeginData__;
00248   char OSDLanguage[I18N_MAX_LOCALE_LEN];
00249   char OSDSkin[MaxSkinName];
00250   char OSDTheme[MaxThemeName];
00251   int PrimaryDVB;
00252   int ShowInfoOnChSwitch;
00253   int TimeoutRequChInfo;
00254   int MenuScrollPage;
00255   int MenuScrollWrap;
00256   int MenuKeyCloses;
00257   int MarkInstantRecord;
00258   char NameInstantRecord[MaxFileName];
00259   int InstantRecordTime;
00260   int LnbSLOF;
00261   int LnbFrequLo;
00262   int LnbFrequHi;
00263   int DiSEqC;
00264   int SetSystemTime;
00265   int TimeSource;
00266   int TimeTransponder;
00267   int MarginStart, MarginStop;
00268   int AudioLanguages[I18N_MAX_LANGUAGES + 1];
00269   int DisplaySubtitles;
00270   int SupportTeletext;
00271   int SubtitleLanguages[I18N_MAX_LANGUAGES + 1];
00272   int SubtitleOffset;
00273   int SubtitleFgTransparency, SubtitleBgTransparency;
00274   int EPGLanguages[I18N_MAX_LANGUAGES + 1];
00275   int EPGScanTimeout;
00276   int EPGBugfixLevel;
00277   int EPGLinger;
00278   int SVDRPTimeout;
00279   int ZapTimeout;
00280   int ChannelEntryTimeout;
00281   int DefaultPriority, DefaultLifetime;
00282   int PausePriority, PauseLifetime;
00283   int PauseKeyHandling;
00284   int UseSubtitle;
00285   int UseVps;
00286   int VpsMargin;
00287   int RecordingDirs;
00288   int FoldersInTimerMenu;
00289   int NumberKeysForChars;
00290   int VideoDisplayFormat;
00291   int VideoFormat;
00292   int UpdateChannels;
00293   int UseDolbyDigital;
00294   int ChannelInfoPos;
00295   int ChannelInfoTime;
00296   double OSDLeftP, OSDTopP, OSDWidthP, OSDHeightP;
00297   int OSDLeft, OSDTop, OSDWidth, OSDHeight;
00298   double OSDAspect;
00299   int OSDMessageTime;
00300   int UseSmallFont;
00301   int AntiAlias;
00302   char FontOsd[MAXFONTNAME];
00303   char FontSml[MAXFONTNAME];
00304   char FontFix[MAXFONTNAME];
00305   double FontOsdSizeP;
00306   double FontSmlSizeP;
00307   double FontFixSizeP;
00308   int FontOsdSize;
00309   int FontSmlSize;
00310   int FontFixSize;
00311   int MaxVideoFileSize;
00312   int MaxRecordingSize;
00313   int SplitEditedFiles;
00314   int DelTimeshiftRec;
00315   int HardLinkCutter;
00316   int MinEventTimeout, MinUserInactivity;
00317   time_t NextWakeupTime;
00318   int MultiSpeedMode;
00319   int ShowReplayMode;
00320   int ShowRemainingTime;
00321   int ResumeID;
00322   int JumpPlay;
00323   int PlayJump;
00324   int PauseLastMark;
00325   int CurrentChannel;
00326   int CurrentVolume;
00327   int CurrentDolby;
00328   int InitialVolume;
00329   int ChannelsWrap;
00330   int EmergencyExit;
00331   int __EndData__;
00332   cString InitialChannel;
00333   cString DeviceBondings;
00334   cSetup(void);
00335   cSetup& operator= (const cSetup &s);
00336   bool Load(const char *FileName);
00337   bool Save(void);
00338   };
00339 
00340 extern cSetup Setup;
00341 
00342 #endif //__CONFIG_H