📄 megaco_text_gen_prev3c.hrl
字号:
%% ``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 V3 Megaco/H.248 text messages from internal form%%----------------------------------------------------------------------%% -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(#'MegacoMessage'{authHeader = asn1_NOVALUE, mess = Mess}, State) -> [ ?LWSP, enc_Message(Mess, State) ];enc_MegacoMessage(#'MegacoMessage'{authHeader = Auth, mess = Mess}, State) -> [ ?LWSP, enc_AuthenticationHeader(Auth, State), enc_Message(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(#'DomainName'{portNumber = asn1_NOVALUE, name = Name}, State) -> [ $<, %% BUGBUG: (ALPHA / DIGIT) *63(ALPHA / DIGIT / "-" / ".") enc_STRING(Name, State, 1, 64), $> ];enc_DomainName(#'DomainName'{portNumber = PortNumber, name = Name}, State) -> [ $<, %% BUGBUG: (ALPHA / DIGIT) *63(ALPHA / DIGIT / "-" / ".") enc_STRING(Name, State, 1, 64), $>, $:, enc_portNumber(PortNumber, State) ].enc_IP4Address(#'IP4Address'{portNumber = asn1_NOVALUE, address = [A1, A2, A3, A4]}, State) -> [ $[, enc_V4hex(A1, State), ?DOT, enc_V4hex(A2, State), ?DOT, enc_V4hex(A3, State), ?DOT, enc_V4hex(A4, State), $] ];enc_IP4Address(#'IP4Address'{portNumber = PortNumber, address = [A1, A2, A3, A4]}, State) -> [ $[, enc_V4hex(A1, State), ?DOT, enc_V4hex(A2, State), ?DOT, enc_V4hex(A3, State), ?DOT, enc_V4hex(A4, State), $], $:, enc_portNumber(PortNumber, State) ]. enc_V4hex(Val, State) -> enc_DIGIT(Val, State, 0, 255).enc_IP6Address(#'IP6Address'{portNumber = asn1_NOVALUE, address = Addr}, State) when is_list(Addr) and (length(Addr) == 16) -> [ $[, enc_IP6Address_address(Addr, State), $] ];enc_IP6Address(#'IP6Address'{portNumber = PortNumber, address = Addr}, State) when is_list(Addr) and (length(Addr) == 16) -> [ $[, enc_IP6Address_address(Addr, State), $], $:, enc_portNumber(PortNumber, State) ].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);%% segmentReply ->%% enc_SegmentReply(Val, State); _ -> error({invalid_Transaction_tag, Tag}) end.enc_TransactionResponseAck([Mand], State) -> [ ?ResponseAckToken, ?LBRKT_INDENT(State), [enc_TransactionAck(Mand, State)], ?RBRKT_INDENT(State) ];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 is_binary(Bin) -> [Bin].enc_TransactionRequest_actions(Bin, _State) when is_binary(Bin) -> [Bin]; %% Already encoded...enc_TransactionRequest_actions({'TransactionRequest_actions',Val}, State) -> enc_TransactionRequest_actions(Val, State);enc_TransactionRequest_actions([Mand], State) -> [enc_ActionRequest(Mand, 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 = asn1_NOVALUE, transactionResult = Res%% , %% segmentationNumber = SegNo,%% segmentationComplete = SegCompl }, State) -> [ ?ReplyToken, ?EQUAL, enc_TransactionId(Tid, State), ?LBRKT_INDENT(State), enc_TransactionReply_transactionResult(Res, ?INC_INDENT(State)), ?RBRKT_INDENT(State) ];enc_TransactionReply(#'TransactionReply'{transactionId = Tid, immAckRequired = Req, transactionResult = Res%% ,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -