blob: 26f953ee2e8a6658801efd5bdf614c889e830fe5 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Server management functions.
3 *
Willy Tarreauc6ca1a02007-05-13 19:43:47 +02004 * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdlib.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020014
15#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020016#include <common/memory.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020017
18#include <types/backend.h>
19#include <types/capture.h>
20#include <types/log.h>
21#include <types/proxy.h>
22#include <types/server.h>
23
Willy Tarreau7341d942007-05-13 19:56:02 +020024#include <proto/buffers.h>
Willy Tarreau8d5d7f22007-01-21 19:16:41 +010025#include <proto/hdr_idx.h>
Willy Tarreau332f8bf2007-05-13 21:36:56 +020026#include <proto/log.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027#include <proto/session.h>
28#include <proto/queue.h>
29
30
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020031struct pool_head *pool2_session;
Willy Tarreaubaaee002006-06-26 02:48:02 +020032
33/*
34 * frees the context associated to a session. It must have been removed first.
35 */
36void session_free(struct session *s)
37{
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010038 struct http_txn *txn = &s->txn;
Willy Tarreau632f5a72007-07-11 10:42:35 +020039 struct proxy *fe = s->fe;
Willy Tarreau0f7562b2007-01-07 15:46:13 +010040
Willy Tarreaubaaee002006-06-26 02:48:02 +020041 if (s->pend_pos)
42 pendconn_free(s->pend_pos);
43 if (s->req)
Willy Tarreau7341d942007-05-13 19:56:02 +020044 pool_free2(pool2_buffer, s->req);
Willy Tarreaubaaee002006-06-26 02:48:02 +020045 if (s->rep)
Willy Tarreau7341d942007-05-13 19:56:02 +020046 pool_free2(pool2_buffer, s->rep);
Willy Tarreaubaaee002006-06-26 02:48:02 +020047
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010048 if (txn->hdr_idx.v != NULL)
Willy Tarreau632f5a72007-07-11 10:42:35 +020049 pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
Willy Tarreau41dff822007-01-01 23:32:30 +010050
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010051 if (txn->rsp.cap != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020052 struct cap_hdr *h;
Willy Tarreau632f5a72007-07-11 10:42:35 +020053 for (h = fe->rsp_cap; h; h = h->next) {
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010054 if (txn->rsp.cap[h->index] != NULL)
Willy Tarreaucf7f3202007-05-13 22:46:04 +020055 pool_free2(h->pool, txn->rsp.cap[h->index]);
Willy Tarreaubaaee002006-06-26 02:48:02 +020056 }
Willy Tarreau632f5a72007-07-11 10:42:35 +020057 pool_free2(fe->rsp_cap_pool, txn->rsp.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +020058 }
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010059 if (txn->req.cap != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020060 struct cap_hdr *h;
Willy Tarreau632f5a72007-07-11 10:42:35 +020061 for (h = fe->req_cap; h; h = h->next) {
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010062 if (txn->req.cap[h->index] != NULL)
Willy Tarreaucf7f3202007-05-13 22:46:04 +020063 pool_free2(h->pool, txn->req.cap[h->index]);
Willy Tarreaubaaee002006-06-26 02:48:02 +020064 }
Willy Tarreau632f5a72007-07-11 10:42:35 +020065 pool_free2(fe->req_cap_pool, txn->req.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +020066 }
67
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010068 if (txn->uri)
Willy Tarreau332f8bf2007-05-13 21:36:56 +020069 pool_free2(pool2_requri, txn->uri);
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010070 if (txn->cli_cookie)
Willy Tarreau086b3b42007-05-13 21:45:51 +020071 pool_free2(pool2_capture, txn->cli_cookie);
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010072 if (txn->srv_cookie)
Willy Tarreau086b3b42007-05-13 21:45:51 +020073 pool_free2(pool2_capture, txn->srv_cookie);
Willy Tarreaubaaee002006-06-26 02:48:02 +020074
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020075 pool_free2(pool2_session, s);
Willy Tarreau632f5a72007-07-11 10:42:35 +020076
77 /* We may want to free the maximum amount of pools if the proxy is stopping */
78 if (unlikely(fe->state == PR_STSTOPPED)) {
79 if (pool2_buffer)
80 pool_flush2(pool2_buffer);
81 if (fe->hdr_idx_pool)
82 pool_flush2(fe->hdr_idx_pool);
83 if (pool2_requri)
84 pool_flush2(pool2_requri);
85 if (pool2_capture)
86 pool_flush2(pool2_capture);
87 if (pool2_session)
88 pool_flush2(pool2_session);
89 if (fe->req_cap_pool)
90 pool_flush2(fe->req_cap_pool);
91 if (fe->rsp_cap_pool)
92 pool_flush2(fe->rsp_cap_pool);
93 }
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020094}
95
96
97/* perform minimal intializations, report 0 in case of error, 1 if OK. */
98int init_session()
99{
100 pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED);
101 return pool2_session != NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200102}
103
104
105/*
106 * Local variables:
107 * c-indent-level: 8
108 * c-basic-offset: 8
109 * End:
110 */