HTTP_CLIENT_RESULT uhttp_client_set_trusted_cert()

in src/uhttp.c [1534:1561]


HTTP_CLIENT_RESULT uhttp_client_set_trusted_cert(HTTP_CLIENT_HANDLE handle, const char* certificate)
{
    HTTP_CLIENT_RESULT result;
    if (handle == NULL || certificate == NULL)
    {
        /* Codes_SRS_UHTTP_07_038: [If handle is NULL then http_client_set_trace shall return HTTP_CLIENT_INVALID_ARG] */
        result = HTTP_CLIENT_INVALID_ARG;
        LogError("invalid parameter handle: %p certificate: %p", handle, certificate);
    }
    else if (handle->recv_msg.recv_state != state_initial)
    {
        result = HTTP_CLIENT_INVALID_STATE;
        LogError("You must set the certificates before opening the connection");
    }
    else
    {
        if (mallocAndStrcpy_s(&handle->certificate, certificate) != 0)
        {
            result = HTTP_CLIENT_ERROR;
            LogError("failure allocating certificate");
        }
        else
        {
            result = HTTP_CLIENT_OK;
        }
    }
    return result;
}