bool MCSessionExpireCookie() { MCAutoStringRef t_session_name; /* UNCHECKED */ MCS_get_session_name(&t_session_name); return MCServerSetCookie(*t_session_name, MCSTR("EXPIRE"), MCS_time() - 60 * 60 * 24, nil, nil, false, true); }
bool MCServerGetSessionIdFromCookie(char *&r_id) { MCVariable *t_cookie_array; t_cookie_array = MCVariable::lookupglobal_cstring("$_COOKIE"); if (t_cookie_array == NULL) { r_id = NULL; return true; } // ensure cookie array is evaluated if (t_cookie_array->isdeferred() && ES_NORMAL != ((MCDeferredVariable*)t_cookie_array)->compute()) return false; MCExecPoint ep; if (ES_NORMAL != t_cookie_array->fetch_element(ep, MCS_get_session_name())) return false; // retrieve ID from cookie value if (ep.isempty()) r_id = NULL; else r_id = ep.getsvalue().clone(); return true; }
bool MCSessionStart(MCStringRef p_session_id, MCSessionRef &r_session) { bool t_success = true; MCSessionIndexRef t_index = NULL; MCSession *t_session = NULL; MCSession *t_index_session = NULL; t_success = MCSessionOpenIndex(t_index); if (t_success) { if (p_session_id != NULL && MCSessionFindMatchingSession(t_index, p_session_id, t_index_session)) { t_success = MCSessionCopySession(t_index_session, t_session); } else { t_success = MCSessionCreateSession(t_index, p_session_id, t_session); } MCAutoStringRef t_session_name; if (t_success) t_success = MCS_get_session_name(&t_session_name); if (t_success) { MCAutoStringRef t_session_id_str; /* UNCHECKED */ MCStringCreateWithCString(t_session->id, &t_session_id_str); t_success = MCServerSetCookie(*t_session_name, *t_session_id_str, 0, nil, nil, false, true); } if (t_success) t_success = MCSessionOpenSession(t_index, t_session); if (t_success) MCSessionRefreshExpireTime(t_session); } if (t_index != NULL) t_success &= MCSessionCloseIndex(t_index, t_success); if (t_success) r_session = t_session; else { if (t_session != NULL) MCSessionCloseSession(t_session, false); } return t_success; }