2
%% <year>2000-2008</year>
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
4
%% Copyright Ericsson AB 2000-2009. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
17
%% The Initial Developer of the Original Code is Ericsson AB.
20
21
%%----------------------------------------------------------------------
21
22
%% Purpose: Encode Megaco/H.248 text messages from internal form
1916
1917
synchISDN -> ?SynchISDNToken
1919
enc_DigitMapDescriptor(Val, State)
1920
when is_record(Val, 'DigitMapDescriptor') ->
1920
enc_DigitMapDescriptor(#'DigitMapDescriptor'{digitMapName = asn1_NOVALUE,
1921
digitMapValue = Value} = Val,
1923
when (Value =/= asn1_NOVALUE) ->
1924
case is_empty_DigitMapValue(Value) of
1926
error({invalid_DigitMapDescriptor, Val});
1931
?LBRKT_INDENT(State),
1932
enc_DigitMapValue(Value, ?INC_INDENT(State)),
1933
?RBRKT_INDENT(State)
1936
enc_DigitMapDescriptor(#'DigitMapDescriptor'{digitMapName = Name,
1937
digitMapValue = asn1_NOVALUE},
1939
when (Name =/= asn1_NOVALUE) ->
1922
1941
?DigitMapToken,
1924
enc_DigitMapName(Val#'DigitMapDescriptor'.digitMapName, State),
1925
?LBRKT_INDENT(State),
1926
enc_DigitMapValue(Val#'DigitMapDescriptor'.digitMapValue,
1927
?INC_INDENT(State)),
1928
?RBRKT_INDENT(State)
1943
enc_DigitMapName(Name, State)
1945
enc_DigitMapDescriptor(#'DigitMapDescriptor'{digitMapName = Name,
1946
digitMapValue = Value},
1948
when (Name =/= asn1_NOVALUE) andalso (Value =/= asn1_NOVALUE) ->
1949
case is_empty_DigitMapValue(Value) of
1954
enc_DigitMapName(Name, State)
1960
enc_DigitMapName(Name, State),
1961
?LBRKT_INDENT(State),
1962
enc_DigitMapValue(Value, ?INC_INDENT(State)),
1963
?RBRKT_INDENT(State)
1966
enc_DigitMapDescriptor(BadVal, _State) ->
1967
error({invalid_DigitMapDescriptor, BadVal}).
1931
1969
enc_DigitMapName({'DigitMapName',Val}, State) ->
1932
1970
enc_DigitMapName(Val, State);
1933
1971
enc_DigitMapName(Val, State) ->
1934
1972
enc_Name(Val, State).
1974
is_empty_DigitMapValue(#'DigitMapValue'{startTimer = asn1_NOVALUE,
1975
shortTimer = asn1_NOVALUE,
1976
longTimer = asn1_NOVALUE,
1977
digitMapBody = []}) ->
1979
is_empty_DigitMapValue(#'DigitMapValue'{}) ->
1936
1982
enc_DigitMapValue(Val, State)
1937
1983
when is_record(Val, 'DigitMapValue') ->
2139
2185
enc_Value({'Value',Val}, State) ->
2140
2186
enc_Value(Val, State);
2141
2187
enc_Value(String, _State) ->
2142
case quoted_string_count(String, 0, true) of
2144
[?DQUOTE, String, ?DQUOTE];
2146
[?DQUOTE, String, ?DQUOTE];
2188
case quoted_string_count(String, 0, true, false) of
2190
[?DQUOTE, String, ?DQUOTE];
2192
[?DQUOTE, String, ?DQUOTE];
2151
quoted_string_count([H | T], Count, IsSafe) ->
2197
quoted_string_count([?DoubleQuoteToken | T], 0 = Count, _IsSafe, _MaybeQuoted) ->
2198
%% Already a quoted string. Make sure it ends
2199
quoted_string_count(T, Count + 1, true, true);
2200
quoted_string_count([?DoubleQuoteToken], Count, IsSafe, true = MaybeQuoted) ->
2201
%% An explicitly quoted string
2202
{IsSafe, Count, MaybeQuoted};
2203
quoted_string_count([H | T], Count, IsSafe, MaybeQuoted) ->
2152
2204
case ?classify_char(H) of
2153
safe_char_upper -> quoted_string_count(T, Count + 1, IsSafe);
2154
safe_char -> quoted_string_count(T, Count + 1, IsSafe);
2155
rest_char -> quoted_string_count(T, Count + 1, false);
2156
white_space -> quoted_string_count(T, Count + 1, false);
2205
safe_char_upper -> quoted_string_count(T, Count + 1, IsSafe, MaybeQuoted);
2206
safe_char -> quoted_string_count(T, Count + 1, IsSafe, MaybeQuoted);
2207
rest_char -> quoted_string_count(T, Count + 1, false, MaybeQuoted);
2208
white_space -> quoted_string_count(T, Count + 1, false, MaybeQuoted);
2157
2209
_ -> error({illegal_char, H})
2159
quoted_string_count([], Count, IsSafe) ->
2211
quoted_string_count([], _Count, _IsSafe, true = _MaybeQuoted) ->
2212
error({illegal_char, ?DoubleQuoteToken});
2213
quoted_string_count([], Count, IsSafe, MaybeQuoted) ->
2214
{IsSafe, Count, MaybeQuoted}.
2162
2216
enc_DigitString(String, _State) when is_list(String) ->
2163
2217
[?DQUOTE, String, ?DQUOTE].
2183
2237
enc_QUOTED_STRING(String, _State) when is_list(String) ->
2184
{_IsSafe, Count} = quoted_string_count(String, 0, true),
2185
verify_count(Count, 1, infinity),
2186
[?DQUOTE, String, ?DQUOTE].
2238
case quoted_string_count(String, 0, true, false) of
2239
{_IsSafe, Count, false = _QuotedString} ->
2240
verify_count(Count, 1, infinity),
2241
[?DQUOTE, String, ?DQUOTE];
2242
{_IsSafe, Count, true = _QuotedString} ->
2243
verify_count(Count, 3, infinity), % quotes not included in the count
2188
2248
%% The internal format of hex digits is a list of octets
2189
2249
%% Min and Max means #hexDigits