示例#1
0
文件: request.c 项目: cemonds/onion
/**
 * @short Returns the session dict.
 * @memberof onion_request_t
 * 
 * If it does not exists it creates it. If there is a cookie with a proper name it is used, 
 * even for creation.
 * 
 * Returned dictionary can be freely managed (added new keys...) and this is the session data.
 */
onion_dict *onion_request_get_session_dict(onion_request *req){
	if (!req->session){
		onion_request_guess_session_id(req);
		if (!req->session){ // Maybe old session is not to be used anymore
			req->session_id=onion_sessions_create(req->server->sessions);
			req->session=onion_sessions_get(req->server->sessions, req->session_id);
		}
	}
	return req->session;
}
示例#2
0
文件: request.c 项目: cemonds/onion
/** 
 * @short Frees the session dictionary.
 * @memberof onion_request_t
 * 
 * If data is under onion_dict scope (just dicts into dicts and strings), all data is freed.
 * If the user has set some custom data, THAT MEMORY IS LEAKED.
 */
void onion_request_session_free(onion_request *req){
	if (!req->session_id)
		onion_request_guess_session_id(req);
	if (req->session_id){
		onion_sessions_remove(req->server->sessions, req->session_id);
		onion_dict_free(req->session);
		req->session=NULL;
		free(req->session_id);
		req->session_id=NULL;
	}
}
示例#3
0
/**
 * @short Frees the session dictionary.
 * @memberof onion_request_t
 *
 * It removes the session from the sessions dictionary, so this session does not exist anymore.
 *
 * If data is under onion_dict scope (just dicts into dicts and strings), all data is freed.
 * If the user has set some custom data, THAT MEMORY IS LEAKED.
 */
void onion_request_session_free(onion_request *req) {
    if (!req->session_id)
        onion_request_guess_session_id(req);
    if (req->session_id) {
        ONION_DEBUG("Removing from session storage session id: %s",req->session_id);
        onion_sessions_remove(req->connection.listen_point->server->sessions, req->session_id);
        onion_dict_free(req->session);
        req->session=NULL;
        onion_low_free(req->session_id);
        req->session_id=NULL;
    }
}
示例#4
0
/**
 * @short Returns the session dict.
 * @memberof onion_request_t
 *
 * If it does not exists it creates it. If there is a cookie with a proper name it is used,
 * even for creation.
 *
 * Sessions HAVE TO be gotten before sending any header, or user may face double sessionid, ghost sessions and some other
 * artifacts, as the cookie is not set if session is not used. If this condition happen (send headers and then ask for session) a
 * WARNING is written.
 *
 * Session is not automatically retrieved as it is a slow operation and not used normally, only on "active" handlers.
 *
 * Returned dictionary can be freely managed (added new keys...) and this is the session data.
 *
 * @return session dictionary for current request.
 */
onion_dict *onion_request_get_session_dict(onion_request *req) {
    if (!req->session) {
        if (req->flags & OR_HEADER_SENT) {
            ONION_WARNING("Asking for session AFTER sending headers. This may result in double sessionids, and wrong session behaviour. Please modify your handlers to ask for session BEFORE sending any data.");
        }
        onion_request_guess_session_id(req);
        if (!req->session) { // Maybe old session is not to be used anymore
            req->session_id=onion_sessions_create(req->connection.listen_point->server->sessions);
            req->session=onion_sessions_get(req->connection.listen_point->server->sessions, req->session_id);
        }
    }
    return req->session;
}