Copyright | (c) 2013-2014 Edward Blake |
---|---|
License | BSD-style |
Maintainer | Edward L. Blake <edwardlblake@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Encodes and decodes serialized PHP sessions in the format used by the "php" setting for session.serialize_handler.
- decodePHPSession :: ByteString -> Maybe PHPSessionVariableList
- decodePHPSessionEither :: ByteString -> Either PHPSessionDecodingError PHPSessionVariableList
- decodePHPSessionValue :: ByteString -> Maybe PHPSessionValue
- decodePHPSessionValueEither :: ByteString -> Either PHPSessionDecodingError PHPSessionValue
- encodePHPSession :: PHPSessionVariableList -> ByteString
- encodePHPSessionValue :: PHPSessionValue -> ByteString
- decodePartialPHPSessionValue :: ByteString -> Maybe (PHPSessionValue, ByteString)
- decodePartialPHPSessionValueEither :: ByteString -> Either PHPSessionDecodingError (PHPSessionValue, ByteString)
- type PHPSessionVariableList = [(ByteString, PHPSessionValue)]
- data PHPSessionClassName = PHPSessionClassName ByteString
- data PHPSessionValue
- = PHPSessionValueArray [(PHPSessionValue, PHPSessionValue)]
- | PHPSessionValueBool Bool
- | PHPSessionValueFloat (Either Int Double)
- | PHPSessionValueInt Int
- | PHPSessionValueNull
- | PHPSessionValueObject PHPSessionClassName [(PHPSessionValue, PHPSessionValue)]
- | PHPSessionValueObjectSerializeable PHPSessionClassName ByteString
- | PHPSessionValueString ByteString
- | PHPSessionValueMisc ByteString [PHPSessionAttr]
- data PHPSessionAttr
Decode from ByteString
decodePHPSession :: ByteString -> Maybe PHPSessionVariableList Source
Decodes a ByteString
containing a serialization of a list of session variables
using the "php" session serialization format into a PHPSessionVariableList
decodePHPSessionEither :: ByteString -> Either PHPSessionDecodingError PHPSessionVariableList Source
A version of decodePHPSession
that returns a PHPSessionDecodingError
when
decoding the ByteString
fails.
decodePHPSessionValue :: ByteString -> Maybe PHPSessionValue Source
Decodes a ByteString
containing a session serialization of a value into a
PHPSessionValue
. The format being decoded is similar if not probably the same
format used by PHP's serialize/unserialize functions.
Nothing
is returned if the input bytestring could not be parsed correctly.
decodePHPSessionValueEither :: ByteString -> Either PHPSessionDecodingError PHPSessionValue Source
A version of decodePHPSessionValue
that returns PHPSessionDecodingError
when decoding the ByteString
fails.
Encode to ByteString
encodePHPSession :: PHPSessionVariableList -> ByteString Source
Encode a PHPSessionVariableList
into a ByteString
containing the serialization
of a list of session variables using the "php" session serialization format.
encodePHPSessionValue :: PHPSessionValue -> ByteString Source
Encode a PHPSessionValue
into a ByteString
containing the serialization of a
PHP value. The format being encoded into is similar if not probably the same
format used by PHP's serialize/unserialize functions.
Decode only part of a ByteString
decodePartialPHPSessionValue :: ByteString -> Maybe (PHPSessionValue, ByteString) Source
Decodes as much of a ByteString
as needed into a PHPSessionValue
and returns
the rest of the string. Decoding ends at either the end of the string or when the
extent of the current nested structure is met when an extra closing curly brace is
encountered. The format being decoded is similar if not probably the same
format used by PHP's serialize/unserialize functions.
Nothing
is returned if the input bytestring could not be parsed correctly.
decodePartialPHPSessionValueEither :: ByteString -> Either PHPSessionDecodingError (PHPSessionValue, ByteString) Source
A version of decodePartialPHPSessionValue
that uses Either, on decoding error a
PHPSessionDecodingError
is returned.
PHP session types
type PHPSessionVariableList = [(ByteString, PHPSessionValue)] Source
Holds the "top-level" session variables and their value contents.
data PHPSessionClassName Source
Represents the name of a PHP class.
data PHPSessionValue Source
PHPSessionValue
Represents a PHP value, which may be a number, string,
array, object, boolean, null, or references.
PHPSessionValueArray
represents an array as a list of key-value pairs of values of typePHPSessionValue
.PHPSessionValueObject
is similar toPHPSessionValueArray
but also includes a class name of typePHPSessionClassName
.PHPSessionValueObjectSerializeable
represent objects of which their classes implement Serializeable to handle their own serialization and don't use the normal serialization format for its contained objects.PHPSessionValueBool
,PHPSessionValueInt
,PHPSessionValueFloat
,PHPSessionValueNull
, andPHPSessionValueString
represent basic types boolean, integer, floats, null and string respectively.PHPSessionValueFloat
stores the number representation as anEither
Int
Double
to preserve instances where the number representation is actually an integer. It should be noted that the re-encoded value is usually rounded unlike PHP's representation.PHPSessionValueMisc
stores a few other types such as references and values which follow the general serialization format but aren't recognized by the decoder. A list ofPHPSessionAttr
provides the information for reconstructing the serialized representation when re-encoding this type of value.
data PHPSessionAttr Source
PHPSessionAttr
are values associated with PHPSessionValueMisc
to inspect and
generally re-encode the necessary information for that value.