Code Monkey home page Code Monkey logo

fastcgipp's Introduction

fastcgi++

Author: Eddie Carle

Version: 3.1alpha

News

October 12, 2018 - PostgreSQL functionality is now complete and I'm really hoping to get people testing and giving feedback as soon as possible. I'm pretty proud of this particular iteration at integrating database functionality into fastcgi++ so go easy on me! Check out the example, unit test and reference documentation for further details.

April 5, 2018 - It's been long enough, 3.0 is now official and marked stable.

May 28, 2016 - Some good examples are now done and in the documentation. I've got said documentation hosted online now so check it out.

May 18, 2016 - The re-write is now effectively complete. What I mean by this is that the library now builds and passes some basic benchmarking tests. I'm really hoping to get as much feedback as possible so please test away. The docs are not web hosted anywhere yet so you'll have to build them yourself as described below. Note that the only example/tutorial that works so far is the helloworld one.

April 10, 2016 - Fastcgi++ is going through a dramatic rewrite now and the master branch does not work at all. If you're here hoping for a functional version scroll down to the releases section. If you'd like to read a bit more about the rewrite and fastcgi++ in general, check out [Ten years of fastcgi++].

About

This library is intended as a high-efficiency C++20 api for web development. It allows your applications to communicate with web servers through the FastCGI protocol, tabulates all your environment data, manages character encoding, and allows requests to effectively share CPU time. If you want any further information check the Doxygen documentation associated with the respective release, or build it yourself. Be sure to read through the examples.

Releases

Your best bet for releases and documentation is to clone the Git repository, checkout the tag you want and see the building section of either this file or the Doxygen documentation. If you're too lazy for that, however, you can take the risk and try the following links.

Building

This should provide you with all the basic stuff you need to do to get fastcgi++ built and installed. The build system is CMake and the following instructions assume you are in Bash.

First we need to clone.

git clone https://github.com/eddic/fastcgipp.git fastcgi++

Then we make a build directory.

mkdir fastcgi++.build
cd fastcgi++.build

Now we need run cmake. Note that the install prefix is being explicitly set to /usr because most server spawned FastCGI applications lack the /usr/local library directories in the search path.

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=RELEASE ../fastcgi++

And if we want to build the PostgreSQL stuff we need to actually make it do so.

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=RELEASE -DSQL=true ../fastcgi++

Note that that was to do a release build. That means heavily optimized and not good for debugging. If you want to do some debugging to either fastcgi++ or an application you are developing that uses fastcgi++, do a debug build.

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=DEBUG ../fastcgi++

Or if you want some really hardcore debug and diagnostics info

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=DEBUG -D LOG_LEVEL:INT=4 ../fastcgi++

Now let's build the library itself.

make

Then we can build the documentation if we so desire.

make doc

Now let's install it all (doc included if it was built).

sudo make install

Maybe we should build the unit tests?

make tests

And of course we should run them as well.

make test

And hey, let's build the examples too!

make examples

fastcgipp's People

Contributors

a32sailor avatar astoltz avatar bertoldia avatar bertwim avatar bstoeger avatar codogeno avatar delperugia avatar eddic avatar erroneous1 avatar finkman avatar jatofg avatar kassak avatar kofuk avatar m79lol avatar melvinrook avatar mwischer avatar patlkli avatar slawekme avatar someonegg avatar susnux avatar thatsafunnyname avatar wdcrith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastcgipp's Issues

SEGFAULT on empty HTTP POST requests

it does segfault in http.cpp, fastcgipp version 2.1 in
void Fastcgipp::Http::Environment::parsePostsUrlEncoded()

I did not figured out how to fix it yet.

Version 3.0beta is broken in many ways

  1. The code to set non-blocking mode sets blocking mode instead. Re-read the one-liner you use:

fcntl(listen, F_SETFL, (fcntl(listen, F_GETFL)|O_NONBLOCK)^O_NONBLOCK);

