1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS HTTP Daemon 4 * FILE: config.cpp 5 * PURPOSE: Daemon configuration 6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net) 7 * REVISIONS: 8 * CSH 01/09/2000 Created 9 */ 10 #include <new> 11 #include <stdlib.h> 12 #include <string.h> 13 #include <config.h> 14 #include <tchar.h> 15 16 using namespace std; 17 18 LPCConfig pConfiguration; 19 LPCHttpDaemonThread pDaemonThread; 20 21 // Default constructor 22 CConfig::CConfig() 23 { 24 Reset(); 25 } 26 27 // Default destructor 28 CConfig::~CConfig() 29 { 30 Clear(); 31 } 32 33 // Clear configuration 34 void CConfig::Reset() 35 { 36 MainBase = NULL; 37 HttpBase = NULL; 38 DefaultResources.RemoveAll(); 39 } 40 41 // Create default configuration. Can throw bad_alloc 42 void CConfig::Default() 43 { 44 Clear(); 45 MainBase = _wcsdup((LPWSTR)dcfgMainBase); 46 HttpBase = _strdup(dcfgHttpBase); 47 48 LPSTR lpsStr; 49 try { 50 lpsStr = _strdup(dcfgDefaultResource); 51 DefaultResources.Insert(lpsStr); 52 } catch (bad_alloc&) { 53 free((void *)lpsStr); 54 Clear(); 55 throw; 56 } 57 58 Port = dcfgDefaultPort; 59 } 60 61 // Clear configuration 62 void CConfig::Clear() 63 { 64 if (MainBase != NULL) 65 free((void *)MainBase); 66 if (HttpBase != NULL) 67 free((void *)HttpBase); 68 69 // Free memory for all strings 70 CIterator<LPSTR> *i = DefaultResources.CreateIterator(); 71 for (i->First(); !i->IsDone(); i->Next()) 72 free((void *)i->CurrentItem()); 73 delete i; 74 75 Reset(); 76 } 77 78 // Load configuration 79 BOOL CConfig::Load() 80 { 81 Default(); 82 return TRUE; 83 } 84 85 // Save configuration 86 BOOL CConfig::Save() 87 { 88 return TRUE; 89 } 90 91 // Return MainBase 92 LPWSTR CConfig::GetMainBase() 93 { 94 return MainBase; 95 } 96 97 // Set MainBase 98 void CConfig::SetMainBase(LPWSTR lpwsMainBase) 99 { 100 MainBase = lpwsMainBase; 101 } 102 103 // Return HttpBase 104 LPSTR CConfig::GetHttpBase() 105 { 106 return HttpBase; 107 } 108 109 // Set HttpBase 110 void CConfig::SetHttpBase(LPSTR lpsHttpBase) 111 { 112 HttpBase = lpsHttpBase; 113 } 114 115 // Return DefaultResources 116 CList<LPSTR>* CConfig::GetDefaultResources() 117 { 118 return &DefaultResources; 119 } 120 121 // Return bound port 122 USHORT CConfig::GetPort() 123 { 124 return Port; 125 } 126 127 // Set port 128 VOID CConfig::SetPort(USHORT wPort) 129 { 130 Port = wPort; 131 } 132