# Apache-independent support classes and function

## Classes

class | Passenger::AbstractSpawnManager
| Spawning of application processes. More...
class | Passenger::MessageChannel
| Convenience class for I/O operations on file descriptors. More...
class | Passenger::MessageServer
| Simple pluggable request/response messaging server framework. More...
class | Passenger::Process
| Represents a single application process, as spawned by SpawnManager or by ApplicationPool::Interface::get(). More...
class | Passenger::SpawnManager
| An AbstractSpawnManager implementation. 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`.
bool | Passenger::fileExists (const StaticString &filename, CachedFileStat *cstat=0, unsigned int throttleRate=0)
| Check whether the specified file exists.
FileType | Passenger::getFileType (const StaticString &filename, CachedFileStat *cstat=0, unsigned int throttleRate=0)
| Check whether 'filename' exists and what kind of file it is.
void | Passenger::createFile (const string &filename, const StaticString &contents, mode_t permissions=S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, uid_t owner=USER_NOT_GIVEN, gid_t group=GROUP_NOT_GIVEN, bool overwrite=true)
| Create the given file with the given contents, permissions and ownership.
string | Passenger::canonicalizePath (const string &path)
| Returns a canonical version of the specified path.
string | Passenger::resolveSymlink (const string &path)
| If path refers to a symlink, then this function resolves the symlink for 1 level.
string | Passenger::extractDirName (const StaticString &path)
| Given a path, extracts its directory name.
string | Passenger::extractBaseName (const StaticString &path)
| Given a path, extracts its base name.
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.
bool | Passenger::verifyRailsDir (const string &dir, CachedFileStat *cstat=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, CachedFileStat *cstat=0, unsigned int throttleRate=0)
| Check whether the specified directory is a valid Rack application root directory.
bool | Passenger::verifyWSGIDir (const string &dir, CachedFileStat *cstat=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.

void Passenger::createFile | ( | const string & | filename,
|  | const StaticString & | contents,
|  | mode_t | permissions = `S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH`,
|  | uid_t | owner = `USER_NOT_GIVEN`,
|  | gid_t | group = `GROUP_NOT_GIVEN`,
|  | bool | overwrite = `true` |
| ) |  |  |

Create the given file with the given contents, permissions and ownership.

This function does not leave behind junk files: if the ownership cannot be set or if not all data can be written then then the file will be deleted.

Parameters:

  | filename | The file to create.
  | contents | The contents to write to the file.
  | permissions | The desired file permissions.
  | owner | The desired file owner. Specify USER_NOT_GIVEN if you want to use the current process's owner as the file owner.
  | group | The desired file group. Specify GROUP_NOT_GIVEN if you want to use the current process's group as the file group.
  | overwrite | Whether to overwrite the file if it exists. If set to false and the file exists then nothing will happen.

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 StaticString & | filename,
|  | CachedFileStat * | cstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

Check whether the specified file exists.

Parameters:

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

Returns:
  Whether the file exists.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.
  | TimeRetrievalException |
  | boost::thread_interrupted |

FileType Passenger::getFileType | ( | const StaticString & | filename,
|  | CachedFileStat * | cstat = `0`,
|  | unsigned int | throttleRate = `0` |
| ) |  |  |

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

Parameters:

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

Returns:
  The file type.

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.
  | TimeRetrievalException |
  | boost::thread_interrupted |

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.

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

If path refers to a symlink, then this function resolves the symlink for 1 level.

That is, if the symlink points to another symlink, then the other symlink will not be resolved. The resolved path is returned.

If the symlink doesn't point to an absolute path, then this function will prepend path's directory to the result.

If path doesn't refer to a symlink then this method will return path.

Exceptions:

  | FileSystemException | Something went wrong.

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

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

Parameters:

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

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.
  | TimeRetrievalException |
  | boost::thread_interrupted |

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

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

Parameters:

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

Exceptions:

  | FileSystemException | Unable to check because of a system error.
  | TimeRetrievalException |
  | boost::thread_interrupted |

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

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

Parameters:

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

Exceptions:

  | FileSystemException | Unable to check because of a filesystem error.
  | TimeRetrievalException |
  | boost::thread_interrupted |