//---------------------------------------------------------------------------------
// Name: init()
// Desc: Loads metadata.
//---------------------------------------------------------------------------------
void ResourceManager::init()
{
    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file( RESOURCES_MAP );

    if (!result)
        _FATAL("Failed loading XML document : " + TO_STD_STRING(RESOURCES_MAP) + " XML error :  " + result.description());

    pugi::xml_node resource_tree = doc.child(RESOURCES);
    if ( !resource_tree )
        _FATAL("XML document : " + TO_STD_STRING(RESOURCES_MAP) + " is not valid");

    for ( pugi::xml_node  child = resource_tree.first_child() ; child; child = child.next_sibling() )
    {
        Resource * resource = NULL;

        std::string type = child.name();
        assert( !type.empty() );

        if ( pd->m_loaders.find(type) != pd->m_loaders.end() )
            resource = pd->m_loaders[type]( &child );
        
        assert(resource);

        incResCount( type );
        for ( pugi::xml_attribute element_attrb = child.first_attribute(); element_attrb;  element_attrb = element_attrb.next_attribute() )
        {
            std::string attrb_name = element_attrb.name();

            if ( attrb_name == FILENAME )
                resource->setFilePath(element_attrb.as_string()); 

            if ( attrb_name == RES_NAME )
                resource->setName(element_attrb.as_string()); 

            if ( attrb_name == GLOBAL )
                resource->setGlobal( element_attrb.as_bool() );
        }

        std::string file_path = resource->getFilePath();
        if ( file_path == UNDEFINED || file_path.empty() )
        {
            SAFE_DELETE(resource);
            continue;
        }

        std::string file_name = resource->getName();
        if ( file_name == UNDEFINED || file_name.empty() )
            resource->cutOutNameFromPath();

        resource->setResourceType( type );

        resource->setID( getNextResourceID() );
        pd->m_resources.push_back( resource );
    }
}
예제 #2
0
파일: tuntap_bsd.c 프로젝트: philpep/MLVPN
int
mlvpn_tuntap_read(struct tuntap_s *tuntap)
{
    circular_buffer_t *sbuf;
    mlvpn_tunnel_t *rtun;
    mlvpn_pkt_t *pkt;
    int ret;
    uint32_t type;
    struct iovec iov[2];

    /* choosing a tunnel to send to (direct buffer copy) */
    rtun = mlvpn_rtun_choose();

    /* Not connected to anyone. read and discard packet. */
    if (! rtun)
    {
        char blackhole[DEFAULT_MTU+sizeof(type)];
        return read(tuntap->fd, blackhole, DEFAULT_MTU+sizeof(type));
    }

    /* Buffer checking / reset in case of overflow */
    sbuf = rtun->sbuf;
    if (mlvpn_cb_is_full(sbuf))
        _WARNING("[rtun %s] buffer overflow.\n", rtun->name);

    /* Ask for a free buffer */
    pkt = mlvpn_pktbuffer_write(sbuf);

    iov[0].iov_base = &type;
    iov[0].iov_len = sizeof(type);
    iov[1].iov_base = pkt->pktdata.data;
    iov[1].iov_len = DEFAULT_MTU;

    ret = readv(tuntap->fd, iov, 2);
    if (ret < 0)
    {
        /* read error on tuntap is not recoverable. We must die. */
        _FATAL("[tuntap %s] unrecoverable read error: %s\n",
                tuntap->devname, strerror(errno));
        exit(1);
    } else if (ret == 0) {
        /* End of file */
        _FATAL("[tuntap %s] unrecoverable error (reached EOF on tuntap!)\n",
                tuntap->devname);
        exit(1);
    }
    pkt->pktdata.len = ret - sizeof(type);

    return pkt->pktdata.len;
}
예제 #3
0
파일: crt0-common.c 프로젝트: Ga-vin/MINIX3
void
___start(int argc, char **argv, char **envp,
    void (*cleanup)(void),			/* from shared loader */
    const Obj_Entry *obj,			/* from shared loader */
    struct ps_strings *ps_strings)
{
	environ = envp;

	if (argv[0] != NULL) {
		char *c;
		__progname = argv[0];
		for (c = argv[0]; *c; ++c) {
			if (*c == '/')
				__progname = c + 1;
		}
	} else {
		__progname = empty_string;
	}

