From 353f9834adf3f44c6c7a0f924089bb2b43360404 Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Thu, 24 Jan 2013 17:09:10 -0700 Subject: Updated all cases of exit() to return a valid code Specific codes are as follows, but can easily be changed if a different order/breakdown makes more sense: - 0: Success; everything executed as planned - 1: Configuration Error; something is wrong with/in the configuration file(s) - 2: Class Not Found; what it says - 3: Driver Method Unsupported; the method you're trying to use on a Driver doesn't exist - 4: File Not Found; 404 error - 5: Database Error; something is broken in the database somewhere - 6: Invalid Input; the user attempted to submit a request with invlaid characters in 1+ key names 7 through 26 are reserved for future use - 27: Generic Error; generated by show_error() when the status code is >= 100 28 through 127 are errors generated by user applications, normally by using show_error() with a status code below 100 128 through 254 should not be used by applications, as they are reserved by system-level functions - 255: PHP Fatal Error; automatically generated by PHP for fatal errors, and therefore not allowed for our use Status codes below 100 are shifted up by 28 to place them in the user error range. It may make more sense to have these codes left alone and instead shift the CI errors into the 101 through 127 space, but that's not what I opted for here. It would probably also be a good idea to replace the hard-coded numbers with constants or some such, but I was in a bit of a hurry when I made these changes, so I didn't look around for the best place to do this. With proper guidance, I could easily amend this commit with another that uses such constant values. Signed-off-by: Daniel Hunsaker --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 29 ++++++++++++++++++++++------- system/core/Exceptions.php | 2 +- system/core/Input.php | 3 ++- system/core/Output.php | 2 +- system/database/DB_driver.php | 2 +- system/helpers/download_helper.php | 5 +++-- system/helpers/url_helper.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Trackback.php | 4 ++-- system/libraries/Xmlrpcs.php | 3 ++- 11 files changed, 37 insertions(+), 19 deletions(-) diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 8affde64d..13826c328 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -188,7 +188,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) { - exit; + exit(0); } /* diff --git a/system/core/Common.php b/system/core/Common.php index d494caf80..d6387209b 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -1,3 +1,4 @@ + show_error($heading, $message, 'error_general', $status_code); - exit; + exit($exit_status); } } @@ -392,7 +407,7 @@ if ( ! function_exists('show_404')) { $_error =& load_class('Exceptions', 'core'); $_error->show_404($page, $log_error); - exit; + exit(4); } } @@ -514,11 +529,11 @@ if ( ! function_exists('set_status_header')) if (strpos(php_sapi_name(), 'cgi') === 0) { - header('Status: '.$code.' '.$text, TRUE); + if (!headers_sent()) header('Status: '.$code.' '.$text, TRUE); } else { - header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); + if (!headers_sent()) header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); } } } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index e6023e73b..f799d6027 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -117,7 +117,7 @@ class CI_Exceptions { } echo $this->show_error($heading, $message, 'error_404', 404); - exit; + exit(4); } // -------------------------------------------------------------------- diff --git a/system/core/Input.php b/system/core/Input.php index 82e22dd49..8f37e4464 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -745,7 +745,8 @@ class CI_Input { if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str)) { set_status_header(503); - exit('Disallowed Key Characters.'); + echo 'Disallowed Key Characters.'; + exit(6); } // Clean UTF-8 if supported diff --git a/system/core/Output.php b/system/core/Output.php index a20841463..7898d1972 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -696,7 +696,7 @@ class CI_Output { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $this->set_status_header(304); - exit; + exit(0); } else { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 35ac8e870..cb2ef4ac8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1658,7 +1658,7 @@ abstract class CI_DB_driver { $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); - exit; + exit(5); } // -------------------------------------------------------------------- diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 7294d50c5..d7691cb61 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -141,7 +141,8 @@ if ( ! function_exists('force_download')) // If we have raw data - just dump it if ($data !== NULL) { - exit($data); + echo $data; + exit(0); } // Flush 1MB chunks of data @@ -151,7 +152,7 @@ if ( ! function_exists('force_download')) } fclose($fp); - exit; + exit(0); } } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index a6536cf81..9a0153542 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -549,7 +549,7 @@ if ( ! function_exists('redirect')) header('Location: '.$uri, TRUE, $code); break; } - exit; + exit(0); } } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 4b35dce73..bb7318991 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -291,7 +291,7 @@ class CI_Driver { $trace = debug_backtrace(); _exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']); - exit; + exit(3); } // -------------------------------------------------------------------- diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index ecc7129e3..cc93b2e30 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -212,7 +212,7 @@ class CI_Trackback { public function send_error($message = 'Incomplete Information') { echo '\n\n1\n".$message."\n"; - exit; + exit(0); } // -------------------------------------------------------------------- @@ -228,7 +228,7 @@ class CI_Trackback { public function send_success() { echo '\n\n0\n"; - exit; + exit(0); } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index d4524d230..465a1967b 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -170,7 +170,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc { header('Content-Type: text/xml'); header('Content-Length: '.strlen($payload)); - exit($payload); + echo $payload; + exit(0); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3b5b7f48848d098c6190781f8790a1b0dcb0217c Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Fri, 22 Feb 2013 19:17:56 -0700 Subject: Updated exit codes as constant values Re-allocated exit status codes according to three references, which follow: BSD sysexits.h:http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits GNU recomendations:http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html Bash scripting:http://tldp.org/LDP/abs/html/exitcodes.html The GNU recommendations stem from and expand upon the standard C/C++ library (stdlibc) definitions, while also suggesting some best-practice conventions which happen to prevent exit status code collisions with bash, and probably other shells. The re-allocated codes are now mapped to constant values, set in *application/config/constants.php*, and used throughout the CodeIgniter core. They would additionally be used in *index.php*, but the constants file hasn't been loaded at that point, so the integer values are used instead, and a comment follows each such use with amplifying information on why that particular value was selected. Finally, the errors documentation has been updated accordingly. Signed-off-by: Daniel Hunsaker --- application/config/constants.php | 110 +++++++++++++++++++++++++++++++ index.php | 12 ++-- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 16 +++-- system/core/Exceptions.php | 2 +- system/core/Input.php | 2 +- system/core/Output.php | 2 +- system/database/DB_driver.php | 2 +- system/helpers/download_helper.php | 4 +- system/helpers/url_helper.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Trackback.php | 4 +- system/libraries/Xmlrpcs.php | 2 +- user_guide_src/source/general/errors.rst | 21 +++++- 14 files changed, 158 insertions(+), 25 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index 58264ed5a..32a715952 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -73,6 +73,116 @@ define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); */ define('SHOW_DEBUG_BACKTRACE', TRUE); +/* +|-------------------------------------------------------------------------- +| Exit Status Codes +|-------------------------------------------------------------------------- +| +| Used to indicate the conditions under which the script is exit()ing. +| While there is no universal standard for error codes, there are some +| broad conventions. Three such conventions are presented below, for +| those who wish to make use of them. The CodeIgniter defaults were +| chosen for the least overlap with these conventions, while still +| leaving room for others to be defined in future versions and user +| applications. The CodeIgniter values are defined last so you can +| set them to values used by any of the other conventions, and do so +| by name instead of value. +| +*/ + +/* + * standard C/C++ library (stdlibc): + */ +/* +define('LIBC_EXIT_SUCCESS', 0); +define('LIBC_EXIT_FAILURE', 1); // generic errors +*/ + +/* + * BSD sysexits.h + */ +/* +define('SYS_EX_OK', 0); // successful termination +define('SYS_EX_USAGE', 64); // command line usage error +define('SYS_EX_DATAERR', 65); // data format error +define('SYS_EX_NOINPUT', 66); // cannot open input +define('SYS_EX_NOUSER', 67); // specified user unknown +define('SYS_EX_NOHOST', 68); // specified host name unknown +define('SYS_EX_UNAVAILABLE', 69); // service unavailable +define('SYS_EX_SOFTWARE', 70); // internal software error +define('SYS_EX_OSERR', 71); // system error (e.g., can't fork) +define('SYS_EX_OSFILE', 72); // critical OS file missing +define('SYS_EX_CANTCREAT', 73); // can't create (user) output file +define('SYS_EX_IOERR', 74); // input/output error +define('SYS_EX_TEMPFAIL', 75); // temporary failure; user is invited to retry +define('SYS_EX_PROTOCOL', 76); // remote error in protocol +define('SYS_EX_NOPERM', 77); // permission denied +define('SYS_EX_CONFIG', 78); // configuration error +*/ + +/* + * Bash scripting + */ +/* +define('BASH_EXIT_SUCCESS', 0); +define('BASH_EXIT_ERROR', 1); +define('BASH_EXIT_BUILTIN_MISUSE', 2); +define('BASH_EXIT_CANT_EXEC', 126); +define('BASH_EXIT_CMD_NOT_FOUND', 127); +define('BASH_EXIT_INVALID_EXIT', 128); +define('BASH_EXIT_SIG_HUP', 129); +define('BASH_EXIT_SIG_INT', 130); +define('BASH_EXIT_SIG_QUIT', 131); +define('BASH_EXIT_SIG_ILL', 132); +define('BASH_EXIT_SIG_TRAP', 133); +define('BASH_EXIT_SIG_ABRT', 134); +define('BASH_EXIT_SIG_BUS', 135); +define('BASH_EXIT_SIG_FPE', 136); +define('BASH_EXIT_SIG_KILL', 137); +define('BASH_EXIT_SIG_USR1', 138); +define('BASH_EXIT_SIG_SEGV', 139); +define('BASH_EXIT_SIG_USR2', 140); +define('BASH_EXIT_SIG_PIPE', 141); +define('BASH_EXIT_SIG_ALRM', 142); +define('BASH_EXIT_SIG_TERM', 143); +define('BASH_EXIT_SIG_STKFLT', 144); +define('BASH_EXIT_SIG_CHLD', 145); +define('BASH_EXIT_SIG_CONT', 146); +define('BASH_EXIT_SIG_STOP', 147); +define('BASH_EXIT_SIG_TSTP', 148); +define('BASH_EXIT_SIG_TTIN', 149); +define('BASH_EXIT_SIG_TTOU', 150); +define('BASH_EXIT_SIG_URG', 151); +define('BASH_EXIT_SIG_XCPU', 152); +define('BASH_EXIT_SIG_XFSZ', 153); +define('BASH_EXIT_SIG_VTALRM', 154); +define('BASH_EXIT_SIG_PROF', 155); +define('BASH_EXIT_SIG_WINCH', 156); +define('BASH_EXIT_SIG_IO', 157); +define('BASH_EXIT_SIG_PWR', 158); +define('BASH_EXIT_SIG_SYS', 159); +*/ +/* + * BASH_EXIT_OUTOFRANGE would be 255, and mean an exit status code beyond + * the range of 0-255 was given. However, this code CANNOT BE USED IN PHP, + * so it isn't actually defined, even in a comment. + */ + +/* + * CodeIgniter defaults + */ +define('EXIT_SUCCESS', 0); // no errors +define('EXIT_FAILURE', 1); // generic error +define('EXIT_CONFIG', 3); // configuration error +define('EXIT_404', 4); // file not found; convenience value +define('EXIT_UNK_FILE', 4); // file not found +define('EXIT_UNK_CLASS', 5); // unknown class +define('EXIT_UNK_MEMBER', 6); // unknown class member +define('EXIT_USER_INPUT', 7); // invalid user input +define('EXIT_DATABASE', 8); // database error +define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code +define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code + /* End of file constants.php */ /* Location: ./application/config/constants.php */ \ No newline at end of file diff --git a/index.php b/index.php index be0945740..a52a021ec 100755 --- a/index.php +++ b/index.php @@ -67,7 +67,8 @@ switch (ENVIRONMENT) default: header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); - exit('The application environment is not set correctly.'); + echo 'The application environment is not set correctly.'; + exit(1); // EXIT_* constants not yet defined; 1 is EXIT_FAILURE, a generic error. } /* @@ -190,7 +191,8 @@ switch (ENVIRONMENT) if ( ! is_dir($system_path)) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); - exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME)); + echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME); + exit(3); // EXIT_* constants not yet defined; 3 is EXIT_CONFIG. } /* @@ -225,7 +227,8 @@ switch (ENVIRONMENT) if ( ! is_dir(BASEPATH.$application_folder.'/')) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); - exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF); + echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; + exit(3); // EXIT_* constants not yet defined; 3 is EXIT_CONFIG. } define('APPPATH', BASEPATH.$application_folder.'/'); @@ -241,7 +244,8 @@ switch (ENVIRONMENT) elseif ( ! is_dir(APPPATH.'views/')) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); - exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF); + echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; + exit(3); // EXIT_* constants not yet defined; 3 is EXIT_CONFIG. } else { diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 5a872ef21..8f5271add 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -188,7 +188,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) { - exit(0); + exit(EXIT_SUCCESS); } /* diff --git a/system/core/Common.php b/system/core/Common.php index 3cd97dc2e..479f0da7f 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -177,7 +177,7 @@ if ( ! function_exists('load_class')) // self-referencing loop with the Exceptions class set_status_header(503); echo 'Unable to locate the specified class: '.$class.'.php'; - exit(2); + exit(EXIT_UNK_CLASS); } // Keep track of what we just loaded @@ -251,7 +251,7 @@ if ( ! function_exists('get_config')) { set_status_header(503); echo 'The configuration file does not exist.'; - exit(1); + exit(EXIT_CONFIG); } // Does the $config array exist in the file? @@ -259,7 +259,7 @@ if ( ! function_exists('get_config')) { set_status_header(503); echo 'Your config file does not appear to be formatted correctly.'; - exit(1); + exit(EXIT_CONFIG); } // Are any values being dynamically replaced? @@ -374,12 +374,16 @@ if ( ! function_exists('show_error')) $status_code = abs($status_code); if ($status_code < 100) { - $exit_status = $status_code + 28; + $exit_status = $status_code + EXIT__AUTO_MIN; + if ($exit_status > EXIT__AUTO_MAX) + { + $exit_status = EXIT_FAILURE; + } $status_code = 500; } else { - $exit_status = 27; + $exit_status = EXIT_FAILURE; } $_error =& load_class('Exceptions', 'core'); @@ -407,7 +411,7 @@ if ( ! function_exists('show_404')) { $_error =& load_class('Exceptions', 'core'); $_error->show_404($page, $log_error); - exit(4); + exit(EXIT_UNK_FILE); } } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index f799d6027..423387ff9 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -117,7 +117,7 @@ class CI_Exceptions { } echo $this->show_error($heading, $message, 'error_404', 404); - exit(4); + exit(EXIT_UNK_FILE); } // -------------------------------------------------------------------- diff --git a/system/core/Input.php b/system/core/Input.php index 904f4d6e9..8d491e055 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -746,7 +746,7 @@ class CI_Input { { set_status_header(503); echo 'Disallowed Key Characters.'; - exit(6); + exit(EXIT_USER_INPUT); } // Clean UTF-8 if supported diff --git a/system/core/Output.php b/system/core/Output.php index d4abe871d..1025703dc 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -696,7 +696,7 @@ class CI_Output { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $this->set_status_header(304); - exit(0); + exit(EXIT_SUCCESS); } else { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6ae1d524d..18dbbc76e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1658,7 +1658,7 @@ abstract class CI_DB_driver { $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); - exit(5); + exit(EXIT_DATABASE); } // -------------------------------------------------------------------- diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index daf59f51b..25863eaa4 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -142,7 +142,7 @@ if ( ! function_exists('force_download')) if ($data !== NULL) { echo $data; - exit(0); + exit(EXIT_SUCCESS); } // Flush 1MB chunks of data @@ -152,7 +152,7 @@ if ( ! function_exists('force_download')) } fclose($fp); - exit(0); + exit(EXIT_SUCCESS); } } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d6bf7e2c9..7d5ccff35 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -550,7 +550,7 @@ if ( ! function_exists('redirect')) header('Location: '.$uri, TRUE, $code); break; } - exit(0); + exit(EXIT_SUCCESS); } } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index ba15f81df..9a56013ab 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -290,7 +290,7 @@ class CI_Driver { $trace = debug_backtrace(); _exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']); - exit(3); + exit(EXIT_UNK_MEMBER); } // -------------------------------------------------------------------- diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index cc93b2e30..ea8017efd 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -212,7 +212,7 @@ class CI_Trackback { public function send_error($message = 'Incomplete Information') { echo '\n\n1\n".$message."\n"; - exit(0); + exit(EXIT_SUCCESS); } // -------------------------------------------------------------------- @@ -228,7 +228,7 @@ class CI_Trackback { public function send_success() { echo '\n\n0\n"; - exit(0); + exit(EXIT_SUCCESS); } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 2d2e7f13b..e150c13b7 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -171,7 +171,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { header('Content-Type: text/xml'); header('Content-Length: '.strlen($payload)); echo $payload; - exit(0); + exit(EXIT_SUCCESS); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 8c941aadb..1d6f8120d 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -18,6 +18,15 @@ procedural interfaces that are available globally throughout the application. This approach permits error messages to get triggered without having to worry about class/function scoping. +CodeIgniter also returns a status code whenever a portion of the core +calls ``exit()``. This exit status code is separate from the HTTP status +code, and serves as a notice to other processes that may be watching of +whether the script completed successfully, or if not, what kind of +problem it encountered that caused it to abort. These values are +defined in *application/config/constants.php*. While exit status codes +are most useful in CLI settings, returning the proper code helps server +software keep track of your scripts and the health of your application. + The following functions let you generate errors: show_error() @@ -36,7 +45,12 @@ following error template:: application/errors/error_general.php The optional parameter ``$status_code`` determines what HTTP status -code should be sent with the error. +code should be sent with the error. If ``$status_code`` is less than 100, +the HTTP status code will be set to 500, and the exit status code will +be set to ``$status_code + EXIT__AUTO_MIN``. If that value is larger than +``EXIT__AUTO_MAX``, or if ``$status_code`` is 100 or higher, the exit +status code will be set to ``EXIT_FAILURE``. You can check in +*application/config/constants.php* for more detail. show_404() ========== @@ -53,8 +67,9 @@ the following error template:: application/errors/error_404.php The function expects the string passed to it to be the file path to the -page that isn't found. Note that CodeIgniter automatically shows 404 -messages if controllers are not found. +page that isn't found. The exit status code will be set to ``EXIT_UNK_FILE``. +Note that CodeIgniter automatically shows 404 messages if controllers are +not found. CodeIgniter automatically logs any ``show_404()`` calls. Setting the optional second parameter to FALSE will skip logging. -- cgit v1.2.3-24-g4f1b From 50dfe0175df02fe4aa243757bdf1b42fb9fc3169 Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Mon, 4 Mar 2013 02:05:20 -0700 Subject: Updated in accordance with feedback from @narfbg - Removed commented lists of constants from the three reference conventions, replacing each with the URLs at which more information can be found. - Renamed a few constants to more closely reflect CodeIgniter conventions. - Modified a couple of lines which were in violation of the CI Style Guide. Signed-off-by: Daniel Hunsaker --- application/config/constants.php | 108 +++++-------------------------- index.php | 2 +- system/core/Common.php | 23 ++++--- system/core/Exceptions.php | 2 +- system/helpers/download_helper.php | 4 +- system/libraries/Driver.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- user_guide_src/source/general/errors.rst | 4 +- 8 files changed, 38 insertions(+), 109 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index 32a715952..dc84712cd 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -80,104 +80,30 @@ define('SHOW_DEBUG_BACKTRACE', TRUE); | | Used to indicate the conditions under which the script is exit()ing. | While there is no universal standard for error codes, there are some -| broad conventions. Three such conventions are presented below, for +| broad conventions. Three such conventions are mentioned below, for | those who wish to make use of them. The CodeIgniter defaults were | chosen for the least overlap with these conventions, while still | leaving room for others to be defined in future versions and user -| applications. The CodeIgniter values are defined last so you can -| set them to values used by any of the other conventions, and do so -| by name instead of value. +| applications. +| +| The three main conventions used for determining exit status codes +| are as follows: +| +| Standard C/C++ Library (stdlibc): +| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html +| (This link also contains other GNU-specific conventions) +| BSD sysexits.h: +| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits +| Bash scripting: +| http://tldp.org/LDP/abs/html/exitcodes.html | */ - -/* - * standard C/C++ library (stdlibc): - */ -/* -define('LIBC_EXIT_SUCCESS', 0); -define('LIBC_EXIT_FAILURE', 1); // generic errors -*/ - -/* - * BSD sysexits.h - */ -/* -define('SYS_EX_OK', 0); // successful termination -define('SYS_EX_USAGE', 64); // command line usage error -define('SYS_EX_DATAERR', 65); // data format error -define('SYS_EX_NOINPUT', 66); // cannot open input -define('SYS_EX_NOUSER', 67); // specified user unknown -define('SYS_EX_NOHOST', 68); // specified host name unknown -define('SYS_EX_UNAVAILABLE', 69); // service unavailable -define('SYS_EX_SOFTWARE', 70); // internal software error -define('SYS_EX_OSERR', 71); // system error (e.g., can't fork) -define('SYS_EX_OSFILE', 72); // critical OS file missing -define('SYS_EX_CANTCREAT', 73); // can't create (user) output file -define('SYS_EX_IOERR', 74); // input/output error -define('SYS_EX_TEMPFAIL', 75); // temporary failure; user is invited to retry -define('SYS_EX_PROTOCOL', 76); // remote error in protocol -define('SYS_EX_NOPERM', 77); // permission denied -define('SYS_EX_CONFIG', 78); // configuration error -*/ - -/* - * Bash scripting - */ -/* -define('BASH_EXIT_SUCCESS', 0); -define('BASH_EXIT_ERROR', 1); -define('BASH_EXIT_BUILTIN_MISUSE', 2); -define('BASH_EXIT_CANT_EXEC', 126); -define('BASH_EXIT_CMD_NOT_FOUND', 127); -define('BASH_EXIT_INVALID_EXIT', 128); -define('BASH_EXIT_SIG_HUP', 129); -define('BASH_EXIT_SIG_INT', 130); -define('BASH_EXIT_SIG_QUIT', 131); -define('BASH_EXIT_SIG_ILL', 132); -define('BASH_EXIT_SIG_TRAP', 133); -define('BASH_EXIT_SIG_ABRT', 134); -define('BASH_EXIT_SIG_BUS', 135); -define('BASH_EXIT_SIG_FPE', 136); -define('BASH_EXIT_SIG_KILL', 137); -define('BASH_EXIT_SIG_USR1', 138); -define('BASH_EXIT_SIG_SEGV', 139); -define('BASH_EXIT_SIG_USR2', 140); -define('BASH_EXIT_SIG_PIPE', 141); -define('BASH_EXIT_SIG_ALRM', 142); -define('BASH_EXIT_SIG_TERM', 143); -define('BASH_EXIT_SIG_STKFLT', 144); -define('BASH_EXIT_SIG_CHLD', 145); -define('BASH_EXIT_SIG_CONT', 146); -define('BASH_EXIT_SIG_STOP', 147); -define('BASH_EXIT_SIG_TSTP', 148); -define('BASH_EXIT_SIG_TTIN', 149); -define('BASH_EXIT_SIG_TTOU', 150); -define('BASH_EXIT_SIG_URG', 151); -define('BASH_EXIT_SIG_XCPU', 152); -define('BASH_EXIT_SIG_XFSZ', 153); -define('BASH_EXIT_SIG_VTALRM', 154); -define('BASH_EXIT_SIG_PROF', 155); -define('BASH_EXIT_SIG_WINCH', 156); -define('BASH_EXIT_SIG_IO', 157); -define('BASH_EXIT_SIG_PWR', 158); -define('BASH_EXIT_SIG_SYS', 159); -*/ -/* - * BASH_EXIT_OUTOFRANGE would be 255, and mean an exit status code beyond - * the range of 0-255 was given. However, this code CANNOT BE USED IN PHP, - * so it isn't actually defined, even in a comment. - */ - -/* - * CodeIgniter defaults - */ define('EXIT_SUCCESS', 0); // no errors -define('EXIT_FAILURE', 1); // generic error +define('EXIT_ERROR', 1); // generic error define('EXIT_CONFIG', 3); // configuration error -define('EXIT_404', 4); // file not found; convenience value -define('EXIT_UNK_FILE', 4); // file not found -define('EXIT_UNK_CLASS', 5); // unknown class -define('EXIT_UNK_MEMBER', 6); // unknown class member +define('EXIT_UNKNOWN_FILE', 4); // file not found +define('EXIT_UNKNOWN_CLASS', 5); // unknown class +define('EXIT_UNKNOWN_METHOD', 6); // unknown class member define('EXIT_USER_INPUT', 7); // invalid user input define('EXIT_DATABASE', 8); // database error define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code diff --git a/index.php b/index.php index a52a021ec..c6314da1f 100755 --- a/index.php +++ b/index.php @@ -68,7 +68,7 @@ switch (ENVIRONMENT) default: header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'The application environment is not set correctly.'; - exit(1); // EXIT_* constants not yet defined; 1 is EXIT_FAILURE, a generic error. + exit(1); // EXIT_* constants not yet defined; 1 is EXIT_ERROR, a generic error. } /* diff --git a/system/core/Common.php b/system/core/Common.php index 479f0da7f..e11668d5f 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -177,7 +177,7 @@ if ( ! function_exists('load_class')) // self-referencing loop with the Exceptions class set_status_header(503); echo 'Unable to locate the specified class: '.$class.'.php'; - exit(EXIT_UNK_CLASS); + exit(EXIT_UNKNOWN_CLASS); } // Keep track of what we just loaded @@ -377,13 +377,13 @@ if ( ! function_exists('show_error')) $exit_status = $status_code + EXIT__AUTO_MIN; if ($exit_status > EXIT__AUTO_MAX) { - $exit_status = EXIT_FAILURE; + $exit_status = EXIT_ERROR; } $status_code = 500; } else { - $exit_status = EXIT_FAILURE; + $exit_status = EXIT_ERROR; } $_error =& load_class('Exceptions', 'core'); @@ -411,7 +411,7 @@ if ( ! function_exists('show_404')) { $_error =& load_class('Exceptions', 'core'); $_error->show_404($page, $log_error); - exit(EXIT_UNK_FILE); + exit(EXIT_UNKNOWN_FILE); } } @@ -531,13 +531,16 @@ if ( ! function_exists('set_status_header')) $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; - if (strpos(php_sapi_name(), 'cgi') === 0) + if ( ! headers_sent()) { - if (!headers_sent()) header('Status: '.$code.' '.$text, TRUE); - } - else - { - if (!headers_sent()) header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); + if (strpos(php_sapi_name(), 'cgi') === 0) + { + header('Status: '.$code.' '.$text, TRUE); + } + else + { + header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); + } } } } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index 423387ff9..9c68d06a5 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -117,7 +117,7 @@ class CI_Exceptions { } echo $this->show_error($heading, $message, 'error_404', 404); - exit(EXIT_UNK_FILE); + exit(EXIT_UNKNOWN_FILE); } // -------------------------------------------------------------------- diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 25863eaa4..bd3296574 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -142,7 +142,7 @@ if ( ! function_exists('force_download')) if ($data !== NULL) { echo $data; - exit(EXIT_SUCCESS); + exit; } // Flush 1MB chunks of data @@ -152,7 +152,7 @@ if ( ! function_exists('force_download')) } fclose($fp); - exit(EXIT_SUCCESS); + exit; } } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 9a56013ab..1bc365cbc 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -290,7 +290,7 @@ class CI_Driver { $trace = debug_backtrace(); _exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']); - exit(EXIT_UNK_MEMBER); + exit(EXIT_UNKNOWN_METHOD); } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index e150c13b7..a6048cb9f 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -171,7 +171,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { header('Content-Type: text/xml'); header('Content-Length: '.strlen($payload)); echo $payload; - exit(EXIT_SUCCESS); + exit; } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 1d6f8120d..441cedb80 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -49,7 +49,7 @@ code should be sent with the error. If ``$status_code`` is less than 100, the HTTP status code will be set to 500, and the exit status code will be set to ``$status_code + EXIT__AUTO_MIN``. If that value is larger than ``EXIT__AUTO_MAX``, or if ``$status_code`` is 100 or higher, the exit -status code will be set to ``EXIT_FAILURE``. You can check in +status code will be set to ``EXIT_ERROR``. You can check in *application/config/constants.php* for more detail. show_404() @@ -67,7 +67,7 @@ the following error template:: application/errors/error_404.php The function expects the string passed to it to be the file path to the -page that isn't found. The exit status code will be set to ``EXIT_UNK_FILE``. +page that isn't found. The exit status code will be set to ``EXIT_UNKNOWN_FILE``. Note that CodeIgniter automatically shows 404 messages if controllers are not found. -- cgit v1.2.3-24-g4f1b From b2ac67a3a766ac18f5041eff7a5cbeef7437a184 Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Mon, 4 Mar 2013 02:31:26 -0700 Subject: Oops, missed a few places where EXIT_SUCCESS was being used. Signed-off-by: Daniel Hunsaker --- system/core/CodeIgniter.php | 2 +- system/core/Output.php | 2 +- system/helpers/url_helper.php | 2 +- system/libraries/Trackback.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 8f5271add..7f76977b5 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -188,7 +188,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) { - exit(EXIT_SUCCESS); + exit; } /* diff --git a/system/core/Output.php b/system/core/Output.php index 1025703dc..25ecd496c 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -696,7 +696,7 @@ class CI_Output { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $this->set_status_header(304); - exit(EXIT_SUCCESS); + exit; } else { diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 7d5ccff35..d0fab3fe0 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -550,7 +550,7 @@ if ( ! function_exists('redirect')) header('Location: '.$uri, TRUE, $code); break; } - exit(EXIT_SUCCESS); + exit; } } diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index ea8017efd..ecc7129e3 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -212,7 +212,7 @@ class CI_Trackback { public function send_error($message = 'Incomplete Information') { echo '\n\n1\n".$message."\n"; - exit(EXIT_SUCCESS); + exit; } // -------------------------------------------------------------------- @@ -228,7 +228,7 @@ class CI_Trackback { public function send_success() { echo '\n\n0\n"; - exit(EXIT_SUCCESS); + exit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8626e93d5b4362c86a58933dda9206ac8810476d Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Mon, 4 Mar 2013 05:14:22 -0700 Subject: Reverting changes to functions that have no business being used in CLI apps to begin with Signed-off-by: Daniel Hunsaker --- system/core/Common.php | 15 ++++++--------- system/helpers/download_helper.php | 3 +-- system/libraries/Trackback.php | 6 ++---- system/libraries/Xmlrpcs.php | 3 +-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index e11668d5f..9baf5e315 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -531,16 +531,13 @@ if ( ! function_exists('set_status_header')) $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; - if ( ! headers_sent()) + if (strpos(php_sapi_name(), 'cgi') === 0) { - if (strpos(php_sapi_name(), 'cgi') === 0) - { - header('Status: '.$code.' '.$text, TRUE); - } - else - { - header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); - } + header('Status: '.$code.' '.$text, TRUE); + } + else + { + header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); } } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index bd3296574..4fe6a0e88 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -141,8 +141,7 @@ if ( ! function_exists('force_download')) // If we have raw data - just dump it if ($data !== NULL) { - echo $data; - exit; + exit($data); } // Flush 1MB chunks of data diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index ecc7129e3..5a45be8dd 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -211,8 +211,7 @@ class CI_Trackback { */ public function send_error($message = 'Incomplete Information') { - echo '\n\n1\n".$message."\n"; - exit; + exit('\n\n1\n".$message."\n"); } // -------------------------------------------------------------------- @@ -227,8 +226,7 @@ class CI_Trackback { */ public function send_success() { - echo '\n\n0\n"; - exit; + exit('\n\n0\n"); } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index a6048cb9f..d263d789d 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -170,8 +170,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { header('Content-Type: text/xml'); header('Content-Length: '.strlen($payload)); - echo $payload; - exit; + exit($payload); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fa01ae4b3a2ed51a93590527c04295eb8cba4e40 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Mar 2013 14:40:18 +0200 Subject: [ci skip] Fix #2289 --- system/libraries/Email.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index daa38484b..756a38a10 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2017,12 +2017,11 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (strpos($reply, '503') !== 0) // Already authenticated + if (strpos($reply, '503') === 0) // Already authenticated { return TRUE; } - - if (strpos($reply, '334') !== 0) + elseif (strpos($reply, '334') !== 0) { $this->_set_error_message('lang:email_failed_smtp_login', $reply); return FALSE; -- cgit v1.2.3-24-g4f1b From 83c344efcae85ef3f07453bda70292a6bb628178 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 4 Mar 2013 14:30:08 +0100 Subject: Cache file driver: clean() now preserves .htaccess and index files --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index f1f1a30be..769bd5a26 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -133,7 +133,7 @@ class CI_Cache_file extends CI_Driver { */ public function clean() { - return delete_files($this->_cache_path); + return delete_files($this->_cache_path, FALSE, TRUE); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 5a6814e2c832186e61d15e2032c4ad41932c4f49 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Mar 2013 15:44:12 +0200 Subject: Fix #2301 --- system/core/Common.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 9baf5e315..10c22375e 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -1,4 +1,3 @@ - show_error($heading, $message, 'error_general', $status_code); exit($exit_status); -- cgit v1.2.3-24-g4f1b From b527bb5ebb262351aa3c9fd393d91b98c8fbee00 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 5 Mar 2013 21:58:49 +0100 Subject: Documentation: update reserved names list Added constants from 50dfe0175df02fe4aa243757bdf1b42fb9fc3169 (exit status codes) --- user_guide_src/source/general/reserved_names.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index d91292363..1ca3b608a 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -66,4 +66,14 @@ Constants - FOPEN_WRITE_CREATE - FOPEN_READ_WRITE_CREATE - FOPEN_WRITE_CREATE_STRICT -- FOPEN_READ_WRITE_CREATE_STRICT \ No newline at end of file +- FOPEN_READ_WRITE_CREATE_STRICT +- EXIT_SUCCESS +- EXIT_ERROR +- EXIT_CONFIG +- EXIT_UNKNOWN_FILE +- EXIT_UNKNOWN_CLASS +- EXIT_UNKNOWN_METHOD +- EXIT_USER_INPUT +- EXIT_DATABASE +- EXIT__AUTO_MIN +- EXIT__AUTO_MAX \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9a6032d87f3911ec6fcaf23736545920198a8b04 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 5 Mar 2013 23:03:12 +0100 Subject: Documentation: another update to reserved names list Added missing user functions. Also fixed a typo in common_functions.rst. --- user_guide_src/source/general/common_functions.rst | 2 +- user_guide_src/source/general/reserved_names.rst | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/general/common_functions.rst b/user_guide_src/source/general/common_functions.rst index 7917d3239..79bd9b459 100644 --- a/user_guide_src/source/general/common_functions.rst +++ b/user_guide_src/source/general/common_functions.rst @@ -31,7 +31,7 @@ version of PHP is lower than the supplied version number. is_really_writable() ==================== -.. php:function:: is_really_writeable($file) +.. php:function:: is_really_writable($file) :param string $file: File path :returns: bool diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index 1ca3b608a..ccc17d61b 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -25,15 +25,21 @@ your controller any of these: Functions --------- +- :php:func:`is_php()` - :php:func:`is_really_writable()` - ``load_class()`` +- ``is_loaded()`` - ``get_config()`` - :php:func:`config_item()` - :php:func:`show_error()` - :php:func:`show_404()` - :php:func:`log_message()` +- :php:func:`set_status_header()` - :php:func:`get_mimes()` - :php:func:`html_escape()` +- :php:func:`remove_invisible_characters()` +- :php:func:`is_https()` +- :php:func:`function_usable()` - :php:func:`get_instance()` - ``_exception_handler()`` - ``_stringify_attributes()`` -- cgit v1.2.3-24-g4f1b From affc3bca4348071c792b6f08e6f88dede7e45266 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 6 Mar 2013 01:30:15 +0100 Subject: Fix a typo in changelog.rst This missing space was broking the link generation. --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 07dae1fdc..0e45a0e8f 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -484,7 +484,7 @@ Bug fixes for 3.0 - Fixed a bug - :doc:`DB result ` method ``list_fields()`` didn't reset its field pointer for the *mysql*, *mysqli* and *mssql* drivers. - Fixed a bug (#73) - :doc:`Security Library ` method ``sanitize_filename()`` could be tricked by an XSS attack. - Fixed a bug (#2211) - :doc:`Migration Library ` extensions couldn't execute ``CI_Migration::__construct()``. -- Fixed a bug (#2255) - :doc:`Email Library ` didn't apply ``smtp_timeout``to socket reads and writes. +- Fixed a bug (#2255) - :doc:`Email Library ` didn't apply ``smtp_timeout`` to socket reads and writes. - Fixed a bug (#2239) - :doc:`Email Library ` improperly handled the Subject when used with ``bcc_batch_mode`` resulting in E_WARNING messages and an empty Subject. - Fixed a bug (#2234) - :doc:`Query Builder ` didn't reset JOIN cache for write-type queries. - Fixed a bug (#2298) - :doc:`Database Results ` method `next_row()` kept returning the last row, allowing for infinite loops. -- cgit v1.2.3-24-g4f1b From 89b67b49616b19e9c9f0bee8f49cb1bfc93b7436 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Mar 2013 19:34:23 +0200 Subject: Fix #2320 --- system/libraries/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 756a38a10..a745d331d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -105,9 +105,9 @@ class CI_Email { /** * SMTP Encryption * - * @var string NULL, 'tls' or 'ssl' + * @var string empty, 'tls' or 'ssl' */ - public $smtp_crypto = NULL; + public $smtp_crypto = ''; /** * Whether to apply word-wrapping to the message body. @@ -1875,7 +1875,7 @@ class CI_Email { return TRUE; } - $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; + $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : ''; $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, $this->smtp_port, -- cgit v1.2.3-24-g4f1b From 219565d05f6b223c28e24422b9d244b201890699 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Mar 2013 20:00:08 +0200 Subject: Add a (default) CI_DB_query_builder::_update_batch() method An improved version of PR #2324, which only targets ODBC. --- system/database/DB_query_builder.php | 41 ++++++++++++++++++++++ system/database/drivers/cubrid/cubrid_driver.php | 41 ---------------------- system/database/drivers/mysql/mysql_driver.php | 41 ---------------------- system/database/drivers/mysqli/mysqli_driver.php | 41 ---------------------- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 41 ---------------------- 5 files changed, 41 insertions(+), 164 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 85a233b50..292621b66 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1854,6 +1854,47 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k." = CASE \n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END, '; + } + + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + /** * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 6663868bd..51bbbdb47 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -429,47 +429,6 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @param string $table Table name - * @param array $values Update data - * @param string $index WHERE key - * @return string - */ - protected function _update_batch($table, $values, $index) - { - $ids = array(); - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field !== $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $cases = ''; - foreach ($final as $k => $v) - { - $cases .= $k." = CASE \n" - .implode("\n", $v) - .'ELSE '.$k.' END, '; - } - - $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); - } - - // -------------------------------------------------------------------- - /** * FROM tables * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 95003f648..b94642b35 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -455,47 +455,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @param string $table Table name - * @param array $values Update data - * @param string $index WHERE key - * @return string - */ - protected function _update_batch($table, $values, $index) - { - $ids = array(); - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field !== $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $cases = ''; - foreach ($final as $k => $v) - { - $cases .= $k." = CASE \n" - .implode("\n", $v)."\n" - .'ELSE '.$k.' END, '; - } - - $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); - } - - // -------------------------------------------------------------------- - /** * FROM tables * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b64a7a2e8..ef2cb8a8d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -426,47 +426,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @param string $table Table name - * @param array $values Update data - * @param string $index WHERE key - * @return string - */ - protected function _update_batch($table, $values, $index) - { - $ids = array(); - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field !== $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $cases = ''; - foreach ($final as $k => $v) - { - $cases .= $k.' = CASE '."\n" - .implode("\n", $v)."\n" - .'ELSE '.$k.' END, '; - } - - $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); - } - - // -------------------------------------------------------------------- - /** * FROM tables * diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 315f6f53b..ff486fc5a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -200,47 +200,6 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * Update_Batch statement - * - * Generates a platform-specific batch update string from the supplied data - * - * @param string $table Table name - * @param array $values Update data - * @param string $index UPDATE key - * @return string - */ - protected function _update_batch($table, $values, $index) - { - $ids = array(); - foreach ($values as $key => $val) - { - $ids[] = $val[$index]; - - foreach (array_keys($val) as $field) - { - if ($field !== $index) - { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; - } - } - } - - $cases = ''; - foreach ($final as $k => $v) - { - $cases .= $k." = CASE \n" - .implode("\n", $v)."\n" - .'ELSE '.$k.' END), '; - } - - $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); - } - - // -------------------------------------------------------------------- - /** * Truncate statement * -- cgit v1.2.3-24-g4f1b From 7b90325ceb8aa6fdb4680afe959927fc000bf548 Mon Sep 17 00:00:00 2001 From: bayssmekanique Date: Tue, 12 Mar 2013 13:25:24 -0700 Subject: Output Class Minify Function Change Added 2 additional MIME types to match against for JavaScript detection. --- system/core/Output.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/core/Output.php b/system/core/Output.php index 25ecd496c..3320ae154 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -793,6 +793,8 @@ class CI_Output { case 'text/css': case 'text/javascript': + case 'application/javascript': + case 'application/x-javascript': $output = $this->_minify_script_style($output); -- cgit v1.2.3-24-g4f1b From 5cb5c0a4354518ac1a8c5b71971d7a7232c33480 Mon Sep 17 00:00:00 2001 From: Sam Doidge Date: Wed, 13 Mar 2013 01:28:06 +0000 Subject: adding thumb_marker to image_lib->clear() --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0cec43fc4..7f01ac028 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -388,7 +388,7 @@ class CI_Image_lib { */ public function clear() { - $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); + $props = array('thumb_marker', 'library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); foreach ($props as $val) { @@ -1767,4 +1767,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file +/* Location: ./system/libraries/Image_lib.php */ -- cgit v1.2.3-24-g4f1b From 7ee2034cabf965c68861b68093f126befbf26727 Mon Sep 17 00:00:00 2001 From: Sam Doidge Date: Wed, 13 Mar 2013 04:43:55 +0000 Subject: removing linebreak --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 7f01ac028..b6a11a3a5 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1767,4 +1767,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 13f6eabafa655828a8c09b4ae0a58a2e3776c269 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 15 Mar 2013 10:56:55 +0200 Subject: Fix MSSQL ALTER TABLE ADD statement An improved version of PR #2329 --- system/database/DB_forge.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 53cdd53b6..d52029ecd 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -680,8 +680,12 @@ abstract class CI_DB_forge { return $sql.'DROP COLUMN '.$this->db->escape_identifiers($field); } + $sql .= ($alter_type === 'ADD') + ? 'ADD ' + : $alter_type.' COLUMN '; + $sqls = array(); - for ($i = 0, $c = count($field), $sql .= $alter_type.' COLUMN '; $i < $c; $i++) + for ($i = 0, $c = count($field); $i < $c; $i++) { $sqls[] = $sql .($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i])); -- cgit v1.2.3-24-g4f1b