floof/mix.exs
2022-11-28 00:54:25 +01:00

107 lines
3.3 KiB
Elixir

defmodule Floof.MixProject do
use Mix.Project
def project do
[
app: :floof,
version: "0.1.0",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
compilers: [:asn1] ++ Mix.compilers(),
asn1_options: [:per],
deps: deps(),
package: package()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:asn1, :crypto, :logger],
mod: {Floof.Application, []},
env: [
# listen_port cam be set to `nil` to disable to server-socket listener
listen_port: 2540,
# listen_opts can be used to specify e.g. `[ip: {192,168,0,133}]` a specific interface IP
listen_opts: [],
# upstreams have structure `{host, port}` or `{host}` (port defaults to 2540)
upstreams: [],
# markers have the structure {bool(), {:RelativeDistinguishedName, oid-as-list(), value()}}
# all of the markers marked with 'true' should be included in each message to-be-processed
# and none of the markers marked with 'false' should be included. the same holds for attrs.
markers: [],
attrs: [],
# these are the markers of form {:RelativeDistinguishedName, oid-as-list(), value()}
# which get added to all processed messages
set_markers: [],
# a list of functions which can be used to further filter packets
# (by returning nil if unwanted) and modify them
extra_filters: [],
# file locations
# the spool dir saves messages in-transit, and is used to prevent RAM OOM
spool_dir: "mock_spool",
# the sessions file is used for persistence of session data across restarts
sessions_file: "mock_sessions.dets"
]
]
end
defp package do
[
maintainers: ["Alain Zscheile"],
licenses: ["Apache-2.0"]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:enacl, "~> 1.0.0"},
{:logger_file_backend, "~> 0.0.13"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
# source: https://github.com/processone/ejabberd/blob/441eca75b23ecc3fd2ae35655d23061fb28cdefa/mix.exs
defmodule Mix.Tasks.Compile.Asn1 do
use Mix.Task
alias Mix.Compilers.Erlang
@recursive true
@manifest ".compile.asn1"
def run(args) do
{opts, _, _} = OptionParser.parse(args, switches: [force: :boolean])
project = Mix.Project.config()
source_paths = project[:asn1_paths] || ["asn1"]
dest_paths = project[:asn1_target] || ["src"]
mappings = Enum.zip(source_paths, dest_paths)
options = project[:asn1_options] || []
force =
case opts[:force] do
true -> [force: true]
_ -> [force: false]
end
Erlang.compile(manifest(), mappings, :asn1, :erl, force, fn
input, output ->
File.mkdir(Path.dirname(output))
options = options ++ [:noobj, outdir: Erlang.to_erl_file(Path.dirname(output))]
case :asn1ct.compile(Erlang.to_erl_file(input), options) do
:ok -> {:ok, [], []}
:error -> {:error, [], []}
end
end)
end
def manifests, do: [manifest()]
defp manifest, do: Path.join(Mix.Project.manifest_path(), @manifest)
def clean, do: Erlang.clean(manifest())
end