@@ -9930,15 +9930,18 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
99309930}
99319931
99329932/*
9933- * Get the "mode" entry from "dict", if it exists, and parse the mode name .
9934- * If the mode is invalide return FAIL.
9933+ * Get the option entries from "dict", and parse them .
9934+ * If an option value is invalid return FAIL.
99359935 */
99369936 static int
9937- get_mode_arg (dict_T *dict, jobopt_T *opt)
9937+ get_job_options (dict_T *dict, jobopt_T *opt)
99389938{
99399939 dictitem_T *item;
99409940 char_u *mode;
99419941
9942+ if (dict == NULL)
9943+ return OK;
9944+
99429945 if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL)
99439946 {
99449947 mode = get_tv_string(&item->di_tv);
@@ -9956,6 +9959,17 @@ get_mode_arg(dict_T *dict, jobopt_T *opt)
99569959 return FAIL;
99579960 }
99589961 }
9962+
9963+ if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL)
9964+ {
9965+ opt->jo_callback = get_callback(&item->di_tv);
9966+ if (opt->jo_callback == NULL)
9967+ {
9968+ EMSG2(_(e_invarg2), "callback");
9969+ return FAIL;
9970+ }
9971+ }
9972+
99599973 return OK;
99609974}
99619975
@@ -9966,7 +9980,6 @@ get_mode_arg(dict_T *dict, jobopt_T *opt)
99669980f_ch_open(typval_T *argvars, typval_T *rettv)
99679981{
99689982 char_u *address;
9969- char_u *callback = NULL;
99709983 char_u *p;
99719984 char *rest;
99729985 int port;
@@ -10004,20 +10017,19 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
1000410017 }
1000510018
1000610019 options.jo_mode = MODE_JSON;
10020+ options.jo_callback = NULL;
1000710021 if (argvars[1].v_type == VAR_DICT)
1000810022 {
1000910023 dict_T *dict = argvars[1].vval.v_dict;
1001010024 dictitem_T *item;
1001110025
1001210026 /* parse argdict */
10013- if (get_mode_arg (dict, &options) == FAIL)
10027+ if (get_job_options (dict, &options) == FAIL)
1001410028 return;
1001510029 if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL)
1001610030 waittime = get_tv_number(&item->di_tv);
1001710031 if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL)
1001810032 timeout = get_tv_number(&item->di_tv);
10019- if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL)
10020- callback = get_callback(&item->di_tv);
1002110033 }
1002210034 if (waittime < 0 || timeout < 0)
1002310035 {
@@ -10029,10 +10041,8 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
1002910041 if (channel != NULL)
1003010042 {
1003110043 rettv->vval.v_channel = channel;
10032- channel_set_mode (channel, options.jo_mode );
10044+ channel_set_options (channel, & options);
1003310045 channel_set_timeout(channel, timeout);
10034- if (callback != NULL && *callback != NUL)
10035- channel_set_callback(channel, callback);
1003610046 }
1003710047}
1003810048
@@ -10082,16 +10092,23 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun)
1008210092{
1008310093 channel_T *channel;
1008410094 char_u *callback = NULL;
10095+ jobopt_T options;
1008510096
1008610097 channel = get_channel_arg(&argvars[0]);
1008710098 if (channel == NULL)
1008810099 return NULL;
1008910100
1009010101 if (argvars[2].v_type != VAR_UNKNOWN)
1009110102 {
10092- callback = get_callback(&argvars[2]);
10093- if (callback == NULL)
10103+ if (argvars[2].v_type != VAR_DICT)
10104+ {
10105+ EMSG(_(e_invarg));
10106+ return NULL;
10107+ }
10108+ options.jo_callback = NULL;
10109+ if (get_job_options(argvars[2].vval.v_dict, &options) == FAIL)
1009410110 return NULL;
10111+ callback = options.jo_callback;
1009510112 }
1009610113 /* Set the callback. An empty callback means no callback and not reading
1009710114 * the response. */
@@ -14511,17 +14528,15 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1451114528
1451214529 /* Default mode is NL. */
1451314530 options.jo_mode = MODE_NL;
14531+ options.jo_callback = NULL;
1451414532 if (argvars[1].v_type != VAR_UNKNOWN)
1451514533 {
14516- dict_T *dict;
14517-
1451814534 if (argvars[1].v_type != VAR_DICT)
1451914535 {
1452014536 EMSG(_(e_invarg));
1452114537 return;
1452214538 }
14523- dict = argvars[1].vval.v_dict;
14524- if (get_mode_arg(dict, &options) == FAIL)
14539+ if (get_job_options(argvars[1].vval.v_dict, &options) == FAIL)
1452514540 return;
1452614541 }
1452714542
0 commit comments