mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-06-01 10:05:31 +00:00
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
This commit is contained in:
31
examples/console-list.cpp
Normal file
31
examples/console-list.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
TF_Init();
|
||||
|
||||
std::vector<std::string> myList = {
|
||||
"Demi Lovato",
|
||||
"The Gremlins",
|
||||
"Al Gore",
|
||||
"Steve Ballmer",
|
||||
"CrossLang",
|
||||
"Tom Scott",
|
||||
"Louis Rossmann",
|
||||
"Mike Nolan",
|
||||
"Tim Cook"
|
||||
};
|
||||
|
||||
auto res = Console::List(myList);
|
||||
|
||||
if(res > myList.size())
|
||||
{
|
||||
Console::WriteLine("You must select one");
|
||||
}
|
||||
else {
|
||||
StdOut() << "You selected " << myList[res] << "." << NewLine();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
20
examples/console-raw.cpp
Normal file
20
examples/console-raw.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine("Press q to quit");
|
||||
Console::SetEcho(false);
|
||||
Console::SetCanonical(false);
|
||||
while(int r = Console::Read())
|
||||
{
|
||||
if(r == 'q')
|
||||
{
|
||||
break;
|
||||
}
|
||||
Console::WriteLine(std::to_string(r));
|
||||
}
|
||||
Console::SetCanonical(true);
|
||||
Console::SetEcho(true);
|
||||
}
|
||||
20
examples/console-test.cpp
Normal file
20
examples/console-test.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <TessesFramework/TessesFramework.hpp>
|
||||
|
||||
using namespace Tesses::Framework;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_Init();
|
||||
Console::SetPosition(0,0);
|
||||
Console::WriteLine("Demi Lovato Is Cute Right");
|
||||
Console::WriteLine("Right");
|
||||
Console::WriteLine("Al Gore");
|
||||
Console::WriteLine("Demi Lovato");
|
||||
Console::WriteLine("Hello \x1B[33myellow\x1B[37m world");
|
||||
Console::ReadLine();
|
||||
|
||||
Console::SetPosition(2,1);
|
||||
|
||||
Console::ClearRetainPosition(ClearBehaviour::CB_CURSORANDBELOW);
|
||||
Console::ReadLine();
|
||||
}
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
LocalFilesystem fs;
|
||||
VFSPath src = fs.SystemToVFSPath(argv[1]);
|
||||
VFSPath dest = fs.SystemToVFSPath(argv[2]);
|
||||
auto srcs = fs.OpenFile(src,"rb");
|
||||
auto dests = fs.OpenFile(dest,"wb");
|
||||
auto srcs = fs.OpenFile(src, "rb");
|
||||
auto dests = fs.OpenFile(dest, "wb");
|
||||
srcs->CopyTo(dests);
|
||||
|
||||
}
|
||||
9
examples/echo-my-name.cpp
Normal file
9
examples/echo-my-name.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine("\"" + TF_GetExecutableName() + "\"");
|
||||
return 0;
|
||||
}
|
||||
9
examples/echo-platform.cpp
Normal file
9
examples/echo-platform.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine(Tesses::Framework::Platform::Environment::GetPlatform());
|
||||
return 0;
|
||||
}
|
||||
@@ -5,57 +5,50 @@ using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s <command> <args...>\n",argv[0]);
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("USAGE: %s <command> <args...>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
std::string root = "./root";
|
||||
std::string mountDemi = "./demi";
|
||||
std::string mountJoelSlashJim = "./joelslashjim";
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> rootdir = std::make_shared<SubdirFilesystem>(LocalFS,root);
|
||||
std::shared_ptr<SubdirFilesystem> rootdir =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, root);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountDemidir = std::make_shared<SubdirFilesystem>(LocalFS,mountDemi);
|
||||
std::shared_ptr<SubdirFilesystem> mountDemidir =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, mountDemi);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountjohnslashjim =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, mountJoelSlashJim);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountjohnslashjim = std::make_shared<SubdirFilesystem>(LocalFS,mountJoelSlashJim);
|
||||
|
||||
std::shared_ptr<MountableFilesystem> fs = std::make_shared<MountableFilesystem>(rootdir);
|
||||
std::shared_ptr<MountableFilesystem> fs =
|
||||
std::make_shared<MountableFilesystem>(rootdir);
|
||||
fs->Mount(std::string("/demi"), mountDemidir);
|
||||
|
||||
fs->Mount(std::string("/joel/jim"), mountjohnslashjim);
|
||||
|
||||
std::string command = argv[1];
|
||||
|
||||
|
||||
if(command == "ls")
|
||||
{
|
||||
if (command == "ls") {
|
||||
std::string dir = "/";
|
||||
if(argc > 2) dir = argv[2];
|
||||
|
||||
for(auto item : fs->EnumeratePaths(dir))
|
||||
{
|
||||
if (argc > 2)
|
||||
dir = argv[2];
|
||||
|
||||
for (auto item : fs->EnumeratePaths(dir)) {
|
||||
std::cout << item.GetFileName() << std::endl;
|
||||
}
|
||||
}
|
||||
else if(command == "cat")
|
||||
{
|
||||
std::shared_ptr<FileStream> strm = std::make_shared<FileStream>(stdout, false,"wb",false);
|
||||
for(int a = 2; a < argc; a++)
|
||||
{
|
||||
} else if (command == "cat") {
|
||||
std::shared_ptr<FileStream> strm =
|
||||
std::make_shared<FileStream>(stdout, false, "wb", false);
|
||||
for (int a = 2; a < argc; a++) {
|
||||
std::string path = argv[a];
|
||||
auto f = fs->OpenFile(path,"rb");
|
||||
if(f != nullptr)
|
||||
{
|
||||
auto f = fs->OpenFile(path, "rb");
|
||||
if (f != nullptr) {
|
||||
f->CopyTo(strm);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <string>
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
VFSPath path("C:/home/user/file");
|
||||
VFSPath path2("D:/home/user/file");
|
||||
VFSPath path3("C:/home/user");
|
||||
std::cout << path.MakeRelative(path2).ToString() << std::endl;
|
||||
|
||||
std::cout << (path3 / path.MakeRelative(path2) / "John").CollapseRelativeParents().ToString() << std::endl;
|
||||
std::cout << (path3 / path.MakeRelative(path2) / "John")
|
||||
.CollapseRelativeParents()
|
||||
.ToString()
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
auto json = Json::Decode("\"\\uD83D\\uDE44\"");
|
||||
std::string str;
|
||||
if(TryGetJToken(json,str))
|
||||
{
|
||||
if (TryGetJToken(json, str)) {
|
||||
std::cout << str << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,15 @@
|
||||
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " <parent> <subpath>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
VFSPath parent(argv[1]);
|
||||
VFSPath subpath(argv[2]);
|
||||
VFSPath newPath(parent,subpath.CollapseRelativeParents());
|
||||
VFSPath newPath(parent, subpath.CollapseRelativeParents());
|
||||
|
||||
std::cout << newPath.ToString() << "\n";
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
std::cout << "Basic auth test" << std::endl;
|
||||
std::string theEncoded="dXNlcjpwYXNz";
|
||||
std::string theEncoded = "dXNlcjpwYXNz";
|
||||
Tesses::Framework::Http::ServerContext ctx(nullptr);
|
||||
ctx.requestHeaders.SetValue("Authorization","Basic " + theEncoded);
|
||||
ctx.requestHeaders.SetValue("Authorization", "Basic " + theEncoded);
|
||||
std::string user;
|
||||
std::string pass;
|
||||
std::cout << Tesses::Framework::Http::BasicAuthServer::GetCreds(ctx,user,pass) << std::endl;
|
||||
std::cout << Tesses::Framework::Http::BasicAuthServer::GetCreds(ctx, user,
|
||||
pass)
|
||||
<< std::endl;
|
||||
std::cout << user << std::endl;
|
||||
std::cout << pass << std::endl;
|
||||
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
#include "TessesFramework/Common.hpp"
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
|
||||
auto timer = TF_Timer([]()->void {
|
||||
std::cout << "Hi, I am a timer" << std::endl;
|
||||
});
|
||||
auto timer = TF_Timer(
|
||||
[]() -> void { std::cout << "Hi, I am a timer" << std::endl; });
|
||||
|
||||
TF_RunEventLoop();
|
||||
|
||||
|
||||
@@ -11,206 +11,171 @@ using namespace Tesses::Framework::Threading;
|
||||
|
||||
std::shared_ptr<ServerSentEvents> sse = std::make_shared<ServerSentEvents>();
|
||||
|
||||
class Johnny : public ServerContextData
|
||||
{
|
||||
public:
|
||||
Johnny()
|
||||
{
|
||||
text = "Steve Ballmer";
|
||||
}
|
||||
std::string text;
|
||||
~Johnny()
|
||||
{
|
||||
std::cout << "Destroying" << std::endl;
|
||||
}
|
||||
class Johnny : public ServerContextData {
|
||||
public:
|
||||
Johnny() { text = "Steve Ballmer"; }
|
||||
std::string text;
|
||||
~Johnny() { std::cout << "Destroying" << std::endl; }
|
||||
};
|
||||
class MyWebServer : public IHttpServer {
|
||||
public:
|
||||
bool Handle(ServerContext& ctx)
|
||||
{
|
||||
std::cout << ctx.path << std::endl;
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("index.html","rb");
|
||||
public:
|
||||
bool Handle(ServerContext &ctx) {
|
||||
std::cout << ctx.path << std::endl;
|
||||
if (ctx.path == "/") {
|
||||
std::shared_ptr<FileStream> fs =
|
||||
std::make_shared<FileStream>("index.html", "rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/html")
|
||||
.SendStream(fs);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/mypath.html")
|
||||
{
|
||||
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendStream(fs);
|
||||
return true;
|
||||
} else if (ctx.path == "/mypath.html") {
|
||||
std::string txt =
|
||||
"<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) +
|
||||
"</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
} else if (ctx.path == "/getabsolute.html") {
|
||||
std::string path;
|
||||
if (ctx.queryParams.TryGetFirst("path", path)) {
|
||||
std::string txt =
|
||||
"<h1>Path: " +
|
||||
HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/getabsolute.html")
|
||||
{
|
||||
std::string path;
|
||||
if(ctx.queryParams.TryGetFirst("path",path))
|
||||
{
|
||||
std::string txt = "<h1>Path: " + HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
} else if (ctx.path == "/streaming.html") {
|
||||
StreamWriter writer(ctx.OpenResponseStream());
|
||||
writer.WriteLine("<html>");
|
||||
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||
writer.WriteLine("<body>");
|
||||
|
||||
writer.WriteLine("<h1>Streaming</h1>");
|
||||
|
||||
writer.WriteLine("<ul>");
|
||||
|
||||
for (size_t i = 0; i < 10000; i++) {
|
||||
writer.WriteLine("<li>" + std::to_string(i) + "</li>");
|
||||
TF_Sleep(10);
|
||||
}
|
||||
else if(ctx.path == "/streaming.html")
|
||||
{
|
||||
StreamWriter writer(ctx.OpenResponseStream());
|
||||
writer.WriteLine("<html>");
|
||||
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||
writer.WriteLine("<body>");
|
||||
|
||||
writer.WriteLine("<h1>Streaming</h1>");
|
||||
writer.WriteLine("</ul>");
|
||||
|
||||
writer.WriteLine("<ul>");
|
||||
writer.WriteLine("</body>");
|
||||
writer.WriteLine("</html>");
|
||||
return true;
|
||||
} else if (ctx.path == "/ssetest.html") {
|
||||
|
||||
for(size_t i=0;i<10000; i++)
|
||||
{
|
||||
writer.WriteLine("<li>" + std::to_string(i) + "</li>");
|
||||
TF_Sleep(10);
|
||||
}
|
||||
} else if (ctx.path == "/sse") {
|
||||
ctx.SendServerSentEvents(sse);
|
||||
return true;
|
||||
} else if (ctx.path == "/main.js") {
|
||||
|
||||
writer.WriteLine("</ul>");
|
||||
std::shared_ptr<FileStream> fs =
|
||||
std::make_shared<FileStream>("main.js", "rb");
|
||||
|
||||
writer.WriteLine("</body>");
|
||||
writer.WriteLine("</html>");
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/ssetest.html")
|
||||
{
|
||||
|
||||
}
|
||||
else if(ctx.path == "/sse")
|
||||
{
|
||||
ctx.SendServerSentEvents(sse);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/main.js")
|
||||
{
|
||||
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("main.js","rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/js")
|
||||
.SendStream(fs);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/upload")
|
||||
{
|
||||
ctx.ParseFormData([](std::string mime, std::string filename, std::string name)->std::shared_ptr<Tesses::Framework::Streams::Stream>{
|
||||
return std::make_shared<FileStream>(filename,"wb");
|
||||
ctx.WithMimeType("text/js").SendStream(fs);
|
||||
return true;
|
||||
} else if (ctx.path == "/upload") {
|
||||
ctx.ParseFormData(
|
||||
[](std::string mime, std::string filename, std::string name)
|
||||
-> std::shared_ptr<Tesses::Framework::Streams::Stream> {
|
||||
return std::make_shared<FileStream>(filename, "wb");
|
||||
});
|
||||
}
|
||||
else if(ctx.path == "/steve")
|
||||
{
|
||||
Johnny* data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
data->text = "Demi Lovato";
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (ctx.path == "/steve") {
|
||||
Johnny *data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
data->text = "Demi Lovato";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class MyOtherWebServer : public IHttpServer
|
||||
{
|
||||
public:
|
||||
bool Handle(ServerContext& ctx)
|
||||
{
|
||||
TF_LOG("IN HANDLE");
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
class MyOtherWebServer : public IHttpServer {
|
||||
public:
|
||||
bool Handle(ServerContext &ctx) {
|
||||
TF_LOG("IN HANDLE");
|
||||
if (ctx.path == "/") {
|
||||
std::string name;
|
||||
if(ctx.queryParams.TryGetFirst("name",name))
|
||||
{
|
||||
if (ctx.queryParams.TryGetFirst("name", name)) {
|
||||
std::cout << name << std::endl;
|
||||
TF_LOG(name);
|
||||
ctx
|
||||
.WithMimeType("text/plain")
|
||||
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",false)
|
||||
.SendText(name + " is cool.");
|
||||
//do something with q
|
||||
ctx.WithMimeType("text/plain")
|
||||
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",
|
||||
false)
|
||||
.SendText(name + " is cool.");
|
||||
// do something with q
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(ctx.path == "/status")
|
||||
{
|
||||
int64_t num;
|
||||
if(ctx.queryParams.TryGetFirstInt("code", num))
|
||||
{
|
||||
ctx.statusCode = (StatusCode)num;
|
||||
}
|
||||
|
||||
ctx.SendErrorPage(true);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/error")
|
||||
{
|
||||
throw std::runtime_error("This is a error");
|
||||
}
|
||||
else if(ctx.path == "/error-debug")
|
||||
{
|
||||
ctx.WithDebug(true);
|
||||
throw std::runtime_error("Platform is " + Tesses::Framework::Platform::Environment::GetPlatform());
|
||||
}
|
||||
else if(ctx.path == "/mymount/steve")
|
||||
{
|
||||
Johnny* data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
ctx.SendText(data->text);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/mypath.html")
|
||||
{
|
||||
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
} else if (ctx.path == "/status") {
|
||||
int64_t num;
|
||||
if (ctx.queryParams.TryGetFirstInt("code", num)) {
|
||||
ctx.statusCode = (StatusCode)num;
|
||||
}
|
||||
|
||||
return false;
|
||||
ctx.SendErrorPage(true);
|
||||
return true;
|
||||
} else if (ctx.path == "/error") {
|
||||
throw std::runtime_error("This is a error");
|
||||
} else if (ctx.path == "/error-debug") {
|
||||
ctx.WithDebug(true);
|
||||
throw std::runtime_error(
|
||||
"Platform is " +
|
||||
Tesses::Framework::Platform::Environment::GetPlatform());
|
||||
} else if (ctx.path == "/mymount/steve") {
|
||||
Johnny *data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
ctx.SendText(data->text);
|
||||
return true;
|
||||
} else if (ctx.path == "/mypath.html") {
|
||||
std::string txt =
|
||||
"<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) +
|
||||
"</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_InitWithConsole();
|
||||
int64_t timer = 0;
|
||||
auto timerHDL= TF_Timer([&timer]()->void{
|
||||
auto timerHDL = TF_Timer([&timer]() -> void {
|
||||
timer++;
|
||||
|
||||
sse->SendData("Timer has ticked " + std::to_string(timer) + " times now");
|
||||
sse->SendData("Timer has ticked " + std::to_string(timer) +
|
||||
" times now");
|
||||
});
|
||||
|
||||
std::shared_ptr<RouteServer> routeSvr = std::make_shared<RouteServer>();
|
||||
routeSvr->Get("/name/{name}/greeting",[](ServerContext& ctx)->bool{
|
||||
routeSvr->Get("/name/{name}/greeting", [](ServerContext &ctx) -> bool {
|
||||
std::string name;
|
||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
||||
{
|
||||
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||
ctx.WithMimeType("text/plain").SendText("Hello " + name);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
routeSvr->Get("/name/{name}/length",[](ServerContext& ctx)->bool{
|
||||
routeSvr->Get("/name/{name}/length", [](ServerContext &ctx) -> bool {
|
||||
std::string name;
|
||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
||||
{
|
||||
ctx.WithMimeType("text/plain").SendText("The length of the name is " + std::to_string(name.size()));
|
||||
}
|
||||
else {
|
||||
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||
ctx.WithMimeType("text/plain")
|
||||
.SendText("The length of the name is " +
|
||||
std::to_string(name.size()));
|
||||
} else {
|
||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<MyOtherWebServer> myo = std::make_shared<MyOtherWebServer>();
|
||||
std::shared_ptr<MyOtherWebServer> myo =
|
||||
std::make_shared<MyOtherWebServer>();
|
||||
std::shared_ptr<MyWebServer> mws = std::make_shared<MyWebServer>();
|
||||
|
||||
std::shared_ptr<MountableServer> mountable = std::make_shared<MountableServer>(myo);
|
||||
mountable->Mount("/mymount/",mws);
|
||||
std::shared_ptr<MountableServer> mountable =
|
||||
std::make_shared<MountableServer>(myo);
|
||||
mountable->Mount("/mymount/", mws);
|
||||
mountable->Mount("/routeSvr/", routeSvr);
|
||||
HttpServer server(10001,mountable);
|
||||
HttpServer server(10001, mountable);
|
||||
server.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
std::cout << "Closing server" << std::endl;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "TessesFramework.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
tf_vfs_t* local = tf_vfs_create_local();
|
||||
|
||||
tf_vfs_dir_t* dir = tf_vfs_opendir(local, "/home/mike");
|
||||
|
||||
string_t* str;
|
||||
while(str = tf_vfs_readdir(dir))
|
||||
{
|
||||
string_println(str);
|
||||
}
|
||||
tf_vfs_closedir(dir);
|
||||
|
||||
tf_stream_t* strm = tf_vfs_open(local,"/home/mike/myPhoto.png", "wb");
|
||||
|
||||
|
||||
|
||||
tf_vfs_close(local);
|
||||
}
|
||||
@@ -3,46 +3,35 @@
|
||||
#include <iostream>
|
||||
using namespace Tesses::Framework::Http;
|
||||
|
||||
class WebSocketConn : public WebSocketConnection
|
||||
{
|
||||
|
||||
public:
|
||||
void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping, std::function<void()> close)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
std::cout << "> ";
|
||||
std::string req;
|
||||
std::getline(std::cin, req);
|
||||
if(req == "exit")
|
||||
break;
|
||||
else
|
||||
SendWebSocketMessage(sendMessage,req);
|
||||
}
|
||||
close();
|
||||
|
||||
}
|
||||
void OnReceive(WebSocketMessage& message)
|
||||
{
|
||||
std::cout << "Message: " << message.ToString() << std::endl;
|
||||
|
||||
|
||||
}
|
||||
void OnClose(bool clean)
|
||||
{
|
||||
std::cout << (clean ? "Closed cleanly" : "Closed unclean") << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
class WebSocketConn : public WebSocketConnection {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
public:
|
||||
void OnOpen(std::function<void(WebSocketMessage &)> sendMessage,
|
||||
std::function<void()> ping, std::function<void()> close) {
|
||||
while (true) {
|
||||
std::cout << "> ";
|
||||
std::string req;
|
||||
std::getline(std::cin, req);
|
||||
if (req == "exit")
|
||||
break;
|
||||
else
|
||||
SendWebSocketMessage(sendMessage, req);
|
||||
}
|
||||
close();
|
||||
}
|
||||
void OnReceive(WebSocketMessage &message) {
|
||||
std::cout << "Message: " << message.ToString() << std::endl;
|
||||
}
|
||||
void OnClose(bool clean) {
|
||||
std::cout << (clean ? "Closed cleanly" : "Closed unclean") << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
HttpDictionary reqHeaders;
|
||||
std::shared_ptr<WebSocketConn> conn = std::make_shared<WebSocketConn>();
|
||||
WebSocketClient("ws://echo.websocket.org/",reqHeaders,conn);
|
||||
|
||||
WebSocketClient("ws://echo.websocket.org/", reqHeaders, conn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user