@@ -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); |
@@ -281,11 +294,13 @@ discard block |
||
| 281 | 294 | |
| 282 | 295 | $def = 'video/mpeg'; |
| 283 | 296 | |
| 284 | - if (!isset($filename)) |
|
| 285 | - return ($def); |
|
| 297 | + if (!isset($filename)) { |
|
| 298 | + return ($def); |
|
| 299 | + } |
|
| 286 | 300 | $dot = strrpos($filename, '.'); |
| 287 | - if (false === $dot) |
|
| 288 | - return ($def); |
|
| 301 | + if (false === $dot) { |
|
| 302 | + return ($def); |
|
| 303 | + } |
|
| 289 | 304 | $ext = strtolower(substr($filename, ($dot + 1))); |
| 290 | 305 | if (array_key_exists($ext, $mime_types)) { |
| 291 | 306 | return ($mime_types[$ext]); |
@@ -405,8 +420,9 @@ discard block |
||
| 405 | 420 | $dotdotdir = ''; |
| 406 | 421 | $dirnames = explode('/', $dir); |
| 407 | 422 | for ($di = 0; $di < sizeof($dirnames); $di++) { |
| 408 | - if ('.' === $dirnames[$di]) |
|
| 409 | - continue; |
|
| 423 | + if ('.' === $dirnames[$di]) { |
|
| 424 | + continue; |
|
| 425 | + } |
|
| 410 | 426 | if ('..' === $dirnames[$di]) { |
| 411 | 427 | $dir = ''; |
| 412 | 428 | break; |
@@ -551,16 +567,21 @@ discard block |
||
| 551 | 567 | continue; |
| 552 | 568 | } |
| 553 | 569 | $entry = trim(fgets($fd)); |
| 554 | - if (false === strpos($entry, '://')) |
|
| 555 | - continue; |
|
| 570 | + if (false === strpos($entry, '://')) { |
|
| 571 | + continue; |
|
| 572 | + } |
|
| 556 | 573 | /* Ok, item matched and may be returned. */ |
| 557 | 574 | $TotalMatches++; |
| 558 | 575 | if (0 < $StartingIndex && |
| 559 | - $TotalMatches < $StartingIndex) |
|
| 560 | - continue; /* Skip first items. */ |
|
| 576 | + $TotalMatches < $StartingIndex) { |
|
| 577 | + continue; |
|
| 578 | + } |
|
| 579 | + /* Skip first items. */ |
|
| 561 | 580 | if (0 < $RequestedCount && |
| 562 | - $NumberReturned >= $RequestedCount) |
|
| 563 | - continue; /* Do not add more than requested. */ |
|
| 581 | + $NumberReturned >= $RequestedCount) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 584 | + /* Do not add more than requested. */ |
|
| 564 | 585 | $NumberReturned++; |
| 565 | 586 | /* Add item to result. */ |
| 566 | 587 | $title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1)))); |
@@ -606,16 +627,22 @@ discard block |
||
| 606 | 627 | foreach ($entries as $entry) { |
| 607 | 628 | $filename = $basedir.$dir.$entry; |
| 608 | 629 | if ('.' === substr($entry, 0, 1) || |
| 609 | - !is_dir($filename)) /* Skip files. */ |
|
| 630 | + !is_dir($filename)) { |
|
| 631 | + /* Skip files. */ |
|
| 610 | 632 | continue; |
| 633 | + } |
|
| 611 | 634 | /* Ok, item matched and may be returned. */ |
| 612 | 635 | $TotalMatches++; |
| 613 | 636 | if (0 < $StartingIndex && |
| 614 | - $TotalMatches < $StartingIndex) |
|
| 615 | - continue; /* Skip first items. */ |
|
| 637 | + $TotalMatches < $StartingIndex) { |
|
| 638 | + continue; |
|
| 639 | + } |
|
| 640 | + /* Skip first items. */ |
|
| 616 | 641 | if (0 < $RequestedCount && |
| 617 | - $NumberReturned >= $RequestedCount) |
|
| 618 | - continue; /* Do not add more than requested. */ |
|
| 642 | + $NumberReturned >= $RequestedCount) { |
|
| 643 | + continue; |
|
| 644 | + } |
|
| 645 | + /* Do not add more than requested. */ |
|
| 619 | 646 | $NumberReturned++; |
| 620 | 647 | /* Add item to result. */ |
| 621 | 648 | if (is_writable($filename)) { |
@@ -635,19 +662,27 @@ discard block |
||
| 635 | 662 | /* Add files to play list. */ |
| 636 | 663 | foreach ($entries as $entry) { |
| 637 | 664 | $filename = $basedir.$dir.$entry; |
| 638 | - if (is_dir($filename)) /* Skip dirs. */ |
|
| 665 | + if (is_dir($filename)) { |
|
| 666 | + /* Skip dirs. */ |
|
| 639 | 667 | continue; |
| 668 | + } |
|
| 640 | 669 | $iclass = upnp_get_class($entry, null); |
| 641 | - if (null === $iclass) /* Skip unsupported file type. */ |
|
| 670 | + if (null === $iclass) { |
|
| 671 | + /* Skip unsupported file type. */ |
|
| 642 | 672 | continue; |
| 673 | + } |
|
| 643 | 674 | /* Ok, item matched and may be returned. */ |
| 644 | 675 | $TotalMatches++; |
| 645 | 676 | if (0 < $StartingIndex && |
| 646 | - $TotalMatches < $StartingIndex) |
|
| 647 | - continue; /* Skip first items. */ |
|
| 677 | + $TotalMatches < $StartingIndex) { |
|
| 678 | + continue; |
|
| 679 | + } |
|
| 680 | + /* Skip first items. */ |
|
| 648 | 681 | if (0 < $RequestedCount && |
| 649 | - $NumberReturned >= $RequestedCount) |
|
| 650 | - continue; /* Do not add more than requested. */ |
|
| 682 | + $NumberReturned >= $RequestedCount) { |
|
| 683 | + continue; |
|
| 684 | + } |
|
| 685 | + /* Do not add more than requested. */ |
|
| 651 | 686 | $NumberReturned++; |
| 652 | 687 | /* Add item to result. */ |
| 653 | 688 | if (is_writable($filename)) { |
@@ -806,38 +841,46 @@ discard block |
||
| 806 | 841 | |
| 807 | 842 | function get_resp_tag_name($sxml) { |
| 808 | 843 | $tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:'); |
| 809 | - if (false === $tag_st) |
|
| 810 | - return (false); |
|
| 844 | + if (false === $tag_st) { |
|
| 845 | + return (false); |
|
| 846 | + } |
|
| 811 | 847 | $tag_st += 25; |
| 812 | 848 | $tag_end = strpos($sxml, '>', $tag_st); |
| 813 | - if (false === $tag_end) |
|
| 814 | - return (false); |
|
| 849 | + if (false === $tag_end) { |
|
| 850 | + return (false); |
|
| 851 | + } |
|
| 815 | 852 | return (substr($sxml, $tag_st, ($tag_end - $tag_st))); |
| 816 | 853 | } |
| 817 | 854 | |
| 818 | 855 | function get_tag_ns($req, $tag) { |
| 819 | 856 | $rreq = strrev($req); |
| 820 | 857 | $ns_st = strpos($rreq, strrev(":$tag>")); |
| 821 | - if (false === $ns_st) |
|
| 822 | - return (false); |
|
| 858 | + if (false === $ns_st) { |
|
| 859 | + return (false); |
|
| 860 | + } |
|
| 823 | 861 | $ns_st += (strlen($tag) + 2); |
| 824 | 862 | $ns_end = strpos($rreq, '/<', $ns_st); |
| 825 | - if (false === $ns_end) |
|
| 826 | - return (false); |
|
| 863 | + if (false === $ns_end) { |
|
| 864 | + return (false); |
|
| 865 | + } |
|
| 827 | 866 | return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st)))); |
| 828 | 867 | } |
| 829 | 868 | |
| 830 | 869 | function tag_ns_replace($req, $sxml, $tag, $ns = false) { |
| 831 | - if (false === $tag) |
|
| 832 | - return ($sxml); |
|
| 833 | - if (false === $ns) |
|
| 834 | - $ns = get_tag_ns($req, $tag); |
|
| 835 | - if (false === $ns) |
|
| 836 | - return ($sxml); |
|
| 870 | + if (false === $tag) { |
|
| 871 | + return ($sxml); |
|
| 872 | + } |
|
| 873 | + if (false === $ns) { |
|
| 874 | + $ns = get_tag_ns($req, $tag); |
|
| 875 | + } |
|
| 876 | + if (false === $ns) { |
|
| 877 | + return ($sxml); |
|
| 878 | + } |
|
| 837 | 879 | while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) { |
| 838 | 880 | $tag_end = strpos($sxml, '>', $tag_st); |
| 839 | - if (false === $tag_end) |
|
| 840 | - return ($sxml); |
|
| 881 | + if (false === $tag_end) { |
|
| 882 | + return ($sxml); |
|
| 883 | + } |
|
| 841 | 884 | $old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st)); |
| 842 | 885 | $new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data); |
| 843 | 886 | $sxml = str_replace($old_tag_data, $new_tag_data, $sxml); |