Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 16 additions & 31 deletions xbmc/network/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ static MHD_Response* create_response(size_t size, void* data, int free, int copy
#endif
}

int CWebServer::AskForAuthentication(struct MHD_Connection *connection)
MHD_Result CWebServer::AskForAuthentication(struct MHD_Connection *connection)
{
int ret;
MHD_Result ret;
struct MHD_Response *response;

response = create_response (0, NULL, MHD_NO, MHD_NO);
Expand All @@ -99,8 +99,7 @@ int CWebServer::AskForAuthentication(struct MHD_Connection *connection)
return MHD_NO;
}

ret = MHD_add_response_header(response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic realm=XBMC");
ret |= MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close");
ret = MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need "Basic realm=XBMC" header?

if (!ret)
{
CLog::Log(LOGERROR, "CWebServer: unable to prepare HTTP Unauthorized response");
Expand Down Expand Up @@ -131,17 +130,10 @@ bool CWebServer::IsAuthenticated(CWebServer *server, struct MHD_Connection *conn
return (server->m_Credentials64Encoded.compare(headervalue + strlen(strbase)) == 0);
}

#if (MHD_VERSION >= 0x00040001)
int CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection,
MHD_Result CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection,
const char *url, const char *method,
const char *version, const char *upload_data,
size_t *upload_data_size, void **con_cls)
#else
int CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection,
const char *url, const char *method,
const char *version, const char *upload_data,
unsigned int *upload_data_size, void **con_cls)
#endif
{
if (cls == NULL || con_cls == NULL)
{
Expand Down Expand Up @@ -254,7 +246,7 @@ int CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection,
MHD_destroy_post_processor(conHandler->postprocessor);
*con_cls = NULL;

int ret = HandleRequest(conHandler->requestHandler, request);
MHD_Result ret = HandleRequest(conHandler->requestHandler, request);
delete conHandler;
return ret;
}
Expand All @@ -277,17 +269,10 @@ int CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection,
return SendErrorResponse(connection, MHD_HTTP_NOT_FOUND, methodType);
}

#if (MHD_VERSION >= 0x00040001)
int CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
MHD_Result CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
const char *filename, const char *content_type,
const char *transfer_encoding, const char *data, uint64_t off,
size_t size)
#else
int CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
const char *filename, const char *content_type,
const char *transfer_encoding, const char *data, uint64_t off,
unsigned int size)
#endif
{
ConnectionHandler *conHandler = (ConnectionHandler *)cls;

Expand All @@ -302,7 +287,7 @@ int CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char *
return MHD_YES;
}

int CWebServer::HandleRequest(IHTTPRequestHandler *handler, const HTTPRequest &request)
MHD_Result CWebServer::HandleRequest(IHTTPRequestHandler *handler, const HTTPRequest &request)
{
if (handler == NULL)
return SendErrorResponse(request.connection, MHD_HTTP_INTERNAL_SERVER_ERROR, request.method);
Expand Down Expand Up @@ -511,7 +496,7 @@ int CWebServer::CreateFileDownloadResponse(struct MHD_Connection *connection, co
return MHD_YES;
}

int CWebServer::CreateErrorResponse(struct MHD_Connection *connection, int responseType, HTTPMethod method, struct MHD_Response *&response)
MHD_Result CWebServer::CreateErrorResponse(struct MHD_Connection *connection, int responseType, HTTPMethod method, struct MHD_Response *&response)
{
size_t payloadSize = 0;
void *payload = NULL;
Expand Down Expand Up @@ -553,10 +538,10 @@ int CWebServer::CreateMemoryDownloadResponse(struct MHD_Connection *connection,
return MHD_YES;
}

int CWebServer::SendErrorResponse(struct MHD_Connection *connection, int errorType, HTTPMethod method)
MHD_Result CWebServer::SendErrorResponse(struct MHD_Connection *connection, int errorType, HTTPMethod method)
{
struct MHD_Response *response = NULL;
int ret = CreateErrorResponse(connection, errorType, method, response);
MHD_Result ret = CreateErrorResponse(connection, errorType, method, response);
if (ret == MHD_YES)
{
ret = MHD_queue_response (connection, errorType, response);
Expand Down Expand Up @@ -809,20 +794,20 @@ std::string CWebServer::GetRequestHeaderValue(struct MHD_Connection *connection,
return value;
}

int CWebServer::GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::map<std::string, std::string> &headerValues)
MHD_Result CWebServer::GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::map<std::string, std::string> &headerValues)
{
if (connection == NULL)
return -1;
return MHD_NO;

return MHD_get_connection_values(connection, kind, FillArgumentMap, &headerValues);
return MHD_YES;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see headerValues being populated any more. This looks like a bug

}

int CWebServer::GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::multimap<std::string, std::string> &headerValues)
MHD_Result CWebServer::GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::multimap<std::string, std::string> &headerValues)
{
if (connection == NULL)
return -1;
return MHD_NO;

return MHD_get_connection_values(connection, kind, FillArgumentMultiMap, &headerValues);
return MHD_YES;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: I don't see headerValues being populated

}

