static void merge_stat_info(struct cache_entry **src, int nr) { static struct cache_entry null_entry; struct cache_entry **dst = src; struct cache_entry *old = &null_entry; while (nr) { struct cache_entry *ce; ce = src[0]; /* We throw away original cache entries except for the stat information */ if (!ce_stage(ce)) { old = ce; src++; nr--; active_nr--; continue; } if (path_matches(ce, old) && same(ce, old)) *ce = *old; ce->ce_flags &= ~htons(CE_STAGEMASK); *dst++ = ce; src++; nr--; } }
static int matching_cookie (const struct cookie *cookie, const char *path, int connection_secure_p, int *path_goodness) { int pg; if (cookie->expiry_time < cookies_now) /* Ignore stale cookies. There is no need to unchain the cookie at this point -- Wget is a relatively short-lived application, and stale cookies will not be saved by `save_cookies'. */ return 0; if (cookie->secure && !connection_secure_p) /* Don't transmit secure cookies over an insecure connection. */ return 0; pg = path_matches (path, cookie->path); if (!pg) return 0; if (path_goodness) /* If the caller requested path_goodness, we return it. This is an optimization, so that the caller doesn't need to call path_matches() again. */ *path_goodness = pg; return 1; }
int ip_match(const struct pattern_spec *pattern, const struct http_request *http) { if (!(pattern->flags & PATTERN_SPEC_URL_PATTERN)) { /* It's not an URL pattern and thus shouldn't be matched against URLs */ return 0; } return (port_matches(http->port, pattern->pattern.url_spec.port_list) && host_matches(http, pattern) && path_matches(http->path, pattern)); }
static int fill(const char *path, int pathlen, int basename_offset, const struct attr_stack *stack, struct all_attrs_item *all_attrs, int rem) { for (; rem > 0 && stack; stack = stack->prev) { int i; const char *base = stack->origin ? stack->origin : ""; for (i = stack->num_matches - 1; 0 < rem && 0 <= i; i--) { const struct match_attr *a = stack->attrs[i]; if (a->is_macro) continue; if (path_matches(path, pathlen, basename_offset, &a->u.pat, base, stack->originlen)) rem = fill_one("fill", all_attrs, a, rem); } } return rem; }
static void trivially_merge_cache(struct cache_entry **src, int nr) { static struct cache_entry null_entry; struct cache_entry **dst = src; struct cache_entry *old = &null_entry; while (nr) { struct cache_entry *ce, *result; ce = src[0]; /* We throw away original cache entries except for the stat information */ if (!ce_stage(ce)) { old = ce; src++; nr--; active_nr--; continue; } if (nr > 2 && (result = merge_entries(ce, src[1], src[2])) != NULL) { /* * See if we can re-use the old CE directly? * That way we get the uptodate stat info. */ if (path_matches(result, old) && same(result, old)) *result = *old; ce = result; ce->ce_flags &= ~htons(CE_STAGEMASK); src += 2; nr -= 2; active_nr -= 2; } *dst++ = ce; src++; nr--; } }
static int check_path_match (const char *cookie_path, const char *path) { return path_matches (path, cookie_path); }
void handle_request(uint8_t *data, uint16_t length) { debug_string_p(PSTR("HTTP: ")); uint8_t type = 0; uint8_t path_start = 0; switch(data[0]) { case 'H': type = HTTP_METHOD_HEAD; path_start = 5; break; case 'G': type = HTTP_METHOD_GET; path_start = 4; break; case 'D': type = HTTP_METHOD_DELETE; path_start = 7; break; case 'P': switch(data[1]) { case 'O': type = HTTP_METHOD_POST; path_start = 5; break; case 'U': type = HTTP_METHOD_PUT; path_start = 4; break; default: type = 0; } break; } // Fetch path only if we have a type if (type) { uint8_t path_length = 0; uint8_t *path = &data[path_start]; while (*path++ > 0x20) { path_length++; } // Make space after path 0x00 (for path matching) data[path_start + path_length] = 0x00; // Debug path debug_string_n((char *)data, path_start + path_length); } // Get callback for type/path combination // path_services_get(&data[path_start]); uint8_t i; void (*callback)(uint8_t, uint8_t *); for (i = 0, callback = 0; i < EXT_WWW_SERVER_SERVICES_LIST_SIZE; i++) { if (path_services[i].path && path_matches(&data[path_start], path_services[i].path)) { callback = path_services[i].callback; break; } } // Prepare tcp reply rbuffer = tcp_prepare_reply(); rlength = 0; // Increase ack with length add_value_to_buffer(length, &buffer_out[TCP_PTR_ACK_NR], 4); // Set ACK flag tcp_add_flags(TCP_FLAG_ACK | TCP_FLAG_PUSH | TCP_FLAG_FIN); // Check if we can handle the request if (callback) { callback(type, data); } else { // Return 404, not found www_server_reply_header(HTTP_STATUS_404, HTTP_CONTENT_TYPE_PLAIN); www_server_reply_add_p(not_found); www_server_reply_send(); } debug_ok(); }