Example #1
0
bool
hash_add(hash_table *table, tc_pool_t *pool, uint64_t key, void *data)
{
    hash_node   *hn, *tmp;
    link_list   *l;
    p_link_node  ln;

    ln = hash_find_node(table, key);
    if (ln == NULL) {
        tmp = hash_node_malloc(pool, key, data);
        if (tmp != NULL) {
            l   = get_link_list(table, key);
            ln  = link_node_malloc(pool, tmp);
            if (ln != NULL) {
                link_list_push(l, ln);
                table->total++;
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        hn = (hash_node *) ln->data;
        hn->data = data;
        return false;
    }
}
static bool 
check_pack_needed_for_recons(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
{
    uint16_t            size_tcp;
    p_link_node         ln;
    unsigned char      *payload, command, *pkt;
    mysql_table_item_t *item;

    if (s->cur_pack.cont_len > 0) {

        size_tcp = tcp->doff << 2;
        payload = (unsigned char *) ((char *) tcp + size_tcp);
        /* skip packet length */
        payload  = payload + 3;
        /* skip packet number */
        payload  = payload + 1;
        command  = payload[0];

        if (command != COM_STMT_PREPARE) {
            return false;
        }

        item = hash_find(ctx.table, s->hash_key);
        if (!item) {
            item = tc_pcalloc(ctx.pool, sizeof(mysql_table_item_t));
            if (item != NULL) {
                item->list = link_list_create(ctx.pool);
                if (item->list != NULL) {
                    hash_add(ctx.table, ctx.pool, s->hash_key, item);
                    if (ctx.table->total > MAX_TABLE_ITEM_NUM) {
                        tc_log_info(LOG_INFO, 0, "too many items in ctx.table");
                    }
                } else {
                    tc_log_info(LOG_ERR, 0, "list create err");
                    return false;
                }
            } else {
                tc_log_info(LOG_ERR, 0, "mysql item create err");
                return false;
            }
        }

        if (item->list->size > MAX_SP_SIZE) {
            tc_log_info(LOG_INFO, 0, "too many prepared stmts for a session");
            return false;
        }

        tc_log_debug1(LOG_INFO, 0, "push packet:%u", ntohs(s->src_port));

        pkt = (unsigned char *) cp_fr_ip_pack(ctx.pool, ip);
        ln  = link_node_malloc(ctx.pool, pkt);
        ln->key = ntohl(tcp->seq);
        link_list_append_by_order(item->list, ln);
        item->tot_cont_len += s->cur_pack.cont_len;

        return true;
    }

    return false;
}
Example #3
0
void
delay_table_add(uint64_t key, struct msg_server_s *msg)
{
    tc_pool_t           *pool;
    p_link_node          ln;
    delay_sess_t        *s;
    struct msg_server_s *cmsg;

    s = (delay_sess_t *) hash_find(table, key);
    if (s == NULL) {
        pool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0);

        if (pool != NULL) {

            s = (delay_sess_t *) tc_pcalloc(pool, sizeof(delay_sess_t));
            if (s != NULL) {
                s->key = key;
                s->pool = pool;
                s->msg_list = link_list_create(s->pool);
                s->evt = tc_event_add_timer(s->pool, OUTPUT_INTERVAL, s, 
                        tc_delay_del_obs);
                msg_ls_cnt++;
                hash_add(table, s->pool, key, s);
            } else {
                return;
            }
        } else {
            return;
        }
    }

    cmsg = copy_message(s->pool, msg);
    if (cmsg != NULL) {
        ln   = link_node_malloc(s->pool, (void *) cmsg);
        link_list_append(s->msg_list, ln);

        msg_item_cnt++;
    }
}
Example #4
0
/* add message to delay table */
void
delay_table_add(uint64_t key, struct msg_server_s *msg)
{
    link_list           *msg_list;
    p_link_node          ln;
    struct msg_server_s *cmsg;

    msg_list = (link_list *) hash_find(table, key);
    if (msg_list == NULL) {
        msg_ls_cnt++;
        msg_list = link_list_create();
        hash_add(table, key, msg_list);
    }

    cmsg = copy_message(msg);
    if (cmsg != NULL) {
        ln   = link_node_malloc((void *) cmsg);
        link_list_append(msg_list, ln);

        msg_item_cnt++;
    }

    return;
}