⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 megaco_binary_transformer_prev3b.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 5 页
字号:
%% ``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 internal form of Megaco/H.248 messages%%-----------------------------------------------------------------------module(megaco_binary_transformer_prev3b).-include_lib("megaco/include/megaco.hrl").%% -include_lib("megaco/include/megaco_message.hrl").-include_lib("megaco/include/megaco_message_prev3b.hrl").-include_lib("megaco/src/app/megaco_internal.hrl").-export([tr_message/3, tr_transaction/3]).-define(DEFAULT_NAME_RESOLVER, megaco_binary_name_resolver_prev3b).-record(state, {mode,                 % verify | encode | decode                resolver_module,      %                 resolver_options}).resolve(Type, Item, State, Constraint) ->    case State#state.mode of        verify ->            Item;        encode ->	    ?d("resolve(encode) -> encode: ~p",[Item]),            Mod = State#state.resolver_module,            Opt = State#state.resolver_options,            EncodedItem = Mod:encode_name(Opt, Type, Item),	    ?d("resolve -> verify contraint for ~p",[EncodedItem]),	    verify_constraint(EncodedItem, Constraint);        decode ->	    ?d("resolve(decode) -> verify contraint for ~p",[Item]),	    DecodedItem = verify_constraint(Item, Constraint),            Mod = State#state.resolver_module,            Opt = State#state.resolver_options,	    ?d("resolve(decode) -> decode: ~p",[DecodedItem]),            Mod:decode_name(Opt, Type, DecodedItem)    end.verify_constraint(Item, valid) ->    Item;verify_constraint(Item, Constraint) when function(Constraint) ->    Constraint(Item).tr_message(MegaMsg, Mode, Config) ->    case Config of        [native] ->            MegaMsg;        [verify] ->            State = #state{mode = verify},            tr_MegacoMessage(MegaMsg, State);        [] ->            State = #state{mode             = Mode,                           resolver_module  = ?DEFAULT_NAME_RESOLVER,                           resolver_options = [8, 8, 8]},            tr_MegacoMessage(MegaMsg, State);        [{binary_name_resolver, {Module, Options}}] when atom(Module) ->            State = #state{mode             = Mode,                            resolver_module  = Module,                            resolver_options = Options},            tr_MegacoMessage(MegaMsg, State)    end.tr_transaction(Trans, Mode, Config) ->    case Config of        [native] ->            Trans;        [verify] ->            State = #state{mode = verify},            tr_Transaction(Trans, State);        [] ->            State = #state{mode             = Mode,                           resolver_module  = ?DEFAULT_NAME_RESOLVER,                           resolver_options = [8, 8, 8]},            tr_Transaction(Trans, State);        [{binary_name_resolver, {Module, Options}}] when atom(Module) ->            State = #state{mode             = Mode,                            resolver_module  = Module,                            resolver_options = Options},            tr_Transaction(Trans, State)    end.tr_MegacoMessage(#'MegacoMessage'{authHeader = Auth,                                  mess       = Mess},                 State) ->    ?d("tr_MegacoMessage -> entry with"       "~n   Auth:  ~p"       "~n   Mess:  ~p"       "~n   State: ~p", [Auth, Mess, State]),    #'MegacoMessage'{authHeader = tr_opt_AuthenticationHeader(Auth, State),                     mess       = tr_Message(Mess, State)}.tr_opt_AuthenticationHeader(asn1_NOVALUE, _State) ->    asn1_NOVALUE;tr_opt_AuthenticationHeader(#'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) ->    tr_HEXDIG(SPI, State, 4, 4). % BUGBUG: Mismatch between ASN.1 and ABNFtr_SequenceNum(SN, State) ->    tr_HEXDIG(SN, State, 4, 4).  % BUGBUG: Mismatch between ASN.1 and ABNFtr_AuthData(AuthData, State) ->    tr_HEXDIG(AuthData, State, 12, 32).  % BUGBUG: Mismatch between ASN.1 and ABNFtr_Message(#'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) ->    tr_DIGIT(Version, State, 0, 99).tr_Message_messageBody({Tag, Val}, State) ->    Val2 =         case Tag of            messageError -> tr_ErrorDescriptor(Val, State);            transactions when list(Val) -> [tr_Transaction(T, State) || T <- Val]        end,    {Tag, Val2}.tr_MId({Tag, Val}, State) ->    Val2 =         case Tag of            ip4Address -> tr_IP4Address(Val, State);            ip6Address -> tr_IP6Address(Val, State);            domainName -> tr_DomainName(Val, State);            deviceName -> tr_PathName(Val,   State);            mtpAddress -> tr_mtpAddress(Val, State)        end,    {Tag, Val2}.tr_mtpAddress(MtpAddr, State) ->    tr_OCTET_STRING(MtpAddr, State, 2, 4).  % BUGBUG: Mismatch between ASN.1 and ABNFtr_DomainName(#'DomainName'{name       = Name,                            portNumber = Port},              State) ->    Domain = #'DomainName'{name       = tr_STRING(Name, State), % BUGBUG: Mismatch between ASN.1 and ABNF                           portNumber = tr_opt_portNumber(Port, State)},    {domainName, Domain2} = resolve(mid, {domainName, Domain}, State, valid),    Domain2.tr_IP4Address(#'IP4Address'{address    = [A1, A2, A3, A4],                            portNumber = Port},              State) ->    #'IP4Address'{address    = [tr_V4hex(A1, State),                                tr_V4hex(A2, State),                                tr_V4hex(A3, State),                                tr_V4hex(A4, State)],                  portNumber = tr_opt_portNumber(Port, State)}.tr_V4hex(Val, State) ->    tr_DIGIT(Val, State, 0, 255).tr_IP6Address(_Val, _State) ->    error(ipv6_not_supported). %% BUGBUG: nyitr_PathName(Path, State) ->    %% BUGBUG: ["*"] NAME *("/" / "*"/ ALPHA / DIGIT /"_" / "$" )     %% BUGBUG: ["@" pathDomainName ]    Constraint = fun({deviceName, Item}) -> tr_STRING(Item, State, 1, 64) end,    resolve(mid, {deviceName, Path}, State, Constraint).tr_Transaction({Tag, Val}, State) ->    Val2 =         case Tag of            transactionRequest ->     tr_TransactionRequest(Val, State);            transactionPending ->     tr_TransactionPending(Val, State);            transactionReply ->       tr_TransactionReply(Val, State);            transactionResponseAck -> [tr_TransactionAck(T, State) || T <- Val]        end,    {Tag, Val2}.tr_TransactionAck(#'TransactionAck'{firstAck = First,				    lastAck  = Last},                          State) ->    #'TransactionAck'{firstAck = tr_TransactionId(First, State),		      lastAck  = tr_opt_TransactionId(Last, State)}.tr_opt_TransactionId(asn1_NOVALUE, _State) ->    asn1_NOVALUE;tr_opt_TransactionId(Id, State) ->    tr_TransactionId(Id, State).tr_TransactionId(Id, State) ->    tr_UINT32(Id, State).tr_TransactionRequest(#'TransactionRequest'{transactionId = Id,                                            actions       = Actions},                      State) when list(Actions) ->    #'TransactionRequest'{transactionId = tr_TransactionId(Id, State),                          actions       = [tr_ActionRequest(ActReq, State) || ActReq <- Actions]}.tr_TransactionPending(#'TransactionPending'{transactionId = Id},                      State) ->    #'TransactionPending'{transactionId = tr_TransactionId(Id, State)}.tr_TransactionReply(#'TransactionReply'{transactionId     = Id,                                        immAckRequired    = ImmAck,                                        transactionResult = TransRes},                    State) ->    #'TransactionReply'{transactionId     = tr_TransactionId(Id, State),                        immAckRequired    = tr_opt_null(ImmAck, State),                        transactionResult = tr_TransactionReply_transactionResult(TransRes, State)}.tr_opt_null(asn1_NOVALUE, _State) -> asn1_NOVALUE;tr_opt_null('NULL', _State)       -> 'NULL'.tr_TransactionReply_transactionResult({Tag, Val}, State) ->    Val2 =         case Tag of            transactionError ->                tr_ErrorDescriptor(Val, State);            actionReplies when list(Val), Val /= [] ->                [tr_ActionReply(ActRep, State) || ActRep <- Val]        end,    {Tag, Val2}.tr_opt_ErrorDescriptor(asn1_NOVALUE, _State) ->    asn1_NOVALUE;tr_opt_ErrorDescriptor(ErrDesc, State) ->    tr_ErrorDescriptor(ErrDesc, State).tr_ErrorDescriptor(#'ErrorDescriptor'{errorCode = Code,                                      errorText = Text},                   State) ->    #'ErrorDescriptor'{errorCode = tr_ErrorCode(Code, State),                       errorText = tr_opt_ErrorText(Text, State)}.tr_ErrorCode(Code, State) ->    tr_DIGIT(Code, State, 0, 999).tr_opt_ErrorText(asn1_NOVALUE, _State)  ->    asn1_NOVALUE;tr_opt_ErrorText(Text, State)  ->    tr_QUOTED_STRING(Text, State).tr_ContextID(CtxId, State) ->    case CtxId of        ?megaco_all_context_id    -> ?megaco_all_context_id;        ?megaco_null_context_id   -> ?megaco_null_context_id;        ?megaco_choose_context_id -> ?megaco_choose_context_id;        Int when integer(Int)     -> tr_UINT32(Int, State)    end.tr_ActionRequest(#'ActionRequest'{contextId           = CtxId,                                  contextRequest      = CtxReq,                                  contextAttrAuditReq = CtxAuditReq,                                  commandRequests     = CmdReqList},                 State) ->    #'ActionRequest'{contextId           = tr_ContextID(CtxId, State),                     contextRequest      = tr_opt_ContextRequest(CtxReq, State),                     contextAttrAuditReq = tr_opt_ContextAttrAuditRequest(CtxAuditReq, State),                     commandRequests     = [tr_CommandRequest(CmdReq, State) || CmdReq <- CmdReqList]}.tr_ActionReply(#'ActionReply'{contextId       = CtxId,                              errorDescriptor = ErrDesc,                              contextReply    = CtxRep,                              commandReply    = CmdRepList},               State) ->    CmdRepList2 = [tr_CommandReply(CmdRep, State) || CmdRep <- CmdRepList],    #'ActionReply'{contextId       = tr_ContextID(CtxId, State),                   errorDescriptor = tr_opt_ErrorDescriptor(ErrDesc, State),                   contextReply    = tr_opt_ContextRequest(CtxRep, State),                   commandReply    = CmdRepList2}.tr_opt_ContextRequest(asn1_NOVALUE, _State) ->    asn1_NOVALUE;tr_opt_ContextRequest(CR, State) ->    tr_ContextRequest(CR, State).tr_ContextRequest(#'ContextRequest'{priority    = Prio,				    emergency   = Em,				    topologyReq = TopReqList,				    iepscallind = Ind,				    contextProp = Props},		  State) ->    Prio2 =         case Prio of            asn1_NOVALUE -> asn1_NOVALUE;            _            -> tr_integer(Prio, State, 0, 15)        end,    Em2 =         case Em of            asn1_NOVALUE -> asn1_NOVALUE;            false        -> false;            true         -> true        end,    TopReqList2 =         case TopReqList of            asn1_NOVALUE -> asn1_NOVALUE;            _            -> [tr_TopologyRequest(TopReq, State) ||                                TopReq <- TopReqList]        end,    Ind2 = 	case Ind of

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -