From bd7402e45786a133b1ef4245c8a27162f491975b Mon Sep 17 00:00:00 2001
From: Pasha Barahimi
Date: Wed, 6 Dec 2023 00:43:19 +0330
Subject: [PATCH 01/23] Change travisCI to github actions
---
.github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++
.travis.yml | 29 -----------------------------
README.md | 2 +-
3 files changed, 39 insertions(+), 30 deletions(-)
create mode 100644 .github/workflows/ci.yml
delete mode 100644 .travis.yml
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f426e1a
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,38 @@
+name: CI
+
+on: [push, pull_request]
+
+jobs:
+ lint:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Run lint
+ uses: jidicula/clang-format-action@v4.11.0
+ with:
+ clang-format-version: "13"
+ fallback-style: "LLVM"
+
+ build-linux:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Install dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y g++ make
+ - name: Build
+ run: make
+ env:
+ CC: gcc
+ CXX: g++
+
+ build-macos:
+ runs-on: macos-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Build
+ run: make
+ env:
+ CC: gcc
+ CXX: g++
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 67765a8..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-before_install:
- - "eval \"${MATRIX_EVAL}\""
-language: cpp
-matrix:
- include:
- -
- env:
- - "MATRIX_EVAL=\"TESTENV=lint && STYLE=LLVM\""
- os: osx
- script:
- - "find . -name *.h -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.hpp -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.c -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.cpp -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- -
- before_install:
- - "sudo apt-get update"
- - "sudo apt-get install -y g++ make"
- env:
- - "MATRIX_EVAL=\"TESTENV=build && CC=gcc && CXX=g++\""
- os: linux
- script:
- - make
- -
- env:
- - "MATRIX_EVAL=\"TESTENV=build && CC=gcc && CXX=g++\""
- os: osx
- script:
- - make
diff --git a/README.md b/README.md
index c959749..1367456 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
AP HTTP
===
-[](https://travis-ci.com/UTAP/APHTTP)
+
[](https://llvm.org/docs/CodingStandards.html)
[](https://github.com/UTAP/APHTTP/releases/latest)
[](https://github.com/UTAP/APHTTP/wiki)
From 6320fd9bb247d0f663711eb28fdef25b344f5157 Mon Sep 17 00:00:00 2001
From: Pasha Barahimi
Date: Wed, 6 Dec 2023 01:24:59 +0330
Subject: [PATCH 02/23] Fix formattings
---
examples/main.cpp | 2 +-
server/server.cpp | 41 +++++++++++++++++++++------------------
utils/template_parser.cpp | 27 ++++++++++++++------------
utils/template_parser.hpp | 2 +-
utils/utilities.cpp | 5 +++--
5 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/examples/main.cpp b/examples/main.cpp
index 1e5c549..fd35afb 100644
--- a/examples/main.cpp
+++ b/examples/main.cpp
@@ -20,7 +20,7 @@ int main(int argc, char **argv) {
server.get("/", new ShowPage("static/home.html"));
server.get("/colors", new ColorHandler("template/colors.html"));
server.run();
- } catch (const Server::Exception& e) {
+ } catch (const Server::Exception &e) {
cerr << e.getMessage() << endl;
}
}
diff --git a/server/server.cpp b/server/server.cpp
index da418e1..e925a99 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -15,17 +15,16 @@
#include "../utils/utilities.hpp"
-
#ifdef _WIN32
#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501 //win xp
+#define _WIN32_WINNT 0x0501 // win xp
#endif
-#include
#include
+#include
#else
-//POSIX sockets
-#include
+// POSIX sockets
#include
+#include
#include //close()
#endif
@@ -39,17 +38,19 @@
#define GETSOCKETERRNO() (errno)
#endif
-static const char* getSocketError() {
+static const char *getSocketError() {
#ifdef _WIN32
- static char message[256];
- message[0] = '\0';
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, WSAGetLastError(), 0, (LPSTR)&message, sizeof(message), NULL);
- char *newline = strrchr(message, '\n');
- if (newline) *newline = '\0';
- return message;
+ static char message[256];
+ message[0] = '\0';
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, WSAGetLastError(), 0, (LPSTR)&message, sizeof(message),
+ NULL);
+ char *newline = strrchr(message, '\n');
+ if (newline)
+ *newline = '\0';
+ return message;
#else
- return strerror(errno);
+ return strerror(errno);
#endif
}
@@ -234,7 +235,7 @@ Request *parseRawReq(char *headersRaw, size_t length) {
} break;
}
}
- } catch (const Server::Exception&) {
+ } catch (const Server::Exception &) {
throw;
} catch (...) {
throw Server::Exception("Error on parsing request");
@@ -247,7 +248,8 @@ Server::Server(int _port) : port(_port) {
WSADATA wsa_data;
int initializeResult = WSAStartup(MAKEWORD(2, 2), &wsa_data);
if (initializeResult != 0) {
- throw Exception("Error: WinSock WSAStartup failed: " + string(getSocketError()));
+ throw Exception("Error: WinSock WSAStartup failed: " +
+ string(getSocketError()));
}
#endif
@@ -257,7 +259,8 @@ Server::Server(int _port) : port(_port) {
int sc_option = 1;
#ifdef _WIN32
- setsockopt(sc, SOL_SOCKET, SO_REUSEADDR, (char*)&sc_option, sizeof(sc_option));
+ setsockopt(sc, SOL_SOCKET, SO_REUSEADDR, (char *)&sc_option,
+ sizeof(sc_option));
#else
setsockopt(sc, SOL_SOCKET, SO_REUSEADDR, &sc_option, sizeof(sc_option));
#endif
@@ -300,7 +303,7 @@ void Server::run() {
throw Exception("Error on accept: " + string(getSocketError()));
Response *res = NULL;
try {
- char* data = new char[BUFSIZE + 1];
+ char *data = new char[BUFSIZE + 1];
size_t recv_len, recv_total_len = 0;
Request *req = NULL;
while (!req) {
@@ -330,7 +333,7 @@ void Server::run() {
res = notFoundHandler->callback(req);
}
delete req;
- } catch (const Exception& exc) {
+ } catch (const Exception &exc) {
delete res;
res = ServerErrorHandler::callback(exc.getMessage());
}
diff --git a/utils/template_parser.cpp b/utils/template_parser.cpp
index 3ca191a..bb7db11 100644
--- a/utils/template_parser.cpp
+++ b/utils/template_parser.cpp
@@ -2,10 +2,11 @@
#include
";
body += "";
- body += "SeddionId: ";
+ body += "SessionId: ";
body += req->getSessionId();
body += "
";
body += "