Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    Senior Member
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    242

    Problem with adding a Page Handler...

    I am trying to add a page handler, but I run into trouble with one and do not get why...
    In the Plugin.pm I put:
    Code:
    sub initPlugin {
        my $class = shift;
    
        ....
    
        Slim::Web::Pages->addPageFunction("^device.state", \&Plugins::PluginName::stateHandler);
    
    }
    In the PluginName.pm there is writte:
    Code:
    sub stateHandler {
    	my ($client, $params, undef, undef, $response) = @_;
    
            $log->debug("Here we are");
    	$response->header("Content-Type" => "text/json; charset=utf-8");
    
    	my $body = '';
    	
    
    	return \$body;
    }
    The log message ist not shown in the log-file nor anywhere else...

    When I change the addPageFunction from "device.state" to "device.log" the handler is called and the message shows up...

    Is there a problem with the filename handed to the addPageFunction?
    LMS-7.9@solaris. 2x Radio, 2x Duet, 1x Chromecast v1, ShairTunes, 1x Philips Hue System

  2. #2
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    15,321
    The first arg is a regexp - "." is a pattern matching char - did you mean any char or should it be escaped like "^device\.state"

  3. #3
    Senior Member
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    242
    Quote Originally Posted by bpa View Post
    The first arg is a regexp - "." is a pattern matching char - did you mean any char or should it be escaped like "^device\.state"
    Okay, now I start to learn something ;o)
    I thought the first arg is more or less string without any other specialties...

    Well, actually I thought of typing http://servername.xx/device.state to call the handler...
    So the escape should work. But why does the same regexp arg with log (device.log) work and with state (device.state) not?
    LMS-7.9@solaris. 2x Radio, 2x Duet, 1x Chromecast v1, ShairTunes, 1x Philips Hue System

  4. #4
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    15,321
    Not sure - whenever I try to use a LMS function I haven't used before I look for other examples - so scanning LMS I find these examples
    Code:
    Slim::Web::Pages->addPageFunction(qr/^update_firmware\.(?:htm|xml)/,\&update_firmware);
    and
    Code:
     
    Slim::Web::Pages->addPageFunction("musicmagic_mix.html" => \&musicmagic_mix);
    So clearly the first args can be a string or a regexp.

    My Perl is a bit vague but I think the "^" makes your string a regexp but if you leave it out the function treats the string as simple match.

  5. #5
    Senior Member
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    242
    Quote Originally Posted by bpa View Post
    Not sure - whenever I try to use a LMS function I haven't used before I look for other examples - so scanning LMS I find these examples
    Code:
    Slim::Web::Pages->addPageFunction(qr/^update_firmware\.(?:htm|xml)/,\&update_firmware);
    and
    Code:
     
    Slim::Web::Pages->addPageFunction("musicmagic_mix.html" => \&musicmagic_mix);
    So clearly the first args can be a string or a regexp.

    My Perl is a bit vague but I think the "^" makes your string a regexp but if you leave it out the function treats the string as simple match.
    I found he same two examles or say the same kind of them...
    Up to now I think it is also an issue with the line ending as the HTTP.pm file reacts on certain ending... But I did not find the place where it reacts on a totally user-defined string/regexp...
    LMS-7.9@solaris. 2x Radio, 2x Duet, 1x Chromecast v1, ShairTunes, 1x Philips Hue System

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    15,321
    Quote Originally Posted by chincheta0815 View Post
    I found he same two examles or say the same kind of them...
    Up to now I think it is also an issue with the line ending as the HTTP.pm file reacts on certain ending... But I did not find the place where it reacts on a totally user-defined string/regexp...
    The use of the regexp as a key to a hash seems to be unusual. I suspect you may have problems if you use the LMS web server for page types other that those which it currently serves. IIRC the cometd stuff is JSON based - I'd look to that part of LMS for examples that might work.

    Note:
    Using addRawFunction might be more appropriate for your use.

    edit 2:

    If you are using a non standard suffix - I wonder whether you should add it to a custom-types.conf file. "log", "html" and "xml" are defined in types.conf. second thoughts - ignore this - wrong "direction"
    Last edited by bpa; 2017-10-10 at 14:56.

  7. #7
    Senior Member
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    242
    Quote Originally Posted by bpa View Post
    The use of the regexp as a key to a hash seems to be unusual. I suspect you may have problems if you use the LMS web server for page types other that those which it currently serves. IIRC the cometd stuff is JSON based - I'd look to that part of LMS for examples that might work.

    Note:
    Using addRawFunction might be more appropriate for your use.

    edit 2:

    If you are using a non standard suffix - I wonder whether you should add it to a custom-types.conf file. "log", "html" and "xml" are defined in types.conf. second thoughts - ignore this - wrong "direction"
    That's what I feared...
    I do not know if writing a RawFunction makes sense for simply using a specific file suffix and displaying file contents as plain text...

    I think for now I will use a standard file suffix, although not what I thought of...
    Best would be to have a kind of "custom-types.conf", but that seems to be something for the audio files...
    LMS-7.9@solaris. 2x Radio, 2x Duet, 1x Chromecast v1, ShairTunes, 1x Philips Hue System

  8. #8
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    15,321
    Quote Originally Posted by chincheta0815 View Post
    That's what I feared...
    I do not know if writing a RawFunction makes sense for simply using a specific file suffix and displaying file contents as plain text...

    I think for now I will use a standard file suffix, although not what I thought of...
    Best would be to have a kind of "custom-types.conf", but that seems to be something for the audio files...
    I think the problem is that you want LMS to be a general purpose web server - LMS is not general purpose.
    The regexp expressions for the all the pagehandlers are probably in an array and for each page requested LMS - tries ALL the regexps for all page handler to find a match that has "Highest" precedence. I suspect another page handler handles your pages request before yours. Pages request do not just disappear - something had handled it.

    It is not normal for a plugin to have a top level LMS URL - they are usually long strings specific to the plugin so that no conflict can arise with standard LMS functions. I think you may have conflict with another LMS function or else LMS has decided it is an "invalid" URL.

    types.conf and custom-types.conf are using when processing pages retrieved by LMS so many are audio but not all . Many pages requests are playlists or webpages /JSON to be parsed to find data such as metadata and as such are not audio. It is genral pursope for input to faciliatate "typing" a page from suffix and/or MIME.

  9. #9
    Senior Member
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    242
    Quote Originally Posted by bpa View Post
    I think the problem is that you want LMS to be a general purpose web server - LMS is not general purpose.
    Yes and no.
    I just want a function showing the content of some files. Easy as I thought it would work (you know the story) I now agree with you concerning the general purpose web server...


    Quote Originally Posted by bpa View Post
    It is not normal for a plugin to have a top level LMS URL - they are usually long strings specific to the plugin so that no conflict can arise with standard LMS functions. I think you may have conflict with another LMS function or else LMS has decided it is an "invalid" URL.
    This is actually something I will change anyways... Something more specific to a plugin url like "plugins/settings/pluginsname/>filename>"...

    Maybe I try it again with the longer filename, just to get to know if it would work then and how LMS treats those requests.
    But then I think it would make more sense to wrap the file content into a filehandler with code syntax hightlighting or so... This is more HTML I think and easier than rewriting LMS routines ind RawFunctions...
    LMS-7.9@solaris. 2x Radio, 2x Duet, 1x Chromecast v1, ShairTunes, 1x Philips Hue System

  10. #10
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    15,321
    Just did quick check the Web/HTTP.pm generateHTTPResponse code which does processing before getPageFunction.

    Do you get a 404 in reply to the "device.state" (note no ^) ?
    What is the MIME type of the page request ?

    It does look like types.conf definiitons are used to validate a page os if suffix is not defined - request will be rejected by 404.

    Code:
    .
    .
    .
    	my $path = $params->{"path"};
    	my $type = Slim::Music::Info::typeFromSuffix($path, 'htm');
    
    	# lots of people need this
    	my $contentType = $params->{'Content-Type'} = $Slim::Music::Info::types{$type};
    
    	if ( Slim::Web::Pages->isRawDownload($path) ) {
    		$contentType = 'application/octet-stream';
    	}
    	
    	if ( $path =~ /(?:music|video|image)\/[0-9a-f]+\/(?:download|cover)/ || $path =~ /^imageproxy\// ) {
    		# Avoid generating templates for download URLs
    		$contentType = 'application/octet-stream';
    	}
    
    	# setup our defaults
    	$response->content_type($contentType);
    	#$response->expires(0);
    
    	# short-circuit if we don't have a content type to respond to.
    	unless (defined($contentType)) {
    
    		return 0 if $path =~ /status/i;
    
    		$response->code(RC_NOT_FOUND);
    
    		$body = filltemplatefile('html/errors/404.html', $params);
    
    		return prepareResponseForSending(
    			$client,
    			$params,
    			$body,
    			$httpClient,
    			$response,
    		);
    	}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •