+ close(ct->rc4c.fd);
+ ct->rc4c.fd = -1;
+ return ret;
+}
+
+/**
+ * Open connection to para_server.
+ *
+ * \param argc Usual argument count.
+ * \param argv Usual argument vector.
+ * \param ct_ptr Points to dynamically allocated and initialized client task
+ * struct upon successful return.
+ * \param loglevel If not \p NULL, the number of the loglevel is stored here.
+ *
+ * Check the command line options given by \a argc and argv, set default values
+ * for user name and rsa key file, read further option from the config file.
+ * Finally, establish a connection to para_server.
+ *
+ * \return Standard.
+ */
+int client_open(int argc, char *argv[], struct client_task **ct_ptr,
+ int *loglevel)
+{
+ char *home = para_homedir();
+ int ret;
+ struct client_task *ct = para_calloc(sizeof(struct client_task));
+
+ ct->buf = para_malloc(CLIENT_BUFSIZE);
+ *ct_ptr = ct;
+ ct->rc4c.fd = -1;
+ ret = -E_CLIENT_SYNTAX;
+ if (client_cmdline_parser(argc, argv, &ct->conf))
+ goto out;
+ HANDLE_VERSION_FLAG("client", ct->conf);
+ ret = -E_CLIENT_SYNTAX;
+ if (!ct->conf.inputs_num)
+ goto out;
+ ct->user = ct->conf.user_given?
+ para_strdup(ct->conf.user_arg) : para_logname();
+
+ ct->key_file = ct->conf.key_file_given?
+ para_strdup(ct->conf.key_file_arg) :
+ make_message("%s/.paraslash/key.%s", home, ct->user);
+
+ ct->config_file = ct->conf.config_file_given?
+ para_strdup(ct->conf.config_file_arg) :
+ make_message("%s/.paraslash/client.conf", home);
+ ret = file_exists(ct->config_file);
+ if (!ret && ct->conf.config_file_given) {
+ ret = -E_NO_CONFIG;
+ goto out;
+ }
+ if (ret) {
+ struct client_cmdline_parser_params params = {
+ .override = 0,
+ .initialize = 0,
+ .check_required = 0,
+ .check_ambiguity = 0,
+ .print_errors = 0
+ };
+ ret = -E_BAD_CONFIG;
+ if (client_cmdline_parser_config_file(ct->config_file,
+ &ct->conf, ¶ms))
+ goto out;
+ }
+ if (loglevel)
+ *loglevel = get_loglevel_by_name(ct->conf.loglevel_arg);
+ PARA_INFO_LOG("loglevel: %s\n", ct->conf.loglevel_arg);
+ PARA_INFO_LOG("config_file: %s\n", ct->config_file);
+ PARA_INFO_LOG("key_file: %s\n", ct->key_file);
+ PARA_NOTICE_LOG("connecting %s:%d\n", ct->conf.hostname_arg,
+ ct->conf.server_port_arg);
+ ret = client_connect(ct);
+out:
+ free(home);
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ client_close(ct);
+ *ct_ptr = NULL;
+ }