2
* AppSession functions.
4
* Copyright 2004-2006 Alexander Lazic, Klaus Wagner
5
* Copyright 2006-2007 Willy Tarreau
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version
10
* 2 of the License, or (at your option) any later version.
17
#include <common/appsession.h>
18
#include <common/config.h>
19
#include <common/memory.h>
20
#include <common/sessionhash.h>
21
#include <common/time.h>
23
#include <types/buffers.h>
24
#include <types/global.h>
25
#include <types/proxy.h>
26
#include <types/server.h>
28
#include <proto/task.h>
31
struct pool_head *pool2_appsess;
32
struct app_pool apools;
35
int appsession_init(void)
37
static int initialized = 0;
40
struct proxy *p = proxy;
43
pool2_appsess = create_pool("appsess", sizeof(appsess), MEM_F_SHARED);
44
if (pool2_appsess == NULL)
47
if (!appsession_task_init()) {
48
int ser_msize, ses_msize;
51
apools.serverid = NULL;
53
ser_msize = sizeof(void *);
54
ses_msize = sizeof(void *);
57
if (ses_msize < p->appsession_len)
58
ses_msize = p->appsession_len;
60
idlen = strlen(s->id);
61
if (ser_msize < idlen)
67
/* we use strings, so reserve space for '\0' */
71
apools.sessid = create_pool("sessid", ses_msize, MEM_F_SHARED);
74
apools.serverid = create_pool("serverid", ser_msize, MEM_F_SHARED);
79
fprintf(stderr, "appsession_task_init failed\n");
87
int appsession_task_init(void)
89
static int initialized = 0;
92
if ((t = pool_alloc2(pool2_task)) == NULL)
98
tv_ms_add(&t->expire, &now, TBLCHKINT);
99
t->process = appsession_refresh;
106
void appsession_refresh(struct task *t, struct timeval *next)
108
struct proxy *p = proxy;
109
struct appsession_hash *htbl;
110
appsess *element, *back;
114
if (p->appsession_name != NULL) {
115
htbl = &p->htbl_proxy;
116
as_hash_for_each_entry_safe(i, element, back, &p->htbl_proxy, hash_list) {
117
if (tv_isle(&element->expire, &now)) {
118
if ((global.mode & MODE_DEBUG) &&
119
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
122
on Linux NULL pointers are caught by sprintf, on solaris -> segfault
124
len = sprintf(trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
125
element->sessid, element->serverid?element->serverid:"(null)");
126
write(1, trash, len);
128
/* delete the expired element from within the hash table */
129
LIST_DEL(&element->hash_list);
130
htbl->destroy(element);
131
}/* end if (tv_isle(&asession->expire, &now)) */
136
tv_ms_add(&t->expire, &now, TBLCHKINT); /* check expiration every 5 seconds */
139
} /* end appsession_refresh */
141
int match_str(const void *key1, const void *key2)
143
appsess *temp1,*temp2;
144
temp1 = (appsess *)key1;
145
temp2 = (appsess *)key2;
147
//fprintf(stdout,">>>>>>>>>>>>>>temp1->sessid :%s:\n",temp1->sessid);
148
//fprintf(stdout,">>>>>>>>>>>>>>temp2->sessid :%s:\n",temp2->sessid);
150
return (strcmp(temp1->sessid,temp2->sessid) == 0);
153
void destroy(appsess *temp1) {
155
pool_free2(apools.sessid, temp1->sessid);
158
pool_free2(apools.serverid, temp1->serverid);
160
pool_free2(pool2_appsess, temp1);
163
void appsession_cleanup( void )
165
struct proxy *p = proxy;
168
appsession_hash_destroy(&(p->htbl_proxy));
171
}/* end appsession_cleanup() */