/*
 * This is identical to 
 * PolicyCompiler_ipf::processMultiAddressObjectsInRE::processNext()
 * TODO: move the code to the class Compiler so it can be reused.
 */
bool RoutingCompiler::processMultiAddressObjectsInRE::processNext()
{
    RoutingRule *rule = getNext(); if (rule==NULL) return false;
    RuleElement *re = RuleElement::cast( rule->getFirstByType(re_type) );

    for (FWObject::iterator i=re->begin(); i!=re->end(); i++)
    {
        FWObject *o= *i;
        if (FWReference::cast(o)!=NULL) o=FWReference::cast(o)->getPointer();
        MultiAddressRunTime *atrt = MultiAddressRunTime::cast(o);
        if (atrt!=NULL && atrt->getSubstitutionTypeName()==AddressTable::TYPENAME)
            compiler->abort(
                rule, 
                "Run-time AddressTable objects are not supported.");

        AddressTable *at = AddressTable::cast(o);
        if (at && at->isRunTime())
            compiler->abort(
                rule, 
                "Run-time AddressTable objects are not supported.");
    }

    tmp_queue.push_back(rule);
    return true;
}
void AddressTableDialog::loadFWObject(FWObject *o)
{
    obj=o;
    AddressTable *s = dynamic_cast<AddressTable*>(obj);
    assert(s!=NULL);


    init = true;

    m_dialog->obj_name->setText( QString::fromUtf8(s->getName().c_str()) );
    m_dialog->commentKeywords->loadFWObject(o);

    m_dialog->filename->setText( s->getSourceName().c_str() );
    m_dialog->r_compiletime->setChecked(s->isCompileTime() );
    m_dialog->r_runtime->setChecked(s->isRunTime() );

    //BrowseButton->setEnabled(s->isCompileTime() );

    //apply->setEnabled( false );

    m_dialog->obj_name->setEnabled(!o->isReadOnly());
    setDisabledPalette(m_dialog->obj_name);

    m_dialog->filename->setEnabled(!o->isReadOnly());
    setDisabledPalette(m_dialog->filename);

    updateButtons();

    init = false;
}
void AddressTableDialog::applyChanges()
{
    std::auto_ptr<FWCmdChange> cmd( new FWCmdChange(m_project, obj));
    FWObject* new_state = cmd->getNewState();

    AddressTable *s = dynamic_cast<AddressTable*>(new_state);
    assert(s!=NULL);

    string oldname = obj->getName();
    new_state->setName( string(m_dialog->obj_name->text().toUtf8().constData()) );
    m_dialog->commentKeywords->applyChanges(new_state);

    QByteArray cs = m_dialog->filename->text().toLocal8Bit();
    s->setSourceName( (const char *)cs );
    s->setRunTime(m_dialog->r_runtime->isChecked() );

    updateButtons();

    if (!cmd->getOldState()->cmp(new_state, true))
    {
        if (obj->isReadOnly()) return;
        m_project->undoStack->push(cmd.release());
    }
   
}
示例#4
0
FWObject* AddressObjectMaker::createAddressTable(ObjectSignature &sig)
{
    FWObject *obj = findMatchingObject(sig);
    if (obj) return obj;

    AddressTable *at =  AddressTable::cast(
        ObjectMaker::createObject(AddressTable::TYPENAME,
                                  sig.object_name.toUtf8().constData()));
    assert(at!=nullptr);
    at->setRunTime(true);
    at->setSourceName(sig.address_table_name.toStdString());
    return at;
}
示例#5
0
static int
dump_local(int argc, char** argv)
{
	AddressTable::Iterator iterator = sAddressTable.GetIterator();
	size_t i = 0;
	while (InterfaceAddress* address = iterator.Next()) {
		address->Dump(++i);
		dprintf("    hash:          %" B_PRIu32 "\n",
			address->domain->address_module->hash_address(address->local,
				false));
	}
	return 0;
}
示例#6
0
InterfaceAddress*
get_interface_address(const sockaddr* local)
{
	if (local->sa_family == AF_UNSPEC)
		return NULL;

	MutexLocker locker(sHashLock);

	InterfaceAddress* address = sAddressTable.Lookup(local);
	if (address == NULL)
		return NULL;

	address->AcquireReference();
	return address;
}
示例#7
0
void
Interface::RemoveAddresses()
{
	RecursiveLocker locker(fLock);

	while (InterfaceAddress* address = fAddresses.RemoveHead()) {
		locker.Unlock();

		if (address->LocalIsDefined()) {
			MutexLocker hashLocker(sHashLock);
			sAddressTable.Remove(address);
		}
		address->ReleaseReference();

		locker.Lock();
	}
}
示例#8
0
status_t
Interface::AddAddress(InterfaceAddress* address)
{
	net_domain* domain = address->domain;
	if (domain == NULL)
		return B_BAD_VALUE;

	RecursiveLocker locker(fLock);
	fAddresses.Add(address);
	locker.Unlock();

	if (address->LocalIsDefined()) {
		MutexLocker hashLocker(sHashLock);
		sAddressTable.Insert(address);
	}
	return B_OK;
}
示例#9
0
void
Interface::RemoveAddress(InterfaceAddress* address)
{
	net_domain* domain = address->domain;
	if (domain == NULL)
		return;

	RecursiveLocker locker(fLock);

	fAddresses.Remove(address);
	address->GetDoublyLinkedListLink()->next = NULL;

	locker.Unlock();

	if (address->LocalIsDefined()) {
		MutexLocker hashLocker(sHashLock);
		sAddressTable.Remove(address);
	}
}
示例#10
0
status_t
update_interface_address(InterfaceAddress* interfaceAddress, int32 option,
	const sockaddr* oldAddress, const sockaddr* newAddress)
{
	TRACE("%s(address %p, option %" B_PRId32 ", oldAddress %s, newAddress "
		"%s)\n", __FUNCTION__, interfaceAddress, option,
		AddressString(interfaceAddress->domain, oldAddress).Data(),
		AddressString(interfaceAddress->domain, newAddress).Data());

	MutexLocker locker(sHashLock);

	// set logical interface address
	sockaddr** _address = interfaceAddress->AddressFor(option);
	if (_address == NULL)
		return B_BAD_VALUE;

	Interface* interface = (Interface*)interfaceAddress->interface;

	interfaceAddress->RemoveDefaultRoutes(option);

	if (option == SIOCDIFADDR) {
		// Remove address, and release its reference (causing our caller to
		// delete it)
		locker.Unlock();

		invalidate_routes(interfaceAddress);

		interface->RemoveAddress(interfaceAddress);
		interfaceAddress->ReleaseReference();
		return B_OK;
	}

	if (interfaceAddress->LocalIsDefined())
		sAddressTable.Remove(interfaceAddress);

	// Copy new address over
	status_t status = InterfaceAddress::Set(_address, newAddress);
	if (status == B_OK) {
		sockaddr* address = *_address;

		if (option == SIOCSIFADDR || option == SIOCSIFNETMASK) {
			// Reset netmask and broadcast addresses to defaults
			net_domain* domain = interfaceAddress->domain;
			sockaddr* defaultNetmask = NULL;
			const sockaddr* netmask = NULL;
			if (option == SIOCSIFADDR) {
				defaultNetmask = InterfaceAddress::Prepare(
					&interfaceAddress->mask, address->sa_len);
			} else
				netmask = newAddress;

			// Reset the broadcast address if the address family has
			// such
			sockaddr* defaultBroadcast = NULL;
			if ((domain->address_module->flags
					& NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS) != 0) {
				defaultBroadcast = InterfaceAddress::Prepare(
					&interfaceAddress->destination, address->sa_len);
			} else
				InterfaceAddress::Set(&interfaceAddress->destination, NULL);

			domain->address_module->set_to_defaults(defaultNetmask,
				defaultBroadcast, interfaceAddress->local, netmask);
		}

		interfaceAddress->AddDefaultRoutes(option);
		notify_interface_changed(interface);
	}

	if (interfaceAddress->LocalIsDefined())
		sAddressTable.Insert(interfaceAddress);
	return status;
}
示例#11
0
文件: mpqe.cpp 项目: vata/wowice
int main(int argc, char** argv)
{
	char version[] = "1.4";
	int hMPQ = 0;
	int hFile = 0;
	int FileSize = 0;
	int FileRead = 0;
	size_t slen = 0;
	mpqeOptions op;
	AddressTable at;
	op.option_verbose = false;
	op.option_outdir = NULL;
	op.option_lowercase = false;
	op.option_baseMPQ = NULL;
	op.option_searchglob = NULL;
	op.option_skipdirstructure = false;
	char* curdir;
	char* errbuf;
	
	printf("MPQ-Extractor v%s by WRS", version);
	if(!LoadAddresses(&at))
	{
		return -1;
	}
	printf(" powered by %s\n", at.pMpqGetVersionString());
	SFMPQVERSION v = at.pSFMpqGetVersion();
	printf("version: %d.%d.%d.%d\n", v.Major, v.Minor, v.Revision, v.Subrevision);
	if(argc<2)
	{
		ShowHelp();
		return -1;
	}
	errbuf = new char[ERRBUF_SIZE];
	curdir = new char[MAX_PATH];
	if(_getcwd(curdir, MAX_PATH) == NULL)
	{
		_strerror_s(errbuf, ERRBUF_SIZE, NULL);
		fprintf(stderr,"Unable to get current working directory : %s\n", errbuf);
		strcpy_s(curdir,MAX_PATH,".");
	}
	for(int i = 1; i < argc; ++i)
	{
		if(_stricmp(argv[i],"/p")==0) // use patch files if available
		{
// this can be a major slowdown in a batch file processing several MPQs
// for speed, extract all the other MPQs first then the patch-*.mpq last
// don't fatal-error out, just print warning message
			printf("Ignoring /p option (removed)\n");
		}
		else if(_stricmp(argv[i],"/l")==0)
		{
			printf("Lowercase output: Enabled\n");
			op.option_lowercase = true;
		}
		else if(_stricmp(argv[i],"/v")==0)
		{
			printf("Verbose output: Enabled\n");
			op.option_verbose = true;
		}
		else if(_stricmp(argv[i],"/d")==0)
		{
			if((i+1)>=argc)
			{
				fprintf(stderr,"Fatal: No output directory specified for /d\n");
				ShowHelp();
				return -1;
			}
			printf("Output directory: %s\n", argv[++i]);
			if(op.option_outdir != NULL)
			{
				delete [] op.option_outdir;
			}
			slen = strlen(argv[i])+1;
			op.option_outdir = new char[slen];
			strcpy_s(op.option_outdir, slen, argv[i]);
		}
		else if(_stricmp(argv[i],"/s")==0)
		{
			op.option_skipdirstructure = true;
			printf("Skipping directory structure creation\n");
		}
		else if(argv[i][0]=='/')
		{
			fprintf(stderr,"Fatal: Unknown option %s\n", argv[i]);
			ShowHelp();
			return -1;
		}
		else
		{
			if(op.option_baseMPQ == NULL)
			{
				slen = strlen(argv[i])+1;
				op.option_baseMPQ = new char[slen];
				strcpy_s(op.option_baseMPQ, slen, argv[i]);
			}
			else
			{
				if(op.option_searchglob != NULL)
				{
					delete [] op.option_searchglob;
				}
				slen = strlen(argv[i]) + 1;
				op.option_searchglob = new char[slen];
				strcpy_s(op.option_searchglob, slen, argv[i]);
			}
		}
	}
	if(op.option_baseMPQ == NULL)
	{
		fprintf(stderr,"Fatal: Did not provide MPQ file for extraction!\n");
		ShowHelp();
		return -1;
	}
	if(op.option_outdir == NULL)
	{
		op.option_outdir = new char[16];
		strcpy_s(op.option_outdir, 16, "MPQOUT");
	}
	if(strchr(op.option_baseMPQ,'\\')) // contains a backslash, change directory
	{
		char* d = op.option_baseMPQ;
		char* p = strrchr(op.option_baseMPQ,'\\');
		*p = '\0';
		p++;
		op.option_baseMPQ = p;
		if(_chdir(d)==-1)
		{
			_strerror_s(errbuf, ERRBUF_SIZE, NULL);
			fprintf(stderr,"Unable to change directory to %s : %s\n", d, errbuf);
			return -1;
		}
	}

	WIN32_FIND_DATA fd;
	HANDLE hf = FindFirstFile(op.option_baseMPQ, &fd);
	if(hf == INVALID_HANDLE_VALUE)
	{
		fprintf(stderr,"Fatal: Could not open MPQ archive %s Error: %s\n", op.option_baseMPQ, GetErrorText(GetLastError()));
		_chdir(curdir);
		return -1;
	}
	// first, get number of matching mpq files ...
	DWORD nFiles = 1;
	while(GetLastError()!=ERROR_NO_MORE_FILES)
	{
		if(FindNextFile(hf, &fd))
		{
			++nFiles;
		}
	}
	FindClose(hf);
	// got number of files, now fill information
	FileList* fList = new FileList[nFiles];
	hf = FindFirstFile(op.option_baseMPQ, &fd);
	if(hf == INVALID_HANDLE_VALUE) // how did this happen? it was valid before!
	{
		fprintf(stderr,"Fatal: Could not open MPQ archive %s Error: %s\n", op.option_baseMPQ, GetErrorText(GetLastError()));
		_chdir(curdir);
		return -1;
	}
	// first, get number of matching mpq files ...
	DWORD index;
	for( index=0; index<nFiles; ++index )
	{
		fList[index].fwtime.HighPart = fd.ftLastWriteTime.dwHighDateTime;
		fList[index].fwtime.LowPart = fd.ftLastWriteTime.dwLowDateTime;
		fList[index].fname = new char[strlen(fd.cFileName)+1];
		strcpy(fList[index].fname, fd.cFileName);
		while(!FindNextFile(hf, &fd))
		{
			if(GetLastError()==ERROR_NO_MORE_FILES)
			{
				nFiles = index+1;
				break;
			}
		}
	}
	// got all mpq file names and last-write-times, now sort them (process oldest first)
	if(nFiles > 1) // no need to sort if there's only one
	{
		FileList tmp;
		// this is probably a slow sorter, but how many mpqs are there going to be anyway?
		for(index=1; index<nFiles; ++index)
		{
			if(fList[index-1].fwtime.QuadPart < fList[index].fwtime.QuadPart) // swap these
			{
				tmp.fname = fList[index].fname;
				tmp.fwtime = fList[index].fwtime;
				fList[index].fname = fList[index-1].fname;
				fList[index].fwtime = fList[index-1].fwtime;
				fList[index-1].fname = tmp.fname;
				fList[index-1].fwtime = tmp.fwtime;
				index = 0; // start over
			}
		}
	}
	// now process the mpqs
	for( index=0; index<nFiles; ++index )
	{
		mpqExtract(&at, &op, fList[index].fname);
	}
	_chdir(curdir);
	delete [] curdir;
	delete [] errbuf;
	return 0;
}