]> git.tue.mpg.de Git - paraslash.git/commitdiff
client: introduce client_open()
authorAndre <maan@p133.(none)>
Mon, 12 Jun 2006 04:01:55 +0000 (06:01 +0200)
committerAndre <maan@p133.(none)>
Mon, 12 Jun 2006 04:01:55 +0000 (06:01 +0200)
and reorder some functions.

client.c

index 0380d5678b3aae84d34bdb62838c3f9cd475cf82..3fc673e7c6386238b4cada69e2ca2dff3df4c357 100644 (file)
--- a/client.c
+++ b/client.c
@@ -51,6 +51,19 @@ INIT_CLIENT_ERRLISTS;
 
 static struct private_client_data *pcd;
 
+static void rc4_send(unsigned long len, const unsigned char *indata,
+               unsigned char *outdata)
+{
+       RC4(&pcd->rc4_send_key, len, indata, outdata);
+}
+
+static void rc4_recv(unsigned long len, const unsigned char *indata,
+               unsigned char *outdata)
+{
+       RC4(&pcd->rc4_recv_key, len, indata, outdata);
+}
+
+
 /*
  * client log function
  */
@@ -78,6 +91,16 @@ static void client_close(struct private_client_data *pcd)
        free(pcd);
 }
 
+static void append_str(char **data, const char* append)
+{
+       if (*data) {
+               char *tmp = make_message("%s\n%s", *data, append);
+               free(*data);
+               *data = tmp;
+       } else
+               *data = para_strdup(append);
+}
+
 static int client_parse_config(int argc, char *argv[],
                struct private_client_data **pcd_ptr)
 {
@@ -119,29 +142,6 @@ out:
        return ret;
 }
 
-static void rc4_send(unsigned long len, const unsigned char *indata,
-               unsigned char *outdata)
-{
-       RC4(&pcd->rc4_send_key, len, indata, outdata);
-}
-
-static void rc4_recv(unsigned long len, const unsigned char *indata,
-               unsigned char *outdata)
-{
-       RC4(&pcd->rc4_recv_key, len, indata, outdata);
-}
-
-static void append_str(char **data, const char* append)
-{
-       if (*data) {
-               char *tmp = make_message("%s\n%s", *data, append);
-               free(*data);
-               *data = tmp;
-       } else
-               *data = para_strdup(append);
-}
-
-
 static int send_stdin(int fd)
 {
        char buf[8192];
@@ -159,6 +159,36 @@ static int send_stdin(int fd)
        return 1;
 }
 
+static int client_open(struct private_client_data *pcd)
+{
+       int ret;
+       struct hostent *he;
+       struct sockaddr_in their_addr;
+
+       /* get the host info */
+       PARA_NOTICE_LOG("getting host info of %s\n",
+               pcd->conf.hostname_arg);
+       ret = get_host_info(pcd->conf.hostname_arg, &he);
+       if (ret < 0)
+               goto out;
+       /* get new socket */
+       ret = get_socket();
+       if (ret < 0)
+               goto out;
+       pcd->fd = ret;
+       /* init their_addr */
+       init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
+       /* connect */
+       PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg);
+       ret = para_connect(pcd->fd, &their_addr);
+       if (ret < 0)
+               goto out;
+       ret = 1;
+out:
+       return ret;
+}
+
+
 /*
  * MAIN
  */
@@ -190,25 +220,7 @@ int main(int argc, char *argv[])
                pcd->conf.hostname_arg,
                pcd->conf.server_port_arg
        );
-       /* concat args */
-       for (i = 0; i < pcd->conf.inputs_num; i++)
-               append_str(&command, pcd->conf.inputs[i]);
-       /* get the host info */
-       PARA_NOTICE_LOG("getting host info of %s\n",
-               pcd->conf.hostname_arg);
-       ret = get_host_info(pcd->conf.hostname_arg, &he);
-       if (ret < 0)
-               goto out;
-       /* get new socket */
-       ret = get_socket();
-       if (ret < 0)
-               goto out;
-       pcd->fd = ret;
-       /* init their_addr */
-       init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
-       /* connect */
-       PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg);
-       ret = para_connect(pcd->fd, &their_addr);
+       ret = client_open(pcd);
        if (ret < 0)
                goto out;
        /* receive welcome message */
@@ -267,6 +279,9 @@ int main(int argc, char *argv[])
                        rc4_buf[0], rc4_buf[1], rc4_buf[2], rc4_buf[3]);
                enable_crypt(pcd->fd, rc4_recv, rc4_send);
        }
+       /* concat args */
+       for (i = 0; i < pcd->conf.inputs_num; i++)
+               append_str(&command, pcd->conf.inputs[i]);
        /* send command */
        PARA_INFO_LOG("--> %s\n", command);
        ret = send_buffer(pcd->fd, command);