Git Product home page Git Product logo

libnavajo's Introduction

libnavajo

Framework to develop easily web interfaces in your C++ applications

Libnavajo makes it easy to run an HTTP server into your own application, implement dynamic pages, and include all the web pages you want (local or compiled into your project)

Specifications :

  • Implementation is HTTP 1.1 compliant with SSL, X509 and HTTP authentification, compression Zlib...
  • Very fast with its fully configurable pthreads pool
  • Support for IPv4 and IPv6
  • Precompiler to include a web repository into your code
  • Generate dynamic and static contents
  • Cookies and advanced session management
  • HTML5 Websockets support
  • Multipart's Content support
  • Fully oriented object
  • Many examples included

Download and install :

git clone https://github.com/titi38/libnavajo.git

mkdir build

cd build

cmake ..

make

sudo make install

Notes:

Libnavajo is released under the CeCILL-C licence ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.txt )

If you want to support us or contribute, please contact [email protected]

libnavajo's People

Contributors

borismansencal avatar geraldolsribeiro avatar intmain-io avatar jcourtat avatar prakhunov avatar sebastien-pelle avatar titi38 avatar zingorn 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

Watchers

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

libnavajo's Issues

make problem with examples

Hi!

I have a problem for linking 1_basic, 3_websoket 4_wschat (2_gauge works fine)

libnavajo-error

my config :
Yosemit 10.10.5
clang 7.0.2
make 3.81

regards!

Two warnings appeared during the compilation of the library

Hi,

I really love your library. I use it for my own purpose and I appreciate the easy way to create interactive webpage with libnavajo through C++ application.

I just report two warnings: `~/Downloads/libnavajo-master/src/WebServer.cc: In member function ‘void WebServer::threadProcessing()’:
~/Downloads/libnavajo-master/src/WebServer.cc:1465: warning: dereferencing pointer ‘clientAddress.417’ does break strict-aliasing rules
~/Downloads/libnavajo-master/src/WebServer.cc:1465: note: initialized from here

~/Downloads/libnavajo-master/src/WebServer.cc:1471: warning: dereferencing pointer ‘clientAddress.418’ does break strict-aliasing rules
~/Downloads/libnavajo-master/src/WebServer.cc:1471: note: initialized from here`

These warnings appeared during the compilation of the library. There are not critical. I'm using GCC 4.4.7 on CentOs 7.

Access POST request payload

Hello Thierry,

I'm currently building a RESTfull api for a small project we have here.

Building pages and adding them to the dynamic repository on-the-fly works well.

However, I can't figure out how to retrieve the payload of a POST request ?

Cheers,

On the fly page creation

Hello Thierry :-)

me, again ;-)

