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

📄 megaco_text_gen_v3.hrl

📁 OTP是开放电信平台的简称
💻 HRL
📖 第 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: Encode V2 Megaco/H.248 text messages from internal form%% The following was changed:%% - MuxType (Nx64kToken)%% - auditItem (terminationAudit)%% - serviceChangeParm (auditItem)%% %% The following was added:%% - All IndAud stuff%%----------------------------------------------------------------------%% -define(d(F,A), io:format("~w:" ++ F ++ "~n", [?MODULE|A])).	       -define(META_ENC(Type, Item), Item) .%% -define(META_ENC(Type, Item), megaco_meta_package:encode(text, Type, Item)).%% -define(META_DEC(Type, Item), megaco_meta_package:decode(text, Type, Item)).enc_MegacoMessage(Val) ->    State = ?INIT_INDENT,    enc_MegacoMessage(Val, State).enc_MegacoMessage(Val, State)  when record(Val, 'MegacoMessage') ->    [     ?LWSP,     enc_AuthenticationHeader(Val#'MegacoMessage'.authHeader, State),     enc_Message(Val#'MegacoMessage'.mess, State)    ].%% Note that encoding the transaction this way%% make the message look a bit strange.enc_Transaction(Val) ->    State = ?INIT_INDENT,    enc_Transaction(Val, State).%% Note that encoding the action request's this way%% make the message look a bit strange.enc_ActionRequests(Val) ->    State = ?INIT_INDENT,    enc_TransactionRequest_actions(Val, State).%% Note that encoding the action request this way%% make the message look a bit strange.enc_ActionRequest(Val) ->    State = ?INIT_INDENT,    enc_ActionRequest(Val, State).enc_CommandRequest(Val) ->    State = ?INIT_INDENT,    enc_CommandRequest(Val, State).enc_ActionReply(Val) ->    State = ?INIT_INDENT,    enc_ActionReply(Val, State).enc_AuthenticationHeader(asn1_NOVALUE, _State) ->    [];enc_AuthenticationHeader(Val, State)  when record(Val, 'AuthenticationHeader') ->    [     ?AuthToken,     ?EQUAL,     enc_SecurityParmIndex(Val#'AuthenticationHeader'.secParmIndex, State),     ?COLON,     enc_SequenceNum(Val#'AuthenticationHeader'.seqNum, State),     ?COLON,     enc_AuthData(Val#'AuthenticationHeader'.ad, State),     ?SEP_INDENT(State)    ].enc_SecurityParmIndex({'SecurityParmIndex',Val}, State) ->    enc_SecurityParmIndex(Val, State);enc_SecurityParmIndex(Val, State) ->    [     "0x",     enc_HEXDIG(Val, State, 8, 8)    ].enc_SequenceNum({'SequenceNum',Val}, State) ->    enc_SequenceNum(Val, State);enc_SequenceNum(Val, State) ->    [     "0x",     enc_HEXDIG(Val, State, 8, 8)    ].enc_AuthData({'AuthData',Val}, State) ->    enc_AuthData(Val, State);enc_AuthData(Val, State) ->    [     "0x",     enc_HEXDIG(Val, State, 24, 64)  %% OTP-4710    ].enc_Message(Val, State)  when record(Val, 'Message') ->    [     ?MegacopToken,     ?SLASH,     enc_version(Val#'Message'.version, State),     ?SEP,     enc_MId(Val#'Message'.mId, State),     ?SEP_INDENT(State),     enc_Message_messageBody(Val#'Message'.messageBody, State)    ].enc_version(Val, State) when integer(Val), Val >= 0 ->    enc_DIGIT(Val, State, 0, 99).enc_Message_messageBody({'Message_messageBody',Val}, State) ->    enc_Message_messageBody(Val, State);enc_Message_messageBody({Tag, Val}, State) ->    case Tag of	messageError ->	    enc_ErrorDescriptor(Val, State);	transactions ->	    enc_Message_messageBody_transactions(Val, State);	_ ->	    error({invalid_messageBody_tag, Tag})    end.enc_Message_messageBody_transactions({'Message_messageBody_transactions',Val}, 				     State) ->    enc_Message_messageBody_transactions(Val, State);enc_Message_messageBody_transactions(Val, State)  when list(Val), Val /= []->    [enc_Transaction(T, State) || T <- Val].enc_MId({'MId',Val}, State) ->    enc_MId(Val, State);enc_MId({Tag, Val}, State) ->    case Tag of	ip4Address ->	    enc_IP4Address(Val, State);	ip6Address ->	    enc_IP6Address(Val, State);	domainName ->	    enc_DomainName(Val, State);	deviceName ->	    enc_PathName(Val, State);	mtpAddress ->	    enc_mtpAddress(Val, State);	_ ->	    error({invalid_MId_tag, Tag})    end.enc_mtpAddress(Val, State) ->    [     ?MtpToken,     ?LBRKT,     enc_OCTET_STRING(Val, State, 2, 4),     ?RBRKT    ].enc_DomainName(Val, State)  when record(Val, 'DomainName') ->    [     $<,     %% BUGBUG: (ALPHA / DIGIT) *63(ALPHA / DIGIT / "-" / ".")     enc_STRING(Val#'DomainName'.name, State, 1, 64),     $>,     case Val#'DomainName'.portNumber of	 asn1_NOVALUE ->	     [];	 PortNumber ->	     [	      $:,	      enc_portNumber(PortNumber, State)	     ]     end    ].enc_IP4Address(Val, State)  when record(Val, 'IP4Address') ->    [A1, A2, A3, A4] = Val#'IP4Address'.address,    [     $[,     enc_V4hex(A1, State),     ?DOT,     enc_V4hex(A2, State),     ?DOT,     enc_V4hex(A3, State),     ?DOT,     enc_V4hex(A4, State),         $],     case Val#'IP4Address'.portNumber of	 asn1_NOVALUE ->	     [];	 PortNumber ->	     [	      $:,	      enc_portNumber(PortNumber, State)	     ]     end    ].enc_V4hex(Val, State) ->    enc_DIGIT(Val, State, 0, 255).enc_IP6Address(Val, State)  when record(Val, 'IP6Address'),       list(Val#'IP6Address'.address),       length(Val#'IP6Address'.address) == 16 ->    [     $[,     enc_IP6Address_address(Val#'IP6Address'.address, State),     $],     case Val#'IP6Address'.portNumber of	 asn1_NOVALUE ->	     [];	 PortNumber ->	     [	      $:,	      enc_portNumber(PortNumber, State)	     ]     end    ].enc_IP6Address_address([0, 0|Addr], State) ->    enc_IP6Address_address2(Addr, 1, false, true, State);enc_IP6Address_address(Addr, State) ->    enc_IP6Address_address2(Addr, 0, false, false, State).enc_IP6Address_address2([0,0], 0, _Padding, _First, _State) ->    [$0];enc_IP6Address_address2([0,0], PadN, false, true, _State) when PadN > 0 ->    [$:, $:]; % Padding from the beginning (all zero's)enc_IP6Address_address2([0,0], PadN, false, false, _State) when PadN > 0 ->    [$:]; % Padding in the middle or endenc_IP6Address_address2([0,0], _, true, _First, _State) ->    [$0];enc_IP6Address_address2([N1,N2], 0, _Padding, _First, State) ->    [enc_hex4([N1, N2], State)];enc_IP6Address_address2([N1,N2], 1, _Padding, _First, State) ->    [$0, $:, enc_hex4([N1, N2], State)];enc_IP6Address_address2([N1,N2], PadN, false, true, State) when PadN > 1 ->    [$:, $:, enc_hex4([N1, N2], State)];enc_IP6Address_address2([N1,N2], PadN, false, false, State) when PadN > 1 ->    [$:, enc_hex4([N1, N2], State)];enc_IP6Address_address2([N1,N2], _PadN, true, _First, State) ->    [enc_hex4([N1, N2], State)];enc_IP6Address_address2([0, 0|Ns], PadN, false, First, State) ->    enc_IP6Address_address2(Ns, PadN+1, false, First, State);enc_IP6Address_address2([0, 0|Ns], _PadN, true, _First, State) ->    [     $0,     $:,     enc_IP6Address_address2(Ns, 0, true, false, State)    ];enc_IP6Address_address2([N1, N2|Ns], 0, Padded, _First, State) ->    [     enc_hex4([N1, N2], State),     $:,     enc_IP6Address_address2(Ns, 0, Padded, false, State)    ];enc_IP6Address_address2([N1, N2|Ns], 1, Padded, _First, State) ->    [     $0,     $:,     enc_hex4([N1, N2], State),     $:,     enc_IP6Address_address2(Ns, 0, Padded, false, State)    ];enc_IP6Address_address2([N1, N2|Ns], PadN, false, true, State) when PadN > 1 ->    %% Padding from the beginning    [     $:,     $:,     enc_hex4([N1, N2], State),     $:,     enc_IP6Address_address2(Ns, 0, true, false, State)    ];enc_IP6Address_address2([N1, N2|Ns], PadN, false, false, State)   when PadN > 1 ->    [     $:,  %% The other ':' has already added     enc_hex4([N1, N2], State),     $:,     enc_IP6Address_address2(Ns, 0, true, false, State)    ];enc_IP6Address_address2([N1, N2|Ns], _PadN, true, _First, State) ->    [     enc_hex4([N1, N2], State),     $:,     enc_IP6Address_address2(Ns, 0, true, false, State)    ].enc_hex4([0,0], _State) ->    $0;enc_hex4([0,N], _State) ->    hex(N);enc_hex4([N1, N2], _State) when N2 =< 15 ->    [hex(N1), $0, hex(N2)];enc_hex4([N1, N2], _State) ->    [hex(N1), hex(N2)].enc_PathName({'PathName',Val}, State) ->    enc_PathName(Val, State);enc_PathName(Val, State) ->    %% BUGBUG: ["*"] NAME *("/" / "*"/ ALPHA / DIGIT /"_" / "$" )     %% BUGBUG: ["@" pathDomainName ]    enc_STRING(Val, State, 1, 64).enc_Transaction(Bin, _State) when binary(Bin) ->    [Bin]; %% Already encoded...enc_Transaction({'Transaction',Val}, State) ->    enc_Transaction(Val, State);enc_Transaction({Tag, Val}, State) ->    case Tag of	transactionRequest ->	    enc_TransactionRequest(Val, State);	transactionPending ->	    enc_TransactionPending(Val, State);	transactionReply ->	    enc_TransactionReply(Val, State);	transactionResponseAck ->	    enc_TransactionResponseAck(Val, State);	_ ->	    error({invalid_Transaction_tag, Tag})    end.enc_TransactionResponseAck([Mand | Opt], State) ->    [     ?ResponseAckToken,     ?LBRKT_INDENT(State),     [enc_TransactionAck(Mand, State) |      [[?COMMA_INDENT(State), enc_TransactionAck(Val, State)] || Val <- Opt]],     ?RBRKT_INDENT(State)    ].    enc_TransactionAck(Val, State)  when record(Val, 'TransactionAck') ->    [     enc_TransactionId(Val#'TransactionAck'.firstAck, ?INC_INDENT(State)),     case Val#'TransactionAck'.lastAck of	 asn1_NOVALUE ->	     [];	 LastAck ->	     ["-",enc_TransactionId(LastAck, State)]     end    ].enc_TransactionId({'TransactionId',Val}, State) ->    enc_TransactionId(Val, State);enc_TransactionId(Val, State) ->    enc_UINT32(Val, State).enc_TransactionRequest(#'TransactionRequest'{transactionId = Tid,					     actions       = Acts}, State) ->    [     ?TransToken,     ?EQUAL,     enc_TransactionId(Tid, State),     ?LBRKT_INDENT(State),     enc_TransactionRequest_actions(Acts, ?INC_INDENT(State)),     ?RBRKT_INDENT(State)    ];enc_TransactionRequest(Bin, _State) when binary(Bin) ->    [Bin].enc_TransactionRequest_actions(Bin, _State) when binary(Bin) ->    [Bin]; %% Already encoded...enc_TransactionRequest_actions({'TransactionRequest_actions',Val}, State) ->    enc_TransactionRequest_actions(Val, State);enc_TransactionRequest_actions([Mand | Opt], State) ->    [enc_ActionRequest(Mand, State) |     [[?COMMA_INDENT(State), enc_ActionRequest(Val, State)] || Val <- Opt]].enc_TransactionPending(#'TransactionPending'{transactionId = Tid}, State) ->    [?PendingToken,     ?EQUAL,     enc_TransactionId(Tid, State),     ?LBRKT_INDENT(State),     ?RBRKT_INDENT(State)    ];enc_TransactionPending(Bin, _State) when binary(Bin) ->    [Bin].enc_TransactionReply(#'TransactionReply'{transactionId     = Tid,					 immAckRequired    = Req,					 transactionResult = Res}, State) ->    [     ?ReplyToken,     ?EQUAL,     enc_TransactionId(Tid, State),     ?LBRKT_INDENT(State),     enc_immAckRequired(Req, State),     enc_TransactionReply_transactionResult(Res, ?INC_INDENT(State)),     ?RBRKT_INDENT(State)    ];enc_TransactionReply(Bin, _State) when binary(Bin) ->    [Bin].enc_immAckRequired(Val, State) ->    case Val of	asn1_NOVALUE -> 	    [];	'NULL'       -> 	    [?ImmAckRequiredToken, ?COMMA_INDENT(?INC_INDENT(State))]    end.enc_TransactionReply_transactionResult({'TransactionReply_transactionResult',					Val}, State) ->    enc_TransactionReply_transactionResult(Val, State);enc_TransactionReply_transactionResult({Tag, Val}, State) ->    case Tag of	transactionError ->	    enc_ErrorDescriptor(Val, State);	actionReplies ->	    enc_TransactionReply_transactionResult_actionReplies(Val, State);	_ ->	    error({invalid_TransactionReply_transactionResult_tag, Tag})     end.enc_TransactionReply_transactionResult_actionReplies({'TransactionReply_transactionResult_actionReplies',Val}, State) ->    enc_TransactionReply_transactionResult_actionReplies(Val, State);enc_TransactionReply_transactionResult_actionReplies([Mand | Opt], State) ->    [enc_ActionReply(Mand, State),     [[?COMMA_INDENT(State), enc_ActionReply(Val, State)] || Val <- Opt]].enc_ErrorDescriptor(Val, State)  when record(Val, 'ErrorDescriptor') ->    [     ?ErrorToken,     ?EQUAL,     enc_ErrorCode(Val#'ErrorDescriptor'.errorCode, State),

⌨️ 快捷键说明

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