Beispiel #1
0
Switches::Switches(const in_sw_tab_t* table, size_t count, bool copy, bool minLength)
	: m_base(table), m_count(count), m_copy(copy), m_minLength(minLength),
	  m_table(0), m_opLengths(0)
{
	fb_assert(table && count > 1); // the last element is a terminator
	if (!table || count < 2)
		complain("Switches: invalid arguments for constructor");

	if (m_copy)
	{
		m_table = FB_NEW(*getDefaultMemoryPool()) in_sw_tab_t[m_count];
		for (size_t iter = 0; iter < m_count; ++iter)
			m_table[iter] = m_base[iter];
	}

	m_opLengths = FB_NEW(*getDefaultMemoryPool()) size_t[m_count];

	for (size_t iter = 0; iter < m_count; ++iter)
	{
		if (m_base[iter].in_sw_name)
		{
			m_opLengths[iter] = strlen(m_base[iter].in_sw_name);
			fb_assert(m_opLengths[iter] > 0);
			fb_assert(!m_minLength || m_opLengths[iter] >= m_base[iter].in_sw_min_length);
		}
		else
			m_opLengths[iter] = 0;
	}
}
Beispiel #2
0
void TraceManager::load_plugins()
{
	// Initialize all trace needs to false
	trace_needs = 0;

	if (init_factories)
		return;

	MutexLockGuard guard(init_factories_mtx, FB_FUNCTION);
	if (init_factories)
		return;

	init_factories = true;

	factories = FB_NEW(*getDefaultMemoryPool()) TraceManager::Factories(*getDefaultMemoryPool());
	for (GetPlugins<ITraceFactory> traceItr(IPluginManager::Trace); traceItr.hasData(); traceItr.next())
	{
		FactoryInfo info;
		info.factory = traceItr.plugin();
		info.factory->addRef();
		string name(traceItr.name());
		name.copyTo(info.name, sizeof(info.name));
		factories->add(info);
	}
}
Beispiel #3
0
MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats& stats)
{
    if (!parentPool)
    {
        parentPool = getDefaultMemoryPool();
    }
    return FB_NEW(*parentPool) MemoryPool(*parentPool, stats);
}
Beispiel #4
0
		static void create(Database* dbb)
		{
			if (!dbb->dbb_external_file_directory_list)
			{
				dbb->dbb_external_file_directory_list =
					FB_NEW(*dbb->dbb_permanent) ExternalFileDirectoryList(dbb);
			}
		}