It gets current socket flags, appends O_NONBLOCK to them with logic OR, and THEN, for some reason, does XOR with O_NONBLOCK, which leads to dropping of O_NONBLOCK flag).

  1. Several places where invalid iterator (end) is dereferenced:
  • Fastcgipp::FcgiStreambuf<wchar_t, std::char_traits<wchar_t>>::emptyBuffer()
    &*record.end() - it's wrong to do this.
  • void Fastcgipp::Http::vecToString(
    string = converter.from_bytes(&_start, &_end); - DITTO
  1. Bad reinterpret cast:
    reinterpret_cast<uint16_t>(write) = 0xffff;
    should be
    reinterpret_cast<uint16_t>(&*write) = 0xffff;

  2. Vector iterator reused between different vectors (which is not allowed):

In template void Fastcgipp::Http::decodeUrlEncoded(

nameEnd is first used as

auto nameEnd(dataEnd);

but later is resued in this statement:

            nameEnd = percentEscapedToRealBytes(
                    nameStart,
                    data,
                    buffer.begin());

Where it becomes an iterator from "buffer".

I'm sure there are many more errors here, but at this point, I kind gave up, this library is not ready to be used in production.

class or struct

../src/http.cpp:626:10: error: class template 'Environment' was previously declared as a struct template [-Werror,-Wmismatched-tags]
template class Fastcgipp::Http::Environment;
^
../include/fastcgi++/http.hpp:251:38: note: previous use is here
template struct Environment
^
../src/http.cpp:626:10: note: did you mean struct here?
template class Fastcgipp::Http::Environment;
^~~~~
struct
../src/http.cpp:627:10: error: class template 'Environment' was previously declared as a struct template [-Werror,-Wmismatched-tags]
template class Fastcgipp::Http::Environment<wchar_t>;
^
../include/fastcgi++/http.hpp:251:38: note: previous use is here
template struct Environment

Allow custom POST data

At the moment the server will return a 500 server error if unknown POST data is received.
But sometimes you want to receive it (e.g. when getting json).
In this case I would like to simply access the post buffer and work with the raw data (parse the json with my Request class).

I can not run helloworld example correctly

Hi @eddic
I cloned fastcgipp,and compile it successfully,then,I run make helloworld.fcgi to generate executable. But I found it listen none port, no bind syscall used, and listen complain "illege seek" error. My question is how run it correctly

fastcgi++ is not stable

I compiled the example echo.cpp, launched with spawn-fcgi. and set up nginx

But when I accessed it in browsers, although it replied the correct webpage, most of time, it replied 504 error

Sometimes it crashes.

Do you have any suggestions?

File Uploads larger than ~500kb causes Read() error behind nginx

Was getting a "Socket read() error on fd 8: Resource temporarily unavailable" when uploading files larger than ~500kb using the library being an nginx proxy. (nginx throws a 502 to the client and "writev() failed (32: Broken pipe) while sending request to upstream" to the error log)

Adding a hacky retry loop that's around the read call (socket.cpp:74 - commit fc9bfc4) seems to fix the issue for my purposes (can upload 20mb+ now) - but I didn't track down the underlying cause.

Hope this helps,
Cheers

Compilation error with gcc 7.1.1

Compilation error with gcc 7.1.1

fastcgipp/include/fastcgi++/fcgistreambuf.hpp:73:28: error: «function» in namespace «std» does not name a template type
                 const std::function<void(const Socket&, std::vector<char>&&)>

patch:

diff --git a/include/fastcgi++/fcgistreambuf.hpp b/include/fastcgi++/fcgistreambuf.hpp
index 6436d07..1f4b3a8 100644
--- a/include/fastcgi++/fcgistreambuf.hpp
+++ b/include/fastcgi++/fcgistreambuf.hpp
@@ -34,6 +34,7 @@
 #include "fastcgi++/block.hpp"
 
 #include <istream>
+#include <functional>
 
 //! Topmost namespace for the fastcgi++ library
 namespace Fastcgipp


Poll gave fd xx which isn't in m_sockets

I came across this problem sometimes.
Jul 10 00:00:03 machinename /fastcgidemo [1452] [error]: Poll gave fd 26 which isn't in m_sockets.
It was likely that socket gourps was in disorder.i want to know what can lead to this error and how to solve.

Debian 9 FastCGI++ does not compile under g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

cmake version 3.13.1

$ sudo apt-get install libpq-dev postgresql-server-dev-all
$ git clone https://github.com/eddic/fastcgipp.git fastcgi++
...
$ cd fastcgi++
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=RELEASE -DSQL=true ..
-- The CXX compiler identification is GNU 6.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PostgreSQL: /usr/lib/x86_64-linux-gnu/libpq.so (found version "9.6.12") 
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/fastcgi++/build

$ make
Scanning dependencies of target fastcgipp
[  5%] Building CXX object CMakeFiles/fastcgipp.dir/src/log.cpp.o
[ 11%] Building CXX object CMakeFiles/fastcgipp.dir/src/block.cpp.o
[ 17%] Building CXX object CMakeFiles/fastcgipp.dir/src/http.cpp.o
[ 23%] Building CXX object CMakeFiles/fastcgipp.dir/src/protocol.cpp.o
[ 29%] Building CXX object CMakeFiles/fastcgipp.dir/src/sockets.cpp.o
[ 35%] Building CXX object CMakeFiles/fastcgipp.dir/src/transceiver.cpp.o
[ 41%] Building CXX object CMakeFiles/fastcgipp.dir/src/fcgistreambuf.cpp.o
[ 47%] Building CXX object CMakeFiles/fastcgipp.dir/src/webstreambuf.cpp.o
[ 52%] Building CXX object CMakeFiles/fastcgipp.dir/src/request.cpp.o
[ 58%] Building CXX object CMakeFiles/fastcgipp.dir/src/manager.cpp.o
[ 64%] Building CXX object CMakeFiles/fastcgipp.dir/src/address.cpp.o
[ 70%] Building CXX object CMakeFiles/fastcgipp.dir/src/mailer.cpp.o
[ 76%] Building CXX object CMakeFiles/fastcgipp.dir/src/email.cpp.o
[ 82%] Building CXX object CMakeFiles/fastcgipp.dir/src/parameters.cpp.o
/home/kas/work/git/fastcgi++/src/parameters.cpp:38:31: fatal error: server/utils/inet.h: No such file or directory
 #include <server/utils/inet.h>
                               ^
compilation terminated.
CMakeFiles/fastcgipp.dir/build.make:231: recipe for target 'CMakeFiles/fastcgipp.dir/src/parameters.cpp.o' failed
make[2]: *** [CMakeFiles/fastcgipp.dir/src/parameters.cpp.o] Error 1
CMakeFiles/Makefile2:168: recipe for target 'CMakeFiles/fastcgipp.dir/all' failed
make[1]: *** [CMakeFiles/fastcgipp.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2

gnu example can not show the image when run with nginx

Since there's no PATH_INFO param in what nginx send to gnu.fcgi.
the following condition is always false.

fastcgipp/examples/gnu.cpp

Lines 102 to 104 in f321a1d

if(
environment().pathInfo.size() == 1
&& environment().pathInfo[0] == L"gnu.png")

possible solution is to use requestUri, since the URI is not started with gnu.png, so use find() here.

&& environment().pathInfo[0] == L"gnu.png")

possible patch:
(the cmakelist.txt change is for debian stable which still uses cmake 3.7 that does not support target_compile_features(fastcgipp PRIVATE cxx_std_14),
just FYI if you're willing to make it build with cmake 3.7)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 99d7e0d..5031dbc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.8)
+cmake_minimum_required(VERSION 3.7)
 project(fastcgi++ VERSION 3.1 LANGUAGES CXX)
 
 string(TIMESTAMP BUILD_TIME UTC)
@@ -111,7 +111,10 @@ set_target_properties(fastcgipp PROPERTIES VERSION ${PROJECT_VERSION}
 
 find_package(Threads REQUIRED)
 target_link_libraries(fastcgipp PUBLIC Threads::Threads)
-target_compile_features(fastcgipp PRIVATE cxx_std_14)
+#target_compile_features(fastcgipp PRIVATE cxx_std_14)
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED on)
+set(CMAKE_CXX_EXTENSIONS off)
 if(UNIX)
     if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
         target_compile_options(fastcgipp PRIVATE -Wall -Werror -fno-omit-frame-pointer)
diff --git a/examples/gnu.cpp b/examples/gnu.cpp
index 26690e6..c9c9e5e 100644
--- a/examples/gnu.cpp
+++ b/examples/gnu.cpp
@@ -99,9 +99,7 @@ L"</html>";
     //! [Response]
        bool response()
        {
-        if(
-                environment().pathInfo.size() == 1
-                && environment().pathInfo[0] == L"gnu.png")
+        if(environment().requestUri.find(L"gnu.png") != environment().requestUri.npos)
             image();
         else
             html();

I've tested the patch, seem work fine.

Way to get Raw FCGI Params

Is there a way to get the raw FCGI Parameters? Your Environment class auto-parses most of them, but it is missing a few that we use. How do I access the raw FCGI parameters of a request?

How to build fastcgi++ as a static library libfastcgipp.a

Hello,
I am not familiar with cmake; I just know how to run it.

I am however very familiar with Linux on the command line.

It would be nice if we could make libfastcgipp.a because of various C++ ABI issues on Linux (e.g. the libstdc++.so could be different on my Linux laptop and on the Linux VPS I am renting).

BTW, I could soon use libfastcgipp.so in the http://refpersys.org/ project

Regards


Basile Starynkevitch
[email protected] (near Paris, France)

FastCGI++ does not compile under gcc 7.1.1

Following the build instructions, I got 2 compilation errors, both about variables ("buffer" and "padStart") on the same line in the file http.hpp. The variables could possibly be used without an initialisation.

how to get custom header

using fastcigpp,i can get standard headers,such as HTTP_HOST,HTTP_COOKIE,SERVER_ADDR etc. how can i get user defined headers,such as xxx_header1,xxxx_header2 etc.

mysql8 support

any plan to support mysql8? specifically the mysqlx plugin/protocol for RDBS+Document Store.

fastcgi++/config.hpp not found

When I was in vs2013 compile fastcgipp - master/examples under the helloworld, tip unable to open include file: "fastcgi++ / config. HPP" : No to the file or directory I really don't have the file view under the directory

Moveable Environment

I have the following situation (fastcgi server):
When a request comes in, I push off all handling of the request to a threadpool and wait for a Fastcgipp::Message to be returned from a function.

If the connection is closed (e.g. if the server/clients's timeout is reached) the request's destructor is called which invalidates things like the request's environment.

If I then try to access the environment from the threadpool thread my process can segfault.

Would it be possible to either:

  • make the Request's environment moveable and add a non-const reference to the environment
  • make the Request's various post/get/file/other attributes movable and add a non-const reference to the environment
  • add a method to move or copy if necessary the various post/get/file/other attributes to a new Environment
  • make the Request's environment a std::shared_ptr so that it sticks around as long as it has a reference (adds overhead)

mail example will fail and retry inifinitly if sender address is bad

The example app mail.fcgi will inifinitly retry with bad sender address.
I found thousands of fail logs after input a bad send address, I think this might be a trouble to your server.

May 05 19:17:45 aa email.fcgi[15698] [error]: Bad reply from SMTP server after MAIL: 501 <oh>: sender address must contain a domain
May 05 19:17:46 aa email.fcgi[15698] [error]: Bad reply from SMTP server after MAIL: 501 <oh>: sender address must contain a domain
...
...
May 05 19:17:46 aa email.fcgi[15698] [error]: Bad reply from SMTP server after MAIL: 501 <oh>: sender address must contain a domain
May 05 19:17:46 aa email.fcgi[15698] [error]: Bad reply from SMTP server after MAIL: 501 <oh>: sender address must contain a domain

build failed in mac os

FAILED: CMakeFiles/fastcgipp.dir/src/log.cpp.o
/Users/didi/bin/c++ -Dfastcgipp_EXPORTS -Iinclude -I/Users/didi/keepwatch/libs/fastcgipp/include -I/Users/didi/include -std=c++14 -Wall -Werror -Wold-style-cast -pthread -fPIC -MD -MT CMakeFiles/fastcgipp.dir/src/log.cpp.o -MF CMakeFiles/fastcgipp.dir/src/log.cpp.o.d -o CMakeFiles/fastcgipp.dir/src/log.cpp.o -c /Users/didi/keepwatch/libs/fastcgipp/src/log.cpp
/Users/didi/keepwatch/libs/fastcgipp/src/log.cpp: 在函数‘std::__cxx11::wstring Fastcgipp::Logging::getHostname()’中:
/Users/didi/keepwatch/libs/fastcgipp/src/log.cpp:51:25: 错误:‘HOST_NAME_MAX’在此作用域中尚未声明
char buffer[HOST_NAME_MAX+2];
^
/Users/didi/keepwatch/libs/fastcgipp/src/log.cpp:52:25: 错误:‘buffer’在此作用域中尚未声明
gethostname(buffer, sizeof(buffer));
^
/Users/didi/keepwatch/libs/fastcgipp/src/log.cpp: 在函数‘std::__cxx11::wstring Fastcgipp::Logging::getProgram()’中:
/Users/didi/keepwatch/libs/fastcgipp/src/log.cpp:75:25: 错误:‘program_invocation_name’在此作用域中尚未声明
program_invocation_name,

Not an issue just a question

If I wanted to access an environment variable like the script_name and then use that to determine which class to hand to the Fastcgipp::Manager would be the simplest way to go about doing this? I'm using v 2.1

Thread::Thread unkown

The library uses Thread::Thread and therefore calls find_package(Threads REQUIRED).

The problem is, that it only calls it on it's own CMakeLists.txt and not within it's FastcgippConfig.cmake.

This results in an error running cmake configure on a project which is using Fastcgipp but not Thread in first place:

 ...
  Target "FastCgi" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
...

Session Problem

I seem found a problem with the Session Example.
Session.fcgi were not share the s_sessions in different process.
I had open 25 process to launch the Session.fcgi ,
When I reflash the Site too fast , the nginx will use other process(because the first process is using)
and then the session size is zero in second process.

3.0 creating named socket fails to create file

The FastCGIPP::SocketGroups::listen( const char*, uint, const char*, const char*) fails
to create a file for the socket that can be referenced by NGINX fastcgi_pass directive.

Start a FastCGI with the following line to create a socket ...

    const char* sockfilepath = "/tmp/hello.sock" ;
    manager.listen(sockfilepath,  0xffffffffUL, "nobody" ) ) ;

Simple NGINX config.

http {
   server {
        location /hello {
           fastcgi_pass unix:/tmp/hello.sock ;
        }
    }
}

Results in the following error.

2017/01/09 20:17:20 [crit] 7#7: *1 connect() to unix:/tmp/hello.sock failed (2: No such file or directory) while connecting to upstream, client: 172.17.0.1, server: localhost, request: "GET /hello HTTP/1.1", upstream: "fastcgi://unix:/tmp/hello.sock:", host: "localhost:8888"

... because the file is not being created.

Get an error when making the application

/root/app/fastcgi++/src/sockets.cpp: In member function ‘Fastcgipp::Socket Fastcgipp::SocketGroup::poll(bool)’:
/root/app/fastcgi++/src/sockets.cpp:448:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if(events == pollIn)

3.0beta build error for sockets.cpp

Similar issue mentioned by MatthewButterfly:
/home/adminuser/fastcgi++/src/sockets.cpp: In member function ‘Fastcgipp::Socket Fastcgipp::SocketGroup::poll(bool)’:
/home/adminuser/fastcgi++/src/sockets.cpp:523:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if(events == pollIn)
^
/home/adminuser/fastcgi++/src/sockets.cpp:538:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if(events == pollIn)

This is on Centos 6.8 with devtoolset-4 and cmake3 installed.

I changed both instances to use if(events & pollIn) and compile worked.
I haven't tested the binary produced but I assume it'll work as you only want to check if the EPOLLIN bits are set in the events.

pkg-config cannot find fastcgi++

I had written a small web server using this library. I used to compile the program using shell scripts and it worked because I directly linked with -lfastcgipp. As a part of my refactor, I want to use build systems (for obvious reasons). I chose meson which could not find fastcgi++. I learned that the pkg-config was not able to find fastcgi++. This is the output of pkg-config --cflags --libs fastcgi++

Package fastcgi++ was not found in the pkg-config search path.
Perhaps you should add the directory containing `fastcgi++.pc'
to the PKG_CONFIG_PATH environment variable
Package 'fastcgi++', required by 'virtual:world', not found

Note: The PKG_CONFIG_PATH variable is empty

A quick google search about pkg-config fastcgi++ brings me to the documentation of fastcgi++ 2.1 which states:

A pkg-config file will be installed so you can compile against the libraries with
g++ -o script.fcgi script.cpp pkg-config –libs –cflags fastcgi++

But the documentation of 3.0 does not state that.

I installed fastcgi++ as mention in the readme without SQL support. have I done something wrong? Or is the support removed in verison 3?

Compile on OSX

Thanks for a great library.

To get this to compile on OSX, can you add to the top of sockets.cpp

#ifndef POLLRDHUP
#define POLLRDHUP 0x2000
#endif

#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
# ifdef SO_NOSIGPIPE
#  define CEPH_USE_SO_NOSIGPIPE
# else
#  error "Cannot block SIGPIPE!"
# endif
#endif

And add to log.cpp:

#if __APPLE__
    #ifndef HOST_NAME_MAX
        #define HOST_NAME_MAX 255
    #endif

    #ifndef program_invocation_name
        #define program_invocation_name "fastcgi"
    #endif
#endif

Cannot compile on Ubuntu

I am having multiple issues under Ubuntu with gcc 5.4.0.

After running make and make install, I try to build the examples. However, I get this error:

#error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

I didn't see any warnings/errors prior. Is there something I am missing?

Problem decoding URL query string

Hi,

when receiving a request, if the query string ends by separator "&", the separator is added to the last value:

http://localhost/doc?p=a&

p is set to "a&" instead of "a".

C++ code showing the problem:

#include "fastcgi++/http.hpp"
#include <iostream>

int main()
{
    const char input[] = "p=a&";

    std::multimap<std::wstring, std::wstring> output;
    Fastcgipp::Http::decodeUrlEncoded(
            input,
            input+sizeof(input)-1,
            output);

    for ( auto & parameter : output )
        std::wcout << parameter.first << "=" << parameter.second << std::endl;
}

codecvt not found

when i make fastcgi++,it's failed.It needs the header file ,but I could not find this file.I tried to update libstdc++ by 'yum',but it told me is lastest.
so how can I get the file codecvt to slove this problem?

how to change http status code

HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Tue, 05 Dec 2017 08:13:47 GMT
Content-Type: text/html; charset=UTF-8

i want to set status code 204. how to do it.

Static Linking Error

Statically linked executable refuses to start web app.
On running make test the following output is shown

Test project /home/ken/Applications/fastcgipp/fastcgipp/build_static
    Start 1: protocol
1/5 Test #1: protocol .........................   Passed    0.01 sec
    Start 2: http
2/5 Test #2: http .............................   Passed    4.03 sec
    Start 3: sockets
3/5 Test #3: sockets ..........................***Exception: SegFault  1.08 sec
    Start 4: transceiver
4/5 Test #4: transceiver ......................***Exception: SegFault  0.00 sec
    Start 5: fcgistreambuf
5/5 Test #5: fcgistreambuf ....................   Passed    0.00 sec

60% tests passed, 2 tests failed out of 5

Total Test time (real) =   5.13 sec

The following tests FAILED:
	  3 - sockets (SEGFAULT)
	  4 - transceiver (SEGFAULT)
Errors while running CTest
make: *** [Makefile:130: test] Error 8

Running ./sockets_test outputs

Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd .
Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd ..
Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd 0 -> /dev/pts/0
Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd 1 -> /dev/pts/0
Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd 2 -> /dev/pts/0
Jan 31 00:19:53 kioko ./sockets_test[25309] [info]: fd 3 -> /proc/25309/fd
Jan 31 00:19:53 kioko ./sockets_test[25309] [diagnostic]: SocketGroup::SocketGroup(): Initialized 
Jan 31 00:19:53 kioko ./sockets_test[25309] [diagnostic]: SocketGroup::SocketGroup(): Initialized 
Segmentation fault

And for ./transceiver_test

Segmentation fault

Dynamic linkage launches the web app but still fails ./sockets_test only

Fastcgipp::Socket Fastcgipp::SocketGroup::poll(bool) ERROR

/src/sockets.cpp:523:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if(events == pollIn)
^
/src/sockets.cpp:538:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if(events == pollIn)

compile with gcc5.2
how to deal with it ?

Socket Test Fails: Unable to connect to 127.0.0.1:12229

Built all okay on Ubuntu Xenial Server (x32_64) but socket tests failed. I shut down Nginx and PHP just in case but unfortunately no difference. Please let me know if you would like any more info...

LastTest.log Snippit

3/4 Testing: Fastcgipp::Sockets
3/4 Test: Fastcgipp::Sockets
Command: "/home/peter_devoy/fastcgi++.build/sockets_test"
Directory: /home/peter_devoy/fastcgi++.build
"Fastcgipp::Sockets" start time: Apr 29 23:03 BST
Output:
----------------------------------------------------------
[error] Unable to connect to 127.0.0.1:12229
[fail] Unable to connect to server
<end of output>
Test time =   0.00 sec
----------------------------------------------------------
Test Failed.
"Fastcgipp::Sockets" end time: Apr 29 23:03 BST
"Fastcgipp::Sockets" time elapsed: 00:00:00
----------------------------------------------------------

Consider setting SO_REUSEADDR/SO_REUSEPORT

Using setsockopt SO_REUSEADDR (or SO_REUSEPORT if Linux >= 3.9, I'd assume yes these days) before bind/listen can make it so that a server that segfaults can start listening right away. I didn't need to worry about this on 2.1 because I used the spawn-fcgi program which I never got to segfault. A great description of these options and how they differ between operating systems it is on stackoverflow.

Pure function called in fcgistreambuf_test

Using gcc 7.3.0 on Ubuntu 18.04 (32 and 64 bits), the fcgistreambuf_test program throws a "pure virtual method called" error when the destructor of streambuf is called. gdb shows:

#5  0x00007ffff77d980f in __cxa_pure_virtual () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x000055555555be95 in Fastcgipp::WebStreambuf<wchar_t, std::char_traits<wchar_t> >::sync (
    this=0x7fffffff6340)
    at ../fastcgipp/include/fastcgi++/webstreambuf.hpp:229
#7  0x000055555555ba36 in Fastcgipp::WebStreambuf<wchar_t, std::char_traits<wchar_t> >::~WebStreambuf (
    this=0x7fffffff6340, __in_chrg=<optimized out>)
    at ../fastcgipp/include/fastcgi++/webstreambuf.hpp:240
#8  0x000055555555c428 in Fastcgipp::FcgiStreambuf<wchar_t, std::char_traits<wchar_t> >::~FcgiStreambuf (
    this=0x7fffffff6340, __in_chrg=<optimized out>)
    at ../fastcgipp/include/fastcgi++/fcgistreambuf.hpp:55
#9  0x000055555555a99e in main () at ../fastcgipp/tests/fcgistreambuf.cpp:312

It seems it is because base class WebStreambuf destructor calls sync which calls emptyBuffer which is a pure function defined in the parent class FcgiStreambuf. And since destructors are called in sequence, FcgiStreambuf is already destroyed when WebStreambuf destructor is executed.

Was working fine in previous versions where sync was called from FcgiStreambuf destructor (tested with commit 3bf169a).

use template programming instead of macros for logging

fastcgipp/include/fastcgi++/log.hpp:94:69: error: declaration of ‘lock’ shadows a previous local [-Werror=shadow]
...
fastcgipp/src/sockets.cpp:547:25: note: in expansion of macro ‘FAIL_LOG’

This is just one example. Using the lock_guard called lock shadows any other variable called lock. You could use a variadic template instead and acheive the same results. Just use , instead of <<. I can submit a PR if you want.

POST JSON

Is there a way to process post data of content type: application/json
I keep getting a warning in my apache2 log file
[warning]: Unknown content type from client

Compile error

Scanning dependencies of target fastcgipp
[ 20%] Building CXX object CMakeFiles/fastcgipp.dir/src/log.cpp.o
cc1plus: error: invalid option argument ‘-Og’
cc1plus: error: unrecognized command line option "-std=c++14"
cc1plus: error: unrecognized command line option "-std=c++14"
make[2]: *** [CMakeFiles/fastcgipp.dir/src/log.cpp.o] Error 1
make[1]: *** [CMakeFiles/fastcgipp.dir/all] Error 2
make: *** [all] Error 2

Sockets test failed

Compilation was OK:

cmake -DCMAKE_BUILD_TYPE=RELEASE ../fastcgipp-master
-- The CXX compiler identification is GNU 5.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/anatoly/CppProjects/fastcgi++.build

make
Scanning dependencies of target fastcgipp
[ 9%] Building CXX object CMakeFiles/fastcgipp.dir/src/log.cpp.o
[ 18%] Building CXX object CMakeFiles/fastcgipp.dir/src/block.cpp.o
[ 27%] Building CXX object CMakeFiles/fastcgipp.dir/src/http.cpp.o
[ 36%] Building CXX object CMakeFiles/fastcgipp.dir/src/protocol.cpp.o
[ 45%] Building CXX object CMakeFiles/fastcgipp.dir/src/sockets.cpp.o
[ 54%] Building CXX object CMakeFiles/fastcgipp.dir/src/transceiver.cpp.o
[ 63%] Building CXX object CMakeFiles/fastcgipp.dir/src/fcgistreambuf.cpp.o
[ 72%] Building CXX object CMakeFiles/fastcgipp.dir/src/webstreambuf.cpp.o
[ 81%] Building CXX object CMakeFiles/fastcgipp.dir/src/request.cpp.o
[ 90%] Building CXX object CMakeFiles/fastcgipp.dir/src/manager.cpp.o
[100%] Linking CXX shared library libfastcgipp.so
[100%] Built target fastcgipp

make tests
[ 52%] Built target fastcgipp
Scanning dependencies of target sockets_test
[ 57%] Building CXX object CMakeFiles/sockets_test.dir/tests/sockets.cpp.o
[ 61%] Linking CXX executable sockets_test
[ 61%] Built target sockets_test
Scanning dependencies of target fcgistreambuf_test
[ 66%] Building CXX object CMakeFiles/fcgistreambuf_test.dir/tests/fcgistreambuf.cpp.o
[ 71%] Linking CXX executable fcgistreambuf_test
[ 71%] Built target fcgistreambuf_test
Scanning dependencies of target http_test
[ 76%] Building CXX object CMakeFiles/http_test.dir/tests/http.cpp.o
[ 80%] Linking CXX executable http_test
[ 80%] Built target http_test
Scanning dependencies of target transceiver_test
[ 85%] Building CXX object CMakeFiles/transceiver_test.dir/tests/transceiver.cpp.o
[ 90%] Linking CXX executable transceiver_test
[ 90%] Built target transceiver_test
Scanning dependencies of target protocol_test
[ 95%] Building CXX object CMakeFiles/protocol_test.dir/tests/protocol.cpp.o
[100%] Linking CXX executable protocol_test
[100%] Built target protocol_test
Scanning dependencies of target tests
[100%] Built target tests

Failing tests:

Running tests...
Test project /home/anatoly/CppProjects/fastcgi++.build
Start 1: protocol
1/5 Test #1: protocol ......................... Passed 0.00 sec
Start 2: http
2/5 Test #2: http ............................. Passed 4.01 sec
Start 3: sockets
3/5 Test #3: sockets ..........................***Failed 1.88 sec
Start 4: transceiver
4/5 Test #4: transceiver ...................... Passed 0.20 sec
Start 5: fcgistreambuf
5/5 Test #5: fcgistreambuf .................... Passed 0.00 sec

80% tests passed, 1 tests failed out of 5

Total Test time (real) = 6.10 sec

The following tests FAILED:
3 - sockets (Failed)
Errors while running CTest
Makefile:127: recipe for target 'test' failed
make: *** [test] Error 8

Operation System:

Ubuntu 16.04

MACOSX_RPATH is not specified

-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

MACOSX_RPATH is not specified for the following targets:

fastcgipp

Export cmake config

Part of modern CMake is exporting a ProjectConfig.cmake file and installing to lib/cmake/project. It would be nice for CMake users to be able to simply:

find_package(Fastcgipp REQUIRED)
add_executable(foo foo.cpp)
target_link_libraries(foo PRIVATE Fastcgipp::fastcgipp)

Building error

Building the examples finishes with the error:

/usr/local/include/fastcgi++/request.hpp:36:36: fatal error: fastcgi++/exceptions.hpp: No such file or directory
compilation terminated.

exceptions.hpp was really deleted in 09b65f4

Build error: Comparison between signed and unsigned integer

Compiling with GCC 5.3.1 or 6.1 on an i586 openSUSE machine the build always exits with an error:

src/request.cpp:106:64: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
[ 108s] && environment().contentLength > m_maxPostSize)
[ 108s] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
[ 108s] /home/abuild/rpmbuild/BUILD/fastcgi++-3.0beta/src/request.cpp: In instantiation of 'std::unique_lockstd::mutex Fastcgipp::Request::handler() [with charT = wchar_t]':
[ 108s] /home/abuild/rpmbuild/BUILD/fastcgi++-3.0beta/src/request.cpp:58:76: required from here
[ 108s] /home/abuild/rpmbuild/BUILD/fastcgi++-3.0beta/src/request.cpp:106:64: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

The reason is that contentLength is unsigned and m_maxPostSize is ssize_t.
A solution would be to use size_t instead of ssize_t and use std::npos instead of -1 (ok they are quite equal ;-) ) to determine if unlimited or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.