summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-05-05 23:34:55 -0400
committerTest_User <hax@andrewyu.org>2023-05-05 23:34:55 -0400
commit329ca8e8f40efdd7838d40435b5f113d2877c13c (patch)
treea71b82548acc60185a448261a0088fa7e925e948 /main.c
parent9343cffa8c032d5b44fce89af7fc5d8709acd9aa (diff)
downloadcoupserv-329ca8e8f40efdd7838d40435b5f113d2877c13c.tar.gz
coupserv-329ca8e8f40efdd7838d40435b5f113d2877c13c.zip
Switch to gnutls, add handling of NICK, add responses to unknown/invalid/etc command, change a few other things
Diffstat (limited to 'main.c')
-rw-r--r--main.c20
1 files changed, 16 insertions, 4 deletions
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 <openssl/ssl.h>
+#include <gnutls/gnutls.h>
#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
#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;