components/webclient/src/webclient.c
static int webclient_open_tls(struct webclient_session *session, const char *URI)
{
    int tls_ret = 0;
    const char *pers = "webclient";

    if (!session)
    {
        return -WEBCLIENT_ERROR;
    }

    session->tls_session = (MbedTLSSession *)web_malloc(sizeof(MbedTLSSession));
    if (session->tls_session == NULL)
    {
        return -WEBCLIENT_NOMEM;
    }

    session->tls_session->buffer_len = WEBCLIENT_RESPONSE_BUFSZ;
    session->tls_session->buffer = web_malloc(session->tls_session->buffer_len);
    if (session->tls_session->buffer == NULL)
    {
        // "no memory for tls_session buffer!"
        return -WEBCLIENT_ERROR;
    }

    if ((tls_ret = mbedtls_client_init(session->tls_session, (void *)pers, strlen(pers))) < 0)
    {
        // "initialize https client failed return: -0x%x.", -tls_ret
        return -WEBCLIENT_ERROR;
    }

    return WEBCLIENT_OK;
}
/**
 * create and initialize https session.
 *
 * @param session webclient session
 * @param URI input server URI address
 *
 * @return <0: create failed, no memory or other errors
 *         =0: success
 */
create and initialize https session.
@param session webclient session
@param URI input server URI address

@return <0: create failed, no memory or other errors
=0: success
create and initialize https session . @param session webclient session @param URI input server URI address @return <0 : create failed no memory or other errors = 0 : success
static int webclient_open_tls(struct webclient_session *session, const char *URI)
{
    int tls_ret = 0;
    const char *pers = "webclient";
    if (!session)
    {
        return -WEBCLIENT_ERROR;
    }
    session->tls_session = (MbedTLSSession *)web_malloc(sizeof(MbedTLSSession));
    if (session->tls_session == NULL)
    {
        return -WEBCLIENT_NOMEM;
    }
    session->tls_session->buffer_len = WEBCLIENT_RESPONSE_BUFSZ;
    session->tls_session->buffer = web_malloc(session->tls_session->buffer_len);
    if (session->tls_session->buffer == NULL)
    {
        return -WEBCLIENT_ERROR;
    }
    if ((tls_ret = mbedtls_client_init(session->tls_session, (void *)pers, strlen(pers))) < 0)
    {
        return -WEBCLIENT_ERROR;
    }
    return WEBCLIENT_OK;
}
static int webclient_open_tls ( struct webclient_session * session , const char * URI ) { int tls_ret = 0 ; const char * pers = " " ; if ( ! session ) { return - WEBCLIENT_ERROR ; } session -> tls_session = ( MbedTLSSession * ) web_malloc ( sizeof ( MbedTLSSession ) ) ; if ( session -> tls_session == NULL ) { return - WEBCLIENT_NOMEM ; } session -> tls_session -> buffer_len = WEBCLIENT_RESPONSE_BUFSZ ; session -> tls_session -> buffer = web_malloc ( session -> tls_session -> buffer_len ) ; if ( session -> tls_session -> buffer == NULL ) { return - WEBCLIENT_ERROR ; } if ( ( tls_ret = mbedtls_client_init ( session -> tls_session , ( void * ) pers , strlen ( pers ) ) ) < 0 ) { return - WEBCLIENT_ERROR ; } return WEBCLIENT_OK ; }
create and initialize https session.
create and initialize https session .
// "no memory for tls_session buffer!" // "initialize https client failed return: -0x%x.", -tls_ret