const char *CWebServer::CreateMimeTypeFromExtension(const char *ext)
Expand Down
28 changes: 9 additions & 19 deletions xbmc/network/WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class CWebServer : public JSONRPC::ITransportLayer
static void UnregisterRequestHandler(IHTTPRequestHandler *handler);

static std::string GetRequestHeaderValue(struct MHD_Connection *connection, enum MHD_ValueKind kind, const std::string &key);
static int GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::map<std::string, std::string> &headerValues);
static int GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::multimap<std::string, std::string> &headerValues);
static MHD_Result GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::map<std::string, std::string> &headerValues);
static MHD_Result GetRequestHeaderValues(struct MHD_Connection *connection, enum MHD_ValueKind kind, std::multimap<std::string, std::string> &headerValues);
private:
struct MHD_Daemon* StartMHD(unsigned int flags, int port);
static int AskForAuthentication (struct MHD_Connection *connection);
static MHD_Result AskForAuthentication (struct MHD_Connection *connection);
static bool IsAuthenticated (CWebServer *server, struct MHD_Connection *connection);

static void* UriRequestLogger(void *cls, const char *uri);
Expand All @@ -69,33 +69,23 @@ class CWebServer : public JSONRPC::ITransportLayer
static int ContentReaderCallback (void *cls, size_t pos, char *buf, int max);
#endif

#if (MHD_VERSION >= 0x00040001)
static int AnswerToConnection (void *cls, struct MHD_Connection *connection,
static MHD_Result AnswerToConnection (void *cls, struct MHD_Connection *connection,
const char *url, const char *method,
const char *version, const char *upload_data,
size_t *upload_data_size, void **con_cls);
static int HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
static MHD_Result HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
const char *filename, const char *content_type,
const char *transfer_encoding, const char *data, uint64_t off,
size_t size);
#else //libmicrohttpd < 0.4.0
static int AnswerToConnection (void *cls, struct MHD_Connection *connection,
const char *url, const char *method,
const char *version, const char *upload_data,
unsigned int *upload_data_size, void **con_cls);
static int HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
const char *filename, const char *content_type,
const char *transfer_encoding, const char *data, uint64_t off,
unsigned int size);
#endif
static int HandleRequest(IHTTPRequestHandler *handler, const HTTPRequest &request);

static MHD_Result HandleRequest(IHTTPRequestHandler *handler, const HTTPRequest &request);
static void ContentReaderFreeCallback (void *cls);
static int CreateRedirect(struct MHD_Connection *connection, const std::string &strURL, struct MHD_Response *&response);
static int CreateFileDownloadResponse(struct MHD_Connection *connection, const std::string &strURL, HTTPMethod methodType, struct MHD_Response *&response, int &responseCode);
static int CreateErrorResponse(struct MHD_Connection *connection, int responseType, HTTPMethod method, struct MHD_Response *&response);
static MHD_Result CreateErrorResponse(struct MHD_Connection *connection, int responseType, HTTPMethod method, struct MHD_Response *&response);
static int CreateMemoryDownloadResponse(struct MHD_Connection *connection, void *data, size_t size, bool free, bool copy, struct MHD_Response *&response);

static int SendErrorResponse(struct MHD_Connection *connection, int errorType, HTTPMethod method);
static MHD_Result SendErrorResponse(struct MHD_Connection *connection, int errorType, HTTPMethod method);

static HTTPMethod GetMethod(const char *method);
static int FillArgumentMap(void *cls, enum MHD_ValueKind kind, const char *key, const char *value);
Expand Down