mirror of
https://github.com/cubixle/radius-rs.git
synced 2026-04-24 22:44:42 +01:00
Fix code generator to ensure the order of the generated values
This commit is contained in:
@@ -3,14 +3,16 @@
|
||||
set -eu
|
||||
|
||||
REPO_ROOT="$(cd ./"$(git rev-parse --show-cdup)" || exit; pwd)"
|
||||
DICTS_DIR="${REPO_ROOT}/dicts"
|
||||
SRC_DIR="${REPO_ROOT}/src"
|
||||
|
||||
DICT_NAMES=(
|
||||
"rfc2865"
|
||||
)
|
||||
DICTS=$(ls "$DICTS_DIR")
|
||||
|
||||
for DICT_NAME in "${DICT_NAMES[@]}"; do
|
||||
cat /dev/null > "${REPO_ROOT}/src/${DICT_NAME}.rs"
|
||||
cargo run --bin code_gen "${REPO_ROOT}/dicts/dictionary.${DICT_NAME}" "${REPO_ROOT}/src/${DICT_NAME}.rs"
|
||||
# shellcheck disable=SC2068
|
||||
for DICT in ${DICTS[@]}; do
|
||||
DICT_NAME="${DICT##*.}"
|
||||
cat /dev/null > "${SRC_DIR}/${DICT_NAME}.rs"
|
||||
cargo run --bin code_gen "${DICTS_DIR}/dictionary.${DICT_NAME}" "${SRC_DIR}/${DICT_NAME}.rs"
|
||||
done
|
||||
|
||||
cargo fmt
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufWriter, Write};
|
||||
use std::path::Path;
|
||||
@@ -110,7 +110,7 @@ use crate::packet::Packet;
|
||||
|
||||
fn generate_values_code(
|
||||
w: &mut BufWriter<File>,
|
||||
attr_to_values_map: &HashMap<String, Vec<RadiusValue>>,
|
||||
attr_to_values_map: &BTreeMap<String, Vec<RadiusValue>>,
|
||||
) {
|
||||
for (attr, values) in attr_to_values_map {
|
||||
generate_values_for_attribute_code(w, attr, values);
|
||||
@@ -333,14 +333,14 @@ fn generate_vsa_attribute_code() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
type DictParsed = (Vec<RadiusAttribute>, HashMap<String, Vec<RadiusValue>>);
|
||||
type DictParsed = (Vec<RadiusAttribute>, BTreeMap<String, Vec<RadiusValue>>);
|
||||
|
||||
fn parse_dict_file(dict_file_path: &Path) -> Result<DictParsed, String> {
|
||||
let line_filter_re = Regex::new(r"^(?:#.*|)$").unwrap();
|
||||
let tabs_re = Regex::new(r"\t+").unwrap();
|
||||
|
||||
let mut radius_attributes: Vec<RadiusAttribute> = Vec::new();
|
||||
let mut radius_attribute_to_values: HashMap<String, Vec<RadiusValue>> = HashMap::new();
|
||||
let mut radius_attribute_to_values: BTreeMap<String, Vec<RadiusValue>> = BTreeMap::new();
|
||||
|
||||
let lines = read_lines(dict_file_path).unwrap();
|
||||
for line_result in lines {
|
||||
|
||||
@@ -6,6 +6,41 @@ use crate::attribute::Attribute;
|
||||
use crate::attributes::AVPType;
|
||||
use crate::packet::Packet;
|
||||
|
||||
pub type FramedCompression = u32;
|
||||
pub const FRAMED_COMPRESSION_NONE: FramedCompression = 0;
|
||||
pub const FRAMED_COMPRESSION_VAN_JACOBSON_TCP_IP: FramedCompression = 1;
|
||||
pub const FRAMED_COMPRESSION_IPX_HEADER_COMPRESSION: FramedCompression = 2;
|
||||
pub const FRAMED_COMPRESSION_STAC_LZS: FramedCompression = 3;
|
||||
|
||||
pub type FramedProtocol = u32;
|
||||
pub const FRAMED_PROTOCOL_PPP: FramedProtocol = 1;
|
||||
pub const FRAMED_PROTOCOL_SLIP: FramedProtocol = 2;
|
||||
pub const FRAMED_PROTOCOL_ARAP: FramedProtocol = 3;
|
||||
pub const FRAMED_PROTOCOL_GANDALF_SLML: FramedProtocol = 4;
|
||||
pub const FRAMED_PROTOCOL_XYLOGICS_IPX_SLIP: FramedProtocol = 5;
|
||||
pub const FRAMED_PROTOCOL_X_75_SYNCHRONOUS: FramedProtocol = 6;
|
||||
|
||||
pub type FramedRouting = u32;
|
||||
pub const FRAMED_ROUTING_NONE: FramedRouting = 0;
|
||||
pub const FRAMED_ROUTING_BROADCAST: FramedRouting = 1;
|
||||
pub const FRAMED_ROUTING_LISTEN: FramedRouting = 2;
|
||||
pub const FRAMED_ROUTING_BROADCAST_LISTEN: FramedRouting = 3;
|
||||
|
||||
pub type LoginService = u32;
|
||||
pub const LOGIN_SERVICE_TELNET: LoginService = 0;
|
||||
pub const LOGIN_SERVICE_RLOGIN: LoginService = 1;
|
||||
pub const LOGIN_SERVICE_TCP_CLEAR: LoginService = 2;
|
||||
pub const LOGIN_SERVICE_PORT_MASTER: LoginService = 3;
|
||||
pub const LOGIN_SERVICE_LAT: LoginService = 4;
|
||||
pub const LOGIN_SERVICE_X25_PAD: LoginService = 5;
|
||||
pub const LOGIN_SERVICE_X25_T3POS: LoginService = 6;
|
||||
pub const LOGIN_SERVICE_TCP_CLEAR_QUIET: LoginService = 8;
|
||||
|
||||
pub type LoginTCPPort = u32;
|
||||
pub const LOGIN_TCP_PORT_TELNET: LoginTCPPort = 23;
|
||||
pub const LOGIN_TCP_PORT_RLOGIN: LoginTCPPort = 513;
|
||||
pub const LOGIN_TCP_PORT_RSH: LoginTCPPort = 514;
|
||||
|
||||
pub type NasPortType = u32;
|
||||
pub const NAS_PORT_TYPE_ASYNC: NasPortType = 0;
|
||||
pub const NAS_PORT_TYPE_SYNC: NasPortType = 1;
|
||||
@@ -28,45 +63,6 @@ pub const NAS_PORT_TYPE_CABLE: NasPortType = 17;
|
||||
pub const NAS_PORT_TYPE_WIRELESS_OTHER: NasPortType = 18;
|
||||
pub const NAS_PORT_TYPE_WIRELESS_802_11: NasPortType = 19;
|
||||
|
||||
pub type LoginTCPPort = u32;
|
||||
pub const LOGIN_TCP_PORT_TELNET: LoginTCPPort = 23;
|
||||
pub const LOGIN_TCP_PORT_RLOGIN: LoginTCPPort = 513;
|
||||
pub const LOGIN_TCP_PORT_RSH: LoginTCPPort = 514;
|
||||
|
||||
pub type FramedCompression = u32;
|
||||
pub const FRAMED_COMPRESSION_NONE: FramedCompression = 0;
|
||||
pub const FRAMED_COMPRESSION_VAN_JACOBSON_TCP_IP: FramedCompression = 1;
|
||||
pub const FRAMED_COMPRESSION_IPX_HEADER_COMPRESSION: FramedCompression = 2;
|
||||
pub const FRAMED_COMPRESSION_STAC_LZS: FramedCompression = 3;
|
||||
|
||||
pub type TerminationAction = u32;
|
||||
pub const TERMINATION_ACTION_DEFAULT: TerminationAction = 0;
|
||||
pub const TERMINATION_ACTION_RADIUS_REQUEST: TerminationAction = 1;
|
||||
|
||||
pub type FramedRouting = u32;
|
||||
pub const FRAMED_ROUTING_NONE: FramedRouting = 0;
|
||||
pub const FRAMED_ROUTING_BROADCAST: FramedRouting = 1;
|
||||
pub const FRAMED_ROUTING_LISTEN: FramedRouting = 2;
|
||||
pub const FRAMED_ROUTING_BROADCAST_LISTEN: FramedRouting = 3;
|
||||
|
||||
pub type LoginService = u32;
|
||||
pub const LOGIN_SERVICE_TELNET: LoginService = 0;
|
||||
pub const LOGIN_SERVICE_RLOGIN: LoginService = 1;
|
||||
pub const LOGIN_SERVICE_TCP_CLEAR: LoginService = 2;
|
||||
pub const LOGIN_SERVICE_PORT_MASTER: LoginService = 3;
|
||||
pub const LOGIN_SERVICE_LAT: LoginService = 4;
|
||||
pub const LOGIN_SERVICE_X25_PAD: LoginService = 5;
|
||||
pub const LOGIN_SERVICE_X25_T3POS: LoginService = 6;
|
||||
pub const LOGIN_SERVICE_TCP_CLEAR_QUIET: LoginService = 8;
|
||||
|
||||
pub type FramedProtocol = u32;
|
||||
pub const FRAMED_PROTOCOL_PPP: FramedProtocol = 1;
|
||||
pub const FRAMED_PROTOCOL_SLIP: FramedProtocol = 2;
|
||||
pub const FRAMED_PROTOCOL_ARAP: FramedProtocol = 3;
|
||||
pub const FRAMED_PROTOCOL_GANDALF_SLML: FramedProtocol = 4;
|
||||
pub const FRAMED_PROTOCOL_XYLOGICS_IPX_SLIP: FramedProtocol = 5;
|
||||
pub const FRAMED_PROTOCOL_X_75_SYNCHRONOUS: FramedProtocol = 6;
|
||||
|
||||
pub type ServiceType = u32;
|
||||
pub const SERVICE_TYPE_LOGIN_USER: ServiceType = 1;
|
||||
pub const SERVICE_TYPE_FRAMED_USER: ServiceType = 2;
|
||||
@@ -80,6 +76,10 @@ pub const SERVICE_TYPE_CALLBACK_NAS_PROMPT: ServiceType = 9;
|
||||
pub const SERVICE_TYPE_CALL_CHECK: ServiceType = 10;
|
||||
pub const SERVICE_TYPE_CALLBACK_ADMINISTRATIVE: ServiceType = 11;
|
||||
|
||||
pub type TerminationAction = u32;
|
||||
pub const TERMINATION_ACTION_DEFAULT: TerminationAction = 0;
|
||||
pub const TERMINATION_ACTION_RADIUS_REQUEST: TerminationAction = 1;
|
||||
|
||||
pub const USER_NAME_TYPE: AVPType = 1;
|
||||
pub fn delete_user_name(packet: &mut Packet) {
|
||||
packet.delete(USER_NAME_TYPE);
|
||||
|
||||
Reference in New Issue
Block a user