Skip to content

Commit 76ee988

Browse files
author
Sebastiano Merlino
committed
Conflicts: .travis.yml
2 parents 2cfc155 + 9f15463 commit 76ee988

File tree

14 files changed

+511
-634
lines changed

14 files changed

+511
-634
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ compiler: gcc
33
# Change this to your needs
44
before_install:
55
- sudo apt-get install texinfo
6-
- wget http://199.231.187.83/resources/libmicrohttpd-0.9.20.tar.gz
7-
- tar -xvzf libmicrohttpd-0.9.20.tar.gz
8-
- cd libmicrohttpd-0.9.20
6+
- wget http://199.231.187.83/resources/libmicrohttpd-0.9.26.tar.gz
7+
- tar -xvzf libmicrohttpd-0.9.26.tar.gz
8+
- cd libmicrohttpd-0.9.26
99
- ./configure --prefix=/usr
1010
- make
1111
- sudo make install

README

Lines changed: 0 additions & 49 deletions
This file was deleted.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
================================= libhttpserver ===================================
2+
3+
When you see this tree, know that you've came across ZenCoders.org
4+
5+
with open('ZenCoders.
6+
`num` in numbers synchronized
7+
datetime d glob. sys.argv[2] .
8+
def myclass `..` @@oscla org. . class {
9+
displ hooks( public static void ma functor:
10+
$myclass->method( impport sys, os.pipe ` @param name`
11+
fcl if(system(cmd) myc. /de ` $card( array("a" srand
12+
format lists: ++: conc ++ "my an WHERE for( == myi
13+
`sys: myvalue(myvalue) sys.t Console.W try{ rais using
14+
connec SELECT * FROM table mycnf acco desc and or selector::clas at
15+
openldap string sys. print "zenc der " { 'a': `ls -l` > appe &firs
16+
import Tkinter paste( $obh &a or it myval bro roll: :: [] require a
17+
case `` super. +y <svg x="100"> expr say " %rooms 1 --account fb- yy
18+
proc meth Animate => send(D, open) putd EndIf 10 whi myc` cont
19+
and main (--) import loop $$ or end onload UNION WITH tab timer 150 *2
20+
end. begin True GtkLabel *label doto partition te let auto i<- (i + d );
21+
.mushup ``/. ^/zenc/ myclass->her flv op <> element >> 71 or
22+
QFileDi : and .. with myc toA channel::bo myc isEmpty a not bodt;
23+
class T public pol str mycalc d pt &&a *i fc add ^ac
24+
::ZenCoders::core::namespac boost::function st f = std: ;; int assert
25+
cout << endl public genera #include "b ost ::ac myna const cast<char*> mys
26+
ac size_t return ran int (*getNextValue)(void) ff double sa_family_t famil
27+
pu a do puts(" ac int main(int argc, char* "%5d struct nam
28+
cs float for typedef enum puts getchar()
29+
if( else #define fp FILE* f char* s
30+
i++ strcat( %s int
31+
31] total+= do
32+
}do while(1) sle
33+
getc strcpy( a for
34+
prin scanf(%d, & get
35+
int void myfunc(int pa retu
36+
BEQ BNEQZ R1 10 ANDI R1 R2 SYS
37+
XOR SYSCALL 5 SLTIU MFLO 15 SW JAL
38+
BNE BLTZAL R1 1 LUI 001 NOOP MULTU SLLV
39+
MOV R1 ADD R1 R2 JUMP 10 1001 BEQ R1 R2 1 ANDI
40+
1101 1010001100 111 001 01 1010 101100 1001 100
41+
110110 100 0 01 101 01100 100 100 1000100011
42+
11101001001 00 11 100 11 10100010
43+
000101001001 10 1001 101000101
44+
010010010010110101001010
45+
46+
For further information:
47+
visit our website www.zencoders.org
48+
49+
Author: Sebastiano Merlino
50+
51+
[![Build Status](https://travis-ci.org/etr/libhttpserver.png?branch=master)](https://travis-ci.org/etr/libhttpserver)

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ AC_PROG_CXX
3737
AC_PROG_LN_S
3838
CXXFLAGS=$OLD_CXXFLAGS
3939
AC_LANG([C++])
40+
AC_SYS_LARGEFILE
4041

4142
if test "`cd $srcdir; /bin/pwd`" = "`/bin/pwd`"; then
4243
AC_MSG_ERROR("you must configure in a separate build directory")

examples/Test.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ void Test::render_GET(const http_request& r, http_response** res)
3939
for(std::map<std::string, std::string, header_comparator>::const_iterator it = head.begin(); it != head.end(); ++it)
4040
cout << (*it).first << "-> " << (*it).second << endl;
4141
string pp = r.get_arg("prova"); */
42-
std::vector<std::string> topics;
43-
topics.push_back("prova");
44-
//return long_polling_receive_response("", 200, "", topics, 10, "keepalive\n");
42+
43+
/*
4544
cout << r.get_querystring() << endl;
4645
*res = new http_file_response("/home/etr/progs/libhttpserver/test/noimg.png", 200, "image/png");
46+
*/
47+
48+
std::vector<std::string> topics;
49+
topics.push_back("prova");
50+
*res = new long_polling_receive_response("", 200, "", topics, false, 10, "keepalive\n");
4751
}
4852

4953
void Test::render_POST(const http_request& r, http_response** res)
@@ -59,13 +63,17 @@ void Test::render_POST(const http_request& r, http_response** res)
5963
cout << vv[i] << endl;
6064
}
6165
return http_string_response("OK",200);*/
66+
67+
/*
6268
http_string_response* s = new http_string_response("OK",100);
6369
s->set_header(http_utils::http_header_location, "B");
6470
s->set_cookie("Ciccio", "Puppo");
6571
s->set_cookie("Peppe", "Puppo");
6672
cout << s->get_cookie("Ciccio") << endl;
6773
*res = s;
68-
// return long_polling_send_response("<script type=\"text/javascript\">alert(\"ciao\")</script>\n", "prova");
74+
*/
75+
76+
*res = new long_polling_send_response("hi!!!!\n", "prova");
6977
}
7078

7179
void Test2::render_GET(const http_request& r, http_response** res)
@@ -88,7 +96,7 @@ void Test::render_PUT(const http_request& r, http_response** res)
8896
int main()
8997
{
9098
// signal(SIGINT, &signal_callback_handler);
91-
webserver ws = create_webserver(8080).max_threads(5);
99+
webserver ws = create_webserver(8080)/*.max_threads(5)*/;
92100
ws_ptr = &ws;
93101
Test dt = Test();
94102
Test2 dt2 = Test2();

examples/hello_world.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
#include <httpserver.hpp>
2+
#include <iostream>
23

34
using namespace httpserver;
45

56
class hello_world_resource : public http_resource<hello_world_resource> {
67
public:
78
void render(const http_request&, http_response**);
9+
void set_some_data(const std::string &s) {data = s;}
10+
std::string data;
811
};
912

1013
//using the render method you are able to catch each type of request you receive
1114
void hello_world_resource::render(const http_request& req, http_response** res)
1215
{
16+
//it is possible to store data inside the resource object that can be altered
17+
//through the requests
18+
std::cout << "Data was: " << data << std::endl;
19+
std::string datapar = req.get_arg("data");
20+
set_some_data(datapar == "" ? "no data passed!!!" : datapar);
21+
std::cout << "Now data is:" << data << std::endl;
22+
1323
//it is possible to send a response initializing an http_string_response
1424
//that reads the content to send in response from a string.
1525
*res = new http_string_response("Hello World!!!", 200);

src/http_response.cpp

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
1515
You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818
USA
1919
*/
2020

2121
#include <cstdio>
2222
#include <functional>
2323
#include <iostream>
2424
#include <sstream>
25+
#include <fcntl.h>
26+
#include <unistd.h>
2527
#include "http_utils.hpp"
2628
#include "webserver.hpp"
2729
#include "http_response.hpp"
@@ -155,20 +157,20 @@ void http_response::get_raw_response_file(
155157
webserver* ws
156158
)
157159
{
158-
char* page = NULL;
159-
size_t size = http::load_file(filename.c_str(), &page);
160+
int fd = open(filename.c_str(), O_RDONLY);
161+
size_t size = lseek(fd, 0, SEEK_END);
160162
if(size)
161-
*response = MHD_create_response_from_buffer(
162-
size,
163-
page,
164-
MHD_RESPMEM_MUST_FREE
165-
);
163+
{
164+
*response = MHD_create_response_from_fd(size, fd);
165+
}
166166
else
167+
{
167168
*response = MHD_create_response_from_buffer(
168-
size,
169+
0,
169170
(void*) "",
170171
MHD_RESPMEM_PERSISTENT
171172
);
173+
}
172174
}
173175

174176
void http_response::get_raw_response_cache(
@@ -184,7 +186,7 @@ void http_response::get_raw_response_cache(
184186
webserver::get_response(ce, &r);
185187
r->get_raw_response(response, ws);
186188
r->decorate_response(*response); //It is done here to avoid to search two times for the same element
187-
189+
188190
//TODO: Check if element is not in cache and throw exception
189191
}
190192

@@ -229,13 +231,11 @@ void http_response::get_raw_response_lp_receive(
229231
webserver* ws
230232
)
231233
{
232-
233-
#ifdef USE_COMET
234234
this->ws = ws;
235235
this->connection_id = MHD_get_connection_info(
236236
this->underlying_connection,
237-
MHD_CONNECTION_INFO_FD
238-
)->socket_fd;
237+
MHD_CONNECTION_INFO_CLIENT_ADDRESS
238+
)->client_addr;
239239

240240
*response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 80,
241241
&long_polling_receive_response::data_generator, (void*) this, NULL);
@@ -246,13 +246,6 @@ void http_response::get_raw_response_lp_receive(
246246
keepalive_secs,
247247
keepalive_msg
248248
);
249-
250-
#else //USE_COMET
251-
252-
http_response::get_raw_response(response, ws);
253-
254-
#endif //USE_COMET
255-
256249
}
257250

258251
ssize_t long_polling_receive_response::data_generator(
@@ -262,8 +255,7 @@ ssize_t long_polling_receive_response::data_generator(
262255
size_t max
263256
)
264257
{
265-
#ifdef USE_COMET
266-
long_polling_receive_response* _this =
258+
long_polling_receive_response* _this =
267259
static_cast<long_polling_receive_response*>(cls);
268260

269261
if(_this->ws->pop_signaled(_this->connection_id))
@@ -275,20 +267,15 @@ ssize_t long_polling_receive_response::data_generator(
275267
}
276268
else
277269
return 0;
278-
#else //USE_COMET
279-
return 0;
280-
#endif //USE_COMET
281270
}
282271

283272
void http_response::get_raw_response_lp_send(
284273
MHD_Response** response,
285274
webserver* ws
286275
)
287276
{
288-
http_response::get_raw_response(response, ws);
289-
#ifdef USE_COMET
277+
http_response::get_raw_response_str(response, ws);
290278
ws->send_message_to_topic(send_topic, content);
291-
#endif //USE_COMET
292279
}
293280

294281
};

0 commit comments

Comments
 (0)