Add the mosx Authors to CREDITS
[paraslash.git] / client.h
1 /*
2  * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  *
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  *
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 /** \file client.h common client functions and exported symbols from client_common.c */
20
21 #include <openssl/rc4.h>
22
23 /**
24  * the different states of a connection from the view of the client
25  */
26 enum {
27         /** tcp connection is established */
28         CL_CONNECTED,
29         /** server sends the welcome message */
30         CL_RECEIVED_WELCOME,
31         /** client sends the authentification request */
32         CL_SENT_AUTH,
33         /** server sends a challenge */
34         CL_RECEIVED_CHALLENGE,
35         /** clientd solves the challenge and sends the result */
36         CL_SENT_CH_RESPONSE,
37         /** server accepts this authentication */
38         CL_RECEIVED_PROCEED,
39         /** client sends the command */
40         CL_SENT_COMMAND,
41         /** server expects data */
42         CL_SENDING,
43         /** client expects data */
44         CL_RECEIVING,
45 };
46
47 #define CLIENT_BUFSIZE 8192
48
49 /**
50  * data specific to a client task
51  */
52 struct private_client_data {
53         /** the state of the connection */
54         int status;
55         /** the file descriptor */
56         int fd;
57         /** the configuration (including the command) */
58         struct client_args_info conf;
59         /** the config file for client options */
60         char *config_file;
61         /** the RSA private key */
62         char *key_file;
63         /** paraslash user name */
64         char *user;
65         /** session key for receiving data */
66         RC4_KEY rc4_recv_key;
67         /** session key for sending data */
68         RC4_KEY rc4_send_key;
69         /** the client task structure */
70         struct task task;
71         /** non-zero if task is unregistered */
72         int eof;
73         /** the buffer used for handshake and receiving */
74         char buf[CLIENT_BUFSIZE];
75         /** number of bytes loaded in \p buf */
76         size_t loaded;
77         /** non-zero if the pre_select hook added \p fd to the read fd set */
78         int check_r;
79         /** non-zero if the pre_select hook added \p fd to the write fd set */
80         int check_w;
81         /** the decrypted challenge */
82         long unsigned challenge_nr;
83         /** pointer to the data to be sent to para_server */
84         char *inbuf;
85         /** number of bytes loaded in \p inbuf */
86         size_t *in_loaded;
87         /** non-zero if input task encountered an eof or an errro condition */
88         int *in_eof;
89 };
90
91 int client_open(struct private_client_data *pcd);
92 void client_close(struct private_client_data *pcd);
93 int client_parse_config(int argc, char *argv[],
94         struct private_client_data **pcd_ptr);
95 void client_pre_select(struct sched *s, struct task *t);
96 void client_post_select(struct sched *s, struct task *t);