Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356842
D3525.id10876.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D3525.id10876.diff
View Options
diff --git a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp
--- a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp
+++ b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp
@@ -1,5 +1,8 @@
#include "DeviceSessionItem.h"
#include "ConfigManager.h"
+#include "Tools.h"
+
+#include <vector>
namespace comm {
namespace network {
@@ -38,9 +41,11 @@
}
void DeviceSessionItem::validate() const {
- if (!this->sessionID.size()) {
- throw std::runtime_error("Error: SessionID is empty.");
- }
+ checkEmptyField("pubKey", this->pubKey);
+ checkEmptyField("notifyToken", this->notifyToken);
+ checkEmptyField("deviceType", this->deviceType);
+ checkEmptyField("appVersion", this->appVersion);
+ checkEmptyField("deviceOs", this->deviceOs);
}
void DeviceSessionItem::assignItemFromDatabase(
diff --git a/services/tunnelbroker/src/Database/MessageItem.cpp b/services/tunnelbroker/src/Database/MessageItem.cpp
--- a/services/tunnelbroker/src/Database/MessageItem.cpp
+++ b/services/tunnelbroker/src/Database/MessageItem.cpp
@@ -1,5 +1,8 @@
#include "MessageItem.h"
#include "ConfigManager.h"
+#include "Tools.h"
+
+#include <vector>
namespace comm {
namespace network {
@@ -33,18 +36,8 @@
}
void MessageItem::validate() const {
- if (!this->messageID.size()) {
- throw std::runtime_error("Error: messageID is empty");
- }
- if (!this->fromDeviceID.size()) {
- throw std::runtime_error("Error: fromDeviceID is empty");
- }
- if (!this->toDeviceID.size()) {
- throw std::runtime_error("Error: toDeviceID is empty");
- }
- if (!this->expire == 0) {
- throw std::runtime_error("Error: expire field not provided");
- }
+ checkEmptyField("messageID", this->messageID);
+ checkEmptyField("expire", this->expire);
}
void MessageItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
diff --git a/services/tunnelbroker/src/Database/PublicKeyItem.cpp b/services/tunnelbroker/src/Database/PublicKeyItem.cpp
--- a/services/tunnelbroker/src/Database/PublicKeyItem.cpp
+++ b/services/tunnelbroker/src/Database/PublicKeyItem.cpp
@@ -1,5 +1,6 @@
#include "PublicKeyItem.h"
#include "ConfigManager.h"
+#include "Tools.h"
namespace comm {
namespace network {
@@ -20,12 +21,7 @@
}
void PublicKeyItem::validate() const {
- if (!this->deviceID.size()) {
- throw std::runtime_error("Error: DeviceID is empty");
- }
- if (!this->publicKey.size()) {
- throw std::runtime_error("Error: PublicKey is empty");
- }
+ checkEmptyField("publicKey", this->publicKey);
}
void PublicKeyItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
diff --git a/services/tunnelbroker/src/Database/SessionSignItem.cpp b/services/tunnelbroker/src/Database/SessionSignItem.cpp
--- a/services/tunnelbroker/src/Database/SessionSignItem.cpp
+++ b/services/tunnelbroker/src/Database/SessionSignItem.cpp
@@ -1,5 +1,6 @@
#include "SessionSignItem.h"
#include "ConfigManager.h"
+#include "Tools.h"
namespace comm {
namespace network {
@@ -22,12 +23,7 @@
}
void SessionSignItem::validate() const {
- if (!this->deviceID.size()) {
- throw std::runtime_error("Error: DeviceID is empty");
- }
- if (!this->sign.size()) {
- throw std::runtime_error("Error: Sign is empty");
- }
+ checkEmptyField("sign", this->sign);
}
void SessionSignItem::assignItemFromDatabase(
diff --git a/services/tunnelbroker/src/Tools/Tools.h b/services/tunnelbroker/src/Tools/Tools.h
--- a/services/tunnelbroker/src/Tools/Tools.h
+++ b/services/tunnelbroker/src/Tools/Tools.h
@@ -11,6 +11,8 @@
bool validateDeviceID(std::string deviceID);
std::string generateUUID();
bool validateSessionID(std::string sessionID);
+void checkEmptyField(std::string fieldName, std::string stringToCheck);
+void checkEmptyField(std::string fieldName, uint64_t numberToCheck);
} // namespace network
} // namespace comm
diff --git a/services/tunnelbroker/src/Tools/Tools.cpp b/services/tunnelbroker/src/Tools/Tools.cpp
--- a/services/tunnelbroker/src/Tools/Tools.cpp
+++ b/services/tunnelbroker/src/Tools/Tools.cpp
@@ -67,5 +67,19 @@
}
}
+void checkEmptyField(std::string fieldName, std::string stringToCheck) {
+ if (stringToCheck.empty()) {
+ throw std::runtime_error(
+ "Error: Required text field " + fieldName + " is empty.");
+ }
+}
+
+void checkEmptyField(std::string fieldName, uint64_t numberToCheck) {
+ if (numberToCheck == 0) {
+ throw std::runtime_error(
+ "Error: Required number " + fieldName + " is zero.");
+ }
+}
+
} // namespace network
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 9:01 PM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577309
Default Alt Text
D3525.id10876.diff (4 KB)
Attached To
Mode
D3525: [services] Tunnelbroker - Empty field checks in database items
Attached
Detach File
Event Timeline
Log In to Comment