	if (ps_strings != NULL)
		__ps_strings = ps_strings;

	if (&DYNAMIC_SYM != NULL) {
		if ((obj == NULL) || (obj->magic != RTLD_MAGIC))
			_FATAL("Corrupt Obj_Entry pointer in GOT\n");
		if (obj->version != RTLD_VERSION)
			_FATAL("Dynamic linker version mismatch\n");
		atexit(cleanup);
	}

#ifdef MCRT0
	atexit(_mcleanup);
	monstartup((u_long)&__eprol, (u_long)&__etext);
#endif

	atexit(_fini);
	_init();

	exit(main(argc, argv, environ));
}
예제 #4
0
파일: tuntap_bsd.c 프로젝트: philpep/MLVPN
int
mlvpn_tuntap_write(struct tuntap_s *tuntap)
{
    int len, datalen;
    mlvpn_pkt_t *pkt;
    circular_buffer_t *buf = tuntap->sbuf;
    uint32_t type;
    struct iovec iov[2];

    /* Safety checks */
    if (mlvpn_cb_is_empty(buf))
    {
        _FATAL("[tuntap %s] tuntap_write called with empty buffer!\n",
                tuntap->devname);
        return -1;
    }

    pkt = mlvpn_pktbuffer_read(buf);

    type = htonl(AF_INET);

    iov[0].iov_base = &type;
    iov[0].iov_len = sizeof(type);
    iov[1].iov_base = pkt->pktdata.data;
    iov[1].iov_len = pkt->pktdata.len;

    len = writev(tuntap->fd, iov, 2);
    datalen = len - iov[0].iov_len;
    if (len < 0)
    {
        _ERROR("[tuntap %s] write error: %s\n",
                tuntap->devname, strerror(errno));
    } else {
        if (datalen != pkt->pktdata.len)
        {
            _ERROR("[tuntap %s] write error: only %d/%d bytes sent.\n",
                    tuntap->devname, datalen, pkt->pktdata.len);
        } else {
            _DEBUG("[tuntap %s] >> wrote %d bytes.\n",
                    tuntap->devname, datalen);
        }
    }

    return datalen;
}
예제 #5
0
ObjectServer::ObjectServer(const char *name, string_map_t *options)
	: FileServer(name, options), m_enable_readdir(false)
{
	string sname("_");
	sname += name;
	const char *submodule = get_string(*options, "Submodule");
	if (submodule == NULL)
	{
		submodule = "default";
	}
	m_submodule = submodule;
	m_server = Modules::instance()->new_instance(submodule, sname.c_str(), options);
	if (!m_server)
	{
		_FATAL("Can not create server module %s", submodule);
	}
	ASSERT(m_server);
}
예제 #6
0
파일: tuntap_bsd.c 프로젝트: philpep/MLVPN
int
mlvpn_tuntap_alloc(struct tuntap_s *tuntap)
{
    char devname[8];
    int fd;
    int i;

    /* TODO: handle this by command line/config file ! */
    /* FreeBSD/OpenBSD (and others maybe) supports each tun on different device. */
    /* examples: /dev/tun0, /dev/tun2 (man 2 if_tun) */
    for (i=0; i < 32; i++)
    {
        snprintf(devname, 5, "%s%d",
            tuntap->type == MLVPN_TUNTAPMODE_TAP ? "tap" : "tun", i);
        snprintf(tuntap->devname, 10, "/dev/%s", devname);

        if ((fd = priv_open_tun(tuntap->type, tuntap->devname)) > 0 )
            break;
    }

    if (fd <= 0)
    {
        _FATAL("[tuntap] unable to open any /dev/%s0 to 32 read/write. "
               "Check permissions.\n",
            tuntap->type == MLVPN_TUNTAPMODE_TAP ? "tap" : "tun");
        return fd;
    }
    tuntap->fd = fd;

    /* geting the actual tun%d inside devname
     * is required for hooks to work properly */
    strlcpy(tuntap->devname, devname, MLVPN_IFNAMSIZ-1);

    char *hook_args[3] = {tuntap->devname, "tuntap_up", NULL};
    mlvpn_hook(MLVPN_HOOK_TUNTAP, 2, hook_args);
    return tuntap->fd;
}