Beispiel #5
0
ResultSet* PreparedStatement::executeQuery(thread_db* tdbb, jrd_tra* transaction)
{
	fb_assert(resultSet == NULL && request->getStatement()->getReceiveMsg());

	if (builder)
		builder->moveToStatement(tdbb, this);

	return FB_NEW(getPool()) ResultSet(tdbb, this, transaction);
}
ConfigStorage::ConfigStorage()
	: m_timer(new TouchFile),
	  m_sharedMemory(NULL),
	  m_recursive(0),
	  m_mutexTID(0)
{
	m_cfg_file = -1;
	m_dirty = false;

	PathName filename;
#ifdef WIN_NT
	DWORD sesID = 0;

	typedef BOOL (WINAPI *PFnProcessIdToSessionId) (DWORD, DWORD *);

	HMODULE hmodKernel32 = GetModuleHandle("kernel32.dll");

	PFnProcessIdToSessionId pfnProcessIdToSessionId =
		(PFnProcessIdToSessionId) GetProcAddress(hmodKernel32, "ProcessIdToSessionId");

	if (fb_utils::isGlobalKernelPrefix() ||
		!pfnProcessIdToSessionId ||
		pfnProcessIdToSessionId(GetCurrentProcessId(), &sesID) == 0 ||
		sesID == 0)
	{
		filename.printf(TRACE_FILE); // TODO: it must be per engine instance
	}
	else
	{
		filename.printf("%s.%u", TRACE_FILE, sesID);
	}
#else
	filename.printf(TRACE_FILE); // TODO: it must be per engine instance
#endif

	try
	{
		m_sharedMemory.reset(FB_NEW(getPool())
			SharedMemory<TraceCSHeader>(filename.c_str(), sizeof(TraceCSHeader), this));
	}
	catch (const Exception& ex)
	{
		iscLogException("ConfigStorage: Cannot initialize the shared memory region", ex);
		throw;
	}

	fb_assert(m_sharedMemory->getHeader());
	fb_assert(m_sharedMemory->getHeader()->mhb_version == 1);

	StorageGuard guard(this);
	checkFile();
	m_timer->start(m_sharedMemory->getHeader()->cfg_file_name);

	++(m_sharedMemory->getHeader()->cnt_uses);
}
Beispiel #7
0
ConfigImpl::ConfigImpl(MemoryPool& p) : ConfigRoot(p), confMessage(p)
{
    // Prepare some stuff

    ConfigFile file(p);
    root_dir = getRootDirectory();
    const int size = FB_NELEM(entries);
    values = FB_NEW(p) ConfigValue[size];

    //string val_sep = ",";
    file.setConfigFilePath(getConfigFilePath());

    // Iterate through the known configuration entries

    for (int i = 0; i < size; i++)
    {
        const ConfigEntry entry = entries[i];
        const string value = getValue(file, entries[i].key);

        if (!value.length())
        {
            // Assign the default value

            values[i] = entries[i].default_value;
            continue;
        }

        // Assign the actual value

        switch (entry.data_type)
        {
        case TYPE_BOOLEAN:
            values[i] = (ConfigValue) asBoolean(value);
            break;
        case TYPE_INTEGER:
            values[i] = (ConfigValue) asInteger(value);
            break;
        case TYPE_STRING:
        {
            const char* src = asString(value);
            char* dst = FB_NEW(p) char[strlen(src) + 1];
            strcpy(dst, src);
            values[i] = (ConfigValue) dst;
        }
        break;
            //case TYPE_STRING_VECTOR:
            //	break;
        }
    }

    if (file.getMessage())
    {
        confMessage = file.getMessage();
    }
}
Beispiel #8
0
void PortsCleanup::registerPort(rem_port* port)
{
	Firebird::MutexLockGuard guard(m_mutex);
	if (!m_ports)
	{
		Firebird::MemoryPool& pool = *getDefaultMemoryPool();
		m_ports = FB_NEW (pool) PortsArray(pool);
	}

	m_ports->add(port);
}
Beispiel #9
0
DmlNode* InAutonomousTransactionNode::parse(thread_db* tdbb, MemoryPool& pool,
		CompilerScratch* csb)
{
	InAutonomousTransactionNode* node = FB_NEW(pool) InAutonomousTransactionNode(pool);

	if (csb->csb_blr_reader.getByte() != 0)	// Reserved for future improvements. Should be 0 for now.
		PAR_syntax_error(csb, "0");

	node->action = PAR_parse_node(tdbb, csb, STATEMENT);

	return node;
}
Beispiel #10
0
ServerAuth::ServerAuth(const char* fName, int fLen, const Firebird::ClumpletWriter& pb,
					   ServerAuth::Part2* p2, P_OP op)
	: fileName(*getDefaultMemoryPool()), clumplet(*getDefaultMemoryPool()),
	  part2(p2), operation(op)
{
	fileName.assign(fName, fLen);
	size_t pbLen = pb.getBufferLength();
	if (pbLen)
	{
		memcpy(clumplet.getBuffer(pbLen), pb.getBuffer(), pbLen);
	}
	authSspi = FB_NEW(*getDefaultMemoryPool()) AuthSspi;
}
Beispiel #11
0
ModuleLoader::Module* ModuleLoader::loadModule(const Firebird::PathName& modPath)
{
    void* module = dlopen(modPath.c_str(), FB_RTLD_MODE);
    if (module == NULL)
    {
#ifdef DEBUG_LOADER
        fprintf(stderr, "load error: %s: %s\n", mod_path.c_str(), dlerror());
#endif // DEBUG_LOADER
        return 0;
    }

    return FB_NEW(*getDefaultMemoryPool()) DlfcnModule(module);
}
Beispiel #12
0
	PublicHandle::PublicHandle()
		: RefPtr<ExistenceMutex>(FB_NEW(*getDefaultMemoryPool()) ExistenceMutex)
	{
		WriteLockGuard guard(sync);

		if (handles->exist(this))
		{
			fb_assert(false);
		}
		else
		{
			handles->add(this);
		}
	}
Beispiel #13
0
InAutonomousTransactionNode* InAutonomousTransactionNode::dsqlPass()
{
	const bool autoTrans = compiledStatement->req_flags & REQ_in_auto_trans_block;
	compiledStatement->req_flags |= REQ_in_auto_trans_block;

	InAutonomousTransactionNode* node = FB_NEW(getPool()) InAutonomousTransactionNode(getPool());
	node->compiledStatement = compiledStatement;
	node->dsqlAction = PASS1_statement(compiledStatement, dsqlAction);

	if (!autoTrans)
		compiledStatement->req_flags &= ~REQ_in_auto_trans_block;

	return node;
}
	TextureAtlasRegionPtr TextureAtlas::AddRegion(const char* name)
	{
		if (!name || strlen(name) == 0){
			Logger::Log(FB_DEFAULT_LOG_ARG, "invalid arg");
			return 0;
		}
		auto it = mRegions.Find(name);
		if (it != mRegions.end()){
			Logger::Log(FB_DEFAULT_LOG_ARG, "already existing. returning it.");
			return it->second;
		}

		TextureAtlasRegionPtr region(FB_NEW(TextureAtlasRegion), [](TextureAtlasRegion* obj){ FB_DELETE(obj); });
		region->mName = name;
		mRegions.Insert(std::make_pair(region->mName, region));
		return region;
	}
