Passed
Push — master ( 490307...0c396d )
by eertheertyerery
02:03
created
www/upnp/control/ContentDirectory.php 1 patch
Braces   +101 added lines, -58 removed lines patch added patch discarded remove patch
@@ -158,8 +158,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
@@ -315,16 +328,21 @@  discard block
 block discarded – undo
315 328
 			continue;
316 329
 		}
317 330
 		$entry = trim(fgets($fd));
318
-		if (false === strpos($entry, '://'))
319
-			continue;
331
+		if (false === strpos($entry, '://')) {
332
+					continue;
333
+		}
320 334
 		/* Ok, item matched and may be returned. */
321 335
 		$TotalMatches++;
322 336
 		if (0 < $StartingIndex &&
323
-		    $TotalMatches < $StartingIndex)
324
-			continue; /* Skip first items. */
337
+		    $TotalMatches < $StartingIndex) {
338
+					continue;
339
+		}
340
+		/* Skip first items. */
325 341
 		if (0 < $RequestedCount &&
326
-		    $NumberReturned >= $RequestedCount)
327
-			continue; /* Do not add more than requested. */
342
+		    $NumberReturned >= $RequestedCount) {
343
+					continue;
344
+		}
345
+		/* Do not add more than requested. */
328 346
 		$NumberReturned++;
329 347
 		/* Add item to result. */
330 348
 		$title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1))));
@@ -370,11 +388,13 @@  discard block
 block discarded – undo
370 388
 
371 389
 	$def = 'video/mpeg';
372 390
 
373
-	if (!isset($filename))
374
-		return ($def);
391
+	if (!isset($filename)) {
392
+			return ($def);
393
+	}
375 394
 	$dot = strrpos($filename, '.');
376
-	if (false === $dot)
377
-		return ($def);
395
+	if (false === $dot) {
396
+			return ($def);
397
+	}
378 398
 	$ext = strtolower(substr($filename, ($dot + 1)));
379 399
 	if (array_key_exists($ext, $mime_types)) {
380 400
 		return ($mime_types[$ext]);
@@ -574,8 +594,9 @@  discard block
 block discarded – undo
574 594
 			$dirnames = explode('/', $dir);
575 595
 			$dirnames_size = sizeof($dirnames);
576 596
 			for ($di = 0; $di < $dirnames_size; $di++) {
577
-				if ('.' === $dirnames[$di])
578
-					continue;
597
+				if ('.' === $dirnames[$di]) {
598
+									continue;
599
+				}
579 600
 				if ('..' === $dirnames[$di]) {
580 601
 					$dir = '';
581 602
 					break;
@@ -622,16 +643,22 @@  discard block
 block discarded – undo
622 643
 	foreach ($entries as $entry) {
623 644
 		$filename = $basedir.$dir.$entry;
624 645
 		if ('.' === substr($entry, 0, 1) ||
625
-		    !is_dir($filename)) /* Skip files. */
646
+		    !is_dir($filename)) {
647
+			/* Skip files. */
626 648
 			continue;
649
+		}
627 650
 		/* Ok, item matched and may be returned. */
628 651
 		$TotalMatches++;
629 652
 		if (0 < $StartingIndex &&
630
-		    $TotalMatches < $StartingIndex)
631
-			continue; /* Skip first items. */
653
+		    $TotalMatches < $StartingIndex) {
654
+					continue;
655
+		}
656
+		/* Skip first items. */
632 657
 		if (0 < $RequestedCount &&
633
-		    $NumberReturned >= $RequestedCount)
634
-			continue; /* Do not add more than requested. */
658
+		    $NumberReturned >= $RequestedCount) {
659
+					continue;
660
+		}
661
+		/* Do not add more than requested. */
635 662
 		$NumberReturned++;
636 663
 		/* Add item to result. */
637 664
 		if (is_writable($filename)) {
@@ -651,19 +678,27 @@  discard block
 block discarded – undo
651 678
 	/* Add files to play list. */
652 679
 	foreach ($entries as $entry) {
653 680
 		$filename = $basedir.$dir.$entry;
654
-		if (is_dir($filename)) /* Skip dirs. */
681
+		if (is_dir($filename)) {
682
+			/* Skip dirs. */
655 683
 			continue;
684
+		}
656 685
 		$iclass = upnp_get_class($entry, null);
657
-		if (null === $iclass) /* Skip unsupported file type. */
686
+		if (null === $iclass) {
687
+			/* Skip unsupported file type. */
658 688
 			continue;
689
+		}
659 690
 		/* Ok, item matched and may be returned. */
660 691
 		$TotalMatches++;
661 692
 		if (0 < $StartingIndex &&
662
-		    $TotalMatches < $StartingIndex)
663
-			continue; /* Skip first items. */
693
+		    $TotalMatches < $StartingIndex) {
694
+					continue;
695
+		}
696
+		/* Skip first items. */
664 697
 		if (0 < $RequestedCount &&
665
-		    $NumberReturned >= $RequestedCount)
666
-			continue; /* Do not add more than requested. */
698
+		    $NumberReturned >= $RequestedCount) {
699
+					continue;
700
+		}
701
+		/* Do not add more than requested. */
667 702
 		$NumberReturned++;
668 703
 		/* Add item to result. */
669 704
 		if (is_writable($filename)) {
@@ -827,38 +862,46 @@  discard block
 block discarded – undo
827 862
 
828 863
 function get_resp_tag_name($sxml) {
829 864
 	$tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:');
830
-	if (false === $tag_st)
831
-		return (false);
865
+	if (false === $tag_st) {
866
+			return (false);
867
+	}
832 868
 	$tag_st += 25;
833 869
 	$tag_end = strpos($sxml, '>', $tag_st);
834
-	if (false === $tag_end)
835
-		return (false);
870
+	if (false === $tag_end) {
871
+			return (false);
872
+	}
836 873
 	return (substr($sxml, $tag_st, ($tag_end - $tag_st)));
837 874
 }
838 875
 
839 876
 function get_tag_ns($req, $tag) {
840 877
 	$rreq = strrev($req);
841 878
 	$ns_st = strpos($rreq, strrev(":$tag>"));
842
-	if (false === $ns_st)
843
-		return (false);
879
+	if (false === $ns_st) {
880
+			return (false);
881
+	}
844 882
 	$ns_st += (strlen($tag) + 2);
845 883
 	$ns_end = strpos($rreq, '/<', $ns_st);
846
-	if (false === $ns_end)
847
-		return (false);
884
+	if (false === $ns_end) {
885
+			return (false);
886
+	}
848 887
 	return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st))));
849 888
 }
850 889
 
851 890
 function tag_ns_replace($req, $sxml, $tag, $ns = false) {
852
-	if (false === $tag)
853
-		return ($sxml);
854
-	if (false === $ns)
855
-		$ns = get_tag_ns($req, $tag);
856
-	if (false === $ns)
857
-		return ($sxml);
891
+	if (false === $tag) {
892
+			return ($sxml);
893
+	}
894
+	if (false === $ns) {
895
+			$ns = get_tag_ns($req, $tag);
896
+	}
897
+	if (false === $ns) {
898
+			return ($sxml);
899
+	}
858 900
 	while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) {
859 901
 		$tag_end = strpos($sxml, '>', $tag_st);
860
-		if (false === $tag_end)
861
-			return ($sxml);
902
+		if (false === $tag_end) {
903
+					return ($sxml);
904
+		}
862 905
 		$old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st));
863 906
 		$new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data);
864 907
 		$sxml = str_replace($old_tag_data, $new_tag_data, $sxml);
Please login to merge, or discard this patch.