/*
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
 * Method:    internalCopyAttributes
 * Signature: ([B[BZ)Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributes
   (JNIEnv *env, jclass clazz, jbyteArray source, jbyteArray destination, jboolean copyLastModified) {

	HANDLE handle;
	WIN32_FIND_DATA info;
	jbyte *sourceFile, *destinationFile;
	int success = 1;

	sourceFile = getByteArray(env, source);
	destinationFile = getByteArray(env, destination);

	handle = FindFirstFile(sourceFile, &info);
	if (handle != INVALID_HANDLE_VALUE) {
		success = SetFileAttributes(destinationFile, info.dwFileAttributes);
		if (success != 0 && copyLastModified) {
			// does not honor copyLastModified
			// call to SetFileTime should pass file handle instead of file name
			// success = SetFileTime(destinationFile, &info.ftCreationTime, &info.ftLastAccessTime, &info.ftLastWriteTime);
		}
	} else {
		success = 0;
	}

	free(sourceFile);
	free(destinationFile);
	FindClose(handle);
	return success;
}
示例#2
0
void WebPage::triggerAction(WebAction action, bool checked)
{
    if (action == Back) {
        m_back = true;
        QVariant var(m_back);
        OPNET::OpNetwork::instance()->sendUIMsg(MSG_navBackOrForward, getByteArray(var));
    }
    if (action == Forward) {
        m_back = false;
        QVariant var(m_back);
        OPNET::OpNetwork::instance()->sendUIMsg(MSG_navBackOrForward, getByteArray(var));
    }

    QWebPage::triggerAction(action, checked);
}
示例#3
0
CString FileIO::getFixedString()
{
	struct typ_prefixByte
	{
		unsigned int len : 7;
		unsigned int encoded : 1;
	};

	unsigned long finalLen = 0;

	unsigned char result = getUByte();
	typ_prefixByte prefix = *((typ_prefixByte*)(&result));

	finalLen = finalLen | (unsigned long)prefix.len;

	int bitshift = 0;

	while (prefix.encoded)
	{
		bitshift += 7;
		result = getUByte();
		prefix = *((typ_prefixByte*)(&result));
		finalLen = finalLen | ((unsigned long)prefix.len) << bitshift;
	}

	char * string = getByteArray(finalLen);
	char * tmpString = new char [finalLen + 1];
	memcpy(tmpString, string, finalLen);
	tmpString[finalLen] = '\0';
	CString finalString(tmpString);
	delete [] tmpString;
	delete [] string;

	return finalString;
}
void Battery::update()
{
    BatteryStatus status      = getStatusValue(mPathBatteryStatus);
    BatteryHealth health      = getHealthValue(mPathBatteryHealth);
    bool          ac_online   = getBooleanValue(mPathACOnline);
    bool          usb_online  = getBooleanValue(mPathUSBOnline);
    bool          present     = getBooleanValue(mPathBatteryPresent);
    int           capacity    = getIntegerValue(mPathBatteryCapacity);
    int           voltage     = getIntegerValue(mPathBatteryVoltage) / mVoltageDivisor;
    int           temperature = getIntegerValue(mPathBatteryTemperature);
    QString       technology  = getByteArray(mPathBatteryTechnology);

    bool changed = (status != mStatus || health != mHealth ||
		    ac_online != mACOnline || usb_online != mUSBOnline ||
		    present != mPresent || capacity != mCapacity ||
		    voltage != mVoltage || temperature != mTemperature ||
		    technology != mTechnology );

    if (changed) {
	mStatus      = status;
	mHealth      = health;
	mACOnline    = ac_online;
	mUSBOnline   = usb_online;
	mPresent     = present;
	mCapacity    = capacity;
	mVoltage     = voltage;
	mTemperature = temperature;
	mTechnology  = technology;
	emit dataChanged();
    }
}
uint8_t initializeVersionChecksumBytesFromBytes(VersionChecksumBytes * self,uint8_t * bytes,uint32_t size,uint8_t cacheString,void (*onErrorReceived)(Error error,char *,...)){	self->cacheString = cacheString;
	self->cachedString = NULL;
	if (! initializeNewByteArrayFromData(getByteArray(self), bytes, size, onErrorReceived)){
		return FALSE;
	}
	return TRUE;
}
static int getIntegerValue(const QString& path)
{
    QByteArray data = getByteArray(path);
    if (data.size())
	return data.toInt();
    return 0;
}
void destroyVersionChecksumBytes(void * vself){
	VersionChecksumBytes * self = vself;
	if (self->cachedString){
		decrementReferenceCount(self->cachedString);
	}
	destroyByteArray(getByteArray(self));
}
/*
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
 * Method:    internalGetFileInfo
 * Signature: ([CLorg/eclipse/core/filesystem/IFileInfo;)Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalGetFileInfo
   (JNIEnv *env, jclass clazz, jbyteArray target, jobject fileInfo) {
	jbyte *name;
	jsize size;
	HANDLE handle;
	WIN32_FIND_DATA info;

	name = getByteArray(env, target);
	size = (*env)->GetArrayLength(env, target);
	// FindFirstFile does not work at the root level. However, we 
	// don't need it because the root will never change timestamp
	// The pattern \\?\c:\ represents a root path  
	if (size == 7 && name[2] == '?' && name[5] == ':' && name[6] == '\\') {
		free(name);
		return fillEmptyDirectory(env, fileInfo);
	}
	handle = FindFirstFile(name, &info);
	free(name);
	if (handle == INVALID_HANDLE_VALUE) {
		if (GetLastError() != ERROR_FILE_NOT_FOUND)
			setIOError(env, fileInfo);
		return JNI_FALSE;
	}
	FindClose(handle);
	return convertFindDataToFileInfo(env, info, fileInfo);
}
ByteArray * getStringForVersionChecksumBytes(VersionChecksumBytes * self){
	if (self->cachedString) {
		incrementReferenceCount(self->cachedString);
		return self->cachedString;
	} else {
		reverseBytes(getByteArray(self));

		BigInt bytes;
		BigIntAlloc(&bytes, getByteArray(self)->length);
		bytes.length = getByteArray(self)->length;
		memcpy(bytes.data, getByteArrayData(getByteArray(self)), bytes.length);

		char * string = encodeBase58(bytes.data,bytes.length);

		if (! string){
			return NULL;
		}
		ByteArray * str = createNewByteArrayFromString(string, TRUE, getByteArray(self)->onErrorReceived);
		if (! str) {
			free(string);
			return NULL;
		}
		reverseBytes(getByteArray(self));
		if (self->cacheString) {
			self->cachedString = str;
			incrementReferenceCount(str);
		}

		return str;
	}
}
/*BYTE SERIALIZATION AND DESERIALIZATION*/
uint32_t serializeTransactionOutput(TransactionOutput * self)
{
	assert(self!= NULL);
	ByteArray * bytes = getMessage(self)->bytes;

	if (!bytes) {
		getMessage(self)->onErrorReceived(
				ERROR_MESSAGE_SERIALISATION_NULL_BYTES,
				"Attempting to serialize a TransactionOutput with no bytes.");
		return 0;
	}

	if (!self->scriptObject) {
		getMessage(self)->onErrorReceived(
				ERROR_MESSAGE_SERIALISATION_BAD_DATA,
				"Attempting to serialize a TransactionOutput without a scriptObject.");
		return 0;
	}

	VarLenInt scriptLen = createVarLenIntFromUInt64(getByteArray(self->scriptObject)->length);

	uint32_t requiredLen = 8 + scriptLen.storageSize + getByteArray(self->scriptObject)->length;

	if (bytes->length < requiredLen) {
		getMessage(self)->onErrorReceived(
				ERROR_MESSAGE_SERIALISATION_BAD_BYTES,
				"TransactionOutput has fewer bytes than expected. TransactionOutput byte-length: %i < required: %i\n",
				bytes->length, requiredLen);
		return 0;
	}

	/* Serialize data into the ByteArray and reference objects to this ByteArray to save memory. */
	writeInt64AsLittleEndianIntoByteArray(bytes, 0, self->value);
	encodeVarLenInt(bytes, 8, scriptLen);

	copyByteArrayToByteArray(bytes, 8 + scriptLen.storageSize, getByteArray(self->scriptObject));
	changeByteArrayDataReference(getByteArray(self->scriptObject), bytes, 8 + scriptLen.storageSize);
	return requiredLen;
}
static Battery::BatteryStatus getStatusValue(const QString& path)
{
    QByteArray data = getByteArray(path);
    if (data.size()) {
	switch (data.data()[0]) {
	case 'C': return Battery::CHARGING;
	case 'D': return Battery::DISCHARGING;
	case 'F': return Battery::FULL;
	case 'N': return Battery::NOT_CHARGING;
	default:
	    return Battery::STATUS_UNKNOWN;
	}
    }
    return Battery::STATUS_UNKNOWN;
}
/*
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
 * Method:    internalSetFileInfo
 * Signature: ([BLorg/eclipse/core/filesystem/IFileInfo;)Z
 */
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalSetFileInfo
  (JNIEnv *env, jclass clazz, jcharArray target, jobject obj) {

	HANDLE handle;
	jbyte *targetFile;
    jmethodID mid;
	int success = JNI_FALSE;
	DWORD attributes;
    jboolean readOnly, hidden, archive;
    jclass cls;

    /* find out if we need to set the readonly bit */
    cls = (*env)->GetObjectClass(env, obj);
    mid = (*env)->GetMethodID(env, cls, "getAttribute", "(I)Z");
    if (mid == 0) goto fail;
    readOnly = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_READ_ONLY);

    /* find out if we need to set the archive bit */
    archive = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_ARCHIVE);

    /* find out if we need to set the hidden bit */
    hidden = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_HIDDEN);

	targetFile = getByteArray(env, target);
	attributes = GetFileAttributes(targetFile);
	if (attributes == (DWORD)-1) goto fail;

	if (readOnly)
		attributes = attributes | FILE_ATTRIBUTE_READONLY;
	else
		attributes = attributes & ~FILE_ATTRIBUTE_READONLY;
	if (archive)
		attributes = attributes | FILE_ATTRIBUTE_ARCHIVE;
	else
		attributes = attributes & ~FILE_ATTRIBUTE_ARCHIVE;
	if (hidden)
		attributes = attributes | FILE_ATTRIBUTE_HIDDEN;
	else
		attributes = attributes & ~FILE_ATTRIBUTE_HIDDEN;
	
	success = SetFileAttributes(targetFile, attributes);

