Major audio format handler cleanups.
[paraslash.git] / client_common.c
index ee3a13f75911788f10f325c905a0ac0bc8fd6356..5bce7fb4c21d7a9dfaa6e7e0a220fe57bc7ad8e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -64,6 +64,7 @@ void client_close(struct client_task *ct)
                disable_crypt(ct->fd);
                close(ct->fd);
        }
                disable_crypt(ct->fd);
                close(ct->fd);
        }
+       free(ct->buf);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
@@ -116,6 +117,8 @@ static void client_pre_select(struct sched *s, struct task *t)
                }
                return;
        case CL_SENDING:
                }
                return;
        case CL_SENDING:
+               if (!ct->in_loaded) /* stdin task not yet started */
+                       return;
                if (*ct->in_loaded) {
                        PARA_INFO_LOG("loaded: %zd\n", *ct->in_loaded);
                        para_fd_set(ct->fd, &s->wfds, &s->max_fileno);
                if (*ct->in_loaded) {
                        PARA_INFO_LOG("loaded: %zd\n", *ct->in_loaded);
                        para_fd_set(ct->fd, &s->wfds, &s->max_fileno);
@@ -308,8 +311,9 @@ err_out:
  *
  * \param argc Usual argument count.
  * \param argv Usual argument vector.
  *
  * \param argc Usual argument count.
  * \param argv Usual argument vector.
- * \param pcd_ptr Points to dynamically allocated and initialized private client data
- * upon successful return.
+ * \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.
  *
  * 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.
@@ -317,16 +321,19 @@ err_out:
  *
  * \return Standard.
  */
  *
  * \return Standard.
  */
-int client_open(int argc, char *argv[], struct client_task **ct_ptr)
+int client_open(int argc, char *argv[], struct client_task **ct_ptr,
+               int *loglevel)
 {
        char *home = para_homedir();
 {
        char *home = para_homedir();
-       struct stat statbuf;
        int ret;
        struct client_task *ct = para_calloc(sizeof(struct client_task));
 
        int ret;
        struct client_task *ct = para_calloc(sizeof(struct client_task));
 
+       ct->buf = para_malloc(CLIENT_BUFSIZE);
        *ct_ptr = ct;
        ct->fd = -1;
        *ct_ptr = ct;
        ct->fd = -1;
-       ret = client_cmdline_parser(argc, argv, &ct->conf);
+       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)
        HANDLE_VERSION_FLAG("client", ct->conf);
        ret = -E_CLIENT_SYNTAX;
        if (!ct->conf.inputs_num)
@@ -341,23 +348,27 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr)
        ct->config_file = ct->conf.config_file_given?
                para_strdup(ct->conf.config_file_arg) :
                make_message("%s/.paraslash/client.conf", home);
        ct->config_file = ct->conf.config_file_given?
                para_strdup(ct->conf.config_file_arg) :
                make_message("%s/.paraslash/client.conf", home);
-       ret = stat(ct->config_file, &statbuf);
-       if (ret && ct->conf.config_file_given) {
+       ret = file_exists(ct->config_file);
+       if (!ret && ct->conf.config_file_given) {
                ret = -E_NO_CONFIG;
                goto out;
        }
                ret = -E_NO_CONFIG;
                goto out;
        }
-       if (!ret) {
+       if (ret) {
                struct client_cmdline_parser_params params = {
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
                struct client_cmdline_parser_params params = {
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
-                       .check_ambiguity = 0
+                       .check_ambiguity = 0,
+                       .print_errors = 0
                };
                };
-               client_cmdline_parser_config_file(ct->config_file,
-                       &ct->conf, &params);
+               ret = -E_BAD_CONFIG;
+               if (client_cmdline_parser_config_file(ct->config_file,
+                       &ct->conf, &params))
+                       goto out;
        }
        }
-       ret = 1;
-       PARA_INFO_LOG("loglevel: %d\n", ct->conf.loglevel_arg);
+       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,
        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,
@@ -372,4 +383,3 @@ out:
        }
        return ret;
 }
        }
        return ret;
 }
-