@@ -158,8 +158,9 @@ discard block |
||
| 158 | 158 | /* "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" */ |
| 159 | 159 | $http_hdr_soapact = $_SERVER['HTTP_SOAPACTION']; |
| 160 | 160 | $soap_shemas = strpos($http_hdr_soapact, 'urn:schemas-upnp-org:service:ContentDirectory:'); |
| 161 | -if (false === $soap_shemas) |
|
| 161 | +if (false === $soap_shemas) { |
|
| 162 | 162 | return (500); |
| 163 | +} |
|
| 163 | 164 | $soap_service_ver = substr($http_hdr_soapact, ($soap_shemas + 46), 1); |
| 164 | 165 | $soap_service_func = substr($http_hdr_soapact, ($soap_shemas + 48), -1); |
| 165 | 166 | |
@@ -209,8 +210,9 @@ discard block |
||
| 209 | 210 | function upnp_url_encode($url) { |
| 210 | 211 | |
| 211 | 212 | if ('http://' !== substr($url, 0, 7) || |
| 212 | - false === ($url_path_off = strrpos($url, '/', 8))) |
|
| 213 | - return (implode('/', array_map('rawurlencode', explode('/', $url)))); |
|
| 213 | + false === ($url_path_off = strrpos($url, '/', 8))) { |
|
| 214 | + return (implode('/', array_map('rawurlencode', explode('/', $url)))); |
|
| 215 | + } |
|
| 214 | 216 | //return (xml_encode(implode('/', array_map('rawurlencode', explode('/', $url))))); |
| 215 | 217 | //return (xml_encode($url)); |
| 216 | 218 | //return ('<![CDATA[' . xml_encode($url) . ']]'); |
@@ -225,14 +227,18 @@ discard block |
||
| 225 | 227 | function upnp_get_class($file, $def) { |
| 226 | 228 | global $file_class; |
| 227 | 229 | |
| 228 | - if (!isset($file)) |
|
| 229 | - return ($def); |
|
| 230 | + if (!isset($file)) { |
|
| 231 | + return ($def); |
|
| 232 | + } |
|
| 230 | 233 | $dot = strrpos($file, '.'); |
| 231 | - if (false === $dot) |
|
| 232 | - return ($def); |
|
| 234 | + if (false === $dot) { |
|
| 235 | + return ($def); |
|
| 236 | + } |
|
| 233 | 237 | $ext = strtolower(substr($file, ($dot + 1))); |
| 234 | - if (isset($file_class[$ext])) /* Skip unsupported file type. */ |
|
| 238 | + if (isset($file_class[$ext])) { |
|
| 239 | + /* Skip unsupported file type. */ |
|
| 235 | 240 | return ($file_class[$ext]); |
| 241 | + } |
|
| 236 | 242 | |
| 237 | 243 | return ($def); |
| 238 | 244 | } |
@@ -241,15 +247,18 @@ discard block |
||
| 241 | 247 | function get_named_val($name, $buf) { /* ...val_name="value"... */ |
| 242 | 248 | |
| 243 | 249 | $st_off = strpos($buf, $name); |
| 244 | - if (false === $st_off) |
|
| 245 | - return (null); |
|
| 250 | + if (false === $st_off) { |
|
| 251 | + return (null); |
|
| 252 | + } |
|
| 246 | 253 | $st_off += strlen($name); |
| 247 | - if ('="' !== substr($buf, $st_off, 2)) |
|
| 248 | - return (null); |
|
| 254 | + if ('="' !== substr($buf, $st_off, 2)) { |
|
| 255 | + return (null); |
|
| 256 | + } |
|
| 249 | 257 | $st_off += 2; |
| 250 | 258 | $en_off = strpos($buf, '"', $st_off); |
| 251 | - if (false === $en_off) |
|
| 252 | - return (null); |
|
| 259 | + if (false === $en_off) { |
|
| 260 | + return (null); |
|
| 261 | + } |
|
| 253 | 262 | |
| 254 | 263 | return (substr($buf, $st_off, ($en_off - $st_off))); |
| 255 | 264 | } |
@@ -259,15 +268,19 @@ discard block |
||
| 259 | 268 | |
| 260 | 269 | $items_count = 0; |
| 261 | 270 | $fd = fopen($filename, 'r'); |
| 262 | - if (false === $fd) |
|
| 263 | - return ($items_count); |
|
| 271 | + if (false === $fd) { |
|
| 272 | + return ($items_count); |
|
| 273 | + } |
|
| 264 | 274 | while (!feof($fd)) { /* Read the file line by line... */ |
| 265 | 275 | $buffer = trim(fgets($fd)); |
| 266 | - if (false === strpos($buffer, '#EXTINF:')) /* Skip empty/bad lines. */ |
|
| 276 | + if (false === strpos($buffer, '#EXTINF:')) { |
|
| 277 | + /* Skip empty/bad lines. */ |
|
| 267 | 278 | continue; |
| 279 | + } |
|
| 268 | 280 | $entry = trim(fgets($fd)); |
| 269 | - if (false === strpos($entry, '://')) |
|
| 270 | - continue; |
|
| 281 | + if (false === strpos($entry, '://')) { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 271 | 284 | $items_count++; |
| 272 | 285 | } |
| 273 | 286 | fclose($fd); |
@@ -280,11 +293,13 @@ discard block |
||
| 280 | 293 | |
| 281 | 294 | $def = 'video/mpeg'; |
| 282 | 295 | |
| 283 | - if (!isset($filename)) |
|
| 284 | - return ($def); |
|
| 296 | + if (!isset($filename)) { |
|
| 297 | + return ($def); |
|
| 298 | + } |
|
| 285 | 299 | $dot = strrpos($filename, '.'); |
| 286 | - if (false === $dot) |
|
| 287 | - return ($def); |
|
| 300 | + if (false === $dot) { |
|
| 301 | + return ($def); |
|
| 302 | + } |
|
| 288 | 303 | $ext = strtolower(substr($filename, ($dot + 1))); |
| 289 | 304 | if (array_key_exists($ext, $mime_types)) { |
| 290 | 305 | return ($mime_types[$ext]); |
@@ -404,8 +419,9 @@ discard block |
||
| 404 | 419 | $dotdotdir = ''; |
| 405 | 420 | $dirnames = explode('/', $dir); |
| 406 | 421 | for ($di = 0; $di < sizeof($dirnames); $di++) { |
| 407 | - if ('.' === $dirnames[$di]) |
|
| 408 | - continue; |
|
| 422 | + if ('.' === $dirnames[$di]) { |
|
| 423 | + continue; |
|
| 424 | + } |
|
| 409 | 425 | if ('..' === $dirnames[$di]) { |
| 410 | 426 | $dir = ''; |
| 411 | 427 | break; |
@@ -550,16 +566,21 @@ discard block |
||
| 550 | 566 | continue; |
| 551 | 567 | } |
| 552 | 568 | $entry = trim(fgets($fd)); |
| 553 | - if (false === strpos($entry, '://')) |
|
| 554 | - continue; |
|
| 569 | + if (false === strpos($entry, '://')) { |
|
| 570 | + continue; |
|
| 571 | + } |
|
| 555 | 572 | /* Ok, item matched and may be returned. */ |
| 556 | 573 | $TotalMatches++; |
| 557 | 574 | if (0 < $StartingIndex && |
| 558 | - $TotalMatches < $StartingIndex) |
|
| 559 | - continue; /* Skip first items. */ |
|
| 575 | + $TotalMatches < $StartingIndex) { |
|
| 576 | + continue; |
|
| 577 | + } |
|
| 578 | + /* Skip first items. */ |
|
| 560 | 579 | if (0 < $RequestedCount && |
| 561 | - $NumberReturned >= $RequestedCount) |
|
| 562 | - continue; /* Do not add more than requested. */ |
|
| 580 | + $NumberReturned >= $RequestedCount) { |
|
| 581 | + continue; |
|
| 582 | + } |
|
| 583 | + /* Do not add more than requested. */ |
|
| 563 | 584 | $NumberReturned++; |
| 564 | 585 | /* Add item to result. */ |
| 565 | 586 | $title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1)))); |
@@ -605,16 +626,22 @@ discard block |
||
| 605 | 626 | foreach ($entries as $entry) { |
| 606 | 627 | $filename = $basedir.$dir.$entry; |
| 607 | 628 | if ('.' === substr($entry, 0, 1) || |
| 608 | - !is_dir($filename)) /* Skip files. */ |
|
| 629 | + !is_dir($filename)) { |
|
| 630 | + /* Skip files. */ |
|
| 609 | 631 | continue; |
| 632 | + } |
|
| 610 | 633 | /* Ok, item matched and may be returned. */ |
| 611 | 634 | $TotalMatches++; |
| 612 | 635 | if (0 < $StartingIndex && |
| 613 | - $TotalMatches < $StartingIndex) |
|
| 614 | - continue; /* Skip first items. */ |
|
| 636 | + $TotalMatches < $StartingIndex) { |
|
| 637 | + continue; |
|
| 638 | + } |
|
| 639 | + /* Skip first items. */ |
|
| 615 | 640 | if (0 < $RequestedCount && |
| 616 | - $NumberReturned >= $RequestedCount) |
|
| 617 | - continue; /* Do not add more than requested. */ |
|
| 641 | + $NumberReturned >= $RequestedCount) { |
|
| 642 | + continue; |
|
| 643 | + } |
|
| 644 | + /* Do not add more than requested. */ |
|
| 618 | 645 | $NumberReturned++; |
| 619 | 646 | /* Add item to result. */ |
| 620 | 647 | if (is_writable($filename)) { |
@@ -634,19 +661,27 @@ discard block |
||
| 634 | 661 | /* Add files to play list. */ |
| 635 | 662 | foreach ($entries as $entry) { |
| 636 | 663 | $filename = $basedir.$dir.$entry; |
| 637 | - if (is_dir($filename)) /* Skip dirs. */ |
|
| 664 | + if (is_dir($filename)) { |
|
| 665 | + /* Skip dirs. */ |
|
| 638 | 666 | continue; |
| 667 | + } |
|
| 639 | 668 | $iclass = upnp_get_class($entry, null); |
| 640 | - if (null === $iclass) /* Skip unsupported file type. */ |
|
| 669 | + if (null === $iclass) { |
|
| 670 | + /* Skip unsupported file type. */ |
|
| 641 | 671 | continue; |
| 672 | + } |
|
| 642 | 673 | /* Ok, item matched and may be returned. */ |
| 643 | 674 | $TotalMatches++; |
| 644 | 675 | if (0 < $StartingIndex && |
| 645 | - $TotalMatches < $StartingIndex) |
|
| 646 | - continue; /* Skip first items. */ |
|
| 676 | + $TotalMatches < $StartingIndex) { |
|
| 677 | + continue; |
|
| 678 | + } |
|
| 679 | + /* Skip first items. */ |
|
| 647 | 680 | if (0 < $RequestedCount && |
| 648 | - $NumberReturned >= $RequestedCount) |
|
| 649 | - continue; /* Do not add more than requested. */ |
|
| 681 | + $NumberReturned >= $RequestedCount) { |
|
| 682 | + continue; |
|
| 683 | + } |
|
| 684 | + /* Do not add more than requested. */ |
|
| 650 | 685 | $NumberReturned++; |
| 651 | 686 | /* Add item to result. */ |
| 652 | 687 | if (is_writable($filename)) { |
@@ -805,38 +840,46 @@ discard block |
||
| 805 | 840 | |
| 806 | 841 | function get_resp_tag_name($sxml) { |
| 807 | 842 | $tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:'); |
| 808 | - if (false === $tag_st) |
|
| 809 | - return (false); |
|
| 843 | + if (false === $tag_st) { |
|
| 844 | + return (false); |
|
| 845 | + } |
|
| 810 | 846 | $tag_st += 25; |
| 811 | 847 | $tag_end = strpos($sxml, '>', $tag_st); |
| 812 | - if (false === $tag_end) |
|
| 813 | - return (false); |
|
| 848 | + if (false === $tag_end) { |
|
| 849 | + return (false); |
|
| 850 | + } |
|
| 814 | 851 | return (substr($sxml, $tag_st, ($tag_end - $tag_st))); |
| 815 | 852 | } |
| 816 | 853 | |
| 817 | 854 | function get_tag_ns($req, $tag) { |
| 818 | 855 | $rreq = strrev($req); |
| 819 | 856 | $ns_st = strpos($rreq, strrev(":$tag>")); |
| 820 | - if (false === $ns_st) |
|
| 821 | - return (false); |
|
| 857 | + if (false === $ns_st) { |
|
| 858 | + return (false); |
|
| 859 | + } |
|
| 822 | 860 | $ns_st += (strlen($tag) + 2); |
| 823 | 861 | $ns_end = strpos($rreq, '/<', $ns_st); |
| 824 | - if (false === $ns_end) |
|
| 825 | - return (false); |
|
| 862 | + if (false === $ns_end) { |
|
| 863 | + return (false); |
|
| 864 | + } |
|
| 826 | 865 | return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st)))); |
| 827 | 866 | } |
| 828 | 867 | |
| 829 | 868 | function tag_ns_replace($req, $sxml, $tag, $ns = false) { |
| 830 | - if (false === $tag) |
|
| 831 | - return ($sxml); |
|
| 832 | - if (false === $ns) |
|
| 833 | - $ns = get_tag_ns($req, $tag); |
|
| 834 | - if (false === $ns) |
|
| 835 | - return ($sxml); |
|
| 869 | + if (false === $tag) { |
|
| 870 | + return ($sxml); |
|
| 871 | + } |
|
| 872 | + if (false === $ns) { |
|
| 873 | + $ns = get_tag_ns($req, $tag); |
|
| 874 | + } |
|
| 875 | + if (false === $ns) { |
|
| 876 | + return ($sxml); |
|
| 877 | + } |
|
| 836 | 878 | while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) { |
| 837 | 879 | $tag_end = strpos($sxml, '>', $tag_st); |
| 838 | - if (false === $tag_end) |
|
| 839 | - return ($sxml); |
|
| 880 | + if (false === $tag_end) { |
|
| 881 | + return ($sxml); |
|
| 882 | + } |
|
| 840 | 883 | $old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st)); |
| 841 | 884 | $new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data); |
| 842 | 885 | $sxml = str_replace($old_tag_data, $new_tag_data, $sxml); |