コード例 #1
0
ファイル: dukascopy.cpp プロジェクト: F3RR3T/dukascopy
tick_data* read(
        const char *filename, pt::ptime epoch, float point_value, size_t *bytes_read) {
    tick_data *result = 0;
    size_t buffer_size = 0;
    unsigned char *buffer = n47::io::loadToBuffer<unsigned char>(filename, &buffer_size);

    if ( buffer != 0 ) {
        if ( n47::lzma::bufferIsLZMA(buffer, buffer_size) ) {
            result = read_bi5(buffer, buffer_size, epoch, point_value, bytes_read);
            // Reading in as bi5 failed lets double check its not binary
            // data in the buffer.
            if (result == 0) {
                result = read_bin(buffer, buffer_size, epoch, point_value);
            }
        } else {
            result = read_bin(buffer, buffer_size, epoch, point_value);
            *bytes_read = buffer_size;
        }
        delete [] buffer;

        if (result != 0 && result->size() != (*bytes_read / n47::ROW_SIZE)) {
            delete result;
            result = 0;
        }
    }
    return result;
}
コード例 #2
0
ファイル: auth.c プロジェクト: cfrodca/tiva-ssh
/**
 * Parse username and password
 */
static int parse_auth(SSH *ssh) {
	byte *p;
	byte *out;
	byte aux;
	word32 outSz;

	p = ssh->sp.data;

	/* Get username */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_UN_LEN)
		return -1;

	memcpy(ssh->user, out, outSz);
	ssh->user[outSz] = 0;

	/* Get service */
	read_bin(&p, &out, &outSz);

	/* Get method */
	read_bin(&p, &out, &outSz);

	/* Only support password based autentication */
	if (memcmp(out, PASSWORD_STR, strlen(PASSWORD_STR)) != 0) {
		return 1;
	}

	/* Read byte */
	read_byte(&p, &aux);

	/* Get password */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_PW_LEN)
		return -1;

	memcpy(ssh->pass, out, outSz);
	ssh->pass[outSz] = 0;

	/* Check username and password */
	if (check_password(ssh->user, ssh->pass) < 0) {
		/* Limit auth attempts */
		if (ssh->authAtt++ > 1) {
			return -1;
		}
		return 1;
	}

	ssh->state = SSH_AUTH;

	return 0;
}
コード例 #3
0
void test_compress(FILE* outFp, FILE* inpFp)
{
    LZ4_stream_t lz4Stream_body;
    LZ4_stream_t* lz4Stream = &lz4Stream_body;

    char inpBuf[2][BLOCK_BYTES];
    int  inpBufIndex = 0;

    LZ4_resetStream(lz4Stream);

    for(;;) {
        char* const inpPtr = inpBuf[inpBufIndex];
        const int inpBytes = (int) read_bin(inpFp, inpPtr, BLOCK_BYTES);
        if(0 == inpBytes) {
            break;
        }

        {
            char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
            const int cmpBytes = LZ4_compress_fast_continue(
                lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf), 1);
            if(cmpBytes <= 0) {
                break;
            }
            write_int(outFp, cmpBytes);
            write_bin(outFp, cmpBuf, (size_t) cmpBytes);
        }

        inpBufIndex = (inpBufIndex + 1) % 2;
    }

    write_int(outFp, 0);
}
コード例 #4
0
void test_compress(file* outfp, file* inpfp)
{
    lz4_streamhc_t lz4stream_body = { 0 };
    lz4_streamhc_t* lz4stream = &lz4stream_body;

    static char inpbuf[ring_buffer_bytes];
    int inpoffset = 0;

    for(;;)
    {
        // read random length ([1,message_max_bytes]) data to the ring buffer.
        char* const inpptr = &inpbuf[inpoffset];
        const int randomlength = (rand() % message_max_bytes) + 1;
        const int inpbytes = (int) read_bin(inpfp, inpptr, randomlength);
        if (0 == inpbytes) break;

        {
            char cmpbuf[lz4_compressbound(message_max_bytes)];
            const int cmpbytes = lz4_compresshc_continue(lz4stream, inpptr, cmpbuf, inpbytes);

            if(cmpbytes <= 0) break;
            write_int32(outfp, cmpbytes);
            write_bin(outfp, cmpbuf, cmpbytes);

            inpoffset += inpbytes;

            // wraparound the ringbuffer offset
            if(inpoffset >= ring_buffer_bytes - message_max_bytes)
                inpoffset = 0;
        }
    }

    write_int32(outfp, 0);
}
コード例 #5
0
ファイル: hex.c プロジェクト: S010/misc
static void
hex(const char *s)
{
	unsigned long long i = 0;

	switch (s[0]) {
	case 'b':
	case 'B':
		i = read_bin(s + 1);
		break;
	case 'x':
	case 'X':
		i = read_hex(s + 1);
		break;
	case '0':
		if (s[1] == '\0')
			i = read_dec(s);
		else if (s[1] == 'x' || s[1] == 'X')
			i = read_hex(s + 2);
		else
			i = read_oct(s + 1);
		break;
	default:
		if (isdigit(*s))
			i = read_dec(s);
		else
			usage();
		break;
	}
	print_bin(i);
	print_chr(i);
	print_dec(i);
	print_hex(i);
	print_oct(i);
}
コード例 #6
0
void test_decompress(FILE* outFp, FILE* inpFp)
{
    static char decBuf[DECODE_RING_BUFFER];
    int   decOffset    = 0;
    LZ4_streamDecode_t lz4StreamDecode_body = { 0 };
    LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;

    for(;;) {
        int cmpBytes = 0;
        char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];

        {
            const size_t r0 = read_int32(inpFp, &cmpBytes);
            if(r0 != 1 || cmpBytes <= 0) break;

            const size_t r1 = read_bin(inpFp, cmpBuf, cmpBytes);
            if(r1 != (size_t) cmpBytes) break;
        }

        {
            char* const decPtr = &decBuf[decOffset];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES);
            if(decBytes <= 0) break;
            decOffset += decBytes;
            write_bin(outFp, decPtr, decBytes);

            // Wraparound the ringbuffer offset
            if(decOffset >= DECODE_RING_BUFFER - MESSAGE_MAX_BYTES) decOffset = 0;
        }
    }
}
コード例 #7
0
void test_compress(FILE* outFp, FILE* inpFp)
{
    LZ4_stream_t lz4Stream_body = { 0 };
    LZ4_stream_t* lz4Stream = &lz4Stream_body;

    static char inpBuf[RING_BUFFER_BYTES];
    int inpOffset = 0;

    for(;;) {
        // Read random length ([1,MESSAGE_MAX_BYTES]) data to the ring buffer.
        char* const inpPtr = &inpBuf[inpOffset];
        const int randomLength = (rand() % MESSAGE_MAX_BYTES) + 1;
        const int inpBytes = (int) read_bin(inpFp, inpPtr, randomLength);
        if (0 == inpBytes) break;

        {
            char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)];
            const int cmpBytes = LZ4_compress_continue(lz4Stream, inpPtr, cmpBuf, inpBytes);
            if(cmpBytes <= 0) break;
            write_int32(outFp, cmpBytes);
            write_bin(outFp, cmpBuf, cmpBytes);

            inpOffset += inpBytes;

            // Wraparound the ringbuffer offset
            if(inpOffset >= RING_BUFFER_BYTES - MESSAGE_MAX_BYTES) inpOffset = 0;
        }
    }

    write_int32(outFp, 0);
}
コード例 #8
0
int compare(FILE* fp0, FILE* fp1)
{
    int result = 0;

    while(0 == result) {
        char b0[65536];
        char b1[65536];
        const size_t r0 = read_bin(fp0, b0, sizeof(b0));
        const size_t r1 = read_bin(fp1, b1, sizeof(b1));

        result = (int) r0 - (int) r1;

        if(0 == r0 || 0 == r1) {
            break;
        }
        if(0 == result) {
            result = memcmp(b0, b1, r0);
        }
    }

    return result;
}
コード例 #9
0
ファイル: decoder.c プロジェクト: KirinDave/erlectricity
VALUE read_any_raw(unsigned char **pData) {
  switch(peek_1(pData)) {
    case ERL_SMALL_INT:
      return read_small_int(pData);
      break;
    case ERL_INT:
      return read_int(pData);
      break;
    case ERL_FLOAT:
      return read_float(pData);
      break;
    case ERL_ATOM:
      return read_atom(pData);
      break;
    case ERL_PID:
      return read_pid(pData);
      break;
    case ERL_SMALL_TUPLE:
      return read_small_tuple(pData);
      break;
    case ERL_LARGE_TUPLE:
      return read_large_tuple(pData);
      break;
    case ERL_NIL:
      return read_nil(pData);
      break;
    case ERL_STRING:
      return read_string(pData);
      break;
    case ERL_LIST:
      return read_list(pData);
      break;
    case ERL_BIN:
      return read_bin(pData);
      break;
    case ERL_SMALL_BIGNUM:
      return read_small_bignum(pData);
      break;
    case ERL_LARGE_BIGNUM:
      return read_large_bignum(pData);
      break;
    case ERL_NEW_REF:
      return read_new_reference(pData);
      break;
  }
  return Qnil;
}
コード例 #10
0
static void test_compress(
    FILE* outFp,
    FILE* inpFp,
    size_t messageMaxBytes,
    size_t ringBufferBytes)
{
    LZ4_stream_t* const lz4Stream = LZ4_createStream();
    const size_t cmpBufBytes = LZ4_COMPRESSBOUND(messageMaxBytes);
    char* const cmpBuf = (char*) malloc(cmpBufBytes);
    char* const inpBuf = (char*) malloc(ringBufferBytes);
    int inpOffset = 0;

    for ( ; ; )
    {
        char* const inpPtr = &inpBuf[inpOffset];

#if 0
        // Read random length data to the ring buffer.
        const int randomLength = (rand() % messageMaxBytes) + 1;
        const int inpBytes = (int) read_bin(inpFp, inpPtr, randomLength);
        if (0 == inpBytes) break;
#else
        // Read line to the ring buffer.
        int inpBytes = 0;
        if (!fgets(inpPtr, (int) messageMaxBytes, inpFp))
            break;
        inpBytes = (int) strlen(inpPtr);
#endif

        {
            const int cmpBytes = LZ4_compress_fast_continue(
                lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes, 1);
            if (cmpBytes <= 0) break;
            write_uint16(outFp, (uint16_t) cmpBytes);
            write_bin(outFp, cmpBuf, cmpBytes);

            // Add and wraparound the ringbuffer offset
            inpOffset += inpBytes;
            if ((size_t)inpOffset >= ringBufferBytes - messageMaxBytes) inpOffset = 0;
        }
    }
    write_uint16(outFp, 0);

    free(inpBuf);
    free(cmpBuf);
    LZ4_freeStream(lz4Stream);
}
コード例 #11
0
ファイル: factorytest.c プロジェクト: sky8336/mn201307
static void test_result_init(void)
{
	int i = 0;
	int value = -1;
      char property[32] = {0};

	  //ui init
	ui_init();
	ui_set_background(BACKGROUND_ICON_NONE);
	read_bin();

	property_get("persist.modem.l.enable", property, "not_find");
	if(!strcmp(property, "1")){
            mode_type = 1;
	}
      LOGD("persist.modem.l.enable = %s,mode_type:%d", property,mode_type);
}
コード例 #12
0
ファイル: dukascopy.cpp プロジェクト: F3RR3T/dukascopy
tick_data* read_bi5(
        unsigned char *lzma_buffer, size_t lzma_buffer_size, pt::ptime epoch,
        float point_value, size_t *bytes_read) {
    tick_data *result = 0;

    // decompress
    int status;
    unsigned char *buffer = n47::lzma::decompress(lzma_buffer,
            lzma_buffer_size, &status, bytes_read);

    if (status != N47_E_OK) {
        bytes_read = 0;
    } else {
        // convert to tick data (with read_bin).
        result = read_bin(buffer, *bytes_read, epoch, point_value);
        delete [] buffer;
    }

    return result;
}
コード例 #13
0
ファイル: decode.c プロジェクト: kenpratt/bert
VALUE read_any_raw(unsigned char **pData, VALUE forceToEncoding) {
  switch(peek_1(pData)) {
    case ERL_SMALL_INT:
      return read_small_int(pData);
      break;
    case ERL_INT:
      return read_int(pData);
      break;
    case ERL_FLOAT:
      return read_float(pData);
      break;
    case ERL_ATOM:
      return read_atom(pData);
      break;
    case ERL_SMALL_TUPLE:
      return read_small_tuple(pData, forceToEncoding);
      break;
    case ERL_LARGE_TUPLE:
      return read_large_tuple(pData, forceToEncoding);
      break;
    case ERL_NIL:
      return read_nil(pData);
      break;
    case ERL_STRING:
      return read_string(pData, forceToEncoding);
      break;
    case ERL_LIST:
      return read_list(pData, forceToEncoding);
      break;
    case ERL_BIN:
      return read_bin(pData, forceToEncoding);
      break;
    case ERL_SMALL_BIGNUM:
      return read_small_bignum(pData);
      break;
    case ERL_LARGE_BIGNUM:
      return read_large_bignum(pData);
      break;
  }
  return Qnil;
}
コード例 #14
0
void test_decompress(FILE* outFp, FILE* inpFp)
{
    LZ4_streamDecode_t lz4StreamDecode_body;
    LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;

    char decBuf[2][BLOCK_BYTES];
    int  decBufIndex = 0;

    LZ4_setStreamDecode(lz4StreamDecode, NULL, 0);

    for(;;) {
        char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
        int  cmpBytes = 0;

        {
            const size_t readCount0 = read_int(inpFp, &cmpBytes);
            if(readCount0 != 1 || cmpBytes <= 0) {
                break;
            }

            const size_t readCount1 = read_bin(inpFp, cmpBuf, (size_t) cmpBytes);
            if(readCount1 != (size_t) cmpBytes) {
                break;
            }
        }

        {
            char* const decPtr = decBuf[decBufIndex];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, BLOCK_BYTES);
            if(decBytes <= 0) {
                break;
            }
            write_bin(outFp, decPtr, (size_t) decBytes);
        }

        decBufIndex = (decBufIndex + 1) % 2;
    }
}
コード例 #15
0
void test_decompress(file* outfp, file* inpfp)
{
    static char decbuf[dec_buffer_bytes];
    int decoffset = 0;
    lz4_streamdecode_t lz4streamdecode_body = { 0 };
    lz4_streamdecode_t* lz4streamdecode = &lz4streamdecode_body;

    for(;;)
    {
        int  cmpbytes = 0;
        char cmpbuf[lz4_compressbound(message_max_bytes)];

        {
            const size_t r0 = read_int32(inpfp, &cmpbytes);
            size_t r1;
            if(r0 != 1 || cmpbytes <= 0)
                break;

            r1 = read_bin(inpfp, cmpbuf, cmpbytes);
            if(r1 != (size_t) cmpbytes)
                break;
        }

        {
            char* const decptr = &decbuf[decoffset];
            const int decbytes = lz4_decompress_safe_continue(
                lz4streamdecode, cmpbuf, decptr, cmpbytes, message_max_bytes);
            if(decbytes <= 0)
                break;

            decoffset += decbytes;
            write_bin(outfp, decptr, decbytes);

            // wraparound the ringbuffer offset
            if(decoffset >= dec_buffer_bytes - message_max_bytes)
                decoffset = 0;
        }
    }
}
コード例 #16
0
static void test_decompress(
    FILE* outFp,
    FILE* inpFp,
    size_t messageMaxBytes,
    size_t ringBufferBytes)
{
    LZ4_streamDecode_t* const lz4StreamDecode = LZ4_createStreamDecode();
    char* const cmpBuf = (char*) malloc(LZ4_COMPRESSBOUND(messageMaxBytes));
    char* const decBuf = (char*) malloc(ringBufferBytes);
    int decOffset = 0;

    for ( ; ; )
    {
        uint16_t cmpBytes = 0;

        if (read_uint16(inpFp, &cmpBytes) != 1) break;
        if (cmpBytes <= 0) break;
        if (read_bin(inpFp, cmpBuf, cmpBytes) != cmpBytes) break;

        {
            char* const decPtr = &decBuf[decOffset];
            const int decBytes = LZ4_decompress_safe_continue(
                lz4StreamDecode, cmpBuf, decPtr, cmpBytes, (int) messageMaxBytes);
            if (decBytes <= 0) break;
            write_bin(outFp, decPtr, decBytes);

            // Add and wraparound the ringbuffer offset
            decOffset += decBytes;
            if ((size_t)decOffset >= ringBufferBytes - messageMaxBytes) decOffset = 0;
        }
    }

    free(decBuf);
    free(cmpBuf);
    LZ4_freeStreamDecode(lz4StreamDecode);
}