mirror of
https://github.com/cubixle/radius-rs.git
synced 2026-04-24 23:04:43 +01:00
Respect the pre-defined attribute type on each value
This commit is contained in:
@@ -131,31 +131,36 @@ fn main() {
|
||||
.collect();
|
||||
dict_file_paths.sort();
|
||||
|
||||
let mut rfc_names: Vec<String> = Vec::new();
|
||||
let mut attribute_name_to_rfc_name: HashMap<String, String> = HashMap::new();
|
||||
|
||||
for dict_file_path in dict_file_paths {
|
||||
let (radius_attributes, radius_attribute_to_values_map) =
|
||||
parse_dict_file(dict_file_path).unwrap();
|
||||
|
||||
let rfc_name = dict_file_path.extension().unwrap().to_str().unwrap();
|
||||
|
||||
for attr in &radius_attributes {
|
||||
attribute_name_to_rfc_name.insert(attr.name.clone(), rfc_name.to_owned());
|
||||
}
|
||||
|
||||
let value_defined_attributes_set = radius_attribute_to_values_map
|
||||
.keys()
|
||||
.collect::<HashSet<&String>>();
|
||||
|
||||
let rfc_name = dict_file_path.extension().unwrap().to_str().unwrap();
|
||||
let mut w = BufWriter::new(File::create(out_dir.join(format!("{}.rs", rfc_name))).unwrap());
|
||||
|
||||
generate_header(&mut w);
|
||||
generate_header(&mut w, &rfc_names);
|
||||
generate_attributes_code(&mut w, &radius_attributes, &value_defined_attributes_set);
|
||||
generate_values_code(&mut w, &radius_attribute_to_values_map);
|
||||
generate_values_code(
|
||||
&mut w,
|
||||
&radius_attribute_to_values_map,
|
||||
&attribute_name_to_rfc_name,
|
||||
);
|
||||
|
||||
for attr in &radius_attributes {
|
||||
attribute_name_to_rfc_name.insert(attr.name.clone(), rfc_name.to_owned());
|
||||
}
|
||||
rfc_names.push(rfc_name.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_header(w: &mut BufWriter<File>) {
|
||||
fn generate_header(w: &mut BufWriter<File>, rfc_names: &[String]) {
|
||||
let code = b"// Code generated by machine generator; DO NOT EDIT.
|
||||
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
@@ -169,19 +174,32 @@ use crate::tag::Tag;
|
||||
";
|
||||
|
||||
w.write_all(code).unwrap();
|
||||
|
||||
for rfc_name in rfc_names {
|
||||
w.write_all(format!("use crate::{};\n", rfc_name).as_bytes())
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_values_code(
|
||||
w: &mut BufWriter<File>,
|
||||
attr_to_values_map: &BTreeMap<String, Vec<RadiusValue>>,
|
||||
attr_name_to_rfc_name: &HashMap<String, String>,
|
||||
) {
|
||||
for (attr, values) in attr_to_values_map {
|
||||
generate_values_for_attribute_code(w, attr, values);
|
||||
generate_values_for_attribute_code(w, attr, values, attr_name_to_rfc_name.get(attr));
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_values_for_attribute_code(w: &mut BufWriter<File>, attr: &str, values: &[RadiusValue]) {
|
||||
fn generate_values_for_attribute_code(
|
||||
w: &mut BufWriter<File>,
|
||||
attr: &str,
|
||||
values: &[RadiusValue],
|
||||
maybe_rfc_name: Option<&String>,
|
||||
) {
|
||||
let type_name = attr.to_pascal_case();
|
||||
|
||||
if maybe_rfc_name.is_none() {
|
||||
w.write_all(
|
||||
format!(
|
||||
"\npub type {type_name} = {radius_value_type};\n",
|
||||
@@ -191,7 +209,23 @@ fn generate_values_for_attribute_code(w: &mut BufWriter<File>, attr: &str, value
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
for v in values {
|
||||
if let Some(rfc_name) = maybe_rfc_name {
|
||||
w.write_all(
|
||||
format!(
|
||||
"pub const {type_name_prefix}_{value_name}: {rfc_name}::{type_name} = {value};\n",
|
||||
type_name_prefix = type_name.to_screaming_snake_case(),
|
||||
value_name = v.name.to_screaming_snake_case(),
|
||||
rfc_name = rfc_name,
|
||||
type_name = type_name,
|
||||
value = v.value,
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap()
|
||||
} else {
|
||||
w.write_all(
|
||||
format!(
|
||||
"pub const {type_name_prefix}_{value_name}: {type_name} = {value};\n",
|
||||
@@ -204,6 +238,7 @@ fn generate_values_for_attribute_code(w: &mut BufWriter<File>, attr: &str, value
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
w.write_all(b"\n").unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
use crate::avp::{AVPError, AVPType, AVP};
|
||||
use crate::packet::Packet;
|
||||
|
||||
use crate::rfc2866;
|
||||
|
||||
pub const ACCT_TUNNEL_CONNECTION_TYPE: AVPType = 68;
|
||||
pub fn delete_acct_tunnel_connection(packet: &mut Packet) {
|
||||
packet.delete(ACCT_TUNNEL_CONNECTION_TYPE);
|
||||
@@ -42,11 +44,9 @@ pub fn lookup_all_acct_tunnel_packets_lost(packet: &Packet) -> Result<Vec<u32>,
|
||||
}
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
pub type AcctStatusType = u32;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_START: AcctStatusType = 9;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_STOP: AcctStatusType = 10;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_REJECT: AcctStatusType = 11;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_START: AcctStatusType = 12;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_STOP: AcctStatusType = 13;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_REJECT: AcctStatusType = 14;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_START: rfc2866::AcctStatusType = 9;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_STOP: rfc2866::AcctStatusType = 10;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_REJECT: rfc2866::AcctStatusType = 11;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_START: rfc2866::AcctStatusType = 12;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_STOP: rfc2866::AcctStatusType = 13;
|
||||
pub const ACCT_STATUS_TYPE_TUNNEL_LINK_REJECT: rfc2866::AcctStatusType = 14;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
use crate::avp::{AVPError, AVPType, AVP};
|
||||
use crate::packet::Packet;
|
||||
|
||||
use crate::rfc2865;
|
||||
|
||||
pub const ERROR_CAUSE_TYPE: AVPType = 101;
|
||||
pub fn delete_error_cause(packet: &mut Packet) {
|
||||
packet.delete(ERROR_CAUSE_TYPE);
|
||||
@@ -40,5 +42,4 @@ pub const ERROR_CAUSE_PROXY_PROCESSING_ERROR: ErrorCause = 505;
|
||||
pub const ERROR_CAUSE_RESOURCES_UNAVAILABLE: ErrorCause = 506;
|
||||
pub const ERROR_CAUSE_REQUEST_INITIATED: ErrorCause = 507;
|
||||
|
||||
pub type ServiceType = u32;
|
||||
pub const SERVICE_TYPE_AUTHORIZE_ONLY: ServiceType = 17;
|
||||
pub const SERVICE_TYPE_AUTHORIZE_ONLY: rfc2865::ServiceType = 17;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
// Code generated by machine generator; DO NOT EDIT.
|
||||
|
||||
pub type AcctTerminateCause = u32;
|
||||
pub const ACCT_TERMINATE_CAUSE_SUPPLICANT_RESTART: AcctTerminateCause = 19;
|
||||
pub const ACCT_TERMINATE_CAUSE_REAUTHENTICATION_FAILURE: AcctTerminateCause = 20;
|
||||
pub const ACCT_TERMINATE_CAUSE_PORT_REINIT: AcctTerminateCause = 21;
|
||||
pub const ACCT_TERMINATE_CAUSE_PORT_DISABLED: AcctTerminateCause = 22;
|
||||
use crate::rfc2865;
|
||||
use crate::rfc2866;
|
||||
|
||||
pub type NasPortType = u32;
|
||||
pub const NAS_PORT_TYPE_TOKEN_RING: NasPortType = 20;
|
||||
pub const NAS_PORT_TYPE_FDDI: NasPortType = 21;
|
||||
use crate::rfc2868;
|
||||
|
||||
pub type TunnelType = u32;
|
||||
pub const TUNNEL_TYPE_VLAN: TunnelType = 13;
|
||||
pub const ACCT_TERMINATE_CAUSE_SUPPLICANT_RESTART: rfc2866::AcctTerminateCause = 19;
|
||||
pub const ACCT_TERMINATE_CAUSE_REAUTHENTICATION_FAILURE: rfc2866::AcctTerminateCause = 20;
|
||||
pub const ACCT_TERMINATE_CAUSE_PORT_REINIT: rfc2866::AcctTerminateCause = 21;
|
||||
pub const ACCT_TERMINATE_CAUSE_PORT_DISABLED: rfc2866::AcctTerminateCause = 22;
|
||||
|
||||
pub const NAS_PORT_TYPE_TOKEN_RING: rfc2865::NasPortType = 20;
|
||||
pub const NAS_PORT_TYPE_FDDI: rfc2865::NasPortType = 21;
|
||||
|
||||
pub const TUNNEL_TYPE_VLAN: rfc2868::TunnelType = 13;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Code generated by machine generator; DO NOT EDIT.
|
||||
|
||||
pub type NasPortType = u32;
|
||||
pub const NAS_PORT_TYPE_PP_PO_A: NasPortType = 30;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_A: NasPortType = 31;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_E: NasPortType = 32;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_VLAN: NasPortType = 33;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_QIN_Q: NasPortType = 34;
|
||||
use crate::rfc2865;
|
||||
|
||||
pub const NAS_PORT_TYPE_PP_PO_A: rfc2865::NasPortType = 30;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_A: rfc2865::NasPortType = 31;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_E: rfc2865::NasPortType = 32;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_VLAN: rfc2865::NasPortType = 33;
|
||||
pub const NAS_PORT_TYPE_PP_PO_EO_QIN_Q: rfc2865::NasPortType = 34;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Code generated by machine generator; DO NOT EDIT.
|
||||
|
||||
pub type ErrorCause = u32;
|
||||
pub const ERROR_CAUSE_INVALID_ATTRIBUTE_VALUE: ErrorCause = 407;
|
||||
pub const ERROR_CAUSE_MULTIPLE_SESSION_SELECTION_UNSUPPORTED: ErrorCause = 508;
|
||||
use crate::rfc3576;
|
||||
|
||||
pub const ERROR_CAUSE_INVALID_ATTRIBUTE_VALUE: rfc3576::ErrorCause = 407;
|
||||
pub const ERROR_CAUSE_MULTIPLE_SESSION_SELECTION_UNSUPPORTED: rfc3576::ErrorCause = 508;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
use crate::avp::{AVPError, AVPType, AVP};
|
||||
use crate::packet::Packet;
|
||||
|
||||
use crate::rfc2865;
|
||||
|
||||
pub const FRAMED_MANAGEMENT_TYPE: AVPType = 133;
|
||||
pub fn delete_framed_management(packet: &mut Packet) {
|
||||
packet.delete(FRAMED_MANAGEMENT_TYPE);
|
||||
@@ -109,5 +111,4 @@ pub const MANAGEMENT_TRANSPORT_PROTECTION_INTEGRITY_PROTECTION: ManagementTransp
|
||||
pub const MANAGEMENT_TRANSPORT_PROTECTION_INTEGRITY_CONFIDENTIALITY_PROTECTION:
|
||||
ManagementTransportProtection = 3;
|
||||
|
||||
pub type ServiceType = u32;
|
||||
pub const SERVICE_TYPE_FRAMED_MANAGEMENT: ServiceType = 18;
|
||||
pub const SERVICE_TYPE_FRAMED_MANAGEMENT: rfc2865::ServiceType = 18;
|
||||
|
||||
Reference in New Issue
Block a user