Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c8dee81 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 6822

* changes:
  nexus: Rollup update for nexus
parents feb63e9e c4a895b7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public:
    SocketListener(const char *socketNames, bool listen);
    SocketListener(int socketFd, bool listen);

    virtual ~SocketListener() {}
    virtual ~SocketListener();
    int startListener();
    int stopListener();

+67 −14
Original line number Diff line number Diff line
@@ -56,23 +56,72 @@ void FrameworkListener::registerCmd(FrameworkCommand *cmd) {
}

void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
    int argc;
    FrameworkCommandCollection::iterator i;
    int argc = 0;
    char *argv[FrameworkListener::CMD_ARGS_MAX];
    char tmp[255];
    char *p = data;
    char *q = tmp;
    bool esc = false;
    bool quote = false;
    int k;

    memset(argv, 0, sizeof(argv));
    memset(tmp, 0, sizeof(tmp));
    while(*p) {
        if (*p == '\\') {
            if (esc) {
                *q++ = '\\';
                esc = false;
            } else
                esc = true;
            p++;
            continue;
        } else if (esc) {
            if (*p == '"')
                *q++ = '"';
            else if (*p == '\\')
                *q++ = '\\';
            else {
                cli->sendMsg(500, "Unsupported escape sequence", false);
                goto out;
            }
            p++;
            esc = false;
            continue;
        }

    if (!index(data, '"')) {
        char *next = data;
        char *field;
        int i;
        if (*p == '"') {
            if (quote)
                quote = false;
            else
                quote = true;
            p++;
            continue;
        }

        for (i = 0; (i < FrameworkListener::CMD_ARGS_MAX) &&
                    (argv[i] = strsep(&next, " ")); i++);
        argc = i+1;
    } else {
        LOGD("blehhh not supported");
        return;
        *q = *p++;
        if (!quote && *q == ' ') {
            *q = '\0';
            argv[argc++] = strdup(tmp);
            memset(tmp, 0, sizeof(tmp));
            q = tmp;
            continue;
        }
        q++;
    }

    FrameworkCommandCollection::iterator i;
    argv[argc++] = strdup(tmp);
#if 0
    for (k = 0; k < argc; k++) {
        LOGD("arg[%d] = '%s'", k, argv[k]);
    }
#endif

    if (quote) {
        cli->sendMsg(500, "Unclosed quotes error", false);
        goto out;
    }
    
    for (i = mCommands->begin(); i != mCommands->end(); ++i) {
        FrameworkCommand *c = *i;
@@ -81,10 +130,14 @@ void FrameworkListener::dispatchCommand(SocketClient *cli, char *data) {
            if (c->runCommand(cli, argc, argv)) {
                LOGW("Handler '%s' error (%s)", c->getCommand(), strerror(errno));
            }
            return;
            goto out;
        }
    }

    cli->sendMsg(500, "Command not recognized", false);
out:
    int j;
    for (j = 0; j < argc; j++)
        free(argv[j]);
    return;
}
+36 −2
Original line number Diff line number Diff line
@@ -45,9 +45,26 @@ SocketListener::SocketListener(int socketFd, bool listen) {
    mClients = new SocketClientCollection();
}

SocketListener::~SocketListener() {
    if (mSocketName && mSock > -1)
        close(mSock);

    if (mCtrlPipe[0] != -1) {
        close(mCtrlPipe[0]);
        close(mCtrlPipe[1]);
    }
    SocketClientCollection::iterator it;
    for (it = mClients->begin(); it != mClients->end(); ++it) {
        delete (*it);
        it = mClients->erase(it);
    }
    delete mClients;
}