According to this page (https://en.wikipedia.org/wiki/Representational_state_transfer) for a POST within a collection, a new entry is created and then returned.

This is what i do :
m_dr.add( ssUrl.str(), new restKeySetPage( m_db, keySetId, m_dr ) ) ;
response->forwardTo( ssUrl.str() ) ;

However, I get a 404.

I wondering if there is a kind of delay between the page creation and its availability ?

Thanks a lot.

Multiple parameter with the same name

Are there any approaches to handling multiple inputs with the same name?
Some like:
...?var=1&var=20&var=33

This is my try:

--- a/include/libnavajo/HttpRequest.hh
+++ b/include/libnavajo/HttpRequest.hh
@@ -118,8 +118,21 @@ class HttpRequest
       size_t posEq=0;
       if ((posEq = theParam.find('=')) == std::string::npos)
         parameters[theParam]="";
-      else
-        parameters[theParam.substr(0,posEq)]=theParam.substr(posEq+1);
+      else {
+        auto key        = theParam.substr(0,posEq);
+        auto value      = theParam.substr(posEq+1);
+        if( parameters.count( key ) == 0 ) {
+          parameters[key] = value;
+        } else {
+          auto arrayKey = key + "[]";
+          if( parameters.count( arrayKey ) == 1 ) {
+            parameters[arrayKey] += "|" + value;
+          } else {
+            parameters[arrayKey] = parameters[key] + "|" + value;
+          }
+          parameters[key] = value;
+        }
+      }

Memory Leak in WebSockets

While developing an app that sends lots of jpeg data over a websocket, I noticed there was a memory leak.

I have already created a pull request. #24

File corruption when using localRepository and a slow connection

Hello,
i'm trying to download a 10 MB file using localRepository object (no SSL).
If my wget client is on same subnet, the download is very fast and no corruption occurs.
If my wget client is on a distant network, with slow connection (300Kb/sec), then the corruption always happens.
Note that there are no corruption when using httpd between the same hosts, so the slow connection can't be considered as the corruptor.

regards

setServerPort has no effect

in earlier versions it worked, but no no matter what you put in setServerPort the service always runs on 8080

SIGSEGV on WebServer::closeSocket()

Hello,

I'm having an issue (SIGSEGV) within the WebServer::closeSocket()

(gdb) bt
#0  0x00007fffe80000a8 in ?? ()
#1  0x00007ffff7bb16df in WebServer::closeSocket (client=0x7ffff001d620) at /home/sherpa/Workspaces/workspace-Arduino/libnavajo/src/WebServer.cc:1522
#2  0x00007ffff7bb66dd in WebServer::freeClientSockData (c=0x7ffff001d620)
    at /home/sherpa/Workspaces/workspace-Arduino/libnavajo/include/libnavajo/WebServer.hh:49
#3  0x00007ffff7bb0c7c in WebServer::poolThreadProcessing (this=0x61dd60) at /home/sherpa/Workspaces/workspace-Arduino/libnavajo/src/WebServer.cc:1350
#4  0x00007ffff7bb6749 in WebServer::startPoolThread (t=0x61dd60) at /home/sherpa/Workspaces/workspace-Arduino/libnavajo/include/libnavajo/WebServer.hh:84
#5  0x00007ffff73bb6aa in start_thread (arg=0x7ffff7f52700) at pthread_create.c:333
#6  0x00007ffff70f0e9d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

More specifically on following line :
int n=SSL_shutdown(client->ssl);

Certificate has been generated like this :

$ openssl rsa -in privkey.pem > crt.pem    
$ openssl x509 -in cert.pem >> crt.pem

When commenting the webServer->setUseSSL(true, "crt.pem");, it works.

Cheers,

Crash when access the server through https

Hi,

The issue is related to WebServer::setUseSSL method.

If the certificate in the parameter to the method above is not signed by CA and you try to access the server through https in the browser the very first time, the message stating that "The owner of .... has configured their website improperly" appears in the web browser. In that same moment libnavajo crashes with "Broken pipe" exception. If you add security exception in the browser, and run the server again, it works fine.

That crash happens very consistently each time.

https://gyazo.com/cdeb802178501e3a2728798ca3facc17

Thanks for help!

Regards,
Dima.

Feature: DynamicPage HttpResponse send stream or file

Hello,

i try to send the binary data as a HttpResponse from a basic_stream (generated data) in cpp in a DynamicPage.
is there a simple way or must it convert it to a unsigned char *?

is there a simple way in Dynamic Pages to send Files?
I only found the upload not the (dynamic) download.

Thx for helping

No multithread support with SSL

Hello,
According to SSL documentation:

OpenSSL can generally be used safely in multi-threaded applications provided that at least two callback functions are set, the locking_function and threadid_func. Note that OpenSSL is not completely thread-safe, and unfortunately not all global resources have the necessary locks. Further, the thread-safety does not extend to things like multiple threads using the same SSL object at the same time.

I don't see such code for multithreading support in libnavajo.
Before i spend any time on fixing this, i would like to make sure we agree on that fact.

regards
Julien

Dynamic Repos

Sorry for this cuestion, maybe not an issue, part of my ignorance, but i can´t add a dynamic list of repos readed from a config file.

for (auto & path : statics) {
    		LocalRepository repo(config.get("www.statics."+ path + ".www",""), config.get("www.statics."+ path + ".path",""));
            webServer->addRepository(&repo);
 }

Im trying to add dynamic, pushing it to a vector and pass pointer to webserver:
quick and dirty:

std::vector<LocalRepository> repositories;

int i=0;
for (auto & path : statics) {
    		LocalRepository repo(config.get("www.statics."+ path + ".www",""), config.get("www.statics."+ path + ".path",""));
            repositories.push_back(repo);
            LocalRepository rarr = repositories.at(i);
    		webServer->addRepository(&rarr);
            i++;
}

Thanks and sorry

Segmentation fault with Websocket

Hi,
Sometimes when a client is disconnecting, I got a segmentation fault. I thought it was my program, but I'm not sure because GDB informs me that the segmentation fault is from a libnavajo file:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff6968700 (LWP 5245)] 0x0000003a72a788fb in _int_free () from /lib64/libc.so.6 (gdb) bt #0 0x0000003a72a788fb in _int_free () from /lib64/libc.so.6 #1 0x00000000004b56c8 in WebSocketClient::sendingThread (this=0x7fffd0000d40) at ~/Downloads/libnavajo-master/src/WebSocketClient.cc:65 #2 0x00000000004b6569 in WebSocketClient::startSendingThread (t=<value optimized out>) at ~/Downloads/libnavajo-master/include/libnavajo/WebSocketClient.hh:71 #3 0x0000003a72e07aa1 in start_thread () from /lib64/libpthread.so.0 #4 0x0000003a72ae8aad in clone () from /lib64/libc.so.6
Hope it can help

Valgrind report

I just create a simple libnavajo program to show you some issues foudn by valgrind, there are:

  • Memory leaks
  • Invalid write
  • Invalid read

Valgrind report:

==8915== Memcheck, a memory error detector
==8915== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8915== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==8915== Command: ./LibnavajoTest
==8915==
[2017-07-24 10:40:54] > WebServer: Service is starting !
New Websocket from host '10.1.38.22' - socketId=6
==8915== Thread 67:
==8915== Invalid write of size 1
==8915== at 0x41F663: WebSocketClient::receivingThread() (WebSocketClient.cc:242)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Address 0x4e3750b is 0 bytes after a block of size 11 alloc'd
==8915== at 0x4A073AC: realloc (vg_replace_malloc.c:784)
==8915== by 0x4215EE: nvj_gunzip_websocket_v2(unsigned char**, unsigned char const*, unsigned long, bool, unsigned char*, unsigned int*, unsigned int) (nvjGzip.h:331)
==8915== by 0x41F64F: WebSocketClient::receivingThread() (WebSocketClient.cc:237)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
Message: 'testMessage' received from host '10.1.38.22'
^C[2017-07-24 10:41:02] > WebServer: Service is stopping !
pthread_join(): Unknown error
==8915== Invalid write of size 1
==8915== at 0x41F28A: WebSocketClient::receivingThread() (WebSocketClient.cc:138)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Address 0x4dc6a10 is 33,072 bytes inside a block of size 33,104 free'd
==8915== at 0x4A0677A: operator delete(void*) (vg_replace_malloc.c:574)
==8915== by 0x420C75: WebSocketClient::closeWS() (WebSocketClient.cc:314)
==8915== by 0x40E650: removeAllClients (WebSocket.hh:231)
==8915== by 0x40E650: WebServer::exit() (WebServer.cc:1201)
==8915== by 0x4077F3: WebServer::stopService() (WebServer.hh:269)
==8915== by 0x4064F9: exitFunction(int) (main.cpp:11)
==8915== by 0x3B30E3250F: ??? (in /lib64/libc-2.12.so)
==8915== by 0x3B3120EC29: recv (in /lib64/libpthread-2.12.so)
==8915== by 0x41F273: WebSocketClient::receivingThread() (WebSocketClient.cc:133)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Block was alloc'd at
==8915== at 0x4A07DB5: operator new(unsigned long) (vg_replace_malloc.c:332)
==8915== by 0x416F30: newConnectionRequest (WebSocket.hh:214)
==8915== by 0x416F30: WebServer::accept_request(ClientSockData*, bool) (WebServer.cc:648)
==8915== by 0x417486: WebServer::poolThreadProcessing() (WebServer.cc:1431)
==8915== by 0x41D4D8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== Invalid read of size 1
==8915== at 0x41EF27: WebSocketClient::receivingThread() (WebSocketClient.cc:120)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Address 0x4dc6a10 is 33,072 bytes inside a block of size 33,104 free'd
==8915== at 0x4A0677A: operator delete(void*) (vg_replace_malloc.c:574)
==8915== by 0x420C75: WebSocketClient::closeWS() (WebSocketClient.cc:314)
==8915== by 0x40E650: removeAllClients (WebSocket.hh:231)
==8915== by 0x40E650: WebServer::exit() (WebServer.cc:1201)
==8915== by 0x4077F3: WebServer::stopService() (WebServer.hh:269)
==8915== by 0x4064F9: exitFunction(int) (main.cpp:11)
==8915== by 0x3B30E3250F: ??? (in /lib64/libc-2.12.so)
==8915== by 0x3B3120EC29: recv (in /lib64/libpthread-2.12.so)
==8915== by 0x41F273: WebSocketClient::receivingThread() (WebSocketClient.cc:133)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Block was alloc'd at
==8915== at 0x4A07DB5: operator new(unsigned long) (vg_replace_malloc.c:332)
==8915== by 0x416F30: newConnectionRequest (WebSocket.hh:214)
==8915== by 0x416F30: WebServer::accept_request(ClientSockData*, bool) (WebServer.cc:648)
==8915== by 0x417486: WebServer::poolThreadProcessing() (WebServer.cc:1431)
==8915== by 0x41D4D8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== Invalid read of size 1
==8915== at 0x41EF33: WebSocketClient::receivingThread() (WebSocketClient.cc:147)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Address 0x4dc6a10 is 33,072 bytes inside a block of size 33,104 free'd
==8915== at 0x4A0677A: operator delete(void*) (vg_replace_malloc.c:574)
==8915== by 0x420C75: WebSocketClient::closeWS() (WebSocketClient.cc:314)
==8915== by 0x40E650: removeAllClients (WebSocket.hh:231)
==8915== by 0x40E650: WebServer::exit() (WebServer.cc:1201)
==8915== by 0x4077F3: WebServer::stopService() (WebServer.hh:269)
==8915== by 0x4064F9: exitFunction(int) (main.cpp:11)
==8915== by 0x3B30E3250F: ??? (in /lib64/libc-2.12.so)
==8915== by 0x3B3120EC29: recv (in /lib64/libpthread-2.12.so)
==8915== by 0x41F273: WebSocketClient::receivingThread() (WebSocketClient.cc:133)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Block was alloc'd at
==8915== at 0x4A07DB5: operator new(unsigned long) (vg_replace_malloc.c:332)
==8915== by 0x416F30: newConnectionRequest (WebSocket.hh:214)
==8915== by 0x416F30: WebServer::accept_request(ClientSockData*, bool) (WebServer.cc:648)
==8915== by 0x417486: WebServer::poolThreadProcessing() (WebServer.cc:1431)
==8915== by 0x41D4D8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== Invalid read of size 1
==8915== at 0x41EEA0: WebSocketClient::receivingThread() (WebSocketClient.cc:108)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Address 0x4dc6a10 is 33,072 bytes inside a block of size 33,104 free'd
==8915== at 0x4A0677A: operator delete(void*) (vg_replace_malloc.c:574)
==8915== by 0x420C75: WebSocketClient::closeWS() (WebSocketClient.cc:314)
==8915== by 0x40E650: removeAllClients (WebSocket.hh:231)
==8915== by 0x40E650: WebServer::exit() (WebServer.cc:1201)
==8915== by 0x4077F3: WebServer::stopService() (WebServer.hh:269)
==8915== by 0x4064F9: exitFunction(int) (main.cpp:11)
==8915== by 0x3B30E3250F: ??? (in /lib64/libc-2.12.so)
==8915== by 0x3B3120EC29: recv (in /lib64/libpthread-2.12.so)
==8915== by 0x41F273: WebSocketClient::receivingThread() (WebSocketClient.cc:133)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915== Block was alloc'd at
==8915== at 0x4A07DB5: operator new(unsigned long) (vg_replace_malloc.c:332)
==8915== by 0x416F30: newConnectionRequest (WebSocket.hh:214)
==8915== by 0x416F30: WebServer::accept_request(ClientSockData*, bool) (WebServer.cc:648)
==8915== by 0x417486: WebServer::poolThreadProcessing() (WebServer.cc:1431)
==8915== by 0x41D4D8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915==
==8915== HEAP SUMMARY:
==8915== in use at exit: 40,992 bytes in 74 blocks
==8915== total heap usage: 356 allocs, 282 frees, 2,132,562 bytes allocated
==8915==
==8915== Thread 1:
==8915== 30 bytes in 1 blocks are definitely lost in loss record 4 of 11
==8915== at 0x4A071BA: malloc (vg_replace_malloc.c:298)
==8915== by 0x41D8CD: WebSocketClient::sendTextMessage(std::string const&, bool) (WebSocketClient.cc:440)
==8915== by 0x408117: WebSocket::sendBroadcastTextMessage(std::string const&, bool) (WebSocket.hh:120)
==8915== by 0x40837D: MyWebSocket::onTextMessage(WebSocketClient*, std::string const&, bool) (main.cpp:25)
==8915== by 0x41FA03: WebSocketClient::receivingThread() (WebSocketClient.cc:255)
==8915== by 0x421B48: WebSocketClient::startReceivingThread(void*) (WebSocketClient.hh:63)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== 608 bytes in 1 blocks are possibly lost in loss record 9 of 11
==8915== at 0x4A05F1F: calloc (vg_replace_malloc.c:710)
==8915== by 0x3B30611D02: _dl_allocate_tls (in /lib64/ld-2.12.so)
==8915== by 0x3B312072CC: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.12.so)
==8915== by 0x41E5EE: create_thread (nvjThread.h:63)
==8915== by 0x41E5EE: startWebSocketThreads (WebSocketClient.hh:78)
==8915== by 0x41E5EE: WebSocketClient::WebSocketClient(WebSocket*, HttpRequest*) (WebSocketClient.cc:33)
==8915== by 0x416F41: newConnectionRequest (WebSocket.hh:214)
==8915== by 0x416F41: WebServer::accept_request(ClientSockData*, bool) (WebServer.cc:648)
==8915== by 0x417486: WebServer::poolThreadProcessing() (WebServer.cc:1431)
==8915== by 0x41D4D8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== 38,912 bytes in 64 blocks are possibly lost in loss record 11 of 11
==8915== at 0x4A05F1F: calloc (vg_replace_malloc.c:710)
==8915== by 0x3B30611D02: _dl_allocate_tls (in /lib64/ld-2.12.so)
==8915== by 0x3B312072CC: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.12.so)
==8915== by 0x4073DE: create_thread(unsigned long*, void* ()(void), void*, bool, unsigned long) (nvjThread.h:63)
==8915== by 0x40E543: WebServer::initPoolThreads() (WebServer.cc:1447)
==8915== by 0x4127D3: WebServer::threadProcessing() (WebServer.cc:1486)
==8915== by 0x4131B8: WebServer::startThread(void*) (WebServer.cc:1463)
==8915== by 0x3B31207AA0: start_thread (in /lib64/libpthread-2.12.so)
==8915== by 0x3B30EE8BCC: clone (in /lib64/libc-2.12.so)
==8915==
==8915== LEAK SUMMARY:
==8915== definitely lost: 30 bytes in 1 blocks
==8915== indirectly lost: 0 bytes in 0 blocks
==8915== possibly lost: 39,520 bytes in 65 blocks
==8915== still reachable: 1,442 bytes in 8 blocks
==8915== of which reachable via heuristic:
==8915== stdstring : 58 bytes in 2 blocks
==8915== suppressed: 0 bytes in 0 blocks
==8915== Reachable blocks (those to which a pointer was found) are not shown.
==8915== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==8915==
==8915== For counts of detected and suppressed errors, rerun with: -v
==8915== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 8 from 5)

