Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Tapo Origin not being compatible with RFC4566. #42

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/ex_sdp/origin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule ExSDP.Origin do
"""
use Bunch.Access

alias ExSDP.{Address, Utils}
alias ExSDP.{Address}

@enforce_keys [
:session_id,
Expand Down Expand Up @@ -55,7 +55,7 @@ defmodule ExSDP.Origin do
{:ok, t()} | {:error, :invalid_addrtype | :invalid_address}
def parse(origin) do
with {:ok, [username, sess_id, sess_version, nettype, addrtype, address]} <-
Utils.split(origin, " ", 6),
extract_info(origin),
{:ok, addrtype} <- Address.parse_addrtype(addrtype),
{:ok, address} <- Address.parse_address(address) do
# check whether fqdn
Expand All @@ -75,6 +75,23 @@ defmodule ExSDP.Origin do
end
end

@spec extract_info(String.t()) ::
{:error, :too_few_fields} | {:ok, [String.t()]}
def extract_info(origin) do
origin
|> String.split(" ", trim: True)
|> case do
[_username, _sess_id, _sess_version, _nettype, _addrtype, _] = values ->
{:ok, values}

[username, sess_id, sess_version, nettype, _, addrtype, address] ->
{:ok, [username, sess_id, sess_version, nettype, addrtype, address]}

_ ->
{:error, :too_few_fields}
end
end

@doc """
Increments `session_version` field.

Expand Down
Loading