Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Server management functions. |
| 3 | * |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 4 | * Copyright 2000-2007 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 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 Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 14 | |
| 15 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 16 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 17 | |
| 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 Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame^] | 24 | #include <proto/buffers.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 25 | #include <proto/hdr_idx.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 26 | #include <proto/session.h> |
| 27 | #include <proto/queue.h> |
| 28 | |
| 29 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 30 | struct pool_head *pool2_session; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * frees the context associated to a session. It must have been removed first. |
| 34 | */ |
| 35 | void session_free(struct session *s) |
| 36 | { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 37 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 38 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | if (s->pend_pos) |
| 40 | pendconn_free(s->pend_pos); |
| 41 | if (s->req) |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame^] | 42 | pool_free2(pool2_buffer, s->req); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | if (s->rep) |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame^] | 44 | pool_free2(pool2_buffer, s->rep); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 46 | if (txn->hdr_idx.v != NULL) |
| 47 | pool_free_to(s->fe->hdr_idx_pool, txn->hdr_idx.v); |
Willy Tarreau | 41dff82 | 2007-01-01 23:32:30 +0100 | [diff] [blame] | 48 | |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 49 | if (txn->rsp.cap != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 50 | struct cap_hdr *h; |
Willy Tarreau | e2e27a5 | 2007-04-01 00:01:37 +0200 | [diff] [blame] | 51 | for (h = s->fe->rsp_cap; h; h = h->next) { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 52 | if (txn->rsp.cap[h->index] != NULL) |
| 53 | pool_free_to(h->pool, txn->rsp.cap[h->index]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 54 | } |
Willy Tarreau | e2e27a5 | 2007-04-01 00:01:37 +0200 | [diff] [blame] | 55 | pool_free_to(s->fe->rsp_cap_pool, txn->rsp.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | } |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 57 | if (txn->req.cap != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | struct cap_hdr *h; |
Willy Tarreau | e2e27a5 | 2007-04-01 00:01:37 +0200 | [diff] [blame] | 59 | for (h = s->fe->req_cap; h; h = h->next) { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 60 | if (txn->req.cap[h->index] != NULL) |
| 61 | pool_free_to(h->pool, txn->req.cap[h->index]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | } |
Willy Tarreau | e2e27a5 | 2007-04-01 00:01:37 +0200 | [diff] [blame] | 63 | pool_free_to(s->fe->req_cap_pool, txn->req.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 66 | if (txn->uri) |
| 67 | pool_free(requri, txn->uri); |
| 68 | if (txn->cli_cookie) |
| 69 | pool_free(capture, txn->cli_cookie); |
| 70 | if (txn->srv_cookie) |
| 71 | pool_free(capture, txn->srv_cookie); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 72 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 73 | pool_free2(pool2_session, s); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 78 | int init_session() |
| 79 | { |
| 80 | pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); |
| 81 | return pool2_session != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | * Local variables: |
| 87 | * c-indent-level: 8 |
| 88 | * c-basic-offset: 8 |
| 89 | * End: |
| 90 | */ |