summaryrefslogtreecommitdiffstats
path: root/source/cWebAdmin.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 23:48:38 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 23:48:38 +0100
commitf4583fda98b578966969db7d94a0bae3c87b0c80 (patch)
tree7edca3f33014046fa95a330a8809497d4fa52e3d /source/cWebAdmin.cpp
parentFixed a problem in cCSLock (sorry); reverted cChunk (diff)
downloadcuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.gz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.bz2
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.lz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.xz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.zst
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.zip
Diffstat (limited to '')
-rw-r--r--source/cWebAdmin.cpp51
1 files changed, 27 insertions, 24 deletions
diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp
index 23348fcdc..70f89528c 100644
--- a/source/cWebAdmin.cpp
+++ b/source/cWebAdmin.cpp
@@ -245,6 +245,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
}
}
+
+
+
+
bool cWebAdmin::Init( int a_Port )
{
m_Port = a_Port;
@@ -289,45 +293,44 @@ void *cWebAdmin::ListenThread( void *lpParam )
return 0;
}
+
+
+
+
std::string cWebAdmin::GetTemplate()
{
std::string retVal = "";
char SourceFile[] = "webadmin/template.html";
- FILE* f;
-#ifdef _WIN32
- if( fopen_s(&f, SourceFile, "rb" ) == 0 ) // no error
-#else
- if( (f = fopen(SourceFile, "rb" ) ) != 0 ) // no error
-#endif
+ cFile f;
+ if (!f.Open(SourceFile, cFile::fmRead))
{
- // obtain file size:
- fseek (f , 0 , SEEK_END);
- long lSize = ftell (f);
- rewind (f);
+ return "";
+ }
- // allocate memory to contain the whole file:
- char* buffer = (char*) malloc (sizeof(char)*lSize);
+ // obtain file size:
+ int lSize = f.GetSize();
- // copy the file into the buffer:
- size_t result = fread (buffer, 1, lSize, f);
- if ((long)result != lSize)
- {
- LOG ("WEBADMIN: Could not read file %s", SourceFile);
- free( buffer );
- return "";
- }
+ // allocate memory to contain the whole file:
+ std::auto_ptr<char> buffer(new char[lSize]); // auto_ptr deletes the memory in its destructor
- retVal.assign( buffer, lSize );
-
- free( buffer );
- fclose(f);
+ // copy the file into the buffer:
+ if (f.Read(buffer.get(), lSize) != lSize)
+ {
+ LOG ("WEBADMIN: Could not read file \"%s\"", SourceFile);
+ return "";
}
+
+ retVal.assign(buffer.get(), lSize );
+
return retVal;
}
+
+
+
void cWebAdmin::RemovePlugin( lua_State* L )
{
for( PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); )