📄 megaco_session_externalizer.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 Megaco internal form to IDL form%%-----------------------------------------------------------------------module(megaco_session_externalizer).-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(Term, State) -> lists:flatten(io_lib:format("~p", [Term])).tr_atom(Atom, State) -> atom_to_list(Atom).tr_conn_handle(#megaco_conn_handle{local_mid = LocalMid, remote_mid = RemoteMid}, State) -> #'Megaco_ConnHandle'{localMid = tr_MId(LocalMid, State), remoteMid = tr_MId(RemoteMid, State)}.tr_receive_handle(#megaco_receive_handle{local_mid = LocalMid, encoding_mod = EncMod, encoding_config = EncConfig, send_mod = SendMod}, State) -> #'Megaco_ReceiveHandle'{localMid = tr_MId(LocalMid, State), encodingMod = tr_atom(EncMod, State), encodingConfig = tr_enc_conf(EncConfig, State), sendMod = tr_atom(SendMod, State)}.%% tr_enc_conf([native], State) ->%% "native";tr_enc_conf(EncConfig, State) -> tr_term(EncConfig, State).tr_send_handle(SendHandle, State) -> term_to_binary(SendHandle).tr_timer(T, State) when record(T, megaco_incr_timer) -> #'Megaco_Timer'{label = 'TimerType_incr', value = tr_timer_incr(T, State)};tr_timer(T, State) -> #'Megaco_Timer'{label = 'TimerType_once', value = tr_timer_once(T, State)}.tr_timer_incr(T, State) -> #'Megaco_IncrTimer'{waitFor = tr_timer_once(T#megaco_incr_timer.wait_for, State), factor = tr_timer_once(T#megaco_incr_timer.factor, State), incr = tr_timer_once(T#megaco_incr_timer.incr, State), maxRetries = tr_timer_once(T#megaco_incr_timer.max_retries, State)}.tr_timer_once(infinity, State) -> 'Megaco':infinity();tr_timer_once(Int, State) when integer(Int) -> Int.tr_Status(ok, State) -> #'Megaco_Status'{label = ok};tr_Status({errorDesc, Desc}, State) when record(Desc, 'ErrorDescriptor') -> #'Megaco_Status'{label = errorDesc, value = tr_ErrorDescriptor(Desc, State)};tr_Status(Desc, State) when record(Desc, 'MegacoMessage_ErrorDescriptor') -> #'Megaco_Status'{label = errorDesc, value = tr_ErrorDescriptor(Desc, State)};tr_Status({errorString, String}, State) when list(String) -> #'Megaco_Status'{label = errorString, value = String};tr_Status({error, Reason}, State) -> #'Megaco_Status'{label = errorString, value = tr_term(Reason, State)};tr_Status({'EXIT', Reason}, State) -> #'Megaco_Status'{label = errorString, value = tr_term({'EXIT', Reason}, State)}.tr_IpOptions(IpOptions, State) -> [tr_IpOption(IpOption, State) || IpOption <- IpOptions].tr_IpOption({Tag, Val}, State) -> case Tag of host -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_host', value = Val}; port -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_port', value = Val}; ether -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_ether', value = Val}; broadcast -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_broadcast', value = tr_bool(Val, State)}; dontroute -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_dontroute', value = tr_bool(Val, State)}; keepalive -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_keepalive', value = tr_bool(Val, State)}; nodelay -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_nodelay', value = tr_bool(Val, State)}; recbuf -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_recbuf', value = Val}; sndbuf -> #'MegacoSessionIp_IpOption'{label = 'MegacoSessionIp_Ip_sndbuf', value = Val} end.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%tr_MegacoMessage(#'MegacoMessage'{authHeader = Auth, mess = Mess}, State) -> #'MegacoMessage_MegacoMessage'{authHeader = tr_opt_AuthenticationHeader(Auth, State), mess = tr_Message(Mess, State)}.tr_opt_AuthenticationHeader(asn1_NOVALUE, State) -> #'MegacoMessage_OptAuthenticationHeader'{label = false};tr_opt_AuthenticationHeader(Val, State) -> #'MegacoMessage_OptAuthenticationHeader'{label = true, value = tr_AuthenticationHeader(Val, State)}.tr_AuthenticationHeader(#'AuthenticationHeader'{secParmIndex = SPI, seqNum = SN, ad = AuthData}, State) -> #'MegacoMessage_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(#'Message'{version = Version, mId = MID, messageBody = Body}, State) -> #'MegacoMessage_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({Tag, Val}, State) -> case Tag of messageError -> #'MegacoMessage_MessageBodyUnion'{label = 'MessageBodyChoice_messageError', value = tr_ErrorDescriptor(Val, State)}; transactions -> #'MegacoMessage_MessageBodyUnion'{label = 'MessageBodyChoice_transactions', value = [tr_Transaction(T, State) || T <- Val]} end.tr_MId(preliminary_mid, State) -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_preliminary'};tr_MId({Tag, Val}, State) -> case Tag of ip4Address -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_ip4Address', value = tr_IP4Address(Val, State)}; ip6Address -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_ip6Address', value = tr_IP6Address(Val, State)}; domainName -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_domainName', value = tr_DomainName(Val, State)}; deviceName -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_deviceName', value = tr_PathName(Val, State)}; mtpAddress -> #'MegacoMessage_MIdUnion'{label = 'MIdChoice_mtpAddress', value = tr_mtpAddress(Val, State)} end.tr_mtpAddress(MtpAddr, State) -> MtpAddr.tr_DomainName(#'DomainName'{name = Name, portNumber = Port}, State) -> #'MegacoMessage_DomainName'{name = Name, portNumber = tr_opt_unsigned_short(Port, State)}.tr_IP4Address(#'IP4Address'{address = Address, portNumber = Port}, State) -> #'MegacoMessage_IP4Address'{address = Address, portNumber = tr_opt_unsigned_short(Port, State)}.tr_IP6Address(#'IP6Address'{address = Address, portNumber = Port}, State) -> #'MegacoMessage_IP6Address'{address = Address, portNumber = tr_opt_unsigned_short(Port, State)}.tr_PathName(Path, State) -> Path.tr_Transaction({Tag, Val}, State) -> case Tag of transactionRequest -> #'MegacoMessage_TransactionUnion'{label = 'TransactionChoice_transactionRequest', value = tr_TransactionRequest(Val, State)}; transactionPending -> #'MegacoMessage_TransactionUnion'{label = 'TransactionChoice_transactionPending', value = tr_TransactionPending(Val, State)}; transactionReply -> #'MegacoMessage_TransactionUnion'{label = 'TransactionChoice_transactionReply', value = tr_TransactionReply(Val, State)}; transactionResponseAck -> #'MegacoMessage_TransactionUnion'{label = 'TransactionChoice_transactionResponseAck', value = [tr_TransactionAck(T, State) || T <- Val]} end.tr_TransactionAck(#'TransactionAck'{firstAck = First, lastAck = Last}, State) -> #'MegacoMessage_TransactionAck'{firstAck = tr_TransactionId(First, State), lastAck = tr_opt_TransactionId(Last, State)}.tr_opt_TransactionId(asn1_NOVALUE, State) -> #'MegacoMessage_OptTransactionId'{label = false};tr_opt_TransactionId(Id, State) -> #'MegacoMessage_OptTransactionId'{label = true, value = tr_TransactionId(Id, State)}.tr_TransactionId(Id, State) -> Id.tr_TransactionRequest(#'TransactionRequest'{transactionId = Id, actions = Actions}, State) when list(Actions) -> #'MegacoMessage_TransactionRequest'{id = tr_TransactionId(Id, State), actions = [tr_ActionRequest(ActReq, State) || ActReq <- Actions]}.tr_TransactionPending(#'TransactionPending'{transactionId = Id}, State) -> #'MegacoMessage_TransactionPending'{id = tr_TransactionId(Id, State)}.tr_TransactionReply(#'TransactionReply'{transactionId = Id, immAckRequired = ImmAck, transactionResult = TransRes}, State) -> #'MegacoMessage_TransactionReply'{id = tr_TransactionId(Id, State), immAckRequired = tr_opt_null(ImmAck, State), transactionResult = tr_TransactionReply_transactionResult(TransRes, State)}.tr_opt_null(asn1_NOVALUE, State) -> false;tr_opt_null('NULL', State) -> true.tr_TransactionReply_transactionResult({Tag, Val}, State) -> case Tag of transactionError -> #'MegacoMessage_TransactionResultUnion'{label = 'TransactionResultChoice_transactionError', value = tr_ErrorDescriptor(Val, State)}; actionReplies -> #'MegacoMessage_TransactionResultUnion'{label = 'TransactionResultChoice_actionReplies', value = [tr_ActionReply(ActRep, State) || ActRep <- Val]} end.tr_opt_ErrorDescriptor(asn1_NOVALUE, State) -> #'MegacoMessage_OptErrorDescriptor'{label = false};tr_opt_ErrorDescriptor(ErrDesc, State) -> #'MegacoMessage_OptErrorDescriptor'{label = true, value = tr_ErrorDescriptor(ErrDesc, State)}.tr_ErrorDescriptor(#'ErrorDescriptor'{errorCode = Code, errorText = Text}, State) -> #'MegacoMessage_ErrorDescriptor'{code = tr_ErrorCode(Code, State), text = tr_opt_ErrorText(Text, State)}.tr_ErrorCode(Code, State) -> Code.tr_opt_ErrorText(asn1_NOVALUE, State) -> #'MegacoMessage_OptErrorText'{label = false};tr_opt_ErrorText(Text, State) -> #'MegacoMessage_OptErrorText'{label = true, value = Text}.tr_ContextID(CtxId, State) -> CtxId.tr_ActionRequest(#'ActionRequest'{contextId = CtxId, contextRequest = CtxReq, contextAttrAuditReq = CtxAuditReq,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -