# mco_lews_url_param_decode
RT

### Prototype

        MCO_RET mco_lews_url_param_decode(
            char *in_str,
            mco_size_t in_size,
            char *out_str,
            mco_size_t out_size
        );

### Arguments

`in_str`
Pointer to the null-terminated or length-delimited input string containing URL-encoded data (e.g., `"bar%20foo"`).
`in_size`
Size (in bytes) of the input buffer. If the string is null-terminated, this should include the terminator only if it is part of the data to be processed.
`out_str`
Pointer to the output buffer where the decoded string will be stored.
`out_size`
Size (in bytes) of the output buffer, including space for the null terminator.

### Description

> This function decodes a URL-encoded (percent-encoded) string according to RFC 3986.

> It scans the input for sequences of the form `%XX`, where `XX` is a two-digit hexadecimal number, and replaces each such sequence with the corresponding byte (e.g., `%20` → space character `0x20`).

> Invalid percent-encodings (e.g., `%2z`, `%1`) are treated as literal characters and copied as-is.

> The output string is null-terminated.

>         MCO_RET rc;
>         char tmp_buf[1024];
>         lews_connection_context_t ctx;
>         ...
>         /*
>         // Incoming buffer contains:
>         "GET /some?param1=AbC&param2=bar%20foo&param3=123&param4=bar%2zzz&param5=qqq HTTP/1.1\r\n"
>         "Host: example.com\r\n"
>         "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n\r\n"
>         */
>         rc = mco_lews_get_query_param_str((char*)(&ctx.incoming_buf) + ctx.params_pos,
>                                         ctx.params_len, "param2", tmp_buf, sizeof(tmp_buf));
>         ASSERT_EQ(MCO_S_OK, rc);
>         ASSERT_STREQ("bar%20foo", tmp_buf);

>         rc = mco_lews_url_param_decode(tmp_buf, strlen(tmp_buf), tmp_buf, sizeof(tmp_buf));
>         ASSERT_EQ(MCO_S_OK, rc);
>         ASSERT_STREQ("bar foo", tmp_buf);

### Return Codes

`MCO_S_OK`
Input successfully decoded and stored in `out_str`.
`MCO_E_LEWS_NO_ENOUGH_MEMORY`
The output buffer is too small to hold the decoded string (including the null terminator).
`MCO_E_LEWS_BAD_PARAMETERS`
One or more input pointers (`in_str` or `out_str`) are `NULL`.

### Files

Header file:
mcoewslite.h
Source file:
mcoewslite.c
Library:
mcoewslite.a