[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Question regarding HTTP basic auth example
From: |
Martin Velek |
Subject: |
Re: [libmicrohttpd] Question regarding HTTP basic auth example |
Date: |
Mon, 17 Feb 2014 15:23:11 +0100 |
Hi,
because this email is not an answer to Your question, please consider
it like a hint, not advice.
You are not obligated to return only MHD_YES in "if (NULL ==
*con_cls)". You may also return MHD_NO or even process the connection.
According to my stack trace,
Thread [12] 4230 [core: 1] (Suspended : Breakpoint)
AccessHandlerCallback() at http_server.c:303 0x43a281
call_connection_handler() at connection.c:1,303 0x43042a
MHD_connection_handle_idle() at connection.c:2,207 0x431baa
MHD_run_from_select() at daemon.c:1,814 0x43498c
MHD_select() at daemon.c:1,909 0x434e15
MHD_select_thread() at daemon.c:2,417 0x434e7e
rtos_mhd_thread_wrapper() at platform.h:168 0x4327a6
ITaskStartup() at rtos_pthread.c:228 0x40895c
start_thread() at pthread_create.c:308 0x7ffff76c0e9a
clone() at clone.S:112 0x7ffff70f83fd
<...more frames...>
the connection_handler is called after
MHD_CONNECTION_HEADERS_PROCESSED (the first call). At this time, the
*upload_data_size is equal to zero even if the TCP packet contains
data following (behind) the end mark of HTTP headers.
I am using this checking in my url handler:
// New connection?
if (NULL == *con_cls)
{
// Data should never be greater than zero because of first call.
assert((*upload_data_size) == 0);
// Default behavior for authentication is OK.
ret = MHD_YES;
// get username and password
user = MHD_basic_auth_get_username_password(connection, &pass);
// check if it is valid
if (false == credentials_check)
{
ret = generate_unauthorized_response(connection,
authentification_failed_size_,
(void *)authentification_failed_page_,
MHD_RESPMEM_PERSISTENT);
// Return value.
return ret;
}
else
{
*con_cls = Something;
}
}
// already authenticated ....
On Mon, Feb 17, 2014 at 2:13 PM, Sebastian Hammerl
<address@hidden> wrote:
> Hi,
>
> Am 17.02.2014 13:58, schrieb Christian Grothoff:
>
>> if (*upload_data_size > 0)
>> {
>> *upload_data_size = 0; // consume
>> return MHD_YES;
>> }
>
>
> that did it!
>
>
> Thank you very much,
> Sebastian
>