Permalink
Browse files

dont double-decode uri

  • Loading branch information...
1 parent eacb8fc commit 40373bf333bddb5f37725d3440c554e0cea8136e @jehiah jehiah committed Mar 7, 2011
Showing with 24 additions and 72 deletions.
  1. +1 −3 pubsub/pubsub.c
  2. +1 −3 pubsub_filtered/pubsub_filtered.c
  3. +8 −16 simpleattributes/simpleattributes.c
  4. +12 −24 simplegeo/simplegeo.c
  5. +2 −26 sortdb/sortdb.c
View
@@ -232,9 +232,7 @@ void sub_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
currentConns++;
totalConns++;
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
client = calloc(1, sizeof(*client));
argtoi(&args, "multipart", &client->multipart, 1);
client->req = req;
@@ -487,9 +487,7 @@ void sub_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
currentConns++;
totalConns++;
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
client = calloc(1, sizeof(*client));
client->multipart = 0;
@@ -109,7 +109,7 @@ void db_error_to_json(int code, struct json_object *jsobj)
void idx_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *json, *key, *kbuf, *value;
+ char *json, *key, *kbuf, *value;
int i, max, off, len;
TCLIST *keylist = NULL;
struct evkeyvalq args;
@@ -119,9 +119,7 @@ void idx_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
evhttp_send_error(req, 503, "database not connected");
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
key = (char *)evhttp_find_header(&args, "key");
argtoi(&args, "max", &max, 1000);
@@ -162,17 +160,15 @@ void idx_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void del_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *json, *key;
+ char *json, *key;
struct evkeyvalq args;
struct json_object *jsobj;
if (rdb == NULL) {
evhttp_send_error(req, 503, "database not connected");
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
key = (char *)evhttp_find_header(&args, "key");
if (key == NULL) {
@@ -195,7 +191,7 @@ void del_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
int i;
- char *uri, *json, *hash, *kvs, *key, *value;
+ char *json, *hash, *kvs, *key, *value;
struct evkeyvalq args;
struct json_object *jsobj, *jsonPtr, *jsonPtr2;
TCMAP *cols;
@@ -204,9 +200,7 @@ void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
evhttp_send_error(req, 503, "database not connected");
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
hash = (char *)evhttp_find_header(&args, "hash");
kvs = (char *)evhttp_find_header(&args, "kvs");
@@ -255,7 +249,7 @@ void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *json, *hash, *key, *value, *name;
+ char *json, *hash, *key, *value, *name;
struct evkeyvalq args;
struct json_object *jsobj, *jsobj2, *jsobj3;
TCMAP *cols;
@@ -265,9 +259,7 @@ void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
hash = (char *)evhttp_find_header(&args, "hash");
key = (char *)evhttp_find_header(&args, "key");
View
@@ -175,13 +175,11 @@ void db_error_to_json(int code, struct json_object *jsobj)
void box_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
double lat, lng, miles, ulat, ulng, llat, llng;
- char *uri, *json;
+ char *json;
struct evkeyvalq args;
struct json_object *jsobj;
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
argtof(&args, "lat", &lat, 0);
argtof(&args, "lng", &lng, 0);
@@ -201,13 +199,11 @@ void box_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void distance_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
double lat1, lng1, lat2, lng2;
- char *uri, *json;
+ char *json;
struct evkeyvalq args;
struct json_object *jsobj;
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
argtof(&args, "lat1", &lat1, 0);
argtof(&args, "lng1", &lng1, 0);
@@ -222,17 +218,15 @@ void distance_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void del_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *json, *id;
+ char *json, *id;
struct evkeyvalq args;
struct json_object *jsobj;
if (rdb == NULL) {
evhttp_send_error(req, 503, "database not connected");
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
id = (char *)evhttp_find_header(&args, "id");
if (id == NULL) {
@@ -255,7 +249,7 @@ void del_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
const char *value, *name;
- char *uri, *json, *hash, *key;
+ char *json, *hash, *key;
struct evkeyvalq args;
struct json_object *jsobj, *jsobj2, *jsobj3;
TCMAP *cols;
@@ -265,9 +259,7 @@ void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
hash = (char *)evhttp_find_header(&args, "hash");
key = (char *)evhttp_find_header(&args, "key");
@@ -314,7 +306,7 @@ void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *id, *data, *json, *key, *value;
+ char *id, *data, *json, *key, *value;
double lat, lng;
int x, y;
char buf[16];
@@ -326,9 +318,7 @@ void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
evhttp_send_error(req, 503, "database not connected");
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
argtof(&args, "lat", &lat, 0);
argtof(&args, "lng", &lng, 0);
@@ -370,7 +360,7 @@ void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
void search_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
- char *uri, *json;
+ char *json;
double lat, lng, distance, minlat, minlng, maxlat, maxlng, miles, lat2, lng2;
int x1, x2, y1, y2, id, max;
int total;
@@ -393,9 +383,7 @@ void search_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
return;
}
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
argtof(&args, "lat", &lat, 0);
argtof(&args, "lng", &lng, 0);
View
@@ -96,25 +96,13 @@ void get_cb(struct evhttp_request *req, struct evbuffer *evb,void *ctx)
{
struct evkeyvalq args;
char *uri, *key, *line, *newline, *delim, buf[32];
- char *tmp;
int seeks = 0;
_gettime(&ts1);
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
key = (char *)evhttp_find_header(&args, "key");
- // libevent (http.c:2149) is double decoding query string params (already done at http.c:2103)
- // we dont allow spaces in keys, so convert spaces to +
- tmp = key;
- while (*tmp++ != '\0') {
- if (*tmp == ' ') {
- *tmp = '+';
- }
- }
-
if(DEBUG) fprintf(stderr, "/get %s\n", key);
get_requests++;
@@ -160,9 +148,7 @@ void mget_cb(struct evhttp_request *req, struct evbuffer *evb,void *ctx)
_gettime(&ts1);
- uri = evhttp_decode_uri(req->uri);
- evhttp_parse_query(uri, &args);
- free(uri);
+ evhttp_parse_query(req->uri, &args);
mget_requests++;
TAILQ_FOREACH(pair, &args, next) {
@@ -172,16 +158,6 @@ void mget_cb(struct evhttp_request *req, struct evbuffer *evb,void *ctx)
//key = (char *)evhttp_find_header(&args, "key");
- // libevent (http.c:2149) is double decoding query string params
- // (already done at http.c:2103)
- // we dont allow spaces in keys, so convert spaces to +
- tmp = key;
- while (*tmp++ != '\0') {
- if (*tmp == ' ') {
- *tmp = '+';
- }
- }
-
if(DEBUG) fprintf(stderr, "/mget %s\n", key);
if ((line = map_search(key, strlen(key), (char *)map_base,

0 comments on commit 40373bf

Please sign in to comment.