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