comparison Core/HttpServer/MongooseServer.cpp @ 1571:3232f1c995a5

provide the origin of the requests to HTTP handlers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 11:04:19 +0200
parents 2bd2c280f9b5
children f8aae45011c9
comparison
equal deleted inserted replaced
1570:2bd2c280f9b5 1571:3232f1c995a5
632 return; 632 return;
633 } 633 }
634 634
635 635
636 // Apply the filter, if it is installed 636 // Apply the filter, if it is installed
637 char remoteIp[24];
638 sprintf(remoteIp, "%d.%d.%d.%d",
639 reinterpret_cast<const uint8_t*>(&request->remote_ip) [3],
640 reinterpret_cast<const uint8_t*>(&request->remote_ip) [2],
641 reinterpret_cast<const uint8_t*>(&request->remote_ip) [1],
642 reinterpret_cast<const uint8_t*>(&request->remote_ip) [0]);
643
644 std::string username = GetAuthenticatedUsername(headers);
645
637 const IIncomingHttpRequestFilter *filter = that->GetIncomingHttpRequestFilter(); 646 const IIncomingHttpRequestFilter *filter = that->GetIncomingHttpRequestFilter();
638 if (filter != NULL) 647 if (filter != NULL)
639 { 648 {
640 std::string username = GetAuthenticatedUsername(headers);
641
642 char remoteIp[24];
643 sprintf(remoteIp, "%d.%d.%d.%d",
644 reinterpret_cast<const uint8_t*>(&request->remote_ip) [3],
645 reinterpret_cast<const uint8_t*>(&request->remote_ip) [2],
646 reinterpret_cast<const uint8_t*>(&request->remote_ip) [1],
647 reinterpret_cast<const uint8_t*>(&request->remote_ip) [0]);
648
649 if (!filter->IsAllowed(method, request->uri, remoteIp, username.c_str())) 649 if (!filter->IsAllowed(method, request->uri, remoteIp, username.c_str()))
650 { 650 {
651 output.SendUnauthorized(ORTHANC_REALM); 651 output.SendUnauthorized(ORTHANC_REALM);
652 return; 652 return;
653 } 653 }
726 726
727 try 727 try
728 { 728 {
729 if (that->HasHandler()) 729 if (that->HasHandler())
730 { 730 {
731 found = that->GetHandler().Handle(output, method, uri, headers, argumentsGET, body.c_str(), body.size()); 731 found = that->GetHandler().Handle(output, RequestOrigin_Http, remoteIp, username.c_str(),
732 method, uri, headers, argumentsGET, body.c_str(), body.size());
732 } 733 }
733 } 734 }
734 catch (boost::bad_lexical_cast&) 735 catch (boost::bad_lexical_cast&)
735 { 736 {
736 throw OrthancException(ErrorCode_BadParameterType); 737 throw OrthancException(ErrorCode_BadParameterType);