Rewrite grab-client code.
[paraslash.git] / client.h
index 8f7b9a5dc1b47d4783da5ead2274cd87607a296f..fa965c354997ff9fef38ebba8b8220412ffeab84 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1,63 +1,76 @@
 /*
- * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2009 Andre Noll <maan@systemlinux.org>
  *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file client.h common client functions and exported symbols from client_common.c */
 
 #include <openssl/rc4.h>
+
+/**
+ * the different states of a connection from the view of the client
+ */
 enum {
+       /** tcp connection is established */
        CL_CONNECTED,
+       /** server sends the welcome message */
        CL_RECEIVED_WELCOME,
+       /** client sends the authentification request */
        CL_SENT_AUTH,
+       /** server sends a challenge */
        CL_RECEIVED_CHALLENGE,
+       /** clientd solves the challenge and sends the result */
        CL_SENT_CH_RESPONSE,
+       /** server accepts this authentication */
        CL_RECEIVED_PROCEED,
+       /** client sends the command */
        CL_SENT_COMMAND,
-       CL_SENDING_STDIN,
-       CL_RECEIVING_SERVER_OUTPUT
+       /** server expects data */
+       CL_SENDING,
+       /** client expects data */
+       CL_RECEIVING,
 };
 
+/** size of the receiving buffer */
 #define CLIENT_BUFSIZE 8192
 
-struct private_client_data {
+/**
+ * data specific to a client task
+ */
+struct client_task {
+       /** the state of the connection */
        int status;
-       int fd;
+       /** The file descriptor and the rc4 keys. */
+       struct rc4_context rc4c;
+       /** the configuration (including the command) */
        struct client_args_info conf;
+       /** the config file for client options */
        char *config_file;
+       /** the RSA private key */
        char *key_file;
+       /** paraslash user name */
        char *user;
-       RC4_KEY rc4_recv_key;
-       RC4_KEY rc4_send_key;
+       /** the client task structure */
        struct task task;
-       int eof;
-       char buf[CLIENT_BUFSIZE];
+       /** the buffer used for handshake and receiving */
+       char *buf;
+       /** number of bytes loaded in \p buf */
        size_t loaded;
+       /** non-zero if the pre_select hook added \p fd to the read fd set */
        int check_r;
+       /** non-zero if the pre_select hook added \p fd to the write fd set */
        int check_w;
+       /** the decrypted challenge */
        long unsigned challenge_nr;
-       /* only used if stdin gets sent to para_server */
+       /** pointer to the data to be sent to para_server */
        char *inbuf;
+       /** number of bytes loaded in \p inbuf */
        size_t *in_loaded;
-       int *in_eof;
+       /** Non-zero if input task encountered an eof or an error condition. */
+       int *in_error;
 };
 
-int client_open(struct private_client_data *pcd);
-void client_close(struct private_client_data *pcd);
-int client_parse_config(int argc, char *argv[],
-       struct private_client_data **pcd_ptr);
-void client_pre_select(struct sched *s, struct task *t);
-void client_post_select(struct sched *s, struct task *t);
+void client_close(struct client_task *ct);
+int client_open(int argc, char *argv[], struct client_task **ct,
+               int *loglevel);