mirror of
https://github.com/overte-org/overte.git
synced 2025-07-14 10:36:27 +02:00
first cut at domain server config support
This commit is contained in:
parent
00506b1a84
commit
48a579ae49
1 changed files with 38 additions and 3 deletions
|
@ -27,7 +27,10 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include <civetweb.h>
|
||||
|
||||
|
@ -45,6 +48,7 @@ const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
|
|||
|
||||
QMutex assignmentQueueMutex;
|
||||
std::deque<Assignment*> assignmentQueue;
|
||||
QMap<QString, QString> configMap;
|
||||
|
||||
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
||||
*currentPosition++ = nodeToAdd->getType();
|
||||
|
@ -66,6 +70,37 @@ static int mongooseRequestHandler(struct mg_connection *conn) {
|
|||
// upload the file
|
||||
mg_upload(conn, "/tmp");
|
||||
|
||||
return 1;
|
||||
} else if (strncmp(ri->uri, "/config", strlen("/config")) == 0 && strcmp(ri->request_method, "GET") == 0) {
|
||||
|
||||
// Let's split up the URL into it's pieces so we can service it
|
||||
QString uri(ri->uri);
|
||||
QString delimiterPattern("/");
|
||||
QStringList uriParts = uri.split(delimiterPattern);
|
||||
|
||||
QString configGuid = uriParts[2];
|
||||
|
||||
// first part should be empty
|
||||
// second part should be "config"
|
||||
// third part should be a guid, and therefore should not be empty
|
||||
if (!uriParts[0].isEmpty() || uriParts[1] != "config" || configGuid.isEmpty()) {
|
||||
mg_printf(conn, "%s", "HTTP/1.0 400 Bad Request\r\nContent-Type: text/plain\r\n\r\nInvalid parameters.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// assuming the request format was valid, look up the guid in our configs
|
||||
if (!::configMap.contains(configGuid)) {
|
||||
mg_printf(conn, "%s", "HTTP/1.0 404 Not Found\r\nContent-Type: text/plain\r\n\r\nInvalid config GUID.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * configPayload = configMap[configGuid].toLocal8Bit().data();
|
||||
|
||||
// return a 200
|
||||
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
|
||||
// return the configuration "payload"
|
||||
mg_printf(conn, "%s", configPayload);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
// have mongoose process this request from the document_root
|
||||
|
|
Loading…
Reference in a new issue