From 0de7157093d399bbf3ee00c7711dbac3642c03cd Mon Sep 17 00:00:00 2001 From: borisneubert Date: Sat, 11 Jul 2015 08:26:21 +0000 Subject: [PATCH] 02_HTTPSRV: support tabletui (Forum #37232) git-svn-id: https://svn.fhem.de/fhem/trunk@8933 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/02_HTTPSRV.pm | 49 +++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index c93d6f15b..ee0bbd6be 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 02_HTTPSRV: support tabletui (Forum #37232) - bugfix: SOMFY: Only send stop if position changed improved timing for position update fix typos (go-my instead of go_my) diff --git a/fhem/FHEM/02_HTTPSRV.pm b/fhem/FHEM/02_HTTPSRV.pm index eb44b3316..85174d87c 100644 --- a/fhem/FHEM/02_HTTPSRV.pm +++ b/fhem/FHEM/02_HTTPSRV.pm @@ -13,16 +13,27 @@ use warnings; use vars qw(%data); use HttpUtils; +my $HTTPSRV_matchlink = "^\/?(([^\/]*(\/[^\/]+)*)\/?)\$"; + ######################### sub HTTPSRV_addExtension($$$$) { my ($name,$func,$link,$friendlyname)= @_; - - my $url = "/$link"; - Log3 $name, 3, "Registering HTTPSRV $name for URL $url..."; + + # do some cleanup on link/url + # link should really show the link as expected to be called (might include trailing / but no leading /) + # url should only contain the directory piece with a leading / but no trailing / + # $1 is complete link without potentially leading / + # $2 is complete link without potentially leading / and trailing / + $link =~ /$HTTPSRV_matchlink/; + + my $url = "/".$2; + my $modlink = $1; + + Log3 $name, 3, "Registering HTTPSRV $name for URL $url and assigned link $modlink ..."; $data{FWEXT}{$url}{deviceName}= $name; $data{FWEXT}{$url}{FUNC} = $func; - $data{FWEXT}{$url}{LINK} = $link; + $data{FWEXT}{$url}{LINK} = $modlink; $data{FWEXT}{$url}{NAME} = $friendlyname; } @@ -30,7 +41,15 @@ sub HTTPSRV_removeExtension($) { my ($link)= @_; - my $url = "/$link"; + # do some cleanup on link/url + # link should really show the link as expected to be called (might include trailing / but no leading /) + # url should only contain the directory piece with a leading / but no trailing / + # $1 is complete link without potentially leading / + # $2 is complete link without potentially leading / and trailing / + $link =~ /$HTTPSRV_matchlink/; + + my $url = "/".$2; + my $name= $data{FWEXT}{$url}{deviceName}; Log3 $name, 3, "Unregistering HTTPSRV $name for URL $url..."; delete $data{FWEXT}{$url}; @@ -70,6 +89,8 @@ HTTPSRV_Define($$) { $hash->{fhem}{directory}= $directory; $hash->{fhem}{friendlyname}= $friendlyname; + Log3 $name, 3, "$name: new ext defined infix:$infix: dir:$directory:"; + HTTPSRV_addExtension($name, "HTTPSRV_CGI", $infix, $friendlyname); $hash->{STATE} = $name; @@ -114,17 +135,26 @@ sub HTTPSRV_CGI() { my ($request) = @_; # /$infix/filename +# Debug "request= $request"; + + # Match request first without trailing / in the link part if($request =~ m,^(/[^/]+)(/(.*)?)?$,) { my $link= $1; my $filename= $3; my $name; + # If FWEXT not found for this make a second try with a trailing slash in the link part + if(! $data{FWEXT}{$link}) { + $link = $link."/"; + return("text/plain; charset=utf-8", "Illegal request: $request") if(! $data{FWEXT}{$link}); + } + # get device name - $name= $data{FWEXT}{$link}{deviceName} if($data{FWEXT}{$link}); + $name= $data{FWEXT}{$link}{deviceName}; - #Debug "link= $link"; - #Debug "filename= $filename"; - #Debug "name= $name"; +# Debug "link= $link"; +# Debug "filename= $filename"; +# Debug "name= $name"; # return error if no such device return("text/plain; charset=utf-8", "No HTTPSRV device for $link") unless($name); @@ -146,6 +176,7 @@ sub HTTPSRV_CGI() { my $directory= $defs{$name}{fhem}{directory}; $filename= "$directory/$filename"; + #Debug "read filename= $filename"; my @contents; if(open(INPUTFILE, $filename)) { binmode(INPUTFILE);