1
0
mirror of http://git.haproxy.org/git/haproxy.git/ synced 2025-03-24 20:07:33 +00:00

[MINOR] http: move appsession 'sessid' from session to http_txn

This change, suggested by Cyril Bont�, makes a lot of sense and
would have made it obvious that sessid was not properly initialized
while switching to keep-alive. The code is now cleaner.
This commit is contained in:
Willy Tarreau 2010-01-10 10:49:11 +01:00
parent 75661457f7
commit a3377eeeff
4 changed files with 18 additions and 18 deletions

View File

@ -311,6 +311,7 @@ struct http_txn {
char *uri; /* first line if log needed, NULL otherwise */
char *cli_cookie; /* cookie presented by the client, in capture mode */
char *srv_cookie; /* cookie presented by the server, in capture mode */
char *sessid; /* the appsession id, if found in the request or in the response */
int status; /* HTTP status from the server, negative if from proxy */
unsigned int flags; /* transaction flags */
};

View File

@ -163,7 +163,6 @@ struct session {
int conn_retries; /* number of connect retries left */
int flags; /* some flags describing the session */
unsigned term_trace; /* term trace: 4*8 bits indicating which part of the code closed */
char *sessid; /* the session id, if found in the request or in the response */
struct buffer *req; /* request buffer */
struct buffer *rep; /* response buffer */
struct stream_interface si[2]; /* client and server stream interfaces */

View File

@ -185,7 +185,6 @@ int event_accept(int fd) {
s->be = s->fe = p;
s->req = s->rep = NULL; /* will be allocated later */
s->sessid = NULL;
s->si[0].state = s->si[0].prev_state = SI_ST_EST;
s->si[0].err_type = SI_ET_NONE;
@ -263,6 +262,7 @@ int event_accept(int fd) {
* session.c:session_free(). It is important that they are
* properly initialized.
*/
txn->sessid = NULL;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;
txn->uri = NULL;

View File

@ -2988,7 +2988,7 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit)
*/
/* It needs to look into the URI */
if ((s->sessid == NULL) && s->be->appsession_name) {
if ((txn->sessid == NULL) && s->be->appsession_name) {
get_srv_from_appsession(s, msg->sol + msg->sl.rq.u, msg->sl.rq.u_l);
}
@ -5174,19 +5174,19 @@ void manage_client_side_appsession(struct session *t, const char *buf, int len)
if (t->be->options2 & PR_O2_AS_REQL) {
/* request-learn option is enabled : store the sessid in the session for future use */
if (t->sessid != NULL) {
if (txn->sessid != NULL) {
/* free previously allocated memory as we don't need the session id found in the URL anymore */
pool_free2(apools.sessid, t->sessid);
pool_free2(apools.sessid, txn->sessid);
}
if ((t->sessid = pool_alloc2(apools.sessid)) == NULL) {
if ((txn->sessid = pool_alloc2(apools.sessid)) == NULL) {
Alert("Not enough memory process_cli():asession->sessid:malloc().\n");
send_log(t->be, LOG_ALERT, "Not enough memory process_cli():asession->sessid:malloc().\n");
return;
}
memcpy(t->sessid, buf, len);
t->sessid[len] = 0;
memcpy(txn->sessid, buf, len);
txn->sessid[len] = 0;
}
if ((sessid_temp = pool_alloc2(apools.sessid)) == NULL) {
@ -5921,18 +5921,18 @@ void manage_server_side_cookies(struct session *t, struct buffer *rtr)
if (memcmp(p1, t->be->appsession_name, cmp_len) == 0) {
/* Cool... it's the right one */
if (t->sessid != NULL) {
if (txn->sessid != NULL) {
/* free previously allocated memory as we don't need it anymore */
pool_free2(apools.sessid, t->sessid);
pool_free2(apools.sessid, txn->sessid);
}
/* Store the sessid in the session for future use */
if ((t->sessid = pool_alloc2(apools.sessid)) == NULL) {
if ((txn->sessid = pool_alloc2(apools.sessid)) == NULL) {
Alert("Not enough Memory process_srv():asession->sessid:malloc().\n");
send_log(t->be, LOG_ALERT, "Not enough Memory process_srv():asession->sessid:malloc().\n");
return;
}
memcpy(t->sessid, value_begin, value_len);
t->sessid[value_len] = 0;
memcpy(txn->sessid, value_begin, value_len);
txn->sessid[value_len] = 0;
}
} /* end if ((t->be->appsession_name != NULL) ... */
break; /* we don't want to loop again since there cannot be another cookie on the same line */
@ -5941,10 +5941,10 @@ void manage_server_side_cookies(struct session *t, struct buffer *rtr)
old_idx = cur_idx;
} /* end of cookie processing on this header */
if (t->sessid != NULL) {
if (txn->sessid != NULL) {
appsess *asession = NULL;
/* only do insert, if lookup fails */
asession = appsession_hash_lookup(&(t->be->htbl_proxy), t->sessid);
asession = appsession_hash_lookup(&(t->be->htbl_proxy), txn->sessid);
if (asession == NULL) {
size_t server_id_len;
if ((asession = pool_alloc2(pool2_appsess)) == NULL) {
@ -5958,7 +5958,7 @@ void manage_server_side_cookies(struct session *t, struct buffer *rtr)
t->be->htbl_proxy.destroy(asession);
return;
}
memcpy(asession->sessid, t->sessid, t->be->appsession_len);
memcpy(asession->sessid, txn->sessid, t->be->appsession_len);
asession->sessid[t->be->appsession_len] = 0;
server_id_len = strlen(t->srv->id) + 1;
@ -6362,8 +6362,8 @@ void http_end_txn(struct session *s)
pool_free2(pool2_requri, txn->uri);
pool_free2(pool2_capture, txn->cli_cookie);
pool_free2(pool2_capture, txn->srv_cookie);
pool_free2(apools.sessid, s->sessid);
s->sessid = NULL;
pool_free2(apools.sessid, txn->sessid);
txn->sessid = NULL;
txn->uri = NULL;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;