summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike <mjc@avtechpulse.com>2000-01-01 02:16:19 +0900
committerMike <mjc@avtechpulse.com>2000-01-01 02:16:19 +0900
commit8b01a22ac70e86118b232bd2ae35433ac97f8418 (patch)
tree23fbfc18c233811a4ef7d256b699c3e8ed1b1cd5
parent58fd38e868db4dd690a3c2164857f377b19df841 (diff)
Split inputs into separate lines when multiple interactive commands are received
-rw-r--r--globals.h4
-rw-r--r--instr-client.c14
-rw-r--r--nicutils.c6
-rw-r--r--parser.c18
4 files changed, 29 insertions, 13 deletions
diff --git a/globals.h b/globals.h
index 809d526..e753067 100644
--- a/globals.h
+++ b/globals.h
@@ -16,6 +16,10 @@
#endif
+/* comms */
+#define STDBUFSIZE 1024
+
+
/* error codes */
#define OK 0
#define Unrecognized 1
diff --git a/instr-client.c b/instr-client.c
index 6685176..29a3fe0 100644
--- a/instr-client.c
+++ b/instr-client.c
@@ -8,9 +8,9 @@
#include <glib/gprintf.h>
#include "response.h"
+#include "globals.h"
static int port = 3333;
-#define BUFSIZE 1024
GMainContext *context=NULL;
GMainLoop *mainLoop=NULL;
@@ -54,9 +54,9 @@ static gboolean Matches(char *src, char* dst, gssize size)
static gboolean
stdinAvailable (GIOChannel *source, GIOCondition condition, gpointer data)
{
- char tmp[BUFSIZE];
- memset(tmp,0,BUFSIZE);
- int size = read(0, tmp, BUFSIZE);
+ char tmp[STDBUFSIZE];
+ memset(tmp,0,STDBUFSIZE);
+ int size = read(0, tmp, STDBUFSIZE);
if(size<=0) {
return TRUE;
}
@@ -133,14 +133,14 @@ stdinAvailable (GIOChannel *source, GIOCondition condition, gpointer data)
//callback for server input
static gboolean cbServerInput(gpointer data, gpointer additional)
{
- char buffer[BUFSIZE];
+ char buffer[STDBUFSIZE];
gssize size=0;
- memset(buffer,0,BUFSIZE);
+ memset(buffer,0,STDBUFSIZE);
GPollableInputStream* inStream = (GPollableInputStream*)data;
GError *error = NULL;
- size=g_pollable_input_stream_read_nonblocking(inStream, buffer, BUFSIZE, NULL, &error);
+ size=g_pollable_input_stream_read_nonblocking(inStream, buffer, STDBUFSIZE, NULL, &error);
if(size <=0) {
terminate("Connection to server lost", -1);
}
diff --git a/nicutils.c b/nicutils.c
index 4396858..0d42a66 100644
--- a/nicutils.c
+++ b/nicutils.c
@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <unistd.h>
-#define BUFSIZE 8192
+#define NIC_BUF_SIZE 8192
static int netlink_createsock()
{
@@ -128,7 +128,7 @@ static char* route_defaultrouteint()
}
/* Initialize the buffer */
- char* msgBuf = calloc(BUFSIZE, 1);
+ char* msgBuf = calloc(NIC_BUF_SIZE, 1);
if (msgBuf == NULL) {
goto exit;
}
@@ -150,7 +150,7 @@ static char* route_defaultrouteint()
}
/* Read the response */
- if ((len = netlink_readsock(sock, msgBuf, msgSeq, getpid(), BUFSIZE)) < 0) {
+ if ((len = netlink_readsock(sock, msgBuf, msgSeq, getpid(), NIC_BUF_SIZE)) < 0) {
goto exit;
}
diff --git a/parser.c b/parser.c
index bcb2f46..e5a1643 100644
--- a/parser.c
+++ b/parser.c
@@ -609,7 +609,11 @@ static gchar* regex_replace (gchar* in_string, gchar* regex_string, gchar* repla
static gchar* filter_input (gchar *raw_in)
{
g_strstrip (raw_in);
- gchar *step1 = g_strdup (raw_in);
+ gchar *step0 = g_strdup (raw_in);
+
+ // replace weird characters with a space
+ gchar *step1 = regex_replace (step0, "[^\x20-\x7E]+", " ");
+ g_free (step0);
// replace multiple whitespace with single space
gchar *step2 = regex_replace (step1, "\\s+", " ");
@@ -643,6 +647,14 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock (&mutex);
+ gchar **v;
+ v = g_strsplit_set (raw_in, "\r\n", STDBUFSIZE);
+
+ int str_chunk;
+
+ for (str_chunk=0; v[str_chunk] > 0; ++str_chunk) {
+ gchar *in = filter_input (v[str_chunk]);
+
int in_pos; /* this identifies the single character of in being processed */
int command_depth; /* how many command words have been parsed */
int old_command_depth; /* save this if in case of a compound message */
@@ -665,8 +677,6 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
int channel;
int with_id_code;
- gchar *in = filter_input (raw_in);
-
in_pos = 0; /* start at the beginning of the input string */
semicolon_found = 0;
compound_message = 0;
@@ -1118,6 +1128,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer
}
g_free (in);
+ }
+ g_strfreev (v);
g_static_mutex_unlock (&mutex);
}