/lib/snmp/src/compile/snmpc_misc.hrl

https://github.com/dustin/otp · Erlang · 74 lines · 54 code · 2 blank · 18 comment · 2 complexity · 464e207a8c6856e2ecd22b5b30d8effd MD5 · raw file

  1. %%
  2. %% %CopyrightBegin%
  3. %%
  4. %% Copyright Ericsson AB 2004-2009. All Rights Reserved.
  5. %%
  6. %% The contents of this file are subject to the Erlang Public License,
  7. %% Version 1.1, (the "License"); you may not use this file except in
  8. %% compliance with the License. You should have received a copy of the
  9. %% Erlang Public License along with this software. If not, it can be
  10. %% retrieved online at http://www.erlang.org/.
  11. %%
  12. %% Software distributed under the License is distributed on an "AS IS"
  13. %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  14. %% the License for the specific language governing rights and limitations
  15. %% under the License.
  16. %%
  17. %% %CopyrightEnd%
  18. %%
  19. -define(verify_format_version(VFV_Ver1,VFV_Ver2),
  20. fun(VFV_V,VFV_V) ->
  21. ok;
  22. (VFV_V1,VFV_V2) when is_list(VFV_V1) andalso is_list(VFV_V2) ->
  23. Toks1 = string:tokens(VFV_V1, [$.]),
  24. [Major1|_] = case (catch [list_to_integer(I) || I <- Toks1]) of
  25. Nums when is_list(Nums) ->
  26. Nums;
  27. _ ->
  28. {error, {invalid_version_format, VFV_V1}}
  29. end,
  30. Toks2 = string:tokens(VFV_V2, [$.]),
  31. case (catch [list_to_integer(I) || I <- Toks2]) of
  32. [Major1|_] ->
  33. ok;
  34. [_Major2|_] ->
  35. {error, wrong_version};
  36. _ ->
  37. {error, {invalid_version_format, VFV_V2}}
  38. end;
  39. (VFV_V1,VFV_V2) ->
  40. {error, {invalid_format, VFV_V1, VFV_V2}}
  41. end(VFV_Ver1,VFV_Ver2)).
  42. -define(read_mib(RM_FN),
  43. RM_Bin = case file:read_file(RM_FN) of
  44. {ok, RM_B} ->
  45. RM_B;
  46. RM_Error ->
  47. throw(RM_Error)
  48. end,
  49. RM_Mib = case (catch binary_to_term(RM_Bin)) of
  50. RM_M when is_record(RM_M, mib) ->
  51. RM_M;
  52. _ ->
  53. throw({error, bad_mib_format})
  54. end,
  55. #mib{mib_format_version = RM_V1} = #mib{},
  56. case RM_Mib of
  57. #mib{mib_format_version = RM_V2,
  58. misc = RM_X} when is_integer(RM_X) ->
  59. case (catch ?verify_format_version(RM_V1, RM_V2)) of
  60. ok ->
  61. {ok, RM_Mib#mib{misc = []}};
  62. _ ->
  63. throw({error, {wrong_mib_format_version_tag, RM_V2}})
  64. end;
  65. #mib{mib_format_version = RM_V2} ->
  66. case (catch ?verify_format_version(RM_V1, RM_V2)) of
  67. ok ->
  68. {ok, RM_Mib#mib{misc = []}};
  69. _ ->
  70. throw({error, {wrong_mib_format_version_tag, RM_V2}})
  71. end
  72. end).