libsysutils: Move to a null terminated string protocol using space as a field separator.

    Also removes some debugging

Signed-off-by: San Mehat <san@google.com>
diff --git a/include/sysutils/FrameworkCommand.h b/include/sysutils/FrameworkCommand.h
index 5b50247..6c1fca6 100644
--- a/include/sysutils/FrameworkCommand.h
+++ b/include/sysutils/FrameworkCommand.h
@@ -29,7 +29,7 @@
     FrameworkCommand(const char *cmd);
     virtual ~FrameworkCommand() { }
 
-    virtual int runCommand(SocketClient *c, char *data) = 0;
+    virtual int runCommand(SocketClient *c, int argc, char **argv) = 0;
 
     const char *getCommand() { return mCommand; }
 };
diff --git a/include/sysutils/FrameworkListener.h b/include/sysutils/FrameworkListener.h
index 8a83c33..4e3d396 100644
--- a/include/sysutils/FrameworkListener.h
+++ b/include/sysutils/FrameworkListener.h
@@ -22,6 +22,8 @@
 class SocketClient;
 
 class FrameworkListener : public SocketListener {
+public:
+    static const int CMD_ARGS_MAX = 8;
 private:
     FrameworkCommandCollection *mCommands;
 
@@ -34,6 +36,6 @@
     virtual bool onDataAvailable(SocketClient *c);
 
 private:
-    void dispatchCommand(SocketClient *c, char *cmd);
+    void dispatchCommand(SocketClient *c, char *data);
 };
 #endif
diff --git a/libsysutils/src/FrameworkCommand.cpp b/libsysutils/src/FrameworkCommand.cpp
index 94e7426..c52eac7 100644
--- a/libsysutils/src/FrameworkCommand.cpp
+++ b/libsysutils/src/FrameworkCommand.cpp
@@ -25,7 +25,7 @@
     mCommand = cmd;
 }
 
-int FrameworkCommand::runCommand(SocketClient *c, char *data) {
+int FrameworkCommand::runCommand(SocketClient *c, int argc, char **argv) {
     LOGW("Command %s has no run handler!", getCommand());
     errno = ENOSYS;
     return -1;
diff --git a/libsysutils/src/FrameworkListener.cpp b/libsysutils/src/FrameworkListener.cpp
index e8ae847..e9ca897 100644
--- a/libsysutils/src/FrameworkListener.cpp
+++ b/libsysutils/src/FrameworkListener.cpp
@@ -36,17 +36,14 @@
     if ((len = read(c->getSocket(), buffer, sizeof(buffer) -1)) < 0) {
         LOGE("read() failed (%s)", strerror(errno));
         return errno;
-    } else if (!len) {
-        LOGW("Lost connection to client");
+    } else if (!len)
         return false;
-    }
 
     int offset = 0;
     int i;
 
     for (i = 0; i < len; i++) {
-        if (buffer[i] == '\n') {
-            buffer[i] = '\0';
+        if (buffer[i] == '\0') {
             dispatchCommand(c, buffer + offset);
             offset = i + 1;
         }
@@ -58,13 +55,20 @@
     mCommands->push_back(cmd);
 }
 
-void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) {
-    char *next = cmd;
-    char *cm;
-    char *arg;
+void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
+    int argc;
+    char *argv[FrameworkListener::CMD_ARGS_MAX];
 
-    if (!(cm = strsep(&next, ":"))) {
-        cli->sendMsg(500, "Malformatted message", false);
+    if (!index(data, '"')) {
+        char *next = data;
+        char *field;
+        int i;
+
+        for (i = 0; (i < FrameworkListener::CMD_ARGS_MAX) &&
+                    (argv[i] = strsep(&next, " ")); i++);
+        argc = i+1;
+    } else {
+        LOGD("blehhh not supported");
         return;
     }
 
@@ -73,8 +77,8 @@
     for (i = mCommands->begin(); i != mCommands->end(); ++i) {
         FrameworkCommand *c = *i;
 
-        if (!strcmp(cm, c->getCommand())) {
-            if (c->runCommand(cli, next)) {
+        if (!strcmp(argv[0], c->getCommand())) {
+            if (c->runCommand(cli, argc, argv)) {
                 LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
             }
             return;
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index f0e846f..857ed4d 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -33,19 +33,10 @@
         return -1;
     }
 
-    char *tmp;
-    const char *bp = msg;
-
-    if (msg[strlen(msg)] != '\n') {
-        tmp = (char *) alloca(strlen(msg) + 1);
-        strcpy(tmp, msg);
-        strcat(tmp, "\n");
-        bp = tmp;
-    }
-
+    // Send the message including null character
     int rc = 0;
-    const char *p = bp;
-    int brtw = strlen(bp);
+    const char *p = msg;
+    int brtw = strlen(msg) + 1;
 
     pthread_mutex_lock(&mWriteMutex);
     while(brtw) {
diff --git a/libsysutils/src/SocketListener.cpp b/libsysutils/src/SocketListener.cpp
index 1f80121..1a937c2 100644
--- a/libsysutils/src/SocketListener.cpp
+++ b/libsysutils/src/SocketListener.cpp
@@ -157,7 +157,6 @@
                 if (FD_ISSET(fd, &read_fds)) {
                     pthread_mutex_unlock(&mClientsLock);
                     if (!onDataAvailable(*it)) {
-                        LOGD("SocketListener closing client socket");
                         close(fd);
                         pthread_mutex_lock(&mClientsLock);
                         delete *it;