bool EchoGenerator::operator()(Input::input_p& out_input) { if (m_state->produced_input) { return false; } out_input->id = m_state->id; out_input->source = m_state; out_input->connection = Input::Connection(); out_input->connection.connection_opened( Input::Buffer(local_ip), local_port, Input::Buffer(remote_ip), remote_port ); out_input->connection.connection_closed(); out_input->connection.add_transaction() .connection_data_in(Input::Buffer(m_state->request)); ParseModifier()(out_input); m_state->produced_input = true; return true; }
bool SuricataGenerator::operator()(Input::input_p& input) { if (! *m_state->input) { return false; } ++m_state->line_number; *input = Input::Input(); input->id = m_state->prefix + ":" + boost::lexical_cast<string>(m_state->line_number); data_p data = boost::make_shared<data_t>(); input->source = data; boost::smatch match; string line; getline(*m_state->input, line); if (! *m_state->input) { return false; } if (regex_match(line, match, s_re_line)) { data->local_ip = match.str(9); data->remote_ip = match.str(7); input->connection.connection_opened( Input::Buffer(data->local_ip), boost::lexical_cast<uint32_t>( match.str(10) ), Input::Buffer(data->remote_ip), boost::lexical_cast<uint32_t>( match.str(8) ) ); data->request = match.str(4) + " " + match.str(1) + " " \ + match.str(5) + s_eol; data->request += "Referer: " + match.str(3) + s_eol; data->request += "User-Agent: " + match.str(2) + s_eol; data->request += s_eol; boost::smatch response_match; if (regex_match(match.str(6), response_match, s_re_response)) { data->response = match.str(5) + " " + response_match.str(1) + s_eol; data->response += "Location: " + response_match.str(2) + s_eol; } else { data->response = match.str(5) + " " + match.str(6) + s_eol; } input->connection.add_transaction( Input::Buffer(data->request), Input::Buffer(data->response) ); input->connection.connection_closed(); } else { throw runtime_error("Unparsed line: " + line); } ParseModifier()(input); return true; }
bool CKeySet::Parse(const std::string& token) { Reset(); std::string s = StringToLower(token); // parse the modifiers while (!s.empty()) { if (ParseModifier(s, "up+", "u+")) { modifiers |= KS_RELEASE; } else if (ParseModifier(s, "any+", "*+")) { modifiers |= KS_ANYMOD; } else if (ParseModifier(s, "alt+", "a+")) { modifiers |= KS_ALT; } else if (ParseModifier(s, "ctrl+", "c+")) { modifiers |= KS_CTRL; } else if (ParseModifier(s, "meta+", "m+")) { modifiers |= KS_META; } else if (ParseModifier(s, "shift+", "s+")) { modifiers |= KS_SHIFT; } else { break; } } #ifdef DISALLOW_RELEASE_BINDINGS modifiers &= ~KS_RELEASE; #endif // remove ''s, if present if ((s.size() >= 2) && (s[0] == '\'') && (s[s.size() - 1] == '\'')) { s = s.substr(1, s.size() - 2); } if (s.find("0x") == 0) { const char* start = (s.c_str() + 2); char* end; key = strtol(start, &end, 16); if (end == start) { Reset(); LOG_L(L_ERROR, "KeySet: Bad hex value: %s", s.c_str()); return false; } if (key >= SDLK_LAST) { Reset(); LOG_L(L_ERROR, "KeySet: Hex value out of range: %s", s.c_str()); return false; } } else { key = keyCodes->GetCode(s); if (key < 0) { Reset(); LOG_L(L_ERROR, "KeySet: Bad keysym: %s", s.c_str()); return false; } } if (keyCodes->IsModifier(key)) { modifiers |= KS_ANYMOD; } if (AnyMod()) { ClearModifiers(); } return true; }