int SocketListener::startListener() {

    if (!mSocketName && mSock == -1) {
        LOGE("Failed to start unbound listener");
        errno = EINVAL;
        return -1;
    } else if (mSocketName) {
@@ -64,11 +81,15 @@ int SocketListener::startListener() {
    } else if (!mListen)
        mClients->push_back(new SocketClient(mSock));

    if (pipe(mCtrlPipe))
    if (pipe(mCtrlPipe)) {
        LOGE("pipe failed (%s)", strerror(errno));
        return -1;
    }

    if (pthread_create(&mThread, NULL, SocketListener::threadStart, this))
    if (pthread_create(&mThread, NULL, SocketListener::threadStart, this)) {
        LOGE("pthread_create (%s)", strerror(errno));
        return -1;
    }

    return 0;
}
@@ -88,6 +109,19 @@ int SocketListener::stopListener() {
    }
    close(mCtrlPipe[0]);
    close(mCtrlPipe[1]);
    mCtrlPipe[0] = -1;
    mCtrlPipe[1] = -1;

    if (mSocketName && mSock > -1) {
        close(mSock);
        mSock = -1;
    }

    SocketClientCollection::iterator it;
    for (it = mClients->begin(); it != mClients->end(); ++it) {
        delete (*it);
        it = mClients->erase(it);
    }
    return 0;
}

+13 −11
Original line number Diff line number Diff line
@@ -7,23 +7,22 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES:=                                      \
                  main.cpp                             \
                  NetworkManager.cpp                   \
                  NexusCommand.cpp                     \
                  CommandListener.cpp                  \
                  Property.cpp                         \
                  PropertyManager.cpp                  \
                  InterfaceConfig.cpp                  \
                  NetworkManager.cpp                   \
                  Controller.cpp                       \
                  WifiController.cpp                   \
                  LoopController.cpp                   \
                  NexusCommand.cpp                     \
                  TiwlanWifiController.cpp             \
                  TiwlanEventListener.cpp              \
                  WifiNetwork.cpp                      \
                  WifiStatusPoller.cpp                 \
                  ScanResult.cpp                       \
                  Supplicant.cpp                       \
                  SupplicantEvent.cpp                  \
                  SupplicantListener.cpp               \
                  VpnController.cpp                    \
                  ScanResult.cpp                       \
                  WifiScanner.cpp                      \
                  WifiNetwork.cpp                      \
                  OpenVpnController.cpp                \
                  InterfaceConfig.cpp                  \
                  PropertyManager.cpp                  \
                  SupplicantState.cpp                  \
                  SupplicantEventFactory.cpp           \
                  SupplicantConnectedEvent.cpp         \
@@ -34,8 +33,11 @@ LOCAL_SRC_FILES:= \
                  SupplicantConnectionTimeoutEvent.cpp \
                  SupplicantDisconnectedEvent.cpp      \
                  SupplicantStatus.cpp                 \
                  TiwlanEventListener.cpp              \
                  OpenVpnController.cpp                \
                  VpnController.cpp                    \
                  LoopController.cpp                   \
                  DhcpClient.cpp DhcpListener.cpp      \
                  DhcpState.cpp DhcpEvent.cpp          \

LOCAL_MODULE:= nexus

+23 −19
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
#include "NetworkManager.h"
#include "WifiController.h"
#include "VpnController.h"
#include "ErrorCode.h"
#include "ResponseCode.h"

