This repository was archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
support PPP devices with slightly different XML schema #2
Open
dch
wants to merge
3
commits into
benoitc:master
Choose a base branch
from
skunkwerks:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ ebin | |
deps | ||
.DS_Store | ||
erl_crash.dump | ||
.rebar/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ discover1(Sock, MSearch, Timeout, Tries) -> | |
ok = gen_udp:send(Sock, "239.255.255.250", 1900, MSearch), | ||
receive | ||
{udp, _Sock, Ip, _Port, Packet} -> | ||
case get_location(Packet) of | ||
case get_location(http_bin, Packet) of | ||
error -> | ||
discover1(Sock, MSearch, Timeout, Tries-1); | ||
Location -> | ||
|
@@ -177,14 +177,18 @@ get_myip(Ip) -> | |
[{_, {MyIp, _}}|_] = nat_upnp_util:route(Ip), | ||
inet_parse:ntoa(MyIp). | ||
|
||
get_location(Raw) -> | ||
case erlang:decode_packet(httph_bin, Raw, []) of | ||
get_location(Type, Raw) -> | ||
case erlang:decode_packet(Type, Raw, []) of | ||
{ok, {http_response, _, _Code, _Resp}, Rest} -> | ||
get_location(httph_bin, Rest); | ||
{ok, {http_error, _}, Rest} -> | ||
get_location(Rest); | ||
get_location(httph_bin, Rest); | ||
{ok, {http_header, _, 'Location', _, Location}, _Rest} -> | ||
Location; | ||
% {ok, {http_header, _, 'LOCATION', _, Location}, _Rest} -> | ||
% Location; | ||
{ok, {http_header, _, _H, _, _V}, Rest} -> | ||
get_location(Rest); | ||
get_location(httph_bin, Rest); | ||
_ -> | ||
error | ||
end. | ||
|
@@ -211,7 +215,7 @@ get_wan_device(D, RootUrl) -> | |
{ok, D1} -> | ||
get_connection_device(D1, RootUrl); | ||
_ -> | ||
{erro, no_wan_device} | ||
{error, no_wan_device} | ||
end. | ||
|
||
get_connection_device(D, RootUrl) -> | ||
|
@@ -225,26 +229,37 @@ get_connection_device(D, RootUrl) -> | |
|
||
|
||
get_connection_url(D, RootUrl) -> | ||
case get_service(D, "urn:schemas-upnp-org:service:WANIPConnection:1") of | ||
case get_service_url(D, "urn:schemas-upnp-org:service:WANIPConnection:1", RootUrl) of | ||
Resp = {ok, _} -> Resp; | ||
{error, no_service_url} -> | ||
case get_service_url(D, "urn:schemas-upnp-org:service:WANPPPConnection:1", RootUrl) of | ||
Resp = {ok, _} -> Resp; | ||
Resp = {error, _} -> Resp | ||
end; | ||
Resp = {error, _} -> Resp | ||
end. | ||
|
||
get_service_url(D, Urn, RootUrl) -> | ||
case get_service(D, Urn) of | ||
{ok, S} -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there may well be a better approach than nested case here - any better suggestion? |
||
Url = extract_txt(xmerl_xpath:string("controlURL/text()", | ||
S)), | ||
case split(RootUrl, "://") of | ||
[Scheme, Rest] -> | ||
case split(Rest, "/") of | ||
[NetLoc| _] -> | ||
CtlUrl = Scheme ++ "://" ++ NetLoc ++ Url, | ||
{ok, CtlUrl}; | ||
_Else -> | ||
{error, invalid_control_url} | ||
end; | ||
_Else -> | ||
Url = extract_txt(xmerl_xpath:string("controlURL/text()", S)), | ||
get_control_url(Url, RootUrl); | ||
_ -> | ||
{error, no_service_url} | ||
end. | ||
|
||
get_control_url(Url, RootUrl) -> | ||
case split(RootUrl, "://") of | ||
[Scheme, Rest] -> | ||
case split(Rest, "/") of | ||
[NetLoc| _] -> | ||
CtlUrl = Scheme ++ "://" ++ NetLoc ++ Url, | ||
{ok, CtlUrl}; | ||
_Else -> | ||
{error, invalid_control_url} | ||
|
||
end; | ||
_ -> | ||
{error, no_wanipconnection} | ||
_Else -> | ||
{error, invalid_control_url} | ||
end. | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm why do you start by reading the full response? Sounds like it will break other parsing but I may be mistaken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add some tests for each device type I think.
Main reason for this is that just doing httph_bin as before doesn't work. I did wonder if your devices have a different setup and so my change breaks yours, but I figured at least a simple patch to get started.
The "router" is a typically crappy TGv588 (Thomson) router, this firmware is sadly very common across Europe.