# Apache-independent support classes and function

## Classes

class | Passenger::Application
| Represents a single Ruby on Rails or Rack application instance. More...
class | Passenger::ApplicationPool
| A persistent pool of Applications. More...
class | Passenger::ApplicationPoolServer
| Multi-process usage support for ApplicationPool. More...
class | Passenger::DummySpawnManager
| A dummy SpawnManager replacement for testing/debugging purposes. More...
class | Passenger::MessageChannel
| Convenience class for I/O operations on file descriptors. More...
class | Passenger::SpawnManager
| Spawning of Ruby on Rails/Rack application instances. More...
class | Passenger::StandardApplicationPool
| A standard implementation of ApplicationPool for single-process environments. More...
class | Passenger::BufferedUpload
| Represents a buffered upload file. More...

## Functions

template<typename T>
shared_ptr< T > | Passenger::ptr (T *pointer)
| Convenience shortcut for creating a `shared_ptr`.
template<typename T>
string | Passenger::toString (T something)
| Convert anything to a string.
int | Passenger::atoi (const string &s)
| Converts the given string to an integer.
long | Passenger::atol (const string &s)
| Converts the given string to a long integer.
void | Passenger::split (const string &str, char sep, vector< string > &output)
| Split the given string using the given separator.
bool | Passenger::fileExists (const char *filename, CachedMultiFileStat *mstat=0, unsigned int throttleRate=0)
| Check whether the specified file exists.
FileType | Passenger::getFileType (const char *filename, CachedMultiFileStat *mstat=0, unsigned int throttleRate=0)
| Check whether 'filename' exists and what kind of file it is.
string | Passenger::findSpawnServer (const char *passengerRoot=NULL)
| Find the location of the Passenger spawn server script.
string | Passenger::findApplicationPoolServer (const char *passengerRoot)
| Find the location of the Passenger ApplicationPool server executable.
string | Passenger::canonicalizePath (const string &path)
| Returns a canonical version of the specified path.
string | Passenger::escapeForXml (const string &input)
| Escape the given raw string into an XML value.
const char * | Passenger::getSystemTempDir ()
| Return the path name for the directory in which the system stores general temporary files.
string | Passenger::getPassengerTempDir (bool bypassCache=false, const string &systemTempDir="")
| Return the path name for the directory in which Phusion Passenger-specific temporary files are to be stored.
bool | Passenger::verifyRailsDir (const string &dir, CachedMultiFileStat *mstat=0, unsigned int throttleRate=0)
| Check whether the specified directory is a valid Ruby on Rails application root directory.
bool | Passenger::verifyRackDir (const string &dir, CachedMultiFileStat *mstat=0, unsigned int throttleRate=0)
| Check whether the specified directory is a valid Rack application root directory.
bool | Passenger::verifyWSGIDir (const string &dir, CachedMultiFileStat *mstat=0, unsigned int throttleRate=0)
| Check whether the specified directory is a valid WSGI application root directory.

## Function Documentation

string Passenger::canonicalizePath | ( | const string & | path | ) |

Returns a canonical version of the specified path.

All symbolic links and relative path elements are resolved.

Exceptions:

  | FileSystemException | Something went wrong.

string Passenger::escapeForXml | ( | const string & | input | ) |

Escape the given raw string into an XML value.

Exceptions:

  | std::bad_alloc | Something went wrong.

