int Scanner::read_num() { clear_token(); bool hex_dec_mode = false; if (cur_char() == '0' && next_char() == 'x') { push_char(cur_char()); go_ahead(); push_char(cur_char()); go_ahead(); hex_dec_mode = true; } while (true) { char c = cur_char(); if (hex_dec_mode) { if (!is_hex_dec(c)) { break; } } else { if (!is_dec(c)) { break; } } push_char(cur_char()); go_ahead(); } return s_info->num_token; }
int Scanner::read_op(struct OperatorTableEntry *op) { int i; for (i = strlen(op->str); i > 0; i--) { go_ahead(); } return op->op; }
int Scanner::read_sym() { clear_token(); while (is_symbody(cur_char())) { push_char(cur_char()); go_ahead(); } return s_info->sym_token; }
/** * the actual filtering function * Expects Flow messages, otherwise it throws * @param m the message to be checked */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Flow)) throw std::runtime_error("FlowFilter: wrong message type"); const Flow* flow = static_cast<const Flow* > (m.get()); if(is_indirect(m_ip_src_mode)) { if(!go_ahead( (m_ip_src_address & m_ip_src_mask) == (flow->key().src_ip4 & m_ip_src_mask), m_ip_src_mode)) return; } if(is_indirect(m_ip_dst_mode)) { if(!go_ahead( (m_ip_dst_address & m_ip_dst_mask) == (flow->key().dst_ip4 & m_ip_dst_mask), m_ip_dst_mode)) return; } if(is_indirect(m_layer4_mode)) { if(!go_ahead(m_layer4_proto == flow->key().proto, m_layer4_mode)) return; } if( (flow->key().proto != Packet::kUDP) && (flow->key().proto != Packet::kTCP) ) flow_passed(std::move(m)); if(is_indirect(m_src_port_mode)) { if(!go_ahead(m_src_port == flow->key().src_port, m_src_port_mode)) return; } if(is_indirect(m_dst_port_mode)) { if(!go_ahead(m_dst_port == flow->key().dst_port, m_dst_port_mode)) return; } flow_passed(std::move(m)); }
void Scanner::skip_non_token() { while (1) { if ((is_space(cur_char()))) { go_ahead(); } else if (is_comment_start()) { skip_comment(); } else { return ; } } }
int Scanner::read_str() { clear_token(); go_ahead(); while (1) { int c = cur_char(); if (c == '\n') { return -1; } if (c == '\"') { go_ahead(); break; } if (c == '\\') { go_ahead(); c = cur_char(); } push_char(c); go_ahead(); } return s_info->str_token; }
/** * Methode definissant la strategie a adopter * @param strategie - la strategie a adopter */ void Strategy::set(Strat strategy) { switch(strategy) { case BAU_ON: bau_on(); break; case BAU_OFF: bau_off(); break; case GO_AHEAD: go_ahead(); break; default: break; } }
void Scanner::skip_comment() { if (!is_comment_start()) { return ; } char c = next_char(); if (c == '/') { while (cur_char() != '\n' && cur_char() != 0) { go_ahead(); } go_ahead(); } else { go_ahead(); go_ahead(); while (cur_char() != '*' || next_char() != '/') { go_ahead(); } go_ahead(); go_ahead(); } }
/** * the actual filtering function * Expects Packet messages, otherwise it throws * @param m the message to be checked */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Packet)) { throw std::runtime_error("PacketFiler: wrong message type"); } const Packet* packet = static_cast<const Packet* > (m.get()); if(is_indirect(m_layer3_mode)) { if(!go_ahead(m_layer3_proto == packet->l3_protocol(), m_layer3_mode)) { return; } } if( packet->l3_protocol() != Packet::kPktTypeIP4) { packet_passed(std::move(m)); return; } if(is_indirect(m_ip_src_mode)) { if(!go_ahead( (m_ip_src_address & m_ip_src_mask) == (packet->ip_src() & m_ip_src_mask), m_ip_src_mode)) { return; } } if(is_indirect(m_ip_dst_mode)) { if(!go_ahead( (m_ip_dst_address & m_ip_dst_mask) == (packet->ip_dst() & m_ip_dst_mask), m_ip_dst_mode)) { return; } } if(is_indirect(m_layer4_mode)) { if(!go_ahead(m_layer4_proto == packet->l4_protocol(), m_layer4_mode)) { return; } } if( (!packet->is_udp()) && (!packet->is_tcp()) ) { packet_passed(std::move(m)); return; } // checks source port. if (!go_ahead(m_src_port_mode, m_src_ports, packet->src_port())) { return; } // checks destination port. if (!go_ahead(m_dst_port_mode, m_dst_ports, packet->dst_port())) { return; } packet_passed(std::move(m)); }