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


C++ ExceptionRef::getDetails方法代码示例

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


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

示例1: checkAccessControl

bool SessionManager::checkAccessControl(
   const char* username, InternetAddress* ip)
{
   bool rval;

   // check the address against 127.x.x.x for localhost status, any user
   // has access control from localhost
   rval = (strncmp(ip->getAddress(), "127.", 4) == 0);
   if(!rval)
   {
      // not localhost, will have to check session database:

      // get bitmunk user ID
      Url url;
      url.format("/api/3.0/users?username=%s", username);
      DynamicObject user;
      if(mNode->getMessenger()->getFromBitmunk(&url, user))
      {
         rval = mSessionDatabase.checkAccessControl(
            BM_USER_ID(user["id"]), ip->getAddress());
      }
   }

   if(!rval)
   {
      ExceptionRef e = new Exception(
         "Access denied for user.",
         "bitmunk.webui.SessionManager.AccessDenied");
      e->getDetails()["username"] = username;
      e->getDetails()["ip"] = ip->getAddress();
      Exception::push(e);
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:35,代码来源:SessionManager.cpp

示例2: _compileDomainRegex

static PatternRef _compileDomainRegex(const char* domain)
{
   PatternRef rval(NULL);

   string regex = "^";
   regex.append(domain);
   regex.append("$");

   // escape all periods
   StringTools::replaceAll(regex, ".", "\\.");

   // replace all wildcards with (.*)
   StringTools::replaceAll(regex, "*", ".*");

   // try to compile the pattern (match case, no-sub matches allowed)
   rval = Pattern::compile(regex.c_str(), true, false);
   if(rval.isNull())
   {
      ExceptionRef e = new Exception(
         "Could not add proxy domain. Invalid domain format.",
         "bitmunk.node.ProxyResourceHandler.InvalidDomainFormat");
      e->getDetails()["domain"] = domain;
      e->getDetails()["regex"] = regex.c_str();
      Exception::push(e);
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:28,代码来源:ProxyResourceHandler.cpp

示例3: performAction

bool ControlPoint::performAction(
   const char* actionName, DynamicObject& params,
   Service& service, ActionResult& result)
{
   bool rval = false;

   // ensure action exists in the service
   if(!service->hasMember("actions") ||
      !service["actions"]->hasMember(actionName))
   {
      ExceptionRef e = new Exception(
         "Service has no such action.",
         "monarch.upnp.NoSuchAction");
      e->getDetails()["actionName"] = actionName;
      e->getDetails()["serviceType"] = service["serviceType"]->getString();
      e->getDetails()["serviceId"] = service["serviceId"]->getString();
      Exception::set(e);
   }
   else
   {
      // create a soap message
      SoapMessage msg;
      msg["name"] = actionName;
      msg["namespace"] = service["serviceType"]->getString();
      msg["params"] = params;

      // do soap transfer
      rval = doSoap(service, msg, result);
   }

   return rval;
}
开发者ID:bsletten,项目名称:monarch,代码行数:32,代码来源:ControlPoint.cpp

示例4: read

int FileInputStream::read(char* b, int length)
{
   int rval = -1;

   if(ensureOpen())
   {
      rval = 0;

      // do read
      int count = fread(b, 1, length, mHandle);
      if(count != length)
      {
         // check for an error
         if(ferror(mHandle) != 0)
         {
            ExceptionRef e = new Exception(
               "Could not read file.",
               "monarch.io.File.ReadError");
            e->getDetails()["path"] = mFile->getAbsolutePath();
            e->getDetails()["error"] = strerror(errno);
            Exception::set(e);
            rval = -1;
         }
      }

      if(rval != -1)
      {
         // return number of bytes read
         rval = count;
      }
   }

   return rval;
}
开发者ID:bsletten,项目名称:monarch,代码行数:34,代码来源:FileInputStream.cpp

示例5: receive

int AbstractSocket::receive(char* b, int length)
{
   int rval = -1;

   if(!isBound())
   {
      ExceptionRef e = new Exception(
         "Cannot read from unbound socket.",
         SOCKET_EXCEPTION_TYPE ".NotBound");
      Exception::set(e);
   }
   else
   {
      // try to receive some data, don't block
      int flags = 0;
#ifdef MSG_DONTWAIT
      flags |= MSG_DONTWAIT;
#endif
      rval = SOCKET_MACRO_recv(mFileDescriptor, b, length, flags);
      if(rval < 0)
      {
         // see if error is other than no data is available (EAGAIN)
         if(errno != EAGAIN)
         {
            ExceptionRef e = new Exception(
               "Could not read from socket.", SOCKET_EXCEPTION_TYPE);
            e->getDetails()["error"] = strerror(errno);
            Exception::set(e);
         }
         // FIXME: this will probably work differently in the future
         // non-blocking socket, set exception
         else if(isReceiveNonBlocking())
         {
            // using asynchronous IO
            ExceptionRef e = new Exception(
               "Socket would block during receive.",
               SOCKET_EXCEPTION_TYPE ".WouldBlock");
            e->getDetails()["wouldBlock"] = true;
            Exception::set(e);
         }
         // wait for data to become available
         else if(waitUntilReady(true, getReceiveTimeout()))
         {
            // receive data
            rval = SOCKET_MACRO_recv(mFileDescriptor, b, length, flags);
            if(rval < 0)
            {
               ExceptionRef e = new Exception(
                  "Could not read from socket.", SOCKET_EXCEPTION_TYPE);
               e->getDetails()["error"] = strerror(errno);
               Exception::set(e);
            }
         }
      }
   }

   return rval;
}
开发者ID:bsletten,项目名称:monarch,代码行数:58,代码来源:AbstractSocket.cpp

示例6: createDirective

bool DirectiveService::createDirective(
   BtpAction* action, DynamicObject& in, DynamicObject& out)
{
   bool rval = false;

   UserId userId;
   if(mNode->checkLogin(action, &userId))
   {
      // turn user ID into a key
      char key[22];
      snprintf(key, 22, "%" PRIu64, userId);

      // lock to insert directive
      mCacheLock.lock();
      {
         // initialize user's directive cache as needed
         if(!mDirectives->hasMember(key))
         {
            mDirectives[key]->setType(Map);
         }

         DynamicObject& cache = mDirectives[key];
         if(cache->length() < MAX_DIRECTIVES)
         {
            // insert directive into cache
            insertDirective(cache, in);

            // return directive ID
            out["directiveId"] = in["id"]->getString();
            rval = true;

            // fire created event
            Event e;
            e["type"] = "bitmunk.system.Directive.created";
            e["details"]["userId"] = userId;
            e["details"]["directiveId"] = in["id"];
            e["details"]["directive"] = in;
            mNode->getEventController()->schedule(e);
         }
         else
         {
            // too many directives
            ExceptionRef e = new Exception(
               "Could not add directive. Maximum number of "
               "directives reached.",
               "bitmunk.system.DirectiveService.TooManyDirectives");
            e->getDetails()["userId"] = userId;
            e->getDetails()["max"] = MAX_DIRECTIVES;
            Exception::set(e);
         }
      }
      mCacheLock.unlock();
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:56,代码来源:DirectiveService.cpp

示例7: readLine

int FileInputStream::readLine(string& line, char delimiter)
{
   int rval = -1;

   if(ensureOpen())
   {
      rval = 0;

      // feof returns non-zero when EOF
      if(feof(mHandle) == 0)
      {
         // get line
         char* data = NULL;
         size_t size = 0;
         ssize_t length = getdelim(&data, &size, delimiter, mHandle);
         if(length == -1)
         {
            if(feof(mHandle) != 0)
            {
               // end of file
            }
            else
            {
               ExceptionRef e = new Exception(
                  "Could not read file.",
                  "monarch.io.File.ReadError");
               e->getDetails()["path"] = mFile->getAbsolutePath();
               e->getDetails()["error"] = strerror(errno);
               Exception::set(e);
               rval = -1;
            }
         }
         else
         {
            // line was read
            rval = 1;
            if(data[length - 1] == delimiter)
            {
               // do not include delimiter
               line.assign(data, length - 1);
            }
            else
            {
               line.assign(data, length);
            }
            free(data);
         }
      }
   }

   return rval;
}
开发者ID:bsletten,项目名称:monarch,代码行数:52,代码来源:FileInputStream.cpp

示例8: exchange

bool Messenger::exchange(
   UserId peerId,
   Url* url, BtpMessage* out, BtpMessage* in, UserId userId, UserId agentId,
   uint32_t timeout)
{
   bool rval = true;

   if(userId != 0)
   {
      // get user profile
      ProfileRef p;
      if(!mNode->getLoginData(agentId == 0 ? userId : agentId, NULL, &p))
      {
         ExceptionRef e = new Exception(
            "Could not do BTP exchange. Not logged in.",
            "bitmunk.node.Messenger.NotLoggedIn");
         BM_ID_SET(e->getDetails()["userId"], userId);
         BM_ID_SET(e->getDetails()["agentId"], agentId);
         Exception::set(e);
         rval = false;
      }
      else if(!p.isNull())
      {
         // set user ID and profile for outgoing secure message
         out->setUserId(userId);
         out->setAgentProfile(p);

         // set public key source for incoming secure message
         in->setPublicKeySource(mNode->getPublicKeyCache());
      }
   }

   // do btp exchange
   if(rval)
   {
      // if nodeuser is set, override peer ID with it
      DynamicObject vars;
      url->getQueryVariables(vars);
      if(vars->hasMember("nodeuser"))
      {
         peerId = BM_USER_ID(vars["nodeuser"]);
      }

      rval = mClient.exchange(peerId, url, out, in, timeout);
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:48,代码来源:Messenger.cpp

示例9: processDirective

bool DirectiveService::processDirective(
   BtpAction* action, DynamicObject& in, DynamicObject& out)
{
   bool rval = false;

   UserId userId;
   if(mNode->checkLogin(action, &userId))
   {
      // get directive by its ID
      DynamicObject params;
      action->getResourceParams(params);
      const char* id = params[0]->getString();
      DynamicObject directive(NULL);

      // remove directive from cache
      removeDirective(userId, id, &directive);

      // ensure directive is not invalid
      if(directive.isNull())
      {
         // directive not found
         ExceptionRef e = new Exception(
            "Could not process directive. Directive does not exist.",
            "bitmunk.system.DirectiveService.InvalidDirectiveId", 404);
         e->getDetails()["userId"] = userId;
         e->getDetails()["directiveId"] = id;
         Exception::set(e);
      }
      // process directive
      else
      {
         // include user ID in directive
         directive["userId"] = userId;

         // include directive in output
         out["userId"] = userId;
         out["directive"] = directive;

         // run directive processor fiber
         DirectiveProcessor* dp = new DirectiveProcessor(mNode);
         dp->setDirective(directive);
         mNode->getFiberScheduler()->addFiber(dp);
         rval = true;
      }
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:48,代码来源:DirectiveService.cpp

示例10: listen

bool AbstractSocket::listen(int backlog)
{
   if(!isBound())
   {
      ExceptionRef e = new Exception(
         "Cannot listen on unbound socket.",
         SOCKET_EXCEPTION_TYPE ".NotBound");
      Exception::set(e);
   }
   else
   {
      // set backlog
      mBacklog = backlog;

      // listen
      int error = SOCKET_MACRO_listen(mFileDescriptor, backlog);
      if(error < 0)
      {
         ExceptionRef e = new Exception(
            "Could not listen on socket.", SOCKET_EXCEPTION_TYPE);
         e->getDetails()["error"] = strerror(errno);
         Exception::set(e);
      }
      else
      {
         // now listening
         mListening = true;

         // set socket to non-blocking so accept() calls can be interrupted
         SOCKET_MACRO_fcntl(mFileDescriptor, F_SETFL, O_NONBLOCK);
      }
   }

   return mListening;
}
开发者ID:zengyuxing007,项目名称:monarch,代码行数:35,代码来源:AbstractSocket.cpp

示例11: connect

bool AbstractConnection::connect(const char* url)
{
    bool rval = false;

    // clean up old url
    mUrl.setNull();

    // ensure URL isn't malformed
    Exception::clear();
    mUrl = new Url(url);
    if(Exception::isSet())
    {
        ExceptionRef e = new Exception(
            "Invalid database url.",
            "monarch.sql.Connection.InvalidUrl");
        e->getDetails()["url"] = url;
        Exception::push(e);
    }
    else
    {
        // call implementation-specific code
        rval = connect(&(*mUrl));
    }

    return rval;
}
开发者ID:zengyuxing007,项目名称:monarch,代码行数:26,代码来源:AbstractConnection.cpp

示例12: rollback

bool AbstractConnection::rollback()
{
    bool rval = false;

    // save the reason for the rollback
    ExceptionRef reason = Exception::get();

    // attempt to do the rollback
    Statement* s = prepare("ROLLBACK");
    rval = (s != NULL) && s->execute() && s->reset();
    if(!rval)
    {
        ExceptionRef e = new Exception(
            "Could not rollback transaction.",
            "monarch.sql.Connection.TransactionRollbackError");
        if(!reason.isNull())
        {
            e->getDetails()["rollbackReason"] =
                Exception::convertToDynamicObject(reason);
        }
        Exception::push(e);
    }

    return rval;
}
开发者ID:zengyuxing007,项目名称:monarch,代码行数:25,代码来源:AbstractConnection.cpp

示例13: getBitmunkHomePath

bool NodeConfigManager::getBitmunkHomePath(string& path)
{
   bool rval;

   Config c = getConfigManager()->getConfig(MAIN_ID);
   // get initial value
   const char* bitmunkHomePath = c["monarch.app.Core"]["home"]->getString();
   // make sure bitmunkHomePath is user-expanded
   rval = File::expandUser(bitmunkHomePath, path);
   // make sure path is absolute
   if(!rval || !File::isPathAbsolute(path.c_str()))
   {
      ExceptionRef e = new Exception(
         "Could not get absolute bitmunk home path.",
         "bitmunk.node.NodeConfigManager.ConfigError");
      e->getDetails()["bitmunkHomePath"] = bitmunkHomePath;
      Exception::push(e);
      rval = false;
   }

#ifdef WIN32
   if(rval)
   {
      // swap backslashes to standard if on windows
      StringTools::replaceAll(path, "\\", "/");
   }
#endif

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:30,代码来源:NodeConfigManager.cpp

示例14: getSessionFromAction

bool SessionManager::getSessionFromAction(
   BtpAction* action, string& session, InternetAddress* ip)
{
   bool rval = true;

   // get client cookies
   CookieJar jar;
   jar.readCookies(action->getRequest()->getHeader(), CookieJar::Client);

   // check for bitmunk-session cookie
   Cookie cookie = jar.getCookie("bitmunk-session");
   if(cookie.isNull())
   {
      ExceptionRef e = new Exception(
         "No 'bitmunk-session' cookie.",
         "bitmunk.webui.SessionManager.MissingCookie");
      e->getDetails()["missingCookie"] = "bitmunk-session";
      Exception::set(e);
      rval = false;
   }
   else
   {
      // get session ID
      session = cookie["value"]->getString();
   }

   if(rval)
   {
      // get IP
      rval = action->getClientInternetAddress(ip);
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:34,代码来源:SessionManager.cpp

示例15: addError

DynamicObject ValidatorContext::addError(
   const char* type, DynamicObject* object)
{
   DynamicObject errorDetail;

   // setup error detail
   errorDetail["type"] = type;
   // FIXME: localize message -- lehn
   // FIXME: really? do we need to mention this, because we'd have to
   //        do this for every string in the system.. -- manu
   errorDetail["message"] = "The given value does not meet all of the data "
      "validation requirements. Please examine the error details for more "
      "information about the specific requirements.";
   if(object != NULL && (mMaskType & ValidatorContext::MaskInvalidValues) == 0)
   {
      errorDetail["invalidValue"] = *object;
   }

   // add error detail to results errors
   std::string fullpath = getPath();
   mResults["errors"][fullpath.c_str()] = errorDetail;

   // Skip setting exceptions if requested. Return errorDetail regardless.
   if(mSetExceptions)
   {
      ExceptionRef e;

      if(!Exception::isSet())
      {
         e = new Exception(
            "The given object does not meet all of the data validation "
            "requirements. Please examine the error details for more "
            "information about the specific requirements.",
            "monarch.validation.ValidationError");
         Exception::set(e);
      }
      else
      {
         e = Exception::get();
         // Check if we are adding to a ValidationError
         if(!e->isType("monarch.validation.ValidationError"))
         {
            // FIXME: this is a bit bogus. If validation checking keeps causing
            // other exceptions then a long cause chain could be generated
            // switching between ValidationError and other types.
            e = new Exception(
               "The given object does not meet all of the data validation "
               "requirements. Please examine the error details for more "
               "information about the specific requirements.",
               "monarch.validation.ValidationError");
            Exception::push(e);
         }
      }

      // add detail to "errors" section of exception details
      e->getDetails()["errors"][fullpath.c_str()] = errorDetail;
   }

   return errorDetail;
}
开发者ID:zengyuxing007,项目名称:monarch,代码行数:60,代码来源:ValidatorContext.cpp


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