Skip to content

Commit 565a336

Browse files
author
Sebastiano Merlino
committed
Cleaned some code
Adjusted bug in Makfile.am regarding "ln -s" post-install hook
1 parent 672a62a commit 565a336

File tree

2 files changed

+30
-55
lines changed

2 files changed

+30
-55
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ libhttpserver_la_LIBADD = -lmicrohttpd
2727
libhttpserver_la_LDFLAGS =
2828

2929
install-exec-hook:
30-
(cd $(DESTDIR)$(includedir) && $(LN_S) httpserver.hpp httpserverpp)
30+
(cd $(DESTDIR)$(includedir) && $(LN_S) -f httpserver.hpp httpserverpp)
3131

3232
uninstall-hook:
3333
(cd $(DESTDIR)$(includedir) && rm -f httpserverpp)

src/Webserver.cpp

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -577,42 +577,13 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
577577
void* page;
578578
size_t size = 0;
579579
bool to_free = false;
580-
if((dws->registeredResources.count(endpoint) > 0))
581-
{
582-
#ifdef WITH_PYTHON
583-
PyGILState_STATE gstate;
584-
if(PyEval_ThreadsInitialized())
585-
{
586-
gstate = PyGILState_Ensure();
587-
}
588-
#endif
589-
dhrs = dws->registeredResources[endpoint]->routeRequest(supportReq);
590-
#ifdef WITH_PYTHON
591-
if(PyEval_ThreadsInitialized())
592-
{
593-
PyGILState_Release(gstate);
594-
}
595-
#endif
596-
if(dhrs.content != "")
597-
{
598-
vector<char> v_page(dhrs.content.begin(), dhrs.content.end());
599-
size = v_page.size();
600-
page = (void*) malloc(size*sizeof(char));
601-
memcpy( page, &v_page[0], sizeof( char ) * size );
602-
to_free = true;
603-
}
604-
else
605-
{
606-
page = (void*) "";
607-
}
608-
}
609-
else
580+
HttpEndpoint matchingEndpoint;
581+
if(!(dws->registeredResources.count(endpoint) > 0))
610582
{
611583
map<HttpEndpoint, HttpResource* >::iterator it;
612584
int len = -1;
613585
int tot_len = -1;
614586
bool found = false;
615-
HttpEndpoint matchingEndpoint;
616587
for(it=dws->registeredResources.begin(); it!=dws->registeredResources.end(); it++)
617588
{
618589
int endpoint_pieces_len = ((int)((*it).first.get_url_pieces().size()));
@@ -649,33 +620,37 @@ int Webserver::answerToConnection(void* cls, MHD_Connection* connection,
649620
{
650621
supportReq.setArg(url_pars[i], url_pieces[chunkes[i]]);
651622
}
623+
}
624+
}
625+
else
626+
{
627+
matchingEndpoint = dws->registeredResources[endpoint];
628+
}
652629
#ifdef WITH_PYTHON
653-
PyGILState_STATE gstate;
654-
if(PyEval_ThreadsInitialized())
655-
{
656-
gstate = PyGILState_Ensure();
657-
}
630+
PyGILState_STATE gstate;
631+
if(PyEval_ThreadsInitialized())
632+
{
633+
gstate = PyGILState_Ensure();
634+
}
658635
#endif
659-
dhrs = dws->registeredResources[matchingEndpoint]->routeRequest(supportReq);
636+
dhrs = dws->registeredResources[matchingEndpoint]->routeRequest(supportReq);
660637
#ifdef WITH_PYTHON
661-
if(PyEval_ThreadsInitialized())
662-
{
663-
PyGILState_Release(gstate);
664-
}
638+
if(PyEval_ThreadsInitialized())
639+
{
640+
PyGILState_Release(gstate);
641+
}
665642
#endif
666-
if(dhrs.content != "")
667-
{
668-
vector<char> v_page(dhrs.content.begin(), dhrs.content.end());
669-
size = v_page.size();
670-
page = (void*) malloc(size*sizeof(char));
671-
memcpy( page, &v_page[0], sizeof( char ) * size );
672-
to_free = true;
673-
}
674-
else
675-
{
676-
page = (void*)"";
677-
}
678-
}
643+
if(dhrs.content != "")
644+
{
645+
vector<char> v_page(dhrs.content.begin(), dhrs.content.end());
646+
size = v_page.size();
647+
page = (void*) malloc(size*sizeof(char));
648+
memcpy( page, &v_page[0], sizeof( char ) * size );
649+
to_free = true;
650+
}
651+
else
652+
{
653+
page = (void*)"";
679654
}
680655
if(dhrs.responseType == HttpResponse::FILE_CONTENT)
681656
{

0 commit comments

Comments
 (0)