X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=blobdiff_plain;f=src%2Flibfast%2Fsession.c;h=5fd5d9863f44c3e0960fa12075ec0c77e33a92ac;hp=87b7a266de7b5bbf5d66ae710d3f65e82ee6baea;hb=872176d350d16d6c6785f11ec366de3b13efcf74;hpb=6a365f0740ff683de52751c1c2903b0ddb6a7e0c diff --git a/src/libfast/session.c b/src/libfast/session.c index 87b7a26..5fd5d98 100644 --- a/src/libfast/session.c +++ b/src/libfast/session.c @@ -11,8 +11,6 @@ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. - * - * $Id$ */ #define _GNU_SOURCE @@ -36,22 +34,22 @@ struct private_session_t { * public functions */ session_t public; - + /** * session ID */ char *sid; - + /** * list of controller instances controller_t */ linked_list_t *controllers; - + /** * list of filter instances filter_t */ linked_list_t *filters; - + /** * user defined session context */ @@ -82,12 +80,12 @@ static void create_sid(private_session_t *this, request_t *request) char buf[16]; chunk_t chunk = chunk_from_buf(buf); rng_t *rng; - + rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK); if (rng) { rng->get_bytes(rng, sizeof(buf), buf); - this->sid = chunk_to_hex(chunk, FALSE); + this->sid = chunk_to_hex(chunk, NULL, FALSE).ptr; request->add_cookie(request, "SID", this->sid); rng->destroy(rng); } @@ -96,22 +94,22 @@ static void create_sid(private_session_t *this, request_t *request) /** * run all registered filters */ -static bool run_filter(private_session_t *this, request_t *request, - controller_t *controller) +static bool run_filter(private_session_t *this, request_t *request, char *p0, + char *p1, char *p2, char *p3, char *p4, char *p5) { - iterator_t *iterator; + enumerator_t *enumerator; filter_t *filter; - - iterator = this->filters->create_iterator(this->filters, TRUE); - while (iterator->iterate(iterator, (void**)&filter)) + + enumerator = this->filters->create_enumerator(this->filters); + while (enumerator->enumerate(enumerator, &filter)) { - if (!filter->run(filter, request, controller)) + if (!filter->run(filter, request, p0, p1, p2, p3, p4, p5)) { - iterator->destroy(iterator); + enumerator->destroy(enumerator); return FALSE; } } - iterator->destroy(iterator); + enumerator->destroy(enumerator); return TRUE; } @@ -121,44 +119,49 @@ static bool run_filter(private_session_t *this, request_t *request, static void process(private_session_t *this, request_t *request) { char *pos, *start, *param[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; - iterator_t *iterator; + enumerator_t *enumerator; bool handled = FALSE; controller_t *current; int i = 0; - + if (this->sid == NULL) { create_sid(this, request); } - + start = request->get_path(request); if (start) { - if (*start == '/') start++; + if (*start == '/') + { + start++; + } while ((pos = strchr(start, '/')) != NULL && i < 5) { - param[i++] = strndup(start, pos - start); + param[i++] = strndupa(start, pos - start); start = pos + 1; } - param[i] = strdup(start); - iterator = this->controllers->create_iterator(this->controllers, TRUE); - while (iterator->iterate(iterator, (void**)¤t)) + param[i] = strdupa(start); + + if (run_filter(this, request, param[0], param[1], param[2], param[3], + param[4], param[5])) { - if (streq(current->get_name(current), param[0])) - { - if (run_filter(this, request, current)) + enumerator = this->controllers->create_enumerator(this->controllers); + while (enumerator->enumerate(enumerator, ¤t)) + { + if (streq(current->get_name(current), param[0])) { current->handle(current, request, param[1], param[2], param[3], param[4], param[5]); handled = TRUE; + break; } - break; } + enumerator->destroy(enumerator); } - iterator->destroy(iterator); - for (i = 0; i < 6; i++) + else { - free(param[i]); + handled = TRUE; } } if (!handled) @@ -186,7 +189,7 @@ static void destroy(private_session_t *this) { this->controllers->destroy_offset(this->controllers, offsetof(controller_t, destroy)); this->filters->destroy_offset(this->filters, offsetof(filter_t, destroy)); - if (this->context) this->context->destroy(this->context); + DESTROY_IF(this->context); free(this->sid); free(this); } @@ -208,7 +211,7 @@ session_t *session_create(context_t *context) this->controllers = linked_list_create(); this->filters = linked_list_create(); this->context = context; - + return &this->public; }