mco_lews_get_query_param_int

Prototype

    MCO_RET mco_lews_get_query_param_int(const char *in_buffer, mco_uint2 in_buf_size,
                                        const char *param_name, mco_int4 *out_value);

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., "tp").
out_value
Pointer to a variable where the parsed 32-bit signed integer value will be stored.

Description

This function searches for a query or form parameter named param_name in the provided buffer and attempts to parse its value as a signed 32-bit integer (mco_int4).

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 supports standard URL-encoded parameter format (e.g., tp=123). The numeric value must consist only of an optional minus sign followed by decimal digits.

If the numeric string exceeds 19 characters (the maximum length of a 64-bit signed integer in decimal), the function returns MCO_E_LEWS_NO_ENOUGH_MEMORY — this is a safeguard against overflow, even though the target type is 32-bit.

    lews_connection_context_h p_ctx;
    mco_int4 tp;
    ...
    if (IS_METHOD(p_ctx, "GET")) {
        if (IS_URL(p_ctx, "/test")) {
            ret = mco_lews_get_query_param_int(p_ctx->incoming_buf + p_ctx->params_pos,
                                            p_ctx->params_len, "tp", &tp);
            if (ret == MCO_S_OK) {
                /* Use 'tp' value */
                ...
            }
        }
    }

Return Codes

MCO_S_OK
Parameter found and successfully parsed as a valid 32-bit signed integer.
MCO_E_LEWS_NONEXISTENT_PARAMETER
Parameter with the specified name was not found in the buffer.
MCO_E_LEWS_NO_ENOUGH_MEMORY
The numeric string is too long (more than 19 characters) or cannot be safely parsed as a 32-bit integer.

Files

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