bool Passenger::fileExists | ( | const char * | filename,
|  | CachedMultiFileStat * | mstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether the specified file exists.

Parameters:

  | filename | The filename to check.
  | mstat | A CachedMultiFileStat object, if you want to use cached statting.
  | throttleRate | A throttle rate for mstat. Only applicable if mstat is not NULL.

Returns:
  Whether the file exists.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.

string Passenger::findApplicationPoolServer | ( | const char * | passengerRoot | ) |

Find the location of the Passenger ApplicationPool server executable.

Parameters:

  | passengerRoot | The Passenger root folder.

Returns:
  An absolute path to the executable.

Exceptions:

  | FileSystemException | Unable to access parts of the filesystem.

Precondition:
  passengerRoot != NULL

string Passenger::findSpawnServer | ( | const char * | passengerRoot = `NULL` | ) |

Find the location of the Passenger spawn server script.

If passengerRoot is given, t T

Parameters:

  | passengerRoot | The Passenger root folder. If NULL is given, then the spawn server is found by scanning $PATH. For security reasons, only absolute paths are scanned.

Returns:
  An absolute path to the spawn server script, or an empty string on error.

Exceptions:

  | FileSystemException | Unable to access parts of the filesystem.

FileType Passenger::getFileType | ( | const char * | filename,
|  | CachedMultiFileStat * | mstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether 'filename' exists and what kind of file it is.

Parameters:

  | filename | The filename to check.
  | mstat | A CachedMultiFileStat object, if you want to use cached statting.
  | throttleRate | A throttle rate for mstat. Only applicable if mstat is not NULL.

Returns:
  The file type.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.

string Passenger::getPassengerTempDir | ( | bool | bypassCache = `false`,
|  | const string & | systemTempDir = `""` |
| ) |  |  |

Return the path name for the directory in which Phusion Passenger-specific temporary files are to be stored.

This directory is unique for this instance of the web server in which Phusion Passenger is running.

If the environment variable PASSENGER_INSTANCE_TEMP_DIR is set, then that value will be returned. If this environment variable is not set, then it will be set with the return value.

To bypass the usage of the PASSENGER_INSTANCE_TEMP_DIR environment variable, set 'bypassCache' to true.

Parameters:

  | bypassCache | Whether PASSENGER_INSTANCE_TEMP_DIR should be bypassed.
  | systemTempDir | The directory under which the Phusion Passenger-specific temp directory should be located. If set to the empty string, then the return value of getSystemTempDir() will be used. !result.empty()

const char * Passenger::getSystemTempDir | ( |  | ) |

Return the path name for the directory in which the system stores general temporary files.

This is usually "/tmp", but might be something else depending on some environment variables.

result != NULL

template<typename T>

shared_ptr<T> Passenger::ptr | ( | T * | pointer | ) | `[inline]`

Convenience shortcut for creating a `shared_ptr`.

Instead of:

        shared_ptr<Foo> foo;
        ...
        foo = shared_ptr<Foo>(new Foo());

one can write:

        shared_ptr<Foo> foo;
        ...
        foo = ptr(new Foo());

Parameters:

  | pointer | The item to put in the shared_ptr object.

void Passenger::split | ( | const string & | str,
|  | char | sep,
|  | vector< string > & | output |
| ) |  |  |

Split the given string using the given separator.

Parameters:

  | str | The string to split.
  | sep | The separator to use.
  | output | The vector to write the output to.

template<typename T>

string Passenger::toString | ( | T | something | ) | `[inline]`

Convert anything to a string.

Parameters:

  | something | The thing to convert.

bool Passenger::verifyRackDir | ( | const string & | dir,
|  | CachedMultiFileStat * | mstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether the specified directory is a valid Rack application root directory.

Parameters:

  | mstat | A CachedMultiFileStat object, if you want to use cached statting.
  | throttleRate | A throttle rate for mstat. Only applicable if mstat is not NULL.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.

bool Passenger::verifyRailsDir | ( | const string & | dir,
|  | CachedMultiFileStat * | mstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether the specified directory is a valid Ruby on Rails application root directory.

Parameters:

  | mstat | A CachedMultiFileStat object, if you want to use cached statting.
  | throttleRate | A throttle rate for mstat. Only applicable if mstat is not NULL.

Exceptions:

  | FileSystemException | Unable to check because of a system error.

bool Passenger::verifyWSGIDir | ( | const string & | dir,
|  | CachedMultiFileStat * | mstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether the specified directory is a valid WSGI application root directory.

Parameters:

  | mstat | A CachedMultiFileStat object, if you want to use cached statting.
  | throttleRate | A throttle rate for mstat. Only applicable if mstat is not NULL.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.