22 * (c) Danielinux 2024 <root@danielinux.net>
33 * This code is licensed under the GPLv3 license.
44 */
5- #include "wolftcp .h"
5+ #include "wolfip .h"
66#include "httpd.h"
77
88static const char * http_status_text (int status_code ) {
@@ -90,7 +90,7 @@ void http_send_response_headers(struct http_client *hc, int status_code, const c
9090 if (hc -> ssl ) {
9191 wolfSSL_write (hc -> ssl , txt_response , strlen (txt_response ));
9292 } else {
93- ft_send (hc -> httpd -> ipstack , hc -> client_sd , txt_response , strlen (txt_response ), 0 );
93+ wolfIP_sock_send (hc -> httpd -> ipstack , hc -> client_sd , txt_response , strlen (txt_response ), 0 );
9494 }
9595}
9696
@@ -99,7 +99,7 @@ void http_send_response_body(struct http_client *hc, const void *body, size_t le
9999 if (hc -> ssl ) {
100100 wolfSSL_write (hc -> ssl , body , len );
101101 } else {
102- ft_send (hc -> httpd -> ipstack , hc -> client_sd , body , len , 0 );
102+ wolfIP_sock_send (hc -> httpd -> ipstack , hc -> client_sd , body , len , 0 );
103103 }
104104}
105105
@@ -113,10 +113,10 @@ void http_send_response_chunk(struct http_client *hc, const void *chunk, size_t
113113 wolfSSL_write (hc -> ssl , chunk , len );
114114 wolfSSL_write (hc -> ssl , "\r\n" , 2 );
115115 } else {
116- struct ipstack * s = hc -> httpd -> ipstack ;
117- ft_send (s , hc -> client_sd , txt_chunk , strlen (txt_chunk ), 0 );
118- ft_send (s , hc -> client_sd , chunk , len , 0 );
119- ft_send (s , hc -> client_sd , "\r\n" , 2 , 0 );
116+ struct wolfIP * s = hc -> httpd -> ipstack ;
117+ wolfIP_sock_send (s , hc -> client_sd , txt_chunk , strlen (txt_chunk ), 0 );
118+ wolfIP_sock_send (s , hc -> client_sd , chunk , len , 0 );
119+ wolfIP_sock_send (s , hc -> client_sd , "\r\n" , 2 , 0 );
120120 }
121121}
122122
@@ -125,7 +125,7 @@ void http_send_response_chunk_end(struct http_client *hc) {
125125 if (hc -> ssl ) {
126126 wolfSSL_write (hc -> ssl , "0\r\n\r\n" , 5 );
127127 } else {
128- ft_send (hc -> httpd -> ipstack , hc -> client_sd , "0\r\n\r\n" , 5 , 0 );
128+ wolfIP_sock_send (hc -> httpd -> ipstack , hc -> client_sd , "0\r\n\r\n" , 5 , 0 );
129129 }
130130}
131131
@@ -289,7 +289,7 @@ static void http_recv_cb(int sd, uint16_t event, void *arg) {
289289 }
290290 }
291291 } else {
292- ret = ft_recv (hc -> httpd -> ipstack , sd , buf , sizeof (buf ), 0 );
292+ ret = wolfIP_sock_recv (hc -> httpd -> ipstack , sd , buf , sizeof (buf ), 0 );
293293 if (ret == -11 )
294294 return ;
295295 }
@@ -306,15 +306,15 @@ static void http_recv_cb(int sd, uint16_t event, void *arg) {
306306 wolfSSL_free (hc -> ssl );
307307 hc -> ssl = NULL ;
308308 }
309- ft_close (hc -> httpd -> ipstack , sd );
309+ wolfIP_sock_close (hc -> httpd -> ipstack , sd );
310310 hc -> client_sd = 0 ;
311311}
312312
313313static void http_accept_cb (int sd , uint16_t event , void * arg ) {
314314 struct httpd * httpd = (struct httpd * ) arg ;
315- struct ipstack_sockaddr_in addr ;
316- socklen_t addr_len = sizeof (struct ipstack_sockaddr_in );
317- int client_sd = ft_accept (httpd -> ipstack , sd , (struct ipstack_sockaddr * ) & addr , & addr_len );
315+ struct wolfIP_sockaddr_in addr ;
316+ socklen_t addr_len = sizeof (struct wolfIP_sockaddr_in );
317+ int client_sd = wolfIP_sock_accept (httpd -> ipstack , sd , (struct wolfIP_sockaddr * ) & addr , & addr_len );
318318 if (client_sd < 0 ) {
319319 return ;
320320 }
@@ -330,12 +330,12 @@ static void http_accept_cb(int sd, uint16_t event, void *arg) {
330330 wolfSSL_SetIO_FT (httpd -> clients [i ].ssl , client_sd );
331331 } else {
332332 /* Failed to create SSL object */
333- ft_close (httpd -> ipstack , client_sd );
333+ wolfIP_sock_close (httpd -> ipstack , client_sd );
334334 httpd -> clients [i ].client_sd = 0 ;
335335 return ;
336336 }
337337 }
338- ipstack_register_callback (httpd -> ipstack , client_sd , http_recv_cb , & httpd -> clients [i ]);
338+ wolfIP_register_callback (httpd -> ipstack , client_sd , http_recv_cb , & httpd -> clients [i ]);
339339 break ;
340340 }
341341 }
@@ -377,8 +377,8 @@ int httpd_get_request_arg(struct http_request *req, const char *name, char *valu
377377 return -1 ; // Key not found
378378}
379379
380- int httpd_init (struct httpd * httpd , struct ipstack * s , uint16_t port , void * ssl_ctx ) {
381- struct ipstack_sockaddr_in addr ;
380+ int httpd_init (struct httpd * httpd , struct wolfIP * s , uint16_t port , void * ssl_ctx ) {
381+ struct wolfIP_sockaddr_in addr ;
382382 memset (& addr , 0 , sizeof (addr ));
383383 addr .sin_family = AF_INET ;
384384 addr .sin_port = htons (port );
@@ -388,21 +388,21 @@ int httpd_init(struct httpd *httpd, struct ipstack *s, uint16_t port, void *ssl_
388388 memset (httpd , 0 , sizeof (struct httpd ));
389389 httpd -> ipstack = s ;
390390 httpd -> port = port ;
391- httpd -> listen_sd = ft_socket (s , AF_INET , SOCK_STREAM , 0 );
391+ httpd -> listen_sd = wolfIP_sock_socket (s , AF_INET , SOCK_STREAM , 0 );
392392 if (httpd -> listen_sd < 0 ) {
393393 return -1 ;
394394 }
395- if (ft_bind (s , httpd -> listen_sd , (struct ipstack_sockaddr * ) & addr , sizeof (addr )) < 0 ) {
395+ if (wolfIP_sock_bind (s , httpd -> listen_sd , (struct wolfIP_sockaddr * ) & addr , sizeof (addr )) < 0 ) {
396396 return -1 ;
397397 }
398- if (ft_listen (s , httpd -> listen_sd , 5 ) < 0 ) {
398+ if (wolfIP_sock_listen (s , httpd -> listen_sd , 5 ) < 0 ) {
399399 return -1 ;
400400 }
401401 if (ssl_ctx ) {
402402 httpd -> ssl_ctx = (WOLFSSL_CTX * ) ssl_ctx ;
403403 wolfSSL_SetIO_FT_CTX (httpd -> ssl_ctx , httpd -> ipstack );
404404 }
405- ipstack_register_callback (s , httpd -> listen_sd , http_accept_cb , httpd );
405+ wolfIP_register_callback (s , httpd -> listen_sd , http_accept_cb , httpd );
406406 return 0 ;
407407}
408408
0 commit comments