diff options
Diffstat (limited to 'lib/megaco/src/engine')
-rw-r--r-- | lib/megaco/src/engine/depend.mk | 6 | ||||
-rw-r--r-- | lib/megaco/src/engine/megaco_edist_compress.erl | 25 | ||||
-rw-r--r-- | lib/megaco/src/engine/megaco_encoder.erl | 118 | ||||
-rw-r--r-- | lib/megaco/src/engine/megaco_messenger.erl | 4 | ||||
-rw-r--r-- | lib/megaco/src/engine/megaco_user.erl | 386 | ||||
-rw-r--r-- | lib/megaco/src/engine/modules.mk | 3 |
6 files changed, 519 insertions, 23 deletions
diff --git a/lib/megaco/src/engine/depend.mk b/lib/megaco/src/engine/depend.mk index 96ee337e3a..ba919659db 100644 --- a/lib/megaco/src/engine/depend.mk +++ b/lib/megaco/src/engine/depend.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2003-2016. All Rights Reserved. +# Copyright Ericsson AB 2003-2019. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -78,6 +78,10 @@ $(EBIN)/megaco_transport.$(EMULATOR): megaco_transport.erl $(EBIN)/megaco_user.$(EMULATOR): megaco_user.erl +$(EBIN)/megaco_user.$(EMULATOR): megaco_user.erl \ + ../../include/megaco.hrl \ + ../../include/megaco_message_v1.hrl + $(EBIN)/megaco_user_default.$(EMULATOR): megaco_user_default.erl \ ../../include/megaco.hrl \ ../../include/megaco_message_v1.hrl diff --git a/lib/megaco/src/engine/megaco_edist_compress.erl b/lib/megaco/src/engine/megaco_edist_compress.erl index 987a5ec717..968ab6f16e 100644 --- a/lib/megaco/src/engine/megaco_edist_compress.erl +++ b/lib/megaco/src/engine/megaco_edist_compress.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2016. All Rights Reserved. +%% Copyright Ericsson AB 2007-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -25,10 +25,21 @@ -module(megaco_edist_compress). --export([behaviour_info/1]). +-callback encode(R, Version) -> T when + R :: megaco_encoder:megaco_message() | + megaco_encoder:transaction() | + megaco_encoder:action_reply() | + megaco_encoder:action_request() | + megaco_encoder:command_request(), + Version :: megaco_encoder:protocol_version(), + T :: term(). + +-callback decode(T, Version) -> R when + T :: term(), + Version :: megaco_encoder:protocol_version() | dynamic, + R :: megaco_encoder:megaco_message() | + megaco_encoder:transaction() | + megaco_encoder:action_reply() | + megaco_encoder:action_request() | + megaco_encoder:command_request(). -behaviour_info(callbacks) -> - [{encode,2}, - {decode,2}]; -behaviour_info(_) -> - undefined. diff --git a/lib/megaco/src/engine/megaco_encoder.erl b/lib/megaco/src/engine/megaco_encoder.erl index 7ade349083..dd5a3458fc 100644 --- a/lib/megaco/src/engine/megaco_encoder.erl +++ b/lib/megaco/src/engine/megaco_encoder.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2016. All Rights Reserved. +%% Copyright Ericsson AB 2003-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -25,14 +25,108 @@ -module(megaco_encoder). --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{encode_message, 3}, - {decode_message, 3}, - {decode_mini_message, 3}, - {encode_transaction, 3}, - {encode_action_requests, 3}, - {encode_action_reply, 3}]; -behaviour_info(_) -> - undefined. +-export_type([ + protocol_version/0, + segment_no/0, + megaco_message/0, + transaction/0, + transaction_request/0, + transaction_pending/0, + transaction_reply/0, + transaction_response_ack/0, + transaction_ack/0, + segment_reply/0, + action_request/0, + action_reply/0, + command_request/0, + error_desc/0 + ]). + + +-include("megaco_message_internal.hrl"). + +-type protocol_version() :: integer(). +-type segment_no() :: integer(). +-type megaco_message() :: #'MegacoMessage'{}. +-type transaction() :: {transactionRequest, transaction_request()} | + {transactionPending, transaction_reply()} | + {transactionReply, transaction_pending()} | + {transactionResponseAck, transaction_response_ack()} | + {segmentReply, segment_reply()}. +-type transaction_request() :: #'TransactionRequest'{}. +-type transaction_pending() :: #'TransactionPending'{}. +%% The problem with TransactionReply is that its definition depend +%% on which version of the protocol we are using. As of version 3, +%% it has two more fields. +%% -type transaction_reply() :: #'TransactionReply'{}. +-type transaction_reply() :: {'TransactionReply', _, _} | + {'TransactionReply', _, _, _, _}. +-type transaction_response_ack() :: [transaction_ack()]. +-type transaction_ack() :: #'TransactionAck'{}. +-type segment_reply() :: #'SegmentReply'{}. +%% -type action_request() :: #'ActionRequest'{}. +-type action_request() :: {'ActionRequest', _, _, _, _}. +%% -type action_reply() :: #'ActionReply'{}. +-type action_reply() :: {'ActionReply', _, _, _}. +%% -type command_request() :: #'CommandRequest'{}. +-type command_request() :: {'CommandRequest', _, _, _}. +-type error_desc() :: #'ErrorDescriptor'{}. + +-callback encode_message(EncodingConfig, + Version, + Message) -> {ok, Bin} | Error when + EncodingConfig :: list(), + Version :: protocol_version(), + Message :: megaco_message(), + Bin :: binary(), + Error :: term(). + +-callback decode_message(EncodingConfig, + Version, + Bin) -> {ok, Message} | Error when + EncodingConfig :: list(), + Version :: protocol_version() | dynamic, + Bin :: binary(), + Message :: megaco_message(), + Error :: term(). + +-callback decode_mini_message(EncodingConfig, + Version, + Bin) -> {ok, Message} | Error when + EncodingConfig :: list(), + Version :: protocol_version() | dynamic, + Bin :: binary(), + Message :: megaco_message(), + Error :: term(). + +-callback encode_transaction(EncodingConfig, + Version, + Transaction) -> {ok, Bin} | {error, Reason} when + EncodingConfig :: list(), + Version :: protocol_version(), + Transaction :: transaction(), + Bin :: binary(), + Reason :: not_implemented | term(). + +-callback encode_action_requests(EncodingConfig, + Version, + ARs) -> {ok, Bin} | {error, Reason} when + EncodingConfig :: list(), + Version :: protocol_version(), + ARs :: [action_request()], + Bin :: binary(), + Reason :: not_implemented | term(). + +-callback encode_action_reply(EncodingConfig, + Version, + AR) -> {ok, Bin} | {error, Reason} when + EncodingConfig :: list(), + Version :: protocol_version(), + AR :: action_reply(), + Bin :: binary(), + Reason :: not_implemented | term(). + +-optional_callbacks( + [ + encode_action_reply/3 % Only used if segementation is used + ]). diff --git a/lib/megaco/src/engine/megaco_messenger.erl b/lib/megaco/src/engine/megaco_messenger.erl index 1d462b2140..2a9ecee2a7 100644 --- a/lib/megaco/src/engine/megaco_messenger.erl +++ b/lib/megaco/src/engine/megaco_messenger.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1999-2016. All Rights Reserved. +%% Copyright Ericsson AB 1999-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -1391,7 +1391,7 @@ prepare_request(ConnData, T, Rest, AckList, ReqList, Extra) -> %% don't restart the reply_timer. ConnData2 = ConnData#conn_data{protocol_version = Version}, ?report_trace(ConnData2, - "re-send trans reply", [T | {bytes, Bin}]), + "re-send trans reply", [T, {bytes, Bin}]), case megaco_messenger_misc:send_message(ConnData2, true, Bin) of {ok, _} -> ok; diff --git a/lib/megaco/src/engine/megaco_user.erl b/lib/megaco/src/engine/megaco_user.erl new file mode 100644 index 0000000000..47fb1a119d --- /dev/null +++ b/lib/megaco/src/engine/megaco_user.erl @@ -0,0 +1,386 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2019-2019. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%% +%%------------------------------------------------------------------------- +%% Purpose: Megaco user behaviour module +%% +%% This callback functions are the default! Its possible for the user to +%% provide a arbitrary number of "extra" arguments via the user_args +%% config option. +%% So, for instance, the handle_connect/2 could instead become +%% handle_connect/4 if the user sets the user_args option to [foo, bar]. +%% This means that its impossible to define a proper behaviour. +%% So what we do here is to define a behaviour with the "default interface" +%% (the user_args option has the [] as the default value) and set them +%% all to be optional! +%%------------------------------------------------------------------------- + +-module(megaco_user). + +-export_type([ + receive_handle/0, + conn_handle/0, + megaco_timer/0 + ]). + +-include_lib("megaco/include/megaco.hrl"). +%% -include_lib("megaco/include/megaco_message_v1.hrl"). + +-type receive_handle() :: #megaco_receive_handle{}. +-type conn_handle() :: #megaco_conn_handle{}. +-type megaco_timer() :: infinity | non_neg_integer() | #megaco_incr_timer{}. + +-callback handle_connect(ConnHandle, ProtocolVersion) -> + ok | error | {error, ErrorDescr} when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ErrorDescr :: megaco_encoder:error_desc(). +-callback handle_connect(ConnHandle, ProtocolVersion, Extra) -> + ok | error | {error, ErrorDescr} when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + Extra :: term(), + ErrorDescr :: megaco_encoder:error_desc(). + +-callback handle_disconnect(ConnHandle, ProtocolVersion, Reason) -> + megaco:void() when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + Reason :: term(). + +-callback handle_syntax_error(ReceiveHandle, ProtocolVersion, DefaultED) -> + reply | {reply, ED} | no_reply | {no_reply, ED} when + ReceiveHandle :: receive_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + DefaultED :: megaco_encoder:error_desc(), + ED :: megaco_encoder:error_desc(). +-callback handle_syntax_error(ReceiveHandle, ProtocolVersion, DefaultED, Extra) -> + reply | {reply, ED} | no_reply | {no_reply, ED} when + ReceiveHandle :: receive_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + DefaultED :: megaco_encoder:error_desc(), + ED :: megaco_encoder:error_desc(), + Extra :: term(). + +-callback handle_message_error(ConnHandle, ProtocolVersion, ErrorDescr) -> + megaco:void() when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ErrorDescr :: megaco_encoder:error_desc(). +-callback handle_message_error(ConnHandle, ProtocolVersion, ErrorDescr, Extra) -> + megaco:void() when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ErrorDescr :: megaco_encoder:error_desc(), + Extra :: term(). + +-callback handle_trans_request(ConnHandle, ProtocolVersion, ActionRequests) -> + Pending | Reply | ignore_trans_request when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ActionRequests :: [megaco_encoder:action_request()], + Pending :: {pending, ReqData}, + ReqData :: term(), + Reply :: {AckAction, ActualReply} | + {AckAction, ActualReply, SendOptions}, + AckAction :: discard_ack | + {handle_ack, AckData} | + {handle_pending_ack, AckData} | + {handle_sloppy_ack, AckData}, + ActualReply :: [megaco_encoder:action_reply()] | + megaco_encoder:error_desc(), + AckData :: term(), + SendOptions :: [SendOption], + SendOption :: {reply_timer, megaco_timer()} | + {send_handle, term()} | + {protocol_version, integer()}. +-callback handle_trans_request(ConnHandle, + ProtocolVersion, + ActionRequests, + Extra) -> + Pending | Reply | ignore_trans_request when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ActionRequests :: [megaco_encoder:action_request()], + Extra :: term(), + Pending :: {pending, ReqData}, + ReqData :: term(), + Reply :: {AckAction, ActualReply} | + {AckAction, ActualReply, SendOptions}, + AckAction :: discard_ack | + {handle_ack, AckData} | + {handle_pending_ack, AckData} | + {handle_sloppy_ack, AckData}, + ActualReply :: [megaco_encoder:action_reply()] | + megaco_encoder:error_desc(), + AckData :: term(), + SendOptions :: [SendOption], + SendOption :: {reply_timer, megaco_timer()} | + {send_handle, term()} | + {protocol_version, integer()}. + +-callback handle_trans_long_request(ConnHandle, ProtocolVersion, ReqData) -> + Reply when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ReqData :: term(), + Reply :: {AckAction, ActualReply} | + {AckAction, ActualReply, SendOptions}, + AckAction :: discard_ack | + {handle_ack, AckData} | + {handle_sloppy_ack, AckData}, + ActualReply :: [megaco_encoder:action_reply()] | + megaco_encoder:error_desc(), + AckData :: term(), + SendOptions :: [SendOption], + SendOption :: {reply_timer, megaco_timer()} | + {send_handle, term()} | + {protocol_version, megaco_encoder:protocol_version()}. +-callback handle_trans_long_request(ConnHandle, ProtocolVersion, ReqData, Extra) -> + Reply when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + ReqData :: term(), + Extra :: term(), + Reply :: {AckAction, ActualReply} | + {AckAction, ActualReply, SendOptions}, + AckAction :: discard_ack | + {handle_ack, AckData} | + {handle_sloppy_ack, AckData}, + ActualReply :: [megaco_encoder:action_reply()] | + megaco_encoder:error_desc(), + AckData :: term(), + SendOptions :: [SendOption], + SendOption :: {reply_timer, megaco_timer()} | + {send_handle, term()} | + {protocol_version, megaco_encoder:protocol_version()}. + +-callback handle_trans_reply(ConnHandle, + ProtocolVersion, + UserReply, + ReplyData) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + UserReply :: Success | Failure, + ReplyData :: term(), + Success :: {ok, Result}, + Result :: TransactionResult | SegmentResult, + TransactionResult :: [megaco_encoder:action_reply()], + SegmentResult :: {megaco_encoder:segment_no(), + LastSegment, + [megaco_encoder:action_reply()]}, + Failure :: {error, Reason} | + {error, ReplyNo, Reason}, + Reason :: TransactionReason | + SegmentReason | + UserCancelReason | + SendReason | + OtherReason, + TransactionReason :: megaco_encoder:error_desc(), + SegmentReason :: {megaco_encoder:segment_no(), + LastSegment, + megaco_encoder:error_desc()}, + OtherReason :: timeout | + {segment_timeout, MissingSegments} | + exceeded_recv_pending_limit | term(), + LastSegment :: boolean(), + MissingSegments :: [megaco_encoder:segment_no()], + UserCancelReason :: {user_cancel, ReasonForUserCancel}, + ReasonForUserCancel :: term(), + SendReason :: SendCancelledReason | SendFailedReason, + SendCancelledReason :: {send_message_cancelled, + ReasonForSendCancel}, + ReasonForSendCancel :: term(), + SendFailedReason :: {send_message_failed, ReasonForSendFailure}, + ReasonForSendFailure :: term(), + ReplyNo :: pos_integer(). +-callback handle_trans_reply(ConnHandle, + ProtocolVersion, + UserReply, + ReplyData, + Extra) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + UserReply :: Success | Failure, + ReplyData :: term(), + Extra :: term(), + Success :: {ok, Result}, + Result :: TransactionResult | SegmentResult, + TransactionResult :: [megaco_encoder:action_reply()], + SegmentResult :: {megaco_encoder:segment_no(), + LastSegment, + [megaco_encoder:action_reply()]}, + Failure :: {error, Reason} | + {error, ReplyNo, Reason}, + Reason :: TransactionReason | + SegmentReason | + UserCancelReason | + SendReason | + OtherReason, + TransactionReason :: megaco_encoder:error_desc(), + SegmentReason :: {megaco_encoder:segment_no(), + LastSegment, + megaco_encoder:error_desc()}, + OtherReason :: timeout | + {segment_timeout, MissingSegments} | + exceeded_recv_pending_limit | term(), + LastSegment :: boolean(), + MissingSegments :: [megaco_encoder:segment_no()], + UserCancelReason :: {user_cancel, ReasonForUserCancel}, + ReasonForUserCancel :: term(), + SendReason :: SendCancelledReason | SendFailedReason, + SendCancelledReason :: {send_message_cancelled, + ReasonForSendCancel}, + ReasonForSendCancel :: term(), + SendFailedReason :: {send_message_failed, ReasonForSendFailure}, + ReasonForSendFailure :: term(), + ReplyNo :: pos_integer(). + + +-callback handle_trans_ack(ConnHandle, + ProtocolVersion, + AckStatus, + AckData) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + AckStatus :: ok | {error, Reason}, + AckData :: term(), + Reason :: UserCancelReason | SendReason | OtherReason, + UserCancelReason :: {user_cancel, ReasonForUserCancel}, + ReasonForUserCancel :: term(), + SendReason :: SendCancelledReason | SendFailedReason, + SendCancelledReason :: {send_message_cancelled, ReasonForSendCancel}, + ReasonForSendCancel :: term(), + SendFailedReason :: {send_message_failed, ReasonForSendFailure}, + ReasonForSendFailure :: term(), + OtherReason :: term(). +-callback handle_trans_ack(ConnHandle, + ProtocolVersion, + AckStatus, + AckData, + Extra) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + AckStatus :: ok | {error, Reason}, + AckData :: term(), + Extra :: term(), + Reason :: UserCancelReason | SendReason | OtherReason, + UserCancelReason :: {user_cancel, ReasonForUserCancel}, + ReasonForUserCancel :: term(), + SendReason :: SendCancelledReason | SendFailedReason, + SendCancelledReason :: {send_message_cancelled, ReasonForSendCancel}, + ReasonForSendCancel :: term(), + SendFailedReason :: {send_message_failed, ReasonForSendFailure}, + ReasonForSendFailure :: term(), + OtherReason :: term(). + +-callback handle_unexpected_trans(ConnHandle, ProtocolVersion, Trans) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + Trans :: megaco_encoder:transaction_pending() | + megaco_encoder:transaction_reply() | + megaco_encoder:transaction_response_ack(). +-callback handle_unexpected_trans(ConnHandle, ProtocolVersion, Trans, Extra) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + Trans :: megaco_encoder:transaction_pending() | + megaco_encoder:transaction_reply() | + megaco_encoder:transaction_response_ack(), + Extra :: term(). + +-callback handle_trans_request_abort(ConnHandle, + ProtocolVersion, + TransNo, + Pid) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + TransNo :: integer(), + Pid :: undefined | pid(). +-callback handle_trans_request_abort(ConnHandle, + ProtocolVersion, + TransNo, + Pid, + Extra) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + TransNo :: integer(), + Pid :: undefined | pid(), + Extra :: term(). + +-callback handle_segment_reply(ConnHandle, + ProtocolVersion, + TransNo, + SegNo, + SegCompl) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + TransNo :: integer(), + SegNo :: integer(), + SegCompl :: asn1_NOVALUE | 'NULL'. +-callback handle_segment_reply(ConnHandle, + ProtocolVersion, + TransNo, + SegNo, + SegCompl, + Extra) -> + ok when + ConnHandle :: conn_handle(), + ProtocolVersion :: megaco_encoder:protocol_version(), + TransNo :: integer(), + SegNo :: megaco_encoder:segment_no(), + SegCompl :: asn1_NOVALUE | 'NULL', + Extra :: term(). + +-optional_callbacks( + [ + %% The actual number of arguments to *all* functions, + %% depend of the user_args config option. + handle_connect/2, + handle_connect/3, + handle_disconnect/3, + handle_syntax_error/3, + handle_syntax_error/4, + handle_message_error/3, + handle_message_error/4, + handle_trans_request/3, + handle_trans_request/4, + handle_trans_long_request/3, + handle_trans_long_request/4, + handle_trans_reply/4, + handle_trans_reply/5, + handle_trans_ack/4, + handle_trans_ack/5, + handle_unexpected_trans/3, + handle_unexpected_trans/4, + handle_trans_request_abort/4, + handle_trans_request_abort/5, + handle_segment_reply/5, + handle_segment_reply/6 + ]). diff --git a/lib/megaco/src/engine/modules.mk b/lib/megaco/src/engine/modules.mk index b74a096e40..a7f82c1836 100644 --- a/lib/megaco/src/engine/modules.mk +++ b/lib/megaco/src/engine/modules.mk @@ -2,7 +2,7 @@ # %CopyrightBegin% # -# Copyright Ericsson AB 2001-2016. All Rights Reserved. +# Copyright Ericsson AB 2001-2019. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ BEHAVIOUR_MODULES = \ megaco_edist_compress \ megaco_encoder \ + megaco_user \ megaco_transport MODULES = \ |