Skip to content

Commit 3b1b9c6

Browse files
author
Sebastiano Merlino
committed
Removed functions used to access to cache entries attribute from outside
The functions have been moved to the webserver class in order to enhance the protection level
1 parent c587f38 commit 3b1b9c6

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

src/http_response.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ using namespace std;
3030
namespace httpserver
3131
{
3232

33-
void unlock_on_close::do_action()
34-
{
35-
details::unlock_cache_entry(elem);
36-
}
37-
3833
cache_response::~cache_response()
3934
{
4035
if(ce != 0x0)
41-
details::unlock_cache_entry(ce);
36+
webserver::unlock_cache_entry(ce);
4237
}
4338

4439
const std::vector<std::pair<std::string, std::string> > http_response::get_headers()
@@ -169,7 +164,7 @@ void cache_response::get_raw_response(MHD_Response** response, webserver* ws)
169164
if(ce == 0x0)
170165
r = ws->get_from_cache(content, &valid, &ce, true, false);
171166
else
172-
details::get_response(ce, &r);
167+
webserver::get_response(ce, &r);
173168
r->get_raw_response(response, ws);
174169
r->decorate_response(*response); //It is done here to avoid to search two times for the same element
175170

src/httpserver/http_response.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,6 @@ class closure_action
8181
friend class http_response;
8282
};
8383

84-
class unlock_on_close : public closure_action
85-
{
86-
public:
87-
unlock_on_close(cache_entry* elem, bool deletable = true) : closure_action(deletable), elem(elem) { }
88-
unlock_on_close(const unlock_on_close& b) : closure_action(elem), elem(b.elem) { }
89-
unlock_on_close& operator = (const unlock_on_close& b)
90-
{
91-
elem = b.elem;
92-
return *this;
93-
}
94-
virtual void do_action();
95-
private:
96-
cache_entry* elem;
97-
};
98-
9984
/**
10085
* Class representing an abstraction for an Http Response. It is used from classes using these apis to send information through http protocol.
10186
**/

src/httpserver/webserver.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ namespace details
6363
struct modded_request;
6464
struct cache_manager;
6565
struct daemon_item;
66-
void unlock_cache_entry(cache_entry*);
67-
void lock_cache_entry(cache_entry*);
68-
void get_response(cache_entry*, http_response** res);
6966
}
7067

7168
using namespace http;
@@ -402,6 +399,10 @@ class webserver
402399
void **con_cls, int upgrade_socket
403400
);
404401

402+
static void unlock_cache_entry(cache_entry*);
403+
static void lock_cache_entry(cache_entry*);
404+
static void get_response(cache_entry*, http_response** res);
405+
405406
int bodyless_requests_answer(MHD_Connection* connection,
406407
const char* url, const char* method,
407408
const char* version, struct details::modded_request* mr

src/webserver.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -284,26 +284,6 @@ struct cache_entry
284284
}
285285
};
286286

287-
namespace details
288-
{
289-
290-
void unlock_cache_entry(cache_entry* ce)
291-
{
292-
ce->unlock();
293-
}
294-
295-
void lock_cache_entry(cache_entry* ce)
296-
{
297-
ce->lock();
298-
}
299-
300-
void get_response(cache_entry* ce, http_response** res)
301-
{
302-
*res = ce->response.ptr();
303-
}
304-
305-
};
306-
307287
using namespace http;
308288

309289
int policy_callback (void *, const struct sockaddr*, socklen_t);
@@ -1888,4 +1868,19 @@ void webserver::clean_cache()
18881868
pthread_rwlock_unlock(&cache_guard);
18891869
}
18901870

1871+
void webserver::unlock_cache_entry(cache_entry* ce)
1872+
{
1873+
ce->unlock();
1874+
}
1875+
1876+
void webserver::lock_cache_entry(cache_entry* ce)
1877+
{
1878+
ce->lock();
1879+
}
1880+
1881+
void webserver::get_response(cache_entry* ce, http_response** res)
1882+
{
1883+
*res = ce->response.ptr();
1884+
}
1885+
18911886
};

0 commit comments

Comments
 (0)