Esempio n. 1
0
tb_int_t tb_demo_network_spider_main(tb_int_t argc, tb_char_t** argv)
{
#ifdef TB_CONFIG_MODULE_HAVE_OBJECT
    tb_used(g_options);
#endif
    return 0;
}
Esempio n. 2
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_iphlpapi_ref_t tb_iphlpapi()
{
    // init
    static tb_atomic_t      s_binited = 0;
    static tb_iphlpapi_t    s_iphlpapi = {0};

    // init the static instance
    tb_bool_t ok = tb_singleton_static_init(&s_binited, &s_iphlpapi, tb_iphlpapi_instance_init, tb_null);
    tb_assert(ok); tb_used(ok);

    // ok
    return &s_iphlpapi;
}
Esempio n. 3
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_kernel32_ref_t tb_kernel32()
{
    // init
    static tb_atomic_t      s_binited = 0;
    static tb_kernel32_t    s_kernel32 = {0};

    // init the static instance
    tb_bool_t ok = tb_singleton_static_init(&s_binited, &s_kernel32, tb_kernel32_instance_init, tb_null);
    tb_assert(ok); tb_used(ok);

    // ok
    return &s_kernel32;
}
Esempio n. 4
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_ws2_32_t* tb_ws2_32()
{
    // init
    static tb_atomic_t      s_binited = 0;
    static tb_ws2_32_t      s_ws2_32 = {0};

    // init the static instance
    tb_bool_t ok = tb_singleton_static_init(&s_binited, &s_ws2_32, tb_ws2_32_instance_init);
    tb_assert(ok); tb_used(ok);

    // ok
    return &s_ws2_32;
}
Esempio n. 5
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_mswsock_ref_t tb_mswsock()
{
    // init
    static tb_atomic_t      s_binited = 0;
    static tb_mswsock_t     s_mswsock = {0};

    // init the static instance
    tb_bool_t ok = tb_singleton_static_init(&s_binited, &s_mswsock, tb_mswsock_instance_init);
    tb_assert(ok);
    tb_used(ok);

    // ok
    return &s_mswsock;
}
Esempio n. 6
0
static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build)
{
    // the version oly for link the static vtag string
    tb_version_t const* version = tb_version(); tb_used(version);

    // ok
    if ((build / 100) == (XM_VERSION_BUILD / 100))
    {
        tb_trace_d("version: %s", XM_VERSION_STRING);
        return tb_true;
    }
    else
    {
        tb_trace_w("version: %s != %llu", XM_VERSION_STRING, build);
    }

    // no
    return tb_false;
}
Esempio n. 7
0
static tb_size_t tb_vector_iterator_prev_test()
{
    // init
    tb_vector_ref_t vector = tb_vector_init(TB_VECTOR_GROW_SIZE, tb_element_long());
    tb_assert_and_check_return_val(vector, 0);

    tb_size_t n = 10000;
    tb_vector_ninsert_head(vector, (tb_pointer_t)0xf, n);
    tb_hong_t t = tb_mclock();
    tb_rfor_all (tb_char_t*, item, vector) tb_used(item);
    t = tb_mclock() - t;

    // time
    tb_trace_i("tb_vector_iterator_prev(%lu): %lld ms, size: %lu, maxn: %lu", n, t, tb_vector_size(vector), tb_vector_maxn(vector));

    // exit
    tb_vector_exit(vector);

    return n / ((tb_uint32_t)(t) + 1);
}
Esempio n. 8
0
File: tbox.c Progetto: waruqi/tbox
static __tb_inline__ tb_bool_t tb_version_check(tb_hize_t build)
{
#ifdef TB_CONFIG_INFO_HAVE_VERSION
    // the version oly for link the static vtag string
    tb_version_t const* version = tb_version(); tb_used(version);
#endif

    // ok
    if ((build / 100) == (TB_VERSION_BUILD / 100))
    {
        tb_trace_d("version: %s", TB_VERSION_STRING);
        return tb_true;
    }
    else
    {
        tb_trace_w("version: %s != %llu", TB_VERSION_STRING, build);
    }

    // no
    return tb_false;
}
Esempio n. 9
0
static tb_void_t tb_circle_queue_iterator_next_test()
{
    // init
    tb_size_t n = 1000000;
    tb_circle_queue_ref_t queue = tb_circle_queue_init(n, tb_element_long());
    tb_assert_and_check_return(queue);

    // make queue
    while (n--) tb_circle_queue_put(queue, (tb_pointer_t)0xf);

    // done
    tb_hong_t t = tb_mclock();
    tb_for_all (tb_char_t*, item, queue) tb_used(item);
    t = tb_mclock() - t;

    // trace
    tb_trace_i("tb_circle_queue_iterator_next(%lu): %lld ms, size: %lu, maxn: %lu", 1000000, t, tb_circle_queue_size(queue), tb_circle_queue_maxn(queue));

    // exit
    tb_circle_queue_exit(queue);
}
Esempio n. 10
0
static tb_size_t tb_stack_iterator_prev_test()
{
    // init
    tb_size_t n = 1000000;
    tb_stack_ref_t stack = tb_stack_init(n, tb_element_long());
    tb_assert_and_check_return_val(stack, 0);

    tb_size_t i;
    for (i = 0; i < n; i++) tb_stack_put(stack, (tb_pointer_t)0xf);
    tb_hong_t t = tb_mclock();
    tb_rfor_all (tb_char_t*, item, stack) tb_used(item);
    t = tb_mclock() - t;

    // time
    tb_trace_i("tb_stack_iterator_prev(%lu): %lld ms, size: %lu, maxn: %lu", 1000000, t, tb_stack_size(stack), tb_stack_maxn(stack));

    // exit
    tb_stack_exit(stack);

    return n / ((tb_uint32_t)(t) + 1);
}
Esempio n. 11
0
File: tbox.c Progetto: waruqi/tbox
tb_version_t const* tb_version()
{
    // init version tag for binary search
    static __tb_volatile__ tb_char_t const* s_vtag = "[tbox]: [vtag]: " TB_VERSION_STRING; tb_used(s_vtag);

    // init version
    static tb_version_t s_version = {0};
    if (!s_version.major)
    {
        s_version.major = TB_VERSION_MAJOR;
        s_version.minor = TB_VERSION_MINOR;
        s_version.alter = TB_VERSION_ALTER;
        s_version.build = (tb_hize_t)tb_atoll(TB_VERSION_BUILD_STRING);
    }

    return &s_version;
}
Esempio n. 12
0
File: looker.c Progetto: waruqi/tbox
static tb_bool_t tb_dns_looker_resp_done(tb_dns_looker_t* looker, tb_ipaddr_ref_t addr)
{
    // the rpkt and size
    tb_byte_t const*    rpkt = tb_static_buffer_data(&looker->rpkt);
    tb_size_t           size = tb_static_buffer_size(&looker->rpkt);
    tb_assert_and_check_return_val(rpkt && size >= TB_DNS_HEADER_SIZE, tb_false);

    // init stream
    tb_static_stream_t stream;
    tb_static_stream_init(&stream, (tb_byte_t*)rpkt, size);

    // init header
    tb_dns_header_t header;
    header.id           = tb_static_stream_read_u16_be(&stream); tb_static_stream_skip(&stream, 2);
    header.question     = tb_static_stream_read_u16_be(&stream);
    header.answer       = tb_static_stream_read_u16_be(&stream);
    header.authority    = tb_static_stream_read_u16_be(&stream);
    header.resource     = tb_static_stream_read_u16_be(&stream);

    // trace
    tb_trace_d("response: size: %u",        size);
    tb_trace_d("response: id: 0x%04x",      header.id);
    tb_trace_d("response: question: %d",    header.question);
    tb_trace_d("response: answer: %d",      header.answer);
    tb_trace_d("response: authority: %d",   header.authority);
    tb_trace_d("response: resource: %d",    header.resource);
    tb_trace_d("");

    // check header
    tb_assert_and_check_return_val(header.id == TB_DNS_HEADER_MAGIC, tb_false);

    // skip questions, only one question now.
    // name + question1 + question2 + ...
    tb_assert_and_check_return_val(header.question == 1, tb_false);
#if 1
    tb_static_stream_skip_cstr(&stream);
    tb_static_stream_skip(&stream, 4);
#else
    tb_char_t* name = tb_static_stream_read_cstr(&stream);
    //name = tb_dns_decode_name(name);
    tb_assert_and_check_return_val(name, tb_false);
    tb_static_stream_skip(&stream, 4);
    tb_trace_d("response: name: %s", name);
#endif

    // decode answers
    tb_size_t i = 0;
    tb_size_t found = 0;
    for (i = 0; i < header.answer; i++)
    {
        // decode answer
        tb_dns_answer_t answer;
        tb_trace_d("response: answer: %d", i);

        // decode dns name
        tb_char_t const* name = tb_dns_decode_name(&stream, answer.name); tb_used(name);
        tb_trace_d("response: name: %s", name);

        // decode resource
        answer.res.type     = tb_static_stream_read_u16_be(&stream);
        answer.res.class_   = tb_static_stream_read_u16_be(&stream);
        answer.res.ttl      = tb_static_stream_read_u32_be(&stream);
        answer.res.size     = tb_static_stream_read_u16_be(&stream);
        tb_trace_d("response: type: %d",    answer.res.type);
        tb_trace_d("response: class: %d",   answer.res.class_);
        tb_trace_d("response: ttl: %d",     answer.res.ttl);
        tb_trace_d("response: size: %d",    answer.res.size);

        // is ipv4?
        if (answer.res.type == 1)
        {
            // get ipv4
            tb_byte_t b1 = tb_static_stream_read_u8(&stream);
            tb_byte_t b2 = tb_static_stream_read_u8(&stream);
            tb_byte_t b3 = tb_static_stream_read_u8(&stream);
            tb_byte_t b4 = tb_static_stream_read_u8(&stream);

            // trace
            tb_trace_d("response: ipv4: %u.%u.%u.%u", b1, b2, b3, b4);

            // save the first ip
            if (!found) 
            {
                // save it
                if (addr)
                {
                    // init ipv4
                    tb_ipv4_t ipv4;
                    ipv4.u8[0] = b1;
                    ipv4.u8[1] = b2;
                    ipv4.u8[2] = b3;
                    ipv4.u8[3] = b4;

                    // save ipv4
                    tb_ipaddr_ipv4_set(addr, &ipv4);
                }

                // found it
                found = 1;

                // trace
                tb_trace_d("response: ");
                break;
            }
        }
        else
        {
            // decode rdata
            answer.rdata = (tb_byte_t*)tb_dns_decode_name(&stream, answer.name);

            // trace
            tb_trace_d("response: alias: %s", answer.rdata? (tb_char_t const*)answer.rdata : "");
        }

        // trace
        tb_trace_d("response: ");
    }

    // found it?
    tb_check_return_val(found, tb_false);

#if 0
    // decode authorities
    for (i = 0; i < header.authority; i++)
    {
        // decode answer
        tb_dns_answer_t answer;
        tb_trace_d("response: authority: %d", i);

        // decode dns name
        tb_char_t* name = tb_dns_decode_name(&stream, answer.name);
        tb_trace_d("response: name: %s", name? name : "");

        // decode resource
        answer.res.type =   tb_static_stream_read_u16_be(&stream);
        answer.res.class_ = tb_static_stream_read_u16_be(&stream);
        answer.res.ttl =    tb_static_stream_read_u32_be(&stream);
        answer.res.size =   tb_static_stream_read_u16_be(&stream);
        tb_trace_d("response: type: %d",    answer.res.type);
        tb_trace_d("response: class: %d",   answer.res.class_);
        tb_trace_d("response: ttl: %d",     answer.res.ttl);
        tb_trace_d("response: size: %d",    answer.res.size);

        // is ipv4?
        if (answer.res.type == 1)
        {
            tb_byte_t b1 = tb_static_stream_read_u8(&stream);
            tb_byte_t b2 = tb_static_stream_read_u8(&stream);
            tb_byte_t b3 = tb_static_stream_read_u8(&stream);
            tb_byte_t b4 = tb_static_stream_read_u8(&stream);
            tb_trace_d("response: ipv4: %u.%u.%u.%u", b1, b2, b3, b4);
        }
        else
        {
            // decode data
            answer.rdata = tb_dns_decode_name(&stream, answer.name);
            tb_trace_d("response: server: %s", answer.rdata? answer.rdata : "");
        }
        tb_trace_d("response: ");
    }

    for (i = 0; i < header.resource; i++)
    {
        // decode answer
        tb_dns_answer_t answer;
        tb_trace_d("response: resource: %d", i);

        // decode dns name
        tb_char_t* name = tb_dns_decode_name(&stream, answer.name);
        tb_trace_d("response: name: %s", name? name : "");

        // decode resource
        answer.res.type =   tb_static_stream_read_u16_be(&stream);
        answer.res.class_ = tb_static_stream_read_u16_be(&stream);
        answer.res.ttl =    tb_static_stream_read_u32_be(&stream);
        answer.res.size =   tb_static_stream_read_u16_be(&stream);
        tb_trace_d("response: type: %d",    answer.res.type);
        tb_trace_d("response: class: %d",   answer.res.class_);
        tb_trace_d("response: ttl: %d",     answer.res.ttl);
        tb_trace_d("response: size: %d",    answer.res.size);

        // is ipv4?
        if (answer.res.type == 1)
        {
            tb_byte_t b1 = tb_static_stream_read_u8(&stream);
            tb_byte_t b2 = tb_static_stream_read_u8(&stream);
            tb_byte_t b3 = tb_static_stream_read_u8(&stream);
            tb_byte_t b4 = tb_static_stream_read_u8(&stream);
            tb_trace_d("response: ipv4: %u.%u.%u.%u", b1, b2, b3, b4);
        }
        else
        {
            // decode data
            answer.rdata = tb_dns_decode_name(&stream, answer.name);
            tb_trace_d("response: alias: %s", answer.rdata? answer.rdata : "");
        }
        tb_trace_d("response: ");
    }
#endif

    // ok
    return tb_true;
}