Mercurial
comparison seobeo/s_linux_network.c @ 19:875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 06 Oct 2025 09:55:34 -0700 |
| parents | fa2b8af609d9 |
| children | 947b81010aba |
comparison
equal
deleted
inserted
replaced
| 18:fa2b8af609d9 | 19:875bb6e10db7 |
|---|---|
| 74 Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls) | 74 Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls) |
| 75 { | 75 { |
| 76 Seobeo_PHandle p_handle; | 76 Seobeo_PHandle p_handle; |
| 77 p_handle = malloc(sizeof(*p_handle)); | 77 p_handle = malloc(sizeof(*p_handle)); |
| 78 | 78 |
| 79 struct addrinfo hints, *server_infos, *free_server_info; | 79 struct addrinfo hints, *server_infos; |
| 80 int32 socket_fd, yes = 1; // Need this for setsockopt | 80 int32 socket_fd; // Need this for setsockopt |
| 81 | 81 |
| 82 memset(&hints, 0, sizeof hints); | 82 memset(&hints, 0, sizeof hints); |
| 83 hints.ai_family = AF_UNSPEC; | 83 hints.ai_family = AF_UNSPEC; |
| 84 hints.ai_socktype = SOCK_STREAM; | 84 hints.ai_socktype = SOCK_STREAM; |
| 85 | 85 |
| 98 p_handle->socket = socket_fd; | 98 p_handle->socket = socket_fd; |
| 99 p_handle->type = SEOBEO_STREAM_TYPE_CLIENT; | 99 p_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
| 100 if (use_tls) | 100 if (use_tls) |
| 101 { | 101 { |
| 102 printf("USE SSL\n\n"); | 102 printf("USE SSL\n\n"); |
| 103 init_openssl(); | 103 Seobeo_Web_SSL_Init(); |
| 104 p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); | 104 p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); |
| 105 SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); | 105 SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); |
| 106 | 106 |
| 107 p_handle->ssl = SSL_new(p_handle->ssl_ctx); | 107 p_handle->ssl = SSL_new(p_handle->ssl_ctx); |
| 108 SSL_set_fd(p_handle->ssl, p_handle->socket); | 108 SSL_set_fd(p_handle->ssl, p_handle->socket); |
| 141 p_handle->destroyed = false; | 141 p_handle->destroyed = false; |
| 142 | 142 |
| 143 return p_handle; | 143 return p_handle; |
| 144 } | 144 } |
| 145 | 145 |
| 146 Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle) | 146 Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle p_server_handle) |
| 147 { | 147 { |
| 148 struct sockaddr_storage addr; | 148 struct sockaddr_storage addr; |
| 149 socklen_t addrlen = sizeof addr; | 149 socklen_t addrlen = sizeof addr; |
| 150 char client_inet_addr[INET6_ADDRSTRLEN]; | 150 char client_inet_addr[INET6_ADDRSTRLEN]; |
| 151 int client_fd = accept(p_server_handle->socket, | 151 int client_fd = accept(p_server_handle->socket, |
| 152 (struct sockaddr*)&addr, | 152 (struct sockaddr*)&addr, |
| 153 &addrlen); | 153 &addrlen); |
| 154 inet_ntop( | 154 inet_ntop( |
| 155 addr.ss_family, | 155 addr.ss_family, |
| 156 Seobeo_GetIP4OrIP6((struct sockaddr *)&addr), | 156 Seobeo_Get_IP4_Or_IP6((struct sockaddr *)&addr), |
| 157 client_inet_addr, sizeof client_inet_addr); | 157 client_inet_addr, sizeof client_inet_addr); |
| 158 | 158 |
| 159 if (client_fd == -1) | 159 if (client_fd == -1) |
| 160 { | 160 { |
| 161 return NULL; | 161 return NULL; |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 if (p_handle->host) free(p_handle->host); | 201 if (p_handle->host) free(p_handle->host); |
| 202 if (p_handle->port) free(p_handle->port); | 202 if (p_handle->port) free(p_handle->port); |
| 203 | |
| 204 if (p_handle->ssl) | |
| 205 { | |
| 206 SSL_shutdown(p_handle->ssl); | |
| 207 SSL_free(p_handle->ssl); | |
| 208 p_handle->ssl = NULL; | |
| 209 } | |
| 210 | |
| 211 if (p_handle->ssl_ctx) | |
| 212 { | |
| 213 SSL_CTX_free(p_handle->ssl_ctx); | |
| 214 p_handle->ssl_ctx = NULL; | |
| 215 } | |
| 216 | |
| 203 if (p_handle->socket) close(p_handle->socket); | 217 if (p_handle->socket) close(p_handle->socket); |
| 218 | |
| 204 if (p_handle->read_buffer) free(p_handle->read_buffer); | 219 if (p_handle->read_buffer) free(p_handle->read_buffer); |
| 205 if (p_handle->write_buffer) free(p_handle->write_buffer); | 220 if (p_handle->write_buffer) free(p_handle->write_buffer); |
| 221 | |
| 206 if (p_handle->text_copy) free(p_handle->text_copy); | 222 if (p_handle->text_copy) free(p_handle->text_copy); |
| 207 if (p_handle->file_name) free(p_handle->file_name); | 223 if (p_handle->file_name) free(p_handle->file_name); |
| 208 | 224 |
| 209 free(p_handle); | 225 free(p_handle); |
| 210 } | 226 } |
| 366 p_handle->read_buffer_len - consumed | 382 p_handle->read_buffer_len - consumed |
| 367 ); | 383 ); |
| 368 p_handle->read_buffer_len -= consumed; | 384 p_handle->read_buffer_len -= consumed; |
| 369 } | 385 } |
| 370 | 386 |
| 371 void *Seobeo_GetIP4OrIP6(struct sockaddr *sa) | 387 void *Seobeo_Get_IP4_Or_IP6(struct sockaddr *sa) |
| 372 { | 388 { |
| 373 if (sa->sa_family == AF_INET) | 389 if (sa->sa_family == AF_INET) |
| 374 { | 390 { |
| 375 return &(((struct sockaddr_in*)sa)->sin_addr); | 391 return &(((struct sockaddr_in*)sa)->sin_addr); |
| 376 } | 392 } |