CLEANUP: appsession: remove appsession.c and sessionhash.c

Now there's no more code using appsessions we can remove them.
This commit is contained in:
Willy Tarreau 2015-08-10 19:10:52 +02:00
parent 6db62c58d6
commit 9496552e7d
3 changed files with 2 additions and 304 deletions

View File

@ -733,13 +733,13 @@ else
all: haproxy $(EXTRA)
endif
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
OBJS = src/haproxy.o src/base64.o src/protocol.o \
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
src/chunk.o src/channel.o src/listener.o src/lru.o src/xxhash.o \
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o \
src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o \
src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
src/proto_http.o src/raw_sock.o src/backend.o \
src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \
src/stream_interface.o src/dumpstats.o src/proto_tcp.o src/applet.o \
src/session.o src/stream.o src/hdr_idx.o src/ev_select.o src/signal.o \

View File

@ -1,175 +0,0 @@
/*
* AppSession functions.
*
* Copyright 2004-2006 Alexander Lazic, Klaus Wagner
* Copyright 2006-2009 Willy Tarreau
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <common/appsession.h>
#include <common/config.h>
#include <common/memory.h>
#include <common/sessionhash.h>
#include <common/ticks.h>
#include <common/time.h>
#include <types/global.h>
#include <proto/proxy.h>
#include <proto/task.h>
static struct task *appsess_refresh = NULL;
struct pool_head *pool2_appsess;
struct app_pool apools;
int have_appsession;
int appsession_init(void)
{
static int initialized = 0;
int idlen;
struct server *s;
struct proxy *p = proxy;
if (!initialized) {
pool2_appsess = create_pool("appsess", sizeof(appsess), MEM_F_SHARED);
if (pool2_appsess == NULL)
return -1;
if (!appsession_task_init()) {
int ser_msize, ses_msize;
apools.sessid = NULL;
apools.serverid = NULL;
ser_msize = sizeof(void *);
ses_msize = sizeof(void *);
while (p) {
s = p->srv;
if (ses_msize < p->appsession_len)
ses_msize = p->appsession_len;
while (s) {
idlen = strlen(s->id);
if (ser_msize < idlen)
ser_msize = idlen;
s = s->next;
}
p = p->next;
}
/* we use strings, so reserve space for '\0' */
ser_msize ++;
ses_msize ++;
apools.sessid = create_pool("sessid", ses_msize, MEM_F_SHARED);
if (!apools.sessid)
return -1;
apools.serverid = create_pool("serverid", ser_msize, MEM_F_SHARED);
if (!apools.serverid)
return -1;
}
else {
fprintf(stderr, "appsession_task_init failed\n");
return -1;
}
initialized ++;
}
return 0;
}
static struct task *appsession_refresh(struct task *t)
{
struct proxy *p = proxy;
struct appsession_hash *htbl;
appsess *element, *back;
int i;
while (p) {
if (p->appsession_name != NULL) {
htbl = &p->htbl_proxy;
as_hash_for_each_entry_safe(i, element, back, &p->htbl_proxy, hash_list) {
if (tick_is_expired(element->expire, now_ms)) {
if ((global.mode & MODE_DEBUG) &&
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
chunk_printf(&trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
element->sessid, element->serverid?element->serverid:"(null)");
shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
}
/* delete the expired element from within the hash table */
LIST_DEL(&element->hash_list);
htbl->destroy(element);
}/* end if (tv_isle(&asession->expire, &now)) */
}
}
p = p->next;
}
t->expire = tick_add(now_ms, MS_TO_TICKS(TBLCHKINT)); /* check expiration every 5 seconds */
return t;
} /* end appsession_refresh */
int appsession_task_init(void)
{
static int initialized = 0;
if (!initialized) {
if ((appsess_refresh = task_new()) == NULL)
return -1;
appsess_refresh->context = NULL;
appsess_refresh->expire = tick_add(now_ms, MS_TO_TICKS(TBLCHKINT));
appsess_refresh->process = appsession_refresh;
task_queue(appsess_refresh);
initialized ++;
}
return 0;
}
int match_str(const void *key1, const void *key2)
{
appsess *temp1,*temp2;
temp1 = (appsess *)key1;
temp2 = (appsess *)key2;
//fprintf(stdout,">>>>>>>>>>>>>>temp1->sessid :%s:\n",temp1->sessid);
//fprintf(stdout,">>>>>>>>>>>>>>temp2->sessid :%s:\n",temp2->sessid);
return (strcmp(temp1->sessid,temp2->sessid) == 0);
}/* end match_str */
void destroy(appsess *temp1) {
pool_free2(apools.sessid, temp1->sessid);
pool_free2(apools.serverid, temp1->serverid);
pool_free2(pool2_appsess, temp1);
} /* end destroy */
void appsession_cleanup( void )
{
struct proxy *p = proxy;
while(p) {
appsession_hash_destroy(&(p->htbl_proxy));
p = p->next;
}
if (appsess_refresh) {
task_delete(appsess_refresh);
task_free(appsess_refresh);
appsess_refresh = NULL;
}
}/* end appsession_cleanup() */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/

