本文整理汇总了C++中ApiRequest::apikey方法的典型用法代码示例。如果您正苦于以下问题:C++ ApiRequest::apikey方法的具体用法?C++ ApiRequest::apikey怎么用?C++ ApiRequest::apikey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiRequest
的用法示例。
在下文中一共展示了ApiRequest::apikey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: authorise
/*! Authorise API access for the request.
*/
void DeRestPluginPrivate::authorise(ApiRequest &req, ApiResponse &rsp)
{
Q_UNUSED(rsp);
QHostAddress localHost(QHostAddress::LocalHost);
if (req.sock->peerAddress() == localHost)
{
req.auth = ApiAuthLocal;
}
if (req.sock == nullptr) // allow internal requests, as they are issued by triggering rules
{
req.auth = ApiAuthInternal;
}
QString apikey = req.apikey();
apiAuthCurrent = apiAuths.size();
if (apikey.isEmpty())
{
return;
}
std::vector<ApiAuth>::iterator i = apiAuths.begin();
std::vector<ApiAuth>::iterator end = apiAuths.end();
for (size_t pos = 0; i != end; ++i, pos++)
{
if (apikey == i->apikey && i->state == ApiAuth::StateNormal)
{
apiAuthCurrent = pos;
i->lastUseDate = QDateTime::currentDateTimeUtc();
// fill in useragent string if not already exist
if (i->useragent.isEmpty())
{
if (req.hdr.hasKey("User-Agent"))
{
i->useragent = req.hdr.value("User-Agent");
DBG_Printf(DBG_HTTP, "set useragent '%s' for apikey '%s'\n", qPrintable(i->useragent), qPrintable(i->apikey));
}
}
if (req.sock)
{
for (TcpClient &cl : openClients)
{
if (cl.sock == req.sock && cl.closeTimeout > 0)
{
cl.closeTimeout = AUTH_KEEP_ALIVE;
break;
}
}
}
if ((!(i->useragent.isEmpty()) && i->useragent.startsWith(QLatin1String("iConnect"))) || i->devicetype.startsWith(QLatin1String("iConnectHue")))
{
req.mode = ApiModeStrict;
}
else if (i->devicetype.startsWith(QLatin1String("Echo")))
{
req.mode = ApiModeEcho;
}
else if (i->devicetype.startsWith(QLatin1String("Hue Essentials")))
{
// supports deCONZ specifics
}
else if (i->devicetype.startsWith(QLatin1String("hue_")) ||
i->devicetype.startsWith(QLatin1String("Hue ")))
{
req.mode = ApiModeHue;
}
DBG_Printf(DBG_HTTP, "ApiMode: %d\n", req.mode);
i->needSaveDatabase = true;
if (!apiAuthSaveDatabaseTime.isValid() || apiAuthSaveDatabaseTime.elapsed() > (1000 * 60 * 30))
{
apiAuthSaveDatabaseTime.start();
queSaveDb(DB_AUTH, DB_HUGE_SAVE_DELAY);
}
req.auth = ApiAuthFull;
}
}
#if 0
// allow non registered devices to use the api if the link button is pressed
if (gwLinkButton)
{
ApiAuth auth;
auth.needSaveDatabase = true;
auth.apikey = apikey;
auth.devicetype = "unknown";
auth.createDate = QDateTime::currentDateTimeUtc();
auth.lastUseDate = QDateTime::currentDateTimeUtc();
apiAuths.push_back(auth);
queSaveDb(DB_AUTH, DB_SHORT_SAVE_DELAY);
return true;
}
//.........这里部分代码省略.........