Fixed filter, and the client now parses ~~~ and ~~. (closing client)
authorviric@llimona
Mon, 08 Oct 2007 12:16:30 +0200
changeset 76 5c0b9c9f9801
parent 75 525a97517dc7
child 77 24b0568ba017
Fixed filter, and the client now parses ~~~ and ~~. (closing client)
Makefile
client.c
filter.c
filter.h
gen_sockets.c
unix_client.c
--- a/Makefile	Mon Oct 08 12:15:46 2007 +0200
+++ b/Makefile	Mon Oct 08 12:16:30 2007 +0200
@@ -21,6 +21,7 @@
 	flow.o \
 	filter.o \
 	filter_string.o \
+	filter_tildes.o \
 	filter_telnet.o $(LINUX_OBJECTS)
 
 all: tm
--- a/client.c	Mon Oct 08 12:15:46 2007 +0200
+++ b/client.c	Mon Oct 08 12:16:30 2007 +0200
@@ -80,10 +80,16 @@
             if (client_termin_fr)
             {
                 int olen;
-                filter_stream(client_termin_fr, ostream_buffer, &olen,
+                /* We use ostream_buffer2 for data from the
+                 * keyboard to the tm client, because
+                 * *_client.c use the ostream_buffer for data
+                 * from the server to us (tm client). */
+                hex_dump("Client prefilter", stream_buffer, res);
+                filter_stream(client_termin_fr, ostream_buffer2, &olen,
                         stream_buffer,
                         res);
-                net_send(ostream_buffer, olen);
+                if (olen > 0)
+                    net_send(ostream_buffer2, olen);
             }
             else
                 net_send(stream_buffer, res);
@@ -93,10 +99,18 @@
     } while (1);
 }
 
-void filtercb_killer(struct FilterRules *fr, const struct FFilter *ff,
+void filtercb_tildes(struct FilterRules *fr, const struct FFilter *ff,
         char *obuf, int *olen, const char *ibuf, int pos)
 {
-    kill(getpid(), SIGINT);
+    dump_line("filtercb_tildes: '%c'\n", ibuf[pos+3]);
+    if (ibuf[pos+3] == '.')
+        kill(getpid(), SIGINT);
+    else
+    {
+        obuf[(*olen)++] = '~';
+        obuf[(*olen)++] = '~';
+        obuf[(*olen)++] = '~';
+    }
 }
 
 int client()
@@ -114,8 +128,8 @@
         if (command_line.c_param.raw_mode)
         {
             client_termin_fr = new_filter_rules();
-            ff = new_fstring("\x1d");
-            ff->callback = filtercb_killer;
+            ff = new_ftildes();
+            ff->callback = filtercb_tildes;
             add_ffilter(client_termin_fr, ff);
         }
     }
--- a/filter.c	Mon Oct 08 12:15:46 2007 +0200
+++ b/filter.c	Mon Oct 08 12:16:30 2007 +0200
@@ -154,8 +154,23 @@
         fr->fbuffer = realloc(fr->fbuffer, max_matched);
         if (fr->fbuffer == 0) error("Cannot allocate fbuffer");
     }
-    memcpy(fr->fbuffer, buffer + len - max_matched, max_matched);
-    fr->fbuffer_len = max_matched;
+    /* Copy only new data from buffer */
+    {
+        int start_new_data;
+        int size_cpy;
+        int offset;
+        size_cpy = max_matched;
+        start_new_data = len - max_matched;
+        offset = 0;
+        if (start_new_data < 0)
+        {
+            offset += (-start_new_data);
+            size_cpy -= (-start_new_data);
+            start_new_data = 0;
+        }
+        memcpy(fr->fbuffer + offset, buffer + start_new_data, size_cpy);
+        fr->fbuffer_len = max_matched;
+    }
 }
 
 void filter_flush(struct FilterRules *fr, char *obuf, int *olen)
--- a/filter.h	Mon Oct 08 12:15:46 2007 +0200
+++ b/filter.h	Mon Oct 08 12:16:30 2007 +0200
@@ -37,3 +37,6 @@
 
 /* filter_telnet.c */
 struct FFilter *new_ftelnet();
+
+/* filter_tildes.c */
+struct FFilter *new_ftildes();
--- a/gen_sockets.c	Mon Oct 08 12:15:46 2007 +0200
+++ b/gen_sockets.c	Mon Oct 08 12:16:30 2007 +0200
@@ -13,8 +13,10 @@
 
 char *stream_buffer = 0;
 char *ostream_buffer = 0;
+char *ostream_buffer2 = 0;
 int stream_buffer_size;
 int ostream_buffer_size;
+int ostream_buffer2_size;
 
 void init_stream_buffers()
 {
@@ -32,9 +34,12 @@
             stream_buffer_size = min(command_line.buffer_size, eth_buf);
         }
 #endif
+        stream_buffer = (char *) malloc(stream_buffer_size);
+
         ostream_buffer_size = stream_buffer_size;
-        stream_buffer = (char *) malloc(stream_buffer_size);
         ostream_buffer = (char *) malloc(ostream_buffer_size);
+        ostream_buffer2_size = stream_buffer_size;
+        ostream_buffer2 = (char *) malloc(ostream_buffer_size);
     }
 }
 
--- a/unix_client.c	Mon Oct 08 12:15:46 2007 +0200
+++ b/unix_client.c	Mon Oct 08 12:16:30 2007 +0200
@@ -71,5 +71,5 @@
 void c_unix_send(const char *buf, size_t len)
 {
     hex_dump("send_unix_client",buf, len);
-    write(conn_socket, stream_buffer, len);
+    write(conn_socket, buf, len);
 }