summaryrefslogtreecommitdiffstats
path: root/WebServer
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-29 20:28:19 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-29 20:28:19 +0100
commit89afb970d88e3efa8ddb2f1eafff10cd6525f2b7 (patch)
tree206b3ba15c0fc87b3bf9ad7371f73887280945c4 /WebServer
parentVC2008 compilation with new lua webplugin (diff)
downloadcuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar.gz
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar.bz2
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar.lz
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar.xz
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.tar.zst
cuberite-89afb970d88e3efa8ddb2f1eafff10cd6525f2b7.zip
Diffstat (limited to '')
-rw-r--r--WebServer/Globals.cpp10
-rw-r--r--WebServer/Globals.h78
-rw-r--r--WebServer/Socket.cpp6
-rw-r--r--WebServer/StdHelpers.cpp3
-rw-r--r--WebServer/UrlHelper.cpp6
-rw-r--r--WebServer/WebServer.cpp18
-rw-r--r--WebServer/WebServer.h100
-rw-r--r--WebServer/base64.cpp3
-rw-r--r--WebServer/cEvents.cpp (renamed from WebServer/cEvent.cpp)55
-rw-r--r--WebServer/cEvents.h (renamed from WebServer/cEvent.h)16
10 files changed, 197 insertions, 98 deletions
diff --git a/WebServer/Globals.cpp b/WebServer/Globals.cpp
new file mode 100644
index 000000000..2c60fd698
--- /dev/null
+++ b/WebServer/Globals.cpp
@@ -0,0 +1,10 @@
+
+// Globals.cpp
+
+// This file is used for precompiled header generation in MSVC environments
+
+#include "Globals.h"
+
+
+
+
diff --git a/WebServer/Globals.h b/WebServer/Globals.h
new file mode 100644
index 000000000..027b988ef
--- /dev/null
+++ b/WebServer/Globals.h
@@ -0,0 +1,78 @@
+
+// Globals.h
+
+// This file gets included from every module in the project, so that global symbols may be introduced easily
+// Also used for precompiled header generation in MSVC environments
+
+
+
+
+
+// OS-dependent stuff:
+#ifdef _WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #include <Windows.h>
+ #include <winsock.h>
+#else
+ #include <sys/types.h>
+ #include <sys/stat.h> // for mkdir
+ #include <sys/time.h>
+ #include <time.h>
+ #include <dirent.h>
+ #include <errno.h>
+ #include <iostream>
+
+ #include <cstdio>
+ #include <cstring>
+ #include <pthread.h>
+ #include <semaphore.h>
+ #include <errno.h>
+ #include <fcntl.h>
+#endif
+
+
+
+
+
+// CRT stuff:
+#include <assert.h>
+#include <stdio.h>
+
+
+
+
+
+// STL stuff:
+#include <vector>
+#include <list>
+#include <string>
+#include <map>
+#include <algorithm>
+
+
+
+
+
+// Common headers:
+#include "../source/cCriticalSection.h"
+#include "../source/cMCLogger.h"
+
+
+
+
+
+// Common definitions:
+
+/// Evaluates to the number of elements in an array (compile-time!)
+#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
+
+// sprintf_s is the preferred call in MSVC ("secure"); make it *nix-compatible:
+#ifndef _WIN32
+ #define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
+ #define vsnprintf_s(buffer, buffer_size, maxcount, stringbuffer, ...) (vsnprintf(buffer, maxcount, stringbuffer, __VA_ARGS__))
+#endif // _WIN32
+
+
+
+
+
diff --git a/WebServer/Socket.cpp b/WebServer/Socket.cpp
index 1ae3c9f37..ec3c9a5c7 100644
--- a/WebServer/Socket.cpp
+++ b/WebServer/Socket.cpp
@@ -29,7 +29,7 @@
THIS IS NOT THE ORIGINAL SOURCE1!!1!!!~!!~`1ONE!!`1
*/
-#include "../source/cMCLogger.h"
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Socket.h"
#include <iostream>
@@ -38,11 +38,11 @@
#include <cstring>
#include <sys/time.h>
#else
-#define MSG_NOSIGNAL (0)
+ #define MSG_NOSIGNAL (0)
#endif
#ifdef __MAC_NA
-#define MSG_NOSIGNAL (0)
+ #define MSG_NOSIGNAL (0)
#endif
using namespace std;
diff --git a/WebServer/StdHelpers.cpp b/WebServer/StdHelpers.cpp
index 6bb05f421..f858c0bc4 100644
--- a/WebServer/StdHelpers.cpp
+++ b/WebServer/StdHelpers.cpp
@@ -29,8 +29,9 @@
THIS IS NOT THE ORIGINAL SOURCE1!!1!!!~!!~`1ONE!!`1
*/
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
#include "StdHelpers.h"
-#include <algorithm>
#include <cctype>
std::string ReplaceInStr(const std::string& in, const std::string& search_for, const std::string& replace_with) {
diff --git a/WebServer/UrlHelper.cpp b/WebServer/UrlHelper.cpp
index 3cdb0fc60..44f1166fd 100644
--- a/WebServer/UrlHelper.cpp
+++ b/WebServer/UrlHelper.cpp
@@ -29,14 +29,12 @@
THIS IS NOT THE ORIGINAL SOURCE1!!1!!!~!!~`1ONE!!`1
*/
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
#include "UrlHelper.h"
#include "Tracer.h"
#include "StdHelpers.h"
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
#include <sstream>
#include <iostream>
diff --git a/WebServer/WebServer.cpp b/WebServer/WebServer.cpp
index 954791663..466093fd3 100644
--- a/WebServer/WebServer.cpp
+++ b/WebServer/WebServer.cpp
@@ -31,24 +31,22 @@
THIS IS NOT THE ORIGINAL SOURCE1!!1!!!~!!~`1ONE!!`1
*/
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
#include <ctime>
#ifdef _WIN32
-#include <process.h>
+ #include <process.h>
#endif
#include <iostream>
-#include <string>
-#include <map>
#include <sstream>
#include "WebServer.h"
+#include "cEvents.h"
#include "Socket.h"
#include "UrlHelper.h"
#include "base64.h"
-#include "cEvent.h"
-
-
webserver::request_func webserver::request_func_=0;
#ifdef _WIN32
@@ -178,7 +176,7 @@ void webserver::Stop()
{
m_bStop = true;
m_Socket->Close();
- m_Event->Wait();
+ m_Events->Wait();
}
void webserver::Begin()
@@ -209,18 +207,18 @@ void webserver::Begin()
pthread_create( hHandle, NULL, Request, ptr_s);
#endif
}
- m_Event->Set();
+ m_Events->Set();
}
webserver::webserver(unsigned int port_to_listen, request_func r) {
m_Socket = new SocketServer(port_to_listen,1);
request_func_ = r;
- m_Event = new cEvent();
+ m_Events = new cEvents();
}
webserver::~webserver()
{
delete m_Socket;
- delete m_Event;
+ delete m_Events;
}
diff --git a/WebServer/WebServer.h b/WebServer/WebServer.h
index 06c6359e6..844af0c46 100644
--- a/WebServer/WebServer.h
+++ b/WebServer/WebServer.h
@@ -30,66 +30,64 @@
THIS IS NOT THE ORIGINAL SOURCE1!!1!!!~!!~`1ONE!!`1
*/
-#include <string>
-#include <map>
-class cEvent;
+class cEvents;
class Socket;
class SocketServer;
class webserver {
- public:
- struct http_request {
-
- http_request()
- : s_( 0 )
- , authentication_given_(false)
- {}
-
- Socket* s_;
- std::string method_;
- std::string path_;
- std::map<std::string, std::string> params_;
-
- std::string accept_;
- std::string accept_language_;
- std::string accept_encoding_;
- std::string user_agent_;
-
- /* status_: used to transmit server's error status, such as
- o 202 OK
- o 404 Not Found
- and so on */
- std::string status_;
-
- /* auth_realm_: allows to set the basic realm for an authentication,
- no need to additionally set status_ if set */
- std::string auth_realm_;
-
- std::string answer_;
-
- /* authentication_given_ is true when the user has entered a username and password.
- These can then be read from username_ and password_ */
- bool authentication_given_;
- std::string username_;
- std::string password_;
- };
-
- typedef void (*request_func) (http_request*);
- webserver(unsigned int port_to_listen, request_func);
+public:
+ struct http_request {
+
+ http_request()
+ : s_( 0 )
+ , authentication_given_(false)
+ {}
+
+ Socket* s_;
+ std::string method_;
+ std::string path_;
+ std::map<std::string, std::string> params_;
+
+ std::string accept_;
+ std::string accept_language_;
+ std::string accept_encoding_;
+ std::string user_agent_;
+
+ /* status_: used to transmit server's error status, such as
+ o 202 OK
+ o 404 Not Found
+ and so on */
+ std::string status_;
+
+ /* auth_realm_: allows to set the basic realm for an authentication,
+ no need to additionally set status_ if set */
+ std::string auth_realm_;
+
+ std::string answer_;
+
+ /* authentication_given_ is true when the user has entered a username and password.
+ These can then be read from username_ and password_ */
+ bool authentication_given_;
+ std::string username_;
+ std::string password_;
+ };
+
+ typedef void (*request_func) (http_request*);
+ webserver(unsigned int port_to_listen, request_func);
~webserver();
void Begin();
void Stop();
- private:
+private:
bool m_bStop;
- #ifdef _WIN32
- static unsigned __stdcall Request(void*);
- #else
- static void* Request(void*);
- #endif
- static request_func request_func_;
-
- cEvent* m_Event;
+#ifdef _WIN32
+ static unsigned __stdcall Request(void*);
+#else
+ static void* Request(void*);
+#endif
+ static request_func request_func_;
+
+ cEvents * m_Events;
SocketServer* m_Socket;
};
diff --git a/WebServer/base64.cpp b/WebServer/base64.cpp
index 8a6f33147..72cd7cd59 100644
--- a/WebServer/base64.cpp
+++ b/WebServer/base64.cpp
@@ -1,3 +1,6 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
#include "base64.h"
#include <iostream>
diff --git a/WebServer/cEvent.cpp b/WebServer/cEvents.cpp
index 289131568..4c9fa8775 100644
--- a/WebServer/cEvent.cpp
+++ b/WebServer/cEvents.cpp
@@ -1,16 +1,13 @@
-#include "cEvent.h"
-#include "../source/cMCLogger.h"
-#ifdef _WIN32
-#include <Windows.h>
-#else
-#include <semaphore.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h> // sprintf()
-#endif
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "cEvents.h"
+
+
-cEvent::cEvent( unsigned int a_NumEvents /* = 1 */ )
+
+
+cEvents::cEvents( unsigned int a_NumEvents /* = 1 */ )
: m_NumEvents( a_NumEvents )
#ifndef _WIN32
, m_bNamed( false )
@@ -34,24 +31,28 @@ cEvent::cEvent( unsigned int a_NumEvents /* = 1 */ )
if( sem_init( HandlePtr, 0, 0 ) )
{
- LOG("WARNING cEvent: Could not create unnamed semaphore, fallback to named.");
+ LOG("WARNING cEvents: Could not create unnamed semaphore, fallback to named.");
m_bNamed = true;
delete HandlePtr; // named semaphores return their own address
char c_Str[32];
- sprintf( c_Str, "cEvent%p", &HandlePtr );
+ sprintf( c_Str, "cEvents%p", &HandlePtr );
HandlePtr = sem_open( c_Str, O_CREAT, 777, 0 );
if( HandlePtr == SEM_FAILED )
LOG("ERROR: Could not create Event. (%i)", errno);
else
if( sem_unlink( c_Str ) != 0 )
- LOG("ERROR: Could not unlink cEvent. (%i)", errno);
+ LOG("ERROR: Could not unlink cEvents. (%i)", errno);
}
}
#endif
}
-cEvent::~cEvent()
+
+
+
+
+cEvents::~cEvents()
{
#ifdef _WIN32
for( unsigned int i = 0; i < m_NumEvents; i++ )
@@ -66,12 +67,12 @@ cEvent::~cEvent()
{
sem_t* & HandlePtr = ((sem_t**)m_Handle)[i];
char c_Str[32];
- sprintf( c_Str, "cEvent%p", &HandlePtr );
+ sprintf( c_Str, "cEvents%p", &HandlePtr );
// LOG("Closing event: %s", c_Str );
// LOG("Sem ptr: %p", HandlePtr );
if( sem_close( HandlePtr ) != 0 )
{
- LOG("ERROR: Could not close cEvent. (%i)", errno);
+ LOG("ERROR: Could not close cEvents. (%i)", errno);
}
}
else
@@ -84,7 +85,11 @@ cEvent::~cEvent()
#endif
}
-void cEvent::Wait()
+
+
+
+
+void cEvents::Wait()
{
#ifdef _WIN32
WaitForMultipleObjects( m_NumEvents, (HANDLE*)m_Handle, true, INFINITE );
@@ -93,20 +98,28 @@ void cEvent::Wait()
{
if( sem_wait( ((sem_t**)m_Handle)[i] ) != 0 )
{
- LOG("ERROR: Could not wait for cEvent. (%i)", errno);
+ LOG("ERROR: Could not wait for cEvents. (%i)", errno);
}
}
#endif
}
-void cEvent::Set(unsigned int a_EventNum /* = 0 */)
+
+
+
+
+void cEvents::Set(unsigned int a_EventNum /* = 0 */)
{
#ifdef _WIN32
SetEvent( ((HANDLE*)m_Handle)[a_EventNum] );
#else
if( sem_post( ((sem_t**)m_Handle)[a_EventNum] ) != 0 )
{
- LOG("ERROR: Could not set cEvent. (%i)", errno);
+ LOG("ERROR: Could not set cEvents. (%i)", errno);
}
#endif
}
+
+
+
+
diff --git a/WebServer/cEvent.h b/WebServer/cEvents.h
index e5b77be50..c8a6a7df9 100644
--- a/WebServer/cEvent.h
+++ b/WebServer/cEvents.h
@@ -1,18 +1,18 @@
#pragma once
-class cEvent
+class cEvents
{
public:
- cEvent( unsigned int a_NumEvents = 1 );
- ~cEvent();
+ cEvents( unsigned int a_NumEvents = 1 );
+ ~cEvents();
void Wait();
void Set(unsigned int a_EventNum = 0);
private:
unsigned int m_NumEvents;
- void* m_Handle; // HANDLE[] pointer
-
-#ifndef _WIN32
- bool m_bNamed;
+ void* m_Handle; // HANDLE[] pointer
+
+#ifndef _WIN32
+ bool m_bNamed;
#endif
-};
+};