]> Pileus Git - ~andy/lamechat/commitdiff
Debug changes
authorAndy Spencer <andy753421@gmail.com>
Sat, 21 Oct 2017 07:01:02 +0000 (07:01 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 21 Oct 2017 07:01:02 +0000 (07:01 +0000)
chat.c
makefile
net.c
view.c
xmpp.c

diff --git a/chat.c b/chat.c
index e099453c0f5e3d65b4d68decebc79f725bc0d7d6..9d2d0059231463481afb8b6887d86c333db3cd91 100644 (file)
--- a/chat.c
+++ b/chat.c
@@ -225,8 +225,10 @@ void chat_exit(void)
        irc_exit();
        xmpp_exit();
 
-       for (int i = 0; i < history; i++)
+       for (int i = 0; i < history; i++) {
+               free((void*)messages[i].from);
                free((void*)messages[i].text);
+       }
        release(&msg_buf);
 }
 
index c64feaf83f2c43426e561730c6f6ade9fe893e3f..04f6f993378b4d60063565122daae7368b1fe35b 100644 (file)
--- a/makefile
+++ b/makefile
@@ -40,6 +40,7 @@ memcheck: $(PROG)
                 --track-origins=yes     \
                 --leak-check=full       \
                 --leak-resolution=high  \
+                --show-leak-kinds=all   \
                 ./$(PROG)
 
 # Rules
diff --git a/net.c b/net.c
index a65d455bba91285330521b3690c7776500493386..6341d748eb57e34578808a1f4a7e761f630eb945 100644 (file)
--- a/net.c
+++ b/net.c
 #include <fcntl.h>
 #include <netdb.h>
 
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
 #include <openssl/bio.h>
 #include <openssl/ssl.h>
 
@@ -93,8 +97,10 @@ static void on_poll(void *_net)
        socklen_t elen = sizeof(err);
        if (getsockopt(net->poll.fd, SOL_SOCKET, SO_ERROR, &err, &elen))
                error("Error getting socket opt");
-       if (err)
+       if (err) {
+               debug("Socket error: %s", strerror(err));
                net_close(net);
+       }
 
        /* State machine */
        if (net->state == NET_CONNECT) {
@@ -168,6 +174,7 @@ void net_open(net_t *net, const char *host, int port)
        struct addrinfo *addrs = NULL;
        struct addrinfo hints = {};
        char service[16];
+       int yes = 1, idle = 60;
 
        net->host = strcopy(host);
        net->port = port;
@@ -191,6 +198,18 @@ void net_open(net_t *net, const char *host, int port)
        if (fcntl(sock, F_SETFL, flags|O_NONBLOCK) < 0)
                error("Error setting net socket non-blocking");
 
+       if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)) < 0)
+               error("Error setting net socket keepidle");
+
+       if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &yes, sizeof(yes)) < 0)
+               error("Error setting net socket keepintvl");
+
+       if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &yes, sizeof(yes)) < 0)
+               error("Error setting net socket keepcnt");
+
+       if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)) < 0)
+               error("Error setting net socket keepalive");
+
        if (connect(sock, addrs->ai_addr, addrs->ai_addrlen) < 0)
                if (errno != EINPROGRESS)
                        error("Error connecting socket");
diff --git a/view.c b/view.c
index e9b387f29096a8bc6aef3df30159f3da6372655b..48eb768ec8e8836494208de2ddc77b918afd7b5c 100644 (file)
--- a/view.c
+++ b/view.c
@@ -80,6 +80,7 @@ static poll_t poll_sig;
 static int    sig_fd;
 static int    running;
 static int    theme;
+static int    draw;
 
 static char   cmd_buf[512];
 static int    cmd_pos;
@@ -526,7 +527,6 @@ void view_init(void)
        start_color();
        timeout(0);
        use_default_colors();
-       mousemask(ALL_MOUSE_EVENTS, NULL);
 
        color_title = color(COLOR_WHITE, COLOR_BLUE);
        color_date  = color(COLOR_BROWN, -1);
@@ -580,16 +580,11 @@ void view_config(const char *group, const char *name, const char *key, const cha
 /* View event */
 void view_sync(void)
 {
-       MEVENT btn;
        int chr = getch();
 
        /* Misc ncurses */
        if (chr == ERR) {
-               return;
-       }
-       if (chr == KEY_MOUSE) {
-               if (getmouse(&btn) != OK)
-                       return;
+               goto redraw;
        }
 
        /* Window management */
@@ -706,21 +701,21 @@ void view_sync(void)
                                chr, chr, chr, chr);
        }
 
-       /* Flush output to screen */
-       refresh();
-}
-
-void view_draw(void)
-{
-       if (!running)
-               return;
-
+redraw:
+       /* Redraw screen */
        update_windows();
 
        draw_header();
        draw_chat();
        draw_status();
        draw_cmdline();
+
+       refresh();
+}
+
+void view_draw(void)
+{
+       draw = 1;
 }
 
 void view_exit(void)
diff --git a/xmpp.c b/xmpp.c
index df57d52a807c7b31eb249482455cdb53b3d8ab69..77e930f053d8b9d54bf7baba24be5f38b1b6af7a 100644 (file)
--- a/xmpp.c
+++ b/xmpp.c
@@ -391,10 +391,16 @@ static void xmpp_run(xmpp_server_t *srv,
        if (srv->state == XMPP_RECV_JID) {
                if (match(start, "jid")) {
                        debug("xmpp: jid -> presence");
+                       //net_print(&srv->net,
+                       //      "<iq id='ping' type='get' from='%s' to='%s'>"
+                       //      "<ping xmlns='urn:xmpp:ping'/>"
+                       //      "</iq>",
+                       //      srv->jid, srv->host);
                        srv->state = XMPP_SEND_PRESENCE;
                }
        }
        if (srv->state == XMPP_SEND_PRESENCE) {
+               net_print(&srv->net, "<presence/>");
                for (channel_t *cur = channels; cur; cur = cur->next) {
                        xmpp_channel_t *chan = (xmpp_channel_t*)cur;
                        if (cur->server != &srv->server || !chan->join)
@@ -415,7 +421,8 @@ static void xmpp_run(xmpp_server_t *srv,
                             match(start, "presence") ? XMPP_IN_PRESENCE :
                                                        XMPP_READY;
                if (srv->state != XMPP_READY) {
-                       strncpy(srv->msg_jid, find_attr(attrs, "from"), JID_LEN);
+                       const char *from = find_attr(attrs, "from") ?: "";
+                       strncpy(srv->msg_jid, from, JID_LEN);
                        split_jid(srv->msg_jid, srv->msg_usr,
                                  srv->msg_srv, srv->msg_res);
 
@@ -546,6 +553,14 @@ static void xmpp_run(xmpp_server_t *srv,
                        srv->msg_res[0] = '\0';
                        srv->msg_from   = NULL;
                        srv->msg_chan   = NULL;
+
+                       static time_t due = 0;
+                       static time_t now = 0;
+                       now = time(NULL);
+                       if (now > due) {
+                               net_print(&srv->net, "<presence/>");
+                               due = now + 30;
+                       }
                }
        }
        /* Error handling */