@@ -111,8 +111,9 @@ discard block |
||
| 111 | 111 | /* "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" */ |
| 112 | 112 | $http_hdr_soapact = $_SERVER['HTTP_SOAPACTION']; |
| 113 | 113 | $soap_shemas = strpos($http_hdr_soapact, 'urn:schemas-upnp-org:service:ContentDirectory:'); |
| 114 | -if (false === $soap_shemas) |
|
| 114 | +if (false === $soap_shemas) { |
|
| 115 | 115 | return (500); |
| 116 | +} |
|
| 116 | 117 | $soap_service_ver = substr($http_hdr_soapact, ($soap_shemas + 46), 1); |
| 117 | 118 | $soap_service_func = substr($http_hdr_soapact, ($soap_shemas + 48), -1); |
| 118 | 119 | |
@@ -162,8 +163,9 @@ discard block |
||
| 162 | 163 | function upnp_url_encode($url) { |
| 163 | 164 | |
| 164 | 165 | if ('http://' !== substr($url, 0, 7) || |
| 165 | - false === ($url_path_off = strrpos($url, '/', 8))) |
|
| 166 | - return (implode('/', array_map('rawurlencode', explode('/', $url)))); |
|
| 166 | + false === ($url_path_off = strrpos($url, '/', 8))) { |
|
| 167 | + return (implode('/', array_map('rawurlencode', explode('/', $url)))); |
|
| 168 | + } |
|
| 167 | 169 | //return (xml_encode(implode('/', array_map('rawurlencode', explode('/', $url))))); |
| 168 | 170 | //return (xml_encode($url)); |
| 169 | 171 | //return ('<![CDATA[' . xml_encode($url) . ']]'); |
@@ -178,14 +180,18 @@ discard block |
||
| 178 | 180 | function upnp_get_class($file, $def) { |
| 179 | 181 | global $file_class; |
| 180 | 182 | |
| 181 | - if (!isset($file)) |
|
| 182 | - return ($def); |
|
| 183 | + if (!isset($file)) { |
|
| 184 | + return ($def); |
|
| 185 | + } |
|
| 183 | 186 | $dot = strrpos($file, '.'); |
| 184 | - if (false === $dot) |
|
| 185 | - return ($def); |
|
| 187 | + if (false === $dot) { |
|
| 188 | + return ($def); |
|
| 189 | + } |
|
| 186 | 190 | $ext = strtolower(substr($file, ($dot + 1))); |
| 187 | - if (isset($file_class[$ext])) /* Skip unsupported file type. */ |
|
| 191 | + if (isset($file_class[$ext])) { |
|
| 192 | + /* Skip unsupported file type. */ |
|
| 188 | 193 | return ($file_class[$ext]); |
| 194 | + } |
|
| 189 | 195 | |
| 190 | 196 | return ($def); |
| 191 | 197 | } |
@@ -194,15 +200,18 @@ discard block |
||
| 194 | 200 | function get_named_val($name, $buf) { /* ...val_name="value"... */ |
| 195 | 201 | |
| 196 | 202 | $st_off = strpos($buf, $name); |
| 197 | - if (false === $st_off) |
|
| 198 | - return (null); |
|
| 203 | + if (false === $st_off) { |
|
| 204 | + return (null); |
|
| 205 | + } |
|
| 199 | 206 | $st_off += strlen($name); |
| 200 | - if ('="' !== substr($buf, $st_off, 2)) |
|
| 201 | - return (null); |
|
| 207 | + if ('="' !== substr($buf, $st_off, 2)) { |
|
| 208 | + return (null); |
|
| 209 | + } |
|
| 202 | 210 | $st_off += 2; |
| 203 | 211 | $en_off = strpos($buf, '"', $st_off); |
| 204 | - if (false === $en_off) |
|
| 205 | - return (null); |
|
| 212 | + if (false === $en_off) { |
|
| 213 | + return (null); |
|
| 214 | + } |
|
| 206 | 215 | |
| 207 | 216 | return (substr($buf, $st_off, ($en_off - $st_off))); |
| 208 | 217 | } |
@@ -212,15 +221,19 @@ discard block |
||
| 212 | 221 | |
| 213 | 222 | $items_count = 0; |
| 214 | 223 | $fd = fopen($filename, 'r'); |
| 215 | - if (false === $fd) |
|
| 216 | - return ($items_count); |
|
| 224 | + if (false === $fd) { |
|
| 225 | + return ($items_count); |
|
| 226 | + } |
|
| 217 | 227 | while (!feof($fd)) { /* Read the file line by line... */ |
| 218 | 228 | $buffer = trim(fgets($fd)); |
| 219 | - if (false === strpos($buffer, '#EXTINF:')) /* Skip empty/bad lines. */ |
|
| 229 | + if (false === strpos($buffer, '#EXTINF:')) { |
|
| 230 | + /* Skip empty/bad lines. */ |
|
| 220 | 231 | continue; |
| 232 | + } |
|
| 221 | 233 | $entry = trim(fgets($fd)); |
| 222 | - if (false === strpos($entry, '://')) |
|
| 223 | - continue; |
|
| 234 | + if (false === strpos($entry, '://')) { |
|
| 235 | + continue; |
|
| 236 | + } |
|
| 224 | 237 | $items_count ++; |
| 225 | 238 | } |
| 226 | 239 | fclose ($fd); |
@@ -277,11 +290,13 @@ discard block |
||
| 277 | 290 | 'ts' => 'video/MP2T', |
| 278 | 291 | 'webm' => 'video/webm', |
| 279 | 292 | ); |
| 280 | - if (!isset($filename)) |
|
| 281 | - return ($def); |
|
| 293 | + if (!isset($filename)) { |
|
| 294 | + return ($def); |
|
| 295 | + } |
|
| 282 | 296 | $dot = strrpos($filename, '.'); |
| 283 | - if (false === $dot) |
|
| 284 | - return ($def); |
|
| 297 | + if (false === $dot) { |
|
| 298 | + return ($def); |
|
| 299 | + } |
|
| 285 | 300 | $ext = strtolower(substr($filename, ($dot + 1))); |
| 286 | 301 | if (array_key_exists($ext, $mime_types)) { |
| 287 | 302 | return ($mime_types[$ext]); |
@@ -401,8 +416,9 @@ discard block |
||
| 401 | 416 | $dotdotdir = ''; |
| 402 | 417 | $dirnames = explode('/', $dir); |
| 403 | 418 | for ($di = 0; $di < sizeof($dirnames); $di ++) { |
| 404 | - if ('.' === $dirnames[$di]) |
|
| 405 | - continue; |
|
| 419 | + if ('.' === $dirnames[$di]) { |
|
| 420 | + continue; |
|
| 421 | + } |
|
| 406 | 422 | if ('..' === $dirnames[$di]) { |
| 407 | 423 | $dir = ''; |
| 408 | 424 | break; |
@@ -547,16 +563,21 @@ discard block |
||
| 547 | 563 | continue; |
| 548 | 564 | } |
| 549 | 565 | $entry = trim(fgets($fd)); |
| 550 | - if (false === strpos($entry, '://')) |
|
| 551 | - continue; |
|
| 566 | + if (false === strpos($entry, '://')) { |
|
| 567 | + continue; |
|
| 568 | + } |
|
| 552 | 569 | /* Ok, item matched and may be returned. */ |
| 553 | 570 | $TotalMatches ++; |
| 554 | 571 | if (0 < $StartingIndex && |
| 555 | - $TotalMatches < $StartingIndex) |
|
| 556 | - continue; /* Skip first items. */ |
|
| 572 | + $TotalMatches < $StartingIndex) { |
|
| 573 | + continue; |
|
| 574 | + } |
|
| 575 | + /* Skip first items. */ |
|
| 557 | 576 | if (0 < $RequestedCount && |
| 558 | - $NumberReturned >= $RequestedCount) |
|
| 559 | - continue; /* Do not add more than requested. */ |
|
| 577 | + $NumberReturned >= $RequestedCount) { |
|
| 578 | + continue; |
|
| 579 | + } |
|
| 580 | + /* Do not add more than requested. */ |
|
| 560 | 581 | $NumberReturned ++; |
| 561 | 582 | /* Add item to result. */ |
| 562 | 583 | $title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1)))); |
@@ -602,16 +623,22 @@ discard block |
||
| 602 | 623 | foreach ($entries as $entry) { |
| 603 | 624 | $filename = $basedir.$dir.$entry; |
| 604 | 625 | if ('.' === substr($entry, 0, 1) || |
| 605 | - !is_dir($filename)) /* Skip files. */ |
|
| 626 | + !is_dir($filename)) { |
|
| 627 | + /* Skip files. */ |
|
| 606 | 628 | continue; |
| 629 | + } |
|
| 607 | 630 | /* Ok, item matched and may be returned. */ |
| 608 | 631 | $TotalMatches ++; |
| 609 | 632 | if (0 < $StartingIndex && |
| 610 | - $TotalMatches < $StartingIndex) |
|
| 611 | - continue; /* Skip first items. */ |
|
| 633 | + $TotalMatches < $StartingIndex) { |
|
| 634 | + continue; |
|
| 635 | + } |
|
| 636 | + /* Skip first items. */ |
|
| 612 | 637 | if (0 < $RequestedCount && |
| 613 | - $NumberReturned >= $RequestedCount) |
|
| 614 | - continue; /* Do not add more than requested. */ |
|
| 638 | + $NumberReturned >= $RequestedCount) { |
|
| 639 | + continue; |
|
| 640 | + } |
|
| 641 | + /* Do not add more than requested. */ |
|
| 615 | 642 | $NumberReturned ++; |
| 616 | 643 | /* Add item to result. */ |
| 617 | 644 | if (is_writable($filename)) { |
@@ -631,19 +658,27 @@ discard block |
||
| 631 | 658 | /* Add files to play list. */ |
| 632 | 659 | foreach ($entries as $entry) { |
| 633 | 660 | $filename = $basedir.$dir.$entry; |
| 634 | - if (is_dir($filename)) /* Skip dirs. */ |
|
| 661 | + if (is_dir($filename)) { |
|
| 662 | + /* Skip dirs. */ |
|
| 635 | 663 | continue; |
| 664 | + } |
|
| 636 | 665 | $iclass = upnp_get_class($entry, null); |
| 637 | - if (null === $iclass) /* Skip unsupported file type. */ |
|
| 666 | + if (null === $iclass) { |
|
| 667 | + /* Skip unsupported file type. */ |
|
| 638 | 668 | continue; |
| 669 | + } |
|
| 639 | 670 | /* Ok, item matched and may be returned. */ |
| 640 | 671 | $TotalMatches ++; |
| 641 | 672 | if (0 < $StartingIndex && |
| 642 | - $TotalMatches < $StartingIndex) |
|
| 643 | - continue; /* Skip first items. */ |
|
| 673 | + $TotalMatches < $StartingIndex) { |
|
| 674 | + continue; |
|
| 675 | + } |
|
| 676 | + /* Skip first items. */ |
|
| 644 | 677 | if (0 < $RequestedCount && |
| 645 | - $NumberReturned >= $RequestedCount) |
|
| 646 | - continue; /* Do not add more than requested. */ |
|
| 678 | + $NumberReturned >= $RequestedCount) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 681 | + /* Do not add more than requested. */ |
|
| 647 | 682 | $NumberReturned ++; |
| 648 | 683 | /* Add item to result. */ |
| 649 | 684 | if (is_writable($filename)) { |
@@ -802,38 +837,46 @@ discard block |
||
| 802 | 837 | |
| 803 | 838 | function get_resp_tag_name($sxml) { |
| 804 | 839 | $tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:'); |
| 805 | - if (false === $tag_st) |
|
| 806 | - return (false); |
|
| 840 | + if (false === $tag_st) { |
|
| 841 | + return (false); |
|
| 842 | + } |
|
| 807 | 843 | $tag_st += 25; |
| 808 | 844 | $tag_end = strpos($sxml, '>', $tag_st); |
| 809 | - if (false === $tag_end) |
|
| 810 | - return (false); |
|
| 845 | + if (false === $tag_end) { |
|
| 846 | + return (false); |
|
| 847 | + } |
|
| 811 | 848 | return (substr($sxml, $tag_st, ($tag_end - $tag_st))); |
| 812 | 849 | } |
| 813 | 850 | |
| 814 | 851 | function get_tag_ns($req, $tag) { |
| 815 | 852 | $rreq = strrev($req); |
| 816 | 853 | $ns_st = strpos($rreq, strrev(":$tag>")); |
| 817 | - if (false === $ns_st) |
|
| 818 | - return (false); |
|
| 854 | + if (false === $ns_st) { |
|
| 855 | + return (false); |
|
| 856 | + } |
|
| 819 | 857 | $ns_st += (strlen($tag) + 2); |
| 820 | 858 | $ns_end = strpos($rreq, '/<', $ns_st); |
| 821 | - if (false === $ns_end) |
|
| 822 | - return (false); |
|
| 859 | + if (false === $ns_end) { |
|
| 860 | + return (false); |
|
| 861 | + } |
|
| 823 | 862 | return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st)))); |
| 824 | 863 | } |
| 825 | 864 | |
| 826 | 865 | function tag_ns_replace($req, $sxml, $tag, $ns=false) { |
| 827 | - if (false === $tag) |
|
| 828 | - return ($sxml); |
|
| 829 | - if (false === $ns) |
|
| 830 | - $ns = get_tag_ns($req, $tag); |
|
| 831 | - if (false === $ns) |
|
| 832 | - return ($sxml); |
|
| 866 | + if (false === $tag) { |
|
| 867 | + return ($sxml); |
|
| 868 | + } |
|
| 869 | + if (false === $ns) { |
|
| 870 | + $ns = get_tag_ns($req, $tag); |
|
| 871 | + } |
|
| 872 | + if (false === $ns) { |
|
| 873 | + return ($sxml); |
|
| 874 | + } |
|
| 833 | 875 | while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) { |
| 834 | 876 | $tag_end = strpos($sxml, '>', $tag_st); |
| 835 | - if (false === $tag_end) |
|
| 836 | - return ($sxml); |
|
| 877 | + if (false === $tag_end) { |
|
| 878 | + return ($sxml); |
|
| 879 | + } |
|
| 837 | 880 | $old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st)); |
| 838 | 881 | $new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data); |
| 839 | 882 | $sxml = str_replace($old_tag_data, $new_tag_data, $sxml); |