当前位置: 首页>>代码示例>>C++>>正文


C++ ApiRequest::apikey方法代码示例

本文整理汇总了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;
    }
//.........这里部分代码省略.........
开发者ID:dresden-elektronik,项目名称:deconz-rest-plugin,代码行数:101,代码来源:authorisation.cpp


注:本文中的ApiRequest::apikey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。