2013-10-04 18:54:13 +04:00
|
|
|
/*
|
2013-11-05 05:17:18 +04:00
|
|
|
* Copyright 2010-2013 Haiku, Inc. All rights reserved.
|
2013-10-04 18:54:13 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Adrien Destugues, pulkomandy@pulkomandy.tk
|
2013-11-05 05:17:18 +04:00
|
|
|
* John Scipione, jscipione@gmail.com
|
2013-10-04 18:54:13 +04:00
|
|
|
*
|
|
|
|
* Corresponds to:
|
2013-11-05 05:17:18 +04:00
|
|
|
* headers/os/net/HttpForm.h hrev46314
|
|
|
|
* src/kits/network/libnetapi/HttpForm.cpp hrev46314
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\file HttpForm.h
|
|
|
|
\ingroup network
|
|
|
|
\brief Management of HTTP form data
|
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum form_type
|
|
|
|
\ingroup network
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_type B_HTTP_FORM_URL_ENCODED
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_type B_HTTP_FORM_MULTIPART
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\enum form_content_type
|
|
|
|
\ingroup network
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_content_type B_HTTPFORM_UNKNOWN
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_content_type B_HTTPFORM_STRING
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_content_type B_HTTPFORM_FILE
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\var form_content_type B_HTTPFORM_BUFFER
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\class BHttpFormData
|
|
|
|
\ingroup network
|
2013-11-05 05:17:18 +04:00
|
|
|
\brief Stores a form data entry sent or received during an HTTP request.
|
2013-10-04 18:54:13 +04:00
|
|
|
|
|
|
|
Each element in a form is stored in an instance of this class. The values
|
|
|
|
can be either strings, arbitrary binary buffers, or a pointer to a file.
|
|
|
|
|
|
|
|
The latter allows reading data from the file as it is being sent through
|
|
|
|
the network, removing hte need to buffer the whole file contents in memory.
|
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn BHttpFormData::BHttpFormData(const BString& name, const BString& value)
|
2013-11-05 05:17:18 +04:00
|
|
|
\brief Construct a BHttpFormData object with a string value.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn BHttpFormData::BHttpFormData(const BString& name, const BPath& value)
|
2013-11-05 05:17:18 +04:00
|
|
|
\brief Construct a BHttpFormData object which value is a file contents
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn BHttpFormData::BHttpFormData(const BString& name, const void* buffer,
|
|
|
|
ssize_t size)
|
2013-11-05 05:17:18 +04:00
|
|
|
\brief Construct a BHttpFormData object which value is a binary buffer.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn bool BHttpFormData::InitCheck() const
|
2013-11-05 05:17:18 +04:00
|
|
|
\brief Checks the initialization of the object
|
2013-10-04 18:54:13 +04:00
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
\return \c false if attempting to construct a BHttpFormData with a \c NULL
|
|
|
|
buffer.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn const BString& BHttpFormData::Name() const
|
|
|
|
\brief Get the form field name
|
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn const BString& BHttpFormData::String() const
|
2013-10-04 18:54:13 +04:00
|
|
|
\brief Get the string value of a form field.
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
\return An empty string for buffer and file based fields.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn const BPath& BHttpFormData::File() const
|
2013-10-04 18:54:13 +04:00
|
|
|
\brief Get the file path of a form field.
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
\return An empty string for buffer and string based fields.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn const void* BHttpFormData::Buffer() const
|
2013-10-04 18:54:13 +04:00
|
|
|
\brief Get a pointer to the data of a form field.
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
\return An empty string for string and file based fields
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn ssize_t BHttpFormData::BufferSize() const;
|
2013-10-04 18:54:13 +04:00
|
|
|
\brief Get the buffer size
|
|
|
|
|
|
|
|
\return 0 for string and file based fields.
|
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn bool BHttpFormData::IsFile() const
|
|
|
|
\return \c true if the field data is a file.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn const BString& BHttpFormData::Filename() const;
|
|
|
|
\return The name of the file, for file based fields.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn const BString& BHttpFormData::MimeType() const
|
|
|
|
\return The MIME type of the data.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
2013-11-05 05:17:18 +04:00
|
|
|
\fn form_content_type BHttpFormData::Type() const
|
|
|
|
\return The kind of field.
|
2013-10-04 18:54:13 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\fn status_t BHttpFormData::CopyBuffer()
|
|
|
|
\brief Make a copy of the internal buffer
|
|
|
|
|
|
|
|
The constructor for buffer-based fields does not copy the data given to it,
|
|
|
|
it just keeps a pointer. If you want to retain ownership of the data, call
|
|
|
|
this method so the buffer copies and releases it.
|
|
|
|
*/
|
|
|
|
|
2013-11-05 05:17:18 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpFormData::MarkAsFile(const BString& filename,
|
|
|
|
const BString& mimeType)
|
|
|
|
\brief Mark a field as a file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpFormData::UnmarkAsFile()
|
|
|
|
\brief Unmark a field as a file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpFormData::CopyBuffer()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpFormData& BHttpFormData::operator=(const BHttpFormData& other)
|
|
|
|
\brief Assignment operator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-10-04 18:54:13 +04:00
|
|
|
/*!
|
|
|
|
\class BHttpForm
|
|
|
|
\ingroup network
|
|
|
|
\brief Container for all the BHttpFormData instances making up an HTTP form contents.
|
|
|
|
*/
|
2013-11-05 05:17:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::BHttpForm()
|
|
|
|
\brief Create a new form object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::BHttpForm(const BHttpForm& other)
|
|
|
|
\brief Create a new form object as a copy of \a other.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::BHttpForm(const BString& formString)
|
|
|
|
\brief Create a new form object and parse the \a formString.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::~BHttpForm()
|
|
|
|
\brief Clear the form and destroy the form object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::ParseString(const BString& formString)
|
|
|
|
\brief Parse the \a formString.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BString BHttpForm::RawData() const
|
|
|
|
\brief Return the form's raw data as a BString.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpForm::AddString(const BString& fieldName,
|
|
|
|
const BString& value)
|
|
|
|
\brief Add a string to the form with the specified \a fieldName and \a value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpForm::AddInt(const BString& fieldName, int32 value)
|
|
|
|
\brief Add an int to the form with the specified \a fieldName and \a value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpForm::AddFile(const BString& fieldName, const BPath& file)
|
|
|
|
\brief Add a file to the form with the specified \a fieldName and \a value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpForm::AddBuffer(const BString& fieldName,
|
|
|
|
const void* buffer, ssize_t size)
|
|
|
|
\brief Add a buffer to the form with the specified \a fieldName and \a buffer
|
|
|
|
and \a size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn status_t BHttpForm::AddBufferCopy(const BString& fieldName,
|
|
|
|
const void* buffer, ssize_t size)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::MarkAsFile(const BString& fieldName,
|
|
|
|
const BString& filename, const BString& mimeType)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::MarkAsFile(const BString& fieldName,
|
|
|
|
const BString& filename)
|
|
|
|
\brief Mark a field as a filename.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::UnmarkAsFile(const BString& fieldName)
|
|
|
|
\brief Unmark a field as a filename.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::SetFormType(form_type type)
|
|
|
|
\brief Change form type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool BHttpForm::HasField(const BString& name) const
|
|
|
|
\brief Returns whether or not a form has a field with the specified \a name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BString BHttpForm::GetMultipartHeader(const BString& fieldName) const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn form_type BHttpForm::GetFormType() const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn const BString& BHttpForm::GetMultipartBoundary() const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BString BHttpForm::GetMultipartFooter() const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn ssize_t BHttpForm::ContentLength() const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::Iterator BHttpForm::GetIterator()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::Clear()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpFormData& BHttpForm::operator[](const BString& name)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::_ExtractNameValuePair(const BString& formString, int32* index)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::_GenerateMultipartBoundary()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::Clear()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\class BHttpForm::Iterator
|
|
|
|
\ingroup network
|
|
|
|
\brief Form Iterator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::Iterator::Iterator(BHttpForm* form)
|
|
|
|
\brief Constructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::Iterator::Iterator(const Iterator& other);
|
|
|
|
\brief Copy contstructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn bool BHttpForm::Iterator::HasNext() const
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpFormData* BHttpForm::Iterator::Next()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn void BHttpForm::Iterator::Remove()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BString BHttpForm::Iterator::MultipartHeader()
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\fn BHttpForm::Iterator& BHttpForm::Iterator::operator=(const Iterator& other)
|
|
|
|
\brief Assignment operator.
|
|
|
|
*/
|