1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

NET: Move cache entry normalization to abort_connection

It simplifies the code and ensures that stuff like conn->from is properly
updated.
This commit is contained in:
Jonas Fonseca 2006-02-08 21:40:08 +01:00 committed by Jonas Fonseca
parent 4bfd40ec10
commit 854bb90d88
9 changed files with 8 additions and 29 deletions

View File

@ -724,6 +724,9 @@ abort_connection(struct connection *conn, enum connection_state state)
assertm(is_in_result_state(state), assertm(is_in_result_state(state),
"connection didn't end in result state (%d)", state); "connection didn't end in result state (%d)", state);
if (state == S_OK && conn->cached)
normalize_cache_entry(conn->cached, conn->from);
set_connection_state(conn, state); set_connection_state(conn, state);
if (conn->running) interrupt_connection(conn); if (conn->running) interrupt_connection(conn);

View File

@ -114,8 +114,6 @@ about_protocol_handler(struct connection *conn)
} }
#endif #endif
normalize_cache_entry(cached, len);
/* Set content to known type */ /* Set content to known type */
mem_free_set(&cached->content_type, stracpy("text/html")); mem_free_set(&cached->content_type, stracpy("text/html"));
} }

View File

@ -157,7 +157,6 @@ data_protocol_handler(struct connection *conn)
int datalen = strlen(data); int datalen = strlen(data);
add_fragment(cached, conn->from, data, datalen); add_fragment(cached, conn->from, data, datalen);
normalize_cache_entry(cached, datalen);
} }
mem_free(data); mem_free(data);

View File

@ -279,6 +279,7 @@ file_protocol_handler(struct connection *connection)
} else { } else {
add_fragment(cached, 0, page.source, page.length); add_fragment(cached, 0, page.source, page.length);
connection->from += page.length;
if (!cached->content_type) { if (!cached->content_type) {
unsigned char *ctype = null_or_stracpy(type); unsigned char *ctype = null_or_stracpy(type);
@ -287,15 +288,10 @@ file_protocol_handler(struct connection *connection)
* allocation. */ * allocation. */
if (type && !ctype) if (type && !ctype)
state = S_OUT_OF_MEM; state = S_OUT_OF_MEM;
else
normalize_cache_entry(cached, page.length);
/* Setup file read or directory listing for /* Setup file read or directory listing for
* viewing. */ * viewing. */
mem_free_set(&cached->content_type, ctype); mem_free_set(&cached->content_type, ctype);
} else {
normalize_cache_entry(cached, page.length);
} }
done_string(&page); done_string(&page);

View File

@ -27,15 +27,6 @@ struct module finger_protocol_module = struct_module(
/* done: */ NULL /* done: */ NULL
); );
static void
finger_end_request(struct connection *conn, enum connection_state state)
{
if (state == S_OK && conn->cached)
normalize_cache_entry(conn->cached, conn->from);
abort_connection(conn, state);
}
static void static void
finger_get_response(struct socket *socket, struct read_buffer *rb) finger_get_response(struct socket *socket, struct read_buffer *rb)
{ {
@ -50,7 +41,7 @@ finger_get_response(struct socket *socket, struct read_buffer *rb)
conn->cached = cached; conn->cached = cached;
if (socket->state == SOCKET_CLOSED) { if (socket->state == SOCKET_CLOSED) {
finger_end_request(conn, S_OK); abort_connection(conn, S_OK);
return; return;
} }

View File

@ -232,8 +232,6 @@ fsp_got_data(struct socket *socket, struct read_buffer *rb)
} }
if (!len) { if (!len) {
if (conn->from)
normalize_cache_entry(conn->cached, conn->from);
abort_connection(conn, S_OK); abort_connection(conn, S_OK);
return; return;
} }

View File

@ -346,7 +346,6 @@ end_gopher_connection(struct connection *conn, enum connection_state state)
conn->from -= 3; conn->from -= 3;
} }
#endif #endif
normalize_cache_entry(conn->cached, conn->from);
} }
abort_connection(conn, state); abort_connection(conn, state);

View File

@ -470,14 +470,12 @@ http_end_request(struct connection *conn, enum connection_state state,
{ {
shutdown_connection_stream(conn); shutdown_connection_stream(conn);
if (state == S_OK && conn->cached) {
normalize_cache_entry(conn->cached, !notrunc ? conn->from : -1);
}
if (conn->info && !((struct http_connection_info *) conn->info)->close if (conn->info && !((struct http_connection_info *) conn->info)->close
&& (!conn->socket->ssl) /* We won't keep alive ssl connections */ && (!conn->socket->ssl) /* We won't keep alive ssl connections */
&& (!get_opt_bool("protocol.http.bugs.post_no_keepalive") && (!get_opt_bool("protocol.http.bugs.post_no_keepalive")
|| !conn->uri->post)) { || !conn->uri->post)) {
if (state == S_OK && conn->cached)
normalize_cache_entry(conn->cached, !notrunc ? conn->from : -1);
set_connection_state(conn, state); set_connection_state(conn, state);
add_keepalive_connection(conn, HTTP_KEEPALIVE_TIMEOUT, NULL); add_keepalive_connection(conn, HTTP_KEEPALIVE_TIMEOUT, NULL);
} else { } else {

View File

@ -475,10 +475,8 @@ end_smb_connection(struct connection *conn)
if (smb_get_cache(conn)) return; if (smb_get_cache(conn)) return;
if (conn->from) { if (conn->from)
normalize_cache_entry(conn->cached, conn->from);
goto bye; goto bye;
}
/* Ensure termination by LF + NUL chars, memory for this /* Ensure termination by LF + NUL chars, memory for this
* was reserved by smb_read_text(). */ * was reserved by smb_read_text(). */
@ -507,7 +505,6 @@ end_smb_connection(struct connection *conn)
add_fragment(conn->cached, 0, page.source, page.length); add_fragment(conn->cached, 0, page.source, page.length);
conn->from += page.length; conn->from += page.length;
normalize_cache_entry(conn->cached, page.length);
done_string(&page); done_string(&page);
mem_free_set(&conn->cached->content_type, stracpy("text/html")); mem_free_set(&conn->cached->content_type, stracpy("text/html"));