From 329ca8e8f40efdd7838d40435b5f113d2877c13c Mon Sep 17 00:00:00 2001 From: Test_User Date: Fri, 5 May 2023 23:34:55 -0400 Subject: Switch to gnutls, add handling of NICK, add responses to unknown/invalid/etc command, change a few other things --- main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 8e0e97b..e95d750 100644 --- a/main.c +++ b/main.c @@ -26,8 +26,10 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#include +#include #include +#include +#include #include "network.h" #include "config.h" @@ -41,10 +43,20 @@ int main(void) { struct string full_msg = {malloc(0), 0}; while (1) { uint8_t data[512]; - uint64_t new_len = SSL_read(ssl, data, 512); + uint64_t new_len; + { + int len; + do { + len = gnutls_record_recv(session, data, 512); + } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED); + if (len < 0) + new_len = 0; + else + new_len = len; + } if (new_len == 0) { - puts("Disconnected."); + WRITES(1, STRING("Disconnected.\n")); return 0; } @@ -60,7 +72,7 @@ int main(void) { void *tmp = realloc(full_msg.data, full_msg.len+new_len); if (tmp == 0 && full_msg.len+new_len != 0) { - puts("OOM... currently just exiting bc there's no automatic reconnect in here yet, and the only sane solution to this is resyncing."); + WRITES(2, STRING("OOM... currently just exiting bc there's no automatic reconnect in here yet, and the only sane solution to this is resyncing.\n")); return 1; } full_msg.data = tmp; -- cgit v1.2.3