Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Each HTTPc_KEY_VAL_EXT objects contained in a table form must have set up a hook function pointer with the parameter OnValTx. The HTTPc transmit buffer pointer and the length available inside are passed as argument to allow the hook function to copy the data value directly inside the HTTPc buffer.

Prototype

Code Block

CPU_BOOLEAN  HTTPc_FormKeyValExtHook (HTTPc_CONN_OBJ     *p_conn_obj,
                                      HTTPc_REQ_OBJ      *p_req_obj,
                                      HTTPc_KEY_VAL_EXT  *p_key_val_obj,
                                      CPU_CHAR           *p_buf,
                                      CPU_INT16U          buf_len,
                                      CPU_INT16U         *p_len_wr);

Arguments

p_conn_obj

Pointer to the current HTTPc Connection Object.

...

Notes / Warnings

None.

Example Template

Code Block
languagecpp
titleListing - HTTP Connection Hook Function that Handles External Key-Value Pairs
linenumberstrue
CPU_CHAR  HTTPc_AppBuf[512];

static  CPU_BOOLEAN  HTTPc_FormKeyValExtHook (HTTPc_CONN_OBJ     *p_conn_obj,
                                              HTTPc_REQ_OBJ      *p_req_obj,
                                              HTTPc_KEY_VAL_EXT  *p_key_val_obj,
                                              CPU_CHAR           *p_buf,
                                              CPU_INT16U          buf_len,
                                              CPU_INT16U         *p_len_wr);
{
            HTTPc_KEY_VAL_EXT  *p_field;
            CPU_CHAR           *p_data;
            CPU_INT16U          min_len;
    static  CPU_INT16U          data_ix;

    p_data = &HTTPc_AppBuf[data_ix];

    min_len = DEF_MIN(buf_len, (p_key_val_obj->ValLen - data_ix));
    if (min_len <= 0) {
        data_ix = 0;
       *p_len_wr = min_len;
        return (DEF_YES);
    }

    Str_Copy_N(p_buf, p_data, min_len);
   *p_len_wr  = min_len;
    data_ix  += min_len;

    return (DEF_NO);
}


Info

This code uses a variable declared as static for example purpose. It cannot work if multiple connections call the same hook function. In that case, the UserDataPtr parameter inside the HTTPc_REQ_OBJ or HTTPc_CONN_OBJ can be used to store data for the application usage.

...