cookie.cpp
来自「Shorthand是一个强大的脚本语言」· C++ 代码 · 共 92 行
CPP
92 行
///////////////////////////////////////////////////////////////////////////////
// $Header: /shorthand/src/cookie.cpp 2 8/28/02 6:27a Arm $
//-----------------------------------------------------------------------------
// Project: ShortHand interpreter
// Author: Andrei Remenchuk <andrei@remenchuk.com>
//-----------------------------------------------------------------------------
// cookie.cpp: ShortHand cookie object
///////////////////////////////////////////////////////////////////////////////
#include "http.h"
#include "cookie.h"
#include "except.h"
class CHttpCookie;
ShhCookie::ShhCookie(ShhModule& module, const YYLTYPE& ctor_location)
: ShhObject(module, "COOKIE", ctor_location)
{
m_cookie = NULL;
}
void ShhCookie::constructor(ShhValueList* args)
{
int argc = args->size();
if (argc < 1)
throw new ShhObjectException(1651, "Cookie constructor requires at least one argument");
string name, value, path, domain;
datetime expires; expires.invalidate();
bool secure = false;
args->get(0)->toString(name);
if (argc > 1) { args->get(1)->toString(value); }
if (argc > 2) { args->get(2)->toDate(expires); }
if (argc > 3) { args->get(3)->toString(path); }
if (argc > 4) { args->get(4)->toString(domain); }
if (argc > 5) { secure = args->get(5)->toInt() != 0; }
m_cookie = new CHttpCookie(name, value, expires, path, domain, secure);
ShhValue prop;
prop = m_cookie->name(); setProperty("name", prop);
prop = m_cookie->value(); setProperty("value", prop);
prop = expires; if (!expires.is_valid()) prop = 0;
setProperty("expires", prop);
prop = m_cookie->path(); setProperty("path", prop);
prop = m_cookie->domain(); setProperty("domain", prop);
prop = (int) secure; setProperty("secure", prop);
}
const CHttpCookie* ShhCookie::getCookie()
{
string value;
datetime expires;
expires.invalidate();
ShhValue prop = getProperty("name");
if (!prop.isEmpty()) { prop.toString(value); m_cookie->set_name(value); }
prop = getProperty("value"); prop.toString(value); m_cookie->set_value(value);
prop = getProperty("expires");
if (!prop.isEmpty()) prop.toDate(expires);
m_cookie->set_expiration(expires);
prop = getProperty("path"); prop.toString(value); m_cookie->set_path(value);
prop = getProperty("domain"); prop.toString(value); m_cookie->set_domain(value);
prop = getProperty("secure"); m_cookie->set_secure(!prop.isEmpty());
return m_cookie;
}
ShhValue ShhCookie::executeMethod(const char* name, ShhValueList* args)
{
ShhValue result(0);
return result;
}
bool ShhCookie::hasMethod(const char* name)
{
return false;
}
ShhCookie::~ShhCookie()
{
if (m_cookie != NULL) delete m_cookie;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?