Beispiel #1
0
static VALUE 
_create_request_hash(struct conn *c, RouteRef route, const char* body, int bodylen) {
  const char *method, *uri, *query;
  VALUE hash_headers;
  struct parsed_header* h;
  int i;

	VALUE hash = createHash();

	addStrToHash(hash, "application", 
    route->_application, strlen(route->_application));

	addStrToHash(hash, "model", 
    route->_model, strlen(route->_model));

	if (route->_action!=NULL) {
		const char* actionName = route->_action;
		addStrToHash(hash, "action", actionName, strlen(actionName));
	}
	
	if (route->_id!=NULL) {
		const char* _id = route->_id;
		addStrToHash(hash, "id", _id, strlen(_id));
	}
	
  method = _shttpd_known_http_methods[c->method].ptr;
	addStrToHash(hash, "request-method", method, strlen(method));
		
	uri = c->uri;
	addStrToHash(hash, "request-uri", uri, strlen(uri));
	
	query = c->query == NULL ? "" : c->query;
	addStrToHash(hash, "request-query", query, strlen(query));
	
	hash_headers = createHash();
  h = &c->ch.cl;
	for (i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) {
		if (h->_name) {
			char* name = trim(_shttpd_strdup(h->_name));
			if (h->_type == HDR_STRING) {
				addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len);
			} else if (h->_type == HDR_INT) {
				addIntToHash(hash_headers, name, h->_v.v_big_int);
			} else if (h->_type == HDR_DATE) {
				addTimeToHash(hash_headers, name, h->_v.v_time);
			}
			free(name);
		}
		h++;
	}
	addHashToHash(hash,"headers",hash_headers);
	
  if (bodylen > 0) {
		addStrToHash(hash, "request-body", body, bodylen);
	}
	
	return hash;
}
Beispiel #2
0
static VALUE 
_CreateRequestHash(HttpContextRef context, RouteRef route) {
	DBG(("Creating Req Hash\n"));
	
	VALUE hash = createHash();

	const char* applicationName = route->_application;
	addStrToHash(hash, "application", applicationName, strlen(applicationName));

	const char* modelName = route->_model;
	addStrToHash(hash, "model", modelName, strlen(modelName));

	if (route->_action!=NULL) {
		const char* actionName = route->_action;
		addStrToHash(hash, "action", actionName, strlen(actionName));
	}
	
	if (route->_id!=NULL) {
		const char* _id = route->_id;
		addStrToHash(hash, "id", _id, strlen(_id));
	}
	
	const char* method = HTTPGetMethod(context->_request->_method);
	addStrToHash(hash, "request-method", method, strlen(method));
	
	const char* uri = context->_request->_uri;
	addStrToHash(hash, "request-uri", uri, strlen(uri));
	
	const char* query = context->_request->_query == NULL ? "" : context->_request->_query;
	addStrToHash(hash, "request-query", query, strlen(query));
	
	VALUE hash_headers = createHash();
	struct parsed_header* h = &context->_request->_cheaders.cl;
	for (int i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) {
		if (h->_name) {
			char* name = trim(strdup(h->_name));
			if (h->_type == HDR_STRING) {
				addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len);
			} else if (h->_type == HDR_INT) {
				addIntToHash(hash_headers, name, h->_v.v_big_int);
			} else if (h->_type == HDR_DATE) {
				addTimeToHash(hash_headers, name, h->_v.v_time);
			}
			free(name);
		}
		h++;
	}
	addHashToHash(hash,"headers",hash_headers);
	
	int buflen = CFDataGetLength(context->_rcvdBytes);
	if (buflen > 0) {
		addStrToHash(hash, "request-body", 
					 (char*)CFDataGetBytePtr(context->_rcvdBytes), buflen);
	}
	
	return hash;
}