Mercurial > urweb
comparison src/c/request.c @ 1370:44a12a321150
queryString and effectfulUrl
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 26 Dec 2010 17:29:03 -0500 |
parents | 87156c44824f |
children | 4e5ca2a77a4d |
comparison
equal
deleted
inserted
replaced
1369:1a78ca089bd0 | 1370:44a12a321150 |
---|---|
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 typedef struct uw_rc { | 166 typedef struct uw_rc { |
167 size_t path_copy_size; | 167 size_t path_copy_size, queryString_size; |
168 char *path_copy; | 168 char *path_copy, *queryString; |
169 } *uw_request_context; | 169 } *uw_request_context; |
170 | 170 |
171 uw_request_context uw_new_request_context(void) { | 171 uw_request_context uw_new_request_context(void) { |
172 uw_request_context r = malloc(sizeof(struct uw_rc)); | 172 uw_request_context r = malloc(sizeof(struct uw_rc)); |
173 r->path_copy_size = 0; | 173 r->path_copy_size = r->queryString_size = 0; |
174 r->path_copy = malloc(0); | 174 r->path_copy = malloc(0); |
175 r->queryString = malloc(0); | |
175 return r; | 176 return r; |
176 } | 177 } |
177 | 178 |
178 void uw_free_request_context(uw_request_context r) { | 179 void uw_free_request_context(uw_request_context r) { |
179 free(r->path_copy); | 180 free(r->path_copy); |
181 free(r->queryString); | |
180 free(r); | 182 free(r); |
181 } | 183 } |
182 | 184 |
183 request_result uw_request(uw_request_context rc, uw_context ctx, | 185 request_result uw_request(uw_request_context rc, uw_context ctx, |
184 char *method, char *path, char *query_string, | 186 char *method, char *path, char *query_string, |
378 else if (!uw_hasPostBody(ctx)) { | 380 else if (!uw_hasPostBody(ctx)) { |
379 inputs = is_post ? body : query_string; | 381 inputs = is_post ? body : query_string; |
380 | 382 |
381 if (inputs) { | 383 if (inputs) { |
382 char *name, *value; | 384 char *name, *value; |
385 int len = strlen(inputs); | |
386 | |
387 if (len+1 > rc->queryString_size) { | |
388 rc->queryString_size = len+1; | |
389 rc->queryString = realloc(rc->queryString, len+1); | |
390 } | |
391 strcpy(rc->queryString, inputs); | |
392 uw_setQueryString(ctx, rc->queryString); | |
383 | 393 |
384 while (*inputs) { | 394 while (*inputs) { |
385 name = inputs; | 395 name = inputs; |
386 if ((inputs = strchr(inputs, '&'))) | 396 if ((inputs = strchr(inputs, '&'))) |
387 *inputs++ = 0; | 397 *inputs++ = 0; |