void accept_request(dino_http_site_t *dino_site, dino_handle_t *dhandle) { // Setup DHANDLE: // if (!read_request(&dhandle->http)) { bad_request(dhandle->http.socket); } else { // Parse the URL Parameters. // stack_char_ptr_t *url_stack = stack_ptr_parse(NULL, string_buffer_c_string(dhandle->http.request.url), "/"); // Search for a match... // dino_route_t *route = list_method_find(dino_site->list, dhandle->http.request.method, url_stack); // Do we have a route? // if (NULL != route) { invoke_method(route, &dhandle->http, url_stack); } else { fprintf(stderr, "[ERROR] Path %s not found; \n\r", string_buffer_c_string(dhandle->http.request.url)); } stack_ptr_free(url_stack); } }
bool add_method_to_site(dino_http_method method, DHANDLE dhandle, http_verb_func verb_func, const char *name, const char *path) { if (NULL == dhandle) { return false; } dino_http_site_t *dino_site = cast_dhandle_site(dhandle); if (NULL != list_find(dino_site->list, name)) { return false; } dino_route_t *dino_route = list_add_new_item(&dino_site->list); // Build name for method // const char *method_name = http_method_prefix_string(method); dino_route->name = dino_string_new_with_size(strlen(method_name) + strlen(name)); dino_string_append_str(dino_route->name, method_name); dino_string_append_str(dino_route->name, name); // Store the path // dino_route->path = dino_string_new_with_str(path); // Parse the path, we need to see if there are any :[name] directives // dino_route->stack = stack_ptr_parse(dino_route->stack, dino_string_c_ptr(dino_route->path), "/"); // Save callback function pointer // dino_route->verb_func = verb_func; dino_route->method = method; return true; }