taskrambler  v0.1.8
Web server and task management solution.
p_request_vars.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2012 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
26 
27 #include "http/parser.h"
28 #include "http/request.h"
29 #include "hash.h"
30 #include "class.h"
31 
32 #include "utils/memory.h"
33 
34 void
35 httpParserRequestVars(HttpParser this)
36 {
37  HttpRequest request = (HttpRequest)this->current;
38  char * delim = strchr(request->uri, '?');
39 
40  if (NULL == delim) {
41  delim = request->uri + strlen(request->uri);
42  }
43 
44  request->path = memMalloc(delim - request->uri + 1);
45  request->path[delim - request->uri] = 0;
46  memcpy(request->path, request->uri, delim - request->uri);
47 
48  while(NULL != delim && 0 != *delim) {
49  char * key = delim + 1;
50  char * eqsign = strchr(key, '=');
51  char * value;
52  size_t nvalue;
53 
54  if (NULL == eqsign) {
55  return;
56  }
57 
58  delim = strchr(eqsign, '&');
59 
60  if (NULL == delim) {
61  delim = key + strlen(key);
62  }
63 
64  nvalue = delim-eqsign-1;
65  value = (0 != nvalue)? eqsign+1 : NULL;
66 
67  hashAdd(request->get,
68  new(HashValue, key, eqsign-key, value, nvalue));
69  }
70 }
71 
72 // vim: set ts=4 sw=4:
void httpParserRequestVars(HttpParser this)
void * memMalloc(size_t)
Definition: memory.c:783
void * hashAdd(Hash, void *)
Definition: add.c:48