fail:
	free(targetFile);
	return success;
}
示例#13
0
KoStore *KoScriptingOdfStore::getReadStore()
{
    QByteArray ba = getByteArray();
    if (ba.isNull()) {
        kWarning(32010)  << "KoScriptingOdfStore::getReadStore() Failed to fetch ByteArray";
        return 0;
    }
    if (m_readStore ) {
        //kDebug(32010) <<"KoScriptingOdfStore::getReadStore() Return cached store";
        Q_ASSERT(m_readDevice);
        return m_readStore;
    }
    //kDebug(32010) <<"KoScriptingOdfStore::getReadStore() Return new store";
    Q_ASSERT(!m_readDevice);
    m_readDevice = new QBuffer(&m_byteArray);
    m_readStore = KoStore::createStore(m_readDevice, KoStore::Read, "KrossScript", KoStore::Tar);
    return m_readStore;
}
static Battery::BatteryHealth getHealthValue(const QString& path)
{
    QByteArray data = getByteArray(path);
    if (data.size()) {
	switch (data.data()[0]) {
	case 'C': return Battery::COLD;
	case 'D': return Battery::DEAD;
	case 'G': return Battery::GOOD;
	case 'O': 
	    if (data == "Overheat")
		return Battery::OVERHEAT;
	    else if (data == "Over voltage")
		return Battery::OVERVOLTAGE;
	    break;
	case 'U':
	    if (data == "Unspecified failure")
		return Battery::FAILURE;
	    break;
	}
    }
    return Battery::HEALTH_UNKNOWN;
}
TransactionHashStatus getTransactionInputHashForVerification(void * txIn,
		ByteArray * prevOutSubScript, uint32_t input, SignatureType signType,
		uint8_t * hash) {
	assert(txIn != NULL);
	assert(prevOutSubScript != NULL);
	assert(input >= 0);
	assert(signType != NULL);
	assert(hash != NULL);

	Transaction * self = txIn;

	if (self->numOfTransactionInput < input + 1) {
		getMessage(self)->onErrorReceived(ERROR_TRANSACTION_FEW_INPUTS,
				"Receiving transaction hash to sign cannot be done for because the input index goes past the number of inputs.");
		return TX_HASH_BAD;
	}

	uint8_t last5Bits = (signType & 0x1f); /* For some reason this is what the C++ client does.*/
	uint32_t sizeOfData = 12 + prevOutSubScript->length; /*Version, lock time and the sign type make up 12 bytes.*/

	if (signType & SIGHASH_ANYONECANPAY) {
		sizeOfData += 41; /* Just this one input. 32 bytes for outPointHash, 4 for outPointIndex, 1 for VarLenInt, 4 for sequence*/
	} else {
		sizeOfData += getSizeOfVarLenInt(self->numOfTransactionInput)
				+ self->numOfTransactionInput * 40; /* All inputs*/
	}

	if (last5Bits == SIGHASH_NONE) {
		sizeOfData++; /* Just for the VarLenInt and no outputs.*/
	} else if ((signType & 0x1f) == SIGHASH_SINGLE) {
		if (self->numOfTransactionOutput < input + 1) {
			getMessage(self)->onErrorReceived(ERROR_TRANSACTION_FEW_OUTPUTS,
					"Receiving transaction hash to sign cannot be done for _SIGHASH_SINGLE because there are not enough outputs.");
			return TX_HASH_BAD;
		}
		sizeOfData += getSizeOfVarLenInt(input + 1) + input * 9; /* For outputs up to the input index*/
		/* The size for the output at the input index.*/
		uint32_t len = getByteArray(self->outputs[input]->scriptObject)->length;
		sizeOfData += 8 + getSizeOfVarLenInt(len) + len;
	} else { /* All outputs. Default to SIGHASH_ALL*/
		sizeOfData += getSizeOfVarLenInt(self->numOfTransactionOutput);
		uint32_t i;
		for (i = 0; i < self->numOfTransactionOutput; i++) {
			uint32_t len = getByteArray(self->outputs[i]->scriptObject)->length;
			sizeOfData += 8 + getSizeOfVarLenInt(len) + len;
		}
	}

	ByteArray * data = createNewByteArrayOfSize(sizeOfData,
			getMessage(self)->onErrorReceived);

	if (!data) {
		return TX_HASH_FAIL;
	}

	writeInt32AsLittleEndianIntoByteArray(data, 0, self->version);

	/* Copy input data. Scripts are not copied for the inputs.*/
	uint32_t cursor;

	if (signType & SIGHASH_ANYONECANPAY) {
		encodeVarLenInt(data, 4, createVarLenIntFromUInt64(1)); /* Only the input the signature is for.*/
		copyByteArrayToByteArray(data, 5, self->inputs[input]->prevOutput.hash);
		writeInt32AsLittleEndianIntoByteArray(data, 37,
				self->inputs[input]->prevOutput.index);
		/*Add prevOutSubScript*/
		copyByteArrayToByteArray(data, 41, prevOutSubScript);
		cursor = 41 + prevOutSubScript->length;
		writeInt32AsLittleEndianIntoByteArray(data, cursor,
				self->inputs[input]->sequence);
		cursor += 4;
	} else {
		VarLenInt inputNum = createVarLenIntFromUInt64(
				self->numOfTransactionInput);
		encodeVarLenInt(data, 4, inputNum);
		cursor = 4 + inputNum.storageSize;
		uint32_t i;
		for (i = 0; i < self->numOfTransactionInput; i++) {
			copyByteArrayToByteArray(data, cursor,
					self->inputs[i]->prevOutput.hash);
			cursor += 32;
			writeInt32AsLittleEndianIntoByteArray(data, cursor,
					self->inputs[i]->prevOutput.index);
			cursor += 4;
			/* Add prevOutSubScript if the input is for the signature.*/
			if (i == input) {
				copyByteArrayToByteArray(data, cursor, prevOutSubScript);
				cursor += prevOutSubScript->length;
			}
			if ((signType == SIGHASH_NONE || signType == SIGHASH_SINGLE)
					&& i != input)
				writeInt32AsLittleEndianIntoByteArray(data, cursor, 0);
			else
				/* SIGHASH_ALL or input index for signing sequence*/
				writeInt32AsLittleEndianIntoByteArray(data, cursor,
						self->inputs[i]->sequence);
			cursor += 4;
		}
	}
	/* Copy output data*/
	if (last5Bits == SIGHASH_NONE) {
		VarLenInt varInt = createVarLenIntFromUInt64(0);
		encodeVarLenInt(data, cursor, varInt);
		cursor++;
	} else if (last5Bits == SIGHASH_SINGLE) {
		VarLenInt varInt = createVarLenIntFromUInt64(input + 1);
		encodeVarLenInt(data, cursor, varInt);
		cursor += varInt.storageSize;

		uint32_t j;
		for (j = 0; j < input; j++) {
			writeInt64AsLittleEndianIntoByteArray(data, cursor,
					0xFFFFFFFFFFFFFFFF); /*_OUTPUT_VALUE_NUS_ONE = 0xFFFFFFFFFFFFFFFF*/
			cursor += 8;
			encodeVarLenInt(data, cursor, createVarLenIntFromUInt64(0));
			cursor++;
		}
		writeInt64AsLittleEndianIntoByteArray(data, cursor,
				self->outputs[input]->value);
		cursor += 8;
		varInt = createVarLenIntFromUInt64(
				getByteArray(self->outputs[input]->scriptObject)->length);
		encodeVarLenInt(data, cursor, varInt);
		cursor += varInt.storageSize;

		copyByteArrayToByteArray(data, cursor,
				getByteArray(self->outputs[input]->scriptObject));
		cursor += varInt.value;
	} else { /* SIGHASH_ALL*/
		VarLenInt varInt = createVarLenIntFromUInt64(
				self->numOfTransactionOutput);
		encodeVarLenInt(data, cursor, varInt);
		cursor += varInt.storageSize;
		uint32_t x;
		for (x = 0; x < self->numOfTransactionOutput; x++) {
			writeInt64AsLittleEndianIntoByteArray(data, cursor,
					self->outputs[x]->value);
			cursor += 8;
			varInt = createVarLenIntFromUInt64(
					getByteArray(self->outputs[x]->scriptObject)->length);
			encodeVarLenInt(data, cursor, varInt);
			cursor += varInt.storageSize;
			copyByteArrayToByteArray(data, cursor,
					getByteArray(self->outputs[x]->scriptObject));
			cursor += varInt.value;
		}
	}
	/* Set lockTime*/
	writeInt32AsLittleEndianIntoByteArray(data, cursor, self->lockTime);
	writeInt32AsLittleEndianIntoByteArray(data, cursor + 4, signType);

	assert(sizeOfData == cursor + 8); /* Must always be like this*/

	uint8_t firstHash[32];
	Sha256(getByteArrayData(data), sizeOfData, firstHash);
	Sha256(firstHash, 32, hash);

	return TX_HASH_GOOD;
}
示例#16
0
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type, const QByteArray& postData)
{
    QString scheme = request.url().scheme();
    if (scheme == QLatin1String("mailto")
        || scheme == QLatin1String("ftp")) {
//        QDesktopServices::openUrl(request.url());
        return false;
    }

    if (IS_CRAWLER) // when crawler, we run the webapplication is the same process
        // make it easier for replay
        return QWebPage::acceptNavigationRequest(frame, request, type, postData);
    
    WebView::OpenType t = WebView::NewWebApp;
    WebView* view = qobject_cast<WebView*>(parent());
    Q_ASSERT(view != 0);

    // little trick to avoid double post
    if (m_posted) {
        m_posted = false;
    } else if (postData.size() > 0) {
        m_posted = true;
    }
    // ctrl open in new tab
    // ctrl-shift open in new tab and select
    // ctrl-alt open in new window
    if (type == QWebPage::NavigationTypeLinkClicked
        && (m_keyboardModifiers & Qt::ControlModifier
            || m_pressedButtons == Qt::MidButton)) {
        bool newWindow = (m_keyboardModifiers & Qt::AltModifier);
        if (newWindow) {
            t = WebView::NewWindow;            
        } else {
            bool selectNewTab = (m_keyboardModifiers & Qt::ShiftModifier);
            if (selectNewTab)
                t = WebView::NewTabSelect;
            else
                t = WebView::NewTabNoSelect;
        }

        // check and load
        view->loadPolicy(request, postData, t);
        
        m_keyboardModifiers = Qt::NoModifier;
        m_pressedButtons = Qt::NoButton;
        return false;
    }
    
    //qDebug() << "navigation request url: " << request.url();
    QUrl::FormattingOptions format = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
    if (frame == mainFrame()) {
        //qDebug() << "mainFrame navigation request to " << request.url();
        m_loadingUrl = request.url();
        
        QUrl current = view->url();
        bool sop = (m_loadingUrl.scheme().toLower() == current.scheme().toLower())
            && (m_loadingUrl.host().toLower() == current.host().toLower())
            && (m_loadingUrl.port() == current.port());
        //QUrl::FormattingOptions format = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
        if (!sop //(view->loaded() || type == QWebPage::NavigationTypeLinkClicked) && !sop
            /*(m_loadingUrl.toString(format) != current.toString(format)) */) {
            t = WebView::NewWebApp;
            
            // check and load
            if (m_posted)
                view->loadPolicy(request, postData, t);
            else
                view->loadPolicy(request, QByteArray(), t);

            return false;
        } else {
            emit loadingUrl(m_loadingUrl);
            
            
            if ((type != NavigationTypeOther) && (type != NavigationTypeReload) && (type != NavigationTypeBackOrForward)
                || (view->m_userAction)) {
                QVariant var(m_loadingUrl.toString());
                OPNET::OpNetwork::instance()->sendUIMsg(MSG_addHistoryItem, getByteArray(var));
                view->m_userAction = false;
            }
            if (type == NavigationTypeBackOrForward) {
                //QVariant var(m_back);
                //OPNET::OpNetwork::instance()->sendUIMsg(MSG_navBackOrForward, getByteArray(var));
                m_back = false;
            }
        }
    }
    else if(frame == 0)
    {
        t = WebView::NewTabNoSelect;

        // check and load
        view->loadPolicy(request, postData, t);

        return false;
    }
    // same-origin and "about:blank" navigation requests fall-through to acceptNavigationRequest
    else if( m_iframeHandled &&
             (request.url().toString(format | QUrl::RemovePath) != view->url().toString(format | QUrl::RemovePath) 
              && request.url().toString() != "about:blank")) {
        //qDebug() << "navigation request for sub-frame \"" << frame->frameName() << "\" to " << request.url() << " type: " << type;
        t = WebView::NewSubFrame;
        OPNET::OpNetwork::instance()->sendSysCall(MSG_EMBED_FRAME, 0, frame->frameName().toAscii());
        view->loadPolicy(request, postData, t);
        return false;
    }

    return QWebPage::acceptNavigationRequest(frame, request, type, postData);
}
static bool getBooleanValue(const QString& path)
{
    QByteArray data = getByteArray(path);
    return (data.size() && data.data()[0] != '0');
}
uint8_t getNetVersionByteForVersionChecksumBytes(VersionChecksumBytes * self){

	return getByteFromByteArray(getByteArray(self), 0);
}