implemented proper argument parsing code
This commit is contained in:
+23
-30
@@ -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)
|
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;
|
iterator_t *iterator;
|
||||||
bool handled = FALSE;
|
bool handled = FALSE;
|
||||||
controller_t *current;
|
controller_t *current;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
if (this->sid == NULL)
|
if (this->sid == NULL)
|
||||||
{
|
{
|
||||||
create_sid(this, request);
|
create_sid(this, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
path = request->get_path(request);
|
start = request->get_path(request);
|
||||||
if (*path == '/') path++;
|
if (start)
|
||||||
pos = strchr(path, '/');
|
|
||||||
if (pos == NULL)
|
|
||||||
{
|
{
|
||||||
controller = strdup(path);
|
if (*start == '/') start++;
|
||||||
action = strdup("");
|
while ((pos = strchr(start, '/')) != NULL && i < 5)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
controller = strndup(path, pos - path);
|
|
||||||
path = pos + 1;
|
|
||||||
pos = strchr(path, '/');
|
|
||||||
if (pos == NULL)
|
|
||||||
{
|
{
|
||||||
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->destroy(iterator);
|
||||||
|
for (i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
free(param[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
free(controller);
|
|
||||||
free(action);
|
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
if (this->controllers->get_first(this->controllers,
|
if (this->controllers->get_first(this->controllers,
|
||||||
|
|||||||
Reference in New Issue
Block a user