Merge commit 'meins/master'
[paraslash.git] / client.h
1 /*
2 * Copyright (C) 1997-2009 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file client.h Common client functions and exported symbols from client_common.c. */
8
9 #include <openssl/rc4.h>
10
11 /** The different states of a connection from the view of the client. */
12 enum {
13 /** TCP connection is established. */
14 CL_CONNECTED,
15 /** Server sends the welcome message. */
16 CL_RECEIVED_WELCOME,
17 /** Client sends the authentification request. */
18 CL_SENT_AUTH,
19 /** Server sends a challenge. */
20 CL_RECEIVED_CHALLENGE,
21 /** Client solves the challenge and sends the result. */
22 CL_SENT_CH_RESPONSE,
23 /** Server accepts this authentication. */
24 CL_RECEIVED_PROCEED,
25 /** Client sends the command. */
26 CL_SENT_COMMAND,
27 /** Server expects data. */
28 CL_SENDING,
29 /** Client expects data. */
30 CL_RECEIVING,
31 };
32
33 /** The size of the receiving buffer. */
34 #define CLIENT_BUFSIZE 8192
35
36 /** Data specific to a client task. */
37 struct client_task {
38 /** The state of the connection. */
39 int status;
40 /** The file descriptor and the rc4 keys. */
41 struct rc4_context rc4c;
42 /** The configuration (including the command). */
43 struct client_args_info conf;
44 /** The config file for client options. */
45 char *config_file;
46 /** The RSA private key. */
47 char *key_file;
48 /** Paraslash user name. */
49 char *user;
50 /** The client task structure. */
51 struct task task;
52 /** The buffer used for handshake and receiving. */
53 char *buf;
54 /** Number of bytes loaded in \a buf. */
55 size_t loaded;
56 /** Non-zero if the pre_select hook added \a fd to the read fd set. */
57 int check_r;
58 /** Non-zero if the pre_select hook added \a fd to the write fd set. */
59 int check_w;
60 /** Pointer to the data to be sent to para_server. */
61 char *inbuf;
62 /** Number of bytes loaded in \a inbuf. */
63 size_t *in_loaded;
64 /** Non-zero if input task encountered an eof or an error condition. */
65 int *in_error;
66 };
67
68 void client_close(struct client_task *ct);
69 int client_open(int argc, char *argv[], struct client_task **ct,
70 int *loglevel);