Example #1
0
void
cgicc::CgiEnvironment::parseCookies()
{
    std::string data = fCookie;

    if(false == data.empty()) {
        std::string::size_type pos;
        std::string::size_type oldPos = 0;

        while(true) {
            // find the ';' terminating a name=value pair
            pos = data.find(";", oldPos);

            // if no ';' was found, the rest of the string is a single cookie
            if(std::string::npos == pos) {
                parseCookie(data.substr(oldPos));
                return;
            }

            // otherwise, the string contains multiple cookies
            // extract it and add the cookie to the list
            parseCookie(data.substr(oldPos, pos - oldPos));

            // update pos (+1 to skip ';')
            oldPos = pos + 1;
        }
    }
}
Example #2
0
static struct hash *htmlHeaderRead(char **pHtml, struct htmlCookie **pCookies)
/* Read in from second line through first blank line and
 * save in hash.  These lines are in the form name: value. */
{
struct hash *hash = hashNew(6);
for (;;)
    {
    char *line = htmlNextCrLfLine(pHtml);
    char *word;
    if (line == NULL)
	{
        warn("End of file in header");
	break;
	}
    word = nextWord(&line);
    if (word == NULL)
        break;
    line = skipLeadingSpaces(line);
    hashAdd(hash, word, cloneString(line));
    if (sameString(word, "Set-Cookie:"))
	{
	struct htmlCookie *cookie = parseCookie(line);
	if (cookie != NULL)
	    slAddTail(pCookies, cookie);
	}
    }
return hash;
}
bool AbstractWebApplication::sessionInitialize()
{
    if (session_ == 0)
    {
        const QString sessionId = parseCookie(request_).value(C_SID);

        // TODO: Additional session check

        if (!sessionId.isEmpty()) {
            if (sessions_.contains(sessionId)) {
                session_ = sessions_[sessionId];
                session_->updateTimestamp();
                return true;
            }
            else {
                qDebug() << Q_FUNC_INFO << "session does not exist!";
            }
        }
    }

    return false;
}