diff options
Diffstat (limited to 'libsysutils')
-rw-r--r-- | libsysutils/src/FrameworkCommand.cpp | 2 | ||||
-rw-r--r-- | libsysutils/src/FrameworkListener.cpp | 30 | ||||
-rw-r--r-- | libsysutils/src/SocketClient.cpp | 15 | ||||
-rw-r--r-- | libsysutils/src/SocketListener.cpp | 1 |
4 files changed, 21 insertions, 27 deletions
diff --git a/libsysutils/src/FrameworkCommand.cpp b/libsysutils/src/FrameworkCommand.cpp index 94e7426ca..c52eac76f 100644 --- a/libsysutils/src/FrameworkCommand.cpp +++ b/libsysutils/src/FrameworkCommand.cpp @@ -25,7 +25,7 @@ FrameworkCommand::FrameworkCommand(const char *cmd) { 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 e8ae8478e..e9ca8977f 100644 --- a/libsysutils/src/FrameworkListener.cpp +++ b/libsysutils/src/FrameworkListener.cpp @@ -36,17 +36,14 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) { 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 @@ void FrameworkListener::registerCmd(FrameworkCommand *cmd) { 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 (!index(data, '"')) { + char *next = data; + char *field; + int i; - if (!(cm = strsep(&next, ":"))) { - cli->sendMsg(500, "Malformatted message", false); + 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 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *cmd) { 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 f0e846f4f..857ed4d10 100644 --- a/libsysutils/src/SocketClient.cpp +++ b/libsysutils/src/SocketClient.cpp @@ -33,19 +33,10 @@ int SocketClient::sendMsg(const char *msg) { 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 1f80121a5..1a937c296 100644 --- a/libsysutils/src/SocketListener.cpp +++ b/libsysutils/src/SocketListener.cpp @@ -157,7 +157,6 @@ void SocketListener::runListener() { 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; |