Merge pull request #40 from Lawlieta/master

【修复】开启 MbedTLS 支持后 getaddrinfo() 失败问题
master
朱天龙 (Armink) 7 years ago committed by GitHub
commit 6518b1a9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -225,16 +225,23 @@ static int webclient_resolve_address(struct webclient_session *session, struct a
memcpy(host_addr_new, host_addr, host_addr_len); memcpy(host_addr_new, host_addr, host_addr_len);
host_addr_new[host_addr_len] = '\0'; host_addr_new[host_addr_len] = '\0';
session->host = host_addr_new; session->host = host_addr_new;
}
LOG_D("host address: %s , port: %s", session->host, port_str);
#ifdef WEBCLIENT_USING_MBED_TLS #ifdef WEBCLIENT_USING_MBED_TLS
if (session->tls_session) if (session->tls_session)
{
session->tls_session->port = web_strdup(port_str);
session->tls_session->host = web_strdup(session->host);
if (session->tls_session->port == RT_NULL || session->tls_session->host == RT_NULL)
{ {
session->tls_session->host = web_strdup(host_addr_new); return -WEBCLIENT_NOMEM;
} }
#endif
}
LOG_D("host address: %s , port: %s", session->host, port_str); return rc;
}
#endif
/* resolve the host name. */ /* resolve the host name. */
{ {
@ -242,22 +249,6 @@ static int webclient_resolve_address(struct webclient_session *session, struct a
int ret; int ret;
rt_memset(&hint, 0, sizeof(hint)); rt_memset(&hint, 0, sizeof(hint));
#ifdef WEBCLIENT_USING_MBED_TLS
if (session->tls_session)
{
session->tls_session->port = web_strdup(port_str);
ret = getaddrinfo(session->tls_session->host, port_str, &hint, res);
if (ret != 0)
{
LOG_E("getaddrinfo err: %d '%s'", ret, session->host);
rc = -WEBCLIENT_ERROR;
}
goto __exit;
}
#endif
ret = getaddrinfo(session->host, port_str, &hint, res); ret = getaddrinfo(session->host, port_str, &hint, res);
if (ret != 0) if (ret != 0)
{ {
@ -265,8 +256,8 @@ static int webclient_resolve_address(struct webclient_session *session, struct a
rc = -WEBCLIENT_ERROR; rc = -WEBCLIENT_ERROR;
goto __exit; goto __exit;
} }
} }
__exit: __exit:
if (rc != WEBCLIENT_OK) if (rc != WEBCLIENT_OK)
{ {
@ -379,7 +370,8 @@ static int webclient_connect(struct webclient_session *session, const char *URI)
goto __exit; goto __exit;
} }
if (!res) /* Not use 'getaddrinfo()' for https connection */
if (session->is_tls == RT_FALSE && res == RT_NULL)
{ {
rc = -WEBCLIENT_ERROR; rc = -WEBCLIENT_ERROR;
goto __exit; goto __exit;
@ -411,8 +403,7 @@ static int webclient_connect(struct webclient_session *session, const char *URI)
if ((tls_ret = mbedtls_client_connect(session->tls_session)) < 0) if ((tls_ret = mbedtls_client_connect(session->tls_session)) < 0)
{ {
LOG_E("connect failed, https client connect return: -0x%x", -tls_ret); LOG_E("connect failed, https client connect return: -0x%x", -tls_ret);
rc = -WEBCLIENT_CONNECT_FAILED; return -WEBCLIENT_CONNECT_FAILED;
goto __exit;
} }
socket_handle = session->tls_session->server_fd.fd; socket_handle = session->tls_session->server_fd.fd;
@ -425,8 +416,7 @@ static int webclient_connect(struct webclient_session *session, const char *URI)
session->socket = socket_handle; session->socket = socket_handle;
rc = WEBCLIENT_OK; return WEBCLIENT_OK;
goto __exit;
} }
#endif #endif

Loading…
Cancel
Save