Hi Christian, 

You're right, I am walking through the URL to extract the keys and
values. 

I wrote this 5 years ago and I must have misunderstood the mechanism at
the time. I still don't quite understand why the strlen method fails for
escaped characters. 

I guess I need to rewrite it and call MHD_get_connection_values with a
callback to handle all possible name/value pairs. This sounds like a
better option than multiple calls to MHD_lookup_connection_value, as
there are lots of key/value pairs which are optionally present in the
API URL. 

Cheers 

David 

----------------------------------------------------------------------
>Hi David, 

>> I'm a bit confused as to how you are accessing the 'camname' field, or 
>> rather, how >you 'skip' to the next field. I suspect you're badly violating 
>> the API, but I'm not sure. 
> 
>> What it sounds to me like is that you're going after 'camname' by something 
>> like: 
> 
>> const char *camname = url[strlen(url)+1]; 
>> const char *camvalue = camname[strlen(camname)+1]; 
>> const char *nextname = camvalue[strlen(camvalue)+1]; // this fails ... 
>> const char *nextvalue = nextname[strlen(nextname)+1]; 
> 
>> where 'url' was the respective argument of the MHD_AccessHandlerCallback. 
>> That kind-of works, modulo escaping, as you can follow the key-value pairs 
>> by walking through memory like this if there is no escaping, but is 
>> excessively ugly and not actually guaranteed to work by MHD's API (it just 
>> happens to work...). 
> 
>> What you should be doing is using either the MHD_lookup_connection_value() 
>> or MHD_get_connection_values() functions: 
> 
>> const char *camvalue = MHD_lookup_connection_value (connection, 
>> MHD_GET_ARGUMENT_KIND, "camname"); 
>> const char *nextvalue = MHD_lookup_connection_value (connection, 
>> MHD_GET_ARGUMENT_KIND, "nextname"); 
> 
>> So are you actually using MHD_lookup_connection_value(), or walking 
>> illicitly over MHD's internal buffers? :-) Happy hacking! Christian On 
>> 09/22/2015 06:47 PM, address@hidden wrote: > 
> 
> ----------------------------------------------------------------------
> Hi there, 
>>>_ I've been using libmicrohttpd for a number of years now, but I have just_ 
>> _ found a basic problem with my URL parser when I receive a URL with_ >_ 
>> escaped characters. In my webpage I am using the javascript function,_ >_ 
>> encodeURIComponent() to help produce the escaped URL, something like this:-_ 
>>>_ setcamparam.cgi?camname=cam&fred, where "cam&fred" is the name string_ 
>>>_ This is converted into the following url_ > >_ 
>>>setcamparam.cgi?camname=cam%26fred_ > >_ which is fine._ > >_ The problem is 
>>>in my http_access_callback, when I receive this url, I_ >_ seem to receive 
>>>"cam&fred" unescaped, but the length of the field I need_ 
>> _ to skip in the url is 2 more than the string length. If there are more_ 
>> escaped characters in the url, then the difference is even higher.
>>> How do I know how many escaped characters have been unescaped so that I
>>_ can parse the url correctly and skip to the next field? I'm just using_ 
>> _ strlen() to skip over each field._ 
>>>_ Best regards_ 
>>>_ David_ 
>>>
 

Reply via email to