acl/lib_acl_cpp/include/acl_cpp/http/HttpCookie.hpp

172 lines
5.0 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
2017-06-02 14:47:24 +08:00
#include "../stdlib/dbuf_pool.hpp"
#include "http_type.hpp"
2014-11-19 00:25:21 +08:00
namespace acl {
/**
* http cookie
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API HttpCookie : public dbuf_obj
2014-11-19 00:25:21 +08:00
{
public:
/**
*
* @param name {const char*} cookie > 0
* @param value {const char*} cookie 0
*
* @param dbuf {dbuf_guard*}
2014-11-19 00:25:21 +08:00
*/
HttpCookie(const char* name, const char* value, dbuf_guard* dbuf = NULL);
2014-11-19 00:25:21 +08:00
/**
* 使使 setCookie cookie
* @param dbuf {dbuf_guard*}
2014-11-19 00:25:21 +08:00
*/
HttpCookie(dbuf_guard* dbuf = NULL);
2015-11-09 22:11:21 +08:00
/**
*
* @param cookie {const HttpCookie*} NULL
* @param dbuf {dbuf_guard*}
2015-11-09 22:11:21 +08:00
*/
HttpCookie(const HttpCookie* cookie, dbuf_guard* dbuf = NULL);
2015-11-09 22:11:21 +08:00
/**
*
2015-11-09 22:11:21 +08:00
*/
~HttpCookie(void);
2014-11-19 00:25:21 +08:00
/**
* Set-Cookie: xxx=xxx; domain=xxx; expires=xxx; path=xxx; max-age=xxx; ...
*
* @param value {const char*} xxx=xxx; domain=xxx; ...
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool setCookie(const char* value);
/**
*
2014-11-19 00:25:21 +08:00
*/
void destroy();
/**
* cookie
* @param domain {const char*} cookie
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& setDomain(const char* domain);
/**
* cookie path
* @param path {const char*} path
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& setPath(const char* path);
/**
* cookie cookie
*
* @param timeout {time_t} ()
* cookie
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& setExpires(time_t timeout);
/**
* cookie
* @param expires {const char*}
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& setExpires(const char* expires);
/**
* cookie
* @param max_age {int}
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& setMaxAge(int max_age);
/**
* cookie
* @param name {const char*}
* @param value {const char*}
* @return {HttpCookie&} 便
2014-11-19 00:25:21 +08:00
*/
HttpCookie& add(const char* name, const char* value);
/**
* cookie
* @return {const char*} 0
* HttpCookie(const char*, const char*)
* setCookie(const char*)
* "\0"
2014-11-19 00:25:21 +08:00
*/
const char* getName(void) const;
/**
* cookie
* @return {const char*} ("\0")
2014-11-19 00:25:21 +08:00
*/
const char* getValue(void) const;
/**
*
* @return {const char*} "\0"
2014-11-19 00:25:21 +08:00
*/
const char* getExpires(void) const;
/**
* cookie
* @return {const char*} "\0"
2014-11-19 00:25:21 +08:00
*/
const char* getDomain(void) const;
/**
* cookie
* @return {const char*} "\0"
2014-11-19 00:25:21 +08:00
*/
const char* getPath(void) const;
/**
* cookie
* @return {int} -1 Max-Age
2014-11-19 00:25:21 +08:00
*/
int getMaxAge(void) const;
/**
*
* @param name {const char*}
* @param case_insensitive {bool} true
*
* @return {const char*} "\0"
2014-11-19 00:25:21 +08:00
*/
const char* getParam(const char* name,
bool case_insensitive = true) const;
/**
* cookie cookie cookie
*
2014-11-19 00:25:21 +08:00
* @return {const std::list<HTTP_PARAM*>&}
*/
const std::list<HTTP_PARAM*>& getParams(void) const;
2015-11-09 22:11:21 +08:00
2014-11-19 00:25:21 +08:00
private:
dbuf_guard* dbuf_internal_;
dbuf_guard* dbuf_;
2014-11-19 00:25:21 +08:00
char dummy_[1];
char* name_;
char* value_;
std::list<HTTP_PARAM*> params_;
bool splitNameValue(char* data, HTTP_PARAM* param);
protected:
// HttpCookie(HttpCookie&) {}
// HttpCookie(const HttpCookie&) {}
2014-11-19 00:25:21 +08:00
};
} // namespace acl end