summaryrefslogtreecommitdiffstats
path: root/libsysutils
diff options
context:
space:
mode:
authorRobert Greenwalt <rgreenwalt@google.com>2012-04-20 15:21:07 -0700
committerRobert Greenwalt <rgreenwalt@google.com>2012-04-20 17:41:42 -0700
commit594947793c98e8e7f58f0e9b2cb962c9ef23adeb (patch)
tree01be6143d60f80dec1048e5cea81c819e0d96ff2 /libsysutils
parent545ab46063f083239b29e59b8b491656d93f2a38 (diff)
downloadsystem_core-594947793c98e8e7f58f0e9b2cb962c9ef23adeb.zip
system_core-594947793c98e8e7f58f0e9b2cb962c9ef23adeb.tar.gz
system_core-594947793c98e8e7f58f0e9b2cb962c9ef23adeb.tar.bz2
Add ability to quote responses as needed.
It's up to the protocol to know when quotes are required. In the future the response should probably all be binary blobs with lengths. bug:6353048 Change-Id: I3f9b48ab0f4e6746d75cdc9c0c84d33f38f63661
Diffstat (limited to 'libsysutils')
-rw-r--r--libsysutils/src/SocketClient.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 1533120..4a1227f 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -107,6 +107,29 @@ int SocketClient::sendCode(int code) {
return sendData(buf, sizeof(buf));
}
+char *SocketClient::quoteArg(const char *arg) {
+ int len = strlen(arg);
+ char *result = (char *)malloc(len * 2 + 3);
+ char *current = result;
+ const char *end = arg + len;
+
+ *(current++) = '"';
+ while (arg < end) {
+ switch (*arg) {
+ case '\\':
+ case '"':
+ *(current++) = '\\'; // fallthrough
+ default:
+ *(current++) = *(arg++);
+ }
+ }
+ *(current++) = '"';
+ *(current++) = '\0';
+ result = (char *)realloc(result, current-result);
+ return result;
+}
+
+
int SocketClient::sendMsg(const char *msg) {
if (mSocket < 0) {
errno = EHOSTUNREACH;