示例#1
0
/**
 * @internal
 *
 * Called to initialize data in a new connection.
 */
static ib_status_t ironbee_conn_init(ib_engine_t *ib,
                                   ib_conn_t *iconn, void *cbdata)
{
    //server_rec *s = cbdata;
    conn_rec *c = (conn_rec *)iconn->pctx;
    ib_status_t rc;

    ib_clog_debug(iconn->ctx, 9, "Initializing connection remote=%s:%d local=%s:%d",
                  c->remote_ip, c->remote_addr->port,
                  c->local_ip, c->local_addr->port);

    /*
     * Create connection fields
     */

    /* remote_ip */
    iconn->remote_ipstr = c->remote_ip;
    rc = ib_data_add_bytestr(iconn->dpi,
                             "remote_ip",
                             (uint8_t *)c->remote_ip,
                             strlen(c->remote_ip),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

    /* remote_port */
    iconn->remote_port = c->remote_addr->port;
    rc = ib_data_add_num(iconn->dpi,
                         "remote_port",
                         c->remote_addr->port,
                         NULL);
    if (rc != IB_OK) {
        return rc;
    }

    /* local_ip */
    iconn->local_ipstr = c->local_ip;
    rc = ib_data_add_bytestr(iconn->dpi,
                             "local_ip",
                             (uint8_t *)c->remote_ip,
                             strlen(c->remote_ip),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

    /* local_port */
    iconn->local_port = c->local_addr->port;
    rc = ib_data_add_num(iconn->dpi,
                         "local_port",
                         c->local_addr->port,
                         NULL);
    if (rc != IB_OK) {
        return rc;
    }

    return IB_OK;
}
示例#2
0
文件: ironbee.c 项目: igalic/ironbee
static ib_status_t ironbee_conn_init(ib_engine_t *ib,
                                   ib_conn_t *iconn, void *cbdata)
{
  /* when does this happen? */
  ib_status_t rc;
  const struct sockaddr *addr;
  int port;

  TSCont contp = iconn->pctx;
  ib_ssn_ctx* data = TSContDataGet(contp);
//  ib_clog_debug(....);

  /* remote ip */
  addr = TSHttpTxnClientAddrGet(data->txnp);

  addr2str(addr, data->remote_ip, &port);

  iconn->remote_ipstr = data->remote_ip;
  rc = ib_data_add_bytestr(iconn->dpi,
                             "remote_ip",
                             (uint8_t *)iconn->remote_ipstr,
                             strlen(data->remote_ip),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

  /* remote port */
  iconn->remote_port = port;
    rc = ib_data_add_num(iconn->dpi, "remote_port", port, NULL);
    if (rc != IB_OK) {
        return rc;
    }

  /* local end */
  addr = TSHttpTxnIncomingAddrGet(data->txnp);

  addr2str(addr, data->local_ip, &port);

    iconn->local_ipstr = data->local_ip;
    rc = ib_data_add_bytestr(iconn->dpi,
                             "local_ip",
                             (uint8_t *)iconn->local_ipstr,
                             strlen(data->local_ip),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

    /* local_port */
    iconn->local_port = port;
    rc = ib_data_add_num(iconn->dpi, "local_port", port, NULL);
    if (rc != IB_OK) {
        return rc;
    }
  return IB_OK;
}
示例#3
0
/*
 * Callback used to generate connection fields.
 */
static ib_status_t core_gen_connect_fields(ib_engine_t *ib,
                                           ib_conn_t *conn,
                                           ib_state_event_type_t event,
                                           void *cbdata)
{
    ib_status_t rc;

    assert(ib != NULL);
    assert(conn != NULL);
    assert(event == handle_connect_event);

    rc = ib_data_add_bytestr(conn->data,
                             "server_addr",
                             (uint8_t *)conn->local_ipstr,
                             strlen(conn->local_ipstr),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

    rc = ib_data_add_num(conn->data,
                         "server_port",
                         conn->local_port,
                         NULL);
    if (rc != IB_OK) {
        return rc;
    }

    rc = ib_data_add_bytestr(conn->data,
                             "remote_addr",
                             (uint8_t *)conn->remote_ipstr,
                             strlen(conn->remote_ipstr),
                             NULL);
    if (rc != IB_OK) {
        return rc;
    }

    rc = ib_data_add_num(conn->data,
                         "remote_port",
                         conn->remote_port,
                         NULL);
    if (rc != IB_OK) {
        return rc;
    }


    return IB_OK;
}
示例#4
0
TEST(TestIronBee, test_data_indexed)
{
    ib_engine_t *ib;
    ib_data_config_t *dataconfig;
    ib_data_t *data;
    ib_field_t *f;
    size_t i;
    size_t j;
    ib_num_t n;

    ibtest_engine_create(&ib);

    ASSERT_EQ(IB_OK, ib_data_config_create(ib_engine_pool_main_get(ib), & dataconfig));

    ASSERT_EQ(IB_OK, ib_data_register_indexed_ex(dataconfig, "foo", 3, &i));
    ASSERT_EQ(IB_OK, ib_data_lookup_index(dataconfig, "foo", &j));
    ASSERT_EQ(i, j);
    ASSERT_EQ(IB_ENOENT, ib_data_lookup_index(dataconfig, "bar", NULL));
    ASSERT_EQ(IB_EINVAL, ib_data_register_indexed(dataconfig, "foo"));

    ASSERT_EQ(IB_OK, ib_data_create(dataconfig, ib_engine_pool_main_get(ib), &data));
    ASSERT_TRUE(data);

    ASSERT_EQ(IB_OK, ib_data_add_num(data, "foo", 5, NULL));
    ASSERT_EQ(IB_OK, ib_data_get_indexed(data, i, &f));
    ASSERT_EQ(IB_OK, ib_field_value(f, ib_ftype_num_out(&n)));
    ASSERT_EQ(5, n);
    ASSERT_EQ(IB_OK, ib_data_get(data, "foo", &f));
    ASSERT_EQ(IB_OK, ib_field_value(f, ib_ftype_num_out(&n)));
    ASSERT_EQ(5, n);
}
示例#5
0
static ib_status_t core_gen_flags_collection(ib_engine_t *ib,
                                             ib_tx_t *tx,
                                             ib_state_event_type_t event,
                                             void *cbdata)
{
    assert(ib != NULL);
    assert(tx != NULL);
    assert(tx->data != NULL);
    assert(event == tx_started_event);

    ib_status_t rc;
    const ib_tx_flag_map_t *flag;

    for (flag = ib_core_fields_tx_flags();  flag->name != NULL;  ++flag) {
        rc = ib_data_add_num(tx->data, flag->tx_name, flag->default_value, NULL);
        if (rc != IB_OK) {
            return rc;
        }
        if (flag->default_value) {
            ib_tx_flags_set(tx, flag->tx_flag);
        }
        else {
            ib_tx_flags_unset(tx, flag->tx_flag);
        }
    }

    return IB_OK;
}