+++ /dev/null
-/*
- * @file module_urla_map.cpp
- * @brief this module provide session persistence by URL session ID.
- *
- * L7VSD: Linux Virtual Server for Layer7 Load Balancing
- * Copyright (C) 2009 NTT COMWARE Corporation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- **********************************************************************/
-
-#include "module_urla_map.h"
-
-session* session_area = NULL;
-session_list_t session_list;
-session_map_t session_map;
-
-int
-create_session_area(int size) {
- // free old session area
- if (session_area) {
- free(session_area);
- }
-
- // allocate new session area
- session_area = (session*) calloc(sizeof(session), size);
- if (session_area == NULL) {
- //XXX
- return -1;
- }
-
- // clear all session
- session_list.clear();
-
- // create session_list
- int i;
- for (i = 0; i < size; i++) {
- session_list.push_back(map + i);
- }
- return 0;
-}
-
-void
-insert_session(char* id, sockaddr_in* dest) {
- struct timeval now;
- // get current time
- gettimeofday(&now, NULL);
-
- // search session id
- session_map_t::iterator i = session_map.find(id);
- // exists session id
- if (i != session.end()) {
- // session overwrite
- (*(i->second))->dest = dest;
- (*(i->second))->time = now.tv_sec;
- // move to top
- session_list.erase(i->second);
- session_list.push_front(*(i->second));
- } else { // insert new session
- // pop oldest session
- session* map = session_list.back();
- session_list.pop_back();
- // search oldest session id
- i = session_map.find(string(map->session_id));
- // exists session id
- if (i != session_map.end())
- session_map.erase(i);
- // set session id and destination
- strncpy(map->id, id, SESSION_ID_LENGTH);
- map->dest = *dest;
- // move to top
- session_list.push_front(map);
- // insert session to map
- session_map.insert(std::pair<std::string, std::list<session*>::iterator>(string(id), session_list.begin()));
- }
-}
-
-sockaddr_in
-find_session(char* id) {
- session_map::iterator i = session_map.find(id);
- // exists session id
- if (i != session_map.end()) {
- return (*(i->second))->dest;
- }
- return NULL;
-}