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


C++ Stanza::getError方法代码示例

本文整理汇总了C++中Stanza::getError方法的典型用法代码示例。如果您正苦于以下问题:C++ Stanza::getError方法的具体用法?C++ Stanza::getError怎么用?C++ Stanza::getError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stanza的用法示例。


在下文中一共展示了Stanza::getError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleStanza

int LoginTask::handleStanza(Stanza& stanza, StanzaHandlerResult& result)
{
  int ok = 1;

  switch(nPhase_) {
  case StreamOpen:
    // <stream:stream xmlns:stream='http://etherx.jabber.org/streams' id='43956666' xmlns='jabber:client' from='user.virtual-presence.org'>
    if (stanza.getName() == "stream:stream") {
      result.stanzaHandled(1);
      result.stanzaConsumed(1);
      sStreamId_ = stanza.getAttribute("id").getValue();
      if (sStreamId_.empty()) {
        apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "<stream:stream> No stream ID"));
        nPhase_ = LoginFailed;
        result.connectionFinished(1);
        result.taskFinished(1);
        pClient_->onProtocolStartFailed();
      } else {
        sendAuthMechQuery();
        nPhase_ = AuthMechanisms;
        pClient_->onProtocolStart();
      }
    }
    break;

  case AuthMechanisms:
    if (stanza.getName() == "iq") {
      // <iq id='1' type='result'><query xmlns='jabber:iq:auth'><username>lluna_484de02a54c5</username><digest/><password/><resource/></query></iq>      
      if (sId_ == stanza.getAttribute("id").getValue()) {
        result.stanzaHandled(1);
        result.stanzaConsumed(1);
        String sType = stanza.getAttribute("type").getValue();
        if (sType == "error") {
          String sError; int nError = 0;
          if (stanza.getError(nError, sError)) {
            apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "jabber:iq:auth error result: %d %s", nError, _sz(sError)));
          } else {
            apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "jabber:iq:auth unknown error result"));
          }
          nPhase_ = LoginFailed;
          result.connectionFinished(1);
          pClient_->onProtocolLoginFailed();
        } else {
          Apollo::XMLNode& query = stanza.getChildRef("query");
          Apollo::XMLNode& digest = query.getChildRef("digest");
          Apollo::XMLNode& password = query.getChildRef("password");
          AP_UNUSED_VARIABLE Apollo::XMLNode& resource = query.getChildRef("resource");
          if (digest) {
            sendDigestAuth();
            nPhase_ = DigestAuth;
          } else if (password) {
            sendPasswordAuth();
            nPhase_ = PasswordAuth;
          } else {
            apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "jabber:iq:auth result: neither digest nor password auth available"));
            nPhase_ = LoginFailed;
            result.connectionFinished(1);
            pClient_->onProtocolLoginFailed();
          }
        }
      }
    }
    break;

  case DigestAuth:
    if (stanza.getName() == "iq") {
      // <iq id='2' type='result'/>
      if (sId_ == stanza.getAttribute("id").getValue()) {
        result.stanzaHandled(1);
        result.stanzaConsumed(1);
        result.taskFinished(1);
        String sType = stanza.getAttribute("type").getValue();
        if (sType == "error") {
          String sError; int nError = 0;
          if (stanza.getError(nError, sError)) {
            apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "DigestAuth error result: %d %s", nError, _sz(sError)));
          } else {
            apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "DigestAuth unknown error result"));
          }
          nPhase_ = LoginFailed;
          result.connectionFinished(1);
          pClient_->onProtocolLoginFailed();
        } else {
          apLog_Info((LOG_CHANNEL, LOG_CONTEXT, "Logged in"));
          nPhase_ = LoggedIn;
          pClient_->onProtocolLogin();
        }
      }
    }
    break;

  case PasswordAuth:
    if (stanza.getName() == "iq") {
      // <iq id='2' type='result'/>
      if (sId_ == stanza.getAttribute("id").getValue()) {
        result.stanzaHandled(1);
        result.stanzaConsumed(1);
        result.taskFinished(1);
        String sType = stanza.getAttribute("type").getValue();
        if (sType == "error") {
//.........这里部分代码省略.........
开发者ID:wolfspelz,项目名称:Apollo,代码行数:101,代码来源:Task.cpp


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