From 883a216d2a5f3d3cbddd230796d15da0af9bfab7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 24 Apr 2015 12:29:31 -0700 Subject: [PATCH] Build fixes. --- controller/SqliteNetworkController.cpp | 17 +++++++++-- controller/SqliteNetworkController.hpp | 1 + controller/controller-api-test.sh | 42 ++++++++++++++++++++++++++ service/ControlPlane.cpp | 6 ++-- service/ControlPlane.hpp | 1 + service/OneService.cpp | 2 +- 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 controller/controller-api-test.sh diff --git a/controller/SqliteNetworkController.cpp b/controller/SqliteNetworkController.cpp index a2bc5fc3a..b9aebbb8a 100644 --- a/controller/SqliteNetworkController.cpp +++ b/controller/SqliteNetworkController.cpp @@ -178,6 +178,7 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) : ||(sqlite3_prepare_v2(_db,"INSERT INTO Network (networkId,name,creationTime,revision) VALUES (?,?,?,1)",-1,&_sCreateNetwork,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"UPDATE Network SET ? = ? WHERE networkId = ?",-1,&_sUpdateNetworkField,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"SELECT revision FROM Network WHERE id = ?",-1,&_sGetNetworkRevision,(const char **)0) != SQLITE_OK) + ||(sqlite3_prepare_v2(_db,"UPDATE Network SET revision = ? WHERE id = ?",-1,&_sSetNetworkRevision,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"SELECT ip,ipNetmaskBits,ipVersion FROM IpAssignment WHERE networkId = ? AND nodeId = ?",-1,&_sGetIpAssignmentsForNode2,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"DELETE FROM Relay WHERE networkId = ?",-1,&_sDeleteRelaysForNetwork,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"INSERT INTO Relay (networkId,nodeId,phyAddress) VALUES (?,?,?)",-1,&_sCreateRelay,(const char **)0) != SQLITE_OK) @@ -220,6 +221,7 @@ SqliteNetworkController::~SqliteNetworkController() sqlite3_finalize(_sCreateNetwork); sqlite3_finalize(_sUpdateNetworkField); sqlite3_finalize(_sGetNetworkRevision); + sqlite3_finalize(_sSetNetworkRevision); sqlite3_finalize(_sGetIpAssignmentsForNode2); sqlite3_finalize(_sDeleteRelaysForNetwork); sqlite3_finalize(_sCreateRelay); @@ -841,11 +843,17 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST( int64_t revision = 0; sqlite3_reset(_sGetNetworkRevision); sqlite3_bind_text(_sGetNetworkRevision,1,nwids,16,SQLITE_STATIC); - if (sqlite3_step(_sGetNetworkRevision) == SQLITE_ROW) + bool networkExists = false; + if (sqlite3_step(_sGetNetworkRevision) == SQLITE_ROW) { + networkExists = true; revision = sqlite3_column_int64(_sGetNetworkRevision,0); + } if (path.size() >= 3) { + if (!networkExists) + return 404; + if ((path.size() == 4)&&(path[2] == "member")&&(path[3].length() == 10)) { uint64_t address = Utils::hexStrToU64(path[3].c_str()); char addrs[24]; @@ -856,7 +864,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST( } else { - if (revision <= 0) { + if (!networkExists) { sqlite3_reset(_sCreateNetwork); sqlite3_bind_text(_sCreateNetwork,1,nwids,16,SQLITE_STATIC); sqlite3_bind_text(_sCreateNetwork,2,nwids,16,SQLITE_STATIC); // default name, will be changed below if a name is specified in JSON @@ -1081,6 +1089,11 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST( json_value_free(j); } + sqlite3_reset(_sSetNetworkRevision); + sqlite3_bind_int64(_sSetNetworkRevision,1,revision += 1); + sqlite3_bind_text(_sSetNetworkRevision,2,nwids,16,SQLITE_STATIC); + sqlite3_step(_sSetNetworkRevision); + return handleControlPlaneHttpGET(path,urlArgs,headers,body,responseBody,responseContentType); } diff --git a/controller/SqliteNetworkController.hpp b/controller/SqliteNetworkController.hpp index 72f1e2033..c61829c3a 100644 --- a/controller/SqliteNetworkController.hpp +++ b/controller/SqliteNetworkController.hpp @@ -113,6 +113,7 @@ private: sqlite3_stmt *_sCreateNetwork; sqlite3_stmt *_sUpdateNetworkField; sqlite3_stmt *_sGetNetworkRevision; + sqlite3_stmt *_sSetNetworkRevision; sqlite3_stmt *_sGetIpAssignmentsForNode2; sqlite3_stmt *_sDeleteRelaysForNetwork; sqlite3_stmt *_sCreateRelay; diff --git a/controller/controller-api-test.sh b/controller/controller-api-test.sh new file mode 100755 index 000000000..934685b38 --- /dev/null +++ b/controller/controller-api-test.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +if [ "$#" -ne "2" ]; then + echo 'Usage: controller-api-test.sh ' + exit 1 +fi + +network_json=$(cat <addAuthToken(authToken.c_str()); if (_master) - _controlPlane->mount("controller",_master); + _controlPlane->mount("controller",reinterpret_cast(_master)); { // Remember networks from previous session std::vector networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));