Example #1
0
    bool prepare(
        MemoryManager                  mm,
        const Functional::value_vec_t& static_args,
        Environment                    environment,
        NodeReporter                   reporter
    )
    {
        ConstByteString expression = static_args[0].as_string();
        try {
            m_expression.assign(
                expression.const_data(), expression.length(),
                boost::regex_constants::normal
            );
        }
        catch (const boost::bad_expression& e) {
            reporter.error(
                "Could not compile regexp: " +
                expression.to_s() +
                " (" + e.what() + ")"
            );
            return false;
        }

        m_replacement = static_args[1].as_string().to_s();
        return true;
    }
Example #2
0
void Transformation::pre_eval(Environment environment, NodeReporter reporter)
{
    // Validation guarantees that the first child is a string interval
    // and thus can be evaluated with default EvalContext.

    Value name_value = literal_value(children().front());
    ConstByteString name = name_value.value_as_byte_string();

    if (! name) {
        reporter.error("Missing transformation name.");
        return;
    }

    m_data->transformation = ConstTransformation::lookup(
        environment, string(name.const_data(), name.length()).c_str()
    );
}
Example #3
0
    Value eval_map(
        MemoryManager                  mm,
        const Functional::value_vec_t& secondary_args,
        boost::any&                    map_state,
        Value                          subvalue
    ) const
    {
        /* If the subvalue we've been given is NULL, likewise return a NULL
         * subvalue. We can't change anything. */
        if (! subvalue) {
            return Value();
        }

        if (subvalue.type() != Value::STRING) {
            return Value();
        }

        ConstByteString text = subvalue.as_string();
        boost::shared_ptr<vector<char> > result(new vector<char>());
        // Ensure that result.data() is non-null, even if we never insert
        // anything.
        result->reserve(1);

        // value_to_data() ensures that a copy is associated with the memory
        // pool and will be deleted when the memory pool goes away.
        value_to_data(result, mm.ib());

        boost::regex_replace(
            back_inserter(*result),
            text.const_data(), text.const_data() + text.length(),
            m_expression,
            m_replacement
        );

        return Value::create_string(
            mm,
            subvalue.name(), subvalue.name_length(),
            ByteString::create_alias(
                mm,
                result->data(), result->size()
            )
        );
    }
Example #4
0
void Operator::pre_eval(Environment environment, NodeReporter reporter)
{
    // Validation guarantees that the first two children are string
    // literals and thus can be evaluated with default EvalContext.

    node_list_t::const_iterator child_i = children().begin();
    Value op_name_value = literal_value(*child_i);
    ++child_i;
    Value params_value = literal_value(*child_i);

    ConstByteString op_name = op_name_value.value_as_byte_string();
    ConstByteString params  = params_value.value_as_byte_string();

    if (! op_name) {
        reporter.error("Missing operator name.");
        return;
    }
    if (! params) {
        reporter.error("Missing parameters.");
        return;
    }

    try {
        m_data->op =
            ConstOperator::lookup(environment, op_name.to_s().c_str());
    }
    catch (IronBee::enoent) {
        reporter.error("No such operator: " + op_name.to_s());
        return;
    }

    if (! (m_data->op.capabilities() & IB_OP_CAPABILITY_NON_STREAM)) {
        reporter.error("Only non-stream operator currently supported.");
        return;
    }

    m_data->instance_data = m_data->op.create_instance(
        environment.main_context(),
        IB_OP_CAPABILITY_NON_STREAM,
        params.to_s().c_str()
    );
}
Example #5
0
void Field::set_byte_string(
    ConstByteString value,
    const char* arg,
    size_t arg_length
) const
{
    Internal::check_type(BYTE_STRING, type());
    Internal::set_value(
        ib(), ib_ftype_bytestr_in(value.ib()),
        arg, arg_length
    );
}
Example #6
0
Field Field::create_byte_string(
    MemoryPool       pool,
    const char*      name,
    size_t           name_length,
    ConstByteString  value
)
{
    return Internal::create_field(
        pool,
        name, name_length,
        Field::BYTE_STRING,
        ib_ftype_bytestr_in(value.ib())
    );
}
Example #7
0
void Field::set_byte_string(ConstByteString value) const
{
    Internal::check_type(BYTE_STRING, type());
    Internal::set_value(ib(), ib_ftype_bytestr_in(value.ib()));
}
Example #8
0
ConstField get(ConstContext ctx, ConstByteString key)
{
    return get(ctx, key.const_data(), key.size());
}
Example #9
0
 /**
  * Remove a value from hash.
  *
  * @param[in] key Key.
  *
  * @return Value removed.
  *
  * @throw enoent if no such key.
  **/
 T remove(ConstByteString key) const
 {
     return remove(key.const_data(), key.length());
 }
Example #10
0
 /**
  * Set a value in hash.
  *
  * @param[in] key   Key.
  * @param[in] value Value.
  **/
 void set(ConstByteString key, T value) const
 {
     set(key.const_data(), key.length(), value);
 }
Example #11
0
 /**
  * Fetch value from hash.
  *
  * @param[in] key Key.
  *
  * @return Value.
  *
  * @throw enoent if no such key.
  **/
 T get(ConstByteString key) const
 {
     return get(key.const_data(), key.length());
 }