diff options
author | Martin Willi <martin@strongswan.org> | 2007-09-28 06:43:59 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2007-09-28 06:43:59 +0000 |
commit | 780050cbc3fd97fbddabc89bd7d7bbd1ef008738 (patch) | |
tree | 3b0cc679c59d99601f26fb64c14e4969017ef594 | |
parent | a57ab4d6907d2729c7f627b71c99a1cefbc0126a (diff) | |
download | strongswan-780050cbc3fd97fbddabc89bd7d7bbd1ef008738.tar.bz2 strongswan-780050cbc3fd97fbddabc89bd7d7bbd1ef008738.tar.xz |
implemented proper argument parsing code
-rw-r--r-- | src/manager/lib/session.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/manager/lib/session.c b/src/manager/lib/session.c index de1c0be54..fe260b887 100644 --- a/src/manager/lib/session.c +++ b/src/manager/lib/session.c @@ -87,51 +87,44 @@ static void create_sid(private_session_t *this, request_t *request) */ static void process(private_session_t *this, request_t *request) { - char *pos, *path, *controller, *action; + char *pos, *start, *param[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; iterator_t *iterator; bool handled = FALSE; controller_t *current; + int i = 0; if (this->sid == NULL) { create_sid(this, request); } - path = request->get_path(request); - if (*path == '/') path++; - pos = strchr(path, '/'); - if (pos == NULL) + start = request->get_path(request); + if (start) { - controller = strdup(path); - action = strdup(""); - } - else - { - controller = strndup(path, pos - path); - path = pos + 1; - pos = strchr(path, '/'); - if (pos == NULL) + if (*start == '/') start++; + while ((pos = strchr(start, '/')) != NULL && i < 5) { - action = strdup(path); + param[i++] = strndup(start, pos - start); + start = pos + 1; } - else + param[i] = strdup(start); + iterator = this->controllers->create_iterator(this->controllers, TRUE); + while (iterator->iterate(iterator, (void**)¤t)) { - action = strndup(path, pos - path); + 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; + } } - } - iterator = this->controllers->create_iterator(this->controllers, TRUE); - while (iterator->iterate(iterator, (void**)¤t)) - { - if (streq(current->get_name(current), controller)) - { - current->handle(current, request, action, NULL, NULL, NULL, NULL); - handled = TRUE; - break; + iterator->destroy(iterator); + for (i = 0; i < 6; i++) + { + free(param[i]); } } - iterator->destroy(iterator); - free(controller); - free(action); if (!handled) { if (this->controllers->get_first(this->controllers, |