Sign up here and you can log into the forum!

UMSP Plugin Development

Discussion, features, plugins--everything about zoster's UMSP UPnP Media Server software

Re: UMSP Plugin Development   

Postby mad_ady » Sun Apr 21, 2013 9:20 pm

There were some changes done in order to allow the UMSP_LAN feature. This feature requires properly encoded strings, so & is automatically escaped to & inside URLs (including inside the id).

In theory, the plugins shouldn't add extra encoding when sending the strings, but they should prepare for doubly encoded strings. So - add the following code to your plugins:

Code: Select all
function _pluginMain($prmQuery){
  $queryData = array();
  $prmQuery = htmlspecialchars_decode($prmQuery); //decode the received query, to remove any doubly-decoded strings (such as &page=5)
  parse_str(urldecode($prmQuery), $queryData);
  //do normal processing here
}


Further details here: http://wiki.wdlxtv.com/UMSP_plugin_development#Plugins_that_work_with_UMSP_LAN_feature
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: UMSP Plugin Development   

Postby DJArty » Sun Apr 21, 2013 10:10 pm

Ok, I hope this don't make problem around crossfirmware work of plugins.
(As I remember on 1.02.21 umsp-test.php warning Conversely required from developer to make conversation from & to & ...)
So if make clear "&" in plugin - it was normally work on 1.02 and on 1.05? (or I need hunt for version number > 0.5.2.x?)
Last edited by DJArty on Sun Apr 21, 2013 10:44 pm, edited 1 time in total.
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413; WMU219453404899; WMR161810775332
User avatar
DJArty
Developer
 
Posts: 540
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: UMSP Plugin Development   

Postby mad_ady » Sun Apr 21, 2013 10:31 pm

The recommended way to do it so that it works on older versions as well is to keep the escaping (if you already have it), but add the double unescape code above. Please note that you will have to do double unescape also in proxy calls, otherwise the URLs will be passed as "&page=5" and will be decoded as &page=5 instead of "&page=5".

So, it's safest to unescape rather than remove url_encode.

The only drawback is that if you escape the title it will be displayed escaped on the WDTV's screen (e.g. "Sports & leisure"), but generally plugins didn't escape titles, just URLs/IDs.
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: UMSP Plugin Development   

Postby DJArty » Mon Apr 22, 2013 1:18 am

Ok,tnks, Ill try test myself.
Just strange from wiki:
This means that special characters like &, <, > can't be used unescaped in any UMSP field. The solution is that the UMSP code automatically escapes all fields, so you don't have to.

but example use htmlspesialchars... for $retMediaItems:
'id' => 'umsp://plugins/'.PLUGIN_NAME.'/'.PLUGIN_NAME.'?' . htmlspecialchars($prmQuery), //send back the same id we got
'res' => htmlspecialchars($queryData['url']),


so on 0.5.2.x looks like this will lead to double decode.. May be possible to turn off this automatically escapes in svn version? (And say to developers use "good rule" - escape special chars manually - like in old versions - so all be compatible from ver. to ver.).

P.S. And why htmlspesialchars() but not htmlentities()?.
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413; WMU219453404899; WMR161810775332
User avatar
DJArty
Developer
 
Posts: 540
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: UMSP Plugin Development   

Postby mad_ady » Mon Apr 22, 2013 2:02 am

The example in the wiki is outdated unfortunately :( After you play with it let me know and we'll fix the documentation.

The way development happened on this feature was mostly by trial and failure. At one point I had the UMSP_LAN feature working, but I had to manually run the htmlspecialchars() function and escape everything. This worked, but I also had to escape & inside titles and the WDTV UI wouldn't unescape it (it works just fine with malformed XML), so I got tired and implemented the escaping/unescaping inside the UMSP code.

Now you can send unescaped strings and the following happens (NOTE: this is based on my poor memory - I haven't looked at the code lately, I might have changed the behavior!):
1. If the requester is from 127.0.0.1 (e.g. the internal WDTV DLNA process), then don't do any escaping. The renderer can work with unescaped links, except for IDs. IDs need to be escaped manually.
2. If the requester is from anywhere else, try to send back escaped content for all fields. Escape the field only if needed (if it's already escaped, don't double escape it).

I don't remember why I used htmlspecialchars instead of htmlentities, but if I remember correctly, the only "invalid" characters in XML files are &, > and <, so there was no point in encoding the other characters as well...

Update: After looking through the code, scratching my head and asking a few WTF? it seems it doesn't work like that. I do escape the complete query independent of the requester and I don't use htmlentities or htmlspecialchars, but my own replacement function (_xmlentities). I fail to remember why htmlspecialchars didn't work for me...

The relevant code is in /usr/share/umsp/funcs-upnp.php
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: UMSP Plugin Development   

Postby DJArty » Mon Apr 22, 2013 7:11 am

My laziness caused me to temporarily make something like this:
Code: Select all
function _xmlentities($string) {
return $string;
}

:D
and now all my plugins work normally (70% was broken before because already use &amp; in code and proxys).
Accept to change 127.0.0.1 to $_SERVER['SERVER_ADDR'] and full id description, but not accept this _xmlentities dirty hack, sorry :roll: .
Later need to check this with UMSP_LAN future (not invented yet what exactly UPNP player to use e.g. from android tablet).
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413; WMU219453404899; WMR161810775332
User avatar
DJArty
Developer
 
Posts: 540
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: UMSP Plugin Development   

Postby mad_ady » Mon Apr 22, 2013 9:55 pm

but not accept this _xmlentities dirty hack, sorry


You are free to improve it/fix it and provide a patch with the condition that the fix does not break the UMSP_LAN feature.

However, seeing that it's been a year since I released that feature and it's not been part of any flashable firmware, you can probably take your time. Also, b-rad has been working on and off on a UMSP replacement that will be able to reuse the existing plugins, but it's written to be more efficient. We'll see when he has something available for testing...
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: UMSP Plugin Development   

Postby DJArty » Tue Apr 23, 2013 1:12 am

One more little thing...
Don't know is it UMSP related or global 1.05 future: if just press and hold arrow down in some listing its step by step only 7 lines and after that jump like page down. Is it posible to turn off this "future"? If I need page down i just press "page down", if I need line by line move I just press "down button" (like in 1.02) what for this speedup?
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413; WMU219453404899; WMR161810775332
User avatar
DJArty
Developer
 
Posts: 540
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: UMSP Plugin Development   

Postby mad_ady » Tue Apr 23, 2013 4:16 am

It isn't UMSP related - it's just the way the OSD works. I doubt you can turn it off...
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: UMSP Plugin Development   

Postby DJArty » Sat May 04, 2013 10:10 am

Ok. What I figure out.
I edit my plugins for UMSP 2.0 ready (only 127.0.0.1 fix) and use my "patch" for funcs-upnp.php..
Plugins working good on 1.05.04 -0.5.x.x svn Live and working good on Live Streaming. So Live used like mediaserver for looking UMSP plugins from LiveStreaming (its really quiet mediaserver :) ).
But looks like Live media server don't work normally on software UPnP mediaplayers e.g. from android "UPnP Player" etc.. May by you (mad_ady) use _xmlentities trick for using on software players? Anyway as I say before _xmlentities no need for Streaming work - strange ).
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413; WMU219453404899; WMR161810775332
User avatar
DJArty
Developer
 
Posts: 540
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

PreviousNext

Return to UMSP Media Server

Who is online

Users browsing this forum: No registered users and 2 guests

cron