]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: move appsession 'sessid' from session to http_txn
authorWilly Tarreau <w@1wt.eu>
Sun, 10 Jan 2010 09:49:11 +0000 (10:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 10 Jan 2010 09:49:11 +0000 (10:49 +0100)
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.

include/types/proto_http.h
include/types/session.h
src/client.c
src/proto_http.c

index a0622b7de720e693d7d3665feec732c5289f774f..c68b0c9d6ef8e50a8e69d23ee81c236f28876b31 100644 (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 */
 };
index 1af52ce1b7a09f1920031d2b0c0fa497147ec9cb..a8ec1e391aed1ccf81d24fdd4f7a2fd732c75fdd 100644 (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 */
index 866fc871e0e1d620cc2462473a73c6b779f29c98..b0184bbc9221bc30373fbccad7173c7536c604ec 100644 (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;
index 92c58691a821a1da1b9604e2890eee42925ab912..bb7da5d34644f3d2f3d07b53000b225c7e8926bc 100644 (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;