⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsbc.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 3 页
字号:
            goto error;    }    /* Functions. */    for (ui = 0; ui < bc->num_functions; ui++) {        if (!ws_encode_buffer(&buffer,                              WS_ENC_UINT8, bc->functions[ui].num_arguments,                              WS_ENC_UINT8, bc->functions[ui].num_locals,                              WS_ENC_MB_UINT32, bc->functions[ui].code_size,                              WS_ENC_DATA, bc->functions[ui].code,                              (size_t) bc->functions[ui].code_size,                              WS_ENC_END))            goto error;    }    /* Fix the byte-code header. */    p = ws_buffer_ptr(&buffer);    /* Encode the size of the byte-code excluding the byte-code header. */    mb = ws_encode_mb_uint32(ws_buffer_len(&buffer) - WS_BC_MAX_HEADER_LEN,                             data, &len);    memcpy(p + WS_BC_MAX_HEADER_LEN - len, mb, len);    /* Set the byte-code file version information. */    WS_PUT_UINT8(p + WS_BC_MAX_HEADER_LEN - len - 1, WS_BC_VERSION);    /* Calculate the beginning of the bc-array and its size. */    *data_return = p + WS_BC_MAX_HEADER_LEN - len - 1;    *data_len_return = ws_buffer_len(&buffer) - WS_BC_MAX_HEADER_LEN + len + 1;    /* All done. */    return WS_TRUE;    /*     * Error handling.     */error:    ws_buffer_uninit(&buffer);    *data_return = NULL;    *data_len_return = 0;    return WS_FALSE;}void ws_bc_data_free(unsigned char *data){    size_t len = WS_MB_UINT32_MAX_ENCODED_LEN;    if (data == NULL)        return;    /* Decode the mb-encoded length so we know how much space it uses. */    (void) ws_decode_mb_uint32(data + 1, &len);    /* Now we can compute the beginning of the array `data'. */    ws_free(data - (WS_MB_UINT32_MAX_ENCODED_LEN - len));}/* A helper macro to update the data pointers during the decoding of   byte-code data. */#define WS_UPDATE_DATA	\    data += decoded;	\    data_len -= decoded/* A helper macro to check the validity of the constant string index   `idx'. */#define WS_CHECK_STRING(idx)				\    if ((idx) >= bc->num_constants			\        || ((bc->constants[(idx)].type			\             != WS_BC_CONST_TYPE_UTF8_STRING)		\            && (bc->constants[(idx)].type		\                != WS_BC_CONST_TYPE_EMPTY_STRING)))	\        goto error;WsBc *ws_bc_decode(const unsigned char *data, size_t data_len){    WsBc *bc = ws_bc_alloc(WS_BC_STRING_ENC_ISO_8859_1);    WsByte b;    WsUInt32 ui32;    WsUInt16 ui16, j;    WsUInt16 ui16b;    WsUInt8 ui8, num_functions, k, l;    WsInt8 i8;    WsInt16 i16;    WsInt32 i32;    WsIeee754Result ieee754;    unsigned char *ucp;    size_t decoded;    /* Decode the byte-code header. */    decoded = ws_decode_buffer(data, data_len,                               WS_ENC_BYTE, &b,                               WS_ENC_MB_UINT32, &ui32,                               WS_ENC_END);    if (!decoded        || b != WS_BC_VERSION        || ui32 != data_len - decoded)        /* This is not a valid (or supported) byte-code header. */        goto error;    WS_UPDATE_DATA;    /* Constant pool. */    decoded = ws_decode_buffer(data, data_len,                               WS_ENC_MB_UINT16, &ui16,                               WS_ENC_MB_UINT16, &ui16b,                               WS_ENC_END);    if (!decoded)        goto error;    bc->string_encoding = ui16b;    bc->constants = ws_calloc(ui16, sizeof(WsBcConstant));    if (bc->constants == NULL)        goto error;    bc->num_constants = ui16;    WS_UPDATE_DATA;    for (j = 0; j < bc->num_constants; j++) {        WsBcConstant *c = &bc->constants[j];        decoded = ws_decode_buffer(data, data_len,                                   WS_ENC_UINT8, &ui8,                                   WS_ENC_END);        if (decoded != 1)            goto error;        WS_UPDATE_DATA;        switch (ui8) {        case WS_BC_CONST_INT8:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_INT8, &i8,                                       WS_ENC_END);            if (decoded != 1)                goto error;            WS_UPDATE_DATA;            c->type = WS_BC_CONST_TYPE_INT;            c->u.v_int = i8;            break;        case WS_BC_CONST_INT16:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_INT16, &i16,                                       WS_ENC_END);            if (decoded != 2)                goto error;            WS_UPDATE_DATA;            c->type = WS_BC_CONST_TYPE_INT;            c->u.v_int = i16;            break;        case WS_BC_CONST_INT32:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_INT32, &i32,                                       WS_ENC_END);            if (decoded != 4)                goto error;            WS_UPDATE_DATA;            c->type = WS_BC_CONST_TYPE_INT;            c->u.v_int = i32;            break;        case WS_BC_CONST_FLOAT32:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_DATA, &ucp, (size_t) 4,                                       WS_ENC_END);            if (decoded != 4)                goto error;            WS_UPDATE_DATA;            ieee754 = ws_ieee754_decode_single(ucp, &c->u.v_float);            switch (ieee754) {            case WS_IEEE754_OK:                c->type = WS_BC_CONST_TYPE_FLOAT32;                break;            case WS_IEEE754_NAN:                c->type = WS_BC_CONST_TYPE_FLOAT32_NAN;                break;            case WS_IEEE754_POSITIVE_INF:                c->type = WS_BC_CONST_TYPE_FLOAT32_POSITIVE_INF;                break;            case WS_IEEE754_NEGATIVE_INF:                c->type = WS_BC_CONST_TYPE_FLOAT32_NEGATIVE_INF;                break;            }            break;        case WS_BC_CONST_UTF8_STRING:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_MB_UINT32, &ui32,                                       WS_ENC_END);            if (decoded == 0)                goto error;            WS_UPDATE_DATA;            c->type = WS_BC_CONST_TYPE_UTF8_STRING;            c->u.v_string.len = ui32;            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_DATA, &ucp, c->u.v_string.len,                                       WS_ENC_END);            if (decoded != ui32)                goto error;            WS_UPDATE_DATA;            c->u.v_string.data = ws_memdup(ucp, ui32);            if (c->u.v_string.data == NULL)                goto error;            /* Check the validity of the data. */            if (!ws_utf8_verify(c->u.v_string.data, c->u.v_string.len,                                &c->u.v_string.num_chars))                goto error;            break;        case WS_BC_CONST_EMPTY_STRING:            c->type = WS_BC_CONST_TYPE_EMPTY_STRING;            break;        case WS_BC_CONST_EXT_ENC_STRING:            ws_fatal("external character encoding not implemented yet");            break;        default:            /* Reserved. */            goto error;            break;        }    }    /* Pragma pool. */    decoded = ws_decode_buffer(data, data_len,                               WS_ENC_MB_UINT16, &ui16,                               WS_ENC_END);    if (!decoded)        goto error;    bc->pragmas = ws_calloc(ui16, sizeof(WsBcPragma));    if (bc->pragmas == NULL)        goto error;    bc->num_pragmas = ui16;    WS_UPDATE_DATA;    for (j = 0; j < bc->num_pragmas; j++) {        WsBcPragma *p = &bc->pragmas[j];        decoded = ws_decode_buffer(data, data_len,                                   WS_ENC_UINT8, &ui8,                                   WS_ENC_END);        if (decoded != 1)            goto error;        WS_UPDATE_DATA;        p->type = ui8;        switch (ui8) {        case WS_BC_PRAGMA_ACCESS_DOMAIN:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_MB_UINT16, &p->index_1,                                       WS_ENC_END);            if (!decoded)                goto error;            WS_CHECK_STRING(p->index_1);            break;        case WS_BC_PRAGMA_ACCESS_PATH:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_MB_UINT16, &p->index_1,                                       WS_ENC_END);            if (!decoded)                goto error;            WS_CHECK_STRING(p->index_1);            break;        case WS_BC_PRAGMA_USER_AGENT_PROPERTY:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_MB_UINT16, &p->index_1,                                       WS_ENC_MB_UINT16, &p->index_2,                                       WS_ENC_END);            if (!decoded)                goto error;            WS_CHECK_STRING(p->index_1);            WS_CHECK_STRING(p->index_2);            break;        case WS_BC_PRAGMA_USER_AGENT_PROPERTY_AND_SCHEME:            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_MB_UINT16, &p->index_1,                                       WS_ENC_MB_UINT16, &p->index_2,                                       WS_ENC_MB_UINT16, &p->index_3,                                       WS_ENC_END);            if (!decoded)                goto error;            WS_CHECK_STRING(p->index_1);            WS_CHECK_STRING(p->index_2);            WS_CHECK_STRING(p->index_3);            break;        default:            goto error;            break;        }        WS_UPDATE_DATA;    }    /* Function pool. */    decoded = ws_decode_buffer(data, data_len,                               WS_ENC_UINT8, &num_functions,                               WS_ENC_END);    if (decoded != 1)        goto error;    WS_UPDATE_DATA;    /* Function names. */    decoded = ws_decode_buffer(data, data_len,                               WS_ENC_UINT8, &ui8,                               WS_ENC_END);    if (decoded != 1)        goto error;    WS_UPDATE_DATA;    if (ui8) {        /* We have function names. */        bc->function_names = ws_calloc(ui8, sizeof(WsBcFunctionName));        if (bc->function_names == NULL)            goto error;        bc->num_function_names = ui8;        for (k = 0; k < bc->num_function_names; k++) {            WsBcFunctionName *n = &bc->function_names[k];            decoded = ws_decode_buffer(data, data_len,                                       WS_ENC_UINT8, &n->index,                                       WS_ENC_UINT8, &ui8,                                       WS_ENC_END);            if (decoded != 2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -