Browse Source

altcp_tls: rename altcp_tls_new -> altcp_tls_wrap, add altcp_tls_new

The new altcp_tls_new() is a type safe version of altcp_tls_alloc()

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
STABLE-2_1_x
Simon Goldschmidt 8 years ago
parent
commit
a044c807f8
  1. 2
      src/apps/altcp_tls/altcp_tls_mbedtls.c
  2. 2
      src/apps/http/altcp_proxyconnect.c
  3. 5
      src/apps/http/httpd.c
  4. 19
      src/apps/mqtt/mqtt.c
  5. 17
      src/apps/smtp/smtp.c
  6. 12
      src/core/altcp_alloc.c
  7. 16
      src/include/lwip/altcp_tls.h

2
src/apps/altcp_tls/altcp_tls_mbedtls.c

@ -605,7 +605,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
}
struct altcp_pcb *
altcp_tls_new(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb)
altcp_tls_wrap(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb)
{
struct altcp_pcb *ret;
if (inner_pcb == NULL) {

2
src/apps/http/altcp_proxyconnect.c

@ -418,7 +418,7 @@ altcp_proxyconnect_tls_alloc(void *arg, u8_t ip_type)
struct altcp_pcb *tls_pcb;
proxy_pcb = altcp_proxyconnect_new_tcp(&cfg->proxy, ip_type);
tls_pcb = altcp_tls_new(cfg->tls_config, proxy_pcb);
tls_pcb = altcp_tls_wrap(cfg->tls_config, proxy_pcb);
if (tls_pcb == NULL) {
altcp_close(proxy_pcb);

5
src/apps/http/httpd.c

@ -2685,10 +2685,7 @@ void
httpd_inits(struct altcp_tls_config *conf)
{
#if LWIP_ALTCP_TLS
struct altcp_pcb *pcb_tls;
struct altcp_pcb *pcb_tcp = altcp_tcp_new_ip_type(IPADDR_TYPE_ANY);
LWIP_ASSERT("httpd_init: tcp_new failed", pcb_tcp != NULL);
pcb_tls = altcp_tls_new(conf, pcb_tcp);
struct altcp_pcb *pcb_tls = altcp_tls_new(conf, IPADDR_TYPE_ANY);
LWIP_ASSERT("httpd_init: altcp_tls_new failed", pcb_tls != NULL);
httpd_init_pcb(pcb_tls, HTTPD_SERVER_PORT_HTTPS);
#else /* LWIP_ALTCP_TLS */

19
src/apps/mqtt/mqtt.c

@ -1362,20 +1362,17 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port,
return ERR_MEM;
}
client->conn = altcp_tcp_new();
if (client->conn == NULL) {
return ERR_MEM;
}
#if LWIP_ALTCP && LWIP_ALTCP_TLS
if (client_info->tls_config) {
struct altcp_pcb *pcb_tls = altcp_tls_new(client_info->tls_config, client->conn);
if (pcb_tls == NULL) {
altcp_close(client->conn);
return ERR_MEM;
}
client->conn = pcb_tls;
}
client->conn = altcp_tls_new(client_info->tls_config, IP_GET_TYPE(ip_addr));
} else
#endif
{
client->conn = altcp_tcp_new_ip_type(IP_GET_TYPE(ip_addr));
}
if (client->conn == NULL) {
return ERR_MEM;
}
/* Set arg pointer for callbacks */
altcp_arg(client->conn, client);

17
src/apps/smtp/smtp.c

@ -460,18 +460,15 @@ smtp_setup_pcb(struct smtp_session *s, const ip_addr_t* remote_ip)
struct altcp_pcb* pcb;
LWIP_UNUSED_ARG(remote_ip);
pcb = altcp_tcp_new_ip_type(IP_GET_TYPE(remote_ip));
if (pcb != NULL) {
#if LWIP_ALTCP && LWIP_ALTCP_TLS
if (smtp_server_tls_config) {
struct altcp_pcb *pcb_tls = altcp_tls_new(smtp_server_tls_config, pcb);
if (pcb_tls == NULL) {
altcp_close(pcb);
return NULL;
}
pcb = pcb_tls;
}
if (smtp_server_tls_config) {
pcb = altcp_tls_new(smtp_server_tls_config, IP_GET_TYPE(remote_ip));
} else
#endif
{
pcb = altcp_tcp_new_ip_type(IP_GET_TYPE(remote_ip));
}
if (pcb != NULL) {
altcp_arg(pcb, s);
altcp_recv(pcb, smtp_tcp_recv);
altcp_err(pcb, smtp_tcp_err);

12
src/core/altcp_alloc.c

@ -58,23 +58,29 @@
/** This standard allocator function creates an altcp pcb for
* TLS over TCP */
struct altcp_pcb *
altcp_tls_alloc(void *arg, u8_t ip_type)
altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type)
{
struct altcp_pcb *inner_conn, *ret;
struct altcp_tls_config *config = (struct altcp_tls_config *)arg;
LWIP_UNUSED_ARG(ip_type);
inner_conn = altcp_tcp_new_ip_type(ip_type);
if (inner_conn == NULL) {
return NULL;
}
ret = altcp_tls_new(config, inner_conn);
ret = altcp_tls_wrap(config, inner_conn);
if (ret == NULL) {
altcp_close(inner_conn);
}
return ret;
}
/** This standard allocator function creates an altcp pcb for
* TLS over TCP */
struct altcp_pcb *
altcp_tls_alloc(void *arg, u8_t ip_type)
{
return altcp_tls_new((struct altcp_tls_config *)arg, ip_type);
}
#endif /* LWIP_ALTCP_TLS */

16
src/include/lwip/altcp_tls.h

@ -85,14 +85,20 @@ struct altcp_tls_config *altcp_tls_create_config_client_2wayauth(const u8_t *ca,
void altcp_tls_free_config(struct altcp_tls_config *conf);
/** @ingroup altcp_tls
* Create new ALTCP_TLS layer
* Create new ALTCP_TLS layer wrapping an existing pcb as inner connection (e.g. TLS over TCP)
*/
struct altcp_pcb *altcp_tls_new(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb);
struct altcp_pcb *altcp_tls_wrap(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb);
/** @ingroup altcp_tls
* Create new ALTCP_TLS layer
* This allocator function fits to @ref altcp_allocator_t / @ref altcp_new.
* 'arg' must contain a struct altcp_tls_config *.
* Create new ALTCP_TLS pcb and its inner tcp pcb
*/
struct altcp_pcb *altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type);
/** @ingroup altcp_tls
* Create new ALTCP_TLS layer pcb and its inner tcp pcb.
* Same as @ref altcp_tls_new but this allocator function fits to
* @ref altcp_allocator_t / @ref altcp_new.\n
'arg' must contain a struct altcp_tls_config *.
*/
struct altcp_pcb *altcp_tls_alloc(void *arg, u8_t ip_type);

Loading…
Cancel
Save