Program used:

#include <signal.h> 
#include <string.h> 
#include "libnavajo/libnavajo.hh"
#include "libnavajo/WebSocket.hh"
#include "libnavajo/LogStdOutput.hh"

WebServer *webServer = NULL;

void exitFunction( int )
{
  if (webServer != NULL) webServer->stopService();
}

class MyWebSocket : public WebSocket
{
  bool onOpening(HttpRequest* request)
  {
    printf ("New Websocket from host '%s' - socketId=%d\n", request->getPeerIpAddress().str().c_str(), request->getClientSockData()->socketId);
    return true;
  }

  void onTextMessage(WebSocketClient* client, const std::string &message, const bool)
  {
    printf ("Message: '%s' received from host '%s'\n", message.c_str(), client->getHttpRequest()->getPeerIpAddress().str().c_str());
    sendBroadcastTextMessage("The message has been received!");
  };
} myWebSocket;

class MyDynamicPage: public DynamicPage
{
  bool getPage(HttpRequest*, HttpResponse *response)
  {
    response->forwardTo("index.html");

    return true;
  }
};


int main()
{
  // connect signals
  signal( SIGTERM, exitFunction );
  signal( SIGINT, exitFunction );
  
  NVJ_LOG->addLogOutput(new LogStdOutput);

  webServer = new WebServer;

  webServer->setServerPort(8080);
  webServer->startService();

  webServer->addWebSocket("test", &myWebSocket);

  LocalRepository localRep("", "./html");

  MyDynamicPage page;
  DynamicRepository myRepo;
  myRepo.add("index.html", &page); // unusual html extension for a dynamic page !

  webServer->addRepository(&localRep);
  webServer->addRepository(&myRepo);

  webServer->wait();
  
  LogRecorder::freeInstance();
  return 0;
}

