1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -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),
"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);
if (conn->running) interrupt_connection(conn);

View File

@ -114,8 +114,6 @@ about_protocol_handler(struct connection *conn)
}
#endif
normalize_cache_entry(cached, len);
/* Set content to known type */
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);
add_fragment(cached, conn->from, data, datalen);
normalize_cache_entry(cached, datalen);
}
mem_free(data);

View File

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

View File

@ -27,15 +27,6 @@ struct module finger_protocol_module = struct_module(
/* 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
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;
if (socket->state == SOCKET_CLOSED) {
finger_end_request(conn, S_OK);
abort_connection(conn, S_OK);
return;
}

View File

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

View File

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

View File

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

View File

@ -475,10 +475,8 @@ end_smb_connection(struct connection *conn)
if (smb_get_cache(conn)) return;
if (conn->from) {
normalize_cache_entry(conn->cached, conn->from);
if (conn->from)
goto bye;
}
/* Ensure termination by LF + NUL chars, memory for this
* 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);
conn->from += page.length;
normalize_cache_entry(conn->cached, page.length);
done_string(&page);
mem_free_set(&conn->cached->content_type, stracpy("text/html"));