#include "ocstack.h"
-#define VERIFY_NON_EMPTY(arg, log_message, ret) \
- if ((arg).empty()) \
+#define VERIFY_VALID_STRING(arg, log_message, ret) \
+ if (std::string::npos == (arg).find_first_not_of(" \f\n\r\t\v")) \
{ \
oclog() << log_message << std::flush; \
return result_guard(ret); \
: m_clientWrapper(clientWrapper), m_host(host), m_userUuid(""),
m_invitationObserveHandle(nullptr), m_groupObserveHandle(nullptr), m_connType(connectivityType)
{
- if (m_host.empty() || m_clientWrapper.expired())
+ if (std::string::npos == m_host.find_first_not_of(" \f\n\r\t\v") || m_clientWrapper.expired())
{
throw OCException(OC::Exception::INVALID_PARAM);
}
const QueryParamsMap& options,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(authProvider, "authProvider cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(authCode, "authCode cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(authProvider, "authProvider cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(authCode, "authCode cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACCOUNT_URI;
const std::string& accessToken,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
OCStackResult result = result_guard(signInOut(userUuid, accessToken, true,
cloudConnectHandler));
OCStackResult OCAccountManager::signOut(const std::string& accessToken,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
- VERIFY_NON_EMPTY(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
OCStackResult result = result_guard(signInOut(m_userUuid, accessToken, false,
cloudConnectHandler));
const std::string& refreshToken,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(refreshToken, "refreshToken cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(refreshToken, "refreshToken cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI;
OCStackResult OCAccountManager::searchUser(const QueryParamsMap& queryParams,
GetCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(queryParams, "queryParams cannot be empty.", OC_STACK_INVALID_PARAM);
+ if (queryParams.empty())
+ {
+ oclog() << "queryParams cannot be empty." << std::flush;
+ return OC_STACK_INVALID_PARAM;
+ }
std::string uri = m_host + OC_RSRVD_ACCOUNT_SEARCH_URI;
const std::string& deviceId,
DeleteCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(deviceId, "deviceId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(accessToken, "accessToken cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(deviceId, "deviceId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACCOUNT_URI
+ "?" + OC_RSRVD_ACCESS_TOKEN + "=" + accessToken
OCStackResult OCAccountManager::createGroup(const QueryParamsMap& queryParams,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI;
OCStackResult OCAccountManager::deleteGroup(const std::string& groupId,
DeleteCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId
+ "?" + OC_RSRVD_OWNER + "=" + m_userUuid;
OCStackResult OCAccountManager::getGroupInfoAll(GetCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI;
OCStackResult OCAccountManager::getGroupInfo(const std::string& groupId,
GetCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId;
const OCRepresentation propertyValue,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId;
const OCRepresentation propertyValue,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId;
const OCRepresentation propertyValue,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId;
OCStackResult OCAccountManager::observeGroup(ObserveCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI;
OCStackResult OCAccountManager::cancelObserveGroup()
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
if (nullptr == m_groupObserveHandle)
{
const std::string& userUuid,
PostCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(m_userUuid, "Need to sign-in first.", OC_STACK_ERROR);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI;
const std::string& userUuid,
DeleteCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
- VERIFY_NON_EMPTY(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(userUuid, "userUuid cannot be empty.", OC_STACK_INVALID_PARAM);
std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI + "?" + OC_RSRVD_GROUP_ID + "=" + groupId
+ ";" + OC_RSRVD_MEMBER_ID + "=" + userUuid;
const bool accept,
DeleteCallback cloudConnectHandler)
{
- VERIFY_NON_EMPTY(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
+ VERIFY_VALID_STRING(groupId, "groupId cannot be empty.", OC_STACK_INVALID_PARAM);
std::string isAccept = accept ? "1" : "0";