31f2cc76140daf9aeb60180d0e89ad31f7a01b96
[paraslash.git] / client.h
1 /*
2 * Copyright (C) 1997-2007 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 /**
12 * the different states of a connection from the view of the client
13 */
14 enum {
15 /** tcp connection is established */
16 CL_CONNECTED,
17 /** server sends the welcome message */
18 CL_RECEIVED_WELCOME,
19 /** client sends the authentification request */
20 CL_SENT_AUTH,
21 /** server sends a challenge */
22 CL_RECEIVED_CHALLENGE,
23 /** clientd solves the challenge and sends the result */
24 CL_SENT_CH_RESPONSE,
25 /** server accepts this authentication */
26 CL_RECEIVED_PROCEED,
27 /** client sends the command */
28 CL_SENT_COMMAND,
29 /** server expects data */
30 CL_SENDING,
31 /** client expects data */
32 CL_RECEIVING,
33 };
34
35 /** size of the receiving buffer */
36 #define CLIENT_BUFSIZE 8192
37
38 /**
39 * data specific to a client task
40 */
41 struct private_client_data {
42 /** the state of the connection */
43 int status;
44 /** the file descriptor */
45 int fd;
46 /** the configuration (including the command) */
47 struct client_args_info conf;
48 /** the config file for client options */
49 char *config_file;
50 /** the RSA private key */
51 char *key_file;
52 /** paraslash user name */
53 char *user;
54 /** session key for receiving data */
55 RC4_KEY rc4_recv_key;
56 /** session key for sending data */
57 RC4_KEY rc4_send_key;
58 /** the client task structure */
59 struct task task;
60 /** non-zero if task is unregistered */
61 int error;
62 /** the buffer used for handshake and receiving */
63 char buf[CLIENT_BUFSIZE];
64 /** number of bytes loaded in \p buf */
65 size_t loaded;
66 /** non-zero if the pre_select hook added \p fd to the read fd set */
67 int check_r;
68 /** non-zero if the pre_select hook added \p fd to the write fd set */
69 int check_w;
70 /** the decrypted challenge */
71 long unsigned challenge_nr;
72 /** pointer to the data to be sent to para_server */
73 char *inbuf;
74 /** number of bytes loaded in \p inbuf */
75 size_t *in_loaded;
76 /** Non-zero if input task encountered an eof or an error condition. */
77 int *in_error;
78 };
79
80 void client_close(struct private_client_data *pcd);
81 int client_open(int argc, char *argv[], struct private_client_data **pcd_ptr);
82 void client_pre_select(struct sched *s, struct task *t);
83 void client_post_select(struct sched *s, struct task *t);