r4358 render_image.php: rename to solutions.php and add comment
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 17 Mar 2011 18:29:34 +0000 (18:29 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 17 Mar 2011 18:29:34 +0000 (18:29 +0000)
printStatic404(): move to solutions.php
proxyStaticURI(): idem

wwwroot/inc/functions.php
wwwroot/inc/solutions.php [moved from wwwroot/inc/render_image.php with 80% similarity]
wwwroot/index.php

index 56094130cc63019cf4d34241a076ff09dc5ea379..2119d7feb1c0701ed26004f743b16a925093e03e 100644 (file)
@@ -39,7 +39,6 @@ define ('RE_L2_WWN_HYPHEN', '/^[0-9a-f]{2}(-[0-9a-f]{2}){7}$/i');
 define ('RE_L2_WWN_SOLID', '/^[0-9a-f]{16}$/i');
 define ('RE_IP4_ADDR', '#^[0-9]{1,3}(\.[0-9]{1,3}){3}$#');
 define ('RE_IP4_NET', '#^[0-9]{1,3}(\.[0-9]{1,3}){3}/[0-9]{1,2}$#');
-define ('RE_STATIC_URI', '#^([[:alpha:]]+)/(?:[[:alpha:]]+/)*[[:alnum:]\._-]+\.([[:alpha:]]+)$#');
 define ('E_8021Q_NOERROR', 0);
 define ('E_8021Q_VERSION_CONFLICT', 101);
 define ('E_8021Q_PULL_REMOTE_ERROR', 102);
@@ -4635,54 +4634,4 @@ function getPortinfoByName (&$object, $portname)
        return NULL;
 }
 
-function printStatic404()
-{
-       header ('404 Not Found');
-?><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
-<html><head>
-<title>404 Not Found</title>
-</head><body>
-<h1>Not Found</h1>
-<p>The requested file was not found in this instance.</p>
-<hr>
-<address>RackTables static content proxy</address>
-</body></html><?php
-       exit;
-}
-
-function proxyStaticURI ($URI)
-{
-       $content_type = array
-       (
-               'css' => 'text/css',
-               'js' => 'text/javascript',
-               'html' => 'text/html',
-               'png' => 'image/png',
-               'gif' => 'image/gif',
-               'jpg' => 'image/jpeg',
-               'jpeg' => 'image/jpeg',
-               'ico' => 'image/x-icon',
-       );
-       $matches = array();
-       if
-       (
-               ! preg_match (RE_STATIC_URI, $URI, $matches)
-               or ! in_array ($matches[1], array ('pix', 'css', 'js'))
-               or ! array_key_exists (strtolower ($matches[2]), $content_type)
-       )
-               printStatic404();
-       global $racktables_staticdir;
-       if (FALSE === $fh = fopen ("${racktables_staticdir}/${URI}", 'r'))
-               printStatic404();
-       else
-       {
-               if (FALSE !== $stat = fstat ($fh))
-                       if (checkCachedResponse (max ($stat['mtime'], $stat['ctime']), 0))
-                               exit;
-               header ('Content-type: ' . $content_type[$matches[2]]);
-               fpassthru ($fh);
-               fclose ($fh);   
-       }
-}
-
 ?>
similarity index 80%
rename from wwwroot/inc/render_image.php
rename to wwwroot/inc/solutions.php
index 8fe027fcfc9294b1e890b1d6811161c9c310ae9e..ca4632a677d3e91de6fd406b2ddb54980aa507f1 100644 (file)
@@ -1,4 +1,14 @@
 <?php
+/*
+
+The purpose of this file is to contain functions, which generate a complete
+HTTP response body and are either "dead ends" or depend on just a small
+amount of other code (which should eventually be placed in a sort of
+"first order" library file).
+
+*/
+
+define ('RE_STATIC_URI', '#^([[:alpha:]]+)/(?:[[:alpha:]]+/)*[[:alnum:]\._-]+\.([[:alpha:]]+)$#');
 
 function dispatchImageRequest()
 {
@@ -203,4 +213,51 @@ function renderFilePreview ($file_id)
        commitAddFileCache ($file_id, ob_get_flush());
 }
 
+function printStatic404()
+{
+       header ('404 Not Found');
+?><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html><head>
+<title>404 Not Found</title>
+</head><body>
+<h1>Not Found</h1>
+<p>The requested file was not found in this instance.</p>
+<hr>
+<address>RackTables static content proxy</address>
+</body></html><?php
+       exit;
+}
+
+function proxyStaticURI ($URI)
+{
+       $content_type = array
+       (
+               'css' => 'text/css',
+               'js' => 'text/javascript',
+               'html' => 'text/html',
+               'png' => 'image/png',
+               'gif' => 'image/gif',
+               'jpg' => 'image/jpeg',
+               'jpeg' => 'image/jpeg',
+               'ico' => 'image/x-icon',
+       );
+       $matches = array();
+       if
+       (
+               ! preg_match (RE_STATIC_URI, $URI, $matches)
+               or ! in_array ($matches[1], array ('pix', 'css', 'js'))
+               or ! array_key_exists (strtolower ($matches[2]), $content_type)
+       )
+               printStatic404();
+       global $racktables_staticdir;
+       if (FALSE === $fh = fopen ("${racktables_staticdir}/${URI}", 'r'))
+               printStatic404();
+       if (FALSE !== $stat = fstat ($fh))
+               if (checkCachedResponse (max ($stat['mtime'], $stat['ctime']), 0))
+                       exit;
+       header ('Content-type: ' . $content_type[$matches[2]]);
+       fpassthru ($fh);
+       fclose ($fh);   
+}
+
 ?>
index b4f8e559d127bb084213c5c2a26514cf05bb7d8e..77160adf239a3022583ac994d760f053eb6e9a4e 100644 (file)
@@ -39,6 +39,7 @@ try {
                break;
        case 'chrome' == $_REQUEST['module']:
                require_once 'inc/init.php';
+               require_once 'inc/solutions.php';
                genericAssertion ('uri', 'string');
                proxyStaticURI ($_REQUEST['uri']);
                break;
@@ -67,7 +68,7 @@ try {
                if (@$_REQUEST['img'] == 'progressbar')
                        if (checkCachedResponse (0, CACHE_DURATION))
                                exit;
-               require_once 'inc/render_image.php';
+               require_once 'inc/solutions.php';
                try
                {
                        dispatchImageRequest();