Esempio n. 1
0
void WriteMesh::write_mesh( const Mesh& mesh, const URI& file, const std::vector<URI>& fields)
{
  update_list_of_available_writers();

  /// @todo this should be improved to allow http(s) which would then upload the mesh
  ///       to a remote location after writing to a temporary file
  ///       uploading can be achieved using the curl library (which we already search for in the build system)

  URI filepath = file;

  if( filepath.scheme() != URI::Scheme::FILE )
    filepath.scheme( URI::Scheme::FILE );


  const std::string extension = filepath.extension();

  if ( m_extensions_to_writers.count(extension) == 0 )
    throw FileFormatError (FromHere(), "No meshwriter exists for files with extension " + extension);

  if (m_extensions_to_writers[extension].size()>1)
  {
     std::string msg;
     msg = filepath.string() + " has ambiguous extension " + extension + "\n"
       +  "Possible writers for this extension are: \n";
     boost_foreach(const Handle< MeshWriter > writer , m_extensions_to_writers[extension])
       msg += " - " + writer->name() + "\n";
     throw FileFormatError( FromHere(), msg);
   }
Esempio n. 2
0
bool operator == (const URI& lhs, const URI& rhs) noexcept {
  return icase_equal(lhs.scheme(), rhs.scheme())
         and (lhs.userinfo() == rhs.userinfo())
         and icase_equal(lhs.host(), rhs.host())
         and lhs.port() == rhs.port()
         and lhs.path() == rhs.path()
         and lhs.query() == rhs.query()
         and lhs.fragment() == rhs.fragment();
}
Esempio n. 3
0
Future<Nothing> Fetcher::fetch(
    const URI& uri,
    const string& directory) const
{
  if (!plugins.contains(uri.scheme())) {
    return Failure("Scheme '" + uri.scheme() + "' is not supported");
  }

  return plugins.at(uri.scheme())->fetch(uri, directory);
}
Esempio n. 4
0
void CPlotter::set_data_set(const URI &uri)
{
  cf3_assert ( !uri.empty() );
  cf3_assert ( uri.scheme() == URI::Scheme::CPATH );

  m_data = uri;
}
Esempio n. 5
0
bool BaseAppProtocolHandler::PullExternalStream(URI uri, Variant streamConfig)
{
    WARN("Pulling in streams for scheme %s in application %s not yet implemented. Stream configuration was:\n%s",
         STR(uri.scheme()),
         STR(GetApplication()->GetName()),
         STR(streamConfig.ToString()));
    return false;
}
Esempio n. 6
0
  XmlNode Protocol::add_signal_frame ( XmlNode& node, const std::string & target,
                                       const URI & sender, const URI & receiver,
                                       bool user_trans )
  {
    cf3_assert(sender.scheme() == URI::Scheme::CPATH);
    cf3_assert(receiver.scheme() == URI::Scheme::CPATH);

    XmlNode signalnode = node.add_node( Tags::node_frame() );

    signalnode.set_attribute( "type", Tags::node_type_signal() );
    signalnode.set_attribute( "target", target );
    signalnode.set_attribute( "sender", sender.string() );
    signalnode.set_attribute( "receiver", receiver.string() );
    signalnode.set_attribute( "transaction", user_trans ? "user" : "auto" );
    signalnode.set_attribute( "frameid", common::UUCount().string() );

    return signalnode;
  }
Esempio n. 7
0
  XmlNode Protocol::add_signal_frame ( XmlNode& node, const std::string & target,
                                       const URI & sender, const URI & receiver,
                                       bool user_trans )
  {
    cf_assert(sender.scheme() == URI::Scheme::CPATH);
    cf_assert(receiver.scheme() == URI::Scheme::CPATH);

    std::string uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()());

    XmlNode signalnode = node.add_node( Tags::node_frame() );

    signalnode.set_attribute( "type", Tags::node_type_signal() );
    signalnode.set_attribute( "target", target );
    signalnode.set_attribute( "sender", sender.string() );
    signalnode.set_attribute( "receiver", receiver.string() );
    signalnode.set_attribute( "transaction", user_trans ? "user" : "auto" );
    signalnode.set_attribute( "frameid", uuid );

    return signalnode;
  }
