📄 megaco_sdp.erl
字号:
%% decode_pp_protocol_version(Value) when is_list(Value) -> ?d("decode_pp_protocol_version -> entry with" "~n Value: ~p", [Value]), Version = s2i(Value, invalid_protocol_version), ?d("decode_pp_protocol_version -> entry with" "~n Version: ~w", [Version]), decode_pp_protocol_version(Version);decode_pp_protocol_version(Version) when is_integer(Version) -> ?d("decode_pp_protocol_version -> entry with" "~n Version: ~w", [Version]), {ok, #megaco_sdp_v{version = Version}}.encode_pp_protocol_version(Version) when is_integer(Version) -> ?d("encode_pp_protocol_version -> entry with" "~n Version: ~w", [Version]), #'PropertyParm'{name = "v", value = [integer_to_list(Version)]};encode_pp_protocol_version(Version) -> error({invalid_protocol_version, Version}).%% ===== Origin =====%% decode_pp_origin(Value) -> ?d("decode_pp_origin -> entry with" "~n Value: ~p", [Value]), case string:tokens(Value, " \t") of [User, SessionId, Version, NetType, AddrType, Address] -> ?d("decode_pp_origin -> entry with" "~n User: ~p" "~n SessionId: ~p" "~n Version: ~p" "~n NetType: ~p" "~n AddrType: ~p" "~n Address: ~p", [User, SessionId, Version, NetType, AddrType, Address]), F = fun(X, R) -> case (catch list_to_integer(X)) of I when is_integer(I) -> I; _ -> error({invalid_origin, {R, X}}) end end, SID = F(SessionId, session_id), V = F(Version, version), SDP = #megaco_sdp_o{user_name = User, session_id = SID, version = V, network_type = decode_network_type(NetType), address_type = decode_address_type(AddrType), address = Address}, {ok, SDP}; Err -> ?d("decode_pp_origin -> " "~n Err: ~p", [Err]), invalid_pp(origin, Value, Err) end. encode_pp_origin(User0, SessionId0, Version0, NetType0, AddrType0, Addr0) -> ?d("do_encode_pp_origin -> entry with" "~n User0: ~p" "~n SessionId0: ~p" "~n Version0: ~p" "~n NetType0: ~p" "~n AddrType0: ~p" "~n Addr0: ~p", [User0, SessionId0, Version0, NetType0, AddrType0, Addr0]), User = encode_origin_user(User0), SessionId = encode_origin_session_id(SessionId0), Version = encode_origin_version(Version0), NetType = encode_origin_network_type(NetType0), AddrType = encode_origin_address_type(AddrType0), Addr = encode_origin_address(Addr0), #'PropertyParm'{name = "o", value = [ User ++ " " ++ SessionId ++ " " ++ Version ++ " " ++ NetType ++ " " ++ AddrType ++ " " ++ Addr ]}.encode_origin_user(User) when is_list(User) -> User;encode_origin_user(BadUser) -> error({invalid_origin_user, BadUser}).encode_origin_session_id(SID) when is_integer(SID) -> integer_to_list(SID);encode_origin_session_id(BadSID) -> error({invalid_origin_session_id, BadSID}).encode_origin_version(Version) when is_integer(Version) -> integer_to_list(Version);encode_origin_version(BadVersion) -> error({invalid_origin_version, BadVersion}).encode_origin_network_type(NT) -> case (catch encode_network_type(NT)) of {error, _} -> error({invalid_origin_network_type, NT}); Val -> Val end.encode_origin_address_type(AT) -> case (catch encode_address_type(AT)) of {error, _} -> error({invalid_origin_address_type, AT}); Val -> Val end.encode_origin_address(Addr) when is_list(Addr) -> Addr;encode_origin_address(BadAddr) -> error({invalid_origin_address, BadAddr}).%% ===== Session Name =====%% decode_pp_session_name(Value) -> ?d("decode_pp_session_name -> entry with" "~n Value: ~p", [Value]), {ok, #megaco_sdp_s{name = Value}}.encode_pp_session_name(Name) when is_list(Name) -> ?d("encode_pp_session_name -> entry with" "~n Name: '~s'", [Name]), #'PropertyParm'{name = "s", value = [Name]};encode_pp_session_name(BadName) -> error({invalid_session_name, BadName}). %% ===== Session and Media Information =====%% decode_pp_session_media_id(Value) -> ?d("decode_pp_session_media_id -> entry with" "~n Value: ~p", [Value]), {ok, #megaco_sdp_i{session_descriptor = Value}}.encode_pp_session_media_id(SD) when is_list(SD) -> ?d("encode_pp_session_media_id -> entry with" "~n SD: '~s'", [SD]), #'PropertyParm'{name = "i", value = [SD]};encode_pp_session_media_id(BadSD) -> error({invalid_session_media_id, BadSD}).%% ===== URI =====%% decode_pp_uri(Value) -> ?d("decode_pp_uri -> entry with" "~n Value: ~p", [Value]), {ok, #megaco_sdp_u{uri = Value}}.encode_pp_uri(URI) when is_list(URI) -> ?d("encode_pp_uri -> entry with" "~n URI: ~p", [URI]), #'PropertyParm'{name = "u", value = [URI]};encode_pp_uri(BadUri) -> error({invalid_uri, BadUri}).%% ===== Email Address and Phone Number =====%% decode_pp_email(Value) -> ?d("decode_pp_email -> entry with" "~n Value: ~p", [Value]), {ok, #megaco_sdp_e{email = Value}}.encode_pp_email(Email) when is_list(Email) -> ?d("encode_pp_email -> entry with" "~n Email: ~p", [Email]), #'PropertyParm'{name = "e", value = [Email]};encode_pp_email(BadEmail) -> error({invalid_email, BadEmail}). decode_pp_phone(Value) -> ?d("decode_pp_phone -> entry with" "~n Value: ~p", [Value]), {ok, #megaco_sdp_p{phone_number = Value}}.encode_pp_phone(Phone) when is_list(Phone) -> ?d("encode_pp_phone -> entry with" "~n Phone: ~p", [Phone]), #'PropertyParm'{name = "p", value = [Phone]};encode_pp_phone(BadPhone) -> error({invalid_phone, BadPhone}).%% ===== Connection Data =====%% decode_pp_connection_data(Value) -> ?d("decode_pp_connection_data -> entry with" "~n Value: ~p", [Value]), case string:tokens(Value, " \t") of [NetType, AddrType, ConnectionAddr] -> ?d("decode_pp_connection_data -> " "~n NetType: ~p" "~n AddrType: ~p" "~n ConnectionAddr: ~p", [NetType, AddrType, ConnectionAddr]), NT = decode_network_type(NetType), AT = decode_address_type(AddrType), case AT of ip4 -> ?d("decode_pp_connection_data -> ip4", []), ConnAddr = case string:tokens(ConnectionAddr, "\/") of [Base, TtlStr, NumOfAddrs] -> ?d("decode_pp_connection_data -> " "~n Base: ~p" "~n TtlStr: ~p" "~n NumOfAddrs:~p", [Base, TtlStr, NumOfAddrs]), TTL = s2i(TtlStr, invalid_connection_data_ttl), ?d("decode_pp_connection_data -> TTL: ~p", [TTL]), NOA = s2i(NumOfAddrs, invalid_connection_data_conn_addr_num_of), ?d("decode_pp_connection_data -> NOA: ~p", [NOA]), #megaco_sdp_c_conn_addr{base = Base, ttl = TTL, num_of = NOA}; [Base, TtlStr] -> ?d("decode_pp_connection_data -> " "~n Base: ~p" "~n TtlStr: ~p", [Base, TtlStr]), TTL = s2i(TtlStr, invalid_connection_data_conn_addr_ttl), ?d("decode_pp_connection_data -> TTL: ~p", [TTL]), #megaco_sdp_c_conn_addr{base = Base, ttl = TTL}; [Base] -> Base end, ?d("decode_pp_connection_data -> " "~n ConnAddr: ~p", [ConnAddr]), SDP = #megaco_sdp_c{network_type = NT, address_type = AT, connection_addr = ConnAddr}, {ok, SDP}; ip6 -> ?d("decode_pp_connection_data -> ip6", []), SDP = #megaco_sdp_c{network_type = NT, address_type = AT, connection_addr = ConnectionAddr}, {ok, SDP}; _ -> SDP = #megaco_sdp_c{network_type = NT, address_type = AT, connection_addr = ConnectionAddr}, {ok, SDP} end; Err -> invalid_pp(connection_data, Value, Err) end.encode_pp_connection_data(NetType0, AddrType0, ConnAddr0) -> ?d("encode_pp_connection_data -> entry with" "~n NetType0: ~p" "~n AddrType0: ~p" "~n ConnAddr0: ~p", [NetType0, AddrType0, ConnAddr0]), NetType = encode_conn_data_network_type(NetType0), AddrType = encode_conn_data_address_type(AddrType0), ConnAddr = encode_conn_data_conn_addr(AddrType0, ConnAddr0), Val = NetType ++ " " ++ AddrType ++ " " ++ ConnAddr, #'PropertyParm'{name = "c", value = [Val]}.encode_conn_data_network_type(NT) -> case (catch encode_network_type(NT)) of {error, _} -> error({invalid_connection_data_network_type, NT}); Val -> Val end.encode_conn_data_address_type(AT) -> case (catch encode_address_type(AT)) of {error, _} -> error({invalid_connection_data_address_type, AT}); Val -> Val end.encode_conn_data_conn_addr(_, CA) when is_list(CA) -> CA;encode_conn_data_conn_addr(ip4, CA) when is_record(CA, megaco_sdp_c_conn_addr) -> encode_conn_data_conn_addr(CA);encode_conn_data_conn_addr(AT, CA) when is_list(AT) and is_record(CA, megaco_sdp_c_conn_addr) -> case tolower(AT) of "ip4" -> encode_conn_data_conn_addr(CA); _ -> error({invalid_connection_data_conn_addr, {AT, CA}}) end;encode_conn_data_conn_addr(_, BadCA) -> error({invalid_connection_data_conn_addr, BadCA}).encode_conn_data_conn_addr(#megaco_sdp_c_conn_addr{base = Base0, ttl = TTL0, num_of = undefined}) -> Base = encode_conn_data_conn_addr_base(Base0), TTL = encode_conn_data_conn_addr_ttl(TTL0), Base ++ "/" ++ TTL;encode_conn_data_conn_addr(#megaco_sdp_c_conn_addr{base = Base0, ttl = TTL0, num_of = NumOf0}) -> Base = encode_conn_data_conn_addr_base(Base0), TTL = encode_conn_data_conn_addr_ttl(TTL0), NumOf = encode_conn_data_conn_addr_num_of(NumOf0), Base ++ "/" ++ TTL ++ "/" ++ NumOf. encode_conn_data_conn_addr_base(Base) when is_list(Base) -> Base;encode_conn_data_conn_addr_base(BadBase) -> error({invalid_connection_data_conn_addr_base, BadBase}).encode_conn_data_conn_addr_ttl(TTL) when is_integer(TTL) -> integer_to_list(TTL);encode_conn_data_conn_addr_ttl(BadTTL) -> error({invalid_connection_data_conn_addr_ttl, BadTTL}).encode_conn_data_conn_addr_num_of(NumOf) when is_integer(NumOf) -> integer_to_list(NumOf);encode_conn_data_conn_addr_num_of(BadNumOf) -> error({invalid_connection_data_conn_addr_num_of, BadNumOf}).%% ===== Bandwidth =====%% decode_pp_bandwidth(Value) -> ?d("decode_pp_bandwidth -> entry with" "~n Value: ~p", [Value]), case string:tokens(Value, ":") of [Modifier, BandwidthStr] -> ?d("decode_pp_bandwidth -> " "~n Modifier: ~p" "~n BandwidthStr: ~p", [Modifier, BandwidthStr]), Bandwidth = s2i(BandwidthStr, invalid_bandwidth_bandwidth), ?d("decode_pp_bandwidth -> " "~n Bandwidth: ~w", [Bandwidth]), SDP = #megaco_sdp_b{modifier = Modifier, bandwidth = Bandwidth}, {ok, SDP}; Err -> invalid_pp(bandwidth_info, Value, Err) end. encode_pp_bandwidth(Modifier0, Bandwidth0) -> ?d("encode_pp_bandwidth -> entry with" "~n Modifier0: ~p" "~n Bandwidth0: ~p", [Modifier0, Bandwidth0]), Modifier = encode_bandwidth_mod(Modifier0), Bandwidth = encode_bandwidth_bw(Bandwidth0), Val = Modifier ++ ":" ++ Bandwidth, #'PropertyParm'{name = "b", value = [Val]}.encode_bandwidth_mod(Modifier) when is_list(Modifier) -> Modifier;encode_bandwidth_mod(BadModifier) -> error({invalid_bandwidth_modifier, BadModifier}).encode_bandwidth_bw(Bandwidth) when is_integer(Bandwidth) -> integer_to_list(Bandwidth);encode_bandwidth_bw(BadBandwidth) -> error({invalid_bandwidth_bandwidth, BadBandwidth}).%% ===== Times, Repeat Times and Time Zones =====%% decode_pp_times(Value) -> ?d("decode_pp_times -> entry with" "~n Value: ~p", [Value]), case string:tokens(Value, " \t") of [StartStr, StopStr] -> ?d("decode_pp_times -> " "~n StartStr: ~p" "~n StopStr: ~p", [StartStr, StopStr]), Start = s2i(StartStr, invalid_times_start), ?d("decode_pp_times -> entry with" "~n Stop: ~w", [Start]), Stop = s2i(StopStr, invalid_times_stop), ?d("decode_pp_times -> entry with" "~n Stop: ~w", [Stop]), SDP = #megaco_sdp_t{start = Start, stop = Stop}, {ok, SDP}; Err -> invalid_pp(time_session_active, Value, Err) end.encode_pp_times(Start0, Stop0) -> ?d("encode_pp_times -> entry with" "~n Start0: ~p" "~n Stop0: ~p", [Start0, Stop0]), Start = encode_times_start(Start0), Stop = encode_times_stop(Stop0), Val = Start ++ " " ++ Stop, #'PropertyParm'{name = "t", value = [Val]}.encode_times_start(Time) when is_integer(Time) -> integer_to_list(Time);encode_times_start(BadTime) -> error({invalid_times_start, BadTime}). encode_times_stop(Time) when is_integer(Time) -> integer_to_list(Time);encode_times_stop(BadTime) -> error({invalid_times_stop, BadTime}). decode_pp_rtimes(Value) -> ?d("decode_pp_rtimes -> entry with" "~n Value: ~p", [Value]), case string:tokens(Value, " \t") of [Repeat, Duration | ListOfOffsets] -> ?d("decode_pp_rtimes -> " "~n Repeat: ~p" "~n Duration: ~p" "~n ListOfOffsets: ~p", [Repeat, Duration, ListOfOffsets]), SDP = #megaco_sdp_r{repeat_interval = Repeat, active_duration = Duration, list_of_offsets = ListOfOffsets}, {ok, SDP}; Err -> invalid_pp(repeat_times, Value, Err) end.encode_pp_rtimes(Repeat0, Duration0, ListOfOffsets0) -> ?d("encode_pp_rtimes -> entry with" "~n Repeat0: ~p" "~n Duration0: ~p" "~n ListOfOffsets0: ~p", [Repeat0, Duration0, ListOfOffsets0]), Repeat = encode_rtimes_repeat(Repeat0), Duration = encode_rtimes_duration(Duration0), ListOfOffsets = encode_rtimes_list_of_offsets(ListOfOffsets0), Val = Repeat ++ " " ++ Duration ++ ListOfOffsets, #'PropertyParm'{name = "r", value = [Val]}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -