diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d22a114a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: tipi.build +# This workflow is triggered on pushes to the repository. +on: [push] + +jobs: + build: + name: build-linux + runs-on: ubuntu-latest + container: tipibuild/tipi-ubuntu + steps: + - name: checkout + uses: actions/checkout@v2 + - name: tipi builds project + run: | + export HOME=/root + mkdir -p ~/.tipi + tipi . -t linux-cxx17 --dont-upgrade --verbose diff --git a/.tipi/deps b/.tipi/deps new file mode 100644 index 00000000..0ae80a61 --- /dev/null +++ b/.tipi/deps @@ -0,0 +1,7 @@ +{ + "tipi-deps/libmicrohttpd" : { } + ,"libuv/libuv":{"u":true, "packages":["libuv"],"src/targets":["uv"]} + ,"cpp-pm/pthreads-win32:vs-16-2019-win64-cxx17" :{"u":true, "packages" : ["pthreads-win32"],"targets" : ["pthreads-win32::pthreads"]} + , "platform" :["CURL::+libcurl"] + , "platform:vs-16-2019-win64-cxx17" :["ZLIB::+zlib", "ZLIB::+zlib", "CURL::+libcurl", "OpenSSL::+SSL", "OpenSSL::+Crypto","target::crypt32", "target::ws2_32"] +} \ No newline at end of file diff --git a/.tipi/opts b/.tipi/opts new file mode 100644 index 00000000..598b83bb --- /dev/null +++ b/.tipi/opts @@ -0,0 +1,3 @@ +add_compile_definitions( + HTTPSERVER_COMPILATION +) \ No newline at end of file diff --git a/.tipi/opts.vs-16-2019-win64-cxx17 b/.tipi/opts.vs-16-2019-win64-cxx17 new file mode 100644 index 00000000..6a0c480b --- /dev/null +++ b/.tipi/opts.vs-16-2019-win64-cxx17 @@ -0,0 +1,7 @@ +add_compile_definitions( + HTTPSERVER_COMPILATION + NOMINMAX + WIN32_LEAN_AND_MEAN + _WIN32_WINNT=0x0A00 # We have to set the windows version targeted + WINVER=0x0A00 # We have to set the windows version targeted +) \ No newline at end of file diff --git a/README.md b/README.md index 07021ed9..d62dc81e 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,33 @@ Copyright (C) 2011-2019 Sebastiano Merlino. Free Documentation License". --> +# Using libhttpserver with tipi.build + +`libhttpserver` can be easily used in [tipi.build](https://tipi.build) projects simply by adding the following entry to your `.tipi/deps`: + +```json +{ + "tipi-deps/libhttpserver" : { "@" : "master"} +} +``` + +To try this you can run the following command in `/` (change the target name appropriately to `linux` or `macos` or `windows`): + +```bash +tipi . -t +``` + +If you want to use this library with tipi you can do : + +[![tipi.build](https://github.com/tipi-deps/libhttpserver/workflows/tipi.build/badge.svg)](https://github.com/tipi-deps/libhttpserver/actions?query=branch%3Amaster) + + # The libhttpserver reference manual + ![GA: Build Status](https://github.com/etr/libhttpserver/actions/workflows/verify-build.yml/badge.svg) + [![Build status](https://ci.appveyor.com/api/projects/status/ktoy6ewkrf0q1hw6/branch/master?svg=true)](https://ci.appveyor.com/project/etr/libhttpserver/branch/master) + [![codecov](https://codecov.io/gh/etr/libhttpserver/branch/master/graph/badge.svg)](https://codecov.io/gh/etr/libhttpserver) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1bd1e8c21f66400fb70e5a5ce357b525)](https://www.codacy.com/gh/etr/libhttpserver/dashboard?utm_source=github.com&utm_medium=referral&utm_content=etr/libhttpserver&utm_campaign=Badge_Grade) [![Gitter chat](https://badges.gitter.im/etr/libhttpserver.png)](https://gitter.im/libhttpserver/community) diff --git a/examples/getopt.h b/examples/getopt.h new file mode 100644 index 00000000..90902235 --- /dev/null +++ b/examples/getopt.h @@ -0,0 +1,75 @@ +#if defined(_MSC_VER) + +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* +* getopt -- +* Parse argc/argv argument vector. +*/ +int + getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + const char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)printf("option requires an argument -- %c\n", optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} +#endif \ No newline at end of file diff --git a/examples/service.cpp b/examples/service.cpp index 3f8ccb03..3c9dada9 100644 --- a/examples/service.cpp +++ b/examples/service.cpp @@ -18,7 +18,13 @@ USA */ +#if defined(_MSC_VER) +#include +#include +#include +#else #include +#endif #include #include diff --git a/src/file_response.cpp b/src/file_response.cpp index 669f5e8b..97002de4 100644 --- a/src/file_response.cpp +++ b/src/file_response.cpp @@ -24,7 +24,19 @@ #include #include #include + +#if defined(_MSC_VER) +#include +#include +#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) + #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif +#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) + #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif +#else #include +#endif #include struct MHD_Response; @@ -43,7 +55,6 @@ MHD_Response* file_response::get_raw_response() { int fd = open(filename.c_str(), O_RDONLY); if (fd == -1) return nullptr; - off_t size = lseek(fd, 0, SEEK_END); if (size == (off_t) -1) return nullptr; diff --git a/src/httpserver/http_utils.hpp b/src/httpserver/http_utils.hpp index 6de523ea..998cee4e 100644 --- a/src/httpserver/http_utils.hpp +++ b/src/httpserver/http_utils.hpp @@ -31,7 +31,7 @@ // needed to force Vista as a bare minimum to have inet_ntop (libmicro defines // this to include XP support as a lower version). -#if defined(__MINGW32__) || defined(__CYGWIN32__) +#if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(_MSC_VER) #define _WINDOWS #undef _WIN32_WINNT #define _WIN32_WINNT 0x600 @@ -45,7 +45,7 @@ #include #include -#if !defined(__MINGW32__) +#if !(defined(__MINGW32__) || defined(_MSC_VER)) #include #endif diff --git a/src/httpserver/webserver.hpp b/src/httpserver/webserver.hpp index ef28cdb6..1692da46 100644 --- a/src/httpserver/webserver.hpp +++ b/src/httpserver/webserver.hpp @@ -36,7 +36,7 @@ #include #include -#if !defined(__MINGW32__) +#if !(defined(__MINGW32__) || defined(_MSC_VER)) #include #endif diff --git a/src/webserver.cpp b/src/webserver.cpp index b345c53e..445e7b22 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -32,13 +32,19 @@ #include #endif +#if defined(_MSC_VER) +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#else +#include +#endif + #include #include #include #include #include #include -#include #include #include #include @@ -92,13 +98,13 @@ struct compare_value { } }; -#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) +#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) static void catcher(int) { } #endif static void ignore_sigpipe() { // Mingw doesn't implement SIGPIPE -#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) +#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) struct sigaction oldsig; struct sigaction sig; diff --git a/test/integ/deferred.cpp b/test/integ/deferred.cpp index 0b37e322..02d37a9a 100644 --- a/test/integ/deferred.cpp +++ b/test/integ/deferred.cpp @@ -32,7 +32,13 @@ #include #include + +#if defined(_MSC_VER) +#include +#include +#else #include +#endif #include "./httpserver.hpp" #include "./littletest.hpp" diff --git a/test/integ/ws_start_stop.cpp b/test/integ/ws_start_stop.cpp index 0db04230..fe1aab00 100644 --- a/test/integ/ws_start_stop.cpp +++ b/test/integ/ws_start_stop.cpp @@ -32,7 +32,13 @@ #include #include + +#if defined(_MSC_VER) +#include +#include +#else #include +#endif #include "./httpserver.hpp" #include "./littletest.hpp"