CommandListener::CommandListener() :
                 FrameworkListener("nexus") {
@@ -60,11 +60,11 @@ int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli,
    WifiNetwork *wn;

    if (!(wn = wc->createNetwork()))
        cli->sendMsg(ErrorCode::OperationFailed, "Failed to create network", true);
        cli->sendMsg(ResponseCode::OperationFailed, "Failed to create network", true);
    else {
        char tmp[128];
        sprintf(tmp, "Created network id %d.", wn->getNetworkId());
        cli->sendMsg(ErrorCode::CommandOkay, tmp, false);
        cli->sendMsg(ResponseCode::CommandOkay, tmp, false);
    }
    return 0;
}
@@ -79,9 +79,9 @@ int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli,
    WifiController *wc = (WifiController *) nm->findController("WIFI");

    if (wc->removeNetwork(atoi(argv[1])))
        cli->sendMsg(ErrorCode::OperationFailed, "Failed to remove network", true);
        cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove network", true);
    else {
        cli->sendMsg(ErrorCode::CommandOkay, "Network removed.", false);
        cli->sendMsg(ResponseCode::CommandOkay, "Network removed.", false);
    }
    return 0;
}
@@ -100,16 +100,16 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli,
    char buffer[256];

    for(it = src->begin(); it != src->end(); ++it) {
        sprintf(buffer, "%s:%u:%d:%s:%s",
        sprintf(buffer, "%s %u %d %s %s",
                (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(),
                (*it)->getFlags(), (*it)->getSsid());
        cli->sendMsg(ErrorCode::WifiScanResult, buffer, false);
        cli->sendMsg(ResponseCode::WifiScanResult, buffer, false);
        delete (*it);
        it = src->erase(it);
    }

    delete src;
    cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete.", false);
    cli->sendMsg(ResponseCode::CommandOkay, "Scan results complete.", false);
    return 0;
}

@@ -128,12 +128,12 @@ int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli,

    for(it = src->begin(); it != src->end(); ++it) {
        sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
        cli->sendMsg(ErrorCode::WifiNetworkList, buffer, false);
        cli->sendMsg(ResponseCode::WifiNetworkList, buffer, false);
        delete (*it);
    }

    delete src;
    cli->sendMsg(ErrorCode::CommandOkay, "Network listing complete.", false);
    cli->sendMsg(ResponseCode::CommandOkay, "Network listing complete.", false);
    return 0;
}

@@ -159,14 +159,14 @@ int CommandListener::GetCmd::runCommand(SocketClient *cli, int argc, char **argv

    char *tmp;
    asprintf(&tmp, "%s %s", argv[1], val);
    cli->sendMsg(ErrorCode::PropertyRead, tmp, false);
    cli->sendMsg(ResponseCode::PropertyRead, tmp, false);
    free(tmp);

    cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false);
    cli->sendMsg(ResponseCode::CommandOkay, "Property read.", false);
    return 0;
out_inval:
    errno = EINVAL;
    cli->sendMsg(ErrorCode::CommandParameterError, "Failed to read property.", true);
    cli->sendMsg(ResponseCode::CommandParameterError, "Failed to read property.", true);
    return 0;
}

@@ -179,12 +179,12 @@ int CommandListener::SetCmd::runCommand(SocketClient *cli, int argc,
    if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2]))
        goto out_inval;

    cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false);
    cli->sendMsg(ResponseCode::CommandOkay, "Property set.", false);
    return 0;

out_inval:
    errno = EINVAL;
    cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true);
    cli->sendMsg(ResponseCode::CommandParameterError, "Failed to set property.", true);
    return 0;
}

@@ -194,10 +194,14 @@ CommandListener::ListCmd::ListCmd() :

int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) {
    android::List<char *> *pc;
    char *prefix = NULL;

    if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList())) {
    if (argc > 1)
        prefix = argv[1];

    if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList(prefix))) {
        errno = ENODATA;
        cli->sendMsg(ErrorCode::CommandParameterError, "Failed to list properties.", true);
        cli->sendMsg(ResponseCode::CommandParameterError, "Failed to list properties.", true);
        return 0;
    }

@@ -218,7 +222,7 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **arg
            free((*it));
            continue;
        }
        cli->sendMsg(ErrorCode::PropertyList, buf, false);
        cli->sendMsg(ResponseCode::PropertyList, buf, false);
        free(buf);

        free((*it));
@@ -226,6 +230,6 @@ int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **arg

    delete pc;

    cli->sendMsg(ErrorCode::CommandOkay, "Properties list complete.", false);
    cli->sendMsg(ResponseCode::CommandOkay, "Properties list complete.", false);
    return 0;
}
Loading