Test on Centos 6 with latest libnavajo code.

GCC 8.3.1 warnings

Hi,

I have corrected some warnings (see PR #36).
However there are still some worrisome warnings with gcc 8.3.1 (on Fedora 29):

[  8%] Building CXX object CMakeFiles/navajoStatic.dir/src/LogFile.cc.o
/home/mansenca/libnavajo/src/LogFile.cc: In constructor 'LogFile::LogFile(const char*)':
/home/mansenca/libnavajo/src/LogFile.cc:56:13: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 30 equals destination size [-Wstringop-truncation]
     strncpy (filename, f, 30);
     ~~~~~~~~^~~~~~~~~~~~~~~~~

and

[ 41%] Building CXX object CMakeFiles/navajoStatic.dir/src/WebSocketClient.cc.o
In file included from /home/mansenca/libnavajo/include/libnavajo/WebSocketClient.hh:21,
                 from /home/mansenca/libnavajo/include/libnavajo/WebSocket.hh:22,
                 from /home/mansenca/libnavajo/src/WebSocketClient.cc:17:
In function 'size_t nvj_gzip_websocket_v2(unsigned char**, const unsigned char*, size_t, z_stream*, unsigned int)',
    inlined from 'bool WebSocketClient::sendMessage(const WebSocketClient::MessageContent*)' at /home/mansenca/libnavajo/src/WebSocketClient.cc:382:35:
/home/mansenca/libnavajo/include/libnavajo/nvjGzip.h:218:58: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
     unsigned char* reallocDst = (unsigned char*) realloc (*dst, sizeDst * sizeof (unsigned char) );
                                                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mansenca/libnavajo/include/libnavajo/nvjGzip.h: In member function 'bool WebSocketClient::sendMessage(const WebSocketClient::MessageContent*)':
/home/mansenca/libnavajo/include/libnavajo/nvjGzip.h:218:58: note: in a call to built-in allocation function 'void* __builtin_malloc(long unsigned int)'

and

[ 95%] Building CXX object CMakeFiles/navajoPrecompiler.dir/src/navajoPrecompiler.cc.o
/home/mansenca/libnavajo/src/navajoPrecompiler.cc: In function 'char* str_replace_first(char*, const char*, const char*)':
/home/mansenca/libnavajo/src/navajoPrecompiler.cc:55:12: warning: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
     strncpy(p, by, len_by);
     ~~~~~~~^~~~~~~~~~~~~~~
/home/mansenca/libnavajo/src/navajoPrecompiler.cc:46:65: note: length computed here
     size_t len_p = strlen(p), len_s = strlen(s), len_by = strlen(by);
                                                           ~~~~~~^~~~

Compilation failing

/home/jouven/sources/git/titi38/libnavajo/src/WebServer.cc: In static member function ‘static int WebServer::verify_callback(int, X509_STORE_CTX*)’:
/home/jouven/sources/git/titi38/libnavajo/src/WebServer.cc:1251:46: error: invalid use of incomplete type ‘X509_STORE_CTX {aka struct x509_store_ctx_st}’
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256);
^~
In file included from /usr/include/openssl/crypto.h:31:0,
from /usr/include/openssl/comp.h:16,
from /usr/include/openssl/ssl.h:47,
from /home/jouven/sources/git/titi38/libnavajo/include/libnavajo/WebServer.hh:28,
from /home/jouven/sources/git/titi38/libnavajo/src/WebServer.cc:30:
/usr/include/openssl/ossl_typ.h:127:16: note: forward declaration of ‘X509_STORE_CTX {aka struct x509_store_ctx_st}’
typedef struct x509_store_ctx_st X509_STORE_CTX;
^~~~~~~~~~~~~~~~~

