mco_lews_get_query_param_str

Prototype

    MCO_RET mco_lews_get_query_param_str(const char *in_buffer, mco_uint2 in_buf_size,
                                        const char *param_name, char *out_buf, mco_uint2 out_buf_size);

Arguments

in_buffer
Pointer to the buffer containing URL query string (for GET) or request body (for POST).
in_buf_size
Size (in bytes) of the in_buffer.
param_name
Null-terminated name of the parameter to search for (e.g., "format").
out_buf
Output buffer where the null-terminated parameter value will be stored if found.
out_buf_size
Size (in bytes) of the out_buf buffer, including space for the null terminator.

Description

This function searches for a query or form parameter named param_name in the provided buffer and copies its raw value as a null-terminated string into out_buf.

For HTTP GET requests, parameters are expected in the query string (the part after ? in the URL).
For HTTP POST requests with application/x-www-form-urlencoded content type, parameters are expected in the request body.

The function does not perform URL decoding. The value is copied exactly as it appears in the input buffer (e.g., %20 remains %20, and + remains +).

    lews_connection_context_h p_ctx;
    ...
    if (IS_METHOD(p_ctx, "GET")) {
        if (IS_URL(p_ctx, "/test")) {
            ret = mco_lews_get_query_param_str(p_ctx->incoming_buf + p_ctx->params_pos,
                                            p_ctx->params_len, "format", tmp_buf, sizeof(tmp_buf));
            if (ret == MCO_S_OK) {
                /* Use 'tmp_buf' containing the raw (undecoded) value */
                ...
            }
        }
    }

Return Codes

MCO_S_OK
Parameter found and its raw value successfully copied to out_buf as a null-terminated string.
MCO_E_LEWS_NONEXISTENT_PARAMETER
Parameter with the specified name was not found in the buffer.
MCO_E_LEWS_NO_ENOUGH_MEMORY
The out_buf is too small to hold the parameter value (including the null terminator).

Files

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