mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-21 13:57:49 +00:00
more error checking
This commit is contained in:
parent
79086f0858
commit
4c0e7aa8b0
@ -213,17 +213,44 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
|||||||
|
|
||||||
config["id"] = PQgetvalue(res, i, 0);
|
config["id"] = PQgetvalue(res, i, 0);
|
||||||
config["nwid"] = PQgetvalue(res, i, 0);
|
config["nwid"] = PQgetvalue(res, i, 0);
|
||||||
|
try {
|
||||||
config["creationTime"] = std::stoull(PQgetvalue(res, i, 1));
|
config["creationTime"] = std::stoull(PQgetvalue(res, i, 1));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["creationTime"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error converting creation time: %s\n", PQgetvalue(res, i, 1));
|
||||||
|
}
|
||||||
config["capabilities"] = json::parse(PQgetvalue(res, i, 2));
|
config["capabilities"] = json::parse(PQgetvalue(res, i, 2));
|
||||||
config["enableBroadcast"] = (strcmp(PQgetvalue(res, i, 3),"t")==0);
|
config["enableBroadcast"] = (strcmp(PQgetvalue(res, i, 3),"t")==0);
|
||||||
|
try {
|
||||||
config["lastModified"] = std::stoull(PQgetvalue(res, i, 4));
|
config["lastModified"] = std::stoull(PQgetvalue(res, i, 4));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["lastModified"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error converting last modified: %s\n", PQgetvalue(res, i, 4));
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["mtu"] = std::stoi(PQgetvalue(res, i, 5));
|
config["mtu"] = std::stoi(PQgetvalue(res, i, 5));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["mtu"] = 2800;
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["multicastLimit"] = std::stoi(PQgetvalue(res, i, 6));
|
config["multicastLimit"] = std::stoi(PQgetvalue(res, i, 6));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["multicastLimit"] = 64;
|
||||||
|
}
|
||||||
config["name"] = PQgetvalue(res, i, 7);
|
config["name"] = PQgetvalue(res, i, 7);
|
||||||
config["private"] = (strcmp(PQgetvalue(res, i, 8),"t")==0);
|
config["private"] = (strcmp(PQgetvalue(res, i, 8),"t")==0);
|
||||||
|
try {
|
||||||
config["remoteTraceLevel"] = std::stoi(PQgetvalue(res, i, 9));
|
config["remoteTraceLevel"] = std::stoi(PQgetvalue(res, i, 9));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["remoteTraceLevel"] = 0;
|
||||||
|
}
|
||||||
config["remoteTraceTarget"] = PQgetvalue(res, i, 10);
|
config["remoteTraceTarget"] = PQgetvalue(res, i, 10);
|
||||||
|
try {
|
||||||
config["revision"] = std::stoull(PQgetvalue(res, i, 11));
|
config["revision"] = std::stoull(PQgetvalue(res, i, 11));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["revision"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error converting revision: %s\n", PQgetvalue(res, i, 11));
|
||||||
|
}
|
||||||
config["rules"] = json::parse(PQgetvalue(res, i, 12));
|
config["rules"] = json::parse(PQgetvalue(res, i, 12));
|
||||||
config["tags"] = json::parse(PQgetvalue(res, i, 13));
|
config["tags"] = json::parse(PQgetvalue(res, i, 13));
|
||||||
config["v4AssignMode"] = json::parse(PQgetvalue(res, i, 14));
|
config["v4AssignMode"] = json::parse(PQgetvalue(res, i, 14));
|
||||||
@ -358,19 +385,59 @@ void PostgreSQL::initializeMembers(PGconn *conn)
|
|||||||
config["activeBridge"] = (strcmp(PQgetvalue(res, i, 2), "t") == 0);
|
config["activeBridge"] = (strcmp(PQgetvalue(res, i, 2), "t") == 0);
|
||||||
config["authorized"] = (strcmp(PQgetvalue(res, i, 3), "t") == 0);
|
config["authorized"] = (strcmp(PQgetvalue(res, i, 3), "t") == 0);
|
||||||
config["capabilities"] = json::parse(PQgetvalue(res, i, 4));
|
config["capabilities"] = json::parse(PQgetvalue(res, i, 4));
|
||||||
|
try {
|
||||||
config["creationTime"] = std::stoull(PQgetvalue(res, i, 5));
|
config["creationTime"] = std::stoull(PQgetvalue(res, i, 5));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["creationTime"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error upding creation time (member): %s\n", PQgetvalue(res, i, 5));
|
||||||
|
}
|
||||||
config["identity"] = PQgetvalue(res, i, 6);
|
config["identity"] = PQgetvalue(res, i, 6);
|
||||||
|
try {
|
||||||
config["lastAuthorizedTime"] = std::stoull(PQgetvalue(res, i, 7));
|
config["lastAuthorizedTime"] = std::stoull(PQgetvalue(res, i, 7));
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
config["lastAuthorizedTime"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error updating last auth time (member): %s\n", PQgetvalue(res, i, 7));
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["lastDeauthorizedTime"] = std::stoull(PQgetvalue(res, i, 8));
|
config["lastDeauthorizedTime"] = std::stoull(PQgetvalue(res, i, 8));
|
||||||
|
} catch( std::exception &e) {
|
||||||
|
config["lastDeauthorizedTime"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error updating last deauth time (member): %s\n", PQgetvalue(res, i, 8));
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["remoteTraceLevel"] = std::stoi(PQgetvalue(res, i, 9));
|
config["remoteTraceLevel"] = std::stoi(PQgetvalue(res, i, 9));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["remoteTraceLevel"] = 0;
|
||||||
|
}
|
||||||
config["remoteTraceTarget"] = PQgetvalue(res, i, 10);
|
config["remoteTraceTarget"] = PQgetvalue(res, i, 10);
|
||||||
config["tags"] = json::parse(PQgetvalue(res, i, 11));
|
config["tags"] = json::parse(PQgetvalue(res, i, 11));
|
||||||
|
try {
|
||||||
config["vMajor"] = std::stoi(PQgetvalue(res, i, 12));
|
config["vMajor"] = std::stoi(PQgetvalue(res, i, 12));
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
config["vMajor"] = -1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["vMinor"] = std::stoi(PQgetvalue(res, i, 13));
|
config["vMinor"] = std::stoi(PQgetvalue(res, i, 13));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["vMinor"] = -1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["vRev"] = std::stoi(PQgetvalue(res, i, 14));
|
config["vRev"] = std::stoi(PQgetvalue(res, i, 14));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["vRev"] = -1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
config["vProto"] = std::stoi(PQgetvalue(res, i, 15));
|
config["vProto"] = std::stoi(PQgetvalue(res, i, 15));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["vProto"] = -1;
|
||||||
|
}
|
||||||
config["noAutoAssignIps"] = (strcmp(PQgetvalue(res, i, 16), "t") == 0);
|
config["noAutoAssignIps"] = (strcmp(PQgetvalue(res, i, 16), "t") == 0);
|
||||||
|
try {
|
||||||
config["revision"] = std::stoull(PQgetvalue(res, i, 17));
|
config["revision"] = std::stoull(PQgetvalue(res, i, 17));
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
config["revision"] = 0ULL;
|
||||||
|
//fprintf(stderr, "Error updating revision (member): %s\n", PQgetvalue(res, i, 17));
|
||||||
|
}
|
||||||
config["objtype"] = "member";
|
config["objtype"] = "member";
|
||||||
config["ipAssignments"] = json::array();
|
config["ipAssignments"] = json::array();
|
||||||
const char *p2[2] = {
|
const char *p2[2] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user