Beispiel #1
0
static SQRESULT sq_mysql_result_col_value(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
	SQObjectType ptype = sq_gettype(v, 2);
	int col = -1;
	if(ptype == OT_STRING){
	    SQ_GET_STRING(v, 2, col_name);
	    col = get_field_idx(self, col_name);
	}
	else
	{
	    SQ_GET_INTEGER(v, 2, idx);
	    col = idx;
	}
	if(col < 0) return sq_throwerror(v, _SC("invalid col index/name"));

    sq_pushstring(v, _curr_row_key, -1);
    if(sq_get(v, 1) == SQ_OK){
        SQ_GET_INTEGER(v, -1, curr_row);
        if(curr_row < dlmysql_num_rows(self)){
        	dlmysql_data_seek(self, curr_row);
        	const MYSQL_ROW res_row = dlmysql_fetch_row(self);
			unsigned long *lengths = dlmysql_fetch_lengths(self);
            sq_pushstring(v, (const SQChar*)res_row[col], lengths[col]);
            return 1;
        }
    }
	return SQ_ERROR;
}
Beispiel #2
0
static SQRESULT sq_fossil_sha3sum(HSQUIRRELVM v) {
	SQ_FUNC_VARS(v);
	SQ_GET_INTEGER(v, 2, iSize);
	switch(iSize)
	{
    case 0:
        iSize = 256;
    case 224:
    case 256:
    case 384:
    case 512:
        break;
    default:
        return sq_throwerror(v, _SC("invalid hash size expected one of [0, 224, 256, 384, 512]"));
	}

    SHA3Context ctx;
    SHA3Init(&ctx, iSize);

    for (int i = 3; i <= _top_; ++i) {
        SQ_GET_STRING(v, i, p);
        SHA3Update(&ctx, (const unsigned char *) p, p_size);
    }

    SQInteger buf_size = iSize/4;
    SQChar *buf = sq_getscratchpad(v, buf_size);
    DigestToBase16(SHA3Final(&ctx), buf, buf_size/2);
    sq_pushstring(v, buf, buf_size);
    return 1;
}
Beispiel #3
0
static SQRESULT sq_axtls_get_error(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    SQ_GET_INTEGER(v, 2, error);
    SQInteger buff_size = 250;
    SQChar *buff = sq_getscratchpad(v, buff_size);
	sq_pushstring(v, ssl_get_error(error, buff, buff_size), -1);
	return 1;
}
Beispiel #4
0
static SQRESULT sq_ssl_get_cert_subject_alt_dnsname(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_INSTANCE();
    SQ_GET_INTEGER(v, 2, dnsindex);
	const char* result = ssl_get_cert_subject_alt_dnsname(self, dnsindex);
	sq_pushstring(v, result, -1);
	return 1;
}
Beispiel #5
0
static SQRESULT sq_ssl_get_cert_dn(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_INSTANCE();
    SQ_GET_INTEGER(v, 2, component);
	const char* result = ssl_get_cert_dn(self, component);
	sq_pushstring(v, result, -1);
	return 1;
}
Beispiel #6
0
static SQRESULT sq_ssl_ctx_find(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_ctx_INSTANCE();
    SQ_GET_INTEGER(v, 2, client_fd);
    SSL *ssl = ssl_find(self, client_fd);
    if(ssl) return ssl_constructor(v, ssl, 0);
    else sq_pushnull(v);
    return 1;
}
Beispiel #7
0
static SQRESULT sq_BitVector_constructor(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	SQ_GET_INTEGER(v, 2, int_size);
//	Bitvec *sqlite3BitvecCreate(u32)
    Bitvec *bv = sqlite3BitvecCreate((u32)int_size);
    SQInteger rc = sq_setinstanceup(v, 1, bv);
    sq_setreleasehook(v,1, BitVector_release_hook);
	return rc;
}
Beispiel #8
0
static SQRESULT sq_BitVector_test_not_null(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_BitVector_INSTANCE();

	SQ_GET_INTEGER(v, 2, int_pos);
	BV_CHECK_RANGE();
//	int sqlite3BitvecTestNotNull(Bitvec*, u32)
    sq_pushinteger(v, sqlite3BitvecTestNotNull(self, (u32)int_pos));
	return 1;
}
Beispiel #9
0
static SQRESULT sq_ssl_ctx_obj_load(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_ctx_INSTANCE();
	SQ_GET_INTEGER(v, 2, obj_type);
	SQ_GET_STRING(v, 3, filename);
	SQ_GET_STRING(v, 4, password);
	int result = ssl_obj_load(self, obj_type, filename, password);
	sq_pushinteger(v, result);
	return 1;
}
Beispiel #10
0
static SQRESULT sq_ssl_ctx_obj_memory_load(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_ctx_INSTANCE();
	SQ_GET_INTEGER(v, 2, obj_type);
	SQ_GET_STRING(v, 3, data);
	SQ_GET_STRING(v, 4, password);
	int result = ssl_obj_memory_load(self, obj_type, (const uint8_t *)data, data_size, password);
	sq_pushinteger(v, result);
	return 1;
}
Beispiel #11
0
static SQRESULT sq_mysql_result_col_name(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
	SQ_GET_INTEGER(v, 2, col);
	if(col < 0 || col > dlmysql_num_fields(self)-1)
		return sq_throwerror(v, _SC("invalid col number (" _PRINT_INT_FMT ")"), col);
	MYSQL_FIELD *fields = dlmysql_fetch_fields(self);
	sq_pushstring(v, fields[col].name, -1);
	return 1;
}
Beispiel #12
0
static SQRESULT sq_mysql_result_eof(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
    sq_pushstring(v, _curr_row_key, -1);
    if(sq_get(v, 1) == SQ_OK){
        SQ_GET_INTEGER(v, -1, curr_row);
        sq_pushbool(v, curr_row < dlmysql_num_rows(self));
    }
	else sq_pushbool(v, SQTrue);
	return 1;
}
Beispiel #13
0
static SQRESULT sq_axtls_get_random0(HSQUIRRELVM v, get_random_fptr_t grf)
{
	SQ_FUNC_VARS_NO_TOP(v);
    SQ_GET_INTEGER(v, 2, length);
    if(length < 1) return sq_throwerror(v, _SC("Minimun length error " _PRINT_INT_FMT), length);
    if(!RNG_is_initialized()) return sq_throwerror(v, _SC("Need to call rng_initialize first"));
    SQChar *buff = sq_getscratchpad(v, length);
    (*grf)(length, buff);
	sq_pushstring(v, buff, length);
    return 1;
}
Beispiel #14
0
static SQRESULT sq_ssl_ctx_server_new(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    GET_ssl_ctx_INSTANCE();
    SQ_GET_INTEGER(v, 2, client_fd);
    SSL *ssl = ssl_server_new(self, client_fd);
    SQRESULT rc = ssl_constructor(v, ssl, 1);
    if(rc == SQ_ERROR && ssl){
        ssl_free(ssl);
    }
    return rc;
}
Beispiel #15
0
static SQRESULT sq_ssl_write(HSQUIRRELVM v){
    SQ_FUNC_VARS(v);
    GET_ssl_INSTANCE();
    SQ_GET_STRING(v, 2, out_data);
	if(_top_ > 2) {
	    SQ_GET_INTEGER(v, 3, size);
	    if(size > out_data_size) return sq_throwerror(v, _SC("parameter 2 size bigger than data size"));
	    out_data_size = size;
	}
	sq_pushinteger(v, ssl_write(self, (const uint8_t *)out_data, out_data_size));
	return 1;
}
Beispiel #16
0
static SQRESULT sq_BitVector_clear(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_BitVector_INSTANCE();

	SQ_GET_INTEGER(v, 2, int_pos);
	BV_CHECK_RANGE();
//	void sqlite3BitvecClear(Bitvec*, u32, void*)
    SQChar *bv_buf = sq_getscratchpad(v, sqlite3BITVEC_SZ());

    sqlite3BitvecClear(self, (u32)int_pos, bv_buf);
	return 0;
}
Beispiel #17
0
static SQRESULT sq_ssl_ctx_client_new(HSQUIRRELVM v){
    SQ_FUNC_VARS(v);
    GET_ssl_ctx_INSTANCE();
    SQ_GET_INTEGER(v, 2, client_fd);
    SQ_OPT_STRING(v, 3, session_id, NULL);
    SQ_OPT_INTEGER(v, 4, size, -1);
	SSL *ssl = ssl_client_new(self, client_fd, (const uint8_t *)session_id,
                           size >= 0 ? size : session_id_size, NULL);
    SQRESULT rc = ssl_constructor(v, ssl, 1);
    if(rc == SQ_ERROR && ssl){
        ssl_free(ssl);
    }
    return rc;
}
Beispiel #18
0
static SQRESULT sq_mysql_result_next_row(HSQUIRRELVM v){
	SQ_FUNC_VARS_NO_TOP(v);
	GET_mysql_result_INSTANCE();
    sq_pushstring(v, _curr_row_key, -1);
    sq_push(v, -1); //make a copy
    if(sq_get(v, 1) == SQ_OK){
        SQ_GET_INTEGER(v, -1, curr_row);
        if(++curr_row < dlmysql_num_rows(self)){
            sq_poptop(v);
            sq_pushinteger(v, curr_row);
            sq_set(v, 1);
            sq_pushbool(v, SQTrue);
            return 1;
        }
    }
	sq_pushbool(v, SQFalse);
	return 1;
}
Beispiel #19
0
/*
** Copies values from State src to State dst.
*/
static SQRESULT copy_values_between_vms (HSQUIRRELVM dst, HSQUIRRELVM src, int argc, int argIdx)
{
    SQRESULT _rc_;
    sq_reservestack(dst, argc + 20);
    argc += argIdx; //we will work with argc args starting at argIdx
    for (; argIdx < argc; argIdx++)
    {
        switch (sq_gettype(src, argIdx))
        {
        case OT_INTEGER:
            SQ_GET_INTEGER(src, argIdx, vint);
            sq_pushinteger(dst, vint);
            break;

        case OT_FLOAT:
            SQ_GET_FLOAT(src, argIdx, vfloat);
            sq_pushfloat (dst, vfloat);
            break;

        case OT_BOOL:
            SQ_GET_BOOL(src, argIdx, vbool);
            sq_pushbool (dst, vbool);
            break;

        case OT_STRING:
        {
            SQ_GET_STRING(src, argIdx, vstr)
            sq_pushstring (dst, vstr, vstr_size);
        }
        break;

        case OT_ARRAY:
        {
            SQInteger size = sq_getsize(src, argIdx);
            sq_newarray(dst, size);
            for(SQInteger i=0; i<size; ++i)
            {
                sq_pushinteger(src, i);
                sq_get(src, -2);
                sq_pushinteger(dst, i);
                if(copy_values_between_vms(dst, src, 1, sq_gettop(src)) != SQ_OK) return SQ_ERROR;
                sq_poptop(src);
                sq_set(dst, -3);
            }
        }
        break;

        case OT_TABLE:
        {
            sq_newtable(dst);
            sq_pushnull(src);
            while(sq_next(src, -2) == SQ_OK)
            {
                SQInteger src_top = sq_gettop(src);
                if(copy_values_between_vms(dst, src, 1, src_top-1) != SQ_OK
                        || copy_values_between_vms(dst, src, 1, src_top) != SQ_OK) return SQ_ERROR;
                sq_newslot(dst, -3, SQFalse);
                sq_pop(src, 2);
            }
            sq_pop(src,1);
        }
        break;

        case OT_USERPOINTER:
        {
            SQUserPointer ptr;
            sq_getuserpointer(src, argIdx, &ptr);
            sq_pushuserpointer(dst, ptr);
        }
        break;

        case OT_NULL:
            sq_pushnull(dst);
            break;

        default:
            return SQ_ERROR;
        }
    }
    return SQ_OK;
}
Beispiel #20
0
static SQRESULT sq_axtls_display_error(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    SQ_GET_INTEGER(v, 2, error);
	ssl_display_error(error);
	return 0;
}
Beispiel #21
0
static SQRESULT sq_mysql_statement_bind_base(HSQUIRRELVM v, SQInteger top, SQ_MysqlStatement *self){

    SQRESULT _rc_;
	if((top - 1) != self->param_count){
		return sq_throwerror(v, "Expect %d params but got %d !", (int)self->param_count, (int)top-1);
	}

    memset(self->bind_data_buffer, 0, self->bind_data_buffer_size);

    int offset = 0;

    for (int argn = 2; argn <= top; ++argn) {
        SQObjectType ptype = sq_gettype(v, argn);
        int i = argn - 2;
        MYSQL_BIND &bind_info = self->bind_params_info[i];

        SQInteger *boolean_or_int;

        switch(ptype) {
            case OT_NULL:{
                bind_info.buffer_type = MYSQL_TYPE_NULL;
                bind_info.is_null = (my_bool*)1;
            }
            break;

            case OT_BOOL:{
                SQ_GET_BOOL(v, argn, param_bool);
                boolean_or_int = (SQInteger *)(((char*)self->bind_params_data) + offset);
                offset += sizeof(SQInteger);
                *boolean_or_int = (SQInteger)param_bool;

                bind_info.buffer_type = MYSQL_TYPE_LONG;
                bind_info.is_null = (my_bool*)0;
                bind_info.buffer = (char *)boolean_or_int;
                bind_info.length = 0;
            }
            break;

            case OT_INTEGER:{
                SQ_GET_INTEGER(v, argn, param_int);
                boolean_or_int = (SQInteger *)(((char*)self->bind_params_data) + offset);
                offset += sizeof(SQInteger);
                *boolean_or_int = param_int;

                bind_info.buffer_type = ((sizeof(SQInteger) == sizeof(int64_t)) ? MYSQL_TYPE_LONGLONG : MYSQL_TYPE_LONG);
                bind_info.is_null = (my_bool*)0;
                bind_info.buffer = (char *)boolean_or_int;
                bind_info.length = 0;
            }
            break;

            case OT_FLOAT:{
                /*
                 * num needs to be it's own
                 * memory here
                         */
                SQFloat *num = (SQFloat *)(((char*)self->bind_params_data) + offset);
                offset += sizeof(SQFloat);
                SQ_GET_FLOAT(v, argn, param_float);
                *num = param_float;

                bind_info.buffer_type = ((sizeof(SQFloat) == sizeof(float)) ? MYSQL_TYPE_FLOAT : MYSQL_TYPE_DOUBLE);
                bind_info.is_null = (my_bool*)0;
                bind_info.buffer = (char *)num;
                bind_info.length = 0;
            }
            break;

            case OT_STRING:{
                SQ_GET_STRING(v, argn, param_string);
                offset += sizeof(char*);

                bind_info.buffer_type = MYSQL_TYPE_STRING;
                bind_info.is_null = (my_bool*)0;
                bind_info.buffer = (char *)param_string;
                bind_info.length_value = param_string_size;
                bind_info.length = &bind_info.length_value;
            }
            break;

            default:{
                return sq_throwerror(v, "Unsupported bind parameter type %d", i);
            }
        }
    }
    return dlmysql_stmt_bind_param(self->stmt, self->bind_params_info);
}
Beispiel #22
0
static SQRESULT sq_axtls_get_config(HSQUIRRELVM v){
    SQ_FUNC_VARS_NO_TOP(v);
    SQ_GET_INTEGER(v, 2, info);
	sq_pushinteger(v, ssl_get_config(info));
	return 1;
}