📄 megaco_session_internalizer.erl
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%%%% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%%%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%%%% $Id$%%%%----------------------------------------------------------------------%% Purpose: Transform IDL form to Megaco internal form%%-----------------------------------------------------------------------module(megaco_session_internalizer).-include_lib("megaco/include/megaco.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-include_lib("megaco_session/include/Megaco.hrl").-include_lib("megaco_session/include/MegacoMessage.hrl").-include_lib("megaco_session/include/MegacoSessionIp.hrl").-compile([export_all]).tr_term([], State) -> [];tr_term(Chars, State) when list(Chars) -> do_string_to_term([], Chars, 1).do_string_to_term(Cont, Chars, Line) -> case catch erl_scan:tokens(Cont, Chars, Line) of {done, {ok, Tokens, EndLine}, Rest} -> case erl_parse:parse_term(Tokens) of {ok, Term} -> Term; {error, Reason} -> throw({error, Reason}) end; {more, Cont2} -> do_string_to_term(Cont2, ". ", Line); Other -> throw({error, Other}) end.tr_atom(Atom, State) -> list_to_atom(Atom).tr_conn_handle(#'Megaco_ConnHandle'{localMid = LocalMid, remoteMid = RemoteMid}, State) -> #megaco_conn_handle{local_mid = tr_MId(LocalMid, State), remote_mid = tr_MId(RemoteMid, State)}.tr_receive_handle(#'Megaco_ReceiveHandle'{localMid = LocalMid, encodingMod = EncMod, encodingConfig = EncConfig, sendMod = SendMod}, State) -> #megaco_receive_handle{local_mid = tr_MId(LocalMid, State), encoding_mod = tr_atom(EncMod, State), encoding_config = tr_enc_conf(EncConfig, State), send_mod = tr_atom(SendMod, State)}.% tr_enc_conf("native", State) ->% [native];tr_enc_conf(EncConfig, State) -> tr_term(EncConfig, State).tr_send_handle(SendHandle, State) -> binary_to_term(SendHandle).tr_timer(#'Megaco_Timer'{label = Tag, value = Val}, State) -> case Tag of 'TimerType_once' -> tr_timer_once(Val, State); 'TimerType_incr' -> #megaco_incr_timer{wait_for = tr_timer_once(Val#'Megaco_IncrTimer'.waitFor, State), factor = tr_timer_once(Val#'Megaco_IncrTimer'.factor, State), incr = tr_timer_once(Val#'Megaco_IncrTimer'.incr, State), max_retries = tr_timer_once(Val#'Megaco_IncrTimer'.maxRetries, State)} end.tr_timer_once(Int, State) -> case 'Megaco':infinity() of Infinity when Infinity == Int-> infinity; _ -> Int end.tr_user_info_value(#'Megaco_UserInfoValue'{label = Item, value = Val}, State) -> case Item of 'UserInfo_connections' -> {connections, [tr_conn_handle(CH, State) || CH <- Val]}; 'UserInfo_receiveHandle' -> {receive_handle, tr_receive_handle(Val, State)}; 'UserInfo_minTransId' -> {min_trans_id, Val}; 'UserInfo_maxTransId' -> {max_trans_id, Val}; 'UserInfo_requestTimer' -> {request_timer, tr_timer(Val, State)}; 'UserInfo_longRequestTimer' -> {long_request_timer, tr_timer(Val, State)}; 'UserInfo_autoAck' -> {auto_ack, Val}; 'UserInfo_replyTimer' -> {reply_timer, tr_timer(Val, State)}; 'UserInfo_pendingTimer' -> {pending_timer, tr_timer(Val, State)}; 'UserInfo_sendMod' -> {send_mod, tr_atom(Val, State)}; 'UserInfo_encodingMod' -> {encoding_mod, tr_atom(Val, State)}; 'UserInfo_encodingConfig' -> {encoding_config, tr_term(Val, State)}; 'UserInfo_protocolVersion' -> {protocol_version, Val}; 'UserInfo_replyData' -> {reply_data, tr_term(Val, State)}; 'UserInfo_userMod' -> {user_mod, tr_atom(Val, State)}; 'UserInfo_userArgs' -> {user_args, tr_term(Val, State)} end.tr_conn_info_value(#'Megaco_ConnInfoValue'{label = Item, value = Val}, State) -> case Item of 'ConnInfo_controlPid' -> {control_pid, Val}; 'ConnInfo_sendHandle' -> {send_handle, tr_term(Val, State)}; 'ConnInfo_receiveHandle' -> {receive_handle, tr_receive_handle(Val, State)}; 'ConnInfo_minTransId' -> {min_trans_id, Val}; 'ConnInfo_maxTransId' -> {max_trans_id, Val}; 'ConnInfo_requestTimer' -> {request_timer, tr_timer(Val, State)}; 'ConnInfo_longRequestTimer' -> {long_request_timer, tr_timer(Val, State)}; 'ConnInfo_autoAck' -> {auto_ack, Val}; 'ConnInfo_replyTimer' -> {reply_timer, tr_timer(Val, State)}; 'ConnInfo_pendingTimer' -> {pending_timer , tr_timer(Val, State)}; 'ConnInfo_sendMod' -> {send_mod, tr_atom(Val, State)}; 'ConnInfo_encodingMod' -> {encoding_mod, tr_atom(Val, State)}; 'ConnInfo_encodingConfig' -> {encoding_config, tr_term(Val, State)}; 'ConnInfo_protocolVersion' -> {protocol_version, Val}; 'ConnInfo_replyData' -> {reply_data, tr_term(Val, State)} end.tr_Status(#'Megaco_Status'{label = Tag, value = Val}, State) -> case Tag of ok -> ok; errorString -> {error, Val}; errorDesc -> {error, tr_ErrorDescriptor(Val, State)} end.tr_IpOptions(IpOptions, State) -> [tr_IpOption(IpOption, State) || IpOption <- IpOptions].tr_IpOption(#'MegacoSessionIp_IpOption'{label = Item, value = Val}, State) -> case Item of 'Ip_host' -> {host, Val}; 'Ip_port' -> {port, Val}; 'Ip_ether' -> {ether, Val}; 'Ip_broadcast' -> {broadcast, tr_bool(Val, State)}; 'Ip_dontroute' -> {dontroute, tr_bool(Val, State)}; 'Ip_keepalive' -> {keepalive, tr_bool(Val, State)}; 'Ip_nodelay' -> {nodelay, tr_bool(Val, State)}; 'Ip_recbuf' -> {recbuf, Val}; 'Ip_sndbuf' -> {sndbuf, Val} end.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%tr_MegacoMessage(#'MegacoMessage_MegacoMessage'{authHeader = Auth, mess = Mess}, State) -> #'MegacoMessage'{authHeader = tr_opt_AuthenticationHeader(Auth, State), mess = tr_Message(Mess, State)}.tr_opt_AuthenticationHeader(#'MegacoMessage_OptAuthenticationHeader'{label = false}, State) -> asn1_NOVALUE;tr_opt_AuthenticationHeader(#'MegacoMessage_OptAuthenticationHeader'{label = true, value = Val}, State) -> tr_AuthenticationHeader(Val, State).tr_AuthenticationHeader(#'MegacoMessage_AuthenticationHeader'{secParmIndex = SPI, seqNum = SN, ad = AuthData}, State) -> #'AuthenticationHeader'{secParmIndex = tr_SecurityParmIndex(SPI, State), seqNum = tr_SequenceNum(SN, State), ad = tr_AuthData(AuthData, State)}.tr_SecurityParmIndex(SPI, State) -> SPI.tr_SequenceNum(SN, State) -> SN.tr_AuthData(AuthData, State) -> AuthData.tr_Message(#'MegacoMessage_Message'{version = Version, mId = MID, messageBody = Body}, State) -> #'Message'{version = tr_version(Version, State), mId = tr_MId(MID, State), messageBody = tr_Message_messageBody(Body, State)}.tr_version(Version, State) -> Version.tr_Message_messageBody(#'MegacoMessage_MessageBodyUnion'{label = Tag, value = Val}, State) -> case Tag of 'MessageBodyChoice_messageError' -> {messageError, tr_ErrorDescriptor(Val, State)}; 'MessageBodyChoice_transactions' -> {transactions, [tr_Transaction(T, State) || T <- Val]} end.tr_MId(#'MegacoMessage_MIdUnion'{label = Tag, value = Val}, State) -> case Tag of 'MIdChoice_ip4Address' -> {ip4Address, tr_IP4Address(Val, State)}; 'MIdChoice_ip6Address' -> {ip6Address, tr_IP6Address(Val, State)}; 'MIdChoice_domainName'-> {domainName, tr_DomainName(Val, State)}; 'MIdChoice_deviceName' -> {deviceName, tr_PathName(Val, State)}; 'MIdChoice_preliminary' -> preliminary_mid end.tr_mtpAddress(MtpAddr, State) -> MtpAddr.tr_DomainName(#'MegacoMessage_DomainName'{name = Name, portNumber = Port}, State) -> #'DomainName'{name = Name, portNumber = tr_opt_unsigned_short(Port, State)}.tr_IP4Address(#'MegacoMessage_IP4Address'{address = Address, portNumber = Port}, State) -> #'IP4Address'{address = Address, portNumber = tr_opt_unsigned_short(Port, State)}.tr_IP6Address(#'MegacoMessage_IP6Address'{address = Address, portNumber = Port}, State) -> #'IP6Address'{address = Address, portNumber = tr_opt_unsigned_short(Port, State)}.tr_PathName(Path, State) -> Path.tr_Transaction(#'MegacoMessage_TransactionUnion'{label = Tag, value = Val}, State) -> case Tag of 'TransactionChoice_transactionRequest' -> {transactionRequest, tr_TransactionRequest(Val, State)}; 'TransactionChoice_transactionPending' -> {transactionPending, tr_TransactionPending(Val, State)}; 'TransactionChoice_transactionReply' -> {transactionReply, tr_TransactionReply(Val, State)}; 'TransactionChoice_transactionResponseAck' -> {transactionResponseAck, [tr_TransactionAck(T, State) || T <- Val]} end.tr_TransactionAck(#'MegacoMessage_TransactionAck'{firstAck = First, lastAck = Last}, State) -> #'TransactionAck'{firstAck = tr_TransactionId(First, State), lastAck = tr_opt_TransactionId(Last, State)}.tr_opt_TransactionId(#'MegacoMessage_OptTransactionId'{label = false}, State) ->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -