|
SASC-NG
DVBSoftCAM
|
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 1.292 2007/06/23 09:06:24 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.6.0" 00026 #define VDRVERSNUM 10600 // Version * 10000 + Major * 100 + Minor 00027 00028 // The plugin API's version number: 00029 00030 #define APIVERSION "1.6.0" 00031 #define APIVERSNUM 10600 // Version * 10000 + Major * 100 + Minor 00032 00033 // When loading plugins, VDR searches them by their APIVERSION, which 00034 // may be smaller than VDRVERSION in case there have been no changes to 00035 // VDR header files since the last APIVERSION. This allows compiled 00036 // plugins to work with newer versions of the core VDR as long as no 00037 // VDR header files have changed. 00038 00039 #define MAXPRIORITY 99 00040 #define MAXLIFETIME 99 00041 00042 #define MINOSDWIDTH 480 00043 #define MAXOSDWIDTH 672 00044 #define MINOSDHEIGHT 324 00045 #define MAXOSDHEIGHT 567 00046 00047 #define MaxFileName 256 00048 #define MaxSkinName 16 00049 #define MaxThemeName 16 00050 00051 class cCommand : public cListObject { 00052 private: 00053 char *title; 00054 char *command; 00055 bool confirm; 00056 static char *result; 00057 public: 00058 cCommand(void); 00059 virtual ~cCommand(); 00060 bool Parse(const char *s); 00061 const char *Title(void) { return title; } 00062 bool Confirm(void) { return confirm; } 00063 const char *Execute(const char *Parameters = NULL); 00064 }; 00065 00066 typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2) 00067 00068 class cSVDRPhost : public cListObject { 00069 private: 00070 struct in_addr addr; 00071 in_addr_t mask; 00072 public: 00073 cSVDRPhost(void); 00074 bool Parse(const char *s); 00075 bool Accepts(in_addr_t Address); 00076 }; 00077 00078 template<class T> class cConfig : public cList<T> { 00079 private: 00080 char *fileName; 00081 bool allowComments; 00082 void Clear(void) 00083 { 00084 free(fileName); 00085 fileName = NULL; 00086 cList<T>::Clear(); 00087 } 00088 public: 00089 cConfig(void) { fileName = NULL; } 00090 virtual ~cConfig() { free(fileName); } 00091 const char *FileName(void) { return fileName; } 00092 bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false) 00093 { 00094 cConfig<T>::Clear(); 00095 if (FileName) { 00096 free(fileName); 00097 fileName = strdup(FileName); 00098 allowComments = AllowComments; 00099 } 00100 bool result = !MustExist; 00101 if (fileName && access(fileName, F_OK) == 0) { 00102 isyslog("loading %s", fileName); 00103 FILE *f = fopen(fileName, "r"); 00104 if (f) { 00105 char *s; 00106 int line = 0; 00107 cReadLine ReadLine; 00108 result = true; 00109 while ((s = ReadLine.Read(f)) != NULL) { 00110 line++; 00111 if (allowComments) { 00112 char *p = strchr(s, '#'); 00113 if (p) 00114 *p = 0; 00115 } 00116 stripspace(s); 00117 if (!isempty(s)) { 00118 T *l = new T; 00119 if (l->Parse(s)) 00120 Add(l); 00121 else { 00122 esyslog("ERROR: error in %s, line %d", fileName, line); 00123 delete l; 00124 result = false; 00125 break; 00126 } 00127 } 00128 } 00129 fclose(f); 00130 } 00131 else { 00132 LOG_ERROR_STR(fileName); 00133 result = false; 00134 } 00135 } 00136 if (!result) 00137 fprintf(stderr, "vdr: error while reading '%s'\n", fileName); 00138 return result; 00139 } 00140 bool Save(void) 00141 { 00142 bool result = true; 00143 T *l = (T *)this->First(); 00144 cSafeFile f(fileName); 00145 if (f.Open()) { 00146 while (l) { 00147 if (!l->Save(f)) { 00148 result = false; 00149 break; 00150 } 00151 l = (T *)l->Next(); 00152 } 00153 if (!f.Close()) 00154 result = false; 00155 } 00156 else 00157 result = false; 00158 return result; 00159 } 00160 }; 00161 00162 class cCommands : public cConfig<cCommand> {}; 00163 00164 class cSVDRPhosts : public cConfig<cSVDRPhost> { 00165 public: 00166 bool Acceptable(in_addr_t Address); 00167 }; 00168 00169 extern cCommands Commands; 00170 extern cCommands RecordingCommands; 00171 extern cSVDRPhosts SVDRPhosts; 00172 00173 class cSetupLine : public cListObject { 00174 private: 00175 char *plugin; 00176 char *name; 00177 char *value; 00178 public: 00179 cSetupLine(void); 00180 cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL); 00181 virtual ~cSetupLine(); 00182 virtual int Compare(const cListObject &ListObject) const; 00183 const char *Plugin(void) { return plugin; } 00184 const char *Name(void) { return name; } 00185 const char *Value(void) { return value; } 00186 bool Parse(char *s); 00187 bool Save(FILE *f); 00188 }; 00189 00190 class cSetup : public cConfig<cSetupLine> { 00191 friend class cPlugin; // needs to be able to call Store() 00192 private: 00193 void StoreLanguages(const char *Name, int *Values); 00194 bool ParseLanguages(const char *Value, int *Values); 00195 bool Parse(const char *Name, const char *Value); 00196 cSetupLine *Get(const char *Name, const char *Plugin = NULL); 00197 void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false); 00198 void Store(const char *Name, int Value, const char *Plugin = NULL); 00199 public: 00200 // Also adjust cMenuSetup (menu.c) when adding parameters here! 00201 int __BeginData__; 00202 int OSDLanguage; 00203 char OSDSkin[MaxSkinName]; 00204 char OSDTheme[MaxThemeName]; 00205 int PrimaryDVB; 00206 int ShowInfoOnChSwitch; 00207 int TimeoutRequChInfo; 00208 int MenuScrollPage; 00209 int MenuScrollWrap; 00210 int MenuKeyCloses; 00211 int MarkInstantRecord; 00212 char NameInstantRecord[MaxFileName]; 00213 int InstantRecordTime; 00214 int LnbSLOF; 00215 int LnbFrequLo; 00216 int LnbFrequHi; 00217 int DiSEqC; 00218 int SetSystemTime; 00219 int TimeSource; 00220 int TimeTransponder; 00221 int MarginStart, MarginStop; 00222 int AudioLanguages[I18nNumLanguages + 1]; 00223 int EPGLanguages[I18nNumLanguages + 1]; 00224 int EPGScanTimeout; 00225 int EPGBugfixLevel; 00226 int EPGLinger; 00227 int SVDRPTimeout; 00228 int ZapTimeout; 00229 int ChannelEntryTimeout; 00230 int PrimaryLimit; 00231 int DefaultPriority, DefaultLifetime; 00232 int PausePriority, PauseLifetime; 00233 int UseSubtitle; 00234 int UseVps; 00235 int VpsMargin; 00236 int RecordingDirs; 00237 int VideoDisplayFormat; 00238 int VideoFormat; 00239 int UpdateChannels; 00240 int UseDolbyDigital; 00241 int ChannelInfoPos; 00242 int ChannelInfoTime; 00243 int OSDLeft, OSDTop, OSDWidth, OSDHeight; 00244 int OSDMessageTime; 00245 int UseSmallFont; 00246 int AntiAlias; 00247 char FontOsd[MAXFONTNAME]; 00248 char FontSml[MAXFONTNAME]; 00249 char FontFix[MAXFONTNAME]; 00250 int FontOsdSize; 00251 int FontSmlSize; 00252 int FontFixSize; 00253 int MaxVideoFileSize; 00254 int SplitEditedFiles; 00255 int MinEventTimeout, MinUserInactivity; 00256 time_t NextWakeupTime; 00257 int MultiSpeedMode; 00258 int ShowReplayMode; 00259 int ResumeID; 00260 int CurrentChannel; 00261 int CurrentVolume; 00262 int CurrentDolby; 00263 int InitialChannel; 00264 int InitialVolume; 00265 int __EndData__; 00266 cSetup(void); 00267 cSetup& operator= (const cSetup &s); 00268 bool Load(const char *FileName); 00269 bool Save(void); 00270 }; 00271 00272 extern cSetup Setup; 00273 00274 #endif //__CONFIG_H