Seems openssl related. I'm on Debian testing (permanent testing).
My openssl version details https://packages.debian.org/testing/openssl

Can't build on Centos 7.6

[jcourtat@ns1 libnavajo] (master)$ mkdir build
[jcourtat@ns1 libnavajo] (master)$ cd build/
[jcourtat@ns1 build] (master)$ cmake3 ..
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- 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 OpenSSL: /usr/lib64/libcrypto.so (found version "1.0.2k")
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.7")
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.5") found components: doxygen dot
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jcourtat/dev/src/github.com/libnavajo/build
[jcourtat@ns1 build] (master)$ make
Scanning dependencies of target navajoPrecompiler
[ 4%] Building CXX object CMakeFiles/navajoPrecompiler.dir/src/navajoPrecompiler.cc.o
[ 8%] Linking CXX executable bin/navajoPrecompiler
[ 8%] Built target navajoPrecompiler
Scanning dependencies of target navajoStatic
[ 12%] Building CXX object CMakeFiles/navajoStatic.dir/src/LocalRepository.cc.o
In file included from /home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/WebRepository.hh:17:0,
from /home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/LocalRepository.hh:17,
from /home/jcourtat/dev/src/github.com/libnavajo/src/LocalRepository.cc:23:
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh: In member function ‘void HttpRequest::decodParams(const string&)’:
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:122:9: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
auto key = theParam.substr(0,posEq);
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:122:14: error: ‘key’ does not name a type
auto key = theParam.substr(0,posEq);
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:123:9: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
auto value = theParam.substr(posEq+1);
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:123:14: error: ‘value’ does not name a type
auto value = theParam.substr(posEq+1);
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:124:31: error: ‘key’ was not declared in this scope
if( parameters.count( key ) == 0 ) {
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:125:29: error: ‘value’ was not declared in this scope
parameters[key] = value;
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:127:11: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
auto arrayKey = key + "[]";
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:127:16: error: ‘arrayKey’ does not name a type
auto arrayKey = key + "[]";
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:128:33: error: ‘arrayKey’ was not declared in this scope
if( parameters.count( arrayKey ) == 1 ) {
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:129:43: error: ‘value’ was not declared in this scope
parameters[arrayKey] += "|" + value;
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:131:60: error: ‘value’ was not declared in this scope
parameters[arrayKey] = parameters[key] + "|" + value;
^
/home/jcourtat/dev/src/github.com/libnavajo/include/libnavajo/HttpRequest.hh:133:29: error: ‘value’ was not declared in this scope
parameters[key] = value;
^
make[2]: *** [CMakeFiles/navajoStatic.dir/src/LocalRepository.cc.o] Error 1
make[1]: *** [CMakeFiles/navajoStatic.dir/all] Error 2
make: *** [all] Error 2

OPTIONS support

In order to support CORS for most browsers it would be great if METHOD OPTIONS support were included. Otherwise the setCORS doesn't work with most modern browsers.

Thanks!

Http response error can't be different of 404

Hello,
thanks for you work on this library.
I don't see how to build a response with the error code i want and the content i want.
when i return false in the getPage() method, libnavajo automatically set HTTP error code to 404 and a default body with HTML is set in the body response.
Am i right ?
If this is the case, would you agree on a patch permitting such configuration ?

regards

Julien

make

hi,
I got an error when running make:
screenshot from 2015-12-15 03 58 56
any hint?

Fermeture du serveur

Bonjour, je suis étudiant a la faculté de bordeaux et je souhaite utilisé libnavajo dans le cadre d'un projet scolaire. Je développe sur Mac OS X El Capitan.

Je me permets de vous contacter car, j'ai un problème sur la fermeture du port utilisé par libnavajo, a chaque fermeture du serveur, je suis obligé de fermer le serveur avec un "kill -9 pid".

Existe-il dans le code, une fonction pour fermer directement le serveur sans avoir a utiliser de kill.

Big file on LocalRepository

Hi,

It seems that the class LocalRepository doesn't support large files (a .png of more than 10MB for example) on server with a little of latency. I have noticed that it works fine on local but not with a distant server.
The image began to load but stopped after a while and the server printed this trace :
[2017-03-26 15:05:33] > Webserver: httpSend failed sending the page: data/153610754_0_Displayed.png

memory leak when using SSL

Hello,

When i set a webserver with SSL, valgrinf reports there are memory leaks.

Here my patch on example 1
diff --git a/examples/1_basic/example.cc b/examples/1_basic/example.cc
index d7ca051..b0702ed 100644
--- a/examples/1_basic/example.cc
+++ b/examples/1_basic/example.cc
@@ -77,9 +77,9 @@ int main()
webServer = new WebServer;

webServer->setServerPort(8080);
-//webServer->setThreadsPoolSize(1);
+webServer->setThreadsPoolSize(4);
//uncomment to switch to https
-//webServer->setUseSSL(true, "mycert.pem");
+webServer->setUseSSL(true, "/home/jcourtat/myCert.pem");

//uncomment to active X509 auth
//webServer->setAuthPeerSSL(true, "cachain.pem");

And here is the valgrind command invocation:
valgrind --leak-check=yes ./example
==6583==
==6583== HEAP SUMMARY:
==6583== in use at exit: 97,511 bytes in 2,932 blocks
==6583== total heap usage: 7,277 allocs, 4,345 frees, 1,521,590 bytes allocated
==6583==
==6583== 2,432 bytes in 4 blocks are possibly lost in loss record 251 of 259
==6583== at 0x4C2A975: calloc (vg_replace_malloc.c:711)
==6583== by 0x4011F94: _dl_allocate_tls (in /usr/lib64/ld-2.17.so)
==6583== by 0x60FC960: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.17.so)
==6583== by 0x4050BC: create_thread(unsigned long*, void* ()(void), void*, bool, unsigned long) (in /home/jcourtat/dev/src/github.com/libnavajo/examples/1_basic/example)
==6583== by 0x4E43D43: WebServer::initPoolThreads() (WebServer.cc:1449)
==6583== by 0x4E46C83: WebServer::threadProcessing() (WebServer.cc:1488)
==6583== by 0x4E47AD8: WebServer::startThread(void*) (WebServer.cc:1465)
==6583== by 0x60FBDC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==6583== by 0x640776C: clone (in /usr/lib64/libc-2.17.so)
==6583==
==6583== 3,808 (1,568 direct, 2,240 indirect) bytes in 14 blocks are definitely lost in loss record 256 of 259
==6583== at 0x4C28BE3: malloc (vg_replace_malloc.c:299)
==6583== by 0x5552592: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1e)
==6583== by 0x55C2A2E: BIO_new (in /usr/lib64/libcrypto.so.1.0.1e)
==6583== by 0x4E4C0D7: WebServer::poolThreadProcessing() (WebServer.cc:1416)
==6583== by 0x4E529C8: WebServer::startPoolThread(void*) (WebServer.hh:71)
==6583== by 0x60FBDC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==6583== by 0x640776C: clone (in /usr/lib64/libc-2.17.so)
==6583==
==6583== LEAK SUMMARY:
==6583== definitely lost: 1,568 bytes in 14 blocks
==6583== indirectly lost: 2,240 bytes in 28 blocks
==6583== possibly lost: 2,432 bytes in 4 blocks
==6583== still reachable: 91,271 bytes in 2,886 blocks
==6583== of which reachable via heuristic:
==6583== stdstring : 119 bytes in 2 blocks
==6583== suppressed: 0 bytes in 0 blocks
==6583== Reachable blocks (those to which a pointer was found) are not shown.
==6583== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6583==
==6583== For counts of detected and suppressed errors, rerun with: -v
==6583== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

i created connection to the webserver this way:
curl -k https://127.0.0.1:8080

regards

Julien

More expansive "Allow" headers for CORS

It seems JQuery/Chrome is a little pushy. It wants Allow Headers and Allow Methods. I found adding

      header += "Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept-Encoding, Accept-Language\r\n";
      header += "Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS\r\n";

to WebServer.cc makes it happy.

libpam

Hi Thierry,

I updated to Ubuntu 16.04. I had to reinstall everything. When compiling libnavajo, It made me think that maybe you should update README with a section like Pre-requisite for installing libpam0g-dev (ubuntu)

$ sudo apt install libpam0g-dev

Hth.

Cheers,

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.