@@ -57,7 +57,9 @@ class http_response
5757 SHOUTCAST_CONTENT,
5858 DIGEST_AUTH_FAIL,
5959 BASIC_AUTH_FAIL,
60- SWITCH_PROTOCOL
60+ SWITCH_PROTOCOL,
61+ LONG_POLLING_RECEIVE,
62+ LONG_POLLING_SEND
6163 };
6264
6365 /* *
@@ -74,7 +76,8 @@ class http_response
7476 const std::string& content_type = " text/plain" ,
7577 const std::string& realm = " " ,
7678 const std::string& opaque = " " ,
77- bool reload_nonce = false
79+ bool reload_nonce = false ,
80+ const std::string& topic = " "
7881 ):
7982 response_type (response_type),
8083 content (content),
@@ -83,7 +86,8 @@ class http_response
8386 opaque (opaque),
8487 reload_nonce (reload_nonce),
8588 fp (-1 ),
86- filename (content)
89+ filename (content),
90+ topic (topic)
8791 {
8892 set_header (http_utils::http_header_content_type, content_type);
8993 }
@@ -101,7 +105,8 @@ class http_response
101105 fp (b.fp),
102106 filename (b.filename),
103107 headers (b.headers),
104- footers (b.footers)
108+ footers (b.footers),
109+ topic (b.topic)
105110 {
106111 }
107112 virtual ~http_response ()
@@ -265,6 +270,10 @@ class http_response
265270 {
266271 return 0 ;
267272 }
273+ const std::string get_topic () const
274+ {
275+ return this ->topic ;
276+ }
268277 protected:
269278 response_type_T response_type;
270279 std::string content;
@@ -276,8 +285,9 @@ class http_response
276285 std::string filename;
277286 std::map<std::string, std::string, header_comparator> headers;
278287 std::map<std::string, std::string, header_comparator> footers;
288+ std::string topic;
279289
280- virtual void get_raw_response (MHD_Response** res, bool * found);
290+ virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
281291
282292 friend class webserver ;
283293 friend void clone_response (const http_response& hr, http_response** dhr);
@@ -310,7 +320,7 @@ class http_file_response : public http_response
310320
311321 http_file_response (const http_response& b) : http_response(b) { }
312322 protected:
313- virtual void get_raw_response (MHD_Response** res, bool * found);
323+ virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
314324};
315325
316326class http_basic_auth_fail_response : public http_response
@@ -372,9 +382,44 @@ class switch_protocol_response : public http_response
372382 {
373383 }
374384 protected:
375- virtual void get_raw_response (MHD_Response** res, bool * found)
385+ virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 ) {}
386+ };
387+
388+ class long_polling_receive_response : public http_response
389+ {
390+ public:
391+ long_polling_receive_response
392+ (
393+ const std::string& content,
394+ int response_code,
395+ const std::string& content_type,
396+ const std::string& topic
397+ ) : http_response(http_response::LONG_POLLING_RECEIVE, content, response_code, content_type, " " , " " , false , topic)
398+ {
399+ }
400+
401+ long_polling_receive_response (const http_response& b) : http_response(b) { }
402+ protected:
403+ virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
404+ private:
405+ static ssize_t data_generator (void * cls, uint64_t pos, char * buf, size_t max);
406+ static void free_callback (void * cls);
407+ };
408+
409+ class long_polling_send_response : public http_response
410+ {
411+ public:
412+ long_polling_send_response
413+ (
414+ const std::string& content,
415+ const std::string& topic
416+ ) : http_response(http_response::LONG_POLLING_SEND, content, 200 , " " , " " , " " , false , topic)
376417 {
377418 }
419+
420+ long_polling_send_response (const http_response& b) : http_response(b) { }
421+ protected:
422+ virtual void get_raw_response (MHD_Response** res, bool * found, webserver* ws = 0x0 );
378423};
379424
380425void clone_response (http_response* hr, http_response** dhr);
0 commit comments