int checkXor(char *buf){
		int i;
		for(i = 0; i< PAYLOADSIZE; i++){
			if(buf[4+i] != xor_buffer[i]){ return 0;}
		}

		/* Xor verified */ 
		writeBufferToFile();
		return 1;
		
}
Esempio n. 2
0
int main(void)
{
    Clear_home();

    initBuffer();

    rBuf = readBuffer;
    wBuf = writeBuffer;

    (void) Cconws("STiNG test...\r\n");

    BYTE found = Supexec (find_STiNG);
    if(!found) {
        sleep(3);
        return 0;
    }

    getServerIp();
	WORD whichTests = 0;
	while(whichTests == 0) {
		showMenu();
		char req = Cnecin();
		if(req >= 'A' && req <= 'Z') req += 32;	// to upper case
		if(req == 'q') break;	// quit
		switch(req) {
		case 'a':	// all tests
			whichTests = 0xffff;
			break;
		case 's':
			whichTests = 0x8000;
			break;
		case '0':
		case '1':
		case '2':
		case '3':
			whichTests = 1 << (req - '0');
		}
	}

    if(whichTests & 1) doTest00();
    if(whichTests & 2) doTest01();
    if(whichTests & 4) doTest02();
    if(whichTests & 8) doTest03();
    if(whichTests & 0x8000) doSpeedTest();

    if(whichTests != 0) writeBufferToFile();
    deinitBuffer();
    
    sleep(3);
    return 0;
}
Esempio n. 3
0
/**
* @brief	Writes the given kernel rules to the rules table attribute file.
*
* @param	kernelRules - a string holding the kernel rules that will be written to the attribute file.
*
* @return	TRUE for success, FALSE for failure.
*/
Bool writeKernelRulesToTableAttrFile(const char * kernelRules, ssize_t kernelRulesBufferSize)
{
	return writeBufferToFile(kernelRules, kernelRulesBufferSize, RULES_TABLE_ATTR_PATH);
}
Esempio n. 4
0
// find image in buffer
int CameraMJPG::cut_image(char* buffer, int length)
{
	if(!buffer || length<=0)
		return 1;

	// find MIME header
	if( find_data_in_buffer(buffer, length, 
		CAMERA_MJPG_MIME_CONTENT_TYPE_JPEG, CAMERA_MJPG_MIME_CONTENT_TYPE_JPEG_SIZE) != 0 )
	{ 

		//printf("[i][CameraMJPG][cut_image] Image header!\n");

		// get message with image size
		const char* pdest1 = find_data_in_buffer(buffer, length, 
			CAMERA_MJPG_MIME_CONTENT_LENGTH, CAMERA_MJPG_MIME_CONTENT_LENGTH_SIZE); 

		pdest1 += CAMERA_MJPG_MIME_CONTENT_LENGTH_SIZE;

		const char* pdest2 = strstr(pdest1, "\r\n\r\n");
		int str_len = pdest2 - pdest1;

		if (str_len > 128){
			printf("[!][CameraMJPG][cut_image] Error: image size error!\n");
			str_len = 128;
		}

		char str_size[128];
		memcpy(str_size, pdest1, str_len);
		str_size[str_len] = 0;

		int size = atoi(str_size);
		//	printf("[i][CameraMJPG][cut_image] image size: %d \n", size);

		if(size > buf_video.real_size)
			printf("[!][CameraMJPG][cut_image] Warning: too big image: %d !\n", size);

		// get data length
		int recv_len = length - (pdest2 - buffer + 4);

		// pointer to image data
		const char* pimage = pdest2 + 4;

		// not all image in buffer
		if (recv_len < size){
			return 2;
		}

		//
		// got image!
		//

		image_counter++;

#if CAMERA_MJPG_SAVE_JPEG_IMAGE
		//
		// save JPEG into file
		//
		char file[128];
		snprintf(file, 128, "image%02d.jpg", imageCounter);
		writeBufferToFile(file, pimage, size);
#endif //#if VIDEOSERVER_SAVE_JPEG_IMAGE

		remove_frame();

#if defined(USE_OPENCV)
		//
		// unpack JPEG-image
		//
		frame = decompress_image(pimage, size);
#else
		frame = new char[size];
		if(frame){
			memcpy(frame, pimage, size);
			frame_size = size;	
		}
		else{
			printf("[!][cut_image][cut_image] Error: cant allocate memory!\n");
		}
#endif // #if defined(USE_OPENCV)

#if 0
		// reset buffer
		buf_video.zero();
#else
		int i, j;
		for(j=0, i=(pimage-buffer)+size; i<length; i++, j++){
			buf_video.data[j] = buf_video.data[i];
		}
		buf_video.size = j;
#endif

		return 0;
	}

	return 3;
}