Esempio n. 8
0
std::size_t URI::HashFn::operator()(const URI& uri) const
{
    std::size_t seed = 0;

    if (uri.scheme()) {
        boost::hash_combine(seed, *uri.scheme());
    }

    if (uri.authority()) {
        boost::hash_combine(seed, *uri.authority());
    }

    boost::hash_combine(seed, uri.path());

    if (uri.query()) {
        boost::hash_combine(seed, *uri.query());
    }

    if (uri.fragment()) {
        boost::hash_combine(seed, *uri.fragment());
    }

    return seed;
}
Esempio n. 9
0
void
HTTPEngineSender::get(const URI& uri)
{
	if (!Raul::Path::is_path(uri) && uri.scheme() != "http") {
		LOG(warn) << "Ignoring GET of non-HTTP URI " << uri << endl;
		return;
	}

	const std::string request_uri = (Raul::Path::is_path(uri))
		?_engine_url.str() + "/patch" + uri.substr(uri.find("/"))
		: uri.str();
	cout << "Get " << request_uri << endl;
	LOG(debug) << "Get " << request_uri << endl;
	SoupMessage* msg = soup_message_new("GET", request_uri.c_str());
	HTTPClientReceiver::send(msg);
}
Esempio n. 10
0
void C3DViewBuilder::signal_create_3dview(SignalArgs &args)
{
  SignalOptions options( args );

  std::string name = options.value<std::string>("3DView name");
  URI parent = options.value<URI>("Parent");

  // some checks
  if(name.empty())
    throw BadValue(FromHere(), "The 3DView name is empty.");

  if(parent.empty())
    throw BadValue(FromHere(), "The parent is empty.");

  if(parent.scheme() != URI::Scheme::CPATH)
    throw InvalidURI(FromHere(), "The parent scheme is not CPATH");

  // create and add the component
  Handle<Component> parent_comp = Core::instance().root().access_component(parent);
  Handle<C3DView> view = parent_comp->create_component<C3DView>( name );
  view->mark_basic();
}
Esempio n. 11
0
void CPlotter::signal_create_xyplot(SignalArgs &args)
{
  SignalOptions options( args );

  std::string name = options.value<std::string>("Plot name");
  URI parent = options.value<URI>("Parent");

  // some checks
  if(name.empty())
    throw BadValue(FromHere(), "The plot name is empty.");

  if(parent.empty())
    throw BadValue(FromHere(), "The parent is empty.");

  if(parent.scheme() != URI::Scheme::CPATH)
    throw InvalidURI(FromHere(), "The parent scheme is not CPATH");

  // create and add the component
  Handle< Component > parent_comp = Core::instance().root().access_component(parent);
  boost::shared_ptr< CPlotXY > plot(common::allocate_component<CPlotXY>(name));
  parent_comp->add_component( plot );
  plot->mark_basic();
  plot->set_data(m_data);
}
Esempio n. 12
0
bool getCredentialsFromKeychain(const URI &uri, ClientRequest::ptr priorRequest,
    std::string &scheme, std::string &realm, std::string &username,
    std::string &password, size_t attempts)
{
    if (attempts != 1)
        return false;
    bool proxy =
       priorRequest->response().status.status == PROXY_AUTHENTICATION_REQUIRED;
    const ChallengeList &challengeList = proxy ?
        priorRequest->response().response.proxyAuthenticate :
        priorRequest->response().response.wwwAuthenticate;
    if (isAcceptable(challengeList, "Basic"))
        scheme = "Basic";
    else if (isAcceptable(challengeList, "Digest"))
        scheme = "Digest";
    else
        return false;

    std::vector<SecKeychainAttribute> attrVector;
    std::string host = uri.authority.host();
    attrVector.push_back((SecKeychainAttribute){kSecServerItemAttr, host.size(),
       (void *)host.c_str()});

    UInt32 port = 0;
    if (uri.authority.portDefined()) {
        port = uri.authority.port();
        attrVector.push_back((SecKeychainAttribute){kSecPortItemAttr,
           sizeof(UInt32), &port});
    }
    SecProtocolType protocol;
    if (proxy && priorRequest->request().requestLine.method == CONNECT)
        protocol = kSecProtocolTypeHTTPSProxy;
    else if (proxy)
        protocol = kSecProtocolTypeHTTPProxy;
    else if (uri.scheme() == "https")
        protocol = kSecProtocolTypeHTTPS;
    else if (uri.scheme() == "http")
        protocol = kSecProtocolTypeHTTP;
    else
        MORDOR_NOTREACHED();
    attrVector.push_back((SecKeychainAttribute){kSecProtocolItemAttr,
        sizeof(SecProtocolType), &protocol});

    ScopedCFRef<SecKeychainSearchRef> search;
    SecKeychainAttributeList attrList;
    attrList.count = (UInt32)attrVector.size();
    attrList.attr = &attrVector[0];

    OSStatus status = SecKeychainSearchCreateFromAttributes(NULL,
        kSecInternetPasswordItemClass, &attrList, &search);
    if (status != 0)
        return false;
    ScopedCFRef<SecKeychainItemRef> item;
    status = SecKeychainSearchCopyNext(search, &item);
    if (status != 0)
        return false;
    SecKeychainAttributeInfo info;
    SecKeychainAttrType tag = kSecAccountItemAttr;
    CSSM_DB_ATTRIBUTE_FORMAT format = CSSM_DB_ATTRIBUTE_FORMAT_STRING;
    info.count = 1;
    info.tag = (UInt32 *)&tag;
    info.format = (UInt32 *)&format;
    
    SecKeychainAttributeList *attrs;
    UInt32 passwordLength = 0;
    void *passwordBytes = NULL;

    status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attrs,
        &passwordLength, &passwordBytes);
    if (status != 0)
        return false;

    try {
        username.assign((const char *)attrs->attr[0].data, attrs->attr[0].length);
        password.assign((const char *)passwordBytes, passwordLength);
    } catch (...) {
        SecKeychainItemFreeContent(attrs, passwordBytes);
        throw;
    }
    SecKeychainItemFreeContent(attrs, passwordBytes);
    return true;
}
Esempio n. 13
0
void Component::complete_path ( URI& path ) const
{
  using namespace boost::algorithm;

//  CFinfo << "PATH [" << path.string() << "]\n" << CFflush;

  cf_assert( path.scheme() == URI::Scheme::CPATH );

  if(path.empty())
    path = "./";

  if ( is_null(m_raw_parent) )
    throw  InvalidURI(FromHere(), "Component \'" + name() + "\' has no parent");

  if (m_root.expired())
    throw  InvalidURI(FromHere(), "Component \'" + name() + "\' has no root");

  boost::shared_ptr<Component> parent = m_raw_parent->self();
  boost::shared_ptr<Component> root   = m_root.lock();

  std::string sp = path.path();

  if ( path.is_relative() ) // transform it to absolute
  {
    if ( starts_with(sp,"/") ) // remove leading "/" if any
      boost::algorithm::replace_first(sp, "/", "" );

    // substitute leading "../" for uri() of parent
    if (starts_with(sp,".."))
    {
      std::string pfp = parent->uri().path();
      boost::algorithm::replace_first(sp, "..", pfp);
    }
    // substitute leading "./" for uri() of this component
    else if (starts_with(sp,"."))
    {
      boost::algorithm::replace_first(sp, ".", uri().path());
    }
    else
    {
      sp = uri().path()+"/"+sp;
    }

  }

  cf_assert ( URI(sp).is_absolute() );

  // break path in tokens and loop on them, while concatenaitng to a new path
  boost::char_separator<char> sep("/");
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  tokenizer tok (sp,sep);

  path = "/" ;
  std::string last;
  for(tokenizer::iterator el=tok.begin(); el!=tok.end(); ++el)
  {
    if ( equals (*el, ".") ) continue;     // substitute any "/./" for nothing

    if ( equals (*el, "..") )              // substitute any "../" for base path
      path = path.base_path();
    else
      path /= *el;
  }

//  CFinfo << "FINAL PATH: [" << path.string() << "]\n" << CFflush;

  cf_assert ( path.is_complete() );
}