mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
decode uri when sending a request; from dug song
svn:r296
This commit is contained in:
parent
785923704c
commit
2225eec22b
1
evhttp.h
1
evhttp.h
@ -175,6 +175,7 @@ int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
|
|||||||
void evhttp_clear_headers(struct evkeyvalq *);
|
void evhttp_clear_headers(struct evkeyvalq *);
|
||||||
|
|
||||||
/* Miscellaneous utility functions */
|
/* Miscellaneous utility functions */
|
||||||
|
char *evhttp_decode_uri(const char *path);
|
||||||
void evhttp_parse_query(const char *uri, struct evkeyvalq *);
|
void evhttp_parse_query(const char *uri, struct evkeyvalq *);
|
||||||
char *evhttp_htmlescape(const char *html);
|
char *evhttp_htmlescape(const char *html);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
36
http.c
36
http.c
@ -55,6 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -888,8 +889,8 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((req->uri = strdup(uri)) == NULL) {
|
if ((req->uri = evhttp_decode_uri(uri)) == NULL) {
|
||||||
event_warn("%s: strdup", __func__);
|
event_warn("%s: evhttp_decode_uri", __func__);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1372,6 +1373,7 @@ evhttp_send(struct evhttp_request *req, struct evbuffer *databuf)
|
|||||||
assert(TAILQ_FIRST(&evcon->requests) == req);
|
assert(TAILQ_FIRST(&evcon->requests) == req);
|
||||||
|
|
||||||
/* xxx: not sure if we really should expose the data buffer this way */
|
/* xxx: not sure if we really should expose the data buffer this way */
|
||||||
|
if (databuf != NULL)
|
||||||
evbuffer_add_buffer(req->output_buffer, databuf);
|
evbuffer_add_buffer(req->output_buffer, databuf);
|
||||||
|
|
||||||
/* Adds headers to the response */
|
/* Adds headers to the response */
|
||||||
@ -1417,9 +1419,39 @@ evhttp_send_page(struct evhttp_request *req, struct evbuffer *databuf)
|
|||||||
evhttp_send(req, databuf);
|
evhttp_send(req, databuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
evhttp_decode_uri(const char *path)
|
||||||
|
{
|
||||||
|
char c, *ret;
|
||||||
|
int i, j, in_query = 0;
|
||||||
|
|
||||||
|
ret = malloc(strlen(path) + 1);
|
||||||
|
if (ret == NULL)
|
||||||
|
event_err(1, "%s: malloc(%d)", __func__, strlen(path) + 1);
|
||||||
|
|
||||||
|
for (i = j = 0; path[i] != '\0'; i++) {
|
||||||
|
c = path[i];
|
||||||
|
if (c == '?') {
|
||||||
|
in_query = 1;
|
||||||
|
} else if (c == '+' && in_query) {
|
||||||
|
c = ' ';
|
||||||
|
} else if (c == '%' && isxdigit(path[i+1]) &&
|
||||||
|
isxdigit(path[i+2])) {
|
||||||
|
char tmp[] = { path[i+1], path[i+2], '\0' };
|
||||||
|
c = (char)strtol(tmp, NULL, 16);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
ret[j++] = c;
|
||||||
|
}
|
||||||
|
ret[j] = '\0';
|
||||||
|
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to parse out arguments in a query.
|
* Helper function to parse out arguments in a query.
|
||||||
* The arguments are separated by key and value.
|
* The arguments are separated by key and value.
|
||||||
|
* URI should already be decoded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user