Beispiel #15
0
StatusVector::StatusVector(const ISC_STATUS* s) :
	Base(FB_NEW(*getDefaultMemoryPool()) ImplStatusVector(s))
{
}
Beispiel #16
0
SLONG ISC_set_prefix(const TEXT* sw, const TEXT* path)
{
/**************************************
 *
 *      i s c _ s e t _ p r e f i x
 *
 **************************************
 *
 * Functional description
 *      Parse the 'E' argument further for 'EL' 'EM' or 'E'
 *
 **************************************/

	/*
	 * We can't call gds__get_prefix() at once when switch is found.
	 * gds__get_prefix() invokes GDS_init_prefix(), which in turn causes
	 * config file to be loaded. And in case when -el or -em is given
	 * before -e, this leads to use of wrong firebird.conf.
	 * To avoid it accumulate values for switches locally,
	 * and finally when called with sw==0, use them in correct order.
	 */
	static struct ESwitches
	{
		Firebird::PathName prefix, lockPrefix, msgPrefix;

		explicit ESwitches(MemoryPool& p)
			: prefix(p), lockPrefix(p), msgPrefix(p)
		{
		}
	}* eSw = 0;

	if (! sw)
	{
		if (eSw)
		{
			setPrefixIfNotEmpty(eSw->prefix, IB_PREFIX_TYPE);
			setPrefixIfNotEmpty(eSw->lockPrefix, IB_PREFIX_LOCK_TYPE);
			setPrefixIfNotEmpty(eSw->msgPrefix, IB_PREFIX_MSG_TYPE);

			delete eSw;
			eSw = 0;
		}

		return 0;
	}

	if ((!path) || (path[0] <= ' '))
	{
		return -1;
	}

	if (! eSw)
	{
		eSw = FB_NEW(*getDefaultMemoryPool()) ESwitches(*getDefaultMemoryPool());
	}

	switch (UPPER(*sw))
	{
	case '\0':
		eSw->prefix = path;
		break;
	case 'L':
		eSw->lockPrefix = path;
		break;
	case 'M':
		eSw->msgPrefix = path;
		break;
	default:
		return -1;
	}

	return 0;
}
Beispiel #17
0
PathUtils::dir_iterator *PathUtils::newDirItr(MemoryPool& p, const Firebird::PathName& path)
{
	return FB_NEW(p) PosixDirItr(p, path);
}
Beispiel #18
0
void Config::setRootDirectoryFromCommandLine(const Firebird::PathName& newRoot)
{
	delete rootFromCommandLine;
	rootFromCommandLine = FB_NEW(*getDefaultMemoryPool())
		Firebird::PathName(*getDefaultMemoryPool(), newRoot);
}
Beispiel #19
0
StatusVector::StatusVector(ISC_STATUS k, ISC_STATUS c) :
	Base(FB_NEW(*getDefaultMemoryPool()) ImplStatusVector(k, c))
{
	operator<<(*(static_cast<Base*>(this)));
}
Beispiel #20
0
Base::Base(ISC_STATUS k, ISC_STATUS c) :
	implementation(FB_NEW(*getDefaultMemoryPool()) ImplBase(k, c))
{
}
Beispiel #21
0
static tdr* get_description(ISC_QUAD* blob_id)
{
	TEXT buffer[1024];
	TEXT* bigger_buffer = 0;
	AliceGlobals* tdgbl = AliceGlobals::getSpecific();

	const TEXT* p = buffer;
	const USHORT length = snarf_blob(blob_id, (USHORT) sizeof(buffer), buffer);
	if (length)
	{
		p = bigger_buffer = (TEXT *) gds__alloc((SLONG) length);
		if (!p)
		{
			tdgbl->status[0] = isc_arg_gds;
			tdgbl->status[1] = isc_virmemexh;
			tdgbl->status[2] = isc_arg_end;

			ALICE_print_status(true, tdgbl->status);
			return NULL;
		}
		snarf_blob(blob_id, length, bigger_buffer);
	}

	tdr* trans = NULL;
	alice_str* host_site = NULL;
	alice_str* database_path = NULL;

	// skip version number
	++p;

	tdr* ptr = NULL; // silence uninitialized warning
	SLONG id_length, id;

	while (*p)
	{
		switch (*p++)
		{
		case TDR_HOST_SITE:
			host_site = alloc_string(&p);
			break;

		case TDR_DATABASE_PATH:
			database_path = alloc_string(&p);
			break;

		case TDR_TRANSACTION_ID:
			id_length = *p++;
			id = gds__vax_integer(reinterpret_cast<const UCHAR*>(p), id_length);
			p += id_length;
			if (!trans) {
				trans = ptr = FB_NEW(*tdgbl->getDefaultPool()) tdr;
			}
			else
			{
				ptr->tdr_next = FB_NEW(*tdgbl->getDefaultPool()) tdr;
				ptr = ptr->tdr_next;
			}
			ptr->tdr_host_site = host_site;
			ptr->tdr_fullpath = database_path;
			parse_fullpath(ptr);
			ptr->tdr_id = id;
			database_path = NULL;
			break;

		default:
			ALICE_print(108);
			// msg 108: Transaction description item unknown.

			if (length) {
				gds__free(bigger_buffer);
			}
			return NULL;
		}
	}

	if (length) {
		gds__free(bigger_buffer);
	}

	return trans;
}
Beispiel #22
0
StatusVector::StatusVector() :
	Base(FB_NEW(*getDefaultMemoryPool()) ImplStatusVector(0, 0))
{
}