View File

@ -1,127 +0,0 @@
/*
* HashTable functions.
*
* Copyright 2007 Arnaud Cornet
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License, version 2.1 as published by the Free Software Foundation.
*
*/
/*
* quick and dirty AppSession hash table, using sessid as key
*/
#include <common/sessionhash.h>
#include <string.h>
#ifdef DEBUG_HASH
#include <stdio.h>
#endif
/*
* This is a bernstein hash derivate
* returns unsigned int between 0 and (TABLESIZE - 1) inclusive
*/
unsigned int appsession_hash_f(char *ptr)
{
unsigned int h = 5381;
while (*ptr) {
h = (h << 5) + h + *ptr;
ptr++;
}
return ((h >> 16) ^ h) & TABLEMASK;
}
int appsession_hash_init(struct appsession_hash *hash,
void(*destroy)(appsess*))
{
int i;
hash->destroy = destroy;
hash->table = malloc(TABLESIZE * sizeof(struct list));
if (hash->table == NULL)
return 0;
for (i = 0; i < TABLESIZE; i++)
LIST_INIT(&hash->table[i]);
return 1;
}
void appsession_hash_insert(struct appsession_hash *hash, appsess *session)
{
unsigned int idx;
idx = appsession_hash_f(session->sessid);
LIST_ADDQ(&hash->table[idx], &session->hash_list);
}
appsess *appsession_hash_lookup(struct appsession_hash *hash, char *sessid)
{
unsigned int idx;
appsess *item;
idx = appsession_hash_f(sessid);
list_for_each_entry(item, &hash->table[idx], hash_list) {
if (strcmp(item->sessid, sessid) == 0)
return item;
}
return NULL;
}
void appsession_hash_remove(struct appsession_hash *hash, appsess *session)
{
unsigned int idx;
appsess *item;
idx = appsession_hash_f(session->sessid);
/* we don't even need to call _safe because we return at once */
list_for_each_entry(item, &hash->table[idx], hash_list) {
if (strcmp(item->sessid, session->sessid) == 0) {
LIST_DEL(&item->hash_list);
hash->destroy(item);
return;
}
}
}
void appsession_hash_destroy(struct appsession_hash *hash)
{
unsigned int i;
appsess *item;
if (!hash->table)
return;
for (i = 0; i < TABLESIZE; i++) {
while (!LIST_ISEMPTY(&hash->table[i])) {
item = LIST_ELEM(hash->table[i].n, appsess *,
hash_list);
hash->destroy(item);
LIST_DEL(&item->hash_list);
}
}
free(hash->table);
hash->table = NULL;
hash->destroy = NULL;
}
#if defined(DEBUG_HASH)
void appsession_hash_dump(struct appsession_hash *hash)
{
unsigned int idx;
appsess *item;
printf("Dumping hashtable 0x%p\n", hash);
for (idx = 0; idx < TABLESIZE; idx++) {
/* we don't even need to call _safe because we return at once */
list_for_each_entry(item, &hash->table[idx], hash_list) {
printf("\ttable[%d]:\t%s\t-> %s request_count %lu\n", idx, item->sessid,
item->serverid, item->request_count);
}
}
printf(".\n");
}
#endif