Bug 1013: Don't assume errno is between 0 and 100000
[elinks.git] / src / protocol / finger / finger.c
blobc26069216807fd7a790eeb3ad4cd6cad7188b269
1 /* Internal "finger" protocol implementation */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include "elinks.h"
9 #include "cache/cache.h"
10 #include "intl/gettext/libintl.h"
11 #include "main/module.h"
12 #include "network/connection.h"
13 #include "network/socket.h"
14 #include "protocol/finger/finger.h"
15 #include "protocol/protocol.h"
16 #include "protocol/uri.h"
17 #include "util/memory.h"
18 #include "util/string.h"
20 struct module finger_protocol_module = struct_module(
21 /* name: */ N_("Finger"),
22 /* options: */ NULL,
23 /* hooks: */ NULL,
24 /* submodules: */ NULL,
25 /* data: */ NULL,
26 /* init: */ NULL,
27 /* done: */ NULL
30 static void
31 finger_get_response(struct socket *socket, struct read_buffer *rb)
33 struct connection *conn = socket->conn;
34 struct cache_entry *cached = get_cache_entry(conn->uri);
35 int l;
37 if (!cached) {
38 abort_connection(conn, connection_state(S_OUT_OF_MEM));
39 return;
41 conn->cached = cached;
43 if (socket->state == SOCKET_CLOSED) {
44 abort_connection(conn, connection_state(S_OK));
45 return;
48 l = rb->length;
49 conn->received += l;
51 if (add_fragment(conn->cached, conn->from, rb->data, l) == 1)
52 conn->tries = 0;
54 conn->from += l;
55 kill_buffer_data(rb, l);
56 read_from_socket(conn->socket, rb, connection_state(S_TRANS),
57 finger_get_response);
60 static void
61 finger_send_request(struct socket *socket)
63 struct connection *conn = socket->conn;
64 struct string req;
66 if (!init_string(&req)) return;
67 /* add_to_string(&req, &rl, "/W"); */
69 if (conn->uri->user) {
70 add_char_to_string(&req, ' ');
71 add_bytes_to_string(&req, conn->uri->user, conn->uri->userlen);
73 add_crlf_to_string(&req);
74 request_from_socket(socket, req.source, req.length,
75 connection_state(S_SENT),
76 SOCKET_END_ONCLOSE, finger_get_response);
77 done_string(&req);
80 void
81 finger_protocol_handler(struct connection *conn)
83 conn->from = 0;
84 make_connection(conn->socket, conn->uri, finger_send_request,
85 conn->cache_mode >= CACHE_MODE_FORCE_RELOAD);