diff --git a/agentf.c b/agentf.c index db4f702a..4b859f44 100644 --- a/agentf.c +++ b/agentf.c @@ -15,8 +15,8 @@ typedef struct agentf { SshChannel *c; bufchain inbuffer; agent_pending_query *pending; - int input_wanted; - int rcvd_eof; + bool input_wanted; + bool rcvd_eof; Channel chan; } agentf; @@ -142,10 +142,10 @@ static void agentf_callback(void *vctx, void *reply, int replylen) } static void agentf_free(Channel *chan); -static int agentf_send(Channel *chan, int is_stderr, const void *, int); +static int agentf_send(Channel *chan, bool is_stderr, const void *, int); static void agentf_send_eof(Channel *chan); static char *agentf_log_close_msg(Channel *chan); -static void agentf_set_input_wanted(Channel *chan, int wanted); +static void agentf_set_input_wanted(Channel *chan, bool wanted); static const struct ChannelVtable agentf_channelvt = { agentf_free, @@ -196,7 +196,7 @@ static void agentf_free(Channel *chan) sfree(af); } -static int agentf_send(Channel *chan, int is_stderr, +static int agentf_send(Channel *chan, bool is_stderr, const void *data, int length) { assert(chan->vt == &agentf_channelvt); @@ -233,7 +233,7 @@ static char *agentf_log_close_msg(Channel *chan) return dupstr("Agent-forwarding connection closed"); } -static void agentf_set_input_wanted(Channel *chan, int wanted) +static void agentf_set_input_wanted(Channel *chan, bool wanted) { assert(chan->vt == &agentf_channelvt); agentf *af = container_of(chan, agentf, chan); diff --git a/be_misc.c b/be_misc.c index 8c1ff481..79a6d33c 100644 --- a/be_misc.c +++ b/be_misc.c @@ -11,7 +11,7 @@ void backend_socket_log(Seat *seat, LogContext *logctx, int type, SockAddr *addr, int port, const char *error_msg, int error_code, Conf *conf, - int session_started) + bool session_started) { char addrbuf[256], *msg; diff --git a/callback.c b/callback.c index b0ecbca2..076d7b4d 100644 --- a/callback.c +++ b/callback.c @@ -99,9 +99,9 @@ void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx) cb->next = NULL; } -int run_toplevel_callbacks(void) +bool run_toplevel_callbacks(void) { - int done_something = false; + bool done_something = false; if (cbhead) { /* @@ -127,7 +127,7 @@ int run_toplevel_callbacks(void) return done_something; } -int toplevel_callback_pending(void) +bool toplevel_callback_pending(void) { return cbcurr != NULL || cbhead != NULL; } diff --git a/cmdgen.c b/cmdgen.c index 16c63a5d..4ef972f3 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -114,7 +114,7 @@ void showversion(void) sfree(buildinfo_text); } -void usage(int standalone) +void usage(bool standalone) { fprintf(standalone ? stderr : stdout, "Usage: puttygen ( keyfile | -t type [ -b bits ] )\n" @@ -163,7 +163,7 @@ void help(void) ); } -static int move(char *from, char *to) +static bool move(char *from, char *to) { int ret; @@ -208,7 +208,7 @@ static char *readpassphrase(const char *filename) #define DEFAULT_RSADSA_BITS 2048 /* For Unix in particular, but harmless if this main() is reused elsewhere */ -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; int main(int argc, char **argv) { @@ -220,8 +220,8 @@ int main(int argc, char **argv) OPENSSH_NEW, SSHCOM } outtype = PRIVATE; int bits = -1; char *comment = NULL, *origcomment = NULL; - int change_passphrase = false; - int errs = false, nogo = false; + bool change_passphrase = false; + bool errs = false, nogo = false; int intype = SSH_KEYTYPE_UNOPENABLE; int sshver = 0; struct ssh2_userkey *ssh2key = NULL; @@ -229,7 +229,7 @@ int main(int argc, char **argv) strbuf *ssh2blob = NULL; char *ssh2alg = NULL; char *old_passphrase = NULL, *new_passphrase = NULL; - int load_encrypted; + bool load_encrypted; progfn_t progressfn = is_interactive() ? progress_update : no_progress; const char *random_device = NULL; @@ -735,7 +735,7 @@ int main(int argc, char **argv) } else { const char *error = NULL; - int encrypted; + bool encrypted; assert(infile != NULL); @@ -930,7 +930,8 @@ int main(int argc, char **argv) outfilename = filename_from_str(outfile ? outfile : ""); switch (outtype) { - int ret, real_outtype; + bool ret; + int real_outtype; case PRIVATE: if (sshver == 1) { diff --git a/cmdline.c b/cmdline.c index ea084e45..f71a7763 100644 --- a/cmdline.c +++ b/cmdline.c @@ -87,7 +87,7 @@ void cmdline_cleanup(void) */ int cmdline_get_passwd_input(prompts_t *p) { - static int tried_once = 0; + static bool tried_once = false; /* * We only handle prompts which don't echo (which we assume to be @@ -109,7 +109,7 @@ int cmdline_get_passwd_input(prompts_t *p) smemclr(cmdline_password, strlen(cmdline_password)); sfree(cmdline_password); cmdline_password = NULL; - tried_once = 1; + tried_once = true; return 1; } @@ -125,13 +125,13 @@ int cmdline_get_passwd_input(prompts_t *p) */ int cmdline_tooltype = 0; -static int cmdline_check_unavailable(int flag, const char *p) +static bool cmdline_check_unavailable(int flag, const char *p) { if (cmdline_tooltype & flag) { cmdline_error("option \"%s\" not available in this tool", p); - return 1; + return true; } - return 0; + return false; } #define UNAVAILABLE_IN(flag) do { \ @@ -159,8 +159,8 @@ static int cmdline_check_unavailable(int flag, const char *p) if (need_save < 0) return x; \ } while (0) -static int seen_hostname_argument = false; -static int seen_port_argument = false; +static bool seen_hostname_argument = false; +static bool seen_port_argument = false; int cmdline_process_param(const char *p, char *value, int need_save, Conf *conf) @@ -881,7 +881,7 @@ void cmdline_run_saved(Conf *conf) } } -int cmdline_host_ok(Conf *conf) +bool cmdline_host_ok(Conf *conf) { /* * Return true if the command-line arguments we've processed in diff --git a/conf.c b/conf.c index 8eee8447..f97b47df 100644 --- a/conf.c +++ b/conf.c @@ -410,7 +410,7 @@ void conf_set_bool(Conf *conf, int primary, bool value) assert(subkeytypes[primary] == TYPE_NONE); assert(valuetypes[primary] == TYPE_BOOL); entry->key.primary = primary; - entry->value.u.boolval = value; + entry->value.u.boolval = value; conf_insert(conf, entry); } @@ -421,11 +421,12 @@ void conf_set_int(Conf *conf, int primary, int value) assert(subkeytypes[primary] == TYPE_NONE); assert(valuetypes[primary] == TYPE_INT); entry->key.primary = primary; - entry->value.u.intval = value; + entry->value.u.intval = value; conf_insert(conf, entry); } -void conf_set_int_int(Conf *conf, int primary, int secondary, int value) +void conf_set_int_int(Conf *conf, int primary, + int secondary, int value) { struct conf_entry *entry = snew(struct conf_entry); @@ -537,7 +538,7 @@ void conf_serialise(BinarySink *bs, Conf *conf) put_uint32(bs, 0xFFFFFFFFU); } -int conf_deserialise(Conf *conf, BinarySource *src) +bool conf_deserialise(Conf *conf, BinarySource *src) { struct conf_entry *entry; unsigned primary; diff --git a/config.c b/config.c index a4e3f778..f30a581f 100644 --- a/config.c +++ b/config.c @@ -85,9 +85,9 @@ void conf_checkbox_handler(union control *ctrl, dlgparam *dlg, key = ctrl->checkbox.context.i; if (key & CHECKBOX_INVERT) { key &= ~CHECKBOX_INVERT; - invert = 1; + invert = true; } else - invert = 0; + invert = false; /* * C lacks a logical XOR, so the following code uses the idiom @@ -159,7 +159,8 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg, Conf *conf = (Conf *)data; if (event == EVENT_REFRESH) { - dlg_filesel_set(ctrl, dlg, conf_get_filename(conf, key)); + dlg_filesel_set( + ctrl, dlg, conf_get_filename(conf, key)); } else if (event == EVENT_VALCHANGE) { Filename *filename = dlg_filesel_get(ctrl, dlg); conf_set_filename(conf, key, filename); @@ -174,7 +175,8 @@ void conf_fontsel_handler(union control *ctrl, dlgparam *dlg, Conf *conf = (Conf *)data; if (event == EVENT_REFRESH) { - dlg_fontsel_set(ctrl, dlg, conf_get_fontspec(conf, key)); + dlg_fontsel_set( + ctrl, dlg, conf_get_fontspec(conf, key)); } else if (event == EVENT_VALCHANGE) { FontSpec *fontspec = dlg_fontsel_get(ctrl, dlg); conf_set_fontspec(conf, key, fontspec); @@ -634,7 +636,7 @@ struct sessionsaver_data { union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton; union control *okbutton, *cancelbutton; struct sesslist sesslist; - int midsession; + bool midsession; char *savedsession; /* the current contents of ssd->editbox */ }; @@ -651,14 +653,15 @@ static void sessionsaver_data_free(void *ssdv) * any, as this is done in more than one place below. Returns 0 for * failure. */ -static int load_selected_session(struct sessionsaver_data *ssd, - dlgparam *dlg, Conf *conf, int *maybe_launch) +static bool load_selected_session( + struct sessionsaver_data *ssd, + dlgparam *dlg, Conf *conf, bool *maybe_launch) { int i = dlg_listbox_index(ssd->listbox, dlg); - int isdef; + bool isdef; if (i < 0) { dlg_beep(dlg); - return 0; + return false; } isdef = !strcmp(ssd->sesslist.sessions[i], "Default Settings"); load_settings(ssd->sesslist.sessions[i], conf); @@ -670,7 +673,7 @@ static int load_selected_session(struct sessionsaver_data *ssd, /* Restore the selection, which might have been clobbered by * changing the value of the edit box. */ dlg_listbox_select(ssd->listbox, dlg, i); - return 1; + return true; } static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, @@ -713,7 +716,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, dlg_listbox_select(ssd->listbox, dlg, top); } } else if (event == EVENT_ACTION) { - int mbl = false; + bool mbl = false; if (!ssd->midsession && (ctrl == ssd->listbox || (ssd->loadbutton && ctrl == ssd->loadbutton))) { @@ -729,7 +732,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, dlg_end(dlg, 1); /* it's all over, and succeeded */ } } else if (ctrl == ssd->savebutton) { - int isdef = !strcmp(ssd->savedsession, "Default Settings"); + bool isdef = !strcmp(ssd->savedsession, "Default Settings"); if (!ssd->savedsession[0]) { int i = dlg_listbox_index(ssd->listbox, dlg); if (i < 0) { @@ -779,7 +782,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, if (dlg_last_focused(ctrl, dlg) == ssd->listbox && !conf_launchable(conf)) { Conf *conf2 = conf_new(); - int mbl = false; + bool mbl = false; if (!load_selected_session(ssd, dlg, conf2, &mbl)) { dlg_beep(dlg); conf_free(conf2); @@ -875,7 +878,8 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, Conf *conf = (Conf *)data; struct colour_data *cd = (struct colour_data *)ctrl->generic.context.p; - int update = false, clear = false, r, g, b; + bool update = false, clear = false; + int r, g, b; if (event == EVENT_REFRESH) { if (ctrl == cd->listbox) { @@ -1464,7 +1468,7 @@ static void clipboard_control(struct controlset *s, const char *label, #endif } -void setup_config_box(struct controlbox *b, int midsession, +void setup_config_box(struct controlbox *b, bool midsession, int protocol, int protcfginfo) { struct controlset *s; @@ -2275,7 +2279,7 @@ void setup_config_box(struct controlbox *b, int midsession, HELPCTX(proxy_auth), conf_editbox_handler, I(CONF_proxy_password), I(1)); - c->editbox.password = 1; + c->editbox.password = true; ctrl_editbox(s, "Telnet command", 'm', 100, HELPCTX(proxy_command), conf_editbox_handler, @@ -2501,7 +2505,7 @@ void setup_config_box(struct controlbox *b, int midsession, HELPCTX(ssh_kex_manual_hostkeys), manual_hostkey_handler, P(mh)); mh->rembutton->generic.column = 1; - mh->rembutton->generic.tabdelay = 1; + mh->rembutton->generic.tabdelay = true; mh->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT, HELPCTX(ssh_kex_manual_hostkeys), manual_hostkey_handler, P(mh)); @@ -2683,7 +2687,7 @@ void setup_config_box(struct controlbox *b, int midsession, HELPCTX(ssh_ttymodes), ttymodes_handler, P(td)); td->setbutton->generic.column = 1; - td->setbutton->generic.tabdelay = 1; + td->setbutton->generic.tabdelay = true; ctrl_columns(s, 1, 100); /* column break */ /* Bit of a hack to get the value radio buttons and * edit-box on the same row. */ @@ -2752,7 +2756,7 @@ void setup_config_box(struct controlbox *b, int midsession, HELPCTX(ssh_tunnels_portfwd), portfwd_handler, P(pfd)); pfd->rembutton->generic.column = 2; - pfd->rembutton->generic.tabdelay = 1; + pfd->rembutton->generic.tabdelay = true; pfd->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT, HELPCTX(ssh_tunnels_portfwd), portfwd_handler, P(pfd)); @@ -2769,7 +2773,7 @@ void setup_config_box(struct controlbox *b, int midsession, HELPCTX(ssh_tunnels_portfwd), portfwd_handler, P(pfd)); pfd->addbutton->generic.column = 2; - pfd->addbutton->generic.tabdelay = 1; + pfd->addbutton->generic.tabdelay = true; pfd->sourcebox = ctrl_editbox(s, "Source port", 's', 40, HELPCTX(ssh_tunnels_portfwd), portfwd_handler, P(pfd), P(NULL)); diff --git a/dialog.c b/dialog.c index e712c452..d00e2529 100644 --- a/dialog.c +++ b/dialog.c @@ -86,7 +86,7 @@ void ctrl_free_set(struct controlset *s) * path. If that path doesn't exist, return the index where it * should be inserted. */ -static int ctrl_find_set(struct controlbox *b, const char *path, int start) +static int ctrl_find_set(struct controlbox *b, const char *path, bool start) { int i, last, thisone; @@ -115,7 +115,7 @@ static int ctrl_find_set(struct controlbox *b, const char *path, int start) int ctrl_find_path(struct controlbox *b, const char *path, int index) { if (index < 0) - index = ctrl_find_set(b, path, 1); + index = ctrl_find_set(b, path, true); else index++; @@ -131,7 +131,7 @@ struct controlset *ctrl_settitle(struct controlbox *b, { struct controlset *s = snew(struct controlset); - int index = ctrl_find_set(b, path, 1); + int index = ctrl_find_set(b, path, true); s->pathname = dupstr(path); s->boxname = NULL; s->boxtitle = dupstr(title); @@ -155,7 +155,7 @@ struct controlset *ctrl_getset(struct controlbox *b, const char *path, const char *name, const char *boxtitle) { struct controlset *s; - int index = ctrl_find_set(b, path, 1); + int index = ctrl_find_set(b, path, true); while (index < b->nctrlsets && !strcmp(b->ctrlsets[index]->pathname, path)) { if (b->ctrlsets[index]->boxname && @@ -227,7 +227,7 @@ static union control *ctrl_new(struct controlset *s, int type, * Fill in the standard fields. */ c->generic.type = type; - c->generic.tabdelay = 0; + c->generic.tabdelay = false; c->generic.column = COLUMN_FIELD(0, s->ncolumns); c->generic.helpctx = helpctx; c->generic.handler = handler; @@ -266,8 +266,8 @@ union control *ctrl_editbox(struct controlset *s, const char *label, c->editbox.label = label ? dupstr(label) : NULL; c->editbox.shortcut = shortcut; c->editbox.percentwidth = percentage; - c->editbox.password = 0; - c->editbox.has_list = 0; + c->editbox.password = false; + c->editbox.has_list = false; c->editbox.context2 = context2; return c; } @@ -281,8 +281,8 @@ union control *ctrl_combobox(struct controlset *s, const char *label, c->editbox.label = label ? dupstr(label) : NULL; c->editbox.shortcut = shortcut; c->editbox.percentwidth = percentage; - c->editbox.password = 0; - c->editbox.has_list = 1; + c->editbox.password = false; + c->editbox.has_list = true; c->editbox.context2 = context2; return c; } @@ -346,8 +346,8 @@ union control *ctrl_pushbutton(struct controlset *s, const char *label, union control *c = ctrl_new(s, CTRL_BUTTON, helpctx, handler, context); c->button.label = label ? dupstr(label) : NULL; c->button.shortcut = shortcut; - c->button.isdefault = 0; - c->button.iscancel = 0; + c->button.isdefault = false; + c->button.iscancel = false; return c; } @@ -359,7 +359,7 @@ union control *ctrl_listbox(struct controlset *s, const char *label, c->listbox.label = label ? dupstr(label) : NULL; c->listbox.shortcut = shortcut; c->listbox.height = 5; /* *shrug* a plausible default */ - c->listbox.draglist = 0; + c->listbox.draglist = false; c->listbox.multisel = 0; c->listbox.percentwidth = 100; c->listbox.ncols = 0; @@ -376,7 +376,7 @@ union control *ctrl_droplist(struct controlset *s, const char *label, c->listbox.label = label ? dupstr(label) : NULL; c->listbox.shortcut = shortcut; c->listbox.height = 0; /* means it's a drop-down list */ - c->listbox.draglist = 0; + c->listbox.draglist = false; c->listbox.multisel = 0; c->listbox.percentwidth = percentage; c->listbox.ncols = 0; @@ -393,7 +393,7 @@ union control *ctrl_draglist(struct controlset *s, const char *label, c->listbox.label = label ? dupstr(label) : NULL; c->listbox.shortcut = shortcut; c->listbox.height = 5; /* *shrug* a plausible default */ - c->listbox.draglist = 1; + c->listbox.draglist = true; c->listbox.multisel = 0; c->listbox.percentwidth = 100; c->listbox.ncols = 0; @@ -403,7 +403,7 @@ union control *ctrl_draglist(struct controlset *s, const char *label, } union control *ctrl_filesel(struct controlset *s, const char *label, - char shortcut, const char *filter, int write, + char shortcut, const char *filter, bool write, const char *title, intorptr helpctx, handler_fn handler, intorptr context) { diff --git a/dialog.h b/dialog.h index fe32da72..864471bb 100644 --- a/dialog.h +++ b/dialog.h @@ -109,7 +109,7 @@ typedef void (*handler_fn)(union control *ctrl, dlgparam *dp, #define STANDARD_PREFIX \ int type; \ char *label; \ - int tabdelay; \ + bool tabdelay; \ int column; \ handler_fn handler; \ intorptr context; \ @@ -142,7 +142,7 @@ union control { * particular control should not yet appear in the tab * order. A subsequent CTRL_TABDELAY entry will place it. */ - int tabdelay; + bool tabdelay; /* * Indicate which column(s) this control occupies. This can * be unpacked into starting column and column span by the @@ -197,7 +197,7 @@ union control { * itself. */ int percentwidth; - int password; /* details of input are hidden */ + bool password; /* details of input are hidden */ /* * A special case of the edit box is the combo box, which * has a drop-down list built in. (Note that a _non_- @@ -208,7 +208,7 @@ union control { * control; front ends are not required to support that * combination. */ - int has_list; + bool has_list; /* * Edit boxes tend to need two items of context, so here's * a spare. @@ -279,12 +279,12 @@ union control { * button', which gets implicitly pressed when you hit * Return even if it doesn't have the input focus. */ - int isdefault; + bool isdefault; /* * Also, the reverse of this: a default cancel-type button, * which is implicitly pressed when you hit Escape. */ - int iscancel; + bool iscancel; } button; struct { STANDARD_PREFIX; @@ -301,7 +301,7 @@ union control { * comfortable with). This is not guaranteed to work on a * drop-down list, so don't try it! */ - int draglist; + bool draglist; /* * If this is non-zero, the list can have more than one * element selected at a time. This is not guaranteed to @@ -344,7 +344,7 @@ union control { * scroll bar if a list box entry goes off the right-hand * side. */ - int hscroll; + bool hscroll; } listbox; struct { STANDARD_PREFIX; @@ -374,7 +374,7 @@ union control { * choosing a file to read or one to write (and possibly * create). */ - int for_writing; + bool for_writing; /* * On at least some platforms, the file selector is a * separate dialog box, and contains a user-settable title. @@ -517,7 +517,7 @@ union control *ctrl_draglist(struct controlset *, const char *label, char shortcut, intorptr helpctx, handler_fn handler, intorptr context); union control *ctrl_filesel(struct controlset *, const char *label, - char shortcut, const char *filter, int write, + char shortcut, const char *filter, bool write, const char *title, intorptr helpctx, handler_fn handler, intorptr context); union control *ctrl_fontsel(struct controlset *, const char *label, @@ -536,8 +536,8 @@ union control *ctrl_tabdelay(struct controlset *, union control *); */ void dlg_radiobutton_set(union control *ctrl, dlgparam *dp, int whichbutton); int dlg_radiobutton_get(union control *ctrl, dlgparam *dp); -void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked); -int dlg_checkbox_get(union control *ctrl, dlgparam *dp); +void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked); +bool dlg_checkbox_get(union control *ctrl, dlgparam *dp); void dlg_editbox_set(union control *ctrl, dlgparam *dp, char const *text); char *dlg_editbox_get(union control *ctrl, dlgparam *dp); /* result must be freed by caller */ /* The `listbox' functions can also apply to combo boxes. */ @@ -556,7 +556,7 @@ void dlg_listbox_addwithid(union control *ctrl, dlgparam *dp, int dlg_listbox_getid(union control *ctrl, dlgparam *dp, int index); /* dlg_listbox_index returns <0 if no single element is selected. */ int dlg_listbox_index(union control *ctrl, dlgparam *dp); -int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index); +bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index); void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index); void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text); void dlg_filesel_set(union control *ctrl, dlgparam *dp, Filename *fn); @@ -614,8 +614,8 @@ void dlg_end(dlgparam *dp, int value); */ void dlg_coloursel_start(union control *ctrl, dlgparam *dp, int r, int g, int b); -int dlg_coloursel_results(union control *ctrl, dlgparam *dp, - int *r, int *g, int *b); +bool dlg_coloursel_results(union control *ctrl, dlgparam *dp, + int *r, int *g, int *b); /* * This routine is used by the platform-independent code to diff --git a/fuzzterm.c b/fuzzterm.c index 477dda58..83a176e6 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -7,7 +7,7 @@ #include "terminal.h" /* For Unix in particular, but harmless if this main() is reused elsewhere */ -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; static const TermWinVtable fuzz_termwin_vt; @@ -37,14 +37,14 @@ int main(int argc, char **argv) #endif while (!feof(stdin)) { len = fread(blk, 1, sizeof(blk), stdin); - term_data(term, 0, blk, len); + term_data(term, false, blk, len); } term_update(term); return 0; } /* functions required by terminal.c */ -static int fuzz_setup_draw_ctx(TermWin *tw) { return true; } +static bool fuzz_setup_draw_ctx(TermWin *tw) { return true; } static void fuzz_draw_text( TermWin *tw, int x, int y, wchar_t *text, int len, unsigned long attr, int lattr, truecolour tc) @@ -72,30 +72,30 @@ static void fuzz_draw_cursor( static int fuzz_char_width(TermWin *tw, int uc) { return 1; } static void fuzz_free_draw_ctx(TermWin *tw) {} static void fuzz_set_cursor_pos(TermWin *tw, int x, int y) {} -static void fuzz_set_raw_mouse_mode(TermWin *tw, int enable) {} +static void fuzz_set_raw_mouse_mode(TermWin *tw, bool enable) {} static void fuzz_set_scrollbar(TermWin *tw, int total, int start, int page) {} static void fuzz_bell(TermWin *tw, int mode) {} static void fuzz_clip_write( TermWin *tw, int clipboard, wchar_t *text, int *attrs, - truecolour *colours, int len, int must_deselect) {} + truecolour *colours, int len, bool must_deselect) {} static void fuzz_clip_request_paste(TermWin *tw, int clipboard) {} static void fuzz_refresh(TermWin *tw) {} static void fuzz_request_resize(TermWin *tw, int w, int h) {} static void fuzz_set_title(TermWin *tw, const char *title) {} static void fuzz_set_icon_title(TermWin *tw, const char *icontitle) {} -static void fuzz_set_minimised(TermWin *tw, int minimised) {} -static int fuzz_is_minimised(TermWin *tw) { return false; } -static void fuzz_set_maximised(TermWin *tw, int maximised) {} +static void fuzz_set_minimised(TermWin *tw, bool minimised) {} +static bool fuzz_is_minimised(TermWin *tw) { return false; } +static void fuzz_set_maximised(TermWin *tw, bool maximised) {} static void fuzz_move(TermWin *tw, int x, int y) {} -static void fuzz_set_zorder(TermWin *tw, int top) {} -static int fuzz_palette_get(TermWin *tw, int n, int *r, int *g, int *b) +static void fuzz_set_zorder(TermWin *tw, bool top) {} +static bool fuzz_palette_get(TermWin *tw, int n, int *r, int *g, int *b) { return false; } static void fuzz_palette_set(TermWin *tw, int n, int r, int g, int b) {} static void fuzz_palette_reset(TermWin *tw) {} static void fuzz_get_pos(TermWin *tw, int *x, int *y) { *x = *y = 0; } static void fuzz_get_pixels(TermWin *tw, int *x, int *y) { *x = *y = 0; } -static const char *fuzz_get_title(TermWin *tw, int icon) { return "moo"; } -static int fuzz_is_utf8(TermWin *tw) { return true; } +static const char *fuzz_get_title(TermWin *tw, bool icon) { return "moo"; } +static bool fuzz_is_utf8(TermWin *tw) { return true; } static const TermWinVtable fuzz_termwin_vt = { fuzz_setup_draw_ctx, @@ -127,7 +127,7 @@ static const TermWinVtable fuzz_termwin_vt = { fuzz_is_utf8, }; -void ldisc_send(Ldisc *ldisc, const void *buf, int len, int interactive) {} +void ldisc_send(Ldisc *ldisc, const void *buf, int len, bool interactive) {} void ldisc_echoedit_update(Ldisc *ldisc) {} void modalfatalbox(const char *fmt, ...) { exit(0); } void nonfatal(const char *fmt, ...) { } @@ -167,8 +167,8 @@ void dlg_error_msg(void *dlg, const char *msg) { } void dlg_end(void *dlg, int value) { } void dlg_coloursel_start(union control *ctrl, void *dlg, int r, int g, int b) { } -int dlg_coloursel_results(union control *ctrl, void *dlg, - int *r, int *g, int *b) { return 0; } +bool dlg_coloursel_results(union control *ctrl, void *dlg, + int *r, int *g, int *b) { return false; } void dlg_refresh(union control *ctrl, void *dlg) { } const char *const appname = "FuZZterm"; diff --git a/import.c b/import.c index d3b1d331..d88ad2bb 100644 --- a/import.c +++ b/import.c @@ -12,39 +12,39 @@ #include "ssh.h" #include "misc.h" -int openssh_pem_encrypted(const Filename *filename); -int openssh_new_encrypted(const Filename *filename); +bool openssh_pem_encrypted(const Filename *filename); +bool openssh_new_encrypted(const Filename *filename); struct ssh2_userkey *openssh_pem_read(const Filename *filename, char *passphrase, const char **errmsg_p); struct ssh2_userkey *openssh_new_read(const Filename *filename, char *passphrase, const char **errmsg_p); -int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key, +bool openssh_auto_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase); +bool openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase); +bool openssh_new_write(const Filename *filename, struct ssh2_userkey *key, char *passphrase); -int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase); -int openssh_new_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase); -int sshcom_encrypted(const Filename *filename, char **comment); +bool sshcom_encrypted(const Filename *filename, char **comment); struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase, const char **errmsg_p); -int sshcom_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase); +bool sshcom_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase); /* * Given a key type, determine whether we know how to import it. */ -int import_possible(int type) +bool import_possible(int type) { if (type == SSH_KEYTYPE_OPENSSH_PEM) - return 1; + return true; if (type == SSH_KEYTYPE_OPENSSH_NEW) - return 1; + return true; if (type == SSH_KEYTYPE_SSHCOM) - return 1; - return 0; + return true; + return false; } /* @@ -63,7 +63,7 @@ int import_target_type(int type) /* * Determine whether a foreign key is encrypted. */ -int import_encrypted(const Filename *filename, int type, char **comment) +bool import_encrypted(const Filename *filename, int type, char **comment) { if (type == SSH_KEYTYPE_OPENSSH_PEM) { /* OpenSSH PEM format doesn't contain a key comment at all */ @@ -77,7 +77,7 @@ int import_encrypted(const Filename *filename, int type, char **comment) } else if (type == SSH_KEYTYPE_SSHCOM) { return sshcom_encrypted(filename, comment); } - return 0; + return false; } /* @@ -107,17 +107,17 @@ struct ssh2_userkey *import_ssh2(const Filename *filename, int type, /* * Export an SSH-1 key. */ -int export_ssh1(const Filename *filename, int type, struct RSAKey *key, - char *passphrase) +bool export_ssh1(const Filename *filename, int type, struct RSAKey *key, + char *passphrase) { - return 0; + return false; } /* * Export an SSH-2 key. */ -int export_ssh2(const Filename *filename, int type, - struct ssh2_userkey *key, char *passphrase) +bool export_ssh2(const Filename *filename, int type, + struct ssh2_userkey *key, char *passphrase) { if (type == SSH_KEYTYPE_OPENSSH_AUTO) return openssh_auto_write(filename, key, passphrase); @@ -125,7 +125,7 @@ int export_ssh2(const Filename *filename, int type, return openssh_new_write(filename, key, passphrase); if (type == SSH_KEYTYPE_SSHCOM) return sshcom_write(filename, key, passphrase); - return 0; + return false; } /* @@ -276,7 +276,7 @@ typedef enum { struct openssh_pem_key { openssh_pem_keytype keytype; - int encrypted; + bool encrypted; openssh_pem_enc encryption; char iv[32]; strbuf *keyblob; @@ -309,7 +309,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename, char *line = NULL; const char *errmsg; char *p; - int headers_done; + bool headers_done; char base64_bit[4]; int base64_chars = 0; @@ -358,7 +358,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename, ret->encrypted = false; memset(ret->iv, 0, sizeof(ret->iv)); - headers_done = 0; + headers_done = false; while (1) { if (!(line = fgetline(fp))) { errmsg = "unexpected end of file"; @@ -415,7 +415,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename, } } } else { - headers_done = 1; + headers_done = true; p = line; while (isbase64(*p)) { @@ -482,13 +482,13 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename, return NULL; } -int openssh_pem_encrypted(const Filename *filename) +bool openssh_pem_encrypted(const Filename *filename) { struct openssh_pem_key *key = load_openssh_pem_key(filename, NULL); - int ret; + bool ret; if (!key) - return 0; + return false; ret = key->encrypted; strbuf_free(key->keyblob); smemclr(key, sizeof(*key)); @@ -775,8 +775,8 @@ struct ssh2_userkey *openssh_pem_read(const Filename *filename, return retval; } -int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase) +bool openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase) { strbuf *pubblob, *privblob, *outblob; unsigned char *spareblob; @@ -786,7 +786,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, const char *header, *footer; char zero[1]; unsigned char iv[8]; - int ret = 0; + bool ret = false; FILE *fp; BinarySource src[1]; @@ -1061,7 +1061,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, base64_encode(fp, outblob->u, outblob->len, 64); fputs(footer, fp); fclose(fp); - ret = 1; + ret = true; error: if (outblob) @@ -1319,13 +1319,13 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename, return NULL; } -int openssh_new_encrypted(const Filename *filename) +bool openssh_new_encrypted(const Filename *filename) { struct openssh_new_key *key = load_openssh_new_key(filename, NULL); - int ret; + bool ret; if (!key) - return 0; + return false; ret = (key->cipher != ON_E_NONE); smemclr(key->keyblob, key->keyblob_size); sfree(key->keyblob); @@ -1515,13 +1515,13 @@ struct ssh2_userkey *openssh_new_read(const Filename *filename, return retval; } -int openssh_new_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase) +bool openssh_new_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase) { strbuf *pubblob, *privblob, *cblob; int padvalue, i; unsigned checkint; - int ret = 0; + bool ret = false; unsigned char bcrypt_salt[16]; const int bcrypt_rounds = 16; FILE *fp; @@ -1628,7 +1628,7 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key, base64_encode(fp, cblob->u, cblob->len, 64); fputs("-----END OPENSSH PRIVATE KEY-----\n", fp); fclose(fp); - ret = 1; + ret = true; error: if (cblob) @@ -1644,8 +1644,8 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key, * The switch function openssh_auto_write(), which chooses one of the * concrete OpenSSH output formats based on the key type. */ -int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase) +bool openssh_auto_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase) { /* * The old OpenSSH format supports a fixed list of key types. We @@ -1753,7 +1753,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename, int hdrstart, len; const char *errmsg; char *p; - int headers_done; + bool headers_done; char base64_bit[4]; int base64_chars = 0; @@ -1780,7 +1780,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename, sfree(line); line = NULL; - headers_done = 0; + headers_done = false; while (1) { if (!(line = fgetline(fp))) { errmsg = "unexpected end of file"; @@ -1840,7 +1840,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename, ret->comment[sizeof(ret->comment)-1] = '\0'; } } else { - headers_done = 1; + headers_done = true; p = line; while (isbase64(*p)) { @@ -1905,12 +1905,12 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename, return NULL; } -int sshcom_encrypted(const Filename *filename, char **comment) +bool sshcom_encrypted(const Filename *filename, char **comment) { struct sshcom_key *key = load_sshcom_key(filename, NULL); BinarySource src[1]; ptrlen str; - int answer = false; + bool answer = false; *comment = NULL; if (!key) @@ -1981,7 +1981,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase, const char prefix_rsa[] = "if-modn{sign{rsa"; const char prefix_dsa[] = "dl-modp{sign{dsa"; enum { RSA, DSA } type; - int encrypted; + bool encrypted; struct ssh2_userkey *ret = NULL, *retkey; const ssh_keyalg *alg; strbuf *blob = NULL; @@ -2017,9 +2017,9 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase, */ str = get_string(src); if (ptrlen_eq_string(str, "none")) - encrypted = 0; + encrypted = false; else if (ptrlen_eq_string(str, "3des-cbc")) - encrypted = 1; + encrypted = true; else { errmsg = "key encryption is of unknown type"; goto error; @@ -2181,17 +2181,18 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase, return ret; } -int sshcom_write(const Filename *filename, struct ssh2_userkey *key, - char *passphrase) +bool sshcom_write(const Filename *filename, struct ssh2_userkey *key, + char *passphrase) { strbuf *pubblob, *privblob, *outblob; ptrlen numbers[6]; - int nnumbers, initial_zero, lenpos, i; + int nnumbers, lenpos, i; + bool initial_zero; BinarySource src[1]; const char *type; char *ciphertext; int cipherlen; - int ret = 0; + bool ret = false; FILE *fp; /* @@ -2234,7 +2235,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key, numbers[5] = p; nnumbers = 6; - initial_zero = 0; + initial_zero = false; type = "if-modn{sign{rsa-pkcs1-sha1},encrypt{rsa-pkcs1v2-oaep}}"; } else if (ssh_key_alg(key->key) == &ssh_dss) { ptrlen p, q, g, y, x; @@ -2261,7 +2262,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key, numbers[4] = x; nnumbers = 5; - initial_zero = 1; + initial_zero = true; type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}"; } else { goto error; /* unsupported key type */ @@ -2362,7 +2363,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key, base64_encode(fp, outblob->u, outblob->len, 70); fputs("---- END SSH2 ENCRYPTED PRIVATE KEY ----\n", fp); fclose(fp); - ret = 1; + ret = true; error: if (outblob) diff --git a/ldisc.c b/ldisc.c index 1273d05d..0779d142 100644 --- a/ldisc.c +++ b/ldisc.c @@ -60,12 +60,12 @@ static void pwrite(Ldisc *ldisc, unsigned char c) } } -static int char_start(Ldisc *ldisc, unsigned char c) +static bool char_start(Ldisc *ldisc, unsigned char c) { if (in_utf(ldisc->term)) return (c < 0x80 || c >= 0xC0); else - return 1; + return true; } static void bsb(Ldisc *ldisc, int n) @@ -84,7 +84,7 @@ Ldisc *ldisc_create(Conf *conf, Terminal *term, Backend *backend, Seat *seat) ldisc->buf = NULL; ldisc->buflen = 0; ldisc->bufsiz = 0; - ldisc->quotenext = 0; + ldisc->quotenext = false; ldisc->backend = backend; ldisc->term = term; @@ -126,7 +126,7 @@ void ldisc_echoedit_update(Ldisc *ldisc) seat_echoedit_update(ldisc->seat, ECHOING, EDITING); } -void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, int interactive) +void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, bool interactive) { const char *buf = (const char *)vbuf; int keyflag = 0; diff --git a/ldisc.h b/ldisc.h index 3b5e8249..65a544ad 100644 --- a/ldisc.h +++ b/ldisc.h @@ -16,10 +16,12 @@ struct Ldisc_tag { /* * Values cached out of conf. */ - int telnet_keyboard, telnet_newline, protocol, localecho, localedit; + bool telnet_keyboard, telnet_newline; + int protocol, localecho, localedit; char *buf; - int buflen, bufsiz, quotenext; + int buflen, bufsiz; + bool quotenext; }; #endif /* PUTTY_LDISC_H */ diff --git a/ldiscucs.c b/ldiscucs.c index 50ce2094..774368f3 100644 --- a/ldiscucs.c +++ b/ldiscucs.c @@ -13,7 +13,7 @@ #include "ldisc.h" void lpage_send(Ldisc *ldisc, - int codepage, const char *buf, int len, int interactive) + int codepage, const char *buf, int len, bool interactive) { wchar_t *widebuffer = 0; int widesize = 0; @@ -33,7 +33,7 @@ void lpage_send(Ldisc *ldisc, sfree(widebuffer); } -void luni_send(Ldisc *ldisc, const wchar_t *widebuf, int len, int interactive) +void luni_send(Ldisc *ldisc, const wchar_t *widebuf, int len, bool interactive) { int ratio = (in_utf(ldisc->term))?3:1; char *linebuffer; diff --git a/logging.c b/logging.c index 68bb8acf..a43ebcd1 100644 --- a/logging.c +++ b/logging.c @@ -87,7 +87,7 @@ static void logfopen_callback(void *vctx, int mode) char buf[256], *event; struct tm tm; const char *fmode; - int shout = false; + bool shout = false; if (mode == 0) { ctx->state = L_ERROR; /* disable logging */ @@ -419,7 +419,7 @@ void log_free(LogContext *ctx) void log_reconfig(LogContext *ctx, Conf *conf) { - int reset_logging; + bool reset_logging; if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename), conf_get_filename(conf, CONF_logfilename)) || @@ -463,7 +463,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port, s = filename_to_str(src); while (*s) { - int sanitise = false; + bool sanitise = false; /* Let (bufp, len) be the string to append. */ bufp = buf; /* don't usually override this */ if (*s == '&') { diff --git a/mainchan.c b/mainchan.c index ffbbb761..ce991933 100644 --- a/mainchan.c +++ b/mainchan.c @@ -14,16 +14,16 @@ static void mainchan_free(Channel *chan); static void mainchan_open_confirmation(Channel *chan); static void mainchan_open_failure(Channel *chan, const char *errtext); -static int mainchan_send(Channel *chan, int is_stderr, const void *, int); +static int mainchan_send(Channel *chan, bool is_stderr, const void *, int); static void mainchan_send_eof(Channel *chan); -static void mainchan_set_input_wanted(Channel *chan, int wanted); +static void mainchan_set_input_wanted(Channel *chan, bool wanted); static char *mainchan_log_close_msg(Channel *chan); -static int mainchan_rcvd_exit_status(Channel *chan, int status); -static int mainchan_rcvd_exit_signal( - Channel *chan, ptrlen signame, int core_dumped, ptrlen msg); -static int mainchan_rcvd_exit_signal_numeric( - Channel *chan, int signum, int core_dumped, ptrlen msg); -static void mainchan_request_response(Channel *chan, int success); +static bool mainchan_rcvd_exit_status(Channel *chan, int status); +static bool mainchan_rcvd_exit_signal( + Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg); +static bool mainchan_rcvd_exit_signal_numeric( + Channel *chan, int signum, bool core_dumped, ptrlen msg); +static void mainchan_request_response(Channel *chan, bool success); static const struct ChannelVtable mainchan_channelvt = { mainchan_free, @@ -61,11 +61,11 @@ struct mainchan { ConnectionLayer *cl; MainChanType type; - int is_simple; + bool is_simple; - int req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback; + bool req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback; int n_req_env, n_env_replies, n_env_fails; - int eof_pending, eof_sent, got_pty, ready; + bool eof_pending, eof_sent, got_pty, ready; int term_width, term_height; @@ -74,7 +74,7 @@ struct mainchan { mainchan *mainchan_new( PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf, - int term_width, int term_height, int is_simple, SshChannel **sc_out) + int term_width, int term_height, bool is_simple, SshChannel **sc_out) { mainchan *mc; @@ -139,7 +139,7 @@ static void mainchan_open_confirmation(Channel *chan) char *key, *val, *cmd; struct X11Display *x11disp; struct X11FakeAuth *x11auth; - int retry_cmd_now = false; + bool retry_cmd_now = false; if (conf_get_bool(mc->conf, CONF_x11_forward)) {; char *x11_setup_err; @@ -212,7 +212,7 @@ static void mainchan_try_fallback_command(mainchan *mc) mc->req_cmd_fallback = true; } -static void mainchan_request_response(Channel *chan, int success) +static void mainchan_request_response(Channel *chan, bool success) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); @@ -362,7 +362,7 @@ static void mainchan_open_failure(Channel *chan, const char *errtext) queue_toplevel_callback(mainchan_open_failure_abort, ctx); } -static int mainchan_send(Channel *chan, int is_stderr, +static int mainchan_send(Channel *chan, bool is_stderr, const void *data, int length) { assert(chan->vt == &mainchan_channelvt); @@ -391,7 +391,7 @@ static void mainchan_send_eof(Channel *chan) ssh_set_wants_user_input(mc->cl, false); /* now stop reading from stdin */ } -static void mainchan_set_input_wanted(Channel *chan, int wanted) +static void mainchan_set_input_wanted(Channel *chan, bool wanted) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); @@ -410,7 +410,7 @@ static char *mainchan_log_close_msg(Channel *chan) return dupstr("Main session channel closed"); } -static int mainchan_rcvd_exit_status(Channel *chan, int status) +static bool mainchan_rcvd_exit_status(Channel *chan, int status) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); @@ -423,7 +423,7 @@ static int mainchan_rcvd_exit_status(Channel *chan, int status) static void mainchan_log_exit_signal_common( mainchan *mc, const char *sigdesc, - int core_dumped, ptrlen msg) + bool core_dumped, ptrlen msg) { PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */ @@ -434,8 +434,8 @@ static void mainchan_log_exit_signal_common( sigdesc, core_msg, msg_pre, PTRLEN_PRINTF(msg), msg_post)); } -static int mainchan_rcvd_exit_signal( - Channel *chan, ptrlen signame, int core_dumped, ptrlen msg) +static bool mainchan_rcvd_exit_signal( + Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); @@ -469,8 +469,8 @@ static int mainchan_rcvd_exit_signal( return true; } -static int mainchan_rcvd_exit_signal_numeric( - Channel *chan, int signum, int core_dumped, ptrlen msg) +static bool mainchan_rcvd_exit_signal_numeric( + Channel *chan, int signum, bool core_dumped, ptrlen msg) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); diff --git a/marshal.c b/marshal.c index 349367aa..06f6d631 100644 --- a/marshal.c +++ b/marshal.c @@ -26,7 +26,7 @@ void BinarySink_put_byte(BinarySink *bs, unsigned char val) bs->write(bs, &val, 1); } -void BinarySink_put_bool(BinarySink *bs, int val) +void BinarySink_put_bool(BinarySink *bs, bool val) { unsigned char cval = val ? 1 : 0; bs->write(bs, &cval, 1); @@ -84,7 +84,7 @@ void BinarySink_put_asciz(BinarySink *bs, const char *str) bs->write(bs, str, strlen(str) + 1); } -int BinarySink_put_pstring(BinarySink *bs, const char *str) +bool BinarySink_put_pstring(BinarySink *bs, const char *str) { size_t len = strlen(str); if (len > 255) @@ -96,7 +96,7 @@ int BinarySink_put_pstring(BinarySink *bs, const char *str) /* ---------------------------------------------------------------------- */ -static int BinarySource_data_avail(BinarySource *src, size_t wanted) +static bool BinarySource_data_avail(BinarySource *src, size_t wanted) { if (src->err) return false; @@ -134,12 +134,12 @@ unsigned char BinarySource_get_byte(BinarySource *src) return *ucp; } -int BinarySource_get_bool(BinarySource *src) +bool BinarySource_get_bool(BinarySource *src) { const unsigned char *ucp; if (!avail(1)) - return 0; + return false; ucp = consume(1); return *ucp != 0; diff --git a/marshal.h b/marshal.h index af35ff7e..e19cd0b9 100644 --- a/marshal.h +++ b/marshal.h @@ -142,7 +142,7 @@ struct BinarySink { void BinarySink_put_data(BinarySink *, const void *data, size_t len); void BinarySink_put_padding(BinarySink *, size_t len, unsigned char padbyte); void BinarySink_put_byte(BinarySink *, unsigned char); -void BinarySink_put_bool(BinarySink *, int); +void BinarySink_put_bool(BinarySink *, bool); void BinarySink_put_uint16(BinarySink *, unsigned long); void BinarySink_put_uint32(BinarySink *, unsigned long); void BinarySink_put_uint64(BinarySink *, uint64_t); @@ -152,7 +152,7 @@ void BinarySink_put_stringz(BinarySink *, const char *str); struct strbuf; void BinarySink_put_stringsb(BinarySink *, struct strbuf *); void BinarySink_put_asciz(BinarySink *, const char *str); -int BinarySink_put_pstring(BinarySink *, const char *str); +bool BinarySink_put_pstring(BinarySink *, const char *str); /* ---------------------------------------------------------------------- */ @@ -274,7 +274,7 @@ struct BinarySource { ptrlen BinarySource_get_data(BinarySource *, size_t); unsigned char BinarySource_get_byte(BinarySource *); -int BinarySource_get_bool(BinarySource *); +bool BinarySource_get_bool(BinarySource *); unsigned BinarySource_get_uint16(BinarySource *); unsigned long BinarySource_get_uint32(BinarySource *); uint64_t BinarySource_get_uint64(BinarySource *); diff --git a/minibidi.c b/minibidi.c index 2bdf4deb..64f27a96 100644 --- a/minibidi.c +++ b/minibidi.c @@ -1086,9 +1086,10 @@ int getPreviousLevel(unsigned char* level, int from) */ int do_shape(bidi_char *line, bidi_char *to, int count) { - int i, tempShape, ligFlag; + int i, tempShape; + bool ligFlag = false; - for (ligFlag=i=0; i 0) switch (line[i-1].wc) { case 0x622: - ligFlag = 1; + ligFlag = true; if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC)) to[i].wc = 0xFEF6; else to[i].wc = 0xFEF5; break; case 0x623: - ligFlag = 1; + ligFlag = true; if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC)) to[i].wc = 0xFEF8; else to[i].wc = 0xFEF7; break; case 0x625: - ligFlag = 1; + ligFlag = true; if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC)) to[i].wc = 0xFEFA; else to[i].wc = 0xFEF9; break; case 0x627: - ligFlag = 1; + ligFlag = true; if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC)) to[i].wc = 0xFEFC; else @@ -1143,7 +1144,7 @@ int do_shape(bidi_char *line, bidi_char *to, int count) } if (ligFlag) { to[i-1].wc = 0x20; - ligFlag = 0; + ligFlag = false; break; } } @@ -1186,18 +1187,19 @@ int do_bidi(bidi_char *line, int count) unsigned char currentEmbedding; unsigned char currentOverride; unsigned char tempType; - int i, j, yes, bover; + int i, j; + bool yes, bover; /* Check the presence of R or AL types as optimization */ - yes = 0; + yes = false; for (i=0; iname_reqd = p->instr_reqd = false; return p; } -void add_prompt(prompts_t *p, char *promptstr, int echo) +void add_prompt(prompts_t *p, char *promptstr, bool echo) { prompt_t *pr = snew(prompt_t); pr->prompt = promptstr; @@ -826,7 +826,7 @@ void bufchain_fetch_consume(bufchain *ch, void *data, int len) bufchain_consume(ch, len); } -int bufchain_try_fetch_consume(bufchain *ch, void *data, int len) +bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len) { if (ch->buffersize >= len) { bufchain_fetch_consume(ch, data, len); @@ -1055,7 +1055,7 @@ void debug_memdump(const void *buf, int len, int L) * Determine whether or not a Conf represents a session which can * sensibly be launched right now. */ -int conf_launchable(Conf *conf) +bool conf_launchable(Conf *conf) { if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL) return conf_get_str(conf, CONF_serline)[0] != 0; @@ -1119,7 +1119,7 @@ void smemclr(void *b, size_t n) { * original version), suitable for putting into the Conf. If not * valid, we return false. */ -int validate_manual_hostkey(char *key) +bool validate_manual_hostkey(char *key) { char *p, *q, *r, *s; @@ -1208,7 +1208,7 @@ int validate_manual_hostkey(char *key) return false; } -int smemeq(const void *av, const void *bv, size_t len) +bool smemeq(const void *av, const void *bv, size_t len) { const unsigned char *a = (const unsigned char *)av; const unsigned char *b = (const unsigned char *)bv; @@ -1253,18 +1253,18 @@ ptrlen ptrlen_from_strbuf(strbuf *sb) return make_ptrlen(sb->u, sb->len); } -int ptrlen_eq_string(ptrlen pl, const char *str) +bool ptrlen_eq_string(ptrlen pl, const char *str) { size_t len = strlen(str); return (pl.len == len && !memcmp(pl.ptr, str, len)); } -int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2) +bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2) { return (pl1.len == pl2.len && !memcmp(pl1.ptr, pl2.ptr, pl1.len)); } -int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail) +bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail) { if (whole.len >= prefix.len && !memcmp(whole.ptr, prefix.ptr, prefix.len)) { @@ -1285,12 +1285,12 @@ char *mkstr(ptrlen pl) return p; } -int strstartswith(const char *s, const char *t) +bool strstartswith(const char *s, const char *t) { return !memcmp(s, t, strlen(t)); } -int strendswith(const char *s, const char *t) +bool strendswith(const char *s, const char *t) { size_t slen = strlen(s), tlen = strlen(t); return slen >= tlen && !strcmp(s + (slen - tlen), t); @@ -1390,8 +1390,8 @@ char *buildinfo(const char *newline) } int nullseat_output( - Seat *seat, int is_stderr, const void *data, int len) { return 0; } -int nullseat_eof(Seat *seat) { return true; } + Seat *seat, bool is_stderr, const void *data, int len) { return 0; } +bool nullseat_eof(Seat *seat) { return true; } int nullseat_get_userpass_input( Seat *seat, prompts_t *p, bufchain *input) { return 0; } void nullseat_notify_remote_exit(Seat *seat) {} @@ -1409,12 +1409,12 @@ int nullseat_confirm_weak_crypto_primitive( int nullseat_confirm_weak_cached_hostkey( Seat *seat, const char *algname, const char *betteralgs, void (*callback)(void *ctx, int result), void *ctx) { return 0; } -int nullseat_is_never_utf8(Seat *seat) { return false; } -int nullseat_is_always_utf8(Seat *seat) { return true; } -void nullseat_echoedit_update(Seat *seat, int echoing, int editing) {} +bool nullseat_is_never_utf8(Seat *seat) { return false; } +bool nullseat_is_always_utf8(Seat *seat) { return true; } +void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing) {} const char *nullseat_get_x_display(Seat *seat) { return NULL; } -int nullseat_get_windowid(Seat *seat, long *id_out) { return false; } -int nullseat_get_window_pixel_size( +bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; } +bool nullseat_get_window_pixel_size( Seat *seat, int *width, int *height) { return false; } void sk_free_peer_info(SocketPeerInfo *pi) diff --git a/misc.h b/misc.h index 587e97e3..5d493c48 100644 --- a/misc.h +++ b/misc.h @@ -61,8 +61,8 @@ int toint(unsigned); char *fgetline(FILE *fp); char *chomp(char *str); -int strstartswith(const char *s, const char *t); -int strendswith(const char *s, const char *t); +bool strstartswith(const char *s, const char *t); +bool strendswith(const char *s, const char *t); void base64_encode_atom(const unsigned char *data, int n, char *out); int base64_decode_atom(const char *atom, unsigned char *out); @@ -82,11 +82,11 @@ void bufchain_prefix(bufchain *ch, void **data, int *len); void bufchain_consume(bufchain *ch, int len); void bufchain_fetch(bufchain *ch, void *data, int len); void bufchain_fetch_consume(bufchain *ch, void *data, int len); -int bufchain_try_fetch_consume(bufchain *ch, void *data, int len); +bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len); void sanitise_term_data(bufchain *out, const void *vdata, int len); -int validate_manual_hostkey(char *key); +bool validate_manual_hostkey(char *key); struct tm ltime(void); @@ -99,9 +99,9 @@ int nullstrcmp(const char *a, const char *b); ptrlen make_ptrlen(const void *ptr, size_t len); ptrlen ptrlen_from_asciz(const char *str); ptrlen ptrlen_from_strbuf(strbuf *sb); -int ptrlen_eq_string(ptrlen pl, const char *str); -int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2); -int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail); +bool ptrlen_eq_string(ptrlen pl, const char *str); +bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2); +bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail); char *mkstr(ptrlen pl); int string_length_for_printf(size_t); /* Derive two printf arguments from a ptrlen, suitable for "%.*s" */ @@ -124,9 +124,9 @@ void smemclr(void *b, size_t len); /* Compare two fixed-length chunks of memory for equality, without * data-dependent control flow (so an attacker with a very accurate * stopwatch can't try to guess where the first mismatching byte was). - * Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at - * by the 'eq' in the name. */ -int smemeq(const void *av, const void *bv, size_t len); + * Returns false for mismatch or true for equality (unlike memcmp), + * hinted at by the 'eq' in the name. */ +bool smemeq(const void *av, const void *bv, size_t len); char *buildinfo(const char *newline); @@ -145,10 +145,10 @@ char *buildinfo(const char *newline); #ifdef DEBUG void debug_printf(const char *fmt, ...); -void debug_memdump(const void *buf, int len, int L); +void debug_memdump(const void *buf, int len, bool L); #define debug(x) (debug_printf x) -#define dmemdump(buf,len) debug_memdump (buf, len, 0); -#define dmemdumpl(buf,len) debug_memdump (buf, len, 1); +#define dmemdump(buf,len) debug_memdump (buf, len, false); +#define dmemdumpl(buf,len) debug_memdump (buf, len, true); #else #define debug(x) #define dmemdump(buf,len) diff --git a/network.h b/network.h index 62f3afe3..a394a356 100644 --- a/network.h +++ b/network.h @@ -32,7 +32,7 @@ struct SocketVtable { int (*write_oob) (Socket *s, const void *data, int len); void (*write_eof) (Socket *s); void (*flush) (Socket *s); - void (*set_frozen) (Socket *s, int is_frozen); + void (*set_frozen) (Socket *s, bool is_frozen); /* ignored by tcp, but vital for ssl */ const char *(*socket_error) (Socket *s); SocketPeerInfo *(*peer_info) (Socket *s); @@ -66,7 +66,7 @@ struct PlugVtable { * indicate this. */ void (*closing) - (Plug *p, const char *error_msg, int error_code, int calling_back); + (Plug *p, const char *error_msg, int error_code, bool calling_back); /* error_msg is NULL iff it is not an error (ie it closed normally) */ /* calling_back != 0 iff there is a Plug function */ /* currently running (would cure the fixme in try_send()) */ @@ -100,22 +100,22 @@ struct PlugVtable { /* NB, control of 'addr' is passed via new_connection, which takes * responsibility for freeing it */ Socket *new_connection(SockAddr *addr, const char *hostname, - int port, int privport, - int oobinline, int nodelay, int keepalive, + int port, bool privport, + bool oobinline, bool nodelay, bool keepalive, Plug *plug, Conf *conf); Socket *new_listener(const char *srcaddr, int port, Plug *plug, - int local_host_only, Conf *conf, int addressfamily); + bool local_host_only, Conf *conf, int addressfamily); SockAddr *name_lookup(const char *host, int port, char **canonicalname, Conf *conf, int addressfamily, LogContext *logctx, const char *lookup_reason_for_logging); -int proxy_for_destination (SockAddr *addr, const char *hostname, int port, - Conf *conf); +bool proxy_for_destination (SockAddr *addr, const char *hostname, int port, + Conf *conf); /* platform-dependent callback from new_connection() */ /* (same caveat about addr as new_connection()) */ Socket *platform_new_connection(SockAddr *addr, const char *hostname, - int port, int privport, - int oobinline, int nodelay, int keepalive, + int port, bool privport, + bool oobinline, bool nodelay, bool keepalive, Plug *plug, Conf *conf); /* socket functions */ @@ -126,10 +126,10 @@ void sk_cleanup(void); /* called just before program exit */ SockAddr *sk_namelookup(const char *host, char **canonicalname, int address_family); SockAddr *sk_nonamelookup(const char *host); void sk_getaddr(SockAddr *addr, char *buf, int buflen); -int sk_addr_needs_port(SockAddr *addr); -int sk_hostname_is_local(const char *name); -int sk_address_is_local(SockAddr *addr); -int sk_address_is_special_local(SockAddr *addr); +bool sk_addr_needs_port(SockAddr *addr); +bool sk_hostname_is_local(const char *name); +bool sk_address_is_local(SockAddr *addr); +bool sk_address_is_special_local(SockAddr *addr); int sk_addrtype(SockAddr *addr); void sk_addrcopy(SockAddr *addr, char *buf); void sk_addr_free(SockAddr *addr); @@ -142,11 +142,11 @@ SockAddr *sk_addr_dup(SockAddr *addr); /* NB, control of 'addr' is passed via sk_new, which takes responsibility * for freeing it, as for new_connection() */ -Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug *p); +Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline, + bool nodelay, bool keepalive, Plug *p); Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, - int local_host_only, int address_family); + bool local_host_only, int address_family); #define sk_plug(s,p) (((s)->vt->plug) (s, p)) #define sk_close(s) (((s)->vt->close) (s)) @@ -278,7 +278,7 @@ extern Plug *const nullplug; void backend_socket_log(Seat *seat, LogContext *logctx, int type, SockAddr *addr, int port, const char *error_msg, int error_code, Conf *conf, - int session_started); + bool session_started); void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len); #endif diff --git a/nullplug.c b/nullplug.c index 4fc16841..ca6c7c2c 100644 --- a/nullplug.c +++ b/nullplug.c @@ -13,7 +13,7 @@ static void nullplug_socket_log(Plug *plug, int type, SockAddr *addr, int port, } static void nullplug_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { } diff --git a/pageant.c b/pageant.c index a50a4397..8bdbe1f6 100644 --- a/pageant.c +++ b/pageant.c @@ -27,7 +27,7 @@ int random_byte(void) return 0; /* unreachable, but placate optimiser */ } -static int pageant_local = false; +static bool pageant_local = false; /* * rsakeys stores SSH-1 RSA keys. ssh2keys stores all SSH-2 keys. @@ -652,17 +652,17 @@ int pageant_count_ssh2_keys(void) return count234(ssh2keys); } -int pageant_add_ssh1_key(struct RSAKey *rkey) +bool pageant_add_ssh1_key(struct RSAKey *rkey) { return add234(rsakeys, rkey) == rkey; } -int pageant_add_ssh2_key(struct ssh2_userkey *skey) +bool pageant_add_ssh2_key(struct ssh2_userkey *skey) { return add234(ssh2keys, skey) == skey; } -int pageant_delete_ssh1_key(struct RSAKey *rkey) +bool pageant_delete_ssh1_key(struct RSAKey *rkey) { struct RSAKey *deleted = del234(rsakeys, rkey); if (!deleted) @@ -671,7 +671,7 @@ int pageant_delete_ssh1_key(struct RSAKey *rkey) return true; } -int pageant_delete_ssh2_key(struct ssh2_userkey *skey) +bool pageant_delete_ssh2_key(struct ssh2_userkey *skey) { struct ssh2_userkey *deleted = del234(ssh2keys, skey); if (!deleted) @@ -704,14 +704,14 @@ struct pageant_conn_state { pageant_logfn_t logfn; unsigned char lenbuf[4], pktbuf[AGENT_MAX_MSGLEN]; unsigned len, got; - int real_packet; + bool real_packet; int crLine; /* for coroutine in pageant_conn_receive */ Plug plug; }; static void pageant_conn_closing(Plug *plug, const char *error_msg, - int error_code, int calling_back) + int error_code, bool calling_back) { struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); @@ -805,7 +805,7 @@ struct pageant_listen_state { }; static void pageant_listen_closing(Plug *plug, const char *error_msg, - int error_code, int calling_back) + int error_code, bool calling_back) { struct pageant_listen_state *pl = container_of( plug, struct pageant_listen_state, plug); @@ -842,7 +842,7 @@ static int pageant_listen_accepting(Plug *plug, if ((err = sk_socket_error(pc->connsock)) != NULL) { sk_close(pc->connsock); sfree(pc); - return true; + return 1; } sk_set_frozen(pc->connsock, 0); @@ -998,7 +998,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase, { struct RSAKey *rkey = NULL; struct ssh2_userkey *skey = NULL; - int needs_pass; + bool needs_pass; int ret; int attempts; char *comment; @@ -1432,7 +1432,8 @@ int pageant_delete_all_keys(char **retstr) { strbuf *request; unsigned char *response; - int resplen, success; + int resplen; + bool success; void *vresponse; request = strbuf_new_for_agent_query(); diff --git a/pageant.h b/pageant.h index e491d4f8..e033546a 100644 --- a/pageant.h +++ b/pageant.h @@ -60,10 +60,10 @@ struct RSAKey *pageant_nth_ssh1_key(int i); struct ssh2_userkey *pageant_nth_ssh2_key(int i); int pageant_count_ssh1_keys(void); int pageant_count_ssh2_keys(void); -int pageant_add_ssh1_key(struct RSAKey *rkey); -int pageant_add_ssh2_key(struct ssh2_userkey *skey); -int pageant_delete_ssh1_key(struct RSAKey *rkey); -int pageant_delete_ssh2_key(struct ssh2_userkey *skey); +bool pageant_add_ssh1_key(struct RSAKey *rkey); +bool pageant_add_ssh2_key(struct ssh2_userkey *skey); +bool pageant_delete_ssh1_key(struct RSAKey *rkey); +bool pageant_delete_ssh2_key(struct ssh2_userkey *skey); /* * This callback must be provided by the Pageant front end code. diff --git a/pinger.c b/pinger.c index d03210e2..ddebc727 100644 --- a/pinger.c +++ b/pinger.c @@ -7,7 +7,7 @@ struct Pinger { int interval; - int pending; + bool pending; unsigned long when_set, next; Backend *backend; }; diff --git a/portfwd.c b/portfwd.c index 1515135d..eaba9820 100644 --- a/portfwd.c +++ b/portfwd.c @@ -27,8 +27,8 @@ typedef struct PortForwarding { ConnectionLayer *cl; /* the connection layer itself */ /* Note that ssh need not be filled in if c is non-NULL */ Socket *s; - int input_wanted; - int ready; + bool input_wanted; + bool ready; SocksState socks_state; /* * `hostname' and `port' are the real hostname and port, once @@ -51,7 +51,7 @@ typedef struct PortForwarding { struct PortListener { ConnectionLayer *cl; Socket *s; - int is_dynamic; + bool is_dynamic; /* * `hostname' and `port' are the real hostname and port, for * ordinary forwardings. @@ -110,7 +110,7 @@ static void pfl_log(Plug *plug, int type, SockAddr *addr, int port, static void pfd_close(struct PortForwarding *pf); static void pfd_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { struct PortForwarding *pf = container_of(plug, struct PortForwarding, plug); @@ -143,7 +143,7 @@ static void pfd_closing(Plug *plug, const char *error_msg, int error_code, static void pfl_terminate(struct PortListener *pl); static void pfl_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { struct PortListener *pl = (struct PortListener *) plug; pfl_terminate(pl); @@ -254,7 +254,7 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len) return; if (socks_version == 4 && message_type == 1) { /* CONNECT message */ - int name_based = false; + bool name_based = false; port = get_uint16(src); ipv4 = get_uint32(src); @@ -437,9 +437,9 @@ static const PlugVtable PortForwarding_plugvt = { static void pfd_chan_free(Channel *chan); static void pfd_open_confirmation(Channel *chan); static void pfd_open_failure(Channel *chan, const char *errtext); -static int pfd_send(Channel *chan, int is_stderr, const void *data, int len); +static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len); static void pfd_send_eof(Channel *chan); -static void pfd_set_input_wanted(Channel *chan, int wanted); +static void pfd_set_input_wanted(Channel *chan, bool wanted); static char *pfd_log_close_msg(Channel *chan); static const struct ChannelVtable PortForwarding_channelvt = { @@ -481,7 +481,7 @@ Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug) pf->cl = cl; pf->input_wanted = true; - pf->ready = 0; + pf->ready = false; pf->socks_state = SOCKS_NONE; pf->hostname = NULL; @@ -526,7 +526,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) s = constructor(ctx, plug); if ((err = sk_socket_error(s)) != NULL) { portfwd_raw_free(chan); - return true; + return 1; } pf = container_of(chan, struct PortForwarding, chan); @@ -626,7 +626,7 @@ static void pfl_terminate(struct PortListener *pl) free_portlistener_state(pl); } -static void pfd_set_input_wanted(Channel *chan, int wanted) +static void pfd_set_input_wanted(Channel *chan, bool wanted) { assert(chan->vt == &PortForwarding_channelvt); PortForwarding *pf = container_of(chan, PortForwarding, chan); @@ -644,7 +644,7 @@ static void pfd_chan_free(Channel *chan) /* * Called to send data down the raw connection. */ -static int pfd_send(Channel *chan, int is_stderr, const void *data, int len) +static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len) { assert(chan->vt == &PortForwarding_channelvt); PortForwarding *pf = container_of(chan, PortForwarding, chan); @@ -663,7 +663,7 @@ static void pfd_open_confirmation(Channel *chan) assert(chan->vt == &PortForwarding_channelvt); PortForwarding *pf = container_of(chan, PortForwarding, chan); - pf->ready = 1; + pf->ready = true; sk_set_frozen(pf->s, 0); sk_write(pf->s, NULL, 0); if (pf->socksbuf) { @@ -1050,8 +1050,8 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf) } } -int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port, - const char *keyhost, int keyport, Conf *conf) +bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port, + const char *keyhost, int keyport, Conf *conf) { PortFwdRecord *pfr; @@ -1091,7 +1091,7 @@ int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port, return true; } -int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port) +bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port) { PortFwdRecord pfr_key; @@ -1153,13 +1153,13 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret, pf->chan.initial_fixed_window_size = 0; pf->chan.vt = &PortForwarding_channelvt; pf->input_wanted = true; - pf->ready = 1; + pf->ready = true; pf->c = c; pf->cl = mgr->cl; pf->socks_state = SOCKS_NONE; pf->s = new_connection(addr, dummy_realhost, port, - 0, 1, 0, 0, &pf->plug, mgr->conf); + false, true, false, false, &pf->plug, mgr->conf); sfree(dummy_realhost); if ((err = sk_socket_error(pf->s)) != NULL) { char *err_ret = dupstr(err); diff --git a/proxy.c b/proxy.c index 89d34952..0aa9cf35 100644 --- a/proxy.c +++ b/proxy.c @@ -33,7 +33,7 @@ void proxy_activate (ProxySocket *p) /* we want to ignore new receive events until we have sent * all of our buffered receive data. */ - sk_set_frozen(p->sub_socket, 1); + sk_set_frozen(p->sub_socket, true); /* how many bytes of output have we buffered? */ output_before = bufchain_size(&p->pending_oob_output_data) + @@ -124,7 +124,7 @@ static void sk_proxy_write_eof (Socket *s) ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { - ps->pending_eof = 1; + ps->pending_eof = true; return; } sk_write_eof(ps->sub_socket); @@ -135,13 +135,13 @@ static void sk_proxy_flush (Socket *s) ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { - ps->pending_flush = 1; + ps->pending_flush = true; return; } sk_flush(ps->sub_socket); } -static void sk_proxy_set_frozen (Socket *s, int is_frozen) +static void sk_proxy_set_frozen (Socket *s, bool is_frozen) { ProxySocket *ps = container_of(s, ProxySocket, sock); @@ -200,7 +200,7 @@ static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, } static void plug_proxy_closing (Plug *p, const char *error_msg, - int error_code, int calling_back) + int error_code, bool calling_back) { ProxySocket *ps = container_of(p, ProxySocket, plugimpl); @@ -224,7 +224,7 @@ static void plug_proxy_receive (Plug *p, int urgent, char *data, int len) * process, hopefully it won't affect the protocol above us */ bufchain_add(&ps->pending_input_data, data, len); - ps->receive_urgent = urgent; + ps->receive_urgent = (urgent != 0); ps->receive_data = data; ps->receive_len = len; ps->negotiate(ps, PROXY_CHANGE_RECEIVE); @@ -262,7 +262,7 @@ static int plug_proxy_accepting(Plug *p, * This function can accept a NULL pointer as `addr', in which case * it will only check the host name. */ -int proxy_for_destination (SockAddr *addr, const char *hostname, +bool proxy_for_destination (SockAddr *addr, const char *hostname, int port, Conf *conf) { int s = 0, e = 0; @@ -277,7 +277,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname, * them. */ if (addr && sk_address_is_special_local(addr)) - return 0; /* do not proxy */ + return false; /* do not proxy */ /* * Check the host name and IP against the hard-coded @@ -286,7 +286,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname, if (!conf_get_bool(conf, CONF_even_proxy_localhost) && (sk_hostname_is_local(hostname) || (addr && sk_address_is_local(addr)))) - return 0; /* do not proxy */ + return false; /* do not proxy */ /* we want a string representation of the IP address for comparisons */ if (addr) { @@ -324,25 +324,27 @@ int proxy_for_destination (SockAddr *addr, const char *hostname, if ((addr && strnicmp(hostip + hostip_len - (e - s - 1), exclude_list + s + 1, e - s - 1) == 0) || strnicmp(hostname + hostname_len - (e - s - 1), - exclude_list + s + 1, e - s - 1) == 0) - return 0; /* IP/hostname range excluded. do not use proxy. */ - + exclude_list + s + 1, e - s - 1) == 0) { + /* IP/hostname range excluded. do not use proxy. */ + return false; + } } else if (exclude_list[e-1] == '*') { /* wildcard at end of entry */ if ((addr && strnicmp(hostip, exclude_list + s, e - s - 1) == 0) || - strnicmp(hostname, exclude_list + s, e - s - 1) == 0) - return 0; /* IP/hostname range excluded. do not use proxy. */ - + strnicmp(hostname, exclude_list + s, e - s - 1) == 0) { + /* IP/hostname range excluded. do not use proxy. */ + return false; + } } else { /* no wildcard at either end, so let's try an absolute * match (ie. a specific IP) */ if (addr && strnicmp(hostip, exclude_list + s, e - s) == 0) - return 0; /* IP/hostname excluded. do not use proxy. */ + return false; /* IP/hostname excluded. do not use proxy. */ if (strnicmp(hostname, exclude_list + s, e - s) == 0) - return 0; /* IP/hostname excluded. do not use proxy. */ + return false; /* IP/hostname excluded. do not use proxy. */ } s = e; @@ -354,7 +356,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname, } /* no matches in the exclude list, so use the proxy */ - return 1; + return true; } static char *dns_log_msg(const char *host, int addressfamily, @@ -410,8 +412,8 @@ static const struct PlugVtable ProxySocket_plugvt = { }; Socket *new_connection(SockAddr *addr, const char *hostname, - int port, int privport, - int oobinline, int nodelay, int keepalive, + int port, bool privport, + bool oobinline, bool nodelay, bool keepalive, Plug *plug, Conf *conf) { if (conf_get_int(conf, CONF_proxy_type) != PROXY_NONE && @@ -439,9 +441,9 @@ Socket *new_connection(SockAddr *addr, const char *hostname, ret->remote_port = port; ret->error = NULL; - ret->pending_flush = 0; - ret->pending_eof = 0; - ret->freeze = 0; + ret->pending_flush = false; + ret->pending_eof = false; + ret->freeze = false; bufchain_init(&ret->pending_input_data); bufchain_init(&ret->pending_output_data); @@ -530,7 +532,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, } Socket *new_listener(const char *srcaddr, int port, Plug *plug, - int local_host_only, Conf *conf, int addressfamily) + bool local_host_only, Conf *conf, int addressfamily) { /* TODO: SOCKS (and potentially others) support inbound * TODO: connections via the proxy. support them. @@ -778,7 +780,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change) strbuf *command = strbuf_new(); char hostname[512]; - int write_hostname = false; + bool write_hostname = false; put_byte(command, 4); /* SOCKS version 4 */ put_byte(command, 1); /* CONNECT command */ diff --git a/proxy.h b/proxy.h index e37b820c..2ecde43a 100644 --- a/proxy.h +++ b/proxy.h @@ -25,9 +25,9 @@ struct ProxySocket { bufchain pending_output_data; bufchain pending_oob_output_data; - int pending_flush; + bool pending_flush; bufchain pending_input_data; - int pending_eof; + bool pending_eof; #define PROXY_STATE_NEW -1 #define PROXY_STATE_ACTIVE 0 @@ -37,10 +37,10 @@ struct ProxySocket { * of the initialization/setup/negotiation with the * proxy server. */ - int freeze; /* should we freeze the underlying socket when - * we are done with the proxy negotiation? this - * simply caches the value of sk_set_frozen calls. - */ + bool freeze; /* should we freeze the underlying socket when + * we are done with the proxy negotiation? this + * simply caches the value of sk_set_frozen calls. + */ #define PROXY_CHANGE_NEW -1 #define PROXY_CHANGE_CLOSING 0 @@ -64,10 +64,10 @@ struct ProxySocket { /* closing */ const char *closing_error_msg; int closing_error_code; - int closing_calling_back; + bool closing_calling_back; /* receive */ - int receive_urgent; + bool receive_urgent; char *receive_data; int receive_len; diff --git a/pscp.c b/pscp.c index ebda4e01..a16825b9 100644 --- a/pscp.c +++ b/pscp.c @@ -26,25 +26,25 @@ #include "sftp.h" #include "storage.h" -static int list = 0; -static int verbose = 0; -static int recursive = 0; -static int preserve = 0; -static int targetshouldbedirectory = 0; -static int statistics = 1; +static bool list = false; +static bool verbose = false; +static bool recursive = false; +static bool preserve = false; +static bool targetshouldbedirectory = false; +static bool statistics = true; static int prev_stats_len = 0; -static int scp_unsafe_mode = 0; +static bool scp_unsafe_mode = false; static int errs = 0; -static int try_scp = 1; -static int try_sftp = 1; -static int main_cmd_is_sftp = 0; -static int fallback_cmd_is_sftp = 0; -static int using_sftp = 0; -static int uploading = 0; +static bool try_scp = true; +static bool try_sftp = true; +static bool main_cmd_is_sftp = false; +static bool fallback_cmd_is_sftp = false; +static bool using_sftp = false; +static bool uploading = false; static Backend *backend; static Conf *conf; -int sent_eof = false; +bool sent_eof = false; static void source(const char *src); static void rsource(const char *src); @@ -60,8 +60,8 @@ const char *const appname = "PSCP"; void ldisc_echoedit_update(Ldisc *ldisc) { } -static int pscp_output(Seat *, int is_stderr, const void *, int); -static int pscp_eof(Seat *); +static int pscp_output(Seat *, bool is_stderr, const void *, int); +static bool pscp_eof(Seat *); static const SeatVtable pscp_seat_vt = { pscp_output, @@ -148,7 +148,7 @@ static unsigned char *outptr; /* where to put the data */ static unsigned outlen; /* how much data required */ static unsigned char *pending = NULL; /* any spare data */ static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */ -static int pscp_output(Seat *seat, int is_stderr, +static int pscp_output(Seat *seat, bool is_stderr, const void *data, int datalen) { unsigned char *p = (unsigned char *) data; @@ -187,7 +187,7 @@ static int pscp_output(Seat *seat, int is_stderr, return 0; } -static int pscp_eof(Seat *seat) +static bool pscp_eof(Seat *seat) { /* * We usually expect to be the party deciding when to close the @@ -201,7 +201,7 @@ static int pscp_eof(Seat *seat) } return false; } -static int ssh_scp_recv(void *buf, int len) +static bool ssh_scp_recv(void *buf, int len) { outptr = buf; outlen = len; @@ -225,15 +225,15 @@ static int ssh_scp_recv(void *buf, int len) pending = NULL; } if (outlen == 0) - return len; + return true; } while (outlen > 0) { if (backend_exitcode(backend) >= 0 || ssh_sftp_loop_iteration() < 0) - return 0; /* doom */ + return false; /* doom */ } - return len; + return true; } /* @@ -455,19 +455,19 @@ static void do_cmd(char *host, char *user, char *cmd) conf_set_str(conf, CONF_remote_cmd2, ""); if (try_sftp) { /* First choice is SFTP subsystem. */ - main_cmd_is_sftp = 1; + main_cmd_is_sftp = true; conf_set_str(conf, CONF_remote_cmd, "sftp"); conf_set_bool(conf, CONF_ssh_subsys, true); if (try_scp) { /* Fallback is to use the provided scp command. */ - fallback_cmd_is_sftp = 0; + fallback_cmd_is_sftp = false; conf_set_str(conf, CONF_remote_cmd2, cmd); conf_set_bool(conf, CONF_ssh_subsys2, false); } else { /* Since we're not going to try SCP, we may as well try * harder to find an SFTP server, since in the current * implementation we have a spare slot. */ - fallback_cmd_is_sftp = 1; + fallback_cmd_is_sftp = true; /* see psftp.c for full explanation of this kludge */ conf_set_str(conf, CONF_remote_cmd2, "test -x /usr/lib/sftp-server &&" @@ -479,7 +479,7 @@ static void do_cmd(char *host, char *user, char *cmd) } } else { /* Don't try SFTP at all; just try the scp command. */ - main_cmd_is_sftp = 0; + main_cmd_is_sftp = false; conf_set_str(conf, CONF_remote_cmd, cmd); conf_set_bool(conf, CONF_ssh_subsys, false); } @@ -572,7 +572,7 @@ static char *colon(char *str) /* * Determine whether a string is entirely composed of dots. */ -static int is_dots(char *str) +static bool is_dots(char *str) { return str[strspn(str, ".")] == '\0'; } @@ -586,7 +586,7 @@ static int response(void) char ch, resp, rbuf[2048]; int p; - if (ssh_scp_recv(&resp, 1) <= 0) + if (!ssh_scp_recv(&resp, 1)) bump("Lost connection"); p = 0; @@ -599,7 +599,7 @@ static int response(void) case 1: /* error */ case 2: /* fatal error */ do { - if (ssh_scp_recv(&ch, 1) <= 0) + if (!ssh_scp_recv(&ch, 1)) bump("Protocol error: Lost connection"); rbuf[p++] = ch; } while (p < sizeof(rbuf) && ch != '\n'); @@ -613,14 +613,14 @@ static int response(void) } } -int sftp_recvdata(char *buf, int len) +bool sftp_recvdata(char *buf, int len) { return ssh_scp_recv(buf, len); } -int sftp_senddata(char *buf, int len) +bool sftp_senddata(char *buf, int len) { backend_send(backend, buf, len); - return 1; + return true; } int sftp_sendbuffer(void) { @@ -724,19 +724,19 @@ static struct scp_sftp_dirstack { int namepos, namelen; char *dirpath; char *wildcard; - int matched_something; /* wildcard match set was non-empty */ + bool matched_something; /* wildcard match set was non-empty */ } *scp_sftp_dirstack_head; static char *scp_sftp_remotepath, *scp_sftp_currentname; static char *scp_sftp_wildcard; -static int scp_sftp_targetisdir, scp_sftp_donethistarget; -static int scp_sftp_preserve, scp_sftp_recursive; +static bool scp_sftp_targetisdir, scp_sftp_donethistarget; +static bool scp_sftp_preserve, scp_sftp_recursive; static unsigned long scp_sftp_mtime, scp_sftp_atime; -static int scp_has_times; +static bool scp_has_times; static struct fxp_handle *scp_sftp_filehandle; static struct fxp_xfer *scp_sftp_xfer; static uint64_t scp_sftp_fileoffset; -int scp_source_setup(const char *target, int shouldbedir) +int scp_source_setup(const char *target, bool shouldbedir) { if (using_sftp) { /* @@ -746,7 +746,7 @@ int scp_source_setup(const char *target, int shouldbedir) struct sftp_packet *pktin; struct sftp_request *req; struct fxp_attrs attrs; - int ret; + bool ret; if (!fxp_init()) { tell_user(stderr, "unable to initialise SFTP: %s", fxp_error()); @@ -759,7 +759,7 @@ int scp_source_setup(const char *target, int shouldbedir) ret = fxp_stat_recv(pktin, req, &attrs); if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) - scp_sftp_targetisdir = 0; + scp_sftp_targetisdir = false; else scp_sftp_targetisdir = (attrs.permissions & 0040000) != 0; @@ -769,7 +769,7 @@ int scp_source_setup(const char *target, int shouldbedir) scp_sftp_remotepath = dupstr(target); - scp_has_times = 0; + scp_has_times = false; } else { (void) response(); } @@ -792,7 +792,7 @@ int scp_send_filetimes(unsigned long mtime, unsigned long atime) if (using_sftp) { scp_sftp_mtime = mtime; scp_sftp_atime = atime; - scp_has_times = 1; + scp_has_times = true; return 0; } else { char buf[80]; @@ -901,11 +901,10 @@ int scp_send_finish(void) struct fxp_attrs attrs; struct sftp_packet *pktin; struct sftp_request *req; - int ret; while (!xfer_done(scp_sftp_xfer)) { pktin = sftp_recv(); - ret = xfer_upload_gotpkt(scp_sftp_xfer, pktin); + int ret = xfer_upload_gotpkt(scp_sftp_xfer, pktin); if (ret <= 0) { tell_user(stderr, "error while writing: %s", fxp_error()); if (ret == INT_MIN) /* pktin not even freed */ @@ -925,7 +924,7 @@ int scp_send_finish(void) attrs.mtime = scp_sftp_mtime; req = fxp_fsetstat_send(scp_sftp_filehandle, attrs); pktin = sftp_wait_for_reply(req); - ret = fxp_fsetstat_recv(pktin, req); + bool ret = fxp_fsetstat_recv(pktin, req); if (!ret) { tell_user(stderr, "unable to set file times: %s", fxp_error()); errs++; @@ -934,7 +933,7 @@ int scp_send_finish(void) req = fxp_close_send(scp_sftp_filehandle); pktin = sftp_wait_for_reply(req); fxp_close_recv(pktin, req); - scp_has_times = 0; + scp_has_times = false; return 0; } else { backend_send(backend, "", 1); @@ -964,7 +963,7 @@ int scp_send_dirname(const char *name, int modes) struct fxp_attrs attrs; struct sftp_packet *pktin; struct sftp_request *req; - int ret; + bool ret; if (scp_sftp_targetisdir) { fullname = dupcat(scp_sftp_remotepath, "/", name, NULL); @@ -1031,7 +1030,7 @@ int scp_send_enddir(void) * right at the start, whereas scp_sink_init is called to * initialise every level of recursion in the protocol. */ -int scp_sink_setup(const char *source, int preserve, int recursive) +int scp_sink_setup(const char *source, bool preserve, bool recursive) { if (using_sftp) { char *newsource; @@ -1056,7 +1055,7 @@ int scp_sink_setup(const char *source, int preserve, int recursive) sfree(newsource); dupsource = dupstr(source); - lastpart = stripslashes(dupsource, 0); + lastpart = stripslashes(dupsource, false); wildcard = dupstr(lastpart); *lastpart = '\0'; if (*dupsource && dupsource[1]) { @@ -1109,7 +1108,7 @@ int scp_sink_setup(const char *source, int preserve, int recursive) } scp_sftp_preserve = preserve; scp_sftp_recursive = recursive; - scp_sftp_donethistarget = 0; + scp_sftp_donethistarget = false; scp_sftp_dirstack_head = NULL; } return 0; @@ -1133,7 +1132,7 @@ struct scp_sink_action { char *name; /* filename or dirname (not ENDDIR) */ long permissions; /* access permissions (not ENDDIR) */ uint64_t size; /* file size (not ENDDIR) */ - int settime; /* 1 if atime and mtime are filled */ + bool settime; /* true if atime and mtime are filled */ unsigned long atime, mtime; /* access times for the file */ }; @@ -1141,11 +1140,11 @@ int scp_get_sink_action(struct scp_sink_action *act) { if (using_sftp) { char *fname; - int must_free_fname; + bool must_free_fname; struct fxp_attrs attrs; struct sftp_packet *pktin; struct sftp_request *req; - int ret; + bool ret; if (!scp_sftp_dirstack_head) { if (!scp_sftp_donethistarget) { @@ -1153,8 +1152,8 @@ int scp_get_sink_action(struct scp_sink_action *act) * Simple case: we are only dealing with one file. */ fname = scp_sftp_remotepath; - must_free_fname = 0; - scp_sftp_donethistarget = 1; + must_free_fname = false; + scp_sftp_donethistarget = true; } else { /* * Even simpler case: one file _which we've done_. @@ -1176,11 +1175,11 @@ int scp_get_sink_action(struct scp_sink_action *act) head->names[head->namepos].filename)))) head->namepos++; /* skip . and .. */ if (head->namepos < head->namelen) { - head->matched_something = 1; + head->matched_something = true; fname = dupcat(head->dirpath, "/", head->names[head->namepos++].filename, NULL); - must_free_fname = 1; + must_free_fname = true; } else { /* * We've come to the end of the list; pop it off @@ -1345,7 +1344,7 @@ int scp_get_sink_action(struct scp_sink_action *act) newitem->dirpath = dupstr(fname); if (scp_sftp_wildcard) { newitem->wildcard = scp_sftp_wildcard; - newitem->matched_something = 0; + newitem->matched_something = false; scp_sftp_wildcard = NULL; } else { newitem->wildcard = NULL; @@ -1356,7 +1355,7 @@ int scp_get_sink_action(struct scp_sink_action *act) act->action = SCP_SINK_RETRY; } else { act->action = SCP_SINK_DIR; - act->buf = dupstr(stripslashes(fname, 0)); + act->buf = dupstr(stripslashes(fname, false)); act->name = act->buf; act->size = 0; /* duhh, it's a directory */ act->permissions = 07777 & attrs.permissions; @@ -1364,9 +1363,9 @@ int scp_get_sink_action(struct scp_sink_action *act) (attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) { act->atime = attrs.atime; act->mtime = attrs.mtime; - act->settime = 1; + act->settime = true; } else - act->settime = 0; + act->settime = false; } return 0; @@ -1375,7 +1374,7 @@ int scp_get_sink_action(struct scp_sink_action *act) * It's a file. Return SCP_SINK_FILE. */ act->action = SCP_SINK_FILE; - act->buf = dupstr(stripslashes(fname, 0)); + act->buf = dupstr(stripslashes(fname, false)); act->name = act->buf; if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) { act->size = attrs.size; @@ -1386,9 +1385,9 @@ int scp_get_sink_action(struct scp_sink_action *act) (attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) { act->atime = attrs.atime; act->mtime = attrs.mtime; - act->settime = 1; + act->settime = true; } else - act->settime = 0; + act->settime = false; if (must_free_fname) scp_sftp_currentname = fname; else @@ -1397,24 +1396,24 @@ int scp_get_sink_action(struct scp_sink_action *act) } } else { - int done = 0; + bool done = false; int i, bufsize; int action; char ch; - act->settime = 0; + act->settime = false; act->buf = NULL; bufsize = 0; while (!done) { - if (ssh_scp_recv(&ch, 1) <= 0) + if (!ssh_scp_recv(&ch, 1)) return 1; if (ch == '\n') bump("Protocol error: Unexpected newline"); i = 0; action = ch; do { - if (ssh_scp_recv(&ch, 1) <= 0) + if (!ssh_scp_recv(&ch, 1)) bump("Lost connection"); if (i >= bufsize) { bufsize = i + 128; @@ -1437,7 +1436,7 @@ int scp_get_sink_action(struct scp_sink_action *act) case 'T': if (sscanf(act->buf, "%lu %*d %lu %*d", &act->mtime, &act->atime) == 2) { - act->settime = 1; + act->settime = true; backend_send(backend, "", 1); continue; /* go round again */ } @@ -1457,7 +1456,7 @@ int scp_get_sink_action(struct scp_sink_action *act) * We will go round this loop only once, unless we hit * `continue' above. */ - done = 1; + done = true; } /* @@ -1542,7 +1541,7 @@ int scp_recv_filedata(char *data, int len) return actuallen; } else { - return ssh_scp_recv(data, len); + return ssh_scp_recv(data, len) ? len : 0; } } @@ -1763,19 +1762,19 @@ static void rsource(const char *src) static void sink(const char *targ, const char *src) { char *destfname; - int targisdir = 0; - int exists; + bool targisdir = false; + bool exists; int attr; WFile *f; uint64_t received; - int wrerror = 0; + bool wrerror = false; uint64_t stat_bytes; time_t stat_starttime, stat_lasttime; char *stat_name; attr = file_type(targ); if (attr == FILE_TYPE_DIRECTORY) - targisdir = 1; + targisdir = true; if (targetshouldbedirectory && !targisdir) bump("%s: Not a directory", targ); @@ -1825,7 +1824,7 @@ static void sink(const char *targ, const char *src) */ char *striptarget, *stripsrc; - striptarget = stripslashes(act.name, 1); + striptarget = stripslashes(act.name, true); if (striptarget != act.name) { tell_user(stderr, "warning: remote host sent a compound" " pathname '%s'", act.name); @@ -1844,7 +1843,7 @@ static void sink(const char *targ, const char *src) } if (src) { - stripsrc = stripslashes(src, 1); + stripsrc = stripslashes(src, true); if (strcmp(striptarget, stripsrc) && !using_sftp && !scp_unsafe_mode) { tell_user(stderr, "warning: remote host tried to write " @@ -1910,7 +1909,7 @@ static void sink(const char *targ, const char *src) stat_bytes = 0; stat_starttime = time(NULL); stat_lasttime = 0; - stat_name = stripslashes(destfname, 1); + stat_name = stripslashes(destfname, true); received = 0; while (received < act.size) { @@ -1928,7 +1927,7 @@ static void sink(const char *targ, const char *src) continue; } if (write_to_file(f, transbuf, read) != (int)read) { - wrerror = 1; + wrerror = true; /* FIXME: in sftp we can actually abort the transfer */ if (statistics) printf("\r%-25.25s | %50s\n", @@ -1974,7 +1973,7 @@ static void toremote(int argc, char *argv[]) char *cmd; int i, wc_type; - uploading = 1; + uploading = true; wtarg = argv[argc - 1]; @@ -2006,11 +2005,11 @@ static void toremote(int argc, char *argv[]) if (colon(argv[0]) != NULL) bump("%s: Remote to remote not supported", argv[0]); - wc_type = test_wildcard(argv[0], 1); + wc_type = test_wildcard(argv[0], true); if (wc_type == WCTYPE_NONEXISTENT) bump("%s: No such file or directory\n", argv[0]); else if (wc_type == WCTYPE_WILDCARD) - targetshouldbedirectory = 1; + targetshouldbedirectory = true; } cmd = dupprintf("scp%s%s%s%s -t %s", @@ -2032,7 +2031,7 @@ static void toremote(int argc, char *argv[]) continue; } - wc_type = test_wildcard(src, 1); + wc_type = test_wildcard(src, true); if (wc_type == WCTYPE_NONEXISTENT) { run_err("%s: No such file or directory", src); continue; @@ -2068,7 +2067,7 @@ static void tolocal(int argc, char *argv[]) const char *src, *targ; char *cmd; - uploading = 0; + uploading = false; if (argc != 2) bump("More than one remote source not supported"); @@ -2173,7 +2172,7 @@ static void get_dir_list(int argc, char *argv[]) if (using_sftp) { scp_sftp_listdir(src); } else { - while (ssh_scp_recv(&c, 1) > 0) + while (ssh_scp_recv(&c, 1)) tell_char(stdout, c); } } @@ -2239,8 +2238,8 @@ void cmdline_error(const char *p, ...) exit(1); } -const int share_can_be_downstream = true; -const int share_can_be_upstream = false; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = false; /* * Main program. (Called `psftp_main' because it gets called from @@ -2277,16 +2276,16 @@ int psftp_main(int argc, char *argv[]) } else if (ret == 1) { /* We have our own verbosity in addition to `flags'. */ if (flags & FLAG_VERBOSE) - verbose = 1; + verbose = true; } else if (strcmp(argv[i], "-pgpfp") == 0) { pgp_fingerprints(); return 1; } else if (strcmp(argv[i], "-r") == 0) { - recursive = 1; + recursive = true; } else if (strcmp(argv[i], "-p") == 0) { - preserve = 1; + preserve = true; } else if (strcmp(argv[i], "-q") == 0) { - statistics = 0; + statistics = false; } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0) { @@ -2295,15 +2294,15 @@ int psftp_main(int argc, char *argv[]) strcmp(argv[i], "--version") == 0) { version(); } else if (strcmp(argv[i], "-ls") == 0) { - list = 1; + list = true; } else if (strcmp(argv[i], "-batch") == 0) { - console_batch_mode = 1; + console_batch_mode = true; } else if (strcmp(argv[i], "-unsafe") == 0) { - scp_unsafe_mode = 1; + scp_unsafe_mode = true; } else if (strcmp(argv[i], "-sftp") == 0) { - try_scp = 0; try_sftp = 1; + try_scp = false; try_sftp = true; } else if (strcmp(argv[i], "-scp") == 0) { - try_scp = 1; try_sftp = 0; + try_scp = true; try_sftp = false; } else if (strcmp(argv[i], "--") == 0) { i++; break; @@ -2325,7 +2324,7 @@ int psftp_main(int argc, char *argv[]) if (argc < 2) usage(); if (argc > 2) - targetshouldbedirectory = 1; + targetshouldbedirectory = true; if (colon(argv[argc - 1]) != NULL) toremote(argc, argv); diff --git a/psftp.c b/psftp.c index 84c81454..3fb8ffbe 100644 --- a/psftp.c +++ b/psftp.c @@ -35,14 +35,14 @@ void do_sftp_cleanup(); char *pwd, *homedir; static Backend *backend; static Conf *conf; -int sent_eof = false; +bool sent_eof = false; /* ------------------------------------------------------------ * Seat vtable. */ -static int psftp_output(Seat *, int is_stderr, const void *, int); -static int psftp_eof(Seat *); +static int psftp_output(Seat *, bool is_stderr, const void *, int); +static bool psftp_eof(Seat *); static const SeatVtable psftp_seat_vt = { psftp_output, @@ -227,7 +227,7 @@ static void not_connected(void) /* ---------------------------------------------------------------------- * The meat of the `get' and `put' commands. */ -int sftp_get_file(char *fname, char *outfname, int recurse, int restart) +bool sftp_get_file(char *fname, char *outfname, bool recurse, bool restart) { struct fxp_handle *fh; struct sftp_packet *pktin; @@ -235,7 +235,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) struct fxp_xfer *xfer; uint64_t offset; WFile *file; - int ret, shown_err = false; + bool toret, shown_err = false; struct fxp_attrs attrs; /* @@ -244,7 +244,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) * subsequent FXP_OPEN will return a usable error message.) */ if (recurse) { - int result; + bool result; req = fxp_stat_send(fname); pktin = sftp_wait_for_reply(req); @@ -267,7 +267,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) if (file_type(outfname) != FILE_TYPE_DIRECTORY && !create_directory(outfname)) { printf("%s: Cannot create directory\n", outfname); - return 0; + return false; } /* @@ -281,7 +281,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) if (!dirhandle) { printf("%s: unable to open directory: %s\n", fname, fxp_error()); - return 0; + return false; } nnames = namesize = 0; ournames = NULL; @@ -302,7 +302,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) fxp_close_recv(pktin, req); sfree(ournames); - return 0; + return false; } if (names->nnames == 0) { fxp_free_names(names); @@ -352,12 +352,13 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) if (restart) { while (i < nnames) { char *nextoutfname; - int ret; + bool nonexistent; nextoutfname = dir_file_cat(outfname, ournames[i]->filename); - ret = (file_type(nextoutfname) == FILE_TYPE_NONEXISTENT); + nonexistent = (file_type(nextoutfname) == + FILE_TYPE_NONEXISTENT); sfree(nextoutfname); - if (ret) + if (nonexistent) break; i++; } @@ -373,20 +374,21 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) */ for (; i < nnames; i++) { char *nextfname, *nextoutfname; - int ret; + bool retd; nextfname = dupcat(fname, "/", ournames[i]->filename, NULL); nextoutfname = dir_file_cat(outfname, ournames[i]->filename); - ret = sftp_get_file(nextfname, nextoutfname, recurse, restart); + retd = sftp_get_file( + nextfname, nextoutfname, recurse, restart); restart = false; /* after first partial file, do full */ sfree(nextoutfname); sfree(nextfname); - if (!ret) { + if (!retd) { for (i = 0; i < nnames; i++) { fxp_free_name(ournames[i]); } sfree(ournames); - return 0; + return false; } } @@ -398,7 +400,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) } sfree(ournames); - return 1; + return true; } } @@ -413,7 +415,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) if (!fh) { printf("%s: open for read: %s\n", fname, fxp_error()); - return 0; + return false; } if (restart) { @@ -429,7 +431,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) pktin = sftp_wait_for_reply(req); fxp_close_recv(pktin, req); - return 0; + return false; } if (restart) { @@ -441,7 +443,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) pktin = sftp_wait_for_reply(req); fxp_close_recv(pktin, req); - return 0; + return false; } offset = get_file_posn(file); @@ -456,24 +458,24 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) * FIXME: we can use FXP_FSTAT here to get the file size, and * thus put up a progress bar. */ - ret = 1; + toret = true; xfer = xfer_download_init(fh, offset); while (!xfer_done(xfer)) { void *vbuf; - int len; + int retd, len; int wpos, wlen; xfer_download_queue(xfer); pktin = sftp_recv(); - ret = xfer_download_gotpkt(xfer, pktin); - if (ret <= 0) { + retd = xfer_download_gotpkt(xfer, pktin); + if (retd <= 0) { if (!shown_err) { printf("error while reading: %s\n", fxp_error()); shown_err = true; } - if (ret == INT_MIN) /* pktin not even freed */ + if (retd == INT_MIN) /* pktin not even freed */ sfree(pktin); - ret = 0; + toret = false; } while (xfer_download_data(xfer, &vbuf, &len)) { @@ -484,14 +486,14 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) wlen = write_to_file(file, buf + wpos, len - wpos); if (wlen <= 0) { printf("error while writing local file\n"); - ret = 0; + toret = false; xfer_set_error(xfer); break; } wpos += wlen; } if (wpos < len) { /* we had an error */ - ret = 0; + toret = false; xfer_set_error(xfer); } @@ -507,10 +509,10 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) pktin = sftp_wait_for_reply(req); fxp_close_recv(pktin, req); - return ret; + return toret; } -int sftp_put_file(char *fname, char *outfname, int recurse, int restart) +bool sftp_put_file(char *fname, char *outfname, bool recurse, bool restart) { struct fxp_handle *fh; struct fxp_xfer *xfer; @@ -518,7 +520,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) struct sftp_request *req; uint64_t offset; RFile *file; - int err = 0, eof; + bool err = false, eof; struct fxp_attrs attrs; long permissions; @@ -528,7 +530,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) * subsequent fopen will return an error message.) */ if (recurse && file_type(fname) == FILE_TYPE_DIRECTORY) { - int result; + bool result; int nnames, namesize; char *name, **ournames; DirHandle *dh; @@ -551,7 +553,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) if (!result) { printf("%s: create directory: %s\n", outfname, fxp_error()); - return 0; + return false; } } @@ -564,7 +566,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) dh = open_directory(fname); if (!dh) { printf("%s: unable to open directory\n", fname); - return 0; + return false; } while ((name = read_filename(dh)) != NULL) { if (nnames >= namesize) { @@ -617,20 +619,20 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) */ for (; i < nnames; i++) { char *nextfname, *nextoutfname; - int ret; + bool retd; nextfname = dir_file_cat(fname, ournames[i]); nextoutfname = dupcat(outfname, "/", ournames[i], NULL); - ret = sftp_put_file(nextfname, nextoutfname, recurse, restart); + retd = sftp_put_file(nextfname, nextoutfname, recurse, restart); restart = false; /* after first partial file, do full */ sfree(nextoutfname); sfree(nextfname); - if (!ret) { + if (!retd) { for (i = 0; i < nnames; i++) { sfree(ournames[i]); } sfree(ournames); - return 0; + return false; } } @@ -642,13 +644,13 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) } sfree(ournames); - return 1; + return true; } file = open_existing_file(fname, NULL, NULL, NULL, &permissions); if (!file) { printf("local: unable to open %s\n", fname); - return 0; + return false; } attrs.flags = 0; PUT_PERMISSIONS(attrs, permissions); @@ -665,25 +667,25 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) if (!fh) { close_rfile(file); printf("%s: open for write: %s\n", outfname, fxp_error()); - return 0; + return false; } if (restart) { struct fxp_attrs attrs; - int ret; + bool retd; req = fxp_fstat_send(fh); pktin = sftp_wait_for_reply(req); - ret = fxp_fstat_recv(pktin, req, &attrs); + retd = fxp_fstat_recv(pktin, req, &attrs); - if (!ret) { + if (!retd) { printf("read size of %s: %s\n", outfname, fxp_error()); - err = 1; + err = true; goto cleanup; } if (!(attrs.flags & SSH_FILEXFER_ATTR_SIZE)) { printf("read size of %s: size was not given\n", outfname); - err = 1; + err = true; goto cleanup; } offset = attrs.size; @@ -702,7 +704,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) * thus put up a progress bar. */ xfer = xfer_upload_init(fh, offset); - eof = 0; + eof = false; while ((!err && !eof) || !xfer_done(xfer)) { char buffer[4096]; int len, ret; @@ -711,9 +713,9 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) len = read_from_file(file, buffer, sizeof(buffer)); if (len == -1) { printf("error while reading local file\n"); - err = 1; + err = true; } else if (len == 0) { - eof = 1; + eof = true; } else { xfer_upload_data(xfer, buffer, len); } @@ -727,7 +729,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) sfree(pktin); if (!err) { printf("error while writing: %s\n", fxp_error()); - err = 1; + err = true; } } } @@ -741,13 +743,13 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) if (!fxp_close_recv(pktin, req)) { if (!err) { printf("error while closing: %s", fxp_error()); - err = 1; + err = true; } } close_rfile(file); - return (err == 0) ? 1 : 0; + return !err; } /* ---------------------------------------------------------------------- @@ -768,7 +770,8 @@ SftpWildcardMatcher *sftp_begin_wildcard_matching(char *name) struct sftp_request *req; char *wildcard; char *unwcdir, *tmpdir, *cdir; - int len, check; + int len; + bool check; SftpWildcardMatcher *swcm; struct fxp_handle *dirh; @@ -777,7 +780,7 @@ SftpWildcardMatcher *sftp_begin_wildcard_matching(char *name) * a fully specified directory part, followed by a wildcard * after that. */ - wildcard = stripslashes(name, 0); + wildcard = stripslashes(name, false); unwcdir = dupstr(name); len = wildcard - name; @@ -904,33 +907,34 @@ void sftp_finish_wildcard_matching(SftpWildcardMatcher *swcm) * argument and iterate over every matching file. Used in several * PSFTP commands (rmdir, rm, chmod, mv). */ -int wildcard_iterate(char *filename, int (*func)(void *, char *), void *ctx) +bool wildcard_iterate(char *filename, bool (*func)(void *, char *), void *ctx) { char *unwcfname, *newname, *cname; - int is_wc, ret; + bool is_wc, toret; unwcfname = snewn(strlen(filename)+1, char); is_wc = !wc_unescape(unwcfname, filename); if (is_wc) { SftpWildcardMatcher *swcm = sftp_begin_wildcard_matching(filename); - int matched = false; + bool matched = false; sfree(unwcfname); if (!swcm) - return 0; + return false; - ret = 1; + toret = true; while ( (newname = sftp_wildcard_get_filename(swcm)) != NULL ) { cname = canonify(newname); if (!cname) { printf("%s: canonify: %s\n", newname, fxp_error()); - ret = 0; + toret = false; } sfree(newname); matched = true; - ret &= func(ctx, cname); + if (!func(ctx, cname)) + toret = false; sfree(cname); } @@ -944,23 +948,23 @@ int wildcard_iterate(char *filename, int (*func)(void *, char *), void *ctx) cname = canonify(unwcfname); if (!cname) { printf("%s: canonify: %s\n", filename, fxp_error()); - ret = 0; + toret = false; } - ret = func(ctx, cname); + toret = func(ctx, cname); sfree(cname); sfree(unwcfname); } - return ret; + return toret; } /* * Handy helper function. */ -int is_wildcard(char *name) +bool is_wildcard(char *name) { char *unwcfname = snewn(strlen(name)+1, char); - int is_wc = !wc_unescape(unwcfname, name); + bool is_wc = !wc_unescape(unwcfname, name); sfree(unwcfname); return is_wc; } @@ -1040,10 +1044,11 @@ int sftp_cmd_ls(struct sftp_command *cmd) wildcard = NULL; } else { char *tmpdir; - int len, check; + int len; + bool check; sfree(unwcdir); - wildcard = stripslashes(dir, 0); + wildcard = stripslashes(dir, false); unwcdir = dupstr(dir); len = wildcard - dir; unwcdir[len] = '\0'; @@ -1207,11 +1212,11 @@ int sftp_cmd_pwd(struct sftp_command *cmd) * transfer (never as a different local name for a remote file) and * can handle wildcards. */ -int sftp_general_get(struct sftp_command *cmd, int restart, int multiple) +int sftp_general_get(struct sftp_command *cmd, bool restart, bool multiple) { char *fname, *unwcfname, *origfname, *origwfname, *outfname; - int i, ret; - int recurse = false; + int i, toret; + bool recurse = false; if (!backend) { not_connected(); @@ -1238,7 +1243,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple) return 0; } - ret = 1; + toret = 1; do { SftpWildcardMatcher *swcm; @@ -1278,9 +1283,9 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple) if (!multiple && i < cmd->nwords) outfname = cmd->words[i++]; else - outfname = stripslashes(origwfname, 0); + outfname = stripslashes(origwfname, false); - ret = sftp_get_file(fname, outfname, recurse, restart); + toret = sftp_get_file(fname, outfname, recurse, restart); sfree(fname); @@ -1294,24 +1299,24 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple) sfree(unwcfname); if (swcm) sftp_finish_wildcard_matching(swcm); - if (!ret) - return ret; + if (!toret) + return toret; } while (multiple && i < cmd->nwords); - return ret; + return toret; } int sftp_cmd_get(struct sftp_command *cmd) { - return sftp_general_get(cmd, 0, 0); + return sftp_general_get(cmd, false, false); } int sftp_cmd_mget(struct sftp_command *cmd) { - return sftp_general_get(cmd, 0, 1); + return sftp_general_get(cmd, false, true); } int sftp_cmd_reget(struct sftp_command *cmd) { - return sftp_general_get(cmd, 1, 0); + return sftp_general_get(cmd, true, false); } /* @@ -1323,11 +1328,12 @@ int sftp_cmd_reget(struct sftp_command *cmd) * transfer (never as a different remote name for a local file) and * can handle wildcards. */ -int sftp_general_put(struct sftp_command *cmd, int restart, int multiple) +int sftp_general_put(struct sftp_command *cmd, bool restart, bool multiple) { char *fname, *wfname, *origoutfname, *outfname; - int i, ret; - int recurse = false; + int i; + int toret; + bool recurse = false; if (!backend) { not_connected(); @@ -1354,7 +1360,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple) return 0; } - ret = 1; + toret = 1; do { WildcardMatcher *wcm; fname = cmd->words[i++]; @@ -1377,7 +1383,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple) if (!multiple && i < cmd->nwords) origoutfname = cmd->words[i++]; else - origoutfname = stripslashes(wfname, 1); + origoutfname = stripslashes(wfname, true); outfname = canonify(origoutfname); if (!outfname) { @@ -1388,7 +1394,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple) } return 0; } - ret = sftp_put_file(wfname, outfname, recurse, restart); + toret = sftp_put_file(wfname, outfname, recurse, restart); sfree(outfname); if (wcm) { @@ -1402,24 +1408,24 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple) if (wcm) finish_wildcard_matching(wcm); - if (!ret) - return ret; + if (!toret) + return toret; } while (multiple && i < cmd->nwords); - return ret; + return toret; } int sftp_cmd_put(struct sftp_command *cmd) { - return sftp_general_put(cmd, 0, 0); + return sftp_general_put(cmd, false, false); } int sftp_cmd_mput(struct sftp_command *cmd) { - return sftp_general_put(cmd, 0, 1); + return sftp_general_put(cmd, false, true); } int sftp_cmd_reput(struct sftp_command *cmd) { - return sftp_general_put(cmd, 1, 0); + return sftp_general_put(cmd, true, false); } int sftp_cmd_mkdir(struct sftp_command *cmd) @@ -1427,7 +1433,7 @@ int sftp_cmd_mkdir(struct sftp_command *cmd) char *dir; struct sftp_packet *pktin; struct sftp_request *req; - int result; + bool result; int i, ret; if (!backend) { @@ -1464,11 +1470,11 @@ int sftp_cmd_mkdir(struct sftp_command *cmd) return ret; } -static int sftp_action_rmdir(void *vctx, char *dir) +static bool sftp_action_rmdir(void *vctx, char *dir) { struct sftp_packet *pktin; struct sftp_request *req; - int result; + bool result; req = fxp_rmdir_send(dir); pktin = sftp_wait_for_reply(req); @@ -1476,12 +1482,12 @@ static int sftp_action_rmdir(void *vctx, char *dir) if (!result) { printf("rmdir %s: %s\n", dir, fxp_error()); - return 0; + return false; } printf("rmdir %s: OK\n", dir); - return 1; + return true; } int sftp_cmd_rmdir(struct sftp_command *cmd) @@ -1505,11 +1511,11 @@ int sftp_cmd_rmdir(struct sftp_command *cmd) return ret; } -static int sftp_action_rm(void *vctx, char *fname) +static bool sftp_action_rm(void *vctx, char *fname) { struct sftp_packet *pktin; struct sftp_request *req; - int result; + bool result; req = fxp_remove_send(fname); pktin = sftp_wait_for_reply(req); @@ -1517,12 +1523,12 @@ static int sftp_action_rm(void *vctx, char *fname) if (!result) { printf("rm %s: %s\n", fname, fxp_error()); - return 0; + return false; } printf("rm %s: OK\n", fname); - return 1; + return true; } int sftp_cmd_rm(struct sftp_command *cmd) @@ -1546,12 +1552,12 @@ int sftp_cmd_rm(struct sftp_command *cmd) return ret; } -static int check_is_dir(char *dstfname) +static bool check_is_dir(char *dstfname) { struct sftp_packet *pktin; struct sftp_request *req; struct fxp_attrs attrs; - int result; + bool result; req = fxp_stat_send(dstfname); pktin = sftp_wait_for_reply(req); @@ -1567,17 +1573,17 @@ static int check_is_dir(char *dstfname) struct sftp_context_mv { char *dstfname; - int dest_is_dir; + bool dest_is_dir; }; -static int sftp_action_mv(void *vctx, char *srcfname) +static bool sftp_action_mv(void *vctx, char *srcfname) { struct sftp_context_mv *ctx = (struct sftp_context_mv *)vctx; struct sftp_packet *pktin; struct sftp_request *req; const char *error; char *finalfname, *newcanon = NULL; - int ret, result; + bool toret, result; if (ctx->dest_is_dir) { char *p; @@ -1590,7 +1596,7 @@ static int sftp_action_mv(void *vctx, char *srcfname) if (!newcanon) { printf("%s: canonify: %s\n", newname, fxp_error()); sfree(newname); - return 0; + return false; } sfree(newname); @@ -1607,14 +1613,14 @@ static int sftp_action_mv(void *vctx, char *srcfname) if (error) { printf("mv %s %s: %s\n", srcfname, finalfname, error); - ret = 0; + toret = false; } else { printf("%s -> %s\n", srcfname, finalfname); - ret = 1; + toret = true; } sfree(newcanon); - return ret; + return toret; } int sftp_cmd_mv(struct sftp_command *cmd) @@ -1666,12 +1672,12 @@ struct sftp_context_chmod { unsigned attrs_clr, attrs_xor; }; -static int sftp_action_chmod(void *vctx, char *fname) +static bool sftp_action_chmod(void *vctx, char *fname) { struct fxp_attrs attrs; struct sftp_packet *pktin; struct sftp_request *req; - int result; + bool result; unsigned oldperms, newperms; struct sftp_context_chmod *ctx = (struct sftp_context_chmod *)vctx; @@ -1682,7 +1688,7 @@ static int sftp_action_chmod(void *vctx, char *fname) if (!result || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) { printf("get attrs for %s: %s\n", fname, result ? "file permissions not provided" : fxp_error()); - return 0; + return false; } attrs.flags = SSH_FILEXFER_ATTR_PERMISSIONS; /* perms _only_ */ @@ -1692,7 +1698,7 @@ static int sftp_action_chmod(void *vctx, char *fname) newperms = attrs.permissions & 07777; if (oldperms == newperms) - return 1; /* no need to do anything! */ + return true; /* no need to do anything! */ req = fxp_setstat_send(fname, attrs); pktin = sftp_wait_for_reply(req); @@ -1700,12 +1706,12 @@ static int sftp_action_chmod(void *vctx, char *fname) if (!result) { printf("set attrs for %s: %s\n", fname, fxp_error()); - return 0; + return false; } printf("%s: %04o -> %04o\n", fname, oldperms, newperms); - return 1; + return true; } int sftp_cmd_chmod(struct sftp_command *cmd) @@ -1925,7 +1931,7 @@ static struct sftp_cmd_lookup { * `shorthelp' is the name of a primary command, which * contains the help that should double up for this command. */ - int listed; /* do we list this in primary help? */ + bool listed; /* do we list this in primary help? */ const char *shorthelp; const char *longhelp; int (*obey) (struct sftp_command *); @@ -2225,7 +2231,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags) char *line; struct sftp_command *cmd; char *p, *q, *r; - int quoting; + bool quoting; cmd = snew(struct sftp_command); cmd->words = NULL; @@ -2302,7 +2308,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags) break; /* mark start of word */ q = r = p; /* q sits at start, r writes word */ - quoting = 0; + quoting = false; while (*p) { if (!quoting && (*p == ' ' || *p == '\t')) break; /* reached end of word */ @@ -2461,7 +2467,7 @@ int do_sftp(int mode, int modeflags, char *batchfile) * Dirty bits: integration with PuTTY. */ -static int verbose = 0; +static bool verbose = false; void ldisc_echoedit_update(Ldisc *ldisc) { } @@ -2488,7 +2494,7 @@ static unsigned char *outptr; /* where to put the data */ static unsigned outlen; /* how much data required */ static unsigned char *pending = NULL; /* any spare data */ static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */ -static int psftp_output(Seat *seat, int is_stderr, +static int psftp_output(Seat *seat, bool is_stderr, const void *data, int datalen) { unsigned char *p = (unsigned char *) data; @@ -2534,7 +2540,7 @@ static int psftp_output(Seat *seat, int is_stderr, return 0; } -static int psftp_eof(Seat *seat) +static bool psftp_eof(Seat *seat) { /* * We expect to be the party deciding when to close the @@ -2548,7 +2554,7 @@ static int psftp_eof(Seat *seat) return false; } -int sftp_recvdata(char *buf, int len) +bool sftp_recvdata(char *buf, int len) { outptr = (unsigned char *) buf; outlen = len; @@ -2572,20 +2578,20 @@ int sftp_recvdata(char *buf, int len) pending = NULL; } if (outlen == 0) - return 1; + return true; } while (outlen > 0) { if (backend_exitcode(backend) >= 0 || ssh_sftp_loop_iteration() < 0) - return 0; /* doom */ + return false; /* doom */ } - return 1; + return true; } -int sftp_senddata(char *buf, int len) +bool sftp_senddata(char *buf, int len) { backend_send(backend, buf, len); - return 1; + return true; } int sftp_sendbuffer(void) { @@ -2839,8 +2845,8 @@ void cmdline_error(const char *p, ...) exit(1); } -const int share_can_be_downstream = true; -const int share_can_be_upstream = false; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = false; /* * Main program. Parse arguments etc. @@ -2886,7 +2892,7 @@ int psftp_main(int argc, char *argv[]) } else if (ret == 1) { /* We have our own verbosity in addition to `flags'. */ if (flags & FLAG_VERBOSE) - verbose = 1; + verbose = true; } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0) { @@ -2898,7 +2904,7 @@ int psftp_main(int argc, char *argv[]) strcmp(argv[i], "--version") == 0) { version(); } else if (strcmp(argv[i], "-batch") == 0) { - console_batch_mode = 1; + console_batch_mode = true; } else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) { mode = 1; batchfile = argv[++i]; diff --git a/psftp.h b/psftp.h index c41675a9..26a9d23b 100644 --- a/psftp.h +++ b/psftp.h @@ -43,7 +43,7 @@ int ssh_sftp_loop_iteration(void); * false, a back end is not (intentionally) active at all (e.g. * psftp before an `open' command). */ -char *ssh_sftp_get_cmdline(const char *prompt, int backend_required); +char *ssh_sftp_get_cmdline(const char *prompt, bool backend_required); /* * Platform-specific function called when we're about to make a @@ -149,7 +149,7 @@ void close_directory(DirHandle *dir); enum { WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD }; -int test_wildcard(const char *name, int cmdline); +int test_wildcard(const char *name, bool cmdline); /* * Actually return matching file names for a local wildcard. @@ -168,12 +168,12 @@ void finish_wildcard_matching(WildcardMatcher *dir); * * Returns true if the filename is kosher, false if dangerous. */ -int vet_filename(const char *name); +bool vet_filename(const char *name); /* - * Create a directory. Returns 0 on error, !=0 on success. + * Create a directory. Returns true on success, false on error. */ -int create_directory(const char *name); +bool create_directory(const char *name); /* * Concatenate a directory name and a file name. The way this is @@ -196,6 +196,6 @@ char *dir_file_cat(const char *dir, const char *file); * pair of overloaded functions, one mapping mutable->mutable and the * other const->const :-( */ -char *stripslashes(const char *str, int local); +char *stripslashes(const char *str, bool local); #endif /* PUTTY_PSFTP_H */ diff --git a/putty.h b/putty.h index f6898aab..fdef2801 100644 --- a/putty.h +++ b/putty.h @@ -153,7 +153,7 @@ struct sesslist { struct unicode_data { char **uni_tbl; - int dbcs_screenfont; + bool dbcs_screenfont; int font_codepage; int line_codepage; wchar_t unitab_scoacs[256]; @@ -497,7 +497,7 @@ struct BackendVtable { const char *(*init) (Seat *seat, Backend **backend_out, LogContext *logctx, Conf *conf, const char *host, int port, - char **realhost, int nodelay, int keepalive); + char **realhost, bool nodelay, bool keepalive); void (*free) (Backend *be); /* Pass in a replacement configuration. */ @@ -509,13 +509,13 @@ struct BackendVtable { void (*size) (Backend *be, int width, int height); void (*special) (Backend *be, SessionSpecialCode code, int arg); const SessionSpecial *(*get_specials) (Backend *be); - int (*connected) (Backend *be); + bool (*connected) (Backend *be); int (*exitcode) (Backend *be); /* If back->sendok() returns false, the backend doesn't currently * want input data, so the frontend should avoid acquiring any if * possible (passing back-pressure on to its sender). */ - int (*sendok) (Backend *be); - int (*ldisc_option_state) (Backend *be, int); + bool (*sendok) (Backend *be); + bool (*ldisc_option_state) (Backend *be, int); void (*provide_ldisc) (Backend *be, Ldisc *ldisc); /* Tells the back end that the front end buffer is clearing. */ void (*unthrottle) (Backend *be, int bufsize); @@ -523,7 +523,7 @@ struct BackendVtable { /* Only implemented in the SSH protocol: check whether a * connection-sharing upstream exists for a given configuration. */ - int (*test_for_upstream)(const char *host, int port, Conf *conf); + bool (*test_for_upstream)(const char *host, int port, Conf *conf); const char *name; int protocol; @@ -595,7 +595,7 @@ GLOBAL int default_port; /* * This is set true by cmdline.c iff a session is loaded with "-load". */ -GLOBAL int loaded_session; +GLOBAL bool loaded_session; /* * This is set to the name of the loaded session. */ @@ -619,7 +619,7 @@ GLOBAL char *cmdline_session_name; */ typedef struct { char *prompt; - int echo; + bool echo; /* * 'result' must be a dynamically allocated array of exactly * 'resultsize' chars. The code for actually reading input may @@ -642,11 +642,11 @@ typedef struct { * information (so the caller should ensure that the supplied text is * sufficient). */ - int to_server; + bool to_server; char *name; /* Short description, perhaps for dialog box title */ - int name_reqd; /* Display of `name' required or optional? */ + bool name_reqd; /* Display of `name' required or optional? */ char *instruction; /* Long description, maybe with embedded newlines */ - int instr_reqd; /* Display of `instruction' required or optional? */ + bool instr_reqd; /* Display of `instruction' required or optional? */ size_t n_prompts; /* May be zero (in which case display the foregoing, * if any, and return success) */ prompt_t **prompts; @@ -654,7 +654,7 @@ typedef struct { * seat_get_userpass_input(); initially NULL */ } prompts_t; prompts_t *new_prompts(); -void add_prompt(prompts_t *p, char *promptstr, int echo); +void add_prompt(prompts_t *p, char *promptstr, bool echo); void prompt_set_result(prompt_t *pr, const char *newstr); void prompt_ensure_result_size(prompt_t *pr, int len); /* Burn the evidence. (Assumes _all_ strings want free()ing.) */ @@ -668,7 +668,7 @@ void free_prompts(prompts_t *p); * background. */ typedef struct optionalrgb { - unsigned char enabled; + bool enabled; unsigned char r, g, b; } optionalrgb; extern const optionalrgb optionalrgb_none; @@ -742,7 +742,7 @@ struct SeatVtable { * * The return value is the current size of the output backlog. */ - int (*output)(Seat *seat, int is_stderr, const void *data, int len); + int (*output)(Seat *seat, bool is_stderr, const void *data, int len); /* * Called when the back end wants to indicate that EOF has arrived @@ -750,7 +750,7 @@ struct SeatVtable { * we intend to keep the session open in the other direction, or * true to indicate that if they're closing so are we. */ - int (*eof)(Seat *seat); + bool (*eof)(Seat *seat); /* * Try to get answers from a set of interactive login prompts. The @@ -884,14 +884,14 @@ struct SeatVtable { * user in the UTF-8 character set. (Affects e.g. visual erase * handling in local line editing.) */ - int (*is_utf8)(Seat *seat); + bool (*is_utf8)(Seat *seat); /* * Notify the seat that the back end, and/or the ldisc between * them, have changed their idea of whether they currently want * local echo and/or local line editing enabled. */ - void (*echoedit_update)(Seat *seat, int echoing, int editing); + void (*echoedit_update)(Seat *seat, bool echoing, bool editing); /* * Return the local X display string relevant to a seat, or NULL @@ -904,7 +904,7 @@ struct SeatVtable { * by returning true and filling in the output pointer. Return * false if there isn't one or if the concept is meaningless. */ - int (*get_windowid)(Seat *seat, long *id_out); + bool (*get_windowid)(Seat *seat, long *id_out); /* * Return the size of the terminal window in pixels. If the @@ -912,7 +912,7 @@ struct SeatVtable { * return false; otherwise fill in the output pointers and return * true. */ - int (*get_window_pixel_size)(Seat *seat, int *width, int *height); + bool (*get_window_pixel_size)(Seat *seat, int *width, int *height); }; #define seat_output(seat, is_stderr, data, len) \ @@ -964,8 +964,8 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...); * These are generally obvious, except for is_utf8, where you might * plausibly want to return either fixed answer 'no' or 'yes'. */ -int nullseat_output(Seat *seat, int is_stderr, const void *data, int len); -int nullseat_eof(Seat *seat); +int nullseat_output(Seat *seat, bool is_stderr, const void *data, int len); +bool nullseat_eof(Seat *seat); int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input); void nullseat_notify_remote_exit(Seat *seat); void nullseat_connection_fatal(Seat *seat, const char *message); @@ -982,12 +982,12 @@ int nullseat_confirm_weak_crypto_primitive( int nullseat_confirm_weak_cached_hostkey( Seat *seat, const char *algname, const char *betteralgs, void (*callback)(void *ctx, int result), void *ctx); -int nullseat_is_never_utf8(Seat *seat); -int nullseat_is_always_utf8(Seat *seat); -void nullseat_echoedit_update(Seat *seat, int echoing, int editing); +bool nullseat_is_never_utf8(Seat *seat); +bool nullseat_is_always_utf8(Seat *seat); +void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing); const char *nullseat_get_x_display(Seat *seat); -int nullseat_get_windowid(Seat *seat, long *id_out); -int nullseat_get_window_pixel_size(Seat *seat, int *width, int *height); +bool nullseat_get_windowid(Seat *seat, long *id_out); +bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height); /* * Seat functions provided by the platform's console-application @@ -1029,7 +1029,7 @@ struct TermWinVtable { * of TermWin handles it by loading the currently configured font * into the HDC and doing a GDI query.) */ - int (*setup_draw_ctx)(TermWin *); + bool (*setup_draw_ctx)(TermWin *); /* Draw text in the window, during a painting operation */ void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len, unsigned long attrs, int line_attrs, truecolour tc); @@ -1045,14 +1045,14 @@ struct TermWinVtable { void (*set_cursor_pos)(TermWin *, int x, int y); - void (*set_raw_mouse_mode)(TermWin *, int enable); + void (*set_raw_mouse_mode)(TermWin *, bool enable); void (*set_scrollbar)(TermWin *, int total, int start, int page); void (*bell)(TermWin *, int mode); void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs, - truecolour *colours, int len, int must_deselect); + truecolour *colours, int len, bool must_deselect); void (*clip_request_paste)(TermWin *, int clipboard); void (*refresh)(TermWin *); @@ -1066,20 +1066,20 @@ struct TermWinVtable { * {min,normal,max} switch. The idea is that when you un-minimise * the window it remembers whether to go back to normal or * maximised. */ - void (*set_minimised)(TermWin *, int minimised); - int (*is_minimised)(TermWin *); - void (*set_maximised)(TermWin *, int maximised); + void (*set_minimised)(TermWin *, bool minimised); + bool (*is_minimised)(TermWin *); + void (*set_maximised)(TermWin *, bool maximised); void (*move)(TermWin *, int x, int y); - void (*set_zorder)(TermWin *, int top); + void (*set_zorder)(TermWin *, bool top); - int (*palette_get)(TermWin *, int n, int *r, int *g, int *b); + bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b); void (*palette_set)(TermWin *, int n, int r, int g, int b); void (*palette_reset)(TermWin *); void (*get_pos)(TermWin *, int *x, int *y); void (*get_pixels)(TermWin *, int *x, int *y); - const char *(*get_title)(TermWin *, int icon); - int (*is_utf8)(TermWin *); + const char *(*get_title)(TermWin *, bool icon); + bool (*is_utf8)(TermWin *); }; #define win_setup_draw_ctx(win) \ @@ -1397,6 +1397,7 @@ void cleanup_exit(int); X(INT, NONE, shadowboldoffset) /* in pixels */ \ X(BOOL, NONE, crhaslf) \ X(STR, NONE, winclass) \ + /* end of list */ /* Now define the actual enum of option keywords using that macro. */ #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword, @@ -1439,7 +1440,7 @@ void conf_set_filename(Conf *conf, int key, const Filename *val); void conf_set_fontspec(Conf *conf, int key, const FontSpec *val); /* Serialisation functions for Duplicate Session */ void conf_serialise(BinarySink *bs, Conf *conf); -int conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/ +bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/ /* * Functions to copy, free, serialise and deserialise FontSpecs. @@ -1475,7 +1476,7 @@ char *save_settings(const char *section, Conf *conf); void save_open_settings(settings_w *sesskey, Conf *conf); void load_settings(const char *section, Conf *conf); void load_open_settings(settings_r *sesskey, Conf *conf); -void get_sesslist(struct sesslist *, int allocate); +void get_sesslist(struct sesslist *, bool allocate); void do_defaults(const char *, Conf *); void registry_cleanup(void); @@ -1507,35 +1508,35 @@ FontSpec *platform_default_fontspec(const char *name); Terminal *term_init(Conf *, struct unicode_data *, TermWin *); void term_free(Terminal *); void term_size(Terminal *, int, int, int); -void term_paint(Terminal *, int, int, int, int, int); +void term_paint(Terminal *, int, int, int, int, bool); void term_scroll(Terminal *, int, int); void term_scroll_to_selection(Terminal *, int); -void term_pwron(Terminal *, int); +void term_pwron(Terminal *, bool); void term_clrsb(Terminal *); void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action, - int,int,int,int,int); + int, int, bool, bool, bool); void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int, unsigned int); void term_lost_clipboard_ownership(Terminal *, int clipboard); void term_update(Terminal *); void term_invalidate(Terminal *); -void term_blink(Terminal *, int set_cursor); +void term_blink(Terminal *, bool set_cursor); void term_do_paste(Terminal *, const wchar_t *, int); void term_nopaste(Terminal *); -int term_ldisc(Terminal *, int option); +bool term_ldisc(Terminal *, int option); void term_copyall(Terminal *, const int *, int); void term_reconfig(Terminal *, Conf *); void term_request_copy(Terminal *, const int *clipboards, int n_clipboards); void term_request_paste(Terminal *, int clipboard); void term_seen_key_event(Terminal *); -int term_data(Terminal *, int is_stderr, const void *data, int len); +int term_data(Terminal *, bool is_stderr, const void *data, int len); void term_provide_backend(Terminal *term, Backend *backend); void term_provide_logctx(Terminal *term, LogContext *logctx); -void term_set_focus(Terminal *term, int has_focus); +void term_set_focus(Terminal *term, bool has_focus); char *term_get_ttymode(Terminal *term, const char *mode); int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input); -int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl); +int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl); /* * Exports from logging.c. @@ -1653,15 +1654,15 @@ extern const struct BackendVtable ssh_backend; Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *); void ldisc_configure(Ldisc *, Conf *); void ldisc_free(Ldisc *); -void ldisc_send(Ldisc *, const void *buf, int len, int interactive); +void ldisc_send(Ldisc *, const void *buf, int len, bool interactive); void ldisc_echoedit_update(Ldisc *); /* * Exports from ldiscucs.c. */ void lpage_send(Ldisc *, int codepage, const char *buf, int len, - int interactive); -void luni_send(Ldisc *, const wchar_t * widebuf, int len, int interactive); + bool interactive); +void luni_send(Ldisc *, const wchar_t * widebuf, int len, bool interactive); /* * Exports from sshrand.c. @@ -1690,7 +1691,7 @@ void pinger_free(Pinger *); */ #include "misc.h" -int conf_launchable(Conf *conf); +bool conf_launchable(Conf *conf); char const *conf_dest(Conf *conf); /* @@ -1701,7 +1702,7 @@ void prepare_session(Conf *conf); /* * Exports from sercfg.c. */ -void ser_setup_config_box(struct controlbox *b, int midsession, +void ser_setup_config_box(struct controlbox *b, bool midsession, int parity_mask, int flow_mask); /* @@ -1716,7 +1717,7 @@ extern const char ver[]; #define CP_UTF8 65001 #endif /* void init_ucs(void); -- this is now in platform-specific headers */ -int is_dbcs_leadbyte(int codepage, char byte); +bool is_dbcs_leadbyte(int codepage, char byte); int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen, wchar_t *wcstr, int wclen); int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen, @@ -1766,7 +1767,7 @@ agent_pending_query *agent_query( void (*callback)(void *, void *, int), void *callback_ctx); void agent_cancel_query(agent_pending_query *); void agent_query_synchronous(strbuf *in, void **out, int *outlen); -int agent_exists(void); +bool agent_exists(void); /* * Exports from wildcard.c @@ -1774,7 +1775,7 @@ int agent_exists(void); const char *wc_error(int value); int wc_match_pl(const char *wildcard, ptrlen target); int wc_match(const char *wildcard, const char *target); -int wc_unescape(char *output, const char *wildcard); +bool wc_unescape(char *output, const char *wildcard); /* * Exports from frontend (windlg.c etc) @@ -1784,15 +1785,15 @@ void pgp_fingerprints(void); * have_ssh_host_key() just returns true if a key of that type is * already cached and false otherwise. */ -int have_ssh_host_key(const char *host, int port, const char *keytype); +bool have_ssh_host_key(const char *host, int port, const char *keytype); /* * Exports from console frontends (wincons.c, uxcons.c) * that aren't equivalents to things in windlg.c et al. */ -extern int console_batch_mode; +extern bool console_batch_mode; int console_get_userpass_input(prompts_t *p); -int is_interactive(void); +bool is_interactive(void); void console_print_error_msg(const char *prefix, const char *msg); void console_print_error_msg_fmt_v( const char *prefix, const char *fmt, va_list ap); @@ -1824,7 +1825,7 @@ int cmdline_process_param(const char *, char *, int, Conf *); void cmdline_run_saved(Conf *); void cmdline_cleanup(void); int cmdline_get_passwd_input(prompts_t *p); -int cmdline_host_ok(Conf *); +bool cmdline_host_ok(Conf *); #define TOOLTYPE_FILETRANSFER 1 #define TOOLTYPE_NONNETWORK 2 #define TOOLTYPE_HOST_ARG 4 @@ -1852,7 +1853,7 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg, void *data, int event); void conf_fontsel_handler(union control *ctrl, dlgparam *dlg, void *data, int event); -void setup_config_box(struct controlbox *b, int midsession, +void setup_config_box(struct controlbox *b, bool midsession, int protocol, int protcfginfo); /* @@ -1864,7 +1865,7 @@ typedef struct bidi_char { } bidi_char; int do_bidi(bidi_char *line, int count); int do_shape(bidi_char *line, bidi_char *to, int count); -int is_rtl(int c); +bool is_rtl(int c); /* * X11 auth mechanisms we know about. @@ -1895,8 +1896,8 @@ enum { */ Filename *filename_from_str(const char *string); const char *filename_to_str(const Filename *fn); -int filename_equal(const Filename *f1, const Filename *f2); -int filename_is_null(const Filename *fn); +bool filename_equal(const Filename *f1, const Filename *f2); +bool filename_is_null(const Filename *fn); Filename *filename_copy(const Filename *fn); void filename_free(Filename *fn); void filename_serialise(BinarySink *bs, const Filename *f); @@ -1904,7 +1905,7 @@ Filename *filename_deserialise(BinarySource *src); char *get_username(void); /* return value needs freeing */ char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */ char filename_char_sanitise(char c); /* rewrite special pathname chars */ -int open_for_write_would_lose_data(const Filename *fn); +bool open_for_write_would_lose_data(const Filename *fn); /* * Exports and imports from timing.c. @@ -1999,7 +2000,7 @@ int open_for_write_would_lose_data(const Filename *fn); typedef void (*timer_fn_t)(void *ctx, unsigned long now); unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx); void expire_timer_context(void *ctx); -int run_timers(unsigned long now, unsigned long *next); +bool run_timers(unsigned long now, unsigned long *next); void timer_change_notify(unsigned long next); unsigned long timing_last_clock(void); @@ -2031,8 +2032,8 @@ unsigned long timing_last_clock(void); */ typedef void (*toplevel_callback_fn_t)(void *ctx); void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx); -int run_toplevel_callbacks(void); -int toplevel_callback_pending(void); +bool run_toplevel_callbacks(void); +bool toplevel_callback_pending(void); void delete_callbacks_for_context(void *ctx); /* @@ -2047,7 +2048,7 @@ void delete_callbacks_for_context(void *ctx); struct IdempotentCallback { toplevel_callback_fn_t fn; void *ctx; - int queued; + bool queued; }; void queue_idempotent_callback(struct IdempotentCallback *ic); diff --git a/raw.c b/raw.c index 827193ea..90dde5d8 100644 --- a/raw.c +++ b/raw.c @@ -13,11 +13,11 @@ typedef struct Raw Raw; struct Raw { Socket *s; - int closed_on_socket_error; + bool closed_on_socket_error; int bufsize; Seat *seat; LogContext *logctx; - int sent_console_eof, sent_socket_eof, session_started; + bool sent_console_eof, sent_socket_eof, session_started; Conf *conf; @@ -57,7 +57,7 @@ static void raw_check_close(Raw *raw) } static void raw_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { Raw *raw = container_of(plug, Raw, plug); @@ -122,7 +122,7 @@ static const PlugVtable Raw_plugvt = { static const char *raw_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, char **realhost, - int nodelay, int keepalive) + bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -161,8 +161,8 @@ static const char *raw_init(Seat *seat, Backend **backend_handle, /* * Open socket. */ - raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, - &raw->plug, conf); + raw->s = new_connection(addr, *realhost, port, false, true, nodelay, + keepalive, &raw->plug, conf); if ((err = sk_socket_error(raw->s)) != NULL) return err; @@ -255,15 +255,15 @@ static const SessionSpecial *raw_get_specials(Backend *be) return NULL; } -static int raw_connected(Backend *be) +static bool raw_connected(Backend *be) { Raw *raw = container_of(be, Raw, backend); return raw->s != NULL; } -static int raw_sendok(Backend *be) +static bool raw_sendok(Backend *be) { - return 1; + return true; } static void raw_unthrottle(Backend *be, int backlog) @@ -272,11 +272,11 @@ static void raw_unthrottle(Backend *be, int backlog) sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); } -static int raw_ldisc(Backend *be, int option) +static bool raw_ldisc(Backend *be, int option) { if (option == LD_EDIT || option == LD_ECHO) - return 1; - return 0; + return true; + return false; } static void raw_provide_ldisc(Backend *be, Ldisc *ldisc) diff --git a/rlogin.c b/rlogin.c index 1b70443e..46bfb7eb 100644 --- a/rlogin.c +++ b/rlogin.c @@ -14,10 +14,10 @@ typedef struct Rlogin Rlogin; struct Rlogin { Socket *s; - int closed_on_socket_error; + bool closed_on_socket_error; int bufsize; - int firstbyte; - int cansize; + bool firstbyte; + bool cansize; int term_width, term_height; Seat *seat; LogContext *logctx; @@ -47,7 +47,7 @@ static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, } static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { Rlogin *rlogin = container_of(plug, Rlogin, plug); @@ -80,7 +80,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len) c = *data++; len--; if (c == '\x80') { - rlogin->cansize = 1; + rlogin->cansize = true; backend_size(&rlogin->backend, rlogin->term_width, rlogin->term_height); } @@ -101,7 +101,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len) data++; len--; } - rlogin->firstbyte = 0; + rlogin->firstbyte = false; } if (len > 0) c_write(rlogin, data, len); @@ -153,7 +153,7 @@ static const PlugVtable Rlogin_plugvt = { static const char *rlogin_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, char **realhost, - int nodelay, int keepalive) + bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -171,8 +171,8 @@ static const char *rlogin_init(Seat *seat, Backend **backend_handle, rlogin->logctx = logctx; rlogin->term_width = conf_get_int(conf, CONF_width); rlogin->term_height = conf_get_int(conf, CONF_height); - rlogin->firstbyte = 1; - rlogin->cansize = 0; + rlogin->firstbyte = true; + rlogin->cansize = false; rlogin->prompt = NULL; rlogin->conf = conf_copy(conf); *backend_handle = &rlogin->backend; @@ -194,7 +194,7 @@ static const char *rlogin_init(Seat *seat, Backend **backend_handle, /* * Open socket. */ - rlogin->s = new_connection(addr, *realhost, port, 1, 0, + rlogin->s = new_connection(addr, *realhost, port, true, false, nodelay, keepalive, &rlogin->plug, conf); if ((err = sk_socket_error(rlogin->s)) != NULL) return err; @@ -346,16 +346,16 @@ static const SessionSpecial *rlogin_get_specials(Backend *be) return NULL; } -static int rlogin_connected(Backend *be) +static bool rlogin_connected(Backend *be) { Rlogin *rlogin = container_of(be, Rlogin, backend); return rlogin->s != NULL; } -static int rlogin_sendok(Backend *be) +static bool rlogin_sendok(Backend *be) { /* Rlogin *rlogin = container_of(be, Rlogin, backend); */ - return 1; + return true; } static void rlogin_unthrottle(Backend *be, int backlog) @@ -364,10 +364,10 @@ static void rlogin_unthrottle(Backend *be, int backlog) sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); } -static int rlogin_ldisc(Backend *be, int option) +static bool rlogin_ldisc(Backend *be, int option) { /* Rlogin *rlogin = container_of(be, Rlogin, backend); */ - return 0; + return false; } static void rlogin_provide_ldisc(Backend *be, Ldisc *ldisc) diff --git a/scpserver.c b/scpserver.c index 1c9912a3..42439159 100644 --- a/scpserver.c +++ b/scpserver.c @@ -256,7 +256,7 @@ typedef struct ScpReplyReceiver ScpReplyReceiver; struct ScpReplyReceiver { - int err; + bool err; unsigned code; char *errmsg; struct fxp_attrs attrs; @@ -371,12 +371,13 @@ typedef struct ScpSourceStackEntry ScpSourceStackEntry; struct ScpSource { SftpServer *sf; - int acks, expect_newline, eof, throttled, finished; + int acks; + bool expect_newline, eof, throttled, finished; SshChannel *sc; ScpSourceStackEntry *head; - int recursive; - int send_file_times; + bool recursive; + bool send_file_times; strbuf *pending_commands[3]; int n_pending_commands; @@ -482,7 +483,7 @@ static void scp_source_push_name( static void scp_source_free(ScpServer *s); static int scp_source_send(ScpServer *s, const void *data, size_t length); static void scp_source_eof(ScpServer *s); -static void scp_source_throttle(ScpServer *s, int throttled); +static void scp_source_throttle(ScpServer *s, bool throttled); static struct ScpServerVtable ScpSource_ScpServer_vt = { scp_source_free, @@ -899,7 +900,7 @@ static int scp_source_send(ScpServer *s, const void *vdata, size_t length) return 0; } -static void scp_source_throttle(ScpServer *s, int throttled) +static void scp_source_throttle(ScpServer *s, bool throttled) { ScpSource *scp = container_of(s, ScpSource, scpserver); @@ -937,10 +938,10 @@ struct ScpSink { uint64_t file_offset, file_size; unsigned long atime, mtime; - int got_file_times; + bool got_file_times; bufchain data; - int input_eof; + bool input_eof; strbuf *command; char command_chr; @@ -968,10 +969,10 @@ struct ScpSinkStackEntry { * should be created _as_ - regardless of the filename in the 'C' * command. */ - int isdir; + bool isdir; }; -static void scp_sink_push(ScpSink *scp, ptrlen pathname, int isdir) +static void scp_sink_push(ScpSink *scp, ptrlen pathname, bool isdir) { ScpSinkStackEntry *node = snew_plus(ScpSinkStackEntry, pathname.len); char *p = snew_plus_get_aux(node); @@ -995,7 +996,7 @@ static void scp_sink_pop(ScpSink *scp) static void scp_sink_free(ScpServer *s); static int scp_sink_send(ScpServer *s, const void *data, size_t length); static void scp_sink_eof(ScpServer *s); -static void scp_sink_throttle(ScpServer *s, int throttled) {} +static void scp_sink_throttle(ScpServer *s, bool throttled) {} static struct ScpServerVtable ScpSink_ScpServer_vt = { scp_sink_free, @@ -1012,7 +1013,7 @@ static void scp_sink_start_callback(void *vscp) static ScpSink *scp_sink_new( SshChannel *sc, const SftpServerVtable *sftpserver_vt, ptrlen pathname, - int pathname_is_definitely_dir) + bool pathname_is_definitely_dir) { ScpSink *scp = snew(ScpSink); memset(scp, 0, sizeof(*scp)); @@ -1295,7 +1296,7 @@ static void scp_error_free(ScpServer *s); static int scp_error_send(ScpServer *s, const void *data, size_t length) { return 0; } static void scp_error_eof(ScpServer *s) {} -static void scp_error_throttle(ScpServer *s, int throttled) {} +static void scp_error_throttle(ScpServer *s, bool throttled) {} static struct ScpServerVtable ScpError_ScpServer_vt = { scp_error_free, @@ -1353,8 +1354,8 @@ static void scp_error_free(ScpServer *s) ScpServer *scp_recognise_exec( SshChannel *sc, const SftpServerVtable *sftpserver_vt, ptrlen command) { - int recursive = false, preserve = false; - int targetshouldbedirectory = false; + bool recursive = false, preserve = false; + bool targetshouldbedirectory = false; ptrlen command_orig = command; if (!ptrlen_startswith(command, PTRLEN_LITERAL("scp "), &command)) diff --git a/sercfg.c b/sercfg.c index 71462100..2c1682f5 100644 --- a/sercfg.c +++ b/sercfg.c @@ -124,7 +124,7 @@ static void serial_flow_handler(union control *ctrl, dlgparam *dlg, } } -void ser_setup_config_box(struct controlbox *b, int midsession, +void ser_setup_config_box(struct controlbox *b, bool midsession, int parity_mask, int flow_mask) { struct controlset *s; diff --git a/sesschan.c b/sesschan.c index 4a390167..1ca085d1 100644 --- a/sesschan.c +++ b/sesschan.c @@ -23,13 +23,13 @@ typedef struct sesschan { LogPolicy logpolicy; Seat seat; - int want_pty; + bool want_pty; struct ssh_ttymodes ttymodes; int wc, hc, wp, hp; strbuf *termtype; - int ignoring_input; - int seen_eof, seen_exit; + bool ignoring_input; + bool seen_eof, seen_exit; Plug xfwd_plug; int n_x11_sockets; @@ -48,25 +48,25 @@ typedef struct sesschan { } sesschan; static void sesschan_free(Channel *chan); -static int sesschan_send(Channel *chan, int is_stderr, const void *, int); +static int sesschan_send(Channel *chan, bool is_stderr, const void *, int); static void sesschan_send_eof(Channel *chan); static char *sesschan_log_close_msg(Channel *chan); -static int sesschan_want_close(Channel *, int, int); -static void sesschan_set_input_wanted(Channel *chan, int wanted); -static int sesschan_run_shell(Channel *chan); -static int sesschan_run_command(Channel *chan, ptrlen command); -static int sesschan_run_subsystem(Channel *chan, ptrlen subsys); -static int sesschan_enable_x11_forwarding( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata, +static bool sesschan_want_close(Channel *, bool, bool); +static void sesschan_set_input_wanted(Channel *chan, bool wanted); +static bool sesschan_run_shell(Channel *chan); +static bool sesschan_run_command(Channel *chan, ptrlen command); +static bool sesschan_run_subsystem(Channel *chan, ptrlen subsys); +static bool sesschan_enable_x11_forwarding( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata, unsigned screen_number); -static int sesschan_enable_agent_forwarding(Channel *chan); -static int sesschan_allocate_pty( +static bool sesschan_enable_agent_forwarding(Channel *chan); +static bool sesschan_allocate_pty( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes); -static int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value); -static int sesschan_send_break(Channel *chan, unsigned length); -static int sesschan_send_signal(Channel *chan, ptrlen signame); -static int sesschan_change_window_size( +static bool sesschan_set_env(Channel *chan, ptrlen var, ptrlen value); +static bool sesschan_send_break(Channel *chan, unsigned length); +static bool sesschan_send_signal(Channel *chan, ptrlen signame); +static bool sesschan_change_window_size( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight); @@ -95,7 +95,7 @@ static const struct ChannelVtable sesschan_channelvt = { chan_no_request_response, }; -static int sftp_chan_send(Channel *chan, int is_stderr, const void *, int); +static int sftp_chan_send(Channel *chan, bool is_stderr, const void *, int); static void sftp_chan_send_eof(Channel *chan); static char *sftp_log_close_msg(Channel *chan); @@ -124,9 +124,9 @@ static const struct ChannelVtable sftp_channelvt = { chan_no_request_response, }; -static int scp_chan_send(Channel *chan, int is_stderr, const void *, int); +static int scp_chan_send(Channel *chan, bool is_stderr, const void *, int); static void scp_chan_send_eof(Channel *chan); -static void scp_set_input_wanted(Channel *chan, int wanted); +static void scp_set_input_wanted(Channel *chan, bool wanted); static char *scp_log_close_msg(Channel *chan); static const struct ChannelVtable scp_channelvt = { @@ -166,11 +166,11 @@ static const LogPolicyVtable sesschan_logpolicy_vt = { sesschan_logging_error, }; -static int sesschan_seat_output(Seat *, int is_stderr, const void *, int); -static int sesschan_seat_eof(Seat *); +static int sesschan_seat_output(Seat *, bool is_stderr, const void *, int); +static bool sesschan_seat_eof(Seat *); static void sesschan_notify_remote_exit(Seat *seat); static void sesschan_connection_fatal(Seat *seat, const char *message); -static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height); +static bool sesschan_get_window_pixel_size(Seat *seat, int *w, int *h); static const SeatVtable sesschan_seat_vt = { sesschan_seat_output, @@ -241,7 +241,7 @@ static void sesschan_free(Channel *chan) sfree(sess); } -static int sesschan_send(Channel *chan, int is_stderr, +static int sesschan_send(Channel *chan, bool is_stderr, const void *data, int length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -264,7 +264,7 @@ static char *sesschan_log_close_msg(Channel *chan) return dupstr("Session channel closed"); } -static void sesschan_set_input_wanted(Channel *chan, int wanted) +static void sesschan_set_input_wanted(Channel *chan, bool wanted) { /* I don't think we need to do anything here */ } @@ -277,7 +277,7 @@ static void sesschan_start_backend(sesschan *sess, const char *cmd) backend_size(sess->backend, sess->wc, sess->hc); } -int sesschan_run_shell(Channel *chan) +bool sesschan_run_shell(Channel *chan) { sesschan *sess = container_of(chan, sesschan, chan); @@ -288,7 +288,7 @@ int sesschan_run_shell(Channel *chan) return true; } -int sesschan_run_command(Channel *chan, ptrlen command) +bool sesschan_run_command(Channel *chan, ptrlen command) { sesschan *sess = container_of(chan, sesschan, chan); @@ -310,7 +310,7 @@ int sesschan_run_command(Channel *chan, ptrlen command) return true; } -int sesschan_run_subsystem(Channel *chan, ptrlen subsys) +bool sesschan_run_subsystem(Channel *chan, ptrlen subsys) { sesschan *sess = container_of(chan, sesschan, chan); @@ -328,7 +328,7 @@ static void fwd_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { /* don't expect any weirdnesses from a listening socket */ } static void fwd_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { /* not here, either */ } static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) @@ -344,13 +344,13 @@ static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) s = constructor(ctx, plug); if ((err = sk_socket_error(s)) != NULL) { portfwd_raw_free(chan); - return true; + return 1; } pi = sk_peer_info(s); portfwd_raw_setup(chan, s, ssh_serverside_x11_open(sess->c->cl, chan, pi)); sk_free_peer_info(pi); - return false; + return 0; } static const PlugVtable xfwd_plugvt = { @@ -361,8 +361,8 @@ static const PlugVtable xfwd_plugvt = { xfwd_accepting, }; -int sesschan_enable_x11_forwarding( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata_hex, +bool sesschan_enable_x11_forwarding( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata_hex, unsigned screen_number) { sesschan *sess = container_of(chan, sesschan, chan); @@ -420,11 +420,11 @@ static int agentfwd_accepting( s = constructor(ctx, plug); if ((err = sk_socket_error(s)) != NULL) { portfwd_raw_free(chan); - return true; + return 1; } portfwd_raw_setup(chan, s, ssh_serverside_agent_open(sess->c->cl, chan)); - return false; + return 0; } static const PlugVtable agentfwd_plugvt = { @@ -435,7 +435,7 @@ static const PlugVtable agentfwd_plugvt = { agentfwd_accepting, }; -int sesschan_enable_agent_forwarding(Channel *chan) +bool sesschan_enable_agent_forwarding(Channel *chan) { sesschan *sess = container_of(chan, sesschan, chan); char *error, *socketname, *dir_prefix; @@ -459,7 +459,7 @@ int sesschan_enable_agent_forwarding(Channel *chan) return sess->agentfwd_socket != NULL; } -int sesschan_allocate_pty( +bool sesschan_allocate_pty( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes) { @@ -483,7 +483,7 @@ int sesschan_allocate_pty( return true; } -int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value) +bool sesschan_set_env(Channel *chan, ptrlen var, ptrlen value) { sesschan *sess = container_of(chan, sesschan, chan); @@ -495,7 +495,7 @@ int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value) return true; } -int sesschan_send_break(Channel *chan, unsigned length) +bool sesschan_send_break(Channel *chan, unsigned length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -511,7 +511,7 @@ int sesschan_send_break(Channel *chan, unsigned length) return false; } -int sesschan_send_signal(Channel *chan, ptrlen signame) +bool sesschan_send_signal(Channel *chan, ptrlen signame) { sesschan *sess = container_of(chan, sesschan, chan); @@ -533,7 +533,7 @@ int sesschan_send_signal(Channel *chan, ptrlen signame) return true; } -int sesschan_change_window_size( +bool sesschan_change_window_size( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight) { @@ -554,7 +554,7 @@ int sesschan_change_window_size( } static int sesschan_seat_output( - Seat *seat, int is_stderr, const void *data, int len) + Seat *seat, bool is_stderr, const void *data, int len) { sesschan *sess = container_of(seat, sesschan, seat); return sshfwd_write_ext(sess->c, is_stderr, data, len); @@ -573,7 +573,7 @@ static void sesschan_check_close_callback(void *vctx) sshfwd_initiate_close(sess->c, NULL); } -static int sesschan_want_close(Channel *chan, int seen_eof, int rcvd_eof) +static bool sesschan_want_close(Channel *chan, bool seen_eof, bool rcvd_eof) { sesschan *sess = container_of(chan, sesschan, chan); @@ -585,7 +585,7 @@ static int sesschan_want_close(Channel *chan, int seen_eof, int rcvd_eof) return (sess->seen_eof && sess->seen_exit); } -static int sesschan_seat_eof(Seat *seat) +static bool sesschan_seat_eof(Seat *seat) { sesschan *sess = container_of(seat, sesschan, seat); @@ -633,7 +633,7 @@ static void sesschan_connection_fatal(Seat *seat, const char *message) sess->ignoring_input = true; } -static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height) +static bool sesschan_get_window_pixel_size(Seat *seat, int *width, int *height) { sesschan *sess = container_of(seat, sesschan, seat); @@ -647,7 +647,7 @@ static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height) * Built-in SFTP subsystem. */ -static int sftp_chan_send(Channel *chan, int is_stderr, +static int sftp_chan_send(Channel *chan, bool is_stderr, const void *data, int length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -695,7 +695,7 @@ static char *sftp_log_close_msg(Channel *chan) * Built-in SCP subsystem. */ -static int scp_chan_send(Channel *chan, int is_stderr, +static int scp_chan_send(Channel *chan, bool is_stderr, const void *data, int length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -713,7 +713,7 @@ static char *scp_log_close_msg(Channel *chan) return dupstr("Session channel (SCP) closed"); } -static void scp_set_input_wanted(Channel *chan, int wanted) +static void scp_set_input_wanted(Channel *chan, bool wanted) { sesschan *sess = container_of(chan, sesschan, chan); scp_throttle(sess->scpsrv, !wanted); diff --git a/settings.c b/settings.c index e1b16918..1e945173 100644 --- a/settings.c +++ b/settings.c @@ -153,8 +153,8 @@ static bool gppb_raw(settings_r *sesskey, const char *name, bool def) return sesskey ? read_setting_i(sesskey, name, def) != 0 : def; } -static void gppb(settings_r *sesskey, const char *name, int def, - Conf *conf, conf_BOOL_NONE primary) +static void gppb(settings_r *sesskey, const char *name, bool def, + Conf *conf, int primary) { conf_set_bool(conf, primary, gppb_raw(sesskey, name, def)); } @@ -178,8 +178,8 @@ static void gppi(settings_r *sesskey, const char *name, int def, * If there's no "=VALUE" (e.g. just NAME,NAME,NAME) then those keys * are mapped to the empty string. */ -static int gppmap(settings_r *sesskey, const char *name, - Conf *conf, int primary) +static bool gppmap(settings_r *sesskey, const char *name, + Conf *conf, int primary) { char *buf, *p, *q, *key, *val; @@ -247,7 +247,7 @@ static int gppmap(settings_r *sesskey, const char *name, * names if include_values is false. */ static void wmap(settings_w *sesskey, char const *outkey, Conf *conf, - int primary, int include_values) + int primary, bool include_values) { char *buf, *p, *key, *realkey; const char *val, *q; @@ -805,10 +805,10 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppfile(sesskey, "LogFileName", conf, CONF_logfilename); gppi(sesskey, "LogType", 0, conf, CONF_logtype); gppi(sesskey, "LogFileClash", LGXF_ASK, conf, CONF_logxfovr); - gppb(sesskey, "LogFlush", 1, conf, CONF_logflush); - gppb(sesskey, "LogHeader", 1, conf, CONF_logheader); - gppb(sesskey, "SSHLogOmitPasswords", 1, conf, CONF_logomitpass); - gppb(sesskey, "SSHLogOmitData", 0, conf, CONF_logomitdata); + gppb(sesskey, "LogFlush", true, conf, CONF_logflush); + gppb(sesskey, "LogHeader", true, conf, CONF_logheader); + gppb(sesskey, "SSHLogOmitPasswords", true, conf, CONF_logomitpass); + gppb(sesskey, "SSHLogOmitData", false, conf, CONF_logomitdata); prot = gpps_raw(sesskey, "Protocol", "default"); conf_set_int(conf, CONF_protocol, default_protocol); @@ -828,7 +828,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) /* The CloseOnExit numbers are arranged in a different order from * the standard FORCE_ON / FORCE_OFF / AUTO. */ i = gppi_raw(sesskey, "CloseOnExit", 1); conf_set_int(conf, CONF_close_on_exit, (i+1)%3); - gppb(sesskey, "WarnOnClose", 1, conf, CONF_warn_on_close); + gppb(sesskey, "WarnOnClose", true, conf, CONF_warn_on_close); { /* This is two values for backward compatibility with 0.50/0.51 */ int pingmin, pingsec; @@ -836,8 +836,8 @@ void load_open_settings(settings_r *sesskey, Conf *conf) pingsec = gppi_raw(sesskey, "PingIntervalSecs", 0); conf_set_int(conf, CONF_ping_interval, pingmin * 60 + pingsec); } - gppb(sesskey, "TCPNoDelay", 1, conf, CONF_tcp_nodelay); - gppb(sesskey, "TCPKeepalives", 0, conf, CONF_tcp_keepalives); + gppb(sesskey, "TCPNoDelay", true, conf, CONF_tcp_nodelay); + gppb(sesskey, "TCPKeepalives", false, conf, CONF_tcp_keepalives); gpps(sesskey, "TerminalType", "xterm", conf, CONF_termtype); gpps(sesskey, "TerminalSpeed", "38400,38400", conf, CONF_termspeed); if (gppmap(sesskey, "TerminalModes", conf, CONF_ttymodes)) { @@ -894,7 +894,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) /* proxy settings */ gpps(sesskey, "ProxyExcludeList", "", conf, CONF_proxy_exclude_list); i = gppi_raw(sesskey, "ProxyDNS", 1); conf_set_int(conf, CONF_proxy_dns, (i+1)%3); - gppb(sesskey, "ProxyLocalhost", 0, conf, CONF_even_proxy_localhost); + gppb(sesskey, "ProxyLocalhost", false, conf, CONF_even_proxy_localhost); gppi(sesskey, "ProxyMethod", -1, conf, CONF_proxy_type); if (conf_get_int(conf, CONF_proxy_type) == -1) { int i; @@ -924,14 +924,15 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppi(sesskey, "ProxyLogToTerm", FORCE_OFF, conf, CONF_proxy_log_to_term); gppmap(sesskey, "Environment", conf, CONF_environmt); gpps(sesskey, "UserName", "", conf, CONF_username); - gppb(sesskey, "UserNameFromEnvironment", 0, conf, CONF_username_from_env); + gppb(sesskey, "UserNameFromEnvironment", false, + conf, CONF_username_from_env); gpps(sesskey, "LocalUserName", "", conf, CONF_localusername); - gppb(sesskey, "NoPTY", 0, conf, CONF_nopty); - gppb(sesskey, "Compression", 0, conf, CONF_compression); - gppb(sesskey, "TryAgent", 1, conf, CONF_tryagent); - gppb(sesskey, "AgentFwd", 0, conf, CONF_agentfwd); - gppb(sesskey, "ChangeUsername", 0, conf, CONF_change_username); - gppb(sesskey, "GssapiFwd", 0, conf, CONF_gssapifwd); + gppb(sesskey, "NoPTY", false, conf, CONF_nopty); + gppb(sesskey, "Compression", false, conf, CONF_compression); + gppb(sesskey, "TryAgent", true, conf, CONF_tryagent); + gppb(sesskey, "AgentFwd", false, conf, CONF_agentfwd); + gppb(sesskey, "ChangeUsername", false, conf, CONF_change_username); + gppb(sesskey, "GssapiFwd", false, conf, CONF_gssapifwd); gprefs(sesskey, "Cipher", "\0", ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist); { @@ -996,33 +997,34 @@ void load_open_settings(settings_r *sesskey, Conf *conf) conf_set_int(conf, CONF_sshprot, sshprot); } gpps(sesskey, "LogHost", "", conf, CONF_loghost); - gppb(sesskey, "SSH2DES", 0, conf, CONF_ssh2_des_cbc); - gppb(sesskey, "SshNoAuth", 0, conf, CONF_ssh_no_userauth); - gppb(sesskey, "SshBanner", 1, conf, CONF_ssh_show_banner); - gppb(sesskey, "AuthTIS", 0, conf, CONF_try_tis_auth); - gppb(sesskey, "AuthKI", 1, conf, CONF_try_ki_auth); - gppb(sesskey, "AuthGSSAPI", 1, conf, CONF_try_gssapi_auth); - gppb(sesskey, "AuthGSSAPIKEX", 1, conf, CONF_try_gssapi_kex); + gppb(sesskey, "SSH2DES", false, conf, CONF_ssh2_des_cbc); + gppb(sesskey, "SshNoAuth", false, conf, CONF_ssh_no_userauth); + gppb(sesskey, "SshBanner", true, conf, CONF_ssh_show_banner); + gppb(sesskey, "AuthTIS", false, conf, CONF_try_tis_auth); + gppb(sesskey, "AuthKI", true, conf, CONF_try_ki_auth); + gppb(sesskey, "AuthGSSAPI", true, conf, CONF_try_gssapi_auth); + gppb(sesskey, "AuthGSSAPIKEX", true, conf, CONF_try_gssapi_kex); #ifndef NO_GSSAPI gprefs(sesskey, "GSSLibs", "\0", gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist); gppfile(sesskey, "GSSCustom", conf, CONF_ssh_gss_custom); #endif - gppb(sesskey, "SshNoShell", 0, conf, CONF_ssh_no_shell); + gppb(sesskey, "SshNoShell", false, conf, CONF_ssh_no_shell); gppfile(sesskey, "PublicKeyFile", conf, CONF_keyfile); gpps(sesskey, "RemoteCommand", "", conf, CONF_remote_cmd); - gppb(sesskey, "RFCEnviron", 0, conf, CONF_rfc_environ); - gppb(sesskey, "PassiveTelnet", 0, conf, CONF_passive_telnet); - gppb(sesskey, "BackspaceIsDelete", 1, conf, CONF_bksp_is_delete); - gppb(sesskey, "RXVTHomeEnd", 0, conf, CONF_rxvt_homeend); + gppb(sesskey, "RFCEnviron", false, conf, CONF_rfc_environ); + gppb(sesskey, "PassiveTelnet", false, conf, CONF_passive_telnet); + gppb(sesskey, "BackspaceIsDelete", true, conf, CONF_bksp_is_delete); + gppb(sesskey, "RXVTHomeEnd", false, conf, CONF_rxvt_homeend); gppi(sesskey, "LinuxFunctionKeys", 0, conf, CONF_funky_type); - gppb(sesskey, "NoApplicationKeys", 0, conf, CONF_no_applic_k); - gppb(sesskey, "NoApplicationCursors", 0, conf, CONF_no_applic_c); - gppb(sesskey, "NoMouseReporting", 0, conf, CONF_no_mouse_rep); - gppb(sesskey, "NoRemoteResize", 0, conf, CONF_no_remote_resize); - gppb(sesskey, "NoAltScreen", 0, conf, CONF_no_alt_screen); - gppb(sesskey, "NoRemoteWinTitle", 0, conf, CONF_no_remote_wintitle); - gppb(sesskey, "NoRemoteClearScroll", 0, conf, CONF_no_remote_clearscroll); + gppb(sesskey, "NoApplicationKeys", false, conf, CONF_no_applic_k); + gppb(sesskey, "NoApplicationCursors", false, conf, CONF_no_applic_c); + gppb(sesskey, "NoMouseReporting", false, conf, CONF_no_mouse_rep); + gppb(sesskey, "NoRemoteResize", false, conf, CONF_no_remote_resize); + gppb(sesskey, "NoAltScreen", false, conf, CONF_no_alt_screen); + gppb(sesskey, "NoRemoteWinTitle", false, conf, CONF_no_remote_wintitle); + gppb(sesskey, "NoRemoteClearScroll", false, + conf, CONF_no_remote_clearscroll); { /* Backward compatibility */ int no_remote_qtitle = gppi_raw(sesskey, "NoRemoteQTitle", 1); @@ -1033,37 +1035,38 @@ void load_open_settings(settings_r *sesskey, Conf *conf) no_remote_qtitle ? TITLE_EMPTY : TITLE_REAL, conf, CONF_remote_qtitle_action); } - gppb(sesskey, "NoDBackspace", 0, conf, CONF_no_dbackspace); - gppb(sesskey, "NoRemoteCharset", 0, conf, CONF_no_remote_charset); - gppb(sesskey, "ApplicationCursorKeys", 0, conf, CONF_app_cursor); - gppb(sesskey, "ApplicationKeypad", 0, conf, CONF_app_keypad); - gppb(sesskey, "NetHackKeypad", 0, conf, CONF_nethack_keypad); - gppb(sesskey, "AltF4", 1, conf, CONF_alt_f4); - gppb(sesskey, "AltSpace", 0, conf, CONF_alt_space); - gppb(sesskey, "AltOnly", 0, conf, CONF_alt_only); - gppb(sesskey, "ComposeKey", 0, conf, CONF_compose_key); - gppb(sesskey, "CtrlAltKeys", 1, conf, CONF_ctrlaltkeys); + gppb(sesskey, "NoDBackspace", false, conf, CONF_no_dbackspace); + gppb(sesskey, "NoRemoteCharset", false, conf, CONF_no_remote_charset); + gppb(sesskey, "ApplicationCursorKeys", false, conf, CONF_app_cursor); + gppb(sesskey, "ApplicationKeypad", false, conf, CONF_app_keypad); + gppb(sesskey, "NetHackKeypad", false, conf, CONF_nethack_keypad); + gppb(sesskey, "AltF4", true, conf, CONF_alt_f4); + gppb(sesskey, "AltSpace", false, conf, CONF_alt_space); + gppb(sesskey, "AltOnly", false, conf, CONF_alt_only); + gppb(sesskey, "ComposeKey", false, conf, CONF_compose_key); + gppb(sesskey, "CtrlAltKeys", true, conf, CONF_ctrlaltkeys); #ifdef OSX_META_KEY_CONFIG - gppb(sesskey, "OSXOptionMeta", 1, conf, CONF_osx_option_meta); - gppb(sesskey, "OSXCommandMeta", 0, conf, CONF_osx_command_meta); + gppb(sesskey, "OSXOptionMeta", true, conf, CONF_osx_option_meta); + gppb(sesskey, "OSXCommandMeta", false, conf, CONF_osx_command_meta); #endif - gppb(sesskey, "TelnetKey", 0, conf, CONF_telnet_keyboard); - gppb(sesskey, "TelnetRet", 1, conf, CONF_telnet_newline); + gppb(sesskey, "TelnetKey", false, conf, CONF_telnet_keyboard); + gppb(sesskey, "TelnetRet", true, conf, CONF_telnet_newline); gppi(sesskey, "LocalEcho", AUTO, conf, CONF_localecho); gppi(sesskey, "LocalEdit", AUTO, conf, CONF_localedit); gpps(sesskey, "Answerback", "PuTTY", conf, CONF_answerback); - gppb(sesskey, "AlwaysOnTop", 0, conf, CONF_alwaysontop); - gppb(sesskey, "FullScreenOnAltEnter", 0, conf, CONF_fullscreenonaltenter); - gppb(sesskey, "HideMousePtr", 0, conf, CONF_hide_mouseptr); - gppb(sesskey, "SunkenEdge", 0, conf, CONF_sunken_edge); + gppb(sesskey, "AlwaysOnTop", false, conf, CONF_alwaysontop); + gppb(sesskey, "FullScreenOnAltEnter", false, + conf, CONF_fullscreenonaltenter); + gppb(sesskey, "HideMousePtr", false, conf, CONF_hide_mouseptr); + gppb(sesskey, "SunkenEdge", false, conf, CONF_sunken_edge); gppi(sesskey, "WindowBorder", 1, conf, CONF_window_border); gppi(sesskey, "CurType", 0, conf, CONF_cursor_type); - gppb(sesskey, "BlinkCur", 0, conf, CONF_blink_cur); + gppb(sesskey, "BlinkCur", false, conf, CONF_blink_cur); /* pedantic compiler tells me I can't use conf, CONF_beep as an int * :-) */ gppi(sesskey, "Beep", 1, conf, CONF_beep); gppi(sesskey, "BeepInd", 0, conf, CONF_beep_ind); gppfile(sesskey, "BellWaveFile", conf, CONF_bell_wavefile); - gppb(sesskey, "BellOverload", 1, conf, CONF_bellovl); + gppb(sesskey, "BellOverload", true, conf, CONF_bellovl); gppi(sesskey, "BellOverloadN", 5, conf, CONF_bellovl_n); i = gppi_raw(sesskey, "BellOverloadT", 2*TICKSPERSEC #ifdef PUTTY_UNIX_H @@ -1086,24 +1089,24 @@ void load_open_settings(settings_r *sesskey, Conf *conf) #endif ); gppi(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines); - gppb(sesskey, "DECOriginMode", 0, conf, CONF_dec_om); - gppb(sesskey, "AutoWrapMode", 1, conf, CONF_wrap_mode); - gppb(sesskey, "LFImpliesCR", 0, conf, CONF_lfhascr); - gppb(sesskey, "CRImpliesLF", 0, conf, CONF_crhaslf); - gppb(sesskey, "DisableArabicShaping", 0, conf, CONF_arabicshaping); - gppb(sesskey, "DisableBidi", 0, conf, CONF_bidi); - gppb(sesskey, "WinNameAlways", 1, conf, CONF_win_name_always); + gppb(sesskey, "DECOriginMode", false, conf, CONF_dec_om); + gppb(sesskey, "AutoWrapMode", true, conf, CONF_wrap_mode); + gppb(sesskey, "LFImpliesCR", false, conf, CONF_lfhascr); + gppb(sesskey, "CRImpliesLF", false, conf, CONF_crhaslf); + gppb(sesskey, "DisableArabicShaping", false, conf, CONF_arabicshaping); + gppb(sesskey, "DisableBidi", false, conf, CONF_bidi); + gppb(sesskey, "WinNameAlways", true, conf, CONF_win_name_always); gpps(sesskey, "WinTitle", "", conf, CONF_wintitle); gppi(sesskey, "TermWidth", 80, conf, CONF_width); gppi(sesskey, "TermHeight", 24, conf, CONF_height); gppfont(sesskey, "Font", conf, CONF_font); gppi(sesskey, "FontQuality", FQ_DEFAULT, conf, CONF_font_quality); gppi(sesskey, "FontVTMode", VT_UNICODE, conf, CONF_vtmode); - gppb(sesskey, "UseSystemColours", 0, conf, CONF_system_colour); - gppb(sesskey, "TryPalette", 0, conf, CONF_try_palette); - gppb(sesskey, "ANSIColour", 1, conf, CONF_ansi_colour); - gppb(sesskey, "Xterm256Colour", 1, conf, CONF_xterm_256_colour); - gppb(sesskey, "TrueColour", 1, conf, CONF_true_colour); + gppb(sesskey, "UseSystemColours", false, conf, CONF_system_colour); + gppb(sesskey, "TryPalette", false, conf, CONF_try_palette); + gppb(sesskey, "ANSIColour", true, conf, CONF_ansi_colour); + gppb(sesskey, "Xterm256Colour", true, conf, CONF_xterm_256_colour); + gppb(sesskey, "TrueColour", true, conf, CONF_true_colour); i = gppi_raw(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1); for (i = 0; i < 22; i++) { @@ -1125,13 +1128,13 @@ void load_open_settings(settings_r *sesskey, Conf *conf) } sfree(buf2); } - gppb(sesskey, "RawCNP", 0, conf, CONF_rawcnp); - gppb(sesskey, "UTF8linedraw", 0, conf, CONF_utf8linedraw); - gppb(sesskey, "PasteRTF", 0, conf, CONF_rtf_paste); + gppb(sesskey, "RawCNP", false, conf, CONF_rawcnp); + gppb(sesskey, "UTF8linedraw", false, conf, CONF_utf8linedraw); + gppb(sesskey, "PasteRTF", false, conf, CONF_rtf_paste); gppi(sesskey, "MouseIsXterm", 0, conf, CONF_mouse_is_xterm); - gppb(sesskey, "RectSelect", 0, conf, CONF_rect_select); - gppb(sesskey, "PasteControls", 0, conf, CONF_paste_controls); - gppb(sesskey, "MouseOverride", 1, conf, CONF_mouse_override); + gppb(sesskey, "RectSelect", false, conf, CONF_rect_select); + gppb(sesskey, "PasteControls", false, conf, CONF_paste_controls); + gppb(sesskey, "MouseOverride", true, conf, CONF_mouse_override); for (i = 0; i < 256; i += 32) { static const char *const defaults[] = { "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", @@ -1171,25 +1174,26 @@ void load_open_settings(settings_r *sesskey, Conf *conf) * into a plausible default for the locale. */ gpps(sesskey, "LineCodePage", "", conf, CONF_line_codepage); - gppb(sesskey, "CJKAmbigWide", 0, conf, CONF_cjk_ambig_wide); - gppb(sesskey, "UTF8Override", 1, conf, CONF_utf8_override); + gppb(sesskey, "CJKAmbigWide", false, conf, CONF_cjk_ambig_wide); + gppb(sesskey, "UTF8Override", true, conf, CONF_utf8_override); gpps(sesskey, "Printer", "", conf, CONF_printer); - gppb(sesskey, "CapsLockCyr", 0, conf, CONF_xlat_capslockcyr); - gppb(sesskey, "ScrollBar", 1, conf, CONF_scrollbar); - gppb(sesskey, "ScrollBarFullScreen", 0, conf, CONF_scrollbar_in_fullscreen); - gppb(sesskey, "ScrollOnKey", 0, conf, CONF_scroll_on_key); - gppb(sesskey, "ScrollOnDisp", 1, conf, CONF_scroll_on_disp); - gppb(sesskey, "EraseToScrollback", 1, conf, CONF_erase_to_scrollback); + gppb(sesskey, "CapsLockCyr", false, conf, CONF_xlat_capslockcyr); + gppb(sesskey, "ScrollBar", true, conf, CONF_scrollbar); + gppb(sesskey, "ScrollBarFullScreen", false, + conf, CONF_scrollbar_in_fullscreen); + gppb(sesskey, "ScrollOnKey", false, conf, CONF_scroll_on_key); + gppb(sesskey, "ScrollOnDisp", true, conf, CONF_scroll_on_disp); + gppb(sesskey, "EraseToScrollback", true, conf, CONF_erase_to_scrollback); gppi(sesskey, "LockSize", 0, conf, CONF_resize_action); - gppb(sesskey, "BCE", 1, conf, CONF_bce); - gppb(sesskey, "BlinkText", 0, conf, CONF_blinktext); - gppb(sesskey, "X11Forward", 0, conf, CONF_x11_forward); + gppb(sesskey, "BCE", true, conf, CONF_bce); + gppb(sesskey, "BlinkText", false, conf, CONF_blinktext); + gppb(sesskey, "X11Forward", false, conf, CONF_x11_forward); gpps(sesskey, "X11Display", "", conf, CONF_x11_display); gppi(sesskey, "X11AuthType", X11_MIT, conf, CONF_x11_auth); gppfile(sesskey, "X11AuthFile", conf, CONF_xauthfile); - gppb(sesskey, "LocalPortAcceptAll", 0, conf, CONF_lport_acceptall); - gppb(sesskey, "RemotePortAcceptAll", 0, conf, CONF_rport_acceptall); + gppb(sesskey, "LocalPortAcceptAll", false, conf, CONF_lport_acceptall); + gppb(sesskey, "RemotePortAcceptAll", false, conf, CONF_rport_acceptall); gppmap(sesskey, "PortForwardings", conf, CONF_portfwd); i = gppi_raw(sesskey, "BugIgnore1", 0); conf_set_int(conf, CONF_sshbug_ignore1, 2-i); i = gppi_raw(sesskey, "BugPlainPW1", 0); conf_set_int(conf, CONF_sshbug_plainpw1, 2-i); @@ -1213,10 +1217,10 @@ void load_open_settings(settings_r *sesskey, Conf *conf) i = gppi_raw(sesskey, "BugWinadj", 0); conf_set_int(conf, CONF_sshbug_winadj, 2-i); i = gppi_raw(sesskey, "BugChanReq", 0); conf_set_int(conf, CONF_sshbug_chanreq, 2-i); conf_set_bool(conf, CONF_ssh_simple, false); - gppb(sesskey, "StampUtmp", 1, conf, CONF_stamp_utmp); - gppb(sesskey, "LoginShell", 1, conf, CONF_login_shell); - gppb(sesskey, "ScrollbarOnLeft", 0, conf, CONF_scrollbar_on_left); - gppb(sesskey, "ShadowBold", 0, conf, CONF_shadowbold); + gppb(sesskey, "StampUtmp", true, conf, CONF_stamp_utmp); + gppb(sesskey, "LoginShell", true, conf, CONF_login_shell); + gppb(sesskey, "ScrollbarOnLeft", false, conf, CONF_scrollbar_on_left); + gppb(sesskey, "ShadowBold", false, conf, CONF_shadowbold); gppfont(sesskey, "BoldFont", conf, CONF_boldfont); gppfont(sesskey, "WideFont", conf, CONF_widefont); gppfont(sesskey, "WideBoldFont", conf, CONF_wideboldfont); @@ -1228,9 +1232,12 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppi(sesskey, "SerialParity", SER_PAR_NONE, conf, CONF_serparity); gppi(sesskey, "SerialFlowControl", SER_FLOW_XONXOFF, conf, CONF_serflow); gpps(sesskey, "WindowClass", "", conf, CONF_winclass); - gppb(sesskey, "ConnectionSharing", 0, conf, CONF_ssh_connection_sharing); - gppb(sesskey, "ConnectionSharingUpstream", 1, conf, CONF_ssh_connection_sharing_upstream); - gppb(sesskey, "ConnectionSharingDownstream", 1, conf, CONF_ssh_connection_sharing_downstream); + gppb(sesskey, "ConnectionSharing", false, + conf, CONF_ssh_connection_sharing); + gppb(sesskey, "ConnectionSharingUpstream", true, + conf, CONF_ssh_connection_sharing_upstream); + gppb(sesskey, "ConnectionSharingDownstream", true, + conf, CONF_ssh_connection_sharing_downstream); gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys); } @@ -1259,7 +1266,7 @@ static int sessioncmp(const void *av, const void *bv) return strcmp(a, b); /* otherwise, compare normally */ } -void get_sesslist(struct sesslist *list, int allocate) +void get_sesslist(struct sesslist *list, bool allocate) { char otherbuf[2048]; int buflen, bufsize, i; diff --git a/sftp.c b/sftp.c index c6ef9fde..de02a1ad 100644 --- a/sftp.c +++ b/sftp.c @@ -21,9 +21,9 @@ static void fxp_internal_error(const char *msg); * Client-specific parts of the send- and receive-packet system. */ -int sftp_send(struct sftp_packet *pkt) +bool sftp_send(struct sftp_packet *pkt) { - int ret; + bool ret; sftp_send_prepare(pkt); ret = sftp_senddata(pkt->data, pkt->length); sftp_pkt_free(pkt); @@ -61,7 +61,7 @@ struct sftp_packet *sftp_recv(void) struct sftp_request { unsigned id; - int registered; + bool registered; void *userdata; }; @@ -132,7 +132,7 @@ static struct sftp_request *sftp_alloc_request(void) */ r = snew(struct sftp_request); r->id = low + 1 + REQUEST_ID_OFFSET; - r->registered = 0; + r->registered = false; r->userdata = NULL; add234(sftp_requests, r); return r; @@ -148,7 +148,7 @@ void sftp_cleanup_request(void) void sftp_register(struct sftp_request *req) { - req->registered = 1; + req->registered = true; } struct sftp_request *sftp_find_request(struct sftp_packet *pktin) @@ -248,7 +248,7 @@ int fxp_error_type(void) /* * Perform exchange of init/version packets. Return 0 on failure. */ -int fxp_init(void) +bool fxp_init(void) { struct sftp_packet *pktout, *pktin; unsigned long remotever; @@ -260,24 +260,24 @@ int fxp_init(void) pktin = sftp_recv(); if (!pktin) { fxp_internal_error("could not connect"); - return 0; + return false; } if (pktin->type != SSH_FXP_VERSION) { fxp_internal_error("did not receive FXP_VERSION"); sftp_pkt_free(pktin); - return 0; + return false; } remotever = get_uint32(pktin); if (get_err(pktin)) { fxp_internal_error("malformed FXP_VERSION packet"); sftp_pkt_free(pktin); - return 0; + return false; } if (remotever > SFTP_PROTO_VERSION) { fxp_internal_error ("remote protocol is more advanced than we support"); sftp_pkt_free(pktin); - return 0; + return false; } /* * In principle, this packet might also contain extension- @@ -287,7 +287,7 @@ int fxp_init(void) */ sftp_pkt_free(pktin); - return 1; + return true; } /* @@ -436,7 +436,7 @@ struct sftp_request *fxp_close_send(struct fxp_handle *handle) return req; } -int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req) { sfree(req); fxp_got_status(pktin); @@ -459,16 +459,13 @@ struct sftp_request *fxp_mkdir_send(const char *path, return req; } -int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } struct sftp_request *fxp_rmdir_send(const char *path) @@ -484,16 +481,13 @@ struct sftp_request *fxp_rmdir_send(const char *path) return req; } -int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } struct sftp_request *fxp_remove_send(const char *fname) @@ -509,16 +503,13 @@ struct sftp_request *fxp_remove_send(const char *fname) return req; } -int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } struct sftp_request *fxp_rename_send(const char *srcfname, @@ -536,16 +527,13 @@ struct sftp_request *fxp_rename_send(const char *srcfname, return req; } -int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } /* @@ -565,19 +553,19 @@ struct sftp_request *fxp_stat_send(const char *fname) return req; } -static int fxp_got_attrs(struct sftp_packet *pktin, struct fxp_attrs *attrs) +static bool fxp_got_attrs(struct sftp_packet *pktin, struct fxp_attrs *attrs) { get_fxp_attrs(pktin, attrs); if (get_err(pktin)) { fxp_internal_error("malformed SSH_FXP_ATTRS packet"); sftp_pkt_free(pktin); - return 0; + return false; } sftp_pkt_free(pktin); - return 1; + return true; } -int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, +bool fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, struct fxp_attrs *attrs) { sfree(req); @@ -586,7 +574,7 @@ int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, } else { fxp_got_status(pktin); sftp_pkt_free(pktin); - return 0; + return false; } } @@ -603,18 +591,18 @@ struct sftp_request *fxp_fstat_send(struct fxp_handle *handle) return req; } -int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, - struct fxp_attrs *attrs) +bool fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, + struct fxp_attrs *attrs) { sfree(req); if (pktin->type == SSH_FXP_ATTRS) { return fxp_got_attrs(pktin, attrs); sftp_pkt_free(pktin); - return 1; + return true; } else { fxp_got_status(pktin); sftp_pkt_free(pktin); - return 0; + return false; } } @@ -636,16 +624,13 @@ struct sftp_request *fxp_setstat_send(const char *fname, return req; } -int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle, @@ -663,16 +648,13 @@ struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle, return req; } -int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req) { int id; sfree(req); id = fxp_got_status(pktin); sftp_pkt_free(pktin); - if (id != 1) { - return 0; - } - return 1; + return id == 1; } /* @@ -826,7 +808,7 @@ struct sftp_request *fxp_write_send(struct fxp_handle *handle, return req; } -int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req) +bool fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req) { sfree(req); fxp_got_status(pktin); @@ -899,7 +881,8 @@ struct req { struct fxp_xfer { uint64_t offset, furthestdata, filesize; - int req_totalsize, req_maxsize, eof, err; + int req_totalsize, req_maxsize; + bool eof, err; struct fxp_handle *fh; struct req *head, *tail; }; @@ -913,14 +896,14 @@ static struct fxp_xfer *xfer_init(struct fxp_handle *fh, uint64_t offset) xfer->head = xfer->tail = NULL; xfer->req_totalsize = 0; xfer->req_maxsize = 1048576; - xfer->err = 0; + xfer->err = false; xfer->filesize = UINT64_MAX; xfer->furthestdata = 0; return xfer; } -int xfer_done(struct fxp_xfer *xfer) +bool xfer_done(struct fxp_xfer *xfer) { /* * We're finished if we've seen EOF _and_ there are no @@ -1059,10 +1042,10 @@ int xfer_download_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin) void xfer_set_error(struct fxp_xfer *xfer) { - xfer->err = 1; + xfer->err = true; } -int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len) +bool xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len) { void *retbuf = NULL; int retlen = 0; @@ -1098,9 +1081,9 @@ int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len) if (retbuf) { *buf = retbuf; *len = retlen; - return 1; + return true; } else - return 0; + return false; } struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset) @@ -1115,17 +1098,14 @@ struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset) * from us is whether the outstanding requests have been * handled once that's done. */ - xfer->eof = 1; + xfer->eof = true; return xfer; } -int xfer_upload_ready(struct fxp_xfer *xfer) +bool xfer_upload_ready(struct fxp_xfer *xfer) { - if (sftp_sendbuffer() == 0) - return 1; - else - return 0; + return sftp_sendbuffer() == 0; } void xfer_upload_data(struct fxp_xfer *xfer, char *buffer, int len) @@ -1168,7 +1148,7 @@ int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin) { struct sftp_request *rreq; struct req *rr, *prev, *next; - int ret; + bool ret; rreq = sftp_find_request(pktin); if (!rreq) @@ -1180,7 +1160,7 @@ int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin) } ret = fxp_write_recv(pktin, rreq); #ifdef DEBUG_UPLOAD - printf("write request %p has returned [%d]\n", rr, ret); + printf("write request %p has returned [%d]\n", rr, ret ? 1 : 0); #endif /* diff --git a/sftp.h b/sftp.h index 1fbb6fa9..95d70ff7 100644 --- a/sftp.h +++ b/sftp.h @@ -62,16 +62,17 @@ * able to get at these functions. * * sftp_recvdata must never return less than len. It either blocks - * until len is available, or it returns failure. + * until len is available and then returns true, or it returns false + * for failure. * - * Both functions return 1 on success, 0 on failure. + * sftp_senddata returns true on success, false on failure. * * sftp_sendbuffer returns the size of the backlog of data in the * transmit queue. */ -int sftp_senddata(char *data, int len); +bool sftp_senddata(char *data, int len); int sftp_sendbuffer(void); -int sftp_recvdata(char *data, int len); +bool sftp_recvdata(char *data, int len); /* * Free sftp_requests @@ -144,13 +145,13 @@ void sftp_send_prepare(struct sftp_packet *pkt); * that many bytes into pkt->data, and call sftp_recv_finish to set up * the type code and BinarySource. */ struct sftp_packet *sftp_recv_prepare(unsigned length); -int sftp_recv_finish(struct sftp_packet *pkt); +bool sftp_recv_finish(struct sftp_packet *pkt); /* Either kind of packet can be freed afterwards with sftp_pkt_free. */ void sftp_pkt_free(struct sftp_packet *pkt); void BinarySink_put_fxp_attrs(BinarySink *bs, struct fxp_attrs attrs); -int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs); +bool BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs); #define put_fxp_attrs(bs, attrs) \ BinarySink_put_fxp_attrs(BinarySink_UPCAST(bs), attrs) #define get_fxp_attrs(bs, attrs) \ @@ -164,9 +165,9 @@ const char *fxp_error(void); int fxp_error_type(void); /* - * Perform exchange of init/version packets. Return 0 on failure. + * Perform exchange of init/version packets. Return false on failure. */ -int fxp_init(void); +bool fxp_init(void); /* * Canonify a pathname. Concatenate the two given path elements @@ -192,56 +193,56 @@ struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* - * Close a file/dir. Returns 1 on success, 0 on error. + * Close a file/dir. Returns true on success, false on error. */ struct sftp_request *fxp_close_send(struct fxp_handle *handle); -int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Make a directory. */ struct sftp_request *fxp_mkdir_send(const char *path, const struct fxp_attrs *attrs); -int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Remove a directory. */ struct sftp_request *fxp_rmdir_send(const char *path); -int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Remove a file. */ struct sftp_request *fxp_remove_send(const char *fname); -int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Rename a file. */ struct sftp_request *fxp_rename_send(const char *srcfname, const char *dstfname); -int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Return file attributes. */ struct sftp_request *fxp_stat_send(const char *fname); -int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, - struct fxp_attrs *attrs); +bool fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req, + struct fxp_attrs *attrs); struct sftp_request *fxp_fstat_send(struct fxp_handle *handle); -int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, - struct fxp_attrs *attrs); +bool fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req, + struct fxp_attrs *attrs); /* * Set file attributes. */ struct sftp_request *fxp_setstat_send(const char *fname, struct fxp_attrs attrs); -int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req); struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle, struct fxp_attrs attrs); -int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Read from a file. @@ -249,14 +250,14 @@ int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req); struct sftp_request *fxp_read_send(struct fxp_handle *handle, uint64_t offset, int len); int fxp_read_recv(struct sftp_packet *pktin, struct sftp_request *req, - char *buffer, int len); + char *buffer, int len); /* - * Write to a file. Returns 0 on error, 1 on OK. + * Write to a file. */ struct sftp_request *fxp_write_send(struct fxp_handle *handle, void *buffer, uint64_t offset, int len); -int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req); +bool fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Read from a directory. @@ -301,14 +302,14 @@ struct fxp_xfer; struct fxp_xfer *xfer_download_init(struct fxp_handle *fh, uint64_t offset); void xfer_download_queue(struct fxp_xfer *xfer); int xfer_download_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin); -int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len); +bool xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len); struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset); -int xfer_upload_ready(struct fxp_xfer *xfer); +bool xfer_upload_ready(struct fxp_xfer *xfer); void xfer_upload_data(struct fxp_xfer *xfer, char *buffer, int len); int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin); -int xfer_done(struct fxp_xfer *xfer); +bool xfer_done(struct fxp_xfer *xfer); void xfer_set_error(struct fxp_xfer *xfer); void xfer_cleanup(struct fxp_xfer *xfer); @@ -362,7 +363,7 @@ struct SftpServerVtable { /* Should call fxp_reply_error or fxp_reply_attrs */ void (*stat)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen path, - int follow_symlinks); + bool follow_symlinks); /* Should call fxp_reply_error or fxp_reply_attrs */ void (*fstat)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen handle); @@ -386,7 +387,7 @@ struct SftpServerVtable { /* Should call fxp_reply_error, or fxp_reply_name_count once and * then fxp_reply_full_name that many times */ void (*readdir)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen handle, - int max_entries, int omit_longname); + int max_entries, bool omit_longname); }; #define sftpsrv_new(vt) \ @@ -494,7 +495,7 @@ struct ScpServerVtable { void (*free)(ScpServer *s); int (*send)(ScpServer *s, const void *data, size_t length); - void (*throttle)(ScpServer *s, int throttled); + void (*throttle)(ScpServer *s, bool throttled); void (*eof)(ScpServer *s); }; diff --git a/sftpcommon.c b/sftpcommon.c index 5becf3ce..57e737fc 100644 --- a/sftpcommon.c +++ b/sftpcommon.c @@ -73,7 +73,7 @@ const struct fxp_attrs no_attrs = { 0 }; #define put_fxp_attrs(bs, attrs) \ BinarySink_put_fxp_attrs(BinarySink_UPCAST(bs), attrs) -int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs) +bool BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs) { attrs->flags = get_uint32(src); if (attrs->flags & SSH_FILEXFER_ATTR_SIZE) @@ -99,7 +99,7 @@ int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs) get_string(src); } } - return 1; + return true; } void sftp_pkt_free(struct sftp_packet *pkt) @@ -131,7 +131,7 @@ struct sftp_packet *sftp_recv_prepare(unsigned length) return pkt; } -int sftp_recv_finish(struct sftp_packet *pkt) +bool sftp_recv_finish(struct sftp_packet *pkt) { BinarySource_INIT(pkt, pkt->data, pkt->length); pkt->type = get_byte(pkt); diff --git a/ssh.c b/ssh.c index 2a5dd85f..1df7028c 100644 --- a/ssh.c +++ b/ssh.c @@ -46,9 +46,9 @@ struct Ssh { /* The last list returned from get_specials. */ SessionSpecial *specials; - int bare_connection; + bool bare_connection; ssh_sharing_state *connshare; - int attempting_connshare; + bool attempting_connshare; struct ssh_connection_shared_gss_state gss_state; @@ -56,20 +56,20 @@ struct Ssh { int savedport; char *fullhostname; - int fallback_cmd; + bool fallback_cmd; int exitcode; int version; int conn_throttle_count; int overall_bufsize; - int throttled_all; - int frozen; + bool throttled_all; + bool frozen; /* in case we find these out before we have a ConnectionLayer to tell */ int term_width, term_height; bufchain in_raw, out_raw, user_input; - int pending_close; + bool pending_close; IdempotentCallback ic_out_raw; PacketLogSettings pls; @@ -105,11 +105,11 @@ struct Ssh { * It's also used to mark the point where we stop counting proxy * command diagnostics as pre-session-startup. */ - int session_started; + bool session_started; Pinger *pinger; - int need_random_unref; + bool need_random_unref; }; @@ -117,7 +117,7 @@ struct Ssh { logevent_and_free((ssh)->logctx, dupprintf params)) static void ssh_shutdown(Ssh *ssh); -static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize); +static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize); static void ssh_bpp_output_raw_data_callback(void *vctx); LogContext *ssh_get_logctx(Ssh *ssh) @@ -316,7 +316,7 @@ static void ssh_bpp_output_raw_data_callback(void *vctx) bufchain_consume(&ssh->out_raw, len); if (backlog > SSH_MAX_BACKLOG) { - ssh_throttle_all(ssh, 1, backlog); + ssh_throttle_all(ssh, true, backlog); return; } } @@ -515,7 +515,7 @@ static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, } static void ssh_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { Ssh *ssh = container_of(plug, Ssh, plug); if (error_msg) { @@ -550,7 +550,7 @@ static void ssh_sent(Plug *plug, int bufsize) * some more data off its bufchain. */ if (bufsize < SSH_MAX_BACKLOG) { - ssh_throttle_all(ssh, 0, bufsize); + ssh_throttle_all(ssh, false, bufsize); queue_idempotent_callback(&ssh->ic_out_raw); } } @@ -592,11 +592,11 @@ static void ssh_hostport_setup(const char *host, int port, Conf *conf, } } -static int ssh_test_for_upstream(const char *host, int port, Conf *conf) +static bool ssh_test_for_upstream(const char *host, int port, Conf *conf) { char *savedhost; int savedport; - int ret; + bool ret; random_ref(); /* platform may need this to determine share socket name */ ssh_hostport_setup(host, port, conf, &savedhost, &savedport, NULL); @@ -621,8 +621,9 @@ static const PlugVtable Ssh_plugvt = { * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *connect_to_host(Ssh *ssh, const char *host, int port, - char **realhost, int nodelay, int keepalive) +static const char *connect_to_host( + Ssh *ssh, const char *host, int port, char **realhost, + bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -686,7 +687,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, ssh->fullhostname = dupstr(*realhost); /* save in case of GSSAPI */ ssh->s = new_connection(addr, *realhost, port, - 0, 1, nodelay, keepalive, + false, true, nodelay, keepalive, &ssh->plug, ssh->conf); if ((err = sk_socket_error(ssh->s)) != NULL) { ssh->s = NULL; @@ -739,7 +740,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, void ssh_throttle_conn(Ssh *ssh, int adjust) { int old_count = ssh->conn_throttle_count; - int frozen; + bool frozen; ssh->conn_throttle_count += adjust; assert(ssh->conn_throttle_count >= 0); @@ -769,7 +770,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust) * Throttle or unthrottle _all_ local data streams (for when sends * on the SSH connection itself back up). */ -static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize) +static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize) { if (enable == ssh->throttled_all) return; @@ -793,7 +794,7 @@ static void ssh_cache_conf_values(Ssh *ssh) static const char *ssh_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, char **realhost, - int nodelay, int keepalive) + bool nodelay, bool keepalive) { const char *p; Ssh *ssh; @@ -838,7 +839,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, static void ssh_free(Backend *be) { Ssh *ssh = container_of(be, Ssh, backend); - int need_random_unref; + bool need_random_unref; ssh_shutdown(ssh); @@ -1015,13 +1016,13 @@ static void ssh_unthrottle(Backend *be, int bufsize) ssh_stdout_unthrottle(ssh->cl, bufsize); } -static int ssh_connected(Backend *be) +static bool ssh_connected(Backend *be) { Ssh *ssh = container_of(be, Ssh, backend); return ssh->s != NULL; } -static int ssh_sendok(Backend *be) +static bool ssh_sendok(Backend *be) { Ssh *ssh = container_of(be, Ssh, backend); return ssh->base_layer && ssh_ppl_want_user_input(ssh->base_layer); @@ -1035,7 +1036,7 @@ void ssh_ldisc_update(Ssh *ssh) ldisc_echoedit_update(ssh->ldisc); } -static int ssh_ldisc(Backend *be, int option) +static bool ssh_ldisc(Backend *be, int option) { Ssh *ssh = container_of(be, Ssh, backend); return ssh->cl ? ssh_ldisc_option(ssh->cl, option) : false; @@ -1082,7 +1083,7 @@ static int ssh_cfg_info(Backend *be) * that fails. This variable is the means by which scp.c can reach * into the SSH code and find out which one it got. */ -extern int ssh_fallback_cmd(Backend *be) +extern bool ssh_fallback_cmd(Backend *be) { Ssh *ssh = container_of(be, Ssh, backend); return ssh->fallback_cmd; diff --git a/ssh.h b/ssh.h index 91f15a2f..c657bca4 100644 --- a/ssh.h +++ b/ssh.h @@ -52,7 +52,7 @@ struct ssh_channel; typedef struct PacketQueueNode PacketQueueNode; struct PacketQueueNode { PacketQueueNode *next, *prev; - int on_free_queue; /* is this packet scheduled for freeing? */ + bool on_free_queue; /* is this packet scheduled for freeing? */ }; typedef struct PktIn { @@ -89,12 +89,12 @@ typedef struct PacketQueueBase { typedef struct PktInQueue { PacketQueueBase pqb; - PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop); + PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop); } PktInQueue; typedef struct PktOutQueue { PacketQueueBase pqb; - PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop); + PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop); } PktOutQueue; void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node); @@ -146,17 +146,17 @@ typedef enum { } Pkt_ACtx; typedef struct PacketLogSettings { - int omit_passwords, omit_data; + bool omit_passwords, omit_data; Pkt_KCtx kctx; Pkt_ACtx actx; } PacketLogSettings; #define MAX_BLANKS 4 /* no packet needs more censored sections than this */ int ssh1_censor_packet( - const PacketLogSettings *pls, int type, int sender_is_client, + const PacketLogSettings *pls, int type, bool sender_is_client, ptrlen pkt, logblank_t *blanks); int ssh2_censor_packet( - const PacketLogSettings *pls, int type, int sender_is_client, + const PacketLogSettings *pls, int type, bool sender_is_client, ptrlen pkt, logblank_t *blanks); PktOut *ssh_new_packet(void); @@ -167,7 +167,7 @@ Socket *ssh_connection_sharing_init( Plug *sshplug, ssh_sharing_state **state); void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate, ConnectionLayer *cl); -int ssh_share_test_for_upstream(const char *host, int port, Conf *conf); +bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf); void share_got_pkt_from_server(ssh_sharing_connstate *ctx, int type, const void *pkt, int pktlen); void share_activate(ssh_sharing_state *sharestate, @@ -259,7 +259,7 @@ struct ConnectionLayerVtable { void (*sharing_no_more_downstreams)(ConnectionLayer *cl); /* Query whether the connection layer is doing agent forwarding */ - int (*agent_forwarding_permitted)(ConnectionLayer *cl); + bool (*agent_forwarding_permitted)(ConnectionLayer *cl); /* Set the size of the main terminal window (if any) */ void (*terminal_size)(ConnectionLayer *cl, int width, int height); @@ -274,15 +274,15 @@ struct ConnectionLayerVtable { * backed up, so it should tell all currently open channels to * cease reading from their local input sources if they can. (Or * tell it that that state of affairs has gone away again.) */ - void (*throttle_all_channels)(ConnectionLayer *cl, int throttled); + void (*throttle_all_channels)(ConnectionLayer *cl, bool throttled); /* Ask the connection layer about its current preference for * line-discipline options. */ - int (*ldisc_option)(ConnectionLayer *cl, int option); + bool (*ldisc_option)(ConnectionLayer *cl, int option); /* Communicate _to_ the connection layer (from the main session * channel) what its preference for line-discipline options is. */ - void (*set_ldisc_option)(ConnectionLayer *cl, int option, int value); + void (*set_ldisc_option)(ConnectionLayer *cl, int option, bool value); /* Communicate to the connection layer whether X and agent * forwarding were successfully enabled (for purposes of @@ -292,7 +292,7 @@ struct ConnectionLayerVtable { /* Communicate to the connection layer whether the main session * channel currently wants user input. */ - void (*set_wants_user_input)(ConnectionLayer *cl, int wanted); + void (*set_wants_user_input)(ConnectionLayer *cl, bool wanted); }; struct ConnectionLayer { @@ -354,9 +354,9 @@ void portfwdmgr_close_all(PortFwdManager *mgr); char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret, char *hostname, int port, SshChannel *c, int addressfamily); -int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port, - const char *keyhost, int keyport, Conf *conf); -int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port); +bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port, + const char *keyhost, int keyport, Conf *conf); +bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port); Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug); void portfwd_raw_free(Channel *pfchan); void portfwd_raw_setup(Channel *pfchan, Socket *s, SshChannel *sc); @@ -415,7 +415,7 @@ struct ec_point { const struct ec_curve *curve; Bignum x, y; Bignum z; /* Jacobian denominator */ - unsigned char infinity; + bool infinity; }; void ec_point_free(struct ec_point *point); @@ -464,12 +464,12 @@ const ssh_keyalg *ec_alg_by_oid(int len, const void *oid, const struct ec_curve **curve); const unsigned char *ec_alg_oid(const ssh_keyalg *alg, int *oidlen); extern const int ec_nist_curve_lengths[], n_ec_nist_curve_lengths; -int ec_nist_alg_and_curve_by_bits(int bits, - const struct ec_curve **curve, - const ssh_keyalg **alg); -int ec_ed_alg_and_curve_by_bits(int bits, - const struct ec_curve **curve, - const ssh_keyalg **alg); +bool ec_nist_alg_and_curve_by_bits(int bits, + const struct ec_curve **curve, + const ssh_keyalg **alg); +bool ec_ed_alg_and_curve_by_bits(int bits, + const struct ec_curve **curve, + const ssh_keyalg **alg); struct ec_key { struct ec_point publicKey; @@ -493,14 +493,14 @@ void BinarySource_get_rsa_ssh1_pub( BinarySource *src, struct RSAKey *result, RsaSsh1Order order); void BinarySource_get_rsa_ssh1_priv( BinarySource *src, struct RSAKey *rsa); -int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key); +bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key); Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key); -int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf); +bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf); void rsasanitise(struct RSAKey *key); int rsastr_len(struct RSAKey *key); void rsastr_fmt(char *str, struct RSAKey *key); char *rsa_ssh1_fingerprint(struct RSAKey *key); -int rsa_verify(struct RSAKey *key); +bool rsa_verify(struct RSAKey *key); void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key, RsaSsh1Order order); int rsa_ssh1_public_blob_len(void *data, int maxlen); @@ -513,8 +513,8 @@ unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len); struct crcda_ctx; struct crcda_ctx *crcda_make_context(void); void crcda_free_context(struct crcda_ctx *ctx); -int detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32_t len, - unsigned char *IV); +bool detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32_t len, + unsigned char *IV); /* * SSH2 RSA key exchange functions @@ -575,7 +575,7 @@ void hmacmd5_key(struct hmacmd5_context *ctx, void const *key, int len); void hmacmd5_do_hmac(struct hmacmd5_context *ctx, const void *blk, int len, unsigned char *hmac); -int supports_sha_ni(void); +bool supports_sha_ni(void); typedef struct SHA_State { uint32_t h[5]; @@ -718,9 +718,9 @@ struct ssh2_macalg { #define ssh2_mac_alg(ctx) ((ctx)->vt) /* Centralised 'methods' for ssh2_mac, defined in sshmac.c */ -int ssh2_mac_verresult(ssh2_mac *, const void *); +bool ssh2_mac_verresult(ssh2_mac *, const void *); void ssh2_mac_generate(ssh2_mac *, void *, int, unsigned long seq); -int ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq); +bool ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq); typedef struct ssh_hash { const struct ssh_hashalg *vt; @@ -763,7 +763,7 @@ struct ssh_keyalg { /* Methods that operate on an existing ssh_key */ void (*freekey) (ssh_key *key); void (*sign) (ssh_key *key, const void *data, int datalen, BinarySink *); - int (*verify) (ssh_key *key, ptrlen sig, ptrlen data); + bool (*verify) (ssh_key *key, ptrlen sig, ptrlen data); void (*public_blob)(ssh_key *key, BinarySink *); void (*private_blob)(ssh_key *key, BinarySink *); void (*openssh_blob) (ssh_key *key, BinarySink *); @@ -815,8 +815,8 @@ struct ssh_compression_alg { int minlen); ssh_decompressor *(*decompress_new)(void); void (*decompress_free)(ssh_decompressor *); - int (*decompress)(ssh_decompressor *, unsigned char *block, int len, - unsigned char **outblock, int *outlen); + bool (*decompress)(ssh_decompressor *, unsigned char *block, int len, + unsigned char **outblock, int *outlen); const char *text_name; }; @@ -893,7 +893,7 @@ extern const char sshver[]; * that fails. This variable is the means by which scp.c can reach * into the SSH code and find out which one it got. */ -extern int ssh_fallback_cmd(Backend *backend); +extern bool ssh_fallback_cmd(Backend *backend); void SHATransform(uint32_t *digest, uint32_t *data); @@ -930,7 +930,7 @@ enum { }; struct X11Display { /* Broken-down components of the display name itself */ - int unixdomain; + bool unixdomain; char *hostname; int displaynum; int screennum; @@ -996,12 +996,12 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype); void x11_free_fake_auth(struct X11FakeAuth *auth); Channel *x11_new_channel(tree234 *authtree, SshChannel *c, const char *peeraddr, int peerport, - int connection_sharing_possible); + bool connection_sharing_possible); char *x11_display(const char *display); /* Platform-dependent X11 functions */ extern void platform_get_x11_auth(struct X11Display *display, Conf *); /* examine a mostly-filled-in X11Display and fill in localauth* */ -extern const int platform_uses_x11_unix_by_default; +extern const bool platform_uses_x11_unix_by_default; /* choose default X transport in the absence of a specified one */ SockAddr *platform_get_x11_unix_address(const char *path, int displaynum); /* make up a SockAddr naming the address for displaynum */ @@ -1074,7 +1074,7 @@ Bignum BinarySource_get_mp_ssh2(BinarySource *); void diagbn(char *prefix, Bignum md); #endif -int dh_is_gex(const struct ssh_kex *kex); +bool dh_is_gex(const struct ssh_kex *kex); struct dh_ctx; struct dh_ctx *dh_setup_group(const struct ssh_kex *kex); struct dh_ctx *dh_setup_gex(Bignum pval, Bignum gval); @@ -1083,13 +1083,13 @@ Bignum dh_create_e(struct dh_ctx *, int nbits); const char *dh_validate_f(struct dh_ctx *, Bignum f); Bignum dh_find_K(struct dh_ctx *, Bignum f); -int rsa_ssh1_encrypted(const Filename *filename, char **comment); +bool rsa_ssh1_encrypted(const Filename *filename, char **comment); int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs, char **commentptr, const char **errorstr); int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key, const char *passphrase, const char **errorstr); -int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, - char *passphrase); +bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, + char *passphrase); extern int base64_decode_atom(const char *atom, unsigned char *out); extern int base64_lines(int datalen); @@ -1101,15 +1101,15 @@ extern void base64_encode(FILE *fp, const unsigned char *data, int datalen, extern struct ssh2_userkey ssh2_wrong_passphrase; #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase) -int ssh2_userkey_encrypted(const Filename *filename, char **comment); +bool ssh2_userkey_encrypted(const Filename *filename, char **comment); struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, const char *passphrase, const char **errorstr); -int ssh2_userkey_loadpub(const Filename *filename, char **algorithm, - BinarySink *bs, - char **commentptr, const char **errorstr); -int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, - char *passphrase); +bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm, + BinarySink *bs, + char **commentptr, const char **errorstr); +bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, + char *passphrase); const ssh_keyalg *find_pubkey_alg(const char *name); const ssh_keyalg *find_pubkey_alg_len(ptrlen name); @@ -1167,17 +1167,17 @@ char *ssh2_fingerprint(ssh_key *key); int key_type(const Filename *filename); const char *key_type_to_str(int type); -int import_possible(int type); +bool import_possible(int type); int import_target_type(int type); -int import_encrypted(const Filename *filename, int type, char **comment); +bool import_encrypted(const Filename *filename, int type, char **comment); int import_ssh1(const Filename *filename, int type, struct RSAKey *key, char *passphrase, const char **errmsg_p); struct ssh2_userkey *import_ssh2(const Filename *filename, int type, char *passphrase, const char **errmsg_p); -int export_ssh1(const Filename *filename, int type, - struct RSAKey *key, char *passphrase); -int export_ssh2(const Filename *filename, int type, - struct ssh2_userkey *key, char *passphrase); +bool export_ssh1(const Filename *filename, int type, + struct RSAKey *key, char *passphrase); +bool export_ssh2(const Filename *filename, int type, + struct ssh2_userkey *key, char *passphrase); void des3_decrypt_pubkey(const void *key, void *blk, int len); void des3_encrypt_pubkey(const void *key, void *blk, int len); @@ -1231,7 +1231,7 @@ enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM }; int platform_ssh_share(const char *name, Conf *conf, Plug *downplug, Plug *upplug, Socket **sock, char **logtext, char **ds_err, char **us_err, - int can_upstream, int can_downstream); + bool can_upstream, bool can_downstream); void platform_ssh_share_cleanup(const char *name); /* @@ -1449,7 +1449,7 @@ enum { struct ssh_ttymodes { /* A boolean per mode, indicating whether it's set. */ - int have_mode[TTYMODE_LIMIT]; + bool have_mode[TTYMODE_LIMIT]; /* The actual value for each mode. */ unsigned mode_val[TTYMODE_LIMIT]; @@ -1463,7 +1463,7 @@ void write_ttymodes_to_packet(BinarySink *bs, int ssh_version, const char *ssh1_pkt_type(int type); const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type); -int ssh2_pkt_type_code_valid(unsigned type); +bool ssh2_pkt_type_code_valid(unsigned type); /* * Need this to warn about support for the original SSH-2 keyfile @@ -1505,11 +1505,11 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset); TYPECHECK(&((type *)0)->localid == (unsigned *)0, \ alloc_channel_id_general(tree, offsetof(type, localid))) -int first_in_commasep_string(char const *needle, char const *haystack, - int haylen); -int in_commasep_string(char const *needle, char const *haystack, int haylen); +bool first_in_commasep_string(char const *needle, char const *haystack, + int haylen); +bool in_commasep_string(char const *needle, char const *haystack, int haylen); void add_to_commasep(strbuf *buf, const char *data); -int get_commasep_word(ptrlen *list, ptrlen *word); +bool get_commasep_word(ptrlen *list, ptrlen *word); int verify_ssh_manual_host_key( Conf *conf, const char *fingerprint, ssh_key *key); @@ -1519,8 +1519,8 @@ ssh_transient_hostkey_cache *ssh_transient_hostkey_cache_new(void); void ssh_transient_hostkey_cache_free(ssh_transient_hostkey_cache *thc); void ssh_transient_hostkey_cache_add( ssh_transient_hostkey_cache *thc, ssh_key *key); -int ssh_transient_hostkey_cache_verify( +bool ssh_transient_hostkey_cache_verify( ssh_transient_hostkey_cache *thc, ssh_key *key); -int ssh_transient_hostkey_cache_has( +bool ssh_transient_hostkey_cache_has( ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg); -int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc); +bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc); diff --git a/ssh1bpp.c b/ssh1bpp.c index f4abd98f..2938e405 100644 --- a/ssh1bpp.c +++ b/ssh1bpp.c @@ -21,7 +21,7 @@ struct ssh1_bpp_state { struct crcda_ctx *crcda_ctx; - int pending_compression_request; + bool pending_compression_request; ssh_compressor *compctx; ssh_decompressor *decompctx; diff --git a/ssh1censor.c b/ssh1censor.c index 755ce3d8..780dc046 100644 --- a/ssh1censor.c +++ b/ssh1censor.c @@ -10,7 +10,7 @@ #include "ssh.h" int ssh1_censor_packet( - const PacketLogSettings *pls, int type, int sender_is_client, + const PacketLogSettings *pls, int type, bool sender_is_client, ptrlen pkt, logblank_t *blanks) { int nblanks = 0; diff --git a/ssh1connection-client.c b/ssh1connection-client.c index 6c7c224f..a2c5e423 100644 --- a/ssh1connection-client.c +++ b/ssh1connection-client.c @@ -29,7 +29,7 @@ void ssh1_connection_direction_specific_setup( } typedef void (*sf_handler_fn_t)(struct ssh1_connection_state *s, - int success, void *ctx); + bool success, void *ctx); struct outstanding_succfail { sf_handler_fn_t handler; @@ -43,14 +43,14 @@ struct outstanding_succfail { * expect to get an acknowledgment regardless, so we arrange to * send that ack immediately after the rest of the queue empties. */ - int trivial; + bool trivial; }; static void ssh1_connection_process_trivial_succfails(void *vs); static void ssh1_queue_succfail_handler( struct ssh1_connection_state *s, sf_handler_fn_t handler, void *ctx, - int trivial) + bool trivial) { struct outstanding_succfail *osf = snew(struct outstanding_succfail); osf->handler = handler; @@ -71,7 +71,7 @@ static void ssh1_queue_succfail_handler( } static void ssh1_connection_process_succfail( - struct ssh1_connection_state *s, int success) + struct ssh1_connection_state *s, bool success) { struct outstanding_succfail *prevhead = s->succfail_head; s->succfail_head = s->succfail_head->next; @@ -88,7 +88,7 @@ static void ssh1_connection_process_trivial_succfails(void *vs) ssh1_connection_process_succfail(s, true); } -int ssh1_handle_direction_specific_packet( +bool ssh1_handle_direction_specific_packet( struct ssh1_connection_state *s, PktIn *pktin) { PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ @@ -233,7 +233,7 @@ int ssh1_handle_direction_specific_packet( s->ppl.seat, pktin->type == SSH1_SMSG_STDERR_DATA, data.ptr, data.len); if (!s->stdout_throttling && bufsize > SSH1_BUFFER_LIMIT) { - s->stdout_throttling = 1; + s->stdout_throttling = true; ssh_throttle_conn(s->ppl.ssh, +1); } } @@ -256,18 +256,18 @@ int ssh1_handle_direction_specific_packet( } static void ssh1mainchan_succfail_wantreply(struct ssh1_connection_state *s, - int success, void *ctx) + bool success, void *ctx) { chan_request_response(s->mainchan_chan, success); } static void ssh1mainchan_succfail_nowantreply(struct ssh1_connection_state *s, - int success, void *ctx) + bool success, void *ctx) { } static void ssh1mainchan_queue_response(struct ssh1_connection_state *s, - int want_reply, int trivial) + bool want_reply, bool trivial) { sf_handler_fn_t handler = (want_reply ? ssh1mainchan_succfail_wantreply : ssh1mainchan_succfail_nowantreply); @@ -275,8 +275,8 @@ static void ssh1mainchan_queue_response(struct ssh1_connection_state *s, } static void ssh1mainchan_request_x11_forwarding( - SshChannel *sc, int want_reply, const char *authproto, - const char *authdata, int screen_number, int oneshot) + SshChannel *sc, bool want_reply, const char *authproto, + const char *authdata, int screen_number, bool oneshot) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -293,7 +293,7 @@ static void ssh1mainchan_request_x11_forwarding( } static void ssh1mainchan_request_agent_forwarding( - SshChannel *sc, int want_reply) + SshChannel *sc, bool want_reply) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -307,7 +307,7 @@ static void ssh1mainchan_request_agent_forwarding( } static void ssh1mainchan_request_pty( - SshChannel *sc, int want_reply, Conf *conf, int w, int h) + SshChannel *sc, bool want_reply, Conf *conf, int w, int h) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -327,14 +327,13 @@ static void ssh1mainchan_request_pty( ssh1mainchan_queue_response(s, want_reply, false); } -static int ssh1mainchan_send_env_var( - SshChannel *sc, int want_reply, const char *var, const char *value) +static bool ssh1mainchan_send_env_var( + SshChannel *sc, bool want_reply, const char *var, const char *value) { return false; /* SSH-1 doesn't support this at all */ } -static void ssh1mainchan_start_shell( - SshChannel *sc, int want_reply) +static void ssh1mainchan_start_shell(SshChannel *sc, bool want_reply) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -347,7 +346,7 @@ static void ssh1mainchan_start_shell( } static void ssh1mainchan_start_command( - SshChannel *sc, int want_reply, const char *command) + SshChannel *sc, bool want_reply, const char *command) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -360,20 +359,20 @@ static void ssh1mainchan_start_command( ssh1mainchan_queue_response(s, want_reply, true); } -static int ssh1mainchan_start_subsystem( - SshChannel *sc, int want_reply, const char *subsystem) +static bool ssh1mainchan_start_subsystem( + SshChannel *sc, bool want_reply, const char *subsystem) { return false; /* SSH-1 doesn't support this at all */ } -static int ssh1mainchan_send_serial_break( - SshChannel *sc, int want_reply, int length) +static bool ssh1mainchan_send_serial_break( + SshChannel *sc, bool want_reply, int length) { return false; /* SSH-1 doesn't support this at all */ } -static int ssh1mainchan_send_signal( - SshChannel *sc, int want_reply, const char *signame) +static bool ssh1mainchan_send_signal( + SshChannel *sc, bool want_reply, const char *signame) { return false; /* SSH-1 doesn't support this at all */ } @@ -398,7 +397,7 @@ static void ssh1mainchan_hint_channel_is_simple(SshChannel *sc) } static int ssh1mainchan_write( - SshChannel *sc, int is_stderr, const void *data, int len) + SshChannel *sc, bool is_stderr, const void *data, int len) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); @@ -463,7 +462,7 @@ SshChannel *ssh1_session_open(ConnectionLayer *cl, Channel *chan) } static void ssh1_rportfwd_response(struct ssh1_connection_state *s, - int success, void *ctx) + bool success, void *ctx) { PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ struct ssh_rportfwd *rpf = (struct ssh_rportfwd *)ctx; diff --git a/ssh1connection-server.c b/ssh1connection-server.c index 1e8ddeea..bdbec47e 100644 --- a/ssh1connection-server.c +++ b/ssh1connection-server.c @@ -13,12 +13,13 @@ #include "ssh1connection.h" #include "sshserver.h" -static int ssh1sesschan_write(SshChannel *c, int is_stderr, const void *, int); +static int ssh1sesschan_write(SshChannel *c, bool is_stderr, + const void *, int); static void ssh1sesschan_write_eof(SshChannel *c); static void ssh1sesschan_initiate_close(SshChannel *c, const char *err); static void ssh1sesschan_send_exit_status(SshChannel *c, int status); static void ssh1sesschan_send_exit_signal( - SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg); + SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg); static const struct SshChannelVtable ssh1sesschan_vtable = { ssh1sesschan_write, @@ -54,7 +55,7 @@ void ssh1_connection_direction_specific_setup( } } -int ssh1_handle_direction_specific_packet( +bool ssh1_handle_direction_specific_packet( struct ssh1_connection_state *s, PktIn *pktin) { PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ @@ -63,7 +64,8 @@ int ssh1_handle_direction_specific_packet( unsigned remid; ptrlen host, cmd, data; char *host_str, *err; - int port, listenport, success; + int port, listenport; + bool success; switch (pktin->type) { case SSH1_CMSG_EXEC_SHELL: @@ -264,7 +266,7 @@ struct ssh_rportfwd *ssh1_rportfwd_alloc( return NULL; } -static int ssh1sesschan_write(SshChannel *sc, int is_stderr, +static int ssh1sesschan_write(SshChannel *sc, bool is_stderr, const void *data, int len) { struct ssh1_connection_state *s = @@ -303,7 +305,7 @@ static void ssh1sesschan_send_exit_status(SshChannel *sc, int status) } static void ssh1sesschan_send_exit_signal( - SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg) + SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg) { /* SSH-1 has no separate representation for signals */ ssh1sesschan_send_exit_status(sc, 128); diff --git a/ssh1connection.c b/ssh1connection.c index a7e09dfc..4d43299c 100644 --- a/ssh1connection.c +++ b/ssh1connection.c @@ -31,7 +31,7 @@ static void ssh1_connection_free(PacketProtocolLayer *); static void ssh1_connection_process_queue(PacketProtocolLayer *); static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); -static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl); +static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl); static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl); static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); @@ -53,16 +53,16 @@ static SshChannel *ssh1_lportfwd_open( const char *description, const SocketPeerInfo *pi, Channel *chan); static struct X11FakeAuth *ssh1_add_x11_display( ConnectionLayer *cl, int authtype, struct X11Display *disp); -static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl); +static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl); static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height); static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize); static int ssh1_stdin_backlog(ConnectionLayer *cl); -static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled); -static int ssh1_ldisc_option(ConnectionLayer *cl, int option); -static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value); +static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled); +static bool ssh1_ldisc_option(ConnectionLayer *cl, int option); +static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value); static void ssh1_enable_x_fwd(ConnectionLayer *cl); static void ssh1_enable_agent_fwd(ConnectionLayer *cl); -static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted); +static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted); static const struct ConnectionLayerVtable ssh1_connlayer_vtable = { ssh1_rportfwd_alloc, @@ -92,7 +92,7 @@ static const struct ConnectionLayerVtable ssh1_connlayer_vtable = { }; static int ssh1channel_write( - SshChannel *c, int is_stderr, const void *buf, int len); + SshChannel *c, bool is_stderr, const void *buf, int len); static void ssh1channel_write_eof(SshChannel *c); static void ssh1channel_initiate_close(SshChannel *c, const char *err); static void ssh1channel_unthrottle(SshChannel *c, int bufsize); @@ -224,13 +224,13 @@ void ssh1_connection_set_protoflags(PacketProtocolLayer *ppl, s->remote_protoflags = remote; } -static int ssh1_connection_filter_queue(struct ssh1_connection_state *s) +static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s) { PktIn *pktin; ptrlen data; struct ssh1_channel *c; unsigned localid; - int expect_halfopen; + bool expect_halfopen; while (1) { if (ssh1_common_filter_queue(&s->ppl)) @@ -511,7 +511,7 @@ static void ssh1_channel_destroy(struct ssh1_channel *c) queue_toplevel_callback(ssh1_check_termination_callback, s); } -int ssh1_check_termination(struct ssh1_connection_state *s) +bool ssh1_check_termination(struct ssh1_connection_state *s) { /* * Decide whether we should terminate the SSH connection now. @@ -584,13 +584,13 @@ static void ssh1channel_unthrottle(SshChannel *sc, int bufsize) struct ssh1_connection_state *s = c->connlayer; if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) { - c->throttling_conn = 0; + c->throttling_conn = false; ssh_throttle_conn(s->ppl.ssh, -1); } } static int ssh1channel_write( - SshChannel *sc, int is_stderr, const void *buf, int len) + SshChannel *sc, bool is_stderr, const void *buf, int len) { struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; @@ -659,7 +659,7 @@ static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) */ } -static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl) +static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -701,7 +701,7 @@ static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize) container_of(cl, struct ssh1_connection_state, cl); if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) { - s->stdout_throttling = 0; + s->stdout_throttling = false; ssh_throttle_conn(s->ppl.ssh, -1); } } @@ -711,7 +711,7 @@ static int ssh1_stdin_backlog(ConnectionLayer *cl) return 0; } -static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled) +static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -722,7 +722,7 @@ static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled) chan_set_input_wanted(c->chan, !throttled); } -static int ssh1_ldisc_option(ConnectionLayer *cl, int option) +static bool ssh1_ldisc_option(ConnectionLayer *cl, int option) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -730,7 +730,7 @@ static int ssh1_ldisc_option(ConnectionLayer *cl, int option) return s->ldisc_opts[option]; } -static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value) +static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -754,7 +754,7 @@ static void ssh1_enable_agent_fwd(ConnectionLayer *cl) s->agent_fwd_enabled = true; } -static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted) +static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -763,7 +763,7 @@ static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted) s->finished_setup = true; } -static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl) +static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl) { struct ssh1_connection_state *s = container_of(ppl, struct ssh1_connection_state, ppl); diff --git a/ssh1connection.h b/ssh1connection.h index 7d5194da..fe4c6157 100644 --- a/ssh1connection.h +++ b/ssh1connection.h @@ -21,25 +21,25 @@ struct ssh1_connection_state { Channel *mainchan_chan; /* the other end of mainchan_sc */ mainchan *mainchan; /* and its subtype */ - int got_pty; - int ldisc_opts[LD_N_OPTIONS]; - int stdout_throttling; - int want_user_input; - int session_terminated; + bool got_pty; + bool ldisc_opts[LD_N_OPTIONS]; + bool stdout_throttling; + bool want_user_input; + bool session_terminated; int term_width, term_height, term_width_orig, term_height_orig; - int X11_fwd_enabled; + bool X11_fwd_enabled; struct X11Display *x11disp; struct X11FakeAuth *x11auth; tree234 *x11authtree; - int agent_fwd_enabled; + bool agent_fwd_enabled; tree234 *rportfwds; PortFwdManager *portfwdmgr; - int portfwdmgr_configured; + bool portfwdmgr_configured; - int finished_setup; + bool finished_setup; /* * These store the list of requests that we're waiting for @@ -49,7 +49,7 @@ struct ssh1_connection_state { */ struct outstanding_succfail *succfail_head, *succfail_tail; - int compressing; /* used in server mode only */ + bool compressing; /* used in server mode only */ ConnectionLayer cl; PacketProtocolLayer ppl; @@ -61,7 +61,7 @@ struct ssh1_channel { unsigned remoteid, localid; int type; /* True if we opened this channel but server hasn't confirmed. */ - int halfopen; + bool halfopen; /* Bitmap of whether we've sent/received CHANNEL_CLOSE and * CHANNEL_CLOSE_CONFIRMATION. */ @@ -79,13 +79,13 @@ struct ssh1_channel { * we set this flag instead to remind us to do so once our buffer * is clear. */ - int pending_eof; + bool pending_eof; /* * True if this channel is causing the underlying connection to be * throttled. */ - int throttling_conn; + bool throttling_conn; /* * True if we currently have backed-up data on the direction of @@ -93,7 +93,7 @@ struct ssh1_channel { * would prefer the 'Channel' implementation not to read further * local input if possible. */ - int throttled_by_backlog; + bool throttled_by_backlog; Channel *chan; /* handle the client side of this channel, if not */ SshChannel sc; /* entry point for chan to talk back to */ @@ -113,7 +113,7 @@ SshChannel *ssh1_serverside_agent_open(ConnectionLayer *cl, Channel *chan); void ssh1_connection_direction_specific_setup( struct ssh1_connection_state *s); -int ssh1_handle_direction_specific_packet( +bool ssh1_handle_direction_specific_packet( struct ssh1_connection_state *s, PktIn *pktin); -int ssh1_check_termination(struct ssh1_connection_state *s); +bool ssh1_check_termination(struct ssh1_connection_state *s); diff --git a/ssh1login-server.c b/ssh1login-server.c index 4e0c7ca0..6689bf64 100644 --- a/ssh1login-server.c +++ b/ssh1login-server.c @@ -28,14 +28,14 @@ struct ssh1_login_server_state { ptrlen username; struct RSAKey *servkey, *hostkey; - int servkey_generated_here; + bool servkey_generated_here; Bignum sesskey; AuthPolicy *authpolicy; unsigned ap_methods, current_method; unsigned char auth_rsa_expected_response[16]; struct RSAKey *authkey; - int auth_successful; + bool auth_successful; PacketProtocolLayer ppl; }; @@ -43,12 +43,12 @@ struct ssh1_login_server_state { static void ssh1_login_server_free(PacketProtocolLayer *); static void ssh1_login_server_process_queue(PacketProtocolLayer *); -static int ssh1_login_server_get_specials( +static bool ssh1_login_server_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { return false; } static void ssh1_login_server_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg) {} -static int ssh1_login_server_want_user_input( +static bool ssh1_login_server_want_user_input( PacketProtocolLayer *ppl) { return false; } static void ssh1_login_server_got_user_input(PacketProtocolLayer *ppl) {} static void ssh1_login_server_reconfigure( @@ -101,7 +101,7 @@ static void ssh1_login_server_free(PacketProtocolLayer *ppl) sfree(s); } -static int ssh1_login_server_filter_queue(struct ssh1_login_server_state *s) +static bool ssh1_login_server_filter_queue(struct ssh1_login_server_state *s) { return ssh1_common_filter_queue(&s->ppl); } diff --git a/ssh1login.c b/ssh1login.c index 7efc068c..a85209a3 100644 --- a/ssh1login.c +++ b/ssh1login.c @@ -20,7 +20,7 @@ struct ssh1_login_state { char *savedhost; int savedport; - int try_agent_auth; + bool try_agent_auth; int remote_protoflags; int local_protoflags; @@ -31,14 +31,14 @@ struct ssh1_login_state { int len; unsigned char *rsabuf; unsigned long supported_ciphers_mask, supported_auths_mask; - int tried_publickey, tried_agent; - int tis_auth_refused, ccard_auth_refused; + bool tried_publickey, tried_agent; + bool tis_auth_refused, ccard_auth_refused; unsigned char cookie[8]; unsigned char session_id[16]; int cipher_type; strbuf *publickey_blob; char *publickey_comment; - int privatekey_available, privatekey_encrypted; + bool privatekey_available, privatekey_encrypted; prompts_t *cur_prompt; int userpass_ret; char c; @@ -47,14 +47,14 @@ struct ssh1_login_state { ptrlen agent_response; BinarySource asrc[1]; /* response from SSH agent */ int keyi, nkeys; - int authed; + bool authed; struct RSAKey key; Bignum challenge; ptrlen comment; int dlgret; Filename *keyfile; struct RSAKey servkey, hostkey; - int want_user_input; + bool want_user_input; PacketProtocolLayer ppl; }; @@ -64,7 +64,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *); static void ssh1_login_dialog_callback(void *, int); static void ssh1_login_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); -static int ssh1_login_want_user_input(PacketProtocolLayer *ppl); +static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl); static void ssh1_login_got_user_input(PacketProtocolLayer *ppl); static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf); @@ -120,7 +120,7 @@ static void ssh1_login_free(PacketProtocolLayer *ppl) sfree(s); } -static int ssh1_login_filter_queue(struct ssh1_login_state *s) +static bool ssh1_login_filter_queue(struct ssh1_login_state *s) { return ssh1_common_filter_queue(&s->ppl); } @@ -279,7 +279,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) ppl_logevent(("Encrypted session key")); { - int cipher_chosen = 0, warn = 0; + bool cipher_chosen = false, warn = false; const char *cipher_string = NULL; int i; for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) { @@ -287,7 +287,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) s->conf, CONF_ssh_cipherlist, i); if (next_cipher == CIPHER_WARN) { /* If/when we choose a cipher, warn about it */ - warn = 1; + warn = true; } else if (next_cipher == CIPHER_AES) { /* XXX Probably don't need to mention this. */ ppl_logevent(("AES not supported in SSH-1, skipping")); @@ -301,7 +301,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) cipher_string = "single-DES"; break; } if (s->supported_ciphers_mask & (1 << s->cipher_type)) - cipher_chosen = 1; + cipher_chosen = true; } } if (!cipher_chosen) { @@ -492,7 +492,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) * Attempt RSA authentication using Pageant. */ s->authed = false; - s->tried_agent = 1; + s->tried_agent = true; ppl_logevent(("Pageant is running. Requesting keys.")); /* Request the keys held by the agent. */ @@ -535,7 +535,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) s->publickey_blob->len)) { ppl_logevent(("Pageant key #%d matches " "configured key file", s->keyi)); - s->tried_publickey = 1; + s->tried_publickey = true; } else /* Skip non-configured key */ continue; @@ -632,12 +632,12 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) * Try public key authentication with the specified * key file. */ - int got_passphrase; /* need not be kept over crReturn */ + bool got_passphrase; /* need not be kept over crReturn */ if (flags & FLAG_VERBOSE) ppl_printf(("Trying public key authentication.\r\n")); ppl_logevent(("Trying public key \"%s\"", filename_to_str(s->keyfile))); - s->tried_publickey = 1; + s->tried_publickey = true; got_passphrase = false; while (!got_passphrase) { /* @@ -805,7 +805,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) ppl_logevent(("TIS authentication declined")); if (flags & FLAG_INTERACTIVE) ppl_printf(("TIS authentication refused.\r\n")); - s->tis_auth_refused = 1; + s->tis_auth_refused = true; continue; } else if (pktin->type == SSH1_SMSG_AUTH_TIS_CHALLENGE) { ptrlen challenge; @@ -853,7 +853,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) if (pktin->type == SSH1_SMSG_FAILURE) { ppl_logevent(("CryptoCard authentication declined")); ppl_printf(("CryptoCard authentication refused.\r\n")); - s->ccard_auth_refused = 1; + s->ccard_auth_refused = true; continue; } else if (pktin->type == SSH1_SMSG_AUTH_CCARD_CHALLENGE) { ptrlen challenge; @@ -1145,7 +1145,7 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl, } } -static int ssh1_login_want_user_input(PacketProtocolLayer *ppl) +static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl) { struct ssh1_login_state *s = container_of(ppl, struct ssh1_login_state, ppl); diff --git a/ssh2bpp.c b/ssh2bpp.c index fddfce00..4d117878 100644 --- a/ssh2bpp.c +++ b/ssh2bpp.c @@ -13,7 +13,7 @@ struct ssh2_bpp_direction { unsigned long sequence; ssh2_cipher *cipher; ssh2_mac *mac; - int etm_mode; + bool etm_mode; const struct ssh_compression_alg *pending_compression; }; @@ -26,7 +26,7 @@ struct ssh2_bpp_state { unsigned cipherblk; PktIn *pktin; struct DataTransferStats *stats; - int cbc_ignore_workaround; + bool cbc_ignore_workaround; struct ssh2_bpp_direction in, out; /* comp and decomp logically belong in the per-direction @@ -34,9 +34,9 @@ struct ssh2_bpp_state { ssh_decompressor *in_decomp; ssh_compressor *out_comp; - int is_server; - int pending_newkeys; - int pending_compression, seen_userauth_success; + bool is_server; + bool pending_newkeys; + bool pending_compression, seen_userauth_success; BinaryPacketProtocol bpp; }; @@ -55,7 +55,7 @@ static const struct BinaryPacketProtocolVtable ssh2_bpp_vtable = { }; BinaryPacketProtocol *ssh2_bpp_new( - LogContext *logctx, struct DataTransferStats *stats, int is_server) + LogContext *logctx, struct DataTransferStats *stats, bool is_server) { struct ssh2_bpp_state *s = snew(struct ssh2_bpp_state); memset(s, 0, sizeof(*s)); @@ -90,8 +90,8 @@ static void ssh2_bpp_free(BinaryPacketProtocol *bpp) void ssh2_bpp_new_outgoing_crypto( BinaryPacketProtocol *bpp, const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv, - const struct ssh2_macalg *mac, int etm_mode, const void *mac_key, - const struct ssh_compression_alg *compression, int delayed_compression) + const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key, + const struct ssh_compression_alg *compression, bool delayed_compression) { struct ssh2_bpp_state *s; assert(bpp->vt == &ssh2_bpp_vtable); @@ -157,8 +157,8 @@ void ssh2_bpp_new_outgoing_crypto( void ssh2_bpp_new_incoming_crypto( BinaryPacketProtocol *bpp, const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv, - const struct ssh2_macalg *mac, int etm_mode, const void *mac_key, - const struct ssh_compression_alg *compression, int delayed_compression) + const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key, + const struct ssh_compression_alg *compression, bool delayed_compression) { struct ssh2_bpp_state *s; assert(bpp->vt == &ssh2_bpp_vtable); @@ -224,7 +224,7 @@ void ssh2_bpp_new_incoming_crypto( queue_idempotent_callback(&s->bpp.ic_in_raw); } -int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp) +bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp) { struct ssh2_bpp_state *s; assert(bpp->vt == &ssh2_bpp_vtable); diff --git a/ssh2censor.c b/ssh2censor.c index 3d13589d..68d9d61c 100644 --- a/ssh2censor.c +++ b/ssh2censor.c @@ -10,7 +10,7 @@ #include "ssh.h" int ssh2_censor_packet( - const PacketLogSettings *pls, int type, int sender_is_client, + const PacketLogSettings *pls, int type, bool sender_is_client, ptrlen pkt, logblank_t *blanks) { int nblanks = 0; diff --git a/ssh2connection-client.c b/ssh2connection-client.c index 8a481f50..d332c677 100644 --- a/ssh2connection-client.c +++ b/ssh2connection-client.c @@ -124,7 +124,7 @@ ChanopenResult ssh2_connection_parse_channel_open( } } -int ssh2_connection_parse_global_request( +bool ssh2_connection_parse_global_request( struct ssh2_connection_state *s, ptrlen type, PktIn *pktin) { /* @@ -240,7 +240,7 @@ struct ssh_rportfwd *ssh2_rportfwd_alloc( PktOut *pktout = ssh_bpp_new_pktout( s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST); put_stringz(pktout, "tcpip-forward"); - put_bool(pktout, 1); /* want reply */ + put_bool(pktout, true); /* want reply */ put_stringz(pktout, rpf->shost); put_uint32(pktout, rpf->sport); pq_push(s->ppl.out_pq, pktout); @@ -268,7 +268,7 @@ void ssh2_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) PktOut *pktout = ssh_bpp_new_pktout( s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST); put_stringz(pktout, "cancel-tcpip-forward"); - put_bool(pktout, 0); /* _don't_ want reply */ + put_bool(pktout, false); /* _don't_ want reply */ put_stringz(pktout, rpf->shost); put_uint32(pktout, rpf->sport); pq_push(s->ppl.out_pq, pktout); @@ -320,7 +320,7 @@ static void ssh2_channel_response( chan_request_response(c->chan, pkt->type == SSH2_MSG_CHANNEL_SUCCESS); } -void ssh2channel_start_shell(SshChannel *sc, int want_reply) +void ssh2channel_start_shell(SshChannel *sc, bool want_reply) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -331,7 +331,7 @@ void ssh2channel_start_shell(SshChannel *sc, int want_reply) } void ssh2channel_start_command( - SshChannel *sc, int want_reply, const char *command) + SshChannel *sc, bool want_reply, const char *command) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -342,8 +342,8 @@ void ssh2channel_start_command( pq_push(s->ppl.out_pq, pktout); } -int ssh2channel_start_subsystem( - SshChannel *sc, int want_reply, const char *subsystem) +bool ssh2channel_start_subsystem( + SshChannel *sc, bool want_reply, const char *subsystem) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -362,20 +362,20 @@ void ssh2channel_send_exit_status(SshChannel *sc, int status) } void ssh2channel_send_exit_signal( - SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg) + SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg) { assert(false && "Should never be called in the client"); } void ssh2channel_send_exit_signal_numeric( - SshChannel *sc, int signum, int core_dumped, ptrlen msg) + SshChannel *sc, int signum, bool core_dumped, ptrlen msg) { assert(false && "Should never be called in the client"); } void ssh2channel_request_x11_forwarding( - SshChannel *sc, int want_reply, const char *authproto, - const char *authdata, int screen_number, int oneshot) + SshChannel *sc, bool want_reply, const char *authproto, + const char *authdata, int screen_number, bool oneshot) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -389,7 +389,7 @@ void ssh2channel_request_x11_forwarding( pq_push(s->ppl.out_pq, pktout); } -void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply) +void ssh2channel_request_agent_forwarding(SshChannel *sc, bool want_reply) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -401,7 +401,7 @@ void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply) } void ssh2channel_request_pty( - SshChannel *sc, int want_reply, Conf *conf, int w, int h) + SshChannel *sc, bool want_reply, Conf *conf, int w, int h) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -422,8 +422,8 @@ void ssh2channel_request_pty( pq_push(s->ppl.out_pq, pktout); } -int ssh2channel_send_env_var( - SshChannel *sc, int want_reply, const char *var, const char *value) +bool ssh2channel_send_env_var( + SshChannel *sc, bool want_reply, const char *var, const char *value) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -437,7 +437,7 @@ int ssh2channel_send_env_var( return true; } -int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length) +bool ssh2channel_send_serial_break(SshChannel *sc, bool want_reply, int length) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -450,8 +450,8 @@ int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length) return true; } -int ssh2channel_send_signal( - SshChannel *sc, int want_reply, const char *signame) +bool ssh2channel_send_signal( + SshChannel *sc, bool want_reply, const char *signame) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; diff --git a/ssh2connection-server.c b/ssh2connection-server.c index e49f591e..7cd7441a 100644 --- a/ssh2connection-server.c +++ b/ssh2connection-server.c @@ -79,7 +79,7 @@ ChanopenResult ssh2_connection_parse_channel_open( } } -int ssh2_connection_parse_global_request( +bool ssh2_connection_parse_global_request( struct ssh2_connection_state *s, ptrlen type, PktIn *pktin) { if (ptrlen_eq_string(type, "tcpip-forward")) { @@ -88,14 +88,14 @@ int ssh2_connection_parse_global_request( /* In SSH-2, the host/port we listen on are the same host/port * we want reported back to us when a connection comes in, * because that's what we tell the client */ - int toret = portfwdmgr_listen( + bool toret = portfwdmgr_listen( s->portfwdmgr, host, port, host, port, s->conf); sfree(host); return toret; } else if (ptrlen_eq_string(type, "cancel-tcpip-forward")) { char *host = mkstr(get_string(pktin)); unsigned port = get_uint32(pktin); - int toret = portfwdmgr_unlisten(s->portfwdmgr, host, port); + bool toret = portfwdmgr_unlisten(s->portfwdmgr, host, port); sfree(host); return toret; } else { @@ -200,19 +200,19 @@ SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan) return &c->sc; } -void ssh2channel_start_shell(SshChannel *sc, int want_reply) +void ssh2channel_start_shell(SshChannel *sc, bool want_reply) { assert(false && "Should never be called in the server"); } void ssh2channel_start_command( - SshChannel *sc, int want_reply, const char *command) + SshChannel *sc, bool want_reply, const char *command) { assert(false && "Should never be called in the server"); } -int ssh2channel_start_subsystem( - SshChannel *sc, int want_reply, const char *subsystem) +bool ssh2channel_start_subsystem( + SshChannel *sc, bool want_reply, const char *subsystem) { assert(false && "Should never be called in the server"); } @@ -229,7 +229,7 @@ void ssh2channel_send_exit_status(SshChannel *sc, int status) } void ssh2channel_send_exit_signal( - SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg) + SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -244,7 +244,7 @@ void ssh2channel_send_exit_signal( } void ssh2channel_send_exit_signal_numeric( - SshChannel *sc, int signum, int core_dumped, ptrlen msg) + SshChannel *sc, int signum, bool core_dumped, ptrlen msg) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; @@ -259,36 +259,36 @@ void ssh2channel_send_exit_signal_numeric( } void ssh2channel_request_x11_forwarding( - SshChannel *sc, int want_reply, const char *authproto, - const char *authdata, int screen_number, int oneshot) + SshChannel *sc, bool want_reply, const char *authproto, + const char *authdata, int screen_number, bool oneshot) { assert(false && "Should never be called in the server"); } -void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply) +void ssh2channel_request_agent_forwarding(SshChannel *sc, bool want_reply) { assert(false && "Should never be called in the server"); } void ssh2channel_request_pty( - SshChannel *sc, int want_reply, Conf *conf, int w, int h) + SshChannel *sc, bool want_reply, Conf *conf, int w, int h) { assert(false && "Should never be called in the server"); } -int ssh2channel_send_env_var( - SshChannel *sc, int want_reply, const char *var, const char *value) +bool ssh2channel_send_env_var( + SshChannel *sc, bool want_reply, const char *var, const char *value) { assert(false && "Should never be called in the server"); } -int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length) +bool ssh2channel_send_serial_break(SshChannel *sc, bool want_reply, int length) { assert(false && "Should never be called in the server"); } -int ssh2channel_send_signal( - SshChannel *sc, int want_reply, const char *signame) +bool ssh2channel_send_signal( + SshChannel *sc, bool want_reply, const char *signame) { assert(false && "Should never be called in the server"); } diff --git a/ssh2connection.c b/ssh2connection.c index f717ae84..0be08aa6 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -14,11 +14,11 @@ static void ssh2_connection_free(PacketProtocolLayer *); static void ssh2_connection_process_queue(PacketProtocolLayer *); -static int ssh2_connection_get_specials( +static bool ssh2_connection_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); -static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl); +static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl); static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl); static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); @@ -53,16 +53,16 @@ static void ssh2_delete_sharing_channel( static void ssh2_sharing_queue_global_request( ConnectionLayer *cl, ssh_sharing_connstate *share_ctx); static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl); -static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl); +static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl); static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height); static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize); static int ssh2_stdin_backlog(ConnectionLayer *cl); -static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled); -static int ssh2_ldisc_option(ConnectionLayer *cl, int option); -static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value); +static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled); +static bool ssh2_ldisc_option(ConnectionLayer *cl, int option); +static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value); static void ssh2_enable_x_fwd(ConnectionLayer *cl); static void ssh2_enable_agent_fwd(ConnectionLayer *cl); -static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted); +static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted); static const struct ConnectionLayerVtable ssh2_connlayer_vtable = { ssh2_rportfwd_alloc, @@ -119,7 +119,7 @@ static char *ssh2_channel_open_failure_error_text(PktIn *pktin) } static int ssh2channel_write( - SshChannel *c, int is_stderr, const void *buf, int len); + SshChannel *c, bool is_stderr, const void *buf, int len); static void ssh2channel_write_eof(SshChannel *c); static void ssh2channel_initiate_close(SshChannel *c, const char *err); static void ssh2channel_unthrottle(SshChannel *c, int bufsize); @@ -239,7 +239,7 @@ static void ssh2_channel_free(struct ssh2_channel *c) } PacketProtocolLayer *ssh2_connection_new( - Ssh *ssh, ssh_sharing_state *connshare, int is_simple, + Ssh *ssh, ssh_sharing_state *connshare, bool is_simple, Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out) { struct ssh2_connection_state *s = snew(struct ssh2_connection_state); @@ -313,7 +313,7 @@ static void ssh2_connection_free(PacketProtocolLayer *ppl) sfree(s); } -static int ssh2_connection_filter_queue(struct ssh2_connection_state *s) +static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s) { PktIn *pktin; PktOut *pktout; @@ -321,7 +321,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s) struct ssh2_channel *c; struct outstanding_channel_request *ocr; unsigned localid, remid, winsize, pktsize, ext_type; - int want_reply, reply_success, expect_halfopen; + bool want_reply, reply_success, expect_halfopen; ChanopenResult chanopen_result; PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ @@ -330,7 +330,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s) * we have an instance of ssh2transport below us, then those * messages won't come here anyway, but they could if we're * running in bare ssh2-connection mode. */ - extern int ssh2_common_filter_queue(PacketProtocolLayer *ppl); + extern bool ssh2_common_filter_queue(PacketProtocolLayer *ppl); while (1) { if (ssh2_common_filter_queue(&s->ppl)) @@ -610,7 +610,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s) } else if (ptrlen_eq_string(type, "exit-signal")) { ptrlen signame; int signum; - int core = false; + bool core = false; ptrlen errmsg; int format; @@ -669,7 +669,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s) ptrlen subsys = get_string(pktin); reply_success = chan_run_subsystem(c->chan, subsys); } else if (ptrlen_eq_string(type, "x11-req")) { - int oneshot = get_bool(pktin); + bool oneshot = get_bool(pktin); ptrlen authproto = get_string(pktin); ptrlen authdata = get_string(pktin); unsigned screen_number = get_uint32(pktin); @@ -1341,13 +1341,13 @@ static void ssh2channel_unthrottle(SshChannel *sc, int bufsize) ssh2_set_window(c, buflimit - bufsize); if (c->throttling_conn && bufsize <= buflimit) { - c->throttling_conn = 0; + c->throttling_conn = false; ssh_throttle_conn(s->ppl.ssh, -1); } } static int ssh2channel_write( - SshChannel *sc, int is_stderr, const void *buf, int len) + SshChannel *sc, bool is_stderr, const void *buf, int len) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); assert(!(c->closes & CLOSES_SENT_EOF)); @@ -1522,19 +1522,19 @@ static void ssh2_send_packet_from_downstream( pq_push(s->ppl.out_pq, pkt); } -static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl) +static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists(); } -static int ssh2_connection_get_specials( +static bool ssh2_connection_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { struct ssh2_connection_state *s = container_of(ppl, struct ssh2_connection_state, ppl); - int toret = false; + bool toret = false; if (s->mainchan) { mainchan_get_specials(s->mainchan, add_special, ctx); @@ -1608,7 +1608,7 @@ static int ssh2_stdin_backlog(ConnectionLayer *cl) bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer) : 0; } -static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled) +static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1621,7 +1621,7 @@ static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled) ssh2_channel_check_throttle(c); } -static int ssh2_ldisc_option(ConnectionLayer *cl, int option) +static bool ssh2_ldisc_option(ConnectionLayer *cl, int option) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1629,7 +1629,7 @@ static int ssh2_ldisc_option(ConnectionLayer *cl, int option) return s->ldisc_opts[option]; } -static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value) +static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1653,7 +1653,7 @@ static void ssh2_enable_agent_fwd(ConnectionLayer *cl) s->agent_fwd_enabled = true; } -static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted) +static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1661,7 +1661,7 @@ static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted) s->want_user_input = wanted; } -static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl) +static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_connection_state *s = container_of(ppl, struct ssh2_connection_state, ppl); diff --git a/ssh2connection.h b/ssh2connection.h index 058efb57..1c70aca4 100644 --- a/ssh2connection.h +++ b/ssh2connection.h @@ -14,28 +14,28 @@ struct ssh2_connection_state { mainchan *mainchan; SshChannel *mainchan_sc; - int ldisc_opts[LD_N_OPTIONS]; + bool ldisc_opts[LD_N_OPTIONS]; int session_attempt, session_status; int term_width, term_height; - int want_user_input; + bool want_user_input; - int ssh_is_simple; - int persistent; + bool ssh_is_simple; + bool persistent; Conf *conf; tree234 *channels; /* indexed by local id */ - int all_channels_throttled; + bool all_channels_throttled; - int X11_fwd_enabled; + bool X11_fwd_enabled; tree234 *x11authtree; - int got_pty; - int agent_fwd_enabled; + bool got_pty; + bool agent_fwd_enabled; tree234 *rportfwds; PortFwdManager *portfwdmgr; - int portfwdmgr_configured; + bool portfwdmgr_configured; const SftpServerVtable *sftpserver_vt; @@ -62,7 +62,7 @@ struct ssh2_channel { unsigned remoteid, localid; int type; /* True if we opened this channel but server hasn't confirmed. */ - int halfopen; + bool halfopen; /* Bitmap of whether we've sent/received CHANNEL_EOF and * CHANNEL_CLOSE. */ @@ -80,13 +80,13 @@ struct ssh2_channel { * we set this flag instead to remind us to do so once our buffer * is clear. */ - int pending_eof; + bool pending_eof; /* * True if this channel is causing the underlying connection to be * throttled. */ - int throttling_conn; + bool throttling_conn; /* * True if we currently have backed-up data on the direction of @@ -94,7 +94,7 @@ struct ssh2_channel { * would prefer the 'Channel' implementation not to read further * local input if possible. */ - int throttled_by_backlog; + bool throttled_by_backlog; bufchain outbuffer, errbuffer; unsigned remwindow, remmaxpkt; @@ -172,28 +172,28 @@ SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan); void ssh2channel_send_exit_status(SshChannel *c, int status); void ssh2channel_send_exit_signal( - SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg); + SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg); void ssh2channel_send_exit_signal_numeric( - SshChannel *c, int signum, int core_dumped, ptrlen msg); + SshChannel *c, int signum, bool core_dumped, ptrlen msg); void ssh2channel_request_x11_forwarding( - SshChannel *c, int want_reply, const char *authproto, - const char *authdata, int screen_number, int oneshot); -void ssh2channel_request_agent_forwarding(SshChannel *c, int want_reply); + SshChannel *c, bool want_reply, const char *authproto, + const char *authdata, int screen_number, bool oneshot); +void ssh2channel_request_agent_forwarding(SshChannel *c, bool want_reply); void ssh2channel_request_pty( - SshChannel *c, int want_reply, Conf *conf, int w, int h); -int ssh2channel_send_env_var( - SshChannel *c, int want_reply, const char *var, const char *value); -void ssh2channel_start_shell(SshChannel *c, int want_reply); + SshChannel *c, bool want_reply, Conf *conf, int w, int h); +bool ssh2channel_send_env_var( + SshChannel *c, bool want_reply, const char *var, const char *value); +void ssh2channel_start_shell(SshChannel *c, bool want_reply); void ssh2channel_start_command( - SshChannel *c, int want_reply, const char *command); -int ssh2channel_start_subsystem( - SshChannel *c, int want_reply, const char *subsystem); -int ssh2channel_send_env_var( - SshChannel *c, int want_reply, const char *var, const char *value); -int ssh2channel_send_serial_break( - SshChannel *c, int want_reply, int length); -int ssh2channel_send_signal( - SshChannel *c, int want_reply, const char *signame); + SshChannel *c, bool want_reply, const char *command); +bool ssh2channel_start_subsystem( + SshChannel *c, bool want_reply, const char *subsystem); +bool ssh2channel_send_env_var( + SshChannel *c, bool want_reply, const char *var, const char *value); +bool ssh2channel_send_serial_break( + SshChannel *c, bool want_reply, int length); +bool ssh2channel_send_signal( + SshChannel *c, bool want_reply, const char *signame); void ssh2channel_send_terminal_size_change(SshChannel *c, int w, int h); #define CHANOPEN_RETURN_FAILURE(code, msgparams) do \ @@ -225,7 +225,7 @@ ChanopenResult ssh2_connection_parse_channel_open( struct ssh2_connection_state *s, ptrlen type, PktIn *pktin, SshChannel *sc); -int ssh2_connection_parse_global_request( +bool ssh2_connection_parse_global_request( struct ssh2_connection_state *s, ptrlen type, PktIn *pktin); #endif /* PUTTY_SSH2CONNECTION_H */ diff --git a/ssh2kex-client.c b/ssh2kex-client.c index a83f32ec..bff5b284 100644 --- a/ssh2kex-client.c +++ b/ssh2kex-client.c @@ -230,8 +230,8 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s) ptrlen data; s->ppl.bpp->pls->kctx = SSH2_PKTCTX_GSSKEX; - s->init_token_sent = 0; - s->complete_rcvd = 0; + s->init_token_sent = false; + s->complete_rcvd = false; s->hkey = NULL; s->fingerprint = NULL; s->keystr = NULL; @@ -349,7 +349,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s) s->gss_stat == SSH_GSS_S_CONTINUE_NEEDED); if (!s->init_token_sent) { - s->init_token_sent = 1; + s->init_token_sent = true; pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_KEXGSS_INIT); if (s->gss_sndtok.length == 0) { @@ -385,7 +385,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s) s->gss_rcvtok.length = data.len; continue; case SSH2_MSG_KEXGSS_COMPLETE: - s->complete_rcvd = 1; + s->complete_rcvd = true; s->f = get_mp_ssh2(pktin); data = get_string(pktin); s->mic.value = (char *)data.ptr; diff --git a/ssh2transhk.c b/ssh2transhk.c index 46e2cf58..e6803c56 100644 --- a/ssh2transhk.c +++ b/ssh2transhk.c @@ -87,11 +87,11 @@ void ssh_transient_hostkey_cache_add( assert(retd == ent); } -int ssh_transient_hostkey_cache_verify( +bool ssh_transient_hostkey_cache_verify( ssh_transient_hostkey_cache *thc, ssh_key *key) { struct ssh_transient_hostkey_cache_entry *ent; - int toret = false; + bool toret = false; if ((ent = find234(thc->cache, (void *)ssh_key_alg(key), ssh_transient_hostkey_cache_find)) != NULL) { @@ -109,7 +109,7 @@ int ssh_transient_hostkey_cache_verify( return toret; } -int ssh_transient_hostkey_cache_has( +bool ssh_transient_hostkey_cache_has( ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg) { struct ssh_transient_hostkey_cache_entry *ent = @@ -118,7 +118,7 @@ int ssh_transient_hostkey_cache_has( return ent != NULL; } -int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc) +bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc) { return count234(thc->cache) > 0; } diff --git a/ssh2transport.c b/ssh2transport.c index 58886991..2a713413 100644 --- a/ssh2transport.c +++ b/ssh2transport.c @@ -44,11 +44,11 @@ static void ssh_comp_none_block(ssh_compressor *handle, int minlen) { } -static int ssh_decomp_none_block(ssh_decompressor *handle, - unsigned char *block, int len, - unsigned char **outblock, int *outlen) +static bool ssh_decomp_none_block(ssh_decompressor *handle, + unsigned char *block, int len, + unsigned char **outblock, int *outlen) { - return 0; + return false; } const static struct ssh_compression_alg ssh_comp_none = { "none", NULL, @@ -62,11 +62,11 @@ const static struct ssh_compression_alg *const compressions[] = { static void ssh2_transport_free(PacketProtocolLayer *); static void ssh2_transport_process_queue(PacketProtocolLayer *); -static int ssh2_transport_get_specials( +static bool ssh2_transport_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); -static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl); +static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl); static void ssh2_transport_got_user_input(PacketProtocolLayer *ppl); static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf); @@ -87,11 +87,11 @@ static const struct PacketProtocolLayerVtable ssh2_transport_vtable = { #ifndef NO_GSSAPI static void ssh2_transport_gss_update(struct ssh2_transport_state *s, - int definitely_rekeying); + bool definitely_rekeying); #endif -static int ssh2_transport_timer_update(struct ssh2_transport_state *s, - unsigned long rekey_time); +static bool ssh2_transport_timer_update(struct ssh2_transport_state *s, + unsigned long rekey_time); static const char *const kexlist_descr[NKEXLIST] = { "key exchange algorithm", @@ -109,7 +109,7 @@ PacketProtocolLayer *ssh2_transport_new( const char *client_greeting, const char *server_greeting, struct ssh_connection_shared_gss_state *shgss, struct DataTransferStats *stats, PacketProtocolLayer *higher_layer, - int is_server) + bool is_server) { struct ssh2_transport_state *s = snew(struct ssh2_transport_state); memset(s, 0, sizeof(*s)); @@ -298,7 +298,7 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm return NULL; } -int ssh2_common_filter_queue(PacketProtocolLayer *ppl) +bool ssh2_common_filter_queue(PacketProtocolLayer *ppl) { static const char *const ssh2_disconnect_reasons[] = { NULL, @@ -359,7 +359,7 @@ int ssh2_common_filter_queue(PacketProtocolLayer *ppl) return false; } -static int ssh2_transport_filter_queue(struct ssh2_transport_state *s) +static bool ssh2_transport_filter_queue(struct ssh2_transport_state *s) { PktIn *pktin; @@ -407,9 +407,10 @@ static void ssh2_write_kexinit_lists( const char *hk_host, int hk_port, const ssh_keyalg *hk_prev, ssh_transient_hostkey_cache *thc, ssh_key *const *our_hostkeys, int our_nhostkeys, - int first_time, int can_gssapi_keyex, int transient_hostkey_mode) + bool first_time, bool can_gssapi_keyex, bool transient_hostkey_mode) { - int i, j, k, warn; + int i, j, k; + bool warn; int n_preferred_kex; const struct ssh_kexes *preferred_kex[KEX_MAX + 1]; /* +1 for GSSAPI */ @@ -735,18 +736,18 @@ static void ssh2_write_kexinit_lists( put_stringz(pktout, ""); } -static int ssh2_scan_kexinits( +static bool ssh2_scan_kexinits( ptrlen client_kexinit, ptrlen server_kexinit, struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST], const struct ssh_kex **kex_alg, const ssh_keyalg **hostkey_alg, transport_direction *cs, transport_direction *sc, - int *warn_kex, int *warn_hk, int *warn_cscipher, int *warn_sccipher, - Ssh *ssh, int *ignore_guess_cs_packet, int *ignore_guess_sc_packet, + bool *warn_kex, bool *warn_hk, bool *warn_cscipher, bool *warn_sccipher, + Ssh *ssh, bool *ignore_guess_cs_packet, bool *ignore_guess_sc_packet, int *n_server_hostkeys, int server_hostkeys[MAXKEXLIST]) { BinarySource client[1], server[1]; int i; - int guess_correct; + bool guess_correct; ptrlen clists[NKEXLIST], slists[NKEXLIST]; const struct kexinit_algorithm *selected[NKEXLIST]; @@ -763,7 +764,8 @@ static int ssh2_scan_kexinits( * kexinit_algorithm structure. */ for (i = 0; i < NKEXLIST; i++) { ptrlen clist, slist, cword, sword, found; - int cfirst, sfirst, j; + bool cfirst, sfirst; + int j; clists[i] = get_string(client); slists[i] = get_string(server); @@ -1025,7 +1027,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl) * fresh ones. */ if (!s->got_session_id && (s->gss_status & GSS_CTXT_MAYFAIL) != 0) - s->can_gssapi_keyex = 0; + s->can_gssapi_keyex = false; s->gss_delegate = conf_get_bool(s->conf, CONF_gssapifwd); } else { s->can_gssapi_keyex = false; @@ -1147,7 +1149,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl) for (j = 0; j < s->n_uncert_hostkeys; j++) { const struct ssh_signkey_with_user_pref_id *hktype = &ssh2_hostkey_algs[s->uncert_hostkeys[j]]; - int better = false; + bool better = false; for (k = 0; k < HK_MAX; k++) { int id = conf_get_int_int(s->conf, CONF_ssh_hklist, k); if (id == HK_WARN) { @@ -1575,11 +1577,12 @@ static void ssh2_transport_timer(void *ctx, unsigned long now) /* * The rekey_time is zero except when re-configuring. * - * We either schedule the next timer and return 0, or return 1 to run the - * callback now, which will call us again to re-schedule on completion. + * We either schedule the next timer and return false, or return true + * to run the callback now, which will call us again to re-schedule on + * completion. */ -static int ssh2_transport_timer_update(struct ssh2_transport_state *s, - unsigned long rekey_time) +static bool ssh2_transport_timer_update(struct ssh2_transport_state *s, + unsigned long rekey_time) { unsigned long mins; unsigned long ticks; @@ -1598,7 +1601,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s, /* If overdue, caller will rekey synchronously now */ if (now - s->last_rekey > ticks) - return 1; + return true; ticks = next - now; } @@ -1633,7 +1636,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s, /* Schedule the next timer */ s->next_rekey = schedule_timer(ticks, ssh2_transport_timer, s); - return 0; + return false; } void ssh2_transport_dialog_callback(void *loginv, int ret) @@ -1658,7 +1661,7 @@ void ssh2_transport_dialog_callback(void *loginv, int ret) * newly obtained context as a proxy for the expiration of the TGT. */ static void ssh2_transport_gss_update(struct ssh2_transport_state *s, - int definitely_rekeying) + bool definitely_rekeying) { PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ int gss_stat; @@ -1754,7 +1757,7 @@ static void ssh2_transport_gss_update(struct ssh2_transport_state *s, * refresh them. We must avoid setting GSS_CRED_UPDATED or * GSS_CTXT_EXPIRES when credential delegation is disabled. */ - if (conf_get_bool(s->conf, CONF_gssapifwd) == 0) + if (!conf_get_bool(s->conf, CONF_gssapifwd)) return; if (s->gss_cred_expiry != GSS_NO_EXPIRATION && @@ -1792,13 +1795,13 @@ void ssh2_transport_notify_auth_done(PacketProtocolLayer *ppl) #endif /* NO_GSSAPI */ -static int ssh2_transport_get_specials( +static bool ssh2_transport_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { struct ssh2_transport_state *s = container_of(ppl, struct ssh2_transport_state, ppl); - int need_separator = false; - int toret; + bool need_separator = false; + bool toret; if (ssh_ppl_get_specials(s->higher_layer, add_special, ctx)) { need_separator = true; @@ -1884,7 +1887,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf) { struct ssh2_transport_state *s; const char *rekey_reason = NULL; - int rekey_mandatory = false; + bool rekey_mandatory = false; unsigned long old_max_data_size, rekey_time; int i; @@ -1905,8 +1908,8 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf) /* We must decrement both counters, so avoid short-circuit * evaluation skipping one */ - int out_expired = DTS_CONSUME(s->stats, out, diff) != 0; - int in_expired = DTS_CONSUME(s->stats, in, diff) != 0; + bool out_expired = DTS_CONSUME(s->stats, out, diff); + bool in_expired = DTS_CONSUME(s->stats, in, diff); if (out_expired || in_expired) rekey_reason = "data limit lowered"; } else { @@ -1953,7 +1956,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf) ssh_ppl_reconfigure(s->higher_layer, conf); } -static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl) +static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_transport_state *s = container_of(ppl, struct ssh2_transport_state, ppl); diff --git a/ssh2transport.h b/ssh2transport.h index a86b6ee1..de6a6fe1 100644 --- a/ssh2transport.h +++ b/ssh2transport.h @@ -29,23 +29,23 @@ struct kexinit_algorithm { union { struct { const struct ssh_kex *kex; - int warn; + bool warn; } kex; struct { const ssh_keyalg *hostkey; - int warn; + bool warn; } hk; struct { const struct ssh2_cipheralg *cipher; - int warn; + bool warn; } cipher; struct { const struct ssh2_macalg *mac; - int etm; + bool etm; } mac; struct { const struct ssh_compression_alg *comp; - int delayed; + bool delayed; } comp; } u; }; @@ -105,9 +105,9 @@ typedef enum RekeyClass { typedef struct transport_direction { const struct ssh2_cipheralg *cipher; const struct ssh2_macalg *mac; - int etm_mode; + bool etm_mode; const struct ssh_compression_alg *comp; - int comp_delayed; + bool comp_delayed; int mkkey_adjust; } transport_direction; @@ -132,7 +132,8 @@ struct ssh2_transport_state { char *hostkey_str; /* string representation, for easy checking in rekeys */ unsigned char session_id[SSH2_KEX_MAX_HASH_LEN]; int session_id_len; - int dh_min_size, dh_max_size, dh_got_size_bounds; + int dh_min_size, dh_max_size; + bool dh_got_size_bounds; struct dh_ctx *dh_ctx; ssh_hash *exhash; @@ -140,10 +141,10 @@ struct ssh2_transport_state { char *client_greeting, *server_greeting; - int kex_in_progress; + bool kex_in_progress; unsigned long next_rekey, last_rekey; const char *deferred_rekey_reason; - int higher_layer_ok; + bool higher_layer_ok; /* * Fully qualified host name, which we need if doing GSSAPI. @@ -161,9 +162,10 @@ struct ssh2_transport_state { #endif ssh_transient_hostkey_cache *thc; - int gss_kex_used; + bool gss_kex_used; - int nbits, pbits, warn_kex, warn_hk, warn_cscipher, warn_sccipher; + int nbits, pbits; + bool warn_kex, warn_hk, warn_cscipher, warn_sccipher; Bignum p, g, e, f, K; strbuf *outgoing_kexinit, *incoming_kexinit; strbuf *client_kexinit, *server_kexinit; /* aliases to the above */ @@ -176,22 +178,22 @@ struct ssh2_transport_state { struct RSAKey *rsa_kex_key; /* for RSA kex */ struct ec_key *ecdh_key; /* for ECDH kex */ unsigned char exchange_hash[SSH2_KEX_MAX_HASH_LEN]; - int can_gssapi_keyex; - int need_gss_transient_hostkey; - int warned_about_no_gss_transient_hostkey; - int got_session_id; + bool can_gssapi_keyex; + bool need_gss_transient_hostkey; + bool warned_about_no_gss_transient_hostkey; + bool got_session_id; int dlgret; - int guessok; - int ignorepkt; + bool guessok; + bool ignorepkt; struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST]; #ifndef NO_GSSAPI Ssh_gss_buf gss_buf; Ssh_gss_buf gss_rcvtok, gss_sndtok; Ssh_gss_stat gss_stat; Ssh_gss_buf mic; - int init_token_sent; - int complete_rcvd; - int gss_delegate; + bool init_token_sent; + bool complete_rcvd; + bool gss_delegate; #endif /* @@ -205,7 +207,7 @@ struct ssh2_transport_state { * Flag indicating that the current rekey is intended to finish * with a newly cross-certified host key. */ - int cross_certifying; + bool cross_certifying; ssh_key *const *hostkeys; int nhostkeys; diff --git a/ssh2userauth-server.c b/ssh2userauth-server.c index 685cf5c0..d28176ea 100644 --- a/ssh2userauth-server.c +++ b/ssh2userauth-server.c @@ -27,7 +27,7 @@ struct ssh2_userauth_server_state { ptrlen username, service, method; unsigned methods, this_method; - int partial_success; + bool partial_success; AuthKbdInt *aki; @@ -162,7 +162,7 @@ static void ssh2_userauth_server_process_queue(PacketProtocolLayer *ppl) if (!auth_none(s->authpolicy, s->username)) goto failure; } else if (ptrlen_eq_string(s->method, "password")) { - int changing; + bool changing; ptrlen password, new_password, *new_password_ptr; s->this_method = AUTHMETHOD_PASSWORD; @@ -192,7 +192,7 @@ static void ssh2_userauth_server_process_queue(PacketProtocolLayer *ppl) goto failure; } } else if (ptrlen_eq_string(s->method, "publickey")) { - int has_signature, success; + bool has_signature, success; ptrlen algorithm, blob, signature; const ssh_keyalg *keyalg; ssh_key *key; diff --git a/ssh2userauth.c b/ssh2userauth.c index c667ab5e..8e4b88dc 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -23,10 +23,10 @@ struct ssh2_userauth_state { PacketProtocolLayer *transport_layer, *successor_layer; Filename *keyfile; - int tryagent, change_username; + bool tryagent, change_username; char *hostname, *fullhostname; char *default_username; - int try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd; + bool try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd; ptrlen session_id; enum { @@ -39,28 +39,28 @@ struct ssh2_userauth_state { AUTH_TYPE_KEYBOARD_INTERACTIVE, AUTH_TYPE_KEYBOARD_INTERACTIVE_QUIET } type; - int need_pw, can_pubkey, can_passwd, can_keyb_inter; + bool need_pw, can_pubkey, can_passwd, can_keyb_inter; int userpass_ret; - int tried_pubkey_config, done_agent; + bool tried_pubkey_config, done_agent; struct ssh_connection_shared_gss_state *shgss; #ifndef NO_GSSAPI - int can_gssapi; - int can_gssapi_keyex_auth; - int tried_gssapi; - int tried_gssapi_keyex_auth; + bool can_gssapi; + bool can_gssapi_keyex_auth; + bool tried_gssapi; + bool tried_gssapi_keyex_auth; time_t gss_cred_expiry; Ssh_gss_buf gss_buf; Ssh_gss_buf gss_rcvtok, gss_sndtok; Ssh_gss_stat gss_stat; #endif - int kbd_inter_refused; + bool kbd_inter_refused; prompts_t *cur_prompt; int num_prompts; char *username; char *password; - int got_username; + bool got_username; strbuf *publickey_blob; - int privatekey_available, privatekey_encrypted; + bool privatekey_available, privatekey_encrypted; char *publickey_algorithm; char *publickey_comment; void *agent_response_to_free; @@ -71,7 +71,7 @@ struct ssh2_userauth_state { ptrlen pk, alg, comment; int len; PktOut *pktout; - int want_user_input; + bool want_user_input; agent_pending_query *auth_agent_query; bufchain banner; @@ -81,11 +81,11 @@ struct ssh2_userauth_state { static void ssh2_userauth_free(PacketProtocolLayer *); static void ssh2_userauth_process_queue(PacketProtocolLayer *); -static int ssh2_userauth_get_specials( +static bool ssh2_userauth_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); -static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl); +static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl); static void ssh2_userauth_got_user_input(PacketProtocolLayer *ppl); static void ssh2_userauth_reconfigure(PacketProtocolLayer *ppl, Conf *conf); @@ -114,11 +114,10 @@ static const struct PacketProtocolLayerVtable ssh2_userauth_vtable = { PacketProtocolLayer *ssh2_userauth_new( PacketProtocolLayer *successor_layer, const char *hostname, const char *fullhostname, - Filename *keyfile, int tryagent, - const char *default_username, int change_username, - int try_ki_auth, - int try_gssapi_auth, int try_gssapi_kex_auth, - int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss) + Filename *keyfile, bool tryagent, + const char *default_username, bool change_username, + bool try_ki_auth, bool try_gssapi_auth, bool try_gssapi_kex_auth, + bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss) { struct ssh2_userauth_state *s = snew(struct ssh2_userauth_state); memset(s, 0, sizeof(*s)); @@ -1101,7 +1100,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) s->num_prompts = get_uint32(pktin); for (i = 0; i < s->num_prompts; i++) { ptrlen prompt; - int echo; + bool echo; static char noprompt[] = ": "; @@ -1213,7 +1212,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) /* * Plain old password authentication. */ - int changereq_first_time; /* not live over crReturn */ + bool changereq_first_time; /* not live over crReturn */ s->ppl.bpp->pls->actx = SSH2_PKTCTX_PASSWORD; @@ -1296,7 +1295,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) * Loop until the server accepts it. */ - int got_new = false; /* not live over crReturn */ + bool got_new = false; /* not live over crReturn */ ptrlen prompt; /* not live over crReturn */ { @@ -1634,7 +1633,7 @@ static PktOut *ssh2_userauth_gss_packet( } #endif -static int ssh2_userauth_get_specials( +static bool ssh2_userauth_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { /* No specials provided by this layer. */ @@ -1647,7 +1646,7 @@ static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl, /* No specials provided by this layer. */ } -static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl) +static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_userauth_state *s = container_of(ppl, struct ssh2_userauth_state, ppl); diff --git a/sshaes.c b/sshaes.c index 45a9eba3..fad9ff4f 100644 --- a/sshaes.c +++ b/sshaes.c @@ -57,14 +57,14 @@ struct AESContext { void (*encrypt_cbc)(unsigned char*, int, AESContext*); void (*decrypt_cbc)(unsigned char*, int, AESContext*); void (*sdctr)(unsigned char*, int, AESContext*); - int isNI; + bool isNI; }; static void aes_encrypt_cbc_sw(unsigned char*, int, AESContext*); static void aes_decrypt_cbc_sw(unsigned char*, int, AESContext*); static void aes_sdctr_sw(unsigned char*, int, AESContext*); -INLINE static int supports_aes_ni(); +INLINE static bool supports_aes_ni(); static void aes_setup_ni(AESContext * ctx, const unsigned char *key, int keylen); @@ -1219,7 +1219,7 @@ const struct ssh2_ciphers ssh2_aes = { #if defined(__clang__) || defined(__GNUC__) #include -INLINE static int supports_aes_ni() +INLINE static bool supports_aes_ni() { unsigned int CPUInfo[4]; __cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); @@ -1228,7 +1228,7 @@ INLINE static int supports_aes_ni() #else /* defined(__clang__) || defined(__GNUC__) */ -INLINE static int supports_aes_ni() +INLINE static bool supports_aes_ni() { unsigned int CPUInfo[4]; __cpuid(CPUInfo, 1); @@ -1755,9 +1755,9 @@ static void aes_setup_ni(AESContext * ctx, const unsigned char *key, int keylen) assert(0); } -INLINE static int supports_aes_ni() +INLINE static bool supports_aes_ni() { - return 0; + return false; } #endif /* COMPILER_SUPPORTS_AES_NI */ diff --git a/sshbn.c b/sshbn.c index 17293762..d61e3ab6 100644 --- a/sshbn.c +++ b/sshbn.c @@ -2085,7 +2085,8 @@ Bignum modinv(Bignum number, Bignum modulus) char *bignum_decimal(Bignum x) { int ndigits, ndigit; - int i, iszero; + int i; + bool iszero; BignumInt carry; char *ret; BignumInt *workspace; @@ -2130,7 +2131,7 @@ char *bignum_decimal(Bignum x) ndigit = ndigits - 1; ret[ndigit] = '\0'; do { - iszero = 1; + iszero = true; carry = 0; for (i = 0; i < (int)x[0]; i++) { /* @@ -2159,7 +2160,7 @@ char *bignum_decimal(Bignum x) carry = r; if (workspace[i]) - iszero = 0; + iszero = false; } ret[--ndigit] = (char) (carry + '0'); } while (!iszero); diff --git a/sshbpp.h b/sshbpp.h index 2b09fdea..26ff477d 100644 --- a/sshbpp.h +++ b/sshbpp.h @@ -17,7 +17,7 @@ struct BinaryPacketProtocolVtable { struct BinaryPacketProtocol { const struct BinaryPacketProtocolVtable *vt; bufchain *in_raw, *out_raw; - int input_eof; /* set this if in_raw will never be added to again */ + bool input_eof; /* set this if in_raw will never be added to again */ PktInQueue in_pq; PktOutQueue out_pq; PacketLogSettings *pls; @@ -39,7 +39,7 @@ struct BinaryPacketProtocol { * error message (either because it's not to be treated as an * error at all, or because some other error message has already * been emitted). */ - int expect_close; + bool expect_close; }; #define ssh_bpp_handle_input(bpp) ((bpp)->vt->handle_input(bpp)) @@ -68,7 +68,7 @@ void ssh_bpp_common_setup(BinaryPacketProtocol *); /* Common helper functions between the SSH-2 full and bare BPPs */ void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp, const char *msg, int category); -int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin); +bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin); /* Convenience macro for BPPs to send formatted strings to the Event * Log. Assumes a function parameter called 'bpp' is in scope, and @@ -92,7 +92,7 @@ int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin); */ struct DataTransferStats { struct { - int running; + bool running; unsigned long remaining; } in, out; }; @@ -103,17 +103,17 @@ struct DataTransferStats { ((stats)->direction.remaining -= (size), false)) BinaryPacketProtocol *ssh2_bpp_new( - LogContext *logctx, struct DataTransferStats *stats, int is_server); + LogContext *logctx, struct DataTransferStats *stats, bool is_server); void ssh2_bpp_new_outgoing_crypto( BinaryPacketProtocol *bpp, const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv, - const struct ssh2_macalg *mac, int etm_mode, const void *mac_key, - const struct ssh_compression_alg *compression, int delayed_compression); + const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key, + const struct ssh_compression_alg *compression, bool delayed_compression); void ssh2_bpp_new_incoming_crypto( BinaryPacketProtocol *bpp, const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv, - const struct ssh2_macalg *mac, int etm_mode, const void *mac_key, - const struct ssh_compression_alg *compression, int delayed_compression); + const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key, + const struct ssh_compression_alg *compression, bool delayed_compression); /* * A query method specific to the interface between ssh2transport and @@ -124,7 +124,7 @@ void ssh2_bpp_new_incoming_crypto( * to start a rekey because then we'd stop responding to anything * _other_ than transport-layer packets and deadlock the protocol. */ -int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp); +bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp); BinaryPacketProtocol *ssh2_bare_bpp_new(LogContext *logctx); @@ -139,9 +139,9 @@ struct ssh_version_receiver { int major_version); }; BinaryPacketProtocol *ssh_verstring_new( - Conf *conf, LogContext *logctx, int bare_connection_mode, + Conf *conf, LogContext *logctx, bool bare_connection_mode, const char *protoversion, struct ssh_version_receiver *rcv, - int server_mode, const char *impl_name); + bool server_mode, const char *impl_name); const char *ssh_verstring_get_remote(BinaryPacketProtocol *); const char *ssh_verstring_get_local(BinaryPacketProtocol *); int ssh_verstring_get_bugs(BinaryPacketProtocol *); diff --git a/sshchan.h b/sshchan.h index dd82fd63..9ec256d6 100644 --- a/sshchan.h +++ b/sshchan.h @@ -19,42 +19,42 @@ struct ChannelVtable { void (*open_confirmation)(Channel *); void (*open_failed)(Channel *, const char *error_text); - int (*send)(Channel *, int is_stderr, const void *buf, int len); + int (*send)(Channel *, bool is_stderr, const void *buf, int len); void (*send_eof)(Channel *); - void (*set_input_wanted)(Channel *, int wanted); + void (*set_input_wanted)(Channel *, bool wanted); char *(*log_close_msg)(Channel *); - int (*want_close)(Channel *, int sent_local_eof, int rcvd_remote_eof); + bool (*want_close)(Channel *, bool sent_local_eof, bool rcvd_remote_eof); /* A method for every channel request we know of. All of these * return true for success or false for failure. */ - int (*rcvd_exit_status)(Channel *, int status); - int (*rcvd_exit_signal)( - Channel *chan, ptrlen signame, int core_dumped, ptrlen msg); - int (*rcvd_exit_signal_numeric)( - Channel *chan, int signum, int core_dumped, ptrlen msg); - int (*run_shell)(Channel *chan); - int (*run_command)(Channel *chan, ptrlen command); - int (*run_subsystem)(Channel *chan, ptrlen subsys); - int (*enable_x11_forwarding)( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata, + bool (*rcvd_exit_status)(Channel *, int status); + bool (*rcvd_exit_signal)( + Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg); + bool (*rcvd_exit_signal_numeric)( + Channel *chan, int signum, bool core_dumped, ptrlen msg); + bool (*run_shell)(Channel *chan); + bool (*run_command)(Channel *chan, ptrlen command); + bool (*run_subsystem)(Channel *chan, ptrlen subsys); + bool (*enable_x11_forwarding)( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata, unsigned screen_number); - int (*enable_agent_forwarding)(Channel *chan); - int (*allocate_pty)( + bool (*enable_agent_forwarding)(Channel *chan); + bool (*allocate_pty)( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes); - int (*set_env)(Channel *chan, ptrlen var, ptrlen value); - int (*send_break)(Channel *chan, unsigned length); - int (*send_signal)(Channel *chan, ptrlen signame); - int (*change_window_size)( + bool (*set_env)(Channel *chan, ptrlen var, ptrlen value); + bool (*send_break)(Channel *chan, unsigned length); + bool (*send_signal)(Channel *chan, ptrlen signame); + bool (*change_window_size)( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight); /* A method for signalling success/failure responses to channel * requests initiated from the SshChannel vtable with want_reply * true. */ - void (*request_response)(Channel *, int success); + void (*request_response)(Channel *, bool success); }; struct Channel { @@ -111,31 +111,31 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext); /* want_close for any channel that wants the default behaviour of not * closing until both directions have had an EOF */ -int chan_default_want_close(Channel *, int, int); +bool chan_default_want_close(Channel *, bool, bool); /* default implementations that refuse all the channel requests */ -int chan_no_exit_status(Channel *, int); -int chan_no_exit_signal(Channel *, ptrlen, int, ptrlen); -int chan_no_exit_signal_numeric(Channel *, int, int, ptrlen); -int chan_no_run_shell(Channel *chan); -int chan_no_run_command(Channel *chan, ptrlen command); -int chan_no_run_subsystem(Channel *chan, ptrlen subsys); -int chan_no_enable_x11_forwarding( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata, +bool chan_no_exit_status(Channel *, int); +bool chan_no_exit_signal(Channel *, ptrlen, bool, ptrlen); +bool chan_no_exit_signal_numeric(Channel *, int, bool, ptrlen); +bool chan_no_run_shell(Channel *chan); +bool chan_no_run_command(Channel *chan, ptrlen command); +bool chan_no_run_subsystem(Channel *chan, ptrlen subsys); +bool chan_no_enable_x11_forwarding( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata, unsigned screen_number); -int chan_no_enable_agent_forwarding(Channel *chan); -int chan_no_allocate_pty( +bool chan_no_enable_agent_forwarding(Channel *chan); +bool chan_no_allocate_pty( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes); -int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value); -int chan_no_send_break(Channel *chan, unsigned length); -int chan_no_send_signal(Channel *chan, ptrlen signame); -int chan_no_change_window_size( +bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value); +bool chan_no_send_break(Channel *chan, unsigned length); +bool chan_no_send_signal(Channel *chan, ptrlen signame); +bool chan_no_change_window_size( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight); /* default implementation that never expects to receive a response */ -void chan_no_request_response(Channel *, int); +void chan_no_request_response(Channel *, bool); /* * Constructor for a trivial do-nothing implementation of @@ -156,7 +156,7 @@ Channel *zombiechan_new(void); */ struct SshChannelVtable { - int (*write)(SshChannel *c, int is_stderr, const void *, int); + int (*write)(SshChannel *c, bool is_stderr, const void *, int); void (*write_eof)(SshChannel *c); void (*initiate_close)(SshChannel *c, const char *err); void (*unthrottle)(SshChannel *c, int bufsize); @@ -174,7 +174,7 @@ struct SshChannelVtable { * want_reply flag, which will cause a callback to * chan_request_response when the result is available. * - * The ones that return 'int' use it to indicate that the SSH + * The ones that return 'bool' use it to indicate that the SSH * protocol in use doesn't support this request at all. * * (It's also intentional that not all of them have a want_reply @@ -185,28 +185,28 @@ struct SshChannelVtable { */ void (*send_exit_status)(SshChannel *c, int status); void (*send_exit_signal)( - SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg); + SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg); void (*send_exit_signal_numeric)( - SshChannel *c, int signum, int core_dumped, ptrlen msg); + SshChannel *c, int signum, bool core_dumped, ptrlen msg); void (*request_x11_forwarding)( - SshChannel *c, int want_reply, const char *authproto, - const char *authdata, int screen_number, int oneshot); + SshChannel *c, bool want_reply, const char *authproto, + const char *authdata, int screen_number, bool oneshot); void (*request_agent_forwarding)( - SshChannel *c, int want_reply); + SshChannel *c, bool want_reply); void (*request_pty)( - SshChannel *c, int want_reply, Conf *conf, int w, int h); - int (*send_env_var)( - SshChannel *c, int want_reply, const char *var, const char *value); + SshChannel *c, bool want_reply, Conf *conf, int w, int h); + bool (*send_env_var)( + SshChannel *c, bool want_reply, const char *var, const char *value); void (*start_shell)( - SshChannel *c, int want_reply); + SshChannel *c, bool want_reply); void (*start_command)( - SshChannel *c, int want_reply, const char *command); - int (*start_subsystem)( - SshChannel *c, int want_reply, const char *subsystem); - int (*send_serial_break)( - SshChannel *c, int want_reply, int length); /* length=0 for default */ - int (*send_signal)( - SshChannel *c, int want_reply, const char *signame); + SshChannel *c, bool want_reply, const char *command); + bool (*start_subsystem)( + SshChannel *c, bool want_reply, const char *subsystem); + bool (*send_serial_break)( + SshChannel *c, bool want_reply, int length); /* length=0 for default */ + bool (*send_signal)( + SshChannel *c, bool want_reply, const char *signame); void (*send_terminal_size_change)( SshChannel *c, int w, int h); void (*hint_channel_is_simple)(SshChannel *c); @@ -265,7 +265,7 @@ struct SshChannel { mainchan *mainchan_new( PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf, - int term_width, int term_height, int is_simple, SshChannel **sc_out); + int term_width, int term_height, bool is_simple, SshChannel **sc_out); void mainchan_get_specials( mainchan *mc, add_special_fn_t add_special, void *ctx); void mainchan_special_cmd(mainchan *mc, SessionSpecialCode code, int arg); diff --git a/sshcommon.c b/sshcommon.c index 4f3622a7..563e4130 100644 --- a/sshcommon.c +++ b/sshcommon.c @@ -72,7 +72,7 @@ static IdempotentCallback ic_pktin_free = { }; static PktIn *pq_in_after(PacketQueueBase *pqb, - PacketQueueNode *prev, int pop) + PacketQueueNode *prev, bool pop) { PacketQueueNode *node = prev->next; if (node == &pqb->end) @@ -94,7 +94,7 @@ static PktIn *pq_in_after(PacketQueueBase *pqb, } static PktOut *pq_out_after(PacketQueueBase *pqb, - PacketQueueNode *prev, int pop) + PacketQueueNode *prev, bool pop) { PacketQueueNode *node = prev->next; if (node == &pqb->end) @@ -261,11 +261,11 @@ void ssh_free_pktout(PktOut *pkt) */ static void zombiechan_free(Channel *chan); -static int zombiechan_send(Channel *chan, int is_stderr, const void *, int); -static void zombiechan_set_input_wanted(Channel *chan, int wanted); +static int zombiechan_send(Channel *chan, bool is_stderr, const void *, int); +static void zombiechan_set_input_wanted(Channel *chan, bool wanted); static void zombiechan_do_nothing(Channel *chan); static void zombiechan_open_failure(Channel *chan, const char *); -static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof); +static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof); static char *zombiechan_log_close_msg(Channel *chan) { return NULL; } static const struct ChannelVtable zombiechan_channelvt = { @@ -317,19 +317,19 @@ static void zombiechan_open_failure(Channel *chan, const char *errtext) assert(chan->vt == &zombiechan_channelvt); } -static int zombiechan_send(Channel *chan, int is_stderr, +static int zombiechan_send(Channel *chan, bool is_stderr, const void *data, int length) { assert(chan->vt == &zombiechan_channelvt); return 0; } -static void zombiechan_set_input_wanted(Channel *chan, int enable) +static void zombiechan_set_input_wanted(Channel *chan, bool enable) { assert(chan->vt == &zombiechan_channelvt); } -static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof) +static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof) { return true; } @@ -349,8 +349,8 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext) assert(0 && "this channel type should never receive OPEN_FAILURE"); } -int chan_default_want_close( - Channel *chan, int sent_local_eof, int rcvd_remote_eof) +bool chan_default_want_close( + Channel *chan, bool sent_local_eof, bool rcvd_remote_eof) { /* * Default close policy: we start initiating the CHANNEL_CLOSE @@ -359,80 +359,80 @@ int chan_default_want_close( return sent_local_eof && rcvd_remote_eof; } -int chan_no_exit_status(Channel *chan, int status) +bool chan_no_exit_status(Channel *chan, int status) { return false; } -int chan_no_exit_signal( - Channel *chan, ptrlen signame, int core_dumped, ptrlen msg) +bool chan_no_exit_signal( + Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg) { return false; } -int chan_no_exit_signal_numeric( - Channel *chan, int signum, int core_dumped, ptrlen msg) +bool chan_no_exit_signal_numeric( + Channel *chan, int signum, bool core_dumped, ptrlen msg) { return false; } -int chan_no_run_shell(Channel *chan) +bool chan_no_run_shell(Channel *chan) { return false; } -int chan_no_run_command(Channel *chan, ptrlen command) +bool chan_no_run_command(Channel *chan, ptrlen command) { return false; } -int chan_no_run_subsystem(Channel *chan, ptrlen subsys) +bool chan_no_run_subsystem(Channel *chan, ptrlen subsys) { return false; } -int chan_no_enable_x11_forwarding( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata, +bool chan_no_enable_x11_forwarding( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata, unsigned screen_number) { return false; } -int chan_no_enable_agent_forwarding(Channel *chan) +bool chan_no_enable_agent_forwarding(Channel *chan) { return false; } -int chan_no_allocate_pty( +bool chan_no_allocate_pty( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes) { return false; } -int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) +bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) { return false; } -int chan_no_send_break(Channel *chan, unsigned length) +bool chan_no_send_break(Channel *chan, unsigned length) { return false; } -int chan_no_send_signal(Channel *chan, ptrlen signame) +bool chan_no_send_signal(Channel *chan, ptrlen signame) { return false; } -int chan_no_change_window_size( +bool chan_no_change_window_size( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight) { return false; } -void chan_no_request_response(Channel *chan, int success) +void chan_no_request_response(Channel *chan, bool success) { assert(0 && "this channel type should never send a want-reply request"); } @@ -687,12 +687,12 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset) * lists of protocol identifiers in SSH-2. */ -int first_in_commasep_string(char const *needle, char const *haystack, - int haylen) +bool first_in_commasep_string(char const *needle, char const *haystack, + int haylen) { int needlen; if (!needle || !haystack) /* protect against null pointers */ - return 0; + return false; needlen = strlen(needle); if (haylen >= needlen && /* haystack is long enough */ @@ -700,11 +700,11 @@ int first_in_commasep_string(char const *needle, char const *haystack, (haylen == needlen || haystack[needlen] == ',') /* either , or EOS follows */ ) - return 1; - return 0; + return true; + return false; } -int in_commasep_string(char const *needle, char const *haystack, int haylen) +bool in_commasep_string(char const *needle, char const *haystack, int haylen) { char *p; @@ -733,7 +733,7 @@ void add_to_commasep(strbuf *buf, const char *data) put_data(buf, data, strlen(data)); } -int get_commasep_word(ptrlen *list, ptrlen *word) +bool get_commasep_word(ptrlen *list, ptrlen *word) { const char *comma; @@ -905,7 +905,7 @@ void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp, (0 SSH2_MESSAGE_TYPES(BITMAP_UNIVERSAL, BITMAP_CONDITIONAL, \ BITMAP_CONDITIONAL, (32*y))) -int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin) +bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin) { static const unsigned valid_bitmap[] = { SSH2_BITMAP_WORD(0), @@ -992,7 +992,7 @@ int verify_ssh_manual_host_key( * Common functions shared between SSH-1 layers. */ -int ssh1_common_get_specials( +bool ssh1_common_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { /* @@ -1008,7 +1008,7 @@ int ssh1_common_get_specials( return false; } -int ssh1_common_filter_queue(PacketProtocolLayer *ppl) +bool ssh1_common_filter_queue(PacketProtocolLayer *ppl) { PktIn *pktin; ptrlen msg; diff --git a/sshcrcda.c b/sshcrcda.c index 2813ceed..ddc70ab8 100644 --- a/sshcrcda.c +++ b/sshcrcda.c @@ -75,7 +75,7 @@ static void crc_update(uint32_t *a, void *b) } /* detect if a block is used in a particular pattern */ -static int check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV) +static bool check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV) { uint32_t crc; uint8_t *c; @@ -98,7 +98,7 @@ static int check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV) } /* Detect a crc32 compensation attack on a packet */ -int detect_attack( +bool detect_attack( struct crcda_ctx *ctx, uint8_t *buf, uint32_t len, uint8_t *IV) { register uint32_t i, j; @@ -125,20 +125,20 @@ int detect_attack( for (c = buf; c < buf + len; c += SSH_BLOCKSIZE) { if (IV && (!CMP(c, IV))) { if ((check_crc(c, buf, len, IV))) - return 1; /* attack detected */ + return true; /* attack detected */ else break; } for (d = buf; d < c; d += SSH_BLOCKSIZE) { if (!CMP(c, d)) { if ((check_crc(c, buf, len, IV))) - return 1; /* attack detected */ + return true; /* attack detected */ else break; } } } - return 0; /* ok */ + return false; /* ok */ } memset(ctx->h, HASH_UNUSEDCHAR, ctx->n * HASH_ENTRYSIZE); @@ -151,18 +151,18 @@ int detect_attack( if (ctx->h[i] == HASH_IV) { if (!CMP(c, IV)) { if (check_crc(c, buf, len, IV)) - return 1; /* attack detected */ + return true; /* attack detected */ else break; } } else if (!CMP(c, buf + ctx->h[i] * SSH_BLOCKSIZE)) { if (check_crc(c, buf, len, IV)) - return 1; /* attack detected */ + return true; /* attack detected */ else break; } } ctx->h[i] = j; } - return 0; /* ok */ + return false; /* ok */ } diff --git a/sshdh.c b/sshdh.c index c18da320..84173e80 100644 --- a/sshdh.c +++ b/sshdh.c @@ -178,7 +178,7 @@ static void dh_init(struct dh_ctx *ctx) ctx->x = ctx->e = NULL; } -int dh_is_gex(const struct ssh_kex *kex) +bool dh_is_gex(const struct ssh_kex *kex) { const struct dh_extra *extra = (const struct dh_extra *)kex->extra; return extra->pdata == NULL; diff --git a/sshdss.c b/sshdss.c index 3aa462b8..1ed1a2ad 100644 --- a/sshdss.c +++ b/sshdss.c @@ -104,16 +104,16 @@ static char *dss_cache_str(ssh_key *key) return p; } -static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) +static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data) { struct dss_key *dss = container_of(key, struct dss_key, sshk); BinarySource src[1]; unsigned char hash[20]; Bignum r, s, w, gu1p, yu2p, gu1yu2p, u1, u2, sha, v; - int ret; + bool toret; if (!dss->p) - return 0; + return false; BinarySource_BARE_INIT(src, sig.ptr, sig.len); @@ -134,7 +134,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) if (get_err(src) || !ptrlen_eq_string(type, "ssh-dss") || sig.len != 40) - return 0; + return false; } /* Now we're sitting on a 40-byte string for sure. */ @@ -145,13 +145,13 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) freebn(r); if (s) freebn(s); - return 0; + return false; } if (!bignum_cmp(s, Zero)) { freebn(r); freebn(s); - return 0; + return false; } /* @@ -161,7 +161,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) if (!w) { freebn(r); freebn(s); - return 0; + return false; } /* @@ -188,7 +188,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) * Step 5. v should now be equal to r. */ - ret = !bignum_cmp(v, r); + toret = !bignum_cmp(v, r); freebn(w); freebn(sha); @@ -201,7 +201,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) freebn(r); freebn(s); - return ret; + return toret; } static void dss_public_blob(ssh_key *key, BinarySink *bs) diff --git a/sshecc.c b/sshecc.c index 13e432e2..947b64a9 100644 --- a/sshecc.c +++ b/sshecc.c @@ -64,7 +64,7 @@ static void initialise_wcurve(struct ec_curve *curve, int bits, curve->w.G.x = bignum_from_bytes(Gx, length); curve->w.G.y = bignum_from_bytes(Gy, length); curve->w.G.curve = curve; - curve->w.G.infinity = 0; + curve->w.G.infinity = false; } static void initialise_mcurve(struct ec_curve *curve, int bits, @@ -89,7 +89,7 @@ static void initialise_mcurve(struct ec_curve *curve, int bits, curve->m.G.y = NULL; curve->m.G.z = NULL; curve->m.G.curve = curve; - curve->m.G.infinity = 0; + curve->m.G.infinity = false; } static void initialise_ecurve(struct ec_curve *curve, int bits, @@ -113,13 +113,13 @@ static void initialise_ecurve(struct ec_curve *curve, int bits, curve->e.B.x = bignum_from_bytes(Bx, length); curve->e.B.y = bignum_from_bytes(By, length); curve->e.B.curve = curve; - curve->e.B.infinity = 0; + curve->e.B.infinity = false; } static struct ec_curve *ec_p256(void) { static struct ec_curve curve = { 0 }; - static unsigned char initialised = 0; + static bool initialised = false; if (!initialised) { @@ -164,7 +164,7 @@ static struct ec_curve *ec_p256(void) curve.textname = curve.name = "nistp256"; /* Now initialised, no need to do it again */ - initialised = 1; + initialised = true; } return &curve; @@ -173,7 +173,7 @@ static struct ec_curve *ec_p256(void) static struct ec_curve *ec_p384(void) { static struct ec_curve curve = { 0 }; - static unsigned char initialised = 0; + static bool initialised = false; if (!initialised) { @@ -230,7 +230,7 @@ static struct ec_curve *ec_p384(void) curve.textname = curve.name = "nistp384"; /* Now initialised, no need to do it again */ - initialised = 1; + initialised = true; } return &curve; @@ -239,7 +239,7 @@ static struct ec_curve *ec_p384(void) static struct ec_curve *ec_p521(void) { static struct ec_curve curve = { 0 }; - static unsigned char initialised = 0; + static bool initialised = false; if (!initialised) { @@ -314,7 +314,7 @@ static struct ec_curve *ec_p521(void) curve.textname = curve.name = "nistp521"; /* Now initialised, no need to do it again */ - initialised = 1; + initialised = true; } return &curve; @@ -323,7 +323,7 @@ static struct ec_curve *ec_p521(void) static struct ec_curve *ec_curve25519(void) { static struct ec_curve curve = { 0 }; - static unsigned char initialised = 0; + static bool initialised = false; if (!initialised) { @@ -359,7 +359,7 @@ static struct ec_curve *ec_curve25519(void) curve.textname = "Curve25519"; /* Now initialised, no need to do it again */ - initialised = 1; + initialised = true; } return &curve; @@ -368,7 +368,7 @@ static struct ec_curve *ec_curve25519(void) static struct ec_curve *ec_ed25519(void) { static struct ec_curve curve = { 0 }; - static unsigned char initialised = 0; + static bool initialised = false; if (!initialised) { @@ -411,7 +411,7 @@ static struct ec_curve *ec_ed25519(void) curve.textname = "Ed25519"; /* Now initialised, no need to do it again */ - initialised = 1; + initialised = true; } return &curve; @@ -419,13 +419,13 @@ static struct ec_curve *ec_ed25519(void) /* Return 1 if a is -3 % p, otherwise return 0 * This is used because there are some maths optimisations */ -static int ec_aminus3(const struct ec_curve *curve) +static bool ec_aminus3(const struct ec_curve *curve) { - int ret; + bool ret; Bignum _p; if (curve->type != EC_WEIERSTRASS) { - return 0; + return false; } _p = bignum_add_long(curve->w.a, 3); @@ -512,20 +512,20 @@ void ec_point_free(struct ec_point *point) if (point->x) freebn(point->x); if (point->y) freebn(point->y); if (point->z) freebn(point->z); - point->infinity = 0; + point->infinity = false; sfree(point); } static struct ec_point *ec_point_new(const struct ec_curve *curve, const Bignum x, const Bignum y, const Bignum z, - unsigned char infinity) + bool infinity) { struct ec_point *point = snewn(1, struct ec_point); point->curve = curve; point->x = x; point->y = y; point->z = z; - point->infinity = infinity ? 1 : 0; + point->infinity = infinity; return point; } @@ -539,14 +539,14 @@ static struct ec_point *ec_point_copy(const struct ec_point *a) a->infinity); } -static int ec_point_verify(const struct ec_point *a) +static bool ec_point_verify(const struct ec_point *a) { if (a->infinity) { - return 1; + return true; } else if (a->curve->type == EC_EDWARDS) { /* Check y^2 - x^2 - 1 - d * x^2 * y^2 == 0 */ Bignum y2, x2, tmp, tmp2, tmp3; - int ret; + bool ret; y2 = ecf_square(a->y, a->curve); x2 = ecf_square(a->x, a->curve); @@ -564,7 +564,7 @@ static int ec_point_verify(const struct ec_point *a) return ret; } else if (a->curve->type == EC_WEIERSTRASS) { /* Verify y^2 = x^3 + ax + b */ - int ret = 0; + bool ret = false; Bignum lhs = NULL, x3 = NULL, ax = NULL, x3ax = NULL, x3axm = NULL, x3axb = NULL, rhs = NULL; @@ -586,13 +586,13 @@ static int ec_point_verify(const struct ec_point *a) rhs = bigmod(x3axb, a->curve->p); freebn(x3axb); - ret = bignum_cmp(lhs, rhs) ? 0 : 1; + ret = !bignum_cmp(lhs, rhs); freebn(lhs); freebn(rhs); return ret; } else { - return 0; + return false; } } @@ -600,17 +600,17 @@ static int ec_point_verify(const struct ec_point *a) * Elliptic curve point maths */ -/* Returns 1 on success and 0 on memory error */ -static int ecp_normalise(struct ec_point *a) +/* Returns true on success and false on memory error */ +static bool ecp_normalise(struct ec_point *a) { if (!a) { /* No point */ - return 0; + return false; } if (a->infinity) { /* Point is at infinity - i.e. normalised */ - return 1; + return true; } if (a->curve->type == EC_WEIERSTRASS) { @@ -621,17 +621,17 @@ static int ecp_normalise(struct ec_point *a) if (!a->x || !a->y) { /* No point defined */ - return 0; + return false; } else if (!a->z) { /* Already normalised */ - return 1; + return true; } Z2 = ecf_square(a->z, a->curve); Z2inv = modinv(Z2, a->curve->p); if (!Z2inv) { freebn(Z2); - return 0; + return false; } tx = modmul(a->x, Z2inv, a->curve->p); freebn(Z2inv); @@ -642,7 +642,7 @@ static int ecp_normalise(struct ec_point *a) freebn(Z3); if (!Z3inv) { freebn(tx); - return 0; + return false; } ty = modmul(a->y, Z3inv, a->curve->p); freebn(Z3inv); @@ -653,7 +653,7 @@ static int ecp_normalise(struct ec_point *a) a->y = ty; freebn(a->z); a->z = NULL; - return 1; + return true; } else if (a->curve->type == EC_MONTGOMERY) { /* In Montgomery (X : Z) represents the x co-ord (X / Z, ?) */ @@ -661,15 +661,15 @@ static int ecp_normalise(struct ec_point *a) if (!a->x) { /* No point defined */ - return 0; + return false; } else if (!a->z) { /* Already normalised */ - return 1; + return true; } tmp = modinv(a->z, a->curve->p); if (!tmp) { - return 0; + return false; } tmp2 = modmul(a->x, tmp, a->curve->p); freebn(tmp); @@ -678,23 +678,23 @@ static int ecp_normalise(struct ec_point *a) a->z = NULL; freebn(a->x); a->x = tmp2; - return 1; + return true; } else if (a->curve->type == EC_EDWARDS) { /* Always normalised */ - return 1; + return true; } else { - return 0; + return false; } } -static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3) +static struct ec_point *ecp_doublew(const struct ec_point *a, bool aminus3) { Bignum S, M, outx, outy, outz; if (bignum_cmp(a->y, Zero) == 0) { /* Identity */ - return ec_point_new(a->curve, NULL, NULL, NULL, 1); + return ec_point_new(a->curve, NULL, NULL, NULL, true); } /* S = 4*X*Y^2 */ @@ -802,7 +802,7 @@ static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3) freebn(YZ); } - return ec_point_new(a->curve, outx, outy, outz, 0); + return ec_point_new(a->curve, outx, outy, outz, false); } static struct ec_point *ecp_doublem(const struct ec_point *a) @@ -865,20 +865,20 @@ static struct ec_point *ecp_doublem(const struct ec_point *a) freebn(tmp); } - return ec_point_new(a->curve, outx, NULL, outz, 0); + return ec_point_new(a->curve, outx, NULL, outz, false); } /* Forward declaration for Edwards curve doubling */ static struct ec_point *ecp_add(const struct ec_point *a, const struct ec_point *b, - const int aminus3); + bool aminus3); -static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3) +static struct ec_point *ecp_double(const struct ec_point *a, bool aminus3) { if (a->infinity) { /* Identity */ - return ec_point_new(a->curve, NULL, NULL, NULL, 1); + return ec_point_new(a->curve, NULL, NULL, NULL, true); } if (a->curve->type == EC_EDWARDS) @@ -897,7 +897,7 @@ static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3) static struct ec_point *ecp_addw(const struct ec_point *a, const struct ec_point *b, - const int aminus3) + bool aminus3) { Bignum U1, U2, S1, S2, outx, outy, outz; @@ -949,7 +949,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a, freebn(S1); freebn(S2); /* Infinity */ - return ec_point_new(a->curve, NULL, NULL, NULL, 1); + return ec_point_new(a->curve, NULL, NULL, NULL, true); } } @@ -1019,7 +1019,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a, } } - return ec_point_new(a->curve, outx, outy, outz, 0); + return ec_point_new(a->curve, outx, outy, outz, false); } static struct ec_point *ecp_addm(const struct ec_point *a, @@ -1070,7 +1070,7 @@ static struct ec_point *ecp_addm(const struct ec_point *a, freebn(tmp2); } - return ec_point_new(a->curve, outx, NULL, outz, 0); + return ec_point_new(a->curve, outx, NULL, outz, false); } static struct ec_point *ecp_adde(const struct ec_point *a, @@ -1135,12 +1135,12 @@ static struct ec_point *ecp_adde(const struct ec_point *a, freebn(tmp2); } - return ec_point_new(a->curve, outx, outy, NULL, 0); + return ec_point_new(a->curve, outx, outy, NULL, false); } static struct ec_point *ecp_add(const struct ec_point *a, const struct ec_point *b, - const int aminus3) + bool aminus3) { if (a->curve != b->curve) { return NULL; @@ -1163,13 +1163,14 @@ static struct ec_point *ecp_add(const struct ec_point *a, return NULL; } -static struct ec_point *ecp_mul_(const struct ec_point *a, const Bignum b, int aminus3) +static struct ec_point *ecp_mul_( + const struct ec_point *a, const Bignum b, bool aminus3) { struct ec_point *A, *ret; int bits, i; A = ec_point_copy(a); - ret = ec_point_new(a->curve, NULL, NULL, NULL, 1); + ret = ec_point_new(a->curve, NULL, NULL, NULL, true); bits = bignum_bitcount(b); for (i = 0; i < bits; ++i) @@ -1209,18 +1210,18 @@ static struct ec_point *ecp_mule(const struct ec_point *a, const Bignum b) int i; struct ec_point *ret; - ret = ec_point_new(a->curve, NULL, NULL, NULL, 1); + ret = ec_point_new(a->curve, NULL, NULL, NULL, true); for (i = bignum_bitcount(b); i >= 0 && ret; --i) { { - struct ec_point *tmp = ecp_double(ret, 0); + struct ec_point *tmp = ecp_double(ret, false); ec_point_free(ret); ret = tmp; } if (ret && bignum_bit(b, i)) { - struct ec_point *tmp = ecp_add(ret, a, 0); + struct ec_point *tmp = ecp_add(ret, a, false); ec_point_free(ret); ret = tmp; } @@ -1235,7 +1236,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n) int bits, i; /* P1 <- P and P2 <- [2]P */ - P2 = ecp_double(p, 0); + P2 = ecp_double(p, false); P1 = ec_point_copy(p); /* for i = bits − 2 down to 0 */ @@ -1250,7 +1251,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n) P2 = tmp; /* P1 <- [2]P1 */ - tmp = ecp_double(P1, 0); + tmp = ecp_double(P1, false); ec_point_free(P1); P1 = tmp; } @@ -1262,7 +1263,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n) P1 = tmp; /* P2 <- [2]P2 */ - tmp = ecp_double(P2, 0); + tmp = ecp_double(P2, false); ec_point_free(P2); P2 = tmp; } @@ -1294,7 +1295,7 @@ static struct ec_point *ecp_summul(const Bignum a, const Bignum b, const struct ec_point *point) { struct ec_point *aG, *bP, *ret; - int aminus3; + bool aminus3; if (point->curve->type != EC_WEIERSTRASS) { return NULL; @@ -1446,23 +1447,23 @@ struct ec_point *ec_public(const Bignum privateKey, const struct ec_curve *curve * Basic sign and verify routines */ -static int _ecdsa_verify(const struct ec_point *publicKey, - const unsigned char *data, const int dataLen, - const Bignum r, const Bignum s) +static bool _ecdsa_verify(const struct ec_point *publicKey, + const unsigned char *data, const int dataLen, + const Bignum r, const Bignum s) { int z_bits, n_bits; Bignum z; - int valid = 0; + bool valid = false; if (publicKey->curve->type != EC_WEIERSTRASS) { - return 0; + return false; } /* Sanity checks */ if (bignum_cmp(r, Zero) == 0 || bignum_cmp(r, publicKey->curve->w.n) >= 0 || bignum_cmp(s, Zero) == 0 || bignum_cmp(s, publicKey->curve->w.n) >= 0) { - return 0; + return false; } /* z = left most bitlen(curve->n) of data */ @@ -1491,7 +1492,7 @@ static int _ecdsa_verify(const struct ec_point *publicKey, w = modinv(s, publicKey->curve->w.n); if (!w) { freebn(z); - return 0; + return false; } u1 = modmul(z, w, publicKey->curve->w.n); u2 = modmul(r, w, publicKey->curve->w.n); @@ -1502,13 +1503,13 @@ static int _ecdsa_verify(const struct ec_point *publicKey, freebn(u2); if (!tmp) { freebn(z); - return 0; + return false; } x = bigmod(tmp->x, publicKey->curve->w.n); ec_point_free(tmp); - valid = (bignum_cmp(r, x) == 0) ? 1 : 0; + valid = (bignum_cmp(r, x) == 0); freebn(x); } @@ -1597,16 +1598,16 @@ static Bignum BinarySource_get_mp_le(BinarySource *src) } #define get_mp_le(src) BinarySource_get_mp_le(BinarySource_UPCAST(src)) -static int decodepoint_ed(const char *p, int length, struct ec_point *point) +static bool decodepoint_ed(const char *p, int length, struct ec_point *point) { /* Got some conversion to do, first read in the y co-ord */ - int negative; + bool negative; point->y = bignum_from_bytes_le((const unsigned char*)p, length); if ((unsigned)bignum_bitcount(point->y) > point->curve->fieldBits) { freebn(point->y); point->y = NULL; - return 0; + return false; } /* Read x bit and then reset it */ negative = bignum_bit(point->y, point->curve->fieldBits - 1); @@ -1618,7 +1619,7 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point) if (!point->x) { freebn(point->y); point->y = NULL; - return 0; + return false; } if (negative) { Bignum tmp = modsub(point->curve->p, point->x, point->curve->p); @@ -1632,20 +1633,20 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point) point->x = NULL; freebn(point->y); point->y = NULL; - return 0; + return false; } - return 1; + return true; } -static int decodepoint(const char *p, int length, struct ec_point *point) +static bool decodepoint(const char *p, int length, struct ec_point *point) { if (point->curve->type == EC_EDWARDS) { return decodepoint_ed(p, length, point); } if (length < 1 || p[0] != 0x04) /* Only support uncompressed point */ - return 0; + return false; /* Skip compression flag */ ++p; --length; @@ -1654,7 +1655,7 @@ static int decodepoint(const char *p, int length, struct ec_point *point) point->x = NULL; point->y = NULL; point->z = NULL; - return 0; + return false; } length = length / 2; point->x = bignum_from_bytes(p, length); @@ -1668,16 +1669,16 @@ static int decodepoint(const char *p, int length, struct ec_point *point) point->x = NULL; freebn(point->y); point->y = NULL; - return 0; + return false; } - return 1; + return true; } -static int BinarySource_get_point(BinarySource *src, struct ec_point *point) +static bool BinarySource_get_point(BinarySource *src, struct ec_point *point) { ptrlen str = get_string(src); - if (get_err(src)) return 0; + if (get_err(src)) return false; return decodepoint(str.ptr, str.len, point); } #define get_point(src, pt) BinarySource_get_point(BinarySource_UPCAST(src), pt) @@ -1737,7 +1738,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *self, ptrlen data) ec->sshk = self; ec->publicKey.curve = curve; - ec->publicKey.infinity = 0; + ec->publicKey.infinity = false; ec->publicKey.x = NULL; ec->publicKey.y = NULL; ec->publicKey.z = NULL; @@ -1925,7 +1926,7 @@ static ssh_key *ed25519_new_priv_openssh(const ssh_keyalg *self, ec->sshk = self; ec->publicKey.curve = ec_ed25519(); - ec->publicKey.infinity = 0; + ec->publicKey.infinity = false; ec->privateKey = NULL; ec->publicKey.x = NULL; ec->publicKey.z = NULL; @@ -2019,7 +2020,7 @@ static ssh_key *ecdsa_new_priv_openssh(const ssh_keyalg *self, ec->sshk = self; ec->publicKey.curve = curve; - ec->publicKey.infinity = 0; + ec->publicKey.infinity = false; ec->publicKey.x = NULL; ec->publicKey.y = NULL; ec->publicKey.z = NULL; @@ -2106,27 +2107,27 @@ static int ecdsa_pubkey_bits(const ssh_keyalg *self, ptrlen blob) return ret; } -static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) +static bool ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) { struct ec_key *ec = container_of(key, struct ec_key, sshk); const struct ecsign_extra *extra = (const struct ecsign_extra *)ec->sshk->extra; BinarySource src[1]; ptrlen sigstr; - int ret; + bool ret; if (!ec->publicKey.x || !ec->publicKey.y || !ec->publicKey.curve) - return 0; + return false; BinarySource_BARE_INIT(src, sig.ptr, sig.len); /* Check the signature starts with the algorithm name */ if (!ptrlen_eq_string(get_string(src), ec->sshk->ssh_id)) - return 0; + return false; sigstr = get_string(src); if (get_err(src)) - return 0; + return false; if (ec->publicKey.curve->type == EC_EDWARDS) { struct ec_point *r; @@ -2135,22 +2136,22 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) /* Check that the signature is two times the length of a point */ if (sigstr.len != pointlen * 2) { - return 0; + return false; } /* Check it's the 256 bit field so that SHA512 is the correct hash */ if (ec->publicKey.curve->fieldBits != 256) { - return 0; + return false; } /* Get the signature */ - r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, 0); + r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, false); if (!r) { - return 0; + return false; } if (!decodepoint(sigstr.ptr, pointlen, r)) { ec_point_free(r); - return 0; + return false; } s = bignum_from_bytes_le( (const char *)sigstr.ptr + pointlen, pointlen); @@ -2193,7 +2194,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) if (!lhs) { ec_point_free(r); freebn(h); - return 0; + return false; } /* rhs = r + h*publicKey */ @@ -2202,14 +2203,14 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) if (!tmp) { ec_point_free(lhs); ec_point_free(r); - return 0; + return false; } - rhs = ecp_add(r, tmp, 0); + rhs = ecp_add(r, tmp, false); ec_point_free(r); ec_point_free(tmp); if (!rhs) { ec_point_free(lhs); - return 0; + return false; } /* Check the point is the same */ @@ -2217,7 +2218,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) if (ret) { ret = !bignum_cmp(lhs->y, rhs->y); if (ret) { - ret = 1; + ret = true; } } ec_point_free(lhs); @@ -2236,7 +2237,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) if (get_err(src)) { freebn(r); freebn(s); - return 0; + return false; } digestLen = extra->hash->hlen; @@ -2643,7 +2644,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec, if (ec->publicKey.curve->type == EC_WEIERSTRASS) { remote.curve = ec->publicKey.curve; - remote.infinity = 0; + remote.infinity = false; if (!decodepoint(remoteKey, remoteKeyLen, &remote)) { return NULL; } @@ -2654,7 +2655,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec, } remote.curve = ec->publicKey.curve; - remote.infinity = 0; + remote.infinity = false; remote.x = bignum_from_bytes_le((const unsigned char *)remoteKey, remoteKeyLen); remote.y = NULL; @@ -2746,9 +2747,8 @@ const unsigned char *ec_alg_oid(const ssh_keyalg *alg, const int ec_nist_curve_lengths[] = { 256, 384, 521 }; const int n_ec_nist_curve_lengths = lenof(ec_nist_curve_lengths); -int ec_nist_alg_and_curve_by_bits(int bits, - const struct ec_curve **curve, - const ssh_keyalg **alg) +bool ec_nist_alg_and_curve_by_bits( + int bits, const struct ec_curve **curve, const ssh_keyalg **alg) { switch (bits) { case 256: *alg = &ssh_ecdsa_nistp256; break; @@ -2760,9 +2760,8 @@ int ec_nist_alg_and_curve_by_bits(int bits, return true; } -int ec_ed_alg_and_curve_by_bits(int bits, - const struct ec_curve **curve, - const ssh_keyalg **alg) +bool ec_ed_alg_and_curve_by_bits( + int bits, const struct ec_curve **curve, const ssh_keyalg **alg) { switch (bits) { case 256: *alg = &ssh_ecdsa_ed25519; break; diff --git a/sshmac.c b/sshmac.c index e3b74b38..3d597418 100644 --- a/sshmac.c +++ b/sshmac.c @@ -7,10 +7,10 @@ #include "ssh.h" -int ssh2_mac_verresult(ssh2_mac *mac, const void *candidate) +bool ssh2_mac_verresult(ssh2_mac *mac, const void *candidate) { unsigned char correct[64]; /* at least as big as all known MACs */ - int toret; + bool toret; assert(mac->vt->len <= sizeof(correct)); ssh2_mac_genresult(mac, correct); @@ -35,7 +35,8 @@ void ssh2_mac_generate(ssh2_mac *mac, void *blk, int len, unsigned long seq) return ssh2_mac_genresult(mac, (unsigned char *)blk + len); } -int ssh2_mac_verify(ssh2_mac *mac, const void *blk, int len, unsigned long seq) +bool ssh2_mac_verify( + ssh2_mac *mac, const void *blk, int len, unsigned long seq) { ssh2_mac_prepare(mac, blk, len, seq); return ssh2_mac_verresult(mac, (const unsigned char *)blk + len); diff --git a/sshppl.h b/sshppl.h index a44ba02c..5069f871 100644 --- a/sshppl.h +++ b/sshppl.h @@ -12,11 +12,11 @@ typedef void (*packet_handler_fn_t)(PacketProtocolLayer *ppl, PktIn *pktin); struct PacketProtocolLayerVtable { void (*free)(PacketProtocolLayer *); void (*process_queue)(PacketProtocolLayer *ppl); - int (*get_specials)( + bool (*get_specials)( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); void (*special_cmd)( PacketProtocolLayer *ppl, SessionSpecialCode code, int arg); - int (*want_user_input)(PacketProtocolLayer *ppl); + bool (*want_user_input)(PacketProtocolLayer *ppl); void (*got_user_input)(PacketProtocolLayer *ppl); void (*reconfigure)(PacketProtocolLayer *ppl, Conf *conf); @@ -97,17 +97,17 @@ PacketProtocolLayer *ssh2_transport_new( const char *client_greeting, const char *server_greeting, struct ssh_connection_shared_gss_state *shgss, struct DataTransferStats *stats, PacketProtocolLayer *higher_layer, - int is_server); + bool is_server); PacketProtocolLayer *ssh2_userauth_new( PacketProtocolLayer *successor_layer, const char *hostname, const char *fullhostname, - Filename *keyfile, int tryagent, - const char *default_username, int change_username, - int try_ki_auth, - int try_gssapi_auth, int try_gssapi_kex_auth, - int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss); + Filename *keyfile, bool tryagent, + const char *default_username, bool change_username, + bool try_ki_auth, + bool try_gssapi_auth, bool try_gssapi_kex_auth, + bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss); PacketProtocolLayer *ssh2_connection_new( - Ssh *ssh, ssh_sharing_state *connshare, int is_simple, + Ssh *ssh, ssh_sharing_state *connshare, bool is_simple, Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out); /* Can't put this in the userauth constructor without having a @@ -139,10 +139,10 @@ void ssh1_connection_set_protoflags( PacketProtocolLayer *ppl, int local, int remote); /* Shared get_specials method between the two ssh1 layers */ -int ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *); +bool ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *); /* Other shared functions between ssh1 layers */ -int ssh1_common_filter_queue(PacketProtocolLayer *ppl); +bool ssh1_common_filter_queue(PacketProtocolLayer *ppl); void ssh1_compute_session_id( unsigned char *session_id, const unsigned char *cookie, struct RSAKey *hostkey, struct RSAKey *servkey); diff --git a/sshpubk.c b/sshpubk.c index a0d73c78..5072ff63 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -23,7 +23,7 @@ static int key_type_fp(FILE *fp); -static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, int pub_only, +static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, bool pub_only, char **commentptr, const char *passphrase, const char **error) { @@ -184,14 +184,14 @@ int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key, * See whether an RSA key is encrypted. Return its comment field as * well. */ -int rsa_ssh1_encrypted(const Filename *filename, char **comment) +bool rsa_ssh1_encrypted(const Filename *filename, char **comment) { FILE *fp; char buf[64]; fp = f_open(filename, "rb", false); if (!fp) - return 0; /* doesn't even exist */ + return false; /* doesn't even exist */ /* * Read the first line of the file and see if it's a v1 private @@ -202,10 +202,10 @@ int rsa_ssh1_encrypted(const Filename *filename, char **comment) /* * This routine will take care of calling fclose() for us. */ - return rsa_ssh1_load_main(fp, NULL, false, comment, NULL, &dummy); + return rsa_ssh1_load_main(fp, NULL, false, comment, NULL, &dummy) == 1; } fclose(fp); - return 0; /* wasn't the right kind of file */ + return false; /* wasn't the right kind of file */ } /* @@ -222,7 +222,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs, const char *error = NULL; /* Default return if we fail. */ - ret = false; + ret = 0; fp = f_open(filename, "rb", false); if (!fp) { @@ -239,7 +239,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs, if (rsa_ssh1_load_main(fp, &key, true, commentptr, NULL, &error)) { rsa_ssh1_public_blob(bs, &key, RSA_SSH1_EXPONENT_FIRST); freersakey(&key); - ret = true; + ret = 1; } fp = NULL; /* rsa_ssh1_load_main unconditionally closes fp */ } else { @@ -291,7 +291,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs, freersakey(&key); sfree(line); fclose(fp); - return true; + return 1; not_public_either: sfree(line); @@ -307,10 +307,10 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs, } /* - * Save an RSA key file. Return nonzero on success. + * Save an RSA key file. Return true on success. */ -int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, - char *passphrase) +bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, + char *passphrase) { strbuf *buf = strbuf_new(); int estart; @@ -377,12 +377,12 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, */ fp = f_open(filename, "wb", true); if (fp) { - int ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len)); + bool ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len)); if (fclose(fp)) - ret = 0; + ret = false; return ret; } else - return 0; + return false; } /* ---------------------------------------------------------------------- @@ -468,7 +468,7 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key, * an HMAC (this was generated for unencrypted keys). */ -static int read_header(FILE * fp, char *header) +static bool read_header(FILE * fp, char *header) { int len = 39; int c; @@ -476,20 +476,20 @@ static int read_header(FILE * fp, char *header) while (1) { c = fgetc(fp); if (c == '\n' || c == '\r' || c == EOF) - return 0; /* failure */ + return false; /* failure */ if (c == ':') { c = fgetc(fp); if (c != ' ') - return 0; + return false; *header = '\0'; - return 1; /* success! */ + return true; /* success! */ } if (len == 0) - return 0; /* failure */ + return false; /* failure */ *header++ = c; len--; } - return 0; /* failure */ + return false; /* failure */ } static char *read_body(FILE * fp) @@ -523,7 +523,7 @@ static char *read_body(FILE * fp) } } -static int read_blob(FILE *fp, int nlines, BinarySink *bs) +static bool read_blob(FILE *fp, int nlines, BinarySink *bs) { unsigned char *blob; char *line; @@ -597,7 +597,8 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, struct ssh2_userkey *ret; int cipher, cipherblk; strbuf *public_blob, *private_blob; - int i, is_mac, old_fmt; + int i; + bool is_mac, old_fmt; int passlen = passphrase ? strlen(passphrase) : 0; const char *error = NULL; @@ -617,11 +618,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, goto error; } if (0 == strcmp(header, "PuTTY-User-Key-File-2")) { - old_fmt = 0; + old_fmt = false; } else if (0 == strcmp(header, "PuTTY-User-Key-File-1")) { /* this is an old key file; warn and then continue */ old_keyfile_warning(); - old_fmt = 1; + old_fmt = true; } else if (0 == strncmp(header, "PuTTY-User-Key-File-", 20)) { /* this is a key file FROM THE FUTURE; refuse it, but with a * more specific error message than the generic one below */ @@ -691,11 +692,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, if (0 == strcmp(header, "Private-MAC")) { if ((mac = read_body(fp)) == NULL) goto error; - is_mac = 1; + is_mac = true; } else if (0 == strcmp(header, "Private-Hash") && old_fmt) { if ((mac = read_body(fp)) == NULL) goto error; - is_mac = 0; + is_mac = false; } else goto error; @@ -732,7 +733,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, char realmac[41]; unsigned char binary[20]; strbuf *macdata; - int free_macdata; + bool free_macdata; if (old_fmt) { /* MAC (or hash) only covers the private blob. */ @@ -834,9 +835,9 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, return ret; } -int rfc4716_loadpub(FILE *fp, char **algorithm, - BinarySink *bs, - char **commentptr, const char **errorstr) +bool rfc4716_loadpub(FILE *fp, char **algorithm, + BinarySink *bs, + char **commentptr, const char **errorstr) { const char *error; char *line, *colon, *value; @@ -968,9 +969,9 @@ int rfc4716_loadpub(FILE *fp, char **algorithm, return false; } -int openssh_loadpub(FILE *fp, char **algorithm, - BinarySink *bs, - char **commentptr, const char **errorstr) +bool openssh_loadpub(FILE *fp, char **algorithm, + BinarySink *bs, + char **commentptr, const char **errorstr) { const char *error; char *line, *base64; @@ -1044,9 +1045,9 @@ int openssh_loadpub(FILE *fp, char **algorithm, return false; } -int ssh2_userkey_loadpub(const Filename *filename, char **algorithm, - BinarySink *bs, - char **commentptr, const char **errorstr) +bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm, + BinarySink *bs, + char **commentptr, const char **errorstr) { FILE *fp; char header[40], *b; @@ -1065,11 +1066,11 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm, * we'll be asked to read a public blob from one of those. */ type = key_type_fp(fp); if (type == SSH_KEYTYPE_SSH2_PUBLIC_RFC4716) { - int ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr); + bool ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr); fclose(fp); return ret; } else if (type == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH) { - int ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr); + bool ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr); fclose(fp); return ret; } else if (type != SSH_KEYTYPE_SSH2) { @@ -1145,49 +1146,49 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm, return false; } -int ssh2_userkey_encrypted(const Filename *filename, char **commentptr) +bool ssh2_userkey_encrypted(const Filename *filename, char **commentptr) { FILE *fp; char header[40], *b, *comment; - int ret; + bool ret; if (commentptr) *commentptr = NULL; fp = f_open(filename, "rb", false); if (!fp) - return 0; + return false; if (!read_header(fp, header) || (0 != strcmp(header, "PuTTY-User-Key-File-2") && 0 != strcmp(header, "PuTTY-User-Key-File-1"))) { fclose(fp); - return 0; + return false; } if ((b = read_body(fp)) == NULL) { fclose(fp); - return 0; + return false; } sfree(b); /* we don't care about key type here */ /* Read the Encryption header line. */ if (!read_header(fp, header) || 0 != strcmp(header, "Encryption")) { fclose(fp); - return 0; + return false; } if ((b = read_body(fp)) == NULL) { fclose(fp); - return 0; + return false; } /* Read the Comment header line. */ if (!read_header(fp, header) || 0 != strcmp(header, "Comment")) { fclose(fp); sfree(b); - return 1; + return true; } if ((comment = read_body(fp)) == NULL) { fclose(fp); sfree(b); - return 1; + return true; } if (commentptr) @@ -1197,9 +1198,9 @@ int ssh2_userkey_encrypted(const Filename *filename, char **commentptr) fclose(fp); if (!strcmp(b, "aes256-cbc")) - ret = 1; + ret = true; else - ret = 0; + ret = false; sfree(b); return ret; } @@ -1233,8 +1234,8 @@ void base64_encode(FILE *fp, const unsigned char *data, int datalen, int cpl) fputc('\n', fp); } -int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, - char *passphrase) +bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, + char *passphrase) { FILE *fp; strbuf *pub_blob, *priv_blob; @@ -1329,7 +1330,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, strbuf_free(priv_blob); smemclr(priv_blob_encrypted, priv_encrypted_len); sfree(priv_blob_encrypted); - return 0; + return false; } fprintf(fp, "PuTTY-User-Key-File-2: %s\n", ssh_key_ssh_id(key->key)); fprintf(fp, "Encryption: %s\n", cipherstr); @@ -1348,7 +1349,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key, strbuf_free(priv_blob); smemclr(priv_blob_encrypted, priv_encrypted_len); sfree(priv_blob_encrypted); - return 1; + return true; } /* ---------------------------------------------------------------------- diff --git a/sshrand.c b/sshrand.c index d0448703..63211693 100644 --- a/sshrand.c +++ b/sshrand.c @@ -42,7 +42,7 @@ struct RandPool { unsigned char incomingb[HASHINPUT]; int incomingpos; - int stir_pending; + bool stir_pending; }; int random_active = 0; diff --git a/sshrsa.c b/sshrsa.c index c033bb94..2d508777 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -42,14 +42,14 @@ void BinarySource_get_rsa_ssh1_priv( rsa->private_exponent = get_mp_ssh1(src); } -int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key) +bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key) { Bignum b1, b2; int i; unsigned char *p; if (key->bytes < length + 4) - return 0; /* RSA key too short! */ + return false; /* RSA key too short! */ memmove(data + key->bytes - length, data, length); data[0] = 0; @@ -74,7 +74,7 @@ int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key) freebn(b1); freebn(b2); - return 1; + return true; } /* @@ -285,10 +285,10 @@ Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key) return rsa_privkey_op(input, key); } -int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf) +bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf) { strbuf *data = strbuf_new(); - int success = false; + bool success = false; BinarySource src[1]; { @@ -391,7 +391,7 @@ char *rsa_ssh1_fingerprint(struct RSAKey *key) * data. We also check the private data itself: we ensure that p > * q and that iqmp really is the inverse of q mod p. */ -int rsa_verify(struct RSAKey *key) +bool rsa_verify(struct RSAKey *key) { Bignum n, ed, pm1, qm1; int cmp; @@ -401,7 +401,7 @@ int rsa_verify(struct RSAKey *key) cmp = bignum_cmp(n, key->modulus); freebn(n); if (cmp != 0) - return 0; + return false; /* e * d must be congruent to 1, modulo (p-1) and modulo (q-1). */ pm1 = copybn(key->p); @@ -411,7 +411,7 @@ int rsa_verify(struct RSAKey *key) cmp = bignum_cmp(ed, One); freebn(ed); if (cmp != 0) - return 0; + return false; qm1 = copybn(key->q); decbn(qm1); @@ -420,7 +420,7 @@ int rsa_verify(struct RSAKey *key) cmp = bignum_cmp(ed, One); freebn(ed); if (cmp != 0) - return 0; + return false; /* * Ensure p > q. @@ -438,7 +438,7 @@ int rsa_verify(struct RSAKey *key) freebn(key->iqmp); key->iqmp = modinv(key->q, key->p); if (!key->iqmp) - return 0; + return false; } /* @@ -448,9 +448,9 @@ int rsa_verify(struct RSAKey *key) cmp = bignum_cmp(n, One); freebn(n); if (cmp != 0) - return 0; + return false; - return 1; + return true; } void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key, @@ -683,13 +683,14 @@ static const unsigned char asn1_weird_stuff[] = { #define ASN1_LEN ( (int) sizeof(asn1_weird_stuff) ) -static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data) +static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data) { struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); BinarySource src[1]; ptrlen type, in_pl; Bignum in, out; - int bytes, i, j, ret; + int bytes, i, j; + bool toret; unsigned char hash[20]; BinarySource_BARE_INIT(src, sig.ptr, sig.len); @@ -706,40 +707,40 @@ static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data) */ in_pl = get_string(src); if (get_err(src) || !ptrlen_eq_string(type, "ssh-rsa")) - return 0; + return false; in = bignum_from_bytes(in_pl.ptr, in_pl.len); out = modpow(in, rsa->exponent, rsa->modulus); freebn(in); - ret = 1; + toret = true; bytes = (bignum_bitcount(rsa->modulus)+7) / 8; /* Top (partial) byte should be zero. */ if (bignum_byte(out, bytes - 1) != 0) - ret = 0; + toret = false; /* First whole byte should be 1. */ if (bignum_byte(out, bytes - 2) != 1) - ret = 0; + toret = false; /* Most of the rest should be FF. */ for (i = bytes - 3; i >= 20 + ASN1_LEN; i--) { if (bignum_byte(out, i) != 0xFF) - ret = 0; + toret = false; } /* Then we expect to see the asn1_weird_stuff. */ for (i = 20 + ASN1_LEN - 1, j = 0; i >= 20; i--, j++) { if (bignum_byte(out, i) != asn1_weird_stuff[j]) - ret = 0; + toret = false; } /* Finally, we expect to see the SHA-1 hash of the signed data. */ SHA_Simple(data.ptr, data.len, hash); for (i = 19, j = 0; i >= 0; i--, j++) { if (bignum_byte(out, i) != hash[j]) - ret = 0; + toret = false; } freebn(out); - return ret; + return toret; } static void rsa2_sign(ssh_key *key, const void *data, int datalen, diff --git a/sshserver.c b/sshserver.c index a97dc86d..b43432dc 100644 --- a/sshserver.c +++ b/sshserver.c @@ -33,7 +33,7 @@ struct server { Socket *socket; Plug plug; int conn_throttle_count; - int frozen; + bool frozen; Conf *conf; ssh_key *const *hostkeys; @@ -74,7 +74,7 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan, int protomajor, int protominor, const void *initial_data, int initial_len) {} Channel *agentf_new(SshChannel *c) { return NULL; } -int agent_exists(void) { return false; } +bool agent_exists(void) { return false; } void ssh_got_exitcode(Ssh *ssh, int exitcode) {} mainchan *mainchan_new( @@ -122,7 +122,7 @@ static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port, } static void server_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { server *srv = container_of(plug, server, plug); if (error_msg) { @@ -175,7 +175,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust) { server *srv = container_of(ssh, server, ssh); int old_count = srv->conn_throttle_count; - int frozen; + bool frozen; srv->conn_throttle_count += adjust; assert(srv->conn_throttle_count >= 0); diff --git a/sshserver.h b/sshserver.h index 348004ed..2dc43d95 100644 --- a/sshserver.h +++ b/sshserver.h @@ -33,18 +33,18 @@ struct AuthKbdInt { }; struct AuthKbdIntPrompt { char *prompt; /* needs freeing */ - int echo; + bool echo; }; unsigned auth_methods(AuthPolicy *); -int auth_none(AuthPolicy *, ptrlen username); +bool auth_none(AuthPolicy *, ptrlen username); int auth_password(AuthPolicy *, ptrlen username, ptrlen password, ptrlen *opt_new_password); /* auth_password returns 1 for 'accepted', 0 for 'rejected', and 2 for * 'ok but now you need to change your password' */ -int auth_publickey(AuthPolicy *, ptrlen username, ptrlen public_blob); +bool auth_publickey(AuthPolicy *, ptrlen username, ptrlen public_blob); /* auth_publickey_ssh1 must return the whole public key given the modulus, * because the SSH-1 client never transmits the exponent over the wire. * The key remains owned by the AuthPolicy. */ @@ -59,12 +59,12 @@ int auth_kbdint_responses(AuthPolicy *, const ptrlen *responses); /* The very similar SSH-1 TIS and CryptoCard methods are combined into * a single API for AuthPolicy, which takes a method argument */ char *auth_ssh1int_challenge(AuthPolicy *, unsigned method, ptrlen username); -int auth_ssh1int_response(AuthPolicy *, ptrlen response); +bool auth_ssh1int_response(AuthPolicy *, ptrlen response); struct RSAKey *auth_publickey_ssh1( AuthPolicy *ap, ptrlen username, Bignum rsa_modulus); /* auth_successful returns false if further authentication is needed */ -int auth_successful(AuthPolicy *, ptrlen username, unsigned method); +bool auth_successful(AuthPolicy *, ptrlen username, unsigned method); PacketProtocolLayer *ssh2_userauth_server_new( PacketProtocolLayer *successor_layer, AuthPolicy *authpolicy); @@ -83,7 +83,7 @@ Channel *sesschan_new(SshChannel *c, LogContext *logctx, Backend *pty_backend_create( Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd, - struct ssh_ttymodes ttymodes, int pipes_instead_of_pty); + struct ssh_ttymodes ttymodes, bool pipes_instead_of_pty); ptrlen pty_backend_exit_signame(Backend *be, char **aux_msg); /* diff --git a/sshsha.c b/sshsha.c index 4e832e50..66d9aca5 100644 --- a/sshsha.c +++ b/sshsha.c @@ -436,12 +436,12 @@ const struct ssh2_macalg ssh_hmac_sha1_96_buggy = { #if defined(__clang__) || defined(__GNUC__) #include -int supports_sha_ni(void) +bool supports_sha_ni(void) { unsigned int CPUInfo[4]; __cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); if (CPUInfo[0] < 7) - return 0; + return false; __cpuid_count(7, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); return CPUInfo[1] & (1 << 29); /* SHA */ @@ -449,12 +449,12 @@ int supports_sha_ni(void) #else /* defined(__clang__) || defined(__GNUC__) */ -int supports_sha_ni(void) +bool supports_sha_ni(void) { unsigned int CPUInfo[4]; __cpuid(CPUInfo, 0); if (CPUInfo[0] < 7) - return 0; + return false; __cpuidex(CPUInfo, 7, 0); return CPUInfo[1] & (1 << 29); /* Check SHA */ @@ -686,9 +686,9 @@ static void sha1_ni(SHA_State * s, const unsigned char *q, int len) assert(0); } -int supports_sha_ni(void) +bool supports_sha_ni(void) { - return 0; + return false; } #endif /* COMPILER_SUPPORTS_AES_NI */ diff --git a/sshshare.c b/sshshare.c index dd44a5c3..48a0ca36 100644 --- a/sshshare.c +++ b/sshshare.c @@ -160,7 +160,8 @@ struct ssh_sharing_connstate { int crLine; /* coroutine state for share_receive */ - int sent_verstring, got_verstring, curr_packetlen; + bool sent_verstring, got_verstring; + int curr_packetlen; unsigned char recvbuf[0x4010]; int recvlen; @@ -235,13 +236,13 @@ struct share_channel { int x11_auth_proto; char *x11_auth_data; int x11_auth_datalen; - int x11_one_shot; + bool x11_one_shot; }; struct share_forwarding { char *host; int port; - int active; /* has the server sent REQUEST_SUCCESS? */ + bool active; /* has the server sent REQUEST_SUCCESS? */ struct ssh_rportfwd *rpf; }; @@ -263,7 +264,7 @@ struct share_xchannel { * channel messages from the server until such time as the server * sends us CHANNEL_CLOSE. */ - int live; + bool live; /* * When we receive OPEN_CONFIRMATION, we will need to send a @@ -291,7 +292,7 @@ enum { struct share_globreq { struct share_globreq *next; int type; - int want_reply; + bool want_reply; struct share_forwarding *fwd; }; @@ -571,7 +572,7 @@ static struct share_channel *share_add_channel chan->x11_auth_data = NULL; chan->x11_auth_proto = -1; chan->x11_auth_datalen = 0; - chan->x11_one_shot = 0; + chan->x11_one_shot = false; if (add234(cs->channels_by_us, chan) != chan) { sfree(chan); return NULL; @@ -936,7 +937,7 @@ static void share_disconnect(struct ssh_sharing_connstate *cs, } static void share_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { struct ssh_sharing_connstate *cs = container_of( plug, struct ssh_sharing_connstate, plug); @@ -997,7 +998,7 @@ void share_dead_xchannel_respond(struct ssh_sharing_connstate *cs, * Handle queued incoming messages from the server destined for an * xchannel which is dead (i.e. downstream sent OPEN_FAILURE). */ - int delete = false; + bool delete = false; while (xc->msghead) { struct share_xchannel_message *msg = xc->msghead; xc->msghead = msg->next; @@ -1157,7 +1158,7 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan, sfree(chan->x11_auth_data); chan->x11_auth_proto = -1; chan->x11_auth_datalen = 0; - chan->x11_one_shot = 0; + chan->x11_one_shot = false; } } @@ -1312,7 +1313,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs, char *err = NULL; BinarySource src[1]; size_t wantreplypos; - int orig_wantreply; + bool orig_wantreply; BinarySource_BARE_INIT(src, pkt, pktlen); @@ -1635,7 +1636,8 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs, * a downstream, and if the latter, which one. */ if (ptrlen_eq_string(request_name, "x11-req")) { - int want_reply, single_connection, screen; + bool want_reply, single_connection; + int screen; ptrlen auth_data; int auth_proto; @@ -1844,7 +1846,7 @@ static void share_sent(Plug *plug, int bufsize) } static void share_listen_closing(Plug *plug, const char *error_msg, - int error_code, int calling_back) + int error_code, bool calling_back) { ssh_sharing_state *sharestate = container_of(plug, ssh_sharing_state, plug); @@ -1968,8 +1970,8 @@ static int share_listen_accepting(Plug *plug, /* Per-application overrides for what roles we can take (e.g. pscp * will never be an upstream) */ -extern const int share_can_be_downstream; -extern const int share_can_be_upstream; +extern const bool share_can_be_downstream; +extern const bool share_can_be_upstream; /* * Decide on the string used to identify the connection point between @@ -2015,7 +2017,7 @@ char *ssh_share_sockname(const char *host, int port, Conf *conf) return sockname; } -int ssh_share_test_for_upstream(const char *host, int port, Conf *conf) +bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf) { char *sockname, *logtext, *ds_err, *us_err; int result; @@ -2071,7 +2073,8 @@ Socket *ssh_connection_sharing_init( const char *host, int port, Conf *conf, LogContext *logctx, Plug *sshplug, ssh_sharing_state **state) { - int result, can_upstream, can_downstream; + int result; + bool can_upstream, can_downstream; char *logtext, *ds_err, *us_err; char *sockname; Socket *sock, *toret = NULL; diff --git a/sshverstring.c b/sshverstring.c index 578ee99f..529b5964 100644 --- a/sshverstring.c +++ b/sshverstring.c @@ -21,9 +21,9 @@ struct ssh_verstring_state { char *our_protoversion; struct ssh_version_receiver *receiver; - int send_early; + bool send_early; - int found_prefix; + bool found_prefix; int major_protoversion; int remote_bugs; char prefix[PREFIX_MAXLEN]; @@ -55,13 +55,13 @@ static const struct BinaryPacketProtocolVtable ssh_verstring_vtable = { }; static void ssh_detect_bugs(struct ssh_verstring_state *s); -static int ssh_version_includes_v1(const char *ver); -static int ssh_version_includes_v2(const char *ver); +static bool ssh_version_includes_v1(const char *ver); +static bool ssh_version_includes_v2(const char *ver); BinaryPacketProtocol *ssh_verstring_new( - Conf *conf, LogContext *logctx, int bare_connection_mode, + Conf *conf, LogContext *logctx, bool bare_connection_mode, const char *protoversion, struct ssh_version_receiver *rcv, - int server_mode, const char *impl_name) + bool server_mode, const char *impl_name) { struct ssh_verstring_state *s = snew(struct ssh_verstring_state); @@ -141,12 +141,12 @@ static int ssh_versioncmp(const char *a, const char *b) return 0; } -static int ssh_version_includes_v1(const char *ver) +static bool ssh_version_includes_v1(const char *ver) { return ssh_versioncmp(ver, "2.0") < 0; } -static int ssh_version_includes_v2(const char *ver) +static bool ssh_version_includes_v2(const char *ver) { return ssh_versioncmp(ver, "1.99") >= 0; } diff --git a/sshzlib.c b/sshzlib.c index ae3e28d2..8171ee11 100644 --- a/sshzlib.c +++ b/sshzlib.c @@ -94,7 +94,7 @@ static int lz77_init(struct LZ77Context *ctx); * instead call literal() for everything. */ static void lz77_compress(struct LZ77Context *ctx, - unsigned char *data, int len, int compress); + unsigned char *data, int len, bool compress); /* * Modifiable parameters. @@ -199,7 +199,7 @@ static void lz77_advance(struct LZ77InternalContext *st, #define CHARAT(k) ( (k)<0 ? st->data[(st->winpos+k)&(WINSIZE-1)] : data[k] ) static void lz77_compress(struct LZ77Context *ctx, - unsigned char *data, int len, int compress) + unsigned char *data, int len, bool compress) { struct LZ77InternalContext *st = ctx->ictx; int i, distance, off, nmatch, matchlen, advance; @@ -370,7 +370,7 @@ struct Outbuf { int outlen, outsize; unsigned long outbits; int noutbits; - int firstblock; + bool firstblock; }; static void outbits(struct Outbuf *out, unsigned long bits, int nbits) @@ -614,7 +614,7 @@ ssh_compressor *zlib_compress_init(void) out = snew(struct Outbuf); out->outbits = out->noutbits = 0; - out->firstblock = 1; + out->firstblock = true; comp->ectx.userdata = out; return &comp->sc; @@ -636,7 +636,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len, struct ssh_zlib_compressor *comp = container_of(sc, struct ssh_zlib_compressor, sc); struct Outbuf *out = (struct Outbuf *) comp->ectx.userdata; - int in_block; + bool in_block; out->outbuf = NULL; out->outlen = out->outsize = 0; @@ -648,7 +648,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len, */ if (out->firstblock) { outbits(out, 0x9C78, 16); - out->firstblock = 0; + out->firstblock = false; in_block = false; } else @@ -967,8 +967,8 @@ static void zlib_emit_char(struct zlib_decompress_ctx *dctx, int c) #define EATBITS(n) ( dctx->nbits -= (n), dctx->bits >>= (n) ) -int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len, - unsigned char **outblock, int *outlen) +bool zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len, + unsigned char **outblock, int *outlen) { struct zlib_decompress_ctx *dctx = container_of(dc, struct zlib_decompress_ctx, dc); @@ -1209,13 +1209,13 @@ int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len, finished: *outblock = dctx->outblk; *outlen = dctx->outlen; - return 1; + return true; decode_error: sfree(dctx->outblk); *outblock = dctx->outblk = NULL; *outlen = 0; - return 0; + return false; } #ifdef ZLIB_STANDALONE diff --git a/telnet.c b/telnet.c index 97bd8e5c..1287bd2d 100644 --- a/telnet.c +++ b/telnet.c @@ -171,7 +171,7 @@ static const struct Opt *const opts[] = { typedef struct Telnet Telnet; struct Telnet { Socket *s; - int closed_on_socket_error; + bool closed_on_socket_error; Seat *seat; LogContext *logctx; @@ -180,14 +180,14 @@ struct Telnet { int opt_states[NUM_OPTS]; - int echoing, editing; - int activated; + bool echoing, editing; + bool activated; int bufsize; - int in_synch; + bool in_synch; int sb_opt, sb_len; unsigned char *sb_buf; int sb_size; - int session_started; + bool session_started; enum { TOP_LEVEL, SEENIAC, SEENWILL, SEENWONT, SEENDO, SEENDONT, @@ -248,7 +248,8 @@ static void deactivate_option(Telnet *telnet, const struct Opt *o) /* * Generate side effects of enabling or disabling an option. */ -static void option_side_effects(Telnet *telnet, const struct Opt *o, int enabled) +static void option_side_effects( + Telnet *telnet, const struct Opt *o, bool enabled) { if (o->option == TELOPT_ECHO && o->send == DO) telnet->echoing = !enabled; @@ -290,7 +291,7 @@ static void activate_option(Telnet *telnet, const struct Opt *o) deactivate_option(telnet, o->option == TELOPT_NEW_ENVIRON ? &o_oenv : &o_nenv); } - option_side_effects(telnet, o, 1); + option_side_effects(telnet, o, true); } static void refused_option(Telnet *telnet, const struct Opt *o) @@ -300,7 +301,7 @@ static void refused_option(Telnet *telnet, const struct Opt *o) send_opt(telnet, WILL, TELOPT_OLD_ENVIRON); telnet->opt_states[o_oenv.index] = REQUESTED; } - option_side_effects(telnet, o, 0); + option_side_effects(telnet, o, false); } static void proc_rec_opt(Telnet *telnet, int cmd, int option) @@ -336,7 +337,7 @@ static void proc_rec_opt(Telnet *telnet, int cmd, int option) case ACTIVE: telnet->opt_states[(*o)->index] = INACTIVE; send_opt(telnet, (*o)->nsend, option); - option_side_effects(telnet, *o, 0); + option_side_effects(telnet, *o, false); break; case INACTIVE: case REALLY_INACTIVE: @@ -542,7 +543,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len) * just stop hiding on the next 0xf2 and hope for the best. */ else if (c == DM) - telnet->in_synch = 0; + telnet->in_synch = false; #endif if (c == CR && telnet->opt_states[o_they_bin.index] != ACTIVE) telnet->state = SEENCR; @@ -562,7 +563,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len) else if (c == SB) telnet->state = SEENSB; else if (c == DM) { - telnet->in_synch = 0; + telnet->in_synch = false; telnet->state = TOP_LEVEL; } else { /* ignore everything else; print it if it's IAC */ @@ -633,7 +634,7 @@ static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, } static void telnet_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { Telnet *telnet = container_of(plug, Telnet, plug); @@ -690,7 +691,7 @@ static const PlugVtable Telnet_plugvt = { static const char *telnet_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, - char **realhost, int nodelay, int keepalive) + char **realhost, bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -736,8 +737,8 @@ static const char *telnet_init(Seat *seat, Backend **backend_handle, /* * Open socket. */ - telnet->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, - &telnet->plug, telnet->conf); + telnet->s = new_connection(addr, *realhost, port, false, true, nodelay, + keepalive, &telnet->plug, telnet->conf); if ((err = sk_socket_error(telnet->s)) != NULL) return err; @@ -1000,16 +1001,16 @@ static const SessionSpecial *telnet_get_specials(Backend *be) return specials; } -static int telnet_connected(Backend *be) +static bool telnet_connected(Backend *be) { Telnet *telnet = container_of(be, Telnet, backend); return telnet->s != NULL; } -static int telnet_sendok(Backend *be) +static bool telnet_sendok(Backend *be) { /* Telnet *telnet = container_of(be, Telnet, backend); */ - return 1; + return true; } static void telnet_unthrottle(Backend *be, int backlog) @@ -1018,7 +1019,7 @@ static void telnet_unthrottle(Backend *be, int backlog) sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); } -static int telnet_ldisc(Backend *be, int option) +static bool telnet_ldisc(Backend *be, int option) { Telnet *telnet = container_of(be, Telnet, backend); if (option == LD_ECHO) diff --git a/terminal.c b/terminal.c index e99edea0..ae0f3917 100644 --- a/terminal.c +++ b/terminal.c @@ -22,8 +22,12 @@ #define posPlt(p1,p2) ( (p1).y <= (p2).y && (p1).x < (p2).x ) #define posPle(p1,p2) ( (p1).y <= (p2).y && (p1).x <= (p2).x ) -#define incpos(p) ( (p).x == term->cols ? ((p).x = 0, (p).y++, 1) : ((p).x++, 0) ) -#define decpos(p) ( (p).x == 0 ? ((p).x = term->cols, (p).y--, 1) : ((p).x--, 0) ) +#define incpos(p) ( (p).x == term->cols ? \ + ((p).x = 0, (p).y++, true) : \ + ((p).x++, false) ) +#define decpos(p) ( (p).x == 0 ? \ + ((p).x = term->cols, (p).y--, true) : \ + ((p).x--, false) ) #define VT52_PLUS @@ -102,16 +106,16 @@ static termline *lineptr(Terminal *, int, int, int); static void unlineptr(termline *); static void check_line_size(Terminal *, termline *); static void do_paint(Terminal *); -static void erase_lots(Terminal *, int, int, int); +static void erase_lots(Terminal *, bool, bool, bool); static int find_last_nonempty_line(Terminal *, tree234 *); -static void swap_screen(Terminal *, int, int, int); +static void swap_screen(Terminal *, int, bool, bool); static void update_sbar(Terminal *); static void deselect(Terminal *); static void term_print_finish(Terminal *); -static void scroll(Terminal *, int, int, int, int); +static void scroll(Terminal *, int, int, int, bool); static void parse_optionalrgb(optionalrgb *out, unsigned *values); -static termline *newline(Terminal *term, int cols, int bce) +static termline *newline(Terminal *term, int cols, bool bce) { termline *line; int j; @@ -278,8 +282,8 @@ static void clear_cc(termline *line, int col) * in do_paint() where we override what we expect the chr and attr * fields to be. */ -static int termchars_equal_override(termchar *a, termchar *b, - unsigned long bchr, unsigned long battr) +static bool termchars_equal_override(termchar *a, termchar *b, + unsigned long bchr, unsigned long battr) { /* FULL-TERMCHAR */ if (!truecolour_equal(a->truecolour, b->truecolour)) @@ -299,7 +303,7 @@ static int termchars_equal_override(termchar *a, termchar *b, return true; } -static int termchars_equal(termchar *a, termchar *b) +static bool termchars_equal(termchar *a, termchar *b) { return termchars_equal_override(a, b, b->chr, b->attr); } @@ -375,7 +379,8 @@ static void makerle(struct buf *b, termline *ldata, void (*makeliteral)(struct buf *b, termchar *c, unsigned long *state)) { - int hdrpos, hdrsize, n, prevlen, prevpos, thislen, thispos, prev2; + int hdrpos, hdrsize, n, prevlen, prevpos, thislen, thispos; + bool prev2; termchar *c = ldata->chars; unsigned long state = 0, oldstate; @@ -1132,8 +1137,8 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen) return line; } -#define lineptr(x) (lineptr)(term,x,__LINE__,false) -#define scrlineptr(x) (lineptr)(term,x,__LINE__,true) +#define lineptr(x) (lineptr)(term,x,__LINE__,0) +#define scrlineptr(x) (lineptr)(term,x,__LINE__,1) /* * Coerce a termline to the terminal's current width. Unlike the @@ -1157,7 +1162,7 @@ static void term_schedule_cblink(Terminal *term); static void term_timer(void *ctx, unsigned long now) { Terminal *term = (Terminal *)ctx; - int update = false; + bool update = false; if (term->tblink_pending && now == term->next_tblink) { term->tblinker = !term->tblinker; @@ -1212,7 +1217,7 @@ static void term_schedule_tblink(Terminal *term) term->next_tblink = schedule_timer(TBLINK_DELAY, term_timer, term); term->tblink_pending = true; } else { - term->tblinker = 1; /* reset when not in use */ + term->tblinker = true; /* reset when not in use */ term->tblink_pending = false; } } @@ -1227,7 +1232,7 @@ static void term_schedule_cblink(Terminal *term) term->next_cblink = schedule_timer(CBLINK_DELAY, term_timer, term); term->cblink_pending = true; } else { - term->cblinker = 1; /* reset when not in use */ + term->cblinker = true; /* reset when not in use */ term->cblink_pending = false; } } @@ -1238,7 +1243,7 @@ static void term_schedule_cblink(Terminal *term) static void term_reset_cblink(Terminal *term) { seen_disp_event(term); - term->cblinker = 1; + term->cblinker = true; term->cblink_pending = false; term_schedule_cblink(term); } @@ -1246,7 +1251,7 @@ static void term_reset_cblink(Terminal *term) /* * Call to begin a visual bell. */ -static void term_schedule_vbell(Terminal *term, int already_started, +static void term_schedule_vbell(Terminal *term, bool already_started, long startpoint) { long ticks_already_gone; @@ -1271,7 +1276,7 @@ static void term_schedule_vbell(Terminal *term, int already_started, * position the cursor below the last non-blank line (scrolling if * necessary). */ -static void power_on(Terminal *term, int clear) +static void power_on(Terminal *term, bool clear) { term->alt_x = term->alt_y = 0; term->savecurs.x = term->savecurs.y = 0; @@ -1287,21 +1292,27 @@ static void power_on(Terminal *term, int clear) term->tabs[i] = (i % 8 == 0 ? true : false); } term->alt_om = term->dec_om = conf_get_bool(term->conf, CONF_dec_om); - term->alt_ins = term->insert = false; - term->alt_wnext = term->wrapnext = - term->save_wnext = term->alt_save_wnext = false; + term->alt_ins = false; + term->insert = false; + term->alt_wnext = false; + term->wrapnext = false; + term->save_wnext = false; + term->alt_save_wnext = false; term->alt_wrap = term->wrap = conf_get_bool(term->conf, CONF_wrap_mode); term->alt_cset = term->cset = term->save_cset = term->alt_save_cset = 0; - term->alt_utf = term->utf = term->save_utf = term->alt_save_utf = 0; + term->alt_utf = false; + term->utf = false; + term->save_utf = false; + term->alt_save_utf = false; term->utf_state = 0; term->alt_sco_acs = term->sco_acs = term->save_sco_acs = term->alt_save_sco_acs = 0; term->cset_attr[0] = term->cset_attr[1] = term->save_csattr = term->alt_save_csattr = CSET_ASCII; - term->rvideo = 0; + term->rvideo = false; term->in_vbell = false; - term->cursor_on = 1; - term->big_cursor = 0; + term->cursor_on = true; + term->big_cursor = false; term->default_attr = term->save_attr = term->alt_save_attr = term->curr_attr = ATTR_DEFAULT; term->curr_truecolour.fg = term->curr_truecolour.bg = optionalrgb_none; @@ -1315,8 +1326,8 @@ static void power_on(Terminal *term, int clear) term->alt_which = 0; term_print_finish(term); term->xterm_mouse = 0; - term->xterm_extended_mouse = 0; - term->urxvt_extended_mouse = 0; + term->xterm_extended_mouse = false; + term->urxvt_extended_mouse = false; win_set_raw_mouse_mode(term->win, false); term->bracketed_paste = false; { @@ -1351,10 +1362,10 @@ void term_update(Terminal *term) term->window_update_pending = false; if (win_setup_draw_ctx(term->win)) { - int need_sbar_update = term->seen_disp_event; + bool need_sbar_update = term->seen_disp_event; if (term->seen_disp_event && term->scroll_on_disp) { term->disptop = 0; /* return to main screen */ - term->seen_disp_event = 0; + term->seen_disp_event = false; need_sbar_update = true; } @@ -1401,7 +1412,7 @@ void term_seen_key_event(Terminal *term) /* * Same as power_on(), but an external function. */ -void term_pwron(Terminal *term, int clear) +void term_pwron(Terminal *term, bool clear) { power_on(term, clear); if (term->ldisc) /* cause ldisc to notice changes */ @@ -1509,7 +1520,7 @@ void term_reconfig(Terminal *term, Conf *conf) * default one. The full list is: Auto wrap mode, DEC Origin * Mode, BCE, blinking text, character classes. */ - int reset_wrap, reset_decom, reset_bce, reset_tblink, reset_charclass; + bool reset_wrap, reset_decom, reset_bce, reset_tblink, reset_charclass; int i; reset_wrap = (conf_get_bool(term->conf, CONF_wrap_mode) != @@ -1520,11 +1531,11 @@ void term_reconfig(Terminal *term, Conf *conf) conf_get_bool(conf, CONF_bce)); reset_tblink = (conf_get_bool(term->conf, CONF_blinktext) != conf_get_bool(conf, CONF_blinktext)); - reset_charclass = 0; + reset_charclass = false; for (i = 0; i < 256; i++) if (conf_get_int_int(term->conf, CONF_wordness, i) != conf_get_int_int(conf, CONF_wordness, i)) - reset_charclass = 1; + reset_charclass = true; /* * If the bidi or shaping settings have changed, flush the bidi @@ -1571,7 +1582,7 @@ void term_reconfig(Terminal *term, Conf *conf) if (conf_get_bool(term->conf, CONF_no_remote_charset)) { term->cset_attr[0] = term->cset_attr[1] = CSET_ASCII; term->sco_acs = term->alt_sco_acs = 0; - term->utf = 0; + term->utf = false; } if (!conf_get_str(term->conf, CONF_printer)) { term_print_finish(term); @@ -1658,10 +1669,11 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win) term->vt52_mode = false; term->cr_lf_return = false; term->seen_disp_event = false; - term->mouse_is_down = false; + term->mouse_is_down = 0; term->reset_132 = false; - term->cblinker = term->tblinker = 0; - term->has_focus = 1; + term->cblinker = false; + term->tblinker = false; + term->has_focus = true; term->repeat_off = false; term->termstate = TOPLEVEL; term->selstate = NO_SELECTION; @@ -1944,7 +1956,8 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines) if (term->alt_x >= newcols) term->alt_x = newcols - 1; term->alt_x = term->alt_y = 0; - term->wrapnext = term->alt_wnext = false; + term->wrapnext = false; + term->alt_wnext = false; term->rows = newrows; term->cols = newcols; @@ -1993,9 +2006,11 @@ static int find_last_nonempty_line(Terminal * term, tree234 * screen) * alternate screen completely. (This is even true if we're already * on it! Blame xterm.) */ -static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos) +static void swap_screen(Terminal *term, int which, + bool reset, bool keep_cur_pos) { int t; + bool bt; pos tp; truecolour ttc; tree234 *ttr; @@ -2024,24 +2039,24 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos) t = term->marg_b; if (!reset) term->marg_b = term->alt_b; term->alt_b = t; - t = term->dec_om; + bt = term->dec_om; if (!reset) term->dec_om = term->alt_om; - term->alt_om = t; - t = term->wrap; + term->alt_om = bt; + bt = term->wrap; if (!reset) term->wrap = term->alt_wrap; - term->alt_wrap = t; - t = term->wrapnext; + term->alt_wrap = bt; + bt = term->wrapnext; if (!reset) term->wrapnext = term->alt_wnext; - term->alt_wnext = t; - t = term->insert; + term->alt_wnext = bt; + bt = term->insert; if (!reset) term->insert = term->alt_ins; - term->alt_ins = t; + term->alt_ins = bt; t = term->cset; if (!reset) term->cset = term->alt_cset; term->alt_cset = t; - t = term->utf; + bt = term->utf; if (!reset) term->utf = term->alt_utf; - term->alt_utf = t; + term->alt_utf = bt; t = term->sco_acs; if (!reset) term->sco_acs = term->alt_sco_acs; term->alt_sco_acs = t; @@ -2066,14 +2081,14 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos) if (!reset && !keep_cur_pos) term->save_truecolour = term->alt_save_truecolour; term->alt_save_truecolour = ttc; - t = term->save_utf; + bt = term->save_utf; if (!reset && !keep_cur_pos) term->save_utf = term->alt_save_utf; - term->alt_save_utf = t; - t = term->save_wnext; + term->alt_save_utf = bt; + bt = term->save_wnext; if (!reset && !keep_cur_pos) term->save_wnext = term->alt_save_wnext; - term->alt_save_wnext = t; + term->alt_save_wnext = bt; t = term->save_sco_acs; if (!reset && !keep_cur_pos) term->save_sco_acs = term->alt_save_sco_acs; @@ -2113,7 +2128,8 @@ static void check_selection(Terminal *term, pos from, pos to) * for backward.) `sb' is true if the scrolling is permitted to * affect the scrollback buffer. */ -static void scroll(Terminal *term, int topline, int botline, int lines, int sb) +static void scroll(Terminal *term, int topline, int botline, + int lines, bool sb) { termline *line; int i, seltop, scrollwinsize; @@ -2275,7 +2291,7 @@ static void move(Terminal *term, int x, int y, int marg_clip) /* * Save or restore the cursor and SGR mode. */ -static void save_cursor(Terminal *term, int save) +static void save_cursor(Terminal *term, bool save) { if (save) { term->savecurs = term->curs; @@ -2357,11 +2373,11 @@ static void check_boundary(Terminal *term, int x, int y) * whole line, or parts thereof. */ static void erase_lots(Terminal *term, - int line_only, int from_begin, int to_end) + bool line_only, bool from_begin, bool to_end) { pos start, end; - int erase_lattr; - int erasing_lines_from_top = 0; + bool erase_lattr; + bool erasing_lines_from_top = false; if (line_only) { start.y = term->curs.y; @@ -2394,7 +2410,7 @@ static void erase_lots(Terminal *term, /* Lines scrolled away shouldn't be brought back on if the terminal * resizes. */ if (start.y == 0 && start.x == 0 && end.x == 0 && erase_lattr) - erasing_lines_from_top = 1; + erasing_lines_from_top = true; if (term->erase_to_scrollback && erasing_lines_from_top) { /* If it's a whole number of lines, starting at the top, and @@ -2510,9 +2526,9 @@ static void insch(Terminal *term, int n) * Toggle terminal mode `mode' to state `state'. (`query' indicates * whether the mode is a DEC private one or a normal one.) */ -static void toggle_mode(Terminal *term, int mode, int query, int state) +static void toggle_mode(Terminal *term, int mode, int query, bool state) { - if (query) + if (query == 1) { switch (mode) { case 1: /* DECCKM: application cursor keys */ term->app_cursor_keys = state; @@ -2589,10 +2605,10 @@ static void toggle_mode(Terminal *term, int mode, int query, int state) win_set_raw_mouse_mode(term->win, state); break; case 1006: /* xterm extended mouse */ - term->xterm_extended_mouse = state ? 1 : 0; + term->xterm_extended_mouse = state; break; case 1015: /* urxvt extended mouse */ - term->urxvt_extended_mouse = state ? 1 : 0; + term->urxvt_extended_mouse = state; break; case 1047: /* alternate screen */ compatibility(OTHER); @@ -2621,7 +2637,8 @@ static void toggle_mode(Terminal *term, int mode, int query, int state) case 2004: /* xterm bracketed paste */ term->bracketed_paste = state ? true : false; break; - } else + } + } else if (query == 0) { switch (mode) { case 4: /* IRM: set insert mode */ compatibility(VT102); @@ -2639,6 +2656,7 @@ static void toggle_mode(Terminal *term, int mode, int query, int state) compatibility2(OTHER, VT220); term->big_cursor = !state; } + } } /* @@ -2676,7 +2694,8 @@ static void do_osc(Terminal *term) (unsigned)r * 0x0101, (unsigned)g * 0x0101, (unsigned)b * 0x0101); - ldisc_send(term->ldisc, reply_buf, strlen(reply_buf), 0); + ldisc_send(term->ldisc, reply_buf, strlen(reply_buf), + false); sfree(reply_buf); } } @@ -3088,7 +3107,7 @@ static void term_out(Terminal *term) c = 0; else { term->termstate = SEEN_ESC; - term->esc_query = false; + term->esc_query = 0; c = '@' + (c & 0x1F); } } @@ -3120,7 +3139,7 @@ static void term_out(Terminal *term) compatibility(ANSIMIN); if (term->ldisc) { lpage_send(term->ldisc, DEFAULT_CODEPAGE, - term->answerback, term->answerbacklen, 0); + term->answerback, term->answerbacklen, false); } break; case '\007': /* BEL: Bell */ @@ -3189,8 +3208,7 @@ static void term_out(Terminal *term) } break; case '\b': /* BS: Back space */ - if (term->curs.x == 0 && - (term->curs.y == 0 || term->wrap == 0)) + if (term->curs.x == 0 && (term->curs.y == 0 || term->wrap)) /* do nothing */ ; else if (term->curs.x == 0 && term->curs.y > 0) term->curs.x = term->cols - 1, term->curs.y--; @@ -3214,7 +3232,7 @@ static void term_out(Terminal *term) else { compatibility(ANSIMIN); term->termstate = SEEN_ESC; - term->esc_query = false; + term->esc_query = 0; } break; case '\015': /* CR: Carriage return */ @@ -3313,7 +3331,7 @@ static void term_out(Terminal *term) term->termstate = SEEN_CSI; term->esc_nargs = 1; term->esc_args[0] = ARG_DEFAULT; - term->esc_query = false; + term->esc_query = 0; break; case ']': /* OSC: xterm escape sequences */ /* Compatibility is nasty here, xterm, linux, decterm yuk! */ @@ -3371,7 +3389,7 @@ static void term_out(Terminal *term) compatibility(VT100); if (term->ldisc && term->id_string[0]) ldisc_send(term->ldisc, term->id_string, - strlen(term->id_string), 0); + strlen(term->id_string), false); break; case 'c': /* RIS: restore power-on settings */ compatibility(VT100); @@ -3381,7 +3399,7 @@ static void term_out(Terminal *term) if (term->reset_132) { if (!term->no_remote_resize) win_request_resize(term->win, 80, term->rows); - term->reset_132 = 0; + term->reset_132 = false; } if (term->scroll_on_disp) term->disptop = 0; @@ -3494,12 +3512,12 @@ static void term_out(Terminal *term) case ANSI('G', '%'): compatibility(OTHER); if (!term->no_remote_charset) - term->utf = 1; + term->utf = true; break; case ANSI('@', '%'): compatibility(OTHER); if (!term->no_remote_charset) - term->utf = 0; + term->utf = false; break; } break; @@ -3528,7 +3546,7 @@ static void term_out(Terminal *term) if (term->esc_query) term->esc_query = -1; else if (c == '?') - term->esc_query = true; + term->esc_query = 1; else term->esc_query = c; term->termstate = SEEN_CSI; @@ -3564,7 +3582,8 @@ static void term_out(Terminal *term) /* this reports xterm version 136 so that VIM can use the drag messages from the mouse reporting */ if (term->ldisc) - ldisc_send(term->ldisc, "\033[>0;136;0c", 11, 0); + ldisc_send(term->ldisc, "\033[>0;136;0c", 11, + false); break; case 'a': /* HPR: move right N cols */ compatibility(ANSI); @@ -3687,7 +3706,7 @@ static void term_out(Terminal *term) /* This is the response for a VT102 */ if (term->ldisc && term->id_string[0]) ldisc_send(term->ldisc, term->id_string, - strlen(term->id_string), 0); + strlen(term->id_string), false); break; case 'n': /* DSR: cursor position query */ if (term->ldisc) { @@ -3695,9 +3714,10 @@ static void term_out(Terminal *term) char buf[32]; sprintf(buf, "\033[%d;%dR", term->curs.y + 1, term->curs.x + 1); - ldisc_send(term->ldisc, buf, strlen(buf), 0); + ldisc_send(term->ldisc, buf, strlen(buf), + false); } else if (term->esc_args[0] == 5) { - ldisc_send(term->ldisc, "\033[0n", 4, 0); + ldisc_send(term->ldisc, "\033[0n", 4, false); } } break; @@ -4088,7 +4108,8 @@ static void term_out(Terminal *term) if (term->ldisc) ldisc_send(term->ldisc, win_is_minimised(term->win) ? - "\033[2t" : "\033[1t", 4, 0); + "\033[2t" : "\033[1t", 4, + false); break; case 13: if (term->ldisc) { @@ -4096,21 +4117,21 @@ static void term_out(Terminal *term) len = sprintf(buf, "\033[3;%u;%ut", (unsigned)x, (unsigned)y); - ldisc_send(term->ldisc, buf, len, 0); + ldisc_send(term->ldisc, buf, len, false); } break; case 14: if (term->ldisc) { win_get_pixels(term->win, &x, &y); len = sprintf(buf, "\033[4;%d;%dt", y, x); - ldisc_send(term->ldisc, buf, len, 0); + ldisc_send(term->ldisc, buf, len, false); } break; case 18: if (term->ldisc) { len = sprintf(buf, "\033[8;%d;%dt", term->rows, term->cols); - ldisc_send(term->ldisc, buf, len, 0); + ldisc_send(term->ldisc, buf, len, false); } break; case 19: @@ -4138,10 +4159,12 @@ static void term_out(Terminal *term) else p = EMPTY_WINDOW_TITLE; len = strlen(p); - ldisc_send(term->ldisc, "\033]L", 3, 0); + ldisc_send(term->ldisc, "\033]L", 3, + false); if (len > 0) - ldisc_send(term->ldisc, p, len, 0); - ldisc_send(term->ldisc, "\033\\", 2, 0); + ldisc_send(term->ldisc, p, len, false); + ldisc_send(term->ldisc, "\033\\", 2, + false); } break; case 21: @@ -4152,10 +4175,12 @@ static void term_out(Terminal *term) else p = EMPTY_WINDOW_TITLE; len = strlen(p); - ldisc_send(term->ldisc, "\033]l", 3, 0); + ldisc_send(term->ldisc, "\033]l", 3, + false); if (len > 0) - ldisc_send(term->ldisc, p, len, 0); - ldisc_send(term->ldisc, "\033\\", 2, 0); + ldisc_send(term->ldisc, p, len, false); + ldisc_send(term->ldisc, "\033\\", 2, + false); } break; } @@ -4241,7 +4266,7 @@ static void term_out(Terminal *term) if (i == 0 || i == 1) { strcpy(buf, "\033[2;1;1;112;112;1;0x"); buf[2] += i; - ldisc_send(term->ldisc, buf, 20, 0); + ldisc_send(term->ldisc, buf, 20, false); } } break; @@ -4657,7 +4682,7 @@ static void term_out(Terminal *term) break; case 'Z': if (term->ldisc) - ldisc_send(term->ldisc, "\033/Z", 3, 0); + ldisc_send(term->ldisc, "\033/Z", 3, false); break; case '=': term->app_keypad_keys = true; @@ -4748,11 +4773,11 @@ static void term_out(Terminal *term) break; case 'v': /* wrap Autowrap on - Wyse style */ /* compatibility(ATARI) */ - term->wrap = 1; + term->wrap = true; break; case 'w': /* Autowrap off */ /* compatibility(ATARI) */ - term->wrap = 0; + term->wrap = false; break; case 'R': @@ -4841,8 +4866,8 @@ static void parse_optionalrgb(optionalrgb *out, unsigned *values) * too many times, we maintain a cache of the last lineful of data * fed to the algorithm on each line of the display. */ -static int term_bidi_cache_hit(Terminal *term, int line, - termchar *lbefore, int width) +static bool term_bidi_cache_hit(Terminal *term, int line, + termchar *lbefore, int width) { int i; @@ -5115,12 +5140,13 @@ static void do_paint(Terminal *term) for (i = 0; i < term->rows; i++) { termline *ldata; termchar *lchars; - int dirty_line, dirty_run, selected; + bool dirty_line, dirty_run, selected; unsigned long attr = 0, cset = 0; int start = 0; int ccount = 0; - int last_run_dirty = 0; - int laststart, dirtyrect; + bool last_run_dirty = false; + int laststart; + bool dirtyrect; int *backward; truecolour tc; @@ -5280,7 +5306,7 @@ static void do_paint(Terminal *term) tc = term->erase_char.truecolour; for (j = 0; j < term->cols; j++) { unsigned long tattr, tchar; - int break_run, do_copy; + bool break_run, do_copy; termchar *d = lchars + j; tattr = newline[j].attr; @@ -5458,7 +5484,7 @@ void term_invalidate(Terminal *term) * Paint the window in response to a WM_PAINT message. */ void term_paint(Terminal *term, - int left, int top, int right, int bottom, int immediately) + int left, int top, int right, int bottom, bool immediately) { int i, j; if (left < 0) left = 0; @@ -5558,7 +5584,7 @@ static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr, truecolour tc) b->bufpos++; } -static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel, +static void clipme(Terminal *term, pos top, pos bottom, bool rect, bool desel, const int *clipboards, int n_clipboards) { clip_workbuf buf; @@ -5575,7 +5601,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel, old_top_x = top.x; /* needed for rect==1 */ while (poslt(top, bottom)) { - int nl = false; + bool nl = false; termline *ldata = lineptr(top.y); pos nlpos; @@ -5722,7 +5748,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel, /* Finally, transfer all that to the clipboard(s). */ { int i; - int clip_local = false; + bool clip_local = false; for (i = 0; i < n_clipboards; i++) { if (clipboards[i] == CLIP_LOCAL) { clip_local = true; @@ -5757,7 +5783,7 @@ void term_copyall(Terminal *term, const int *clipboards, int n_clipboards) top.x = 0; bottom.y = find_last_nonempty_line(term, screen); bottom.x = term->cols; - clipme(term, top, bottom, 0, true, clipboards, n_clipboards); + clipme(term, top, bottom, false, true, clipboards, n_clipboards); } static void paste_from_clip_local(void *vterm) @@ -6038,7 +6064,8 @@ static void term_paste_callback(void *vterm) break; } if (term->ldisc) - luni_send(term->ldisc, term->paste_buffer + term->paste_pos, n, 0); + luni_send(term->ldisc, term->paste_buffer + term->paste_pos, n, + false); term->paste_pos += n; if (term->paste_pos < term->paste_len) { @@ -6056,7 +6083,7 @@ static void term_paste_callback(void *vterm) * alen wide characters starting at a has as a prefix the buffer of * blen characters starting at b. */ -static int wstartswith(const wchar_t *a, size_t alen, +static bool wstartswith(const wchar_t *a, size_t alen, const wchar_t *b, size_t blen) { return alen >= blen && !wcsncmp(a, b, blen); @@ -6065,7 +6092,7 @@ static int wstartswith(const wchar_t *a, size_t alen, void term_do_paste(Terminal *term, const wchar_t *data, int len) { const wchar_t *p; - int paste_controls = conf_get_bool(term->conf, CONF_paste_controls); + bool paste_controls = conf_get_bool(term->conf, CONF_paste_controls); /* * Pasting data into the terminal counts as a keyboard event (for @@ -6142,7 +6169,7 @@ void term_do_paste(Terminal *term, const wchar_t *data, int len) /* Assume a small paste will be OK in one go. */ if (term->paste_len < 256) { if (term->ldisc) - luni_send(term->ldisc, term->paste_buffer, term->paste_len, 0); + luni_send(term->ldisc, term->paste_buffer, term->paste_len, false); if (term->paste_buffer) sfree(term->paste_buffer); term->paste_buffer = 0; @@ -6153,13 +6180,13 @@ void term_do_paste(Terminal *term, const wchar_t *data, int len) } void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, - Mouse_Action a, int x, int y, int shift, int ctrl, int alt) + Mouse_Action a, int x, int y, bool shift, bool ctrl, bool alt) { pos selpoint; termline *ldata; - int raw_mouse = (term->xterm_mouse && - !term->no_mouse_rep && - !(term->mouse_override && shift)); + bool raw_mouse = (term->xterm_mouse && + !term->no_mouse_rep && + !(term->mouse_override && shift)); int default_seltype; if (y < 0) { @@ -6220,7 +6247,8 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, */ if (raw_mouse && (term->selstate != ABOUT_TO) && (term->selstate != DRAGGING)) { - int encstate = 0, r, c, wheel; + int encstate = 0, r, c; + bool wheel; char abuf[32]; int len = 0; @@ -6293,7 +6321,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, len = sprintf(abuf, "\033[M%c%c%c", encstate + 32, c + 32, r + 32); } if (len > 0) - ldisc_send(term->ldisc, abuf, len, 0); + ldisc_send(term->ldisc, abuf, len, false); } return; } @@ -6437,14 +6465,14 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, term_update(term); } -int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl) +int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl) { char *p = buf; if (term->vt52_mode) p += sprintf((char *) p, "\x1B%c", xkey); else { - int app_flg = (term->app_cursor_keys && !term->no_applic_c); + bool app_flg = (term->app_cursor_keys && !term->no_applic_c); #if 0 /* * RDB: VT100 & VT102 manuals both state the app cursor @@ -6506,7 +6534,7 @@ void term_lost_clipboard_ownership(Terminal *term, int clipboard) term_out(term); } -int term_ldisc(Terminal *term, int option) +bool term_ldisc(Terminal *term, int option) { if (option == LD_ECHO) return term->term_echoing; @@ -6531,7 +6559,7 @@ static void term_added_data(Terminal *term) } } -int term_data(Terminal *term, int is_stderr, const void *data, int len) +int term_data(Terminal *term, bool is_stderr, const void *data, int len) { bufchain_add(&term->inbuf, data, len); term_added_data(term); @@ -6569,7 +6597,7 @@ void term_provide_logctx(Terminal *term, LogContext *logctx) term->logctx = logctx; } -void term_set_focus(Terminal *term, int has_focus) +void term_set_focus(Terminal *term, bool has_focus) { term->has_focus = has_focus; term_schedule_cblink(term); @@ -6594,7 +6622,7 @@ char *term_get_ttymode(Terminal *term, const char *mode) struct term_userpass_state { size_t curr_prompt; - int done_prompt; /* printed out prompt yet? */ + bool done_prompt; /* printed out prompt yet? */ size_t pos; /* cursor position */ }; @@ -6611,7 +6639,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) */ p->data = s = snew(struct term_userpass_state); s->curr_prompt = 0; - s->done_prompt = 0; + s->done_prompt = false; /* We only print the `name' caption if we have to... */ if (p->name_reqd && p->name) { size_t l = strlen(p->name); @@ -6639,11 +6667,11 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) while (s->curr_prompt < p->n_prompts) { prompt_t *pr = p->prompts[s->curr_prompt]; - int finished_prompt = 0; + bool finished_prompt = false; if (!s->done_prompt) { term_data_untrusted(term, pr->prompt, strlen(pr->prompt)); - s->done_prompt = 1; + s->done_prompt = true; s->pos = 0; } @@ -6658,19 +6686,19 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) switch (c) { case 10: case 13: - term_data(term, 0, "\r\n", 2); + term_data(term, false, "\r\n", 2); prompt_ensure_result_size(pr, s->pos + 1); pr->result[s->pos] = '\0'; /* go to next prompt, if any */ s->curr_prompt++; - s->done_prompt = 0; - finished_prompt = 1; /* break out */ + s->done_prompt = false; + finished_prompt = true; /* break out */ break; case 8: case 127: if (s->pos > 0) { if (pr->echo) - term_data(term, 0, "\b \b", 3); + term_data(term, false, "\b \b", 3); s->pos--; } break; @@ -6678,14 +6706,14 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) case 27: while (s->pos > 0) { if (pr->echo) - term_data(term, 0, "\b \b", 3); + term_data(term, false, "\b \b", 3); s->pos--; } break; case 3: case 4: /* Immediate abort. */ - term_data(term, 0, "\r\n", 2); + term_data(term, false, "\r\n", 2); sfree(s); p->data = NULL; return 0; /* user abort */ @@ -6700,7 +6728,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) prompt_ensure_result_size(pr, s->pos + 1); pr->result[s->pos++] = c; if (pr->echo) - term_data(term, 0, &c, 1); + term_data(term, false, &c, 1); } break; } diff --git a/terminal.h b/terminal.h index d569f5f4..e39090bb 100644 --- a/terminal.h +++ b/terminal.h @@ -52,7 +52,7 @@ struct termline { int cols; /* number of real columns on the line */ int size; /* number of allocated termchars * (cc-lists may make this > cols) */ - int temporary; /* true if decompressed from scrollback */ + bool temporary; /* true if decompressed from scrollback */ int cc_free; /* offset to first cc in free list */ struct termchar *chars; }; @@ -83,7 +83,7 @@ struct terminal_tag { struct beeptime *beephead, *beeptail; int nbeeps; - int beep_overloaded; + bool beep_overloaded; long lastbeep; #define TTYPE termchar @@ -97,29 +97,29 @@ struct terminal_tag { pos curs; /* cursor */ pos savecurs; /* saved cursor position */ int marg_t, marg_b; /* scroll margins */ - int dec_om; /* DEC origin mode flag */ - int wrap, wrapnext; /* wrap flags */ - int insert; /* insert-mode flag */ + bool dec_om; /* DEC origin mode flag */ + bool wrap, wrapnext; /* wrap flags */ + bool insert; /* insert-mode flag */ int cset; /* 0 or 1: which char set */ int save_cset, save_csattr; /* saved with cursor position */ - int save_utf, save_wnext; /* saved with cursor position */ - int rvideo; /* global reverse video flag */ + bool save_utf, save_wnext; /* saved with cursor position */ + bool rvideo; /* global reverse video flag */ unsigned long rvbell_startpoint; /* for ESC[?5hESC[?5l vbell */ - int cursor_on; /* cursor enabled flag */ - int reset_132; /* Flag ESC c resets to 80 cols */ - int use_bce; /* Use Background coloured erase */ - int cblinker; /* When blinking is the cursor on ? */ - int tblinker; /* When the blinking text is on */ - int blink_is_real; /* Actually blink blinking text */ - int term_echoing; /* Does terminal want local echo? */ - int term_editing; /* Does terminal want local edit? */ + bool cursor_on; /* cursor enabled flag */ + bool reset_132; /* Flag ESC c resets to 80 cols */ + bool use_bce; /* Use Background coloured erase */ + bool cblinker; /* When blinking is the cursor on ? */ + bool tblinker; /* When the blinking text is on */ + bool blink_is_real; /* Actually blink blinking text */ + bool term_echoing; /* Does terminal want local echo? */ + bool term_editing; /* Does terminal want local edit? */ int sco_acs, save_sco_acs; /* CSI 10,11,12m -> OEM charset */ - int vt52_bold; /* Force bold on non-bold colours */ - int utf; /* Are we in toggleable UTF-8 mode? */ + bool vt52_bold; /* Force bold on non-bold colours */ + bool utf; /* Are we in toggleable UTF-8 mode? */ int utf_state; /* Is there a pending UTF-8 character */ int utf_char; /* and what is it so far. */ int utf_size; /* The size of the UTF character. */ - int printing, only_printing; /* Are we doing ANSI printing? */ + bool printing, only_printing; /* Are we doing ANSI printing? */ int print_state; /* state of print-end-sequence scan */ bufchain printer_buf; /* buffered data for printer */ printer_job *print_job; @@ -129,32 +129,36 @@ struct terminal_tag { int alt_save_attr; truecolour alt_save_truecolour; int alt_save_cset, alt_save_csattr; - int alt_save_utf, alt_save_wnext; + bool alt_save_utf; + bool alt_save_wnext; int alt_save_sco_acs; int rows, cols, savelines; - int has_focus; - int in_vbell; + bool has_focus; + bool in_vbell; long vbell_end; - int app_cursor_keys, app_keypad_keys, vt52_mode; - int repeat_off, cr_lf_return; - int seen_disp_event; - int big_cursor; + bool app_cursor_keys, app_keypad_keys, vt52_mode; + bool repeat_off, cr_lf_return; + bool seen_disp_event; + bool big_cursor; int xterm_mouse; /* send mouse messages to host */ - int xterm_extended_mouse; - int urxvt_extended_mouse; + bool xterm_extended_mouse; + bool urxvt_extended_mouse; int mouse_is_down; /* used while tracking mouse buttons */ - int bracketed_paste; + bool bracketed_paste; int cset_attr[2]; /* * Saved settings on the alternate screen. */ - int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins; - int alt_cset, alt_sco_acs, alt_utf; + int alt_x, alt_y; + bool alt_wnext, alt_ins; + bool alt_om, alt_wrap; + int alt_cset, alt_sco_acs; + bool alt_utf; int alt_t, alt_b; int alt_which; int alt_sblines; /* # of lines on alternate screen that should be used for scrollback. */ @@ -166,12 +170,12 @@ struct terminal_tag { int esc_nargs; int esc_query; #define ANSI(x,y) ((x)+((y)<<8)) -#define ANSI_QUE(x) ANSI(x,true) +#define ANSI_QUE(x) ANSI(x,1) #define OSC_STR_MAX 2048 int osc_strlen; char osc_string[OSC_STR_MAX + 1]; - int osc_w; + bool osc_w; char id_string[1024]; @@ -243,19 +247,19 @@ struct terminal_tag { * data to the end of the buffer term_out is in the process of * working through. */ - int in_term_out; + bool in_term_out; /* * We schedule a window update shortly after receiving terminal * data. This tracks whether one is currently pending. */ - int window_update_pending; + bool window_update_pending; long next_update; /* * Track pending blinks and tblinks. */ - int tblink_pending, cblink_pending; + bool tblink_pending, cblink_pending; long next_tblink, next_cblink; /* @@ -274,48 +278,48 @@ struct terminal_tag { * tree234 lookups which would be involved in fetching them from * the former every time. */ - int ansi_colour; + bool ansi_colour; char *answerback; int answerbacklen; - int arabicshaping; + bool arabicshaping; int beep; - int bellovl; + bool bellovl; int bellovl_n; int bellovl_s; int bellovl_t; - int bidi; - int bksp_is_delete; - int blink_cur; - int blinktext; - int cjk_ambig_wide; + bool bidi; + bool bksp_is_delete; + bool blink_cur; + bool blinktext; + bool cjk_ambig_wide; int conf_height; int conf_width; - int crhaslf; - int erase_to_scrollback; + bool crhaslf; + bool erase_to_scrollback; int funky_type; - int lfhascr; - int logflush; + bool lfhascr; + bool logflush; int logtype; - int mouse_override; - int nethack_keypad; - int no_alt_screen; - int no_applic_c; - int no_applic_k; - int no_dbackspace; - int no_mouse_rep; - int no_remote_charset; - int no_remote_resize; - int no_remote_wintitle; - int no_remote_clearscroll; - int rawcnp; - int utf8linedraw; - int rect_select; + bool mouse_override; + bool nethack_keypad; + bool no_alt_screen; + bool no_applic_c; + bool no_applic_k; + bool no_dbackspace; + bool no_mouse_rep; + bool no_remote_charset; + bool no_remote_resize; + bool no_remote_wintitle; + bool no_remote_clearscroll; + bool rawcnp; + bool utf8linedraw; + bool rect_select; int remote_qtitle_action; - int rxvt_homeend; - int scroll_on_disp; - int scroll_on_key; - int xterm_256_colour; - int true_colour; + bool rxvt_homeend; + bool scroll_on_disp; + bool scroll_on_key; + bool xterm_256_colour; + bool true_colour; wchar_t *last_selected_text; int *last_selected_attr; diff --git a/testbn.c b/testbn.c index 29f6b753..364f704a 100644 --- a/testbn.c +++ b/testbn.c @@ -37,7 +37,7 @@ void queue_idempotent_callback(IdempotentCallback *ic) { assert(0); } #define fromxdigit(c) ( (c)>'9' ? ((c)&0xDF) - 'A' + 10 : (c) - '0' ) /* For Unix in particular, but harmless if this main() is reused elsewhere */ -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; int main(int argc, char **argv) { @@ -201,7 +201,7 @@ int main(int argc, char **argv) freebn(answer); } else if (!strcmp(buf, "divmod")) { Bignum n, d, expect_q, expect_r, answer_q, answer_r; - int fail; + bool fail; if (ptrnum != 4) { printf("%d: divmod with %d parameters, expected 4\n", line, ptrnum); diff --git a/timing.c b/timing.c index 0aad374a..8036e438 100644 --- a/timing.c +++ b/timing.c @@ -164,7 +164,7 @@ unsigned long timing_last_clock(void) * Returns the time (in ticks) expected until the next timer after * that triggers. */ -int run_timers(unsigned long anow, unsigned long *next) +bool run_timers(unsigned long anow, unsigned long *next) { struct timer *first; diff --git a/tree234.c b/tree234.c index ea8ff9ee..4cf9cb1e 100644 --- a/tree234.c +++ b/tree234.c @@ -29,6 +29,7 @@ #include #include +#include "defs.h" #include "tree234.h" #ifdef TEST @@ -529,7 +530,7 @@ void *findrelpos234(tree234 * t, void *e, cmpfn234 cmp, search234_state ss; int reldir = (relation == REL234_LT || relation == REL234_LE ? -1 : relation == REL234_GT || relation == REL234_GE ? +1 : 0); - int equal_permitted = (relation != REL234_LT && relation != REL234_GT); + bool equal_permitted = (relation != REL234_LT && relation != REL234_GT); void *toret; /* Only LT / GT relations are permitted with a null query element. */ diff --git a/unix/gtkapp.c b/unix/gtkapp.c index a9f6b02c..70dc7d3c 100644 --- a/unix/gtkapp.c +++ b/unix/gtkapp.c @@ -88,7 +88,7 @@ https://wiki.gnome.org/Projects/GTK%2B/OSX/Bundling has some links. char *x_get_default(const char *key) { return NULL; } -const int buildinfo_gtk_relevant = true; +const bool buildinfo_gtk_relevant = true; #if !GTK_CHECK_VERSION(3,0,0) /* This front end only works in GTK 3. If that's not what we've got, @@ -107,7 +107,7 @@ void session_window_closed(void) {} void window_setup_error(const char *errmsg) {} #else /* GTK_CHECK_VERSION(3,0,0) */ -extern const int use_event_log; +extern const bool use_event_log; static void startup(GApplication *app, gpointer user_data) { @@ -216,7 +216,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend) void launch_duplicate_session(Conf *conf) { - extern const int dup_check_launchable; + extern const bool dup_check_launchable; assert(!dup_check_launchable || conf_launchable(conf)); g_application_hold(G_APPLICATION(app)); new_session_window(conf_copy(conf), NULL); @@ -318,7 +318,7 @@ int main(int argc, char **argv) { /* Call the function in ux{putty,pterm}.c to do app-type * specific setup */ - extern void setup(int); + extern void setup(bool); setup(false); /* false means we are not a one-session process */ } diff --git a/unix/gtkask.c b/unix/gtkask.c index defc98f0..532b260d 100644 --- a/unix/gtkask.c +++ b/unix/gtkask.c @@ -14,6 +14,7 @@ #include #endif +#include "defs.h" #include "gtkfont.h" #include "gtkcompat.h" #include "gtkmisc.h" @@ -501,13 +502,13 @@ static void gtk_askpass_cleanup(struct askpass_ctx *ctx) gtk_widget_destroy(ctx->dialog); } -static int setup_gtk(const char *display) +static bool setup_gtk(const char *display) { - static int gtk_initialised = false; + static bool gtk_initialised = false; int argc; char *real_argv[3]; char **argv = real_argv; - int ret; + bool ret; if (gtk_initialised) return true; @@ -524,10 +525,10 @@ static int setup_gtk(const char *display) return ret; } -const int buildinfo_gtk_relevant = true; +const bool buildinfo_gtk_relevant = true; char *gtk_askpass_main(const char *display, const char *wintitle, - const char *prompt, int *success) + const char *prompt, bool *success) { struct askpass_ctx actx, *ctx = &actx; const char *err; @@ -571,7 +572,8 @@ void modalfatalbox(const char *p, ...) int main(int argc, char **argv) { - int success, exitcode; + bool success; + int exitcode; char *ret; gtk_init(&argc, &argv); diff --git a/unix/gtkcfg.c b/unix/gtkcfg.c index bbde8d2a..8b0ea31f 100644 --- a/unix/gtkcfg.c +++ b/unix/gtkcfg.c @@ -18,7 +18,7 @@ static void about_handler(union control *ctrl, dlgparam *dlg, } } -void gtk_setup_config_box(struct controlbox *b, int midsession, void *win) +void gtk_setup_config_box(struct controlbox *b, bool midsession, void *win) { struct controlset *s, *s2; union control *c; diff --git a/unix/gtkcols.c b/unix/gtkcols.c index fe8005f5..4b963f6e 100644 --- a/unix/gtkcols.c +++ b/unix/gtkcols.c @@ -331,7 +331,7 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget) ColumnsChild *child; GtkWidget *childw; GList *children; - gboolean was_visible; + bool was_visible; g_return_if_fail(container != NULL); g_return_if_fail(IS_COLUMNS(container)); diff --git a/unix/gtkcols.h b/unix/gtkcols.h index b7410cb4..32653b8d 100644 --- a/unix/gtkcols.h +++ b/unix/gtkcols.h @@ -41,7 +41,7 @@ struct ColumnsChild_tag { /* If `widget' is non-NULL, this entry represents an actual widget. */ GtkWidget *widget; gint colstart, colspan; - gboolean force_left; /* for recalcitrant GtkLabels */ + bool force_left; /* for recalcitrant GtkLabels */ ColumnsChild *same_height_as; /* Otherwise, this entry represents a change in the column setup. */ gint ncols; diff --git a/unix/gtkcomm.c b/unix/gtkcomm.c index 15da36d5..6100990e 100644 --- a/unix/gtkcomm.c +++ b/unix/gtkcomm.c @@ -199,7 +199,7 @@ void timer_change_notify(unsigned long next) */ static guint toplevel_callback_idle_id; -static int idle_fn_scheduled; +static bool idle_fn_scheduled; static void notify_toplevel_callback(void *); diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index d988f9fb..d2fd6f64 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -79,7 +79,10 @@ struct uctrl { struct dlgparam { tree234 *byctrl, *bywidget; void *data; - struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */ + struct { + unsigned char r, g, b; /* 0-255 */ + bool ok; + } coloursel_result; /* `flags' are set to indicate when a GTK signal handler is being called * due to automatic processing and should not flag a user event. */ int flags; @@ -281,14 +284,14 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp) return 0; /* got to return something */ } -void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked) +void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked) { struct uctrl *uc = dlg_find_byctrl(dp, ctrl); assert(uc->ctrl->generic.type == CTRL_CHECKBOX); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc->toplevel), checked); } -int dlg_checkbox_get(union control *ctrl, dlgparam *dp) +bool dlg_checkbox_get(union control *ctrl, dlgparam *dp) { struct uctrl *uc = dlg_find_byctrl(dp, ctrl); assert(uc->ctrl->generic.type == CTRL_CHECKBOX); @@ -707,7 +710,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp) return -1; /* placate dataflow analysis */ } -int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) +bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) { struct uctrl *uc = dlg_find_byctrl(dp, ctrl); @@ -748,7 +751,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) if (uc->treeview) { GtkTreeSelection *treesel; GtkTreePath *path; - int ret; + bool ret; assert(uc->treeview != NULL); treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview)); @@ -761,7 +764,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) } #endif assert(!"We shouldn't get here"); - return -1; /* placate dataflow analysis */ + return false; /* placate dataflow analysis */ } void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index) @@ -790,7 +793,7 @@ void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index) items = gtk_container_children(GTK_CONTAINER(uc->list)); nitems = g_list_length(items); if (nitems > 0) { - int modified = false; + bool modified = false; g_list_free(items); newtop = uc->adj->lower + (uc->adj->upper - uc->adj->lower) * index / nitems; @@ -1181,16 +1184,16 @@ void dlg_coloursel_start(union control *ctrl, dlgparam *dp, int r, int g, int b) gtk_widget_show(coloursel); } -int dlg_coloursel_results(union control *ctrl, dlgparam *dp, - int *r, int *g, int *b) +bool dlg_coloursel_results(union control *ctrl, dlgparam *dp, + int *r, int *g, int *b) { if (dp->coloursel_result.ok) { *r = dp->coloursel_result.r; *g = dp->coloursel_result.g; *b = dp->coloursel_result.b; - return 1; + return true; } else - return 0; + return false; } /* ---------------------------------------------------------------------- @@ -1279,7 +1282,7 @@ static gboolean editbox_lostfocus(GtkWidget *ed, GdkEventFocus *event, */ static gboolean listitem_key(GtkWidget *item, GdkEventKey *event, - gpointer data, int multiple) + gpointer data, bool multiple) { GtkAdjustment *adj = GTK_ADJUSTMENT(data); @@ -1877,7 +1880,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, for (i = 0; i < s->ncontrols; i++) { union control *ctrl = s->ctrls[i]; struct uctrl *uc; - int left = false; + bool left = false; GtkWidget *w = NULL; switch (ctrl->generic.type) { @@ -2555,7 +2558,7 @@ static void treeitem_sel(GtkItem *item, gpointer data) #endif #if !GTK_CHECK_VERSION(2,0,0) -static int tree_grab_focus(struct dlgparam *dp) +static bool tree_grab_focus(struct dlgparam *dp) { int i, f; @@ -2592,7 +2595,7 @@ gint tree_focus(GtkContainer *container, GtkDirectionType direction, } #endif -int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) +gint win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) { struct dlgparam *dp = (struct dlgparam *)data; @@ -2717,7 +2720,7 @@ int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) } #if !GTK_CHECK_VERSION(2,0,0) -int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) +gint tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) { struct dlgparam *dp = (struct dlgparam *)data; @@ -2742,7 +2745,7 @@ int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) */ { GtkWidget *w = dp->treeitems[i]; - int vis = true; + bool vis = true; while (w && (GTK_IS_TREE_ITEM(w) || GTK_IS_TREE(w))) { if (!GTK_WIDGET_VISIBLE(w)) { vis = false; @@ -2893,7 +2896,7 @@ void treeview_map_event(GtkWidget *tree, gpointer data) #endif GtkWidget *create_config_box(const char *title, Conf *conf, - int midsession, int protcfginfo, + bool midsession, int protcfginfo, post_dialog_fn_t after, void *afterctx) { GtkWidget *window, *hbox, *vbox, *cols, *label, @@ -2999,7 +3002,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf, #else GtkWidget *treeitem; #endif - int first; + bool first; /* * We expect never to find an implicit path @@ -3213,7 +3216,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf, */ for (index = 0; index < dp->ctrlbox->nctrlsets; index++) { struct controlset *s = dp->ctrlbox->ctrlsets[index]; - int done = 0; + bool done = false; int j; if (*s->pathname) { @@ -3223,7 +3226,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf, s->ctrls[j]->generic.type != CTRL_TEXT) { dlg_set_focus(s->ctrls[j], dp); dp->lastfocus = s->ctrls[j]; - done = 1; + done = true; break; } } @@ -3280,7 +3283,7 @@ const struct message_box_buttons buttons_ok = { GtkWidget *create_message_box( GtkWidget *parentwin, const char *title, const char *msg, int minwid, - int selectable, const struct message_box_buttons *buttons, + bool selectable, const struct message_box_buttons *buttons, post_dialog_fn_t after, void *afterctx) { GtkWidget *window, *w0, *w1; @@ -3770,7 +3773,7 @@ struct eventlog_stuff { int ninitial, ncircular, circular_first; char *seldata; int sellen; - int ignore_selchange; + bool ignore_selchange; }; static void eventlog_destroy(GtkWidget *widget, gpointer data) @@ -3887,7 +3890,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata, * Deselect everything in the list box. */ uc = dlg_find_byctrl(&es->dp, es->listctrl); - es->ignore_selchange = 1; + es->ignore_selchange = true; #if !GTK_CHECK_VERSION(2,0,0) assert(uc->list); gtk_list_unselect_all(GTK_LIST(uc->list)); @@ -3896,7 +3899,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata, gtk_tree_selection_unselect_all (gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview))); #endif - es->ignore_selchange = 0; + es->ignore_selchange = false; sfree(es->seldata); es->sellen = 0; diff --git a/unix/gtkfont.c b/unix/gtkfont.c index 074b61f9..ad29034e 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -73,22 +73,23 @@ struct UnifontVtable { /* * `Methods' of the `class'. */ - unifont *(*create)(GtkWidget *widget, const char *name, int wide, int bold, - int shadowoffset, int shadowalways); - unifont *(*create_fallback)(GtkWidget *widget, int height, int wide, - int bold, int shadowoffset, int shadowalways); + unifont *(*create)(GtkWidget *widget, const char *name, bool wide, + bool bold, int shadowoffset, bool shadowalways); + unifont *(*create_fallback)(GtkWidget *widget, int height, bool wide, + bool bold, int shadowoffset, + bool shadowalways); void (*destroy)(unifont *font); - int (*has_glyph)(unifont *font, wchar_t glyph); + bool (*has_glyph)(unifont *font, wchar_t glyph); void (*draw_text)(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); void (*draw_combining)(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); void (*enum_fonts)(GtkWidget *widget, fontsel_add_entry callback, void *callback_ctx); char *(*canonify_fontname)(GtkWidget *widget, const char *name, int *size, - int *flags, int resolve_aliases); + int *flags, bool resolve_aliases); char *(*scale_fontname)(GtkWidget *widget, const char *name, int size); char *(*size_increment)(unifont *font, int increment); @@ -106,22 +107,23 @@ struct UnifontVtable { * back end other than X). */ -static int x11font_has_glyph(unifont *font, wchar_t glyph); +static bool x11font_has_glyph(unifont *font, wchar_t glyph); static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, int cellwidth); + int len, bool wide, bool bold, + int cellwidth); static unifont *x11font_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways); + bool wide, bool bold, + int shadowoffset, bool shadowalways); static void x11font_destroy(unifont *font); static void x11font_enum_fonts(GtkWidget *widget, fontsel_add_entry callback, void *callback_ctx); static char *x11font_canonify_fontname(GtkWidget *widget, const char *name, int *size, int *flags, - int resolve_aliases); + bool resolve_aliases); static char *x11font_scale_fontname(GtkWidget *widget, const char *name, int size); static char *x11font_size_increment(unifont *font, int increment); @@ -147,7 +149,7 @@ typedef struct x11font_individual { * haven't tried yet from xfs==NULL because we tried and failed, * so that we don't keep trying and failing subsequently). */ - int allocated; + bool allocated; #ifdef DRAW_TEXT_CAIRO /* @@ -190,13 +192,13 @@ struct x11font { * values larger than a byte. That is, this flag tells us * whether we use XDrawString or XDrawString16, etc. */ - int sixteen_bit; + bool sixteen_bit; /* * `variable' is true iff the font is non-fixed-pitch. This * enables some code which takes greater care over character * positioning during text drawing. */ - int variable; + bool variable; /* * real_charset is the charset used when translating text into the * font's internal encoding inside draw_text(). This need not be @@ -208,7 +210,8 @@ struct x11font { /* * Data passed in to unifont_create(). */ - int wide, bold, shadowoffset, shadowalways; + int shadowoffset; + bool wide, bold, shadowalways; unifont u; }; @@ -312,7 +315,7 @@ static char *xlfd_recompose(const struct xlfd_decomposed *dec) } static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs, - int bold, int wide) + bool bold, bool wide) { Atom fontprop = XInternAtom(disp, "FONT", False); unsigned long ret; @@ -343,7 +346,7 @@ static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs, return NULL; } -static int x11_font_width(XFontStruct *xfs, int sixteen_bit) +static int x11_font_width(XFontStruct *xfs, bool sixteen_bit) { if (sixteen_bit) { XChar2b space; @@ -406,7 +409,7 @@ static const XCharStruct *x11_char_struct( return &xfs->per_char[index]; } -static int x11_font_has_glyph( +static bool x11_font_has_glyph( XFontStruct *xfs, unsigned char byte1, unsigned char byte2) { /* @@ -426,15 +429,16 @@ static int x11_font_has_glyph( } static unifont *x11font_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways) + bool wide, bool bold, + int shadowoffset, bool shadowalways) { struct x11font *xfont; XFontStruct *xfs; Display *disp; Atom charset_registry, charset_encoding, spacing; unsigned long registry_ret, encoding_ret, spacing_ret; - int pubcs, realcs, sixteen_bit, variable; + int pubcs, realcs; + bool sixteen_bit, variable; int i; if ((disp = get_x11_display()) == NULL) @@ -577,7 +581,7 @@ static void x11_alloc_subfont(struct x11font *xfont, int sfid) /* Note that xfont->fonts[sfid].xfs may still be NULL, if XLQF failed. */ } -static int x11font_has_glyph(unifont *font, wchar_t glyph) +static bool x11font_has_glyph(unifont *font, wchar_t glyph) { struct x11font *xfont = container_of(font, struct x11font, u); @@ -851,9 +855,10 @@ static void x11font_really_draw_text( const struct x11font_drawfuncs *dfns, unifont_drawctx *ctx, x11font_individual *xfi, Display *disp, int x, int y, const void *string, int nchars, - int shadowoffset, int fontvariable, int cellwidth) + int shadowoffset, bool fontvariable, int cellwidth) { - int start = 0, step, nsteps, centre; + int start = 0, step, nsteps; + bool centre; if (fontvariable) { /* @@ -891,7 +896,7 @@ static void x11font_really_draw_text( static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth) + bool wide, bool bold, int cellwidth) { struct x11font *xfont = container_of(font, struct x11font, u); int sfid; @@ -899,8 +904,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, int mult = (wide ? 2 : 1); int index = 2 * (int)ctx->type; - wide -= xfont->wide; - bold -= xfont->bold; + wide = wide && !xfont->wide; + bold = bold && !xfont->bold; /* * Decide which subfont we're using, and whether we have to @@ -908,13 +913,13 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, */ if (xfont->shadowalways && bold) { shadowoffset = xfont->shadowoffset; - bold = 0; + bold = false; } sfid = 2 * wide + bold; if (!xfont->fonts[sfid].allocated) x11_alloc_subfont(xfont, sfid); if (bold && !xfont->fonts[sfid].xfs) { - bold = 0; + bold = false; shadowoffset = xfont->shadowoffset; sfid = 2 * wide + bold; if (!xfont->fonts[sfid].allocated) @@ -961,7 +966,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, int cellwidth) + int len, bool wide, bool bold, + int cellwidth) { /* * For server-side fonts, there's no sophisticated system for @@ -1138,7 +1144,7 @@ static void x11font_enum_fonts(GtkWidget *widget, static char *x11font_canonify_fontname(GtkWidget *widget, const char *name, int *size, int *flags, - int resolve_aliases) + bool resolve_aliases) { /* * When given an X11 font name to try to make sense of for a @@ -1298,26 +1304,26 @@ static char *x11font_size_increment(unifont *font, int increment) #define PANGO_PRE_1POINT6 /* make life easier for pre-1.4 folk */ #endif -static int pangofont_has_glyph(unifont *font, wchar_t glyph); +static bool pangofont_has_glyph(unifont *font, wchar_t glyph); static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, + int len, bool wide, bool bold, int cellwidth); static unifont *pangofont_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways); + bool wide, bool bold, + int shadowoffset, bool shadowalways); static unifont *pangofont_create_fallback(GtkWidget *widget, int height, - int wide, int bold, - int shadowoffset, int shadowalways); + bool wide, bool bold, + int shadowoffset, bool shadowalways); static void pangofont_destroy(unifont *font); static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback, void *callback_ctx); static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name, int *size, int *flags, - int resolve_aliases); + bool resolve_aliases); static char *pangofont_scale_fontname(GtkWidget *widget, const char *name, int size); static char *pangofont_size_increment(unifont *font, int increment); @@ -1335,7 +1341,8 @@ struct pangofont { /* * Data passed in to unifont_create(). */ - int bold, shadowoffset, shadowalways; + int shadowoffset; + bool bold, shadowalways; /* * Cache of character widths, indexed by Unicode code point. In * pixels; -1 means we haven't asked Pango about this character @@ -1374,14 +1381,15 @@ static const struct UnifontVtable pangofont_vtable = { * if it doesn't. So we check that the font family is actually one * supported by Pango. */ -static int pangofont_check_desc_makes_sense(PangoContext *ctx, - PangoFontDescription *desc) +static bool pangofont_check_desc_makes_sense(PangoContext *ctx, + PangoFontDescription *desc) { #ifndef PANGO_PRE_1POINT6 PangoFontMap *map; #endif PangoFontFamily **families; - int i, nfamilies, matched; + int i, nfamilies; + bool matched; /* * Ask Pango for a list of font families, and iterate through @@ -1413,8 +1421,8 @@ static int pangofont_check_desc_makes_sense(PangoContext *ctx, static unifont *pangofont_create_internal(GtkWidget *widget, PangoContext *ctx, PangoFontDescription *desc, - int wide, int bold, - int shadowoffset, int shadowalways) + bool wide, bool bold, + int shadowoffset, bool shadowalways) { struct pangofont *pfont; #ifndef PANGO_PRE_1POINT6 @@ -1479,8 +1487,8 @@ static unifont *pangofont_create_internal(GtkWidget *widget, } static unifont *pangofont_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways) + bool wide, bool bold, + int shadowoffset, bool shadowalways) { PangoContext *ctx; PangoFontDescription *desc; @@ -1502,8 +1510,8 @@ static unifont *pangofont_create(GtkWidget *widget, const char *name, } static unifont *pangofont_create_fallback(GtkWidget *widget, int height, - int wide, int bold, - int shadowoffset, int shadowalways) + bool wide, bool bold, + int shadowoffset, bool shadowalways) { PangoContext *ctx; PangoFontDescription *desc; @@ -1559,7 +1567,7 @@ static int pangofont_char_width(PangoLayout *layout, struct pangofont *pfont, return pfont->widthcache[uchr]; } -static int pangofont_has_glyph(unifont *font, wchar_t glyph) +static bool pangofont_has_glyph(unifont *font, wchar_t glyph) { /* Pango implements font fallback, so assume it has everything */ return true; @@ -1584,15 +1592,15 @@ static void pango_cairo_draw_layout(unifont_drawctx *ctx, static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, int cellwidth, - int combining) + int len, bool wide, bool bold, + int cellwidth, bool combining) { struct pangofont *pfont = container_of(font, struct pangofont, u); PangoLayout *layout; PangoRectangle rect; char *utfstring, *utfptr; int utflen; - int shadowbold = false; + bool shadowbold = false; void (*draw_layout)(unifont_drawctx *ctx, gint x, gint y, PangoLayout *layout) = NULL; @@ -1614,7 +1622,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font, layout = pango_layout_new(gtk_widget_get_pango_context(pfont->widget)); pango_layout_set_font_description(layout, pfont->desc); - if (bold > pfont->bold) { + if (bold && !pfont->bold) { if (pfont->shadowalways) shadowbold = true; else { @@ -1740,7 +1748,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font, static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth) + bool wide, bool bold, int cellwidth) { pangofont_draw_internal(ctx, font, x, y, string, len, wide, bold, cellwidth, false); @@ -1748,7 +1756,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font, static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, + int len, bool wide, bool bold, int cellwidth) { wchar_t *tmpstring = NULL; @@ -1932,7 +1940,7 @@ static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback, static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name, int *size, int *flags, - int resolve_aliases) + bool resolve_aliases) { /* * When given a Pango font name to try to make sense of for a @@ -2112,8 +2120,8 @@ static const char *unifont_do_prefix(const char *name, int *start, int *end) } } -unifont *unifont_create(GtkWidget *widget, const char *name, int wide, - int bold, int shadowoffset, int shadowalways) +unifont *unifont_create(GtkWidget *widget, const char *name, bool wide, + bool bold, int shadowoffset, bool shadowalways) { int i, start, end; @@ -2135,14 +2143,14 @@ void unifont_destroy(unifont *font) void unifont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth) + bool wide, bool bold, int cellwidth) { font->vt->draw_text(ctx, font, x, y, string, len, wide, bold, cellwidth); } void unifont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth) + bool wide, bool bold, int cellwidth) { font->vt->draw_combining(ctx, font, x, y, string, len, wide, bold, cellwidth); @@ -2168,10 +2176,10 @@ char *unifont_size_increment(unifont *font, int increment) static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, + int len, bool wide, bool bold, int cellwidth); static void multifont_destroy(unifont *font); static char *multifont_size_increment(unifont *font, int increment); @@ -2198,8 +2206,8 @@ static const struct UnifontVtable multifont_vtable = { }; unifont *multifont_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways) + bool wide, bool bold, + int shadowoffset, bool shadowalways) { int i; unifont *font, *fallback; @@ -2253,17 +2261,18 @@ static void multifont_destroy(unifont *font) typedef void (*unifont_draw_func_t)(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, + int len, bool wide, bool bold, int cellwidth); static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth, + bool wide, bool bold, int cellwidth, int cellinc, unifont_draw_func_t draw) { struct multifont *mfont = container_of(font, struct multifont, u); unifont *f; - int ok, i; + bool ok; + int i; while (len > 0) { /* @@ -2290,7 +2299,7 @@ static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x, static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth) + bool wide, bool bold, int cellwidth) { multifont_draw_main(ctx, font, x, y, string, len, wide, bold, cellwidth, cellwidth, unifont_draw_text); @@ -2298,7 +2307,7 @@ static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x, static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, - int len, int wide, int bold, + int len, bool wide, bool bold, int cellwidth) { multifont_draw_main(ctx, font, x, y, string, len, wide, bold, @@ -2335,7 +2344,7 @@ typedef struct unifontsel_internal { tree234 *fonts_by_realname, *fonts_by_selorder; fontinfo *selected; int selsize, intendedsize; - int inhibit_response; /* inhibit callbacks when we change GUI controls */ + bool inhibit_response; /* inhibit callbacks when we change GUI controls */ unifontsel u; } unifontsel_internal; @@ -2529,7 +2538,8 @@ static void unifontsel_setup_stylelist(unifontsel_internal *fs, int start, int end) { GtkTreeIter iter; - int i, listindex, minpos = -1, maxpos = -1, started = false; + int i, listindex, minpos = -1, maxpos = -1; + bool started = false; char *currcs = NULL, *currstyle = NULL; fontinfo *info; @@ -2808,7 +2818,7 @@ static void unifontsel_draw_preview_text(unifontsel_internal *fs) static void unifontsel_select_font(unifontsel_internal *fs, fontinfo *info, int size, int leftlist, - int size_is_explicit) + bool size_is_explicit) { int index; int minval, maxval; @@ -2946,7 +2956,7 @@ static void unifontsel_select_font(unifontsel_internal *fs, static void unifontsel_button_toggled(GtkToggleButton *tb, gpointer data) { unifontsel_internal *fs = (unifontsel_internal *)data; - int newstate = gtk_toggle_button_get_active(tb); + bool newstate = gtk_toggle_button_get_active(tb); int newflags; int flagbit = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tb), "user-data")); diff --git a/unix/gtkfont.h b/unix/gtkfont.h index 249828b4..ff91929e 100644 --- a/unix/gtkfont.h +++ b/unix/gtkfont.h @@ -74,7 +74,7 @@ typedef struct unifont { * missing glyphs from other fonts), or whether it would like a * fallback font to cope with missing glyphs. */ - int want_fallback; + bool want_fallback; /* * Preferred drawing API to use when this class of font is active. @@ -134,18 +134,18 @@ typedef struct unifont_drawctx { } unifont_drawctx; unifont *unifont_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways); + bool wide, bool bold, + int shadowoffset, bool shadowalways); void unifont_destroy(unifont *font); void unifont_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); /* Same as unifont_draw_text, but expects 'string' to contain one * normal char plus combining chars, and overdraws them all in the * same character cell. */ void unifont_draw_combining(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, - int wide, int bold, int cellwidth); + bool wide, bool bold, int cellwidth); /* Return a name that will select a bigger/smaller font than this one, * or NULL if no such name is available. */ char *unifont_size_increment(unifont *font, int increment); @@ -159,8 +159,8 @@ char *unifont_size_increment(unifont *font, int increment); * as if it were an ordinary unifont. */ unifont *multifont_create(GtkWidget *widget, const char *name, - int wide, int bold, - int shadowoffset, int shadowalways); + bool wide, bool bold, + int shadowoffset, bool shadowalways); /* * Unified font selector dialog. I can't be bothered to do a diff --git a/unix/gtkmain.c b/unix/gtkmain.c index cacf56b8..e51b5c43 100644 --- a/unix/gtkmain.c +++ b/unix/gtkmain.c @@ -48,7 +48,7 @@ static char *progname, **gtkargvstart; static int ngtkargs; extern char **pty_argv; /* declared in pty.c */ -extern int use_pty_argv; +extern bool use_pty_argv; static const char *app_name = "pterm"; @@ -312,9 +312,9 @@ void window_setup_error(const char *errmsg) exit(1); } -int do_cmdline(int argc, char **argv, int do_everything, Conf *conf) +bool do_cmdline(int argc, char **argv, bool do_everything, Conf *conf) { - int err = 0; + bool err = false; char *val; /* @@ -327,7 +327,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf) */ #define EXPECTS_ARG { \ if (--argc <= 0) { \ - err = 1; \ + err = true; \ fprintf(stderr, "%s: %s expects an argument\n", appname, p); \ continue; \ } else \ @@ -417,14 +417,14 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf) { #if GTK_CHECK_VERSION(3,0,0) GdkRGBA rgba; - int success = gdk_rgba_parse(&rgba, val); + bool success = gdk_rgba_parse(&rgba, val); #else GdkColor col; - int success = gdk_color_parse(val, &col); + bool success = gdk_color_parse(val, &col); #endif if (!success) { - err = 1; + err = true; fprintf(stderr, "%s: unable to parse colour \"%s\"\n", appname, val); } else { @@ -467,7 +467,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf) pty_argv[argc] = NULL; break; /* finished command-line processing */ } else - err = 1, fprintf(stderr, "%s: -e expects an argument\n", + err = true, fprintf(stderr, "%s: -e expects an argument\n", appname); } else if (!strcmp(p, "-title")) { @@ -535,13 +535,13 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf) } else if (p[0] != '-') { /* Non-option arguments not handled by cmdline.c are errors. */ if (do_everything) { - err = 1; + err = true; fprintf(stderr, "%s: unexpected non-option argument '%s'\n", appname, p); } } else { - err = 1; + err = true; fprintf(stderr, "%s: unrecognized option '%s'\n", appname, p); } } @@ -554,7 +554,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend) return gtk_window_new(GTK_WINDOW_TOPLEVEL); } -const int buildinfo_gtk_relevant = true; +const bool buildinfo_gtk_relevant = true; struct post_initial_config_box_ctx { Conf *conf; @@ -586,14 +586,14 @@ void session_window_closed(void) int main(int argc, char **argv) { Conf *conf; - int need_config_box; + bool need_config_box; setlocale(LC_CTYPE, ""); { /* Call the function in ux{putty,pterm}.c to do app-type * specific setup */ - extern void setup(int); + extern void setup(bool); setup(true); /* true means we are a one-session process */ } @@ -623,10 +623,10 @@ int main(int argc, char **argv) * terminating the main pterm/PuTTY. However, we'll have to * unblock it again when pterm forks. */ - block_signal(SIGPIPE, 1); + block_signal(SIGPIPE, true); if (argc > 1 && !strncmp(argv[1], "---", 3)) { - extern const int dup_check_launchable; + extern const bool dup_check_launchable; read_dupsession_data(conf, argv[1]); /* Splatter this argument so it doesn't clutter a ps listing */ @@ -635,10 +635,10 @@ int main(int argc, char **argv) assert(!dup_check_launchable || conf_launchable(conf)); need_config_box = false; } else { - if (do_cmdline(argc, argv, 0, conf)) + if (do_cmdline(argc, argv, false, conf)) exit(1); /* pre-defaults pass to get -class */ do_defaults(NULL, conf); - if (do_cmdline(argc, argv, 1, conf)) + if (do_cmdline(argc, argv, true, conf)) exit(1); /* post-defaults, do everything */ cmdline_run_saved(conf); diff --git a/unix/gtkmisc.c b/unix/gtkmisc.c index 05379415..c0c9682a 100644 --- a/unix/gtkmisc.c +++ b/unix/gtkmisc.c @@ -190,8 +190,7 @@ GtkBox *our_dialog_make_action_hbox(GtkWindow *dlg) } void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w, - gboolean expand, gboolean fill, - guint padding) + bool expand, bool fill, guint padding) { #if GTK_CHECK_VERSION(3,0,0) /* GtkWindow is a GtkBin, hence contains exactly one child, which diff --git a/unix/gtkmisc.h b/unix/gtkmisc.h index e670d9d4..3d2d1f36 100644 --- a/unix/gtkmisc.h +++ b/unix/gtkmisc.h @@ -12,8 +12,7 @@ void align_label_left(GtkLabel *label); GtkWidget *our_dialog_new(void); void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w, - gboolean expand, gboolean fill, - guint padding); + bool expand, bool fill, guint padding); void our_dialog_set_action_area(GtkWindow *dlg, GtkWidget *w); GtkBox *our_dialog_make_action_hbox(GtkWindow *dlg); diff --git a/unix/gtkwin.c b/unix/gtkwin.c index f88cba75..67068f06 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -133,13 +133,14 @@ struct GtkFrontend { GtkIMContext *imc; #endif unifont *fonts[4]; /* normal, bold, wide, widebold */ - int xpos, ypos, gotpos, gravity; + int xpos, ypos, gravity; + bool gotpos; GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor; GdkColor cols[NALLCOLOURS]; #if !GTK_CHECK_VERSION(3,0,0) GdkColormap *colmap; #endif - int direct_to_font; + bool direct_to_font; struct clipboard_state clipstates[N_CLIPBOARDS]; #ifdef JUST_USE_GTK_CLIPBOARD_UTF8 /* Remember all clipboard_data_instance structures currently @@ -150,8 +151,8 @@ struct GtkFrontend { int clipboard_ctrlshiftins, clipboard_ctrlshiftcv; int font_width, font_height; int width, height, scale; - int ignore_sbar; - int mouseptr_visible; + bool ignore_sbar; + bool mouseptr_visible; BusyStatus busy_status; int alt_keycode; int alt_digits; @@ -162,7 +163,7 @@ struct GtkFrontend { Backend *backend; Terminal *term; LogContext *logctx; - int exited; + bool exited; struct unicode_data ucsdata; Conf *conf; eventlog_stuff *eventlogstuff; @@ -204,7 +205,7 @@ static void cache_conf_values(GtkFrontend *inst) #endif } -static int send_raw_mouse; +static bool send_raw_mouse; static void start_backend(GtkFrontend *inst); static void exit_callback(void *vinst); @@ -314,14 +315,14 @@ static char *gtk_seat_get_ttymode(Seat *seat, const char *mode) return term_get_ttymode(inst->term, mode); } -static int gtk_seat_output(Seat *seat, int is_stderr, +static int gtk_seat_output(Seat *seat, bool is_stderr, const void *data, int len) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); return term_data(inst->term, is_stderr, data, len); } -static int gtk_seat_eof(Seat *seat) +static bool gtk_seat_eof(Seat *seat) { /* GtkFrontend *inst = container_of(seat, GtkFrontend, seat); */ return true; /* do respond to incoming EOF with outgoing */ @@ -338,13 +339,13 @@ static int gtk_seat_get_userpass_input(Seat *seat, prompts_t *p, return ret; } -static int gtk_seat_is_utf8(Seat *seat) +static bool gtk_seat_is_utf8(Seat *seat) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); return win_is_utf8(&inst->termwin); } -static int gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h) +static bool gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); win_get_pixels(&inst->termwin, w, h); @@ -356,7 +357,7 @@ static void gtk_seat_update_specials_menu(Seat *seat); static void gtk_seat_set_busy_status(Seat *seat, BusyStatus status); static const char *gtk_seat_get_x_display(Seat *seat); #ifndef NOT_X_WINDOWS -static int gtk_seat_get_windowid(Seat *seat, long *id); +static bool gtk_seat_get_windowid(Seat *seat, long *id); #endif static const SeatVtable gtk_seat_vt = { @@ -469,7 +470,7 @@ void unregister_dialog(Seat *seat, enum DialogSlot slot) * Minimise or restore the window in response to a server-side * request. */ -static void gtkwin_set_minimised(TermWin *tw, int minimised) +static void gtkwin_set_minimised(TermWin *tw, bool minimised) { /* * GTK 1.2 doesn't know how to do this. @@ -507,7 +508,7 @@ static void gtkwin_move(TermWin *tw, int x, int y) * Move the window to the top or bottom of the z-order in response * to a server-side request. */ -static void gtkwin_set_zorder(TermWin *tw, int top) +static void gtkwin_set_zorder(TermWin *tw, bool top) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); if (top) @@ -529,7 +530,7 @@ static void gtkwin_refresh(TermWin *tw) * Maximise or restore the window in response to a server-side * request. */ -static void gtkwin_set_maximised(TermWin *tw, int maximised) +static void gtkwin_set_maximised(TermWin *tw, bool maximised) { /* * GTK 1.2 doesn't know how to do this. @@ -546,7 +547,7 @@ static void gtkwin_set_maximised(TermWin *tw, int maximised) /* * Report whether the window is minimised, for terminal reports. */ -static int gtkwin_is_minimised(TermWin *tw) +static bool gtkwin_is_minimised(TermWin *tw) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); return !gdk_window_is_viewable(gtk_widget_get_window(inst->window)); @@ -594,7 +595,7 @@ static void gtkwin_get_pixels(TermWin *tw, int *x, int *y) * raise it, so that the user realises they've already been asked this * question. */ -static int find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot) +static bool find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot) { GtkWidget *dialog = inst->dialogs[slot]; if (!dialog) @@ -610,7 +611,7 @@ static int find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot) /* * Return the window or icon title. */ -static const char *gtkwin_get_title(TermWin *tw, int icon) +static const char *gtkwin_get_title(TermWin *tw, bool icon) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); return icon ? inst->icontitle : inst->wintitle; @@ -683,10 +684,10 @@ static void update_mouseptr(GtkFrontend *inst) } } -static void show_mouseptr(GtkFrontend *inst, int show) +static void show_mouseptr(GtkFrontend *inst, bool show) { if (!conf_get_bool(inst->conf, CONF_hide_mouseptr)) - show = 1; + show = true; inst->mouseptr_visible = show; update_mouseptr(inst); } @@ -695,7 +696,8 @@ static void draw_backing_rect(GtkFrontend *inst); static void drawing_area_setup(GtkFrontend *inst, int width, int height) { - int w, h, new_scale, need_size = 0; + int w, h, new_scale; + bool need_size = false; /* * See if the terminal size has changed. @@ -979,7 +981,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) GtkFrontend *inst = (GtkFrontend *)data; char output[256]; wchar_t ucsoutput[2]; - int ucsval, start, end, special, output_charset, use_ucsoutput; + int ucsval, start, end, output_charset; + bool special, use_ucsoutput; bool nethack_mode, app_keypad_mode; bool generated_something = false; @@ -1327,8 +1330,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) (event->keyval == GDK_KEY_C || event->keyval == GDK_KEY_c || event->keyval == GDK_KEY_V || event->keyval == GDK_KEY_v)) { int cfgval = conf_get_int(inst->conf, CONF_ctrlshiftcv); - int paste = (event->keyval == GDK_KEY_V || - event->keyval == GDK_KEY_v); + bool paste = (event->keyval == GDK_KEY_V || + event->keyval == GDK_KEY_v); switch (cfgval) { case CLIPUI_IMPLICIT: @@ -1454,7 +1457,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) event->keyval == GDK_KEY_KP_Page_Up)) { /* nethack mode; do nothing */ } else { - int try_filter = true; + bool try_filter = true; #ifdef META_MANUAL_MASK if (event->state & META_MANUAL_MASK & inst->meta_mod_mask) { @@ -2129,7 +2132,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) output[end] = '\0'; /* NUL-terminate */ generated_something = true; if (inst->ldisc) - ldisc_send(inst->ldisc, output+start, -2, 1); + ldisc_send(inst->ldisc, output+start, -2, true); } else if (!inst->direct_to_font) { if (!use_ucsoutput) { #ifdef KEY_EVENT_DIAGNOSTICS @@ -2150,7 +2153,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) generated_something = true; if (inst->ldisc) lpage_send(inst->ldisc, output_charset, output+start, - end-start, 1); + end-start, true); } else { #ifdef KEY_EVENT_DIAGNOSTICS char *string_string = dupstr(""); @@ -2174,7 +2177,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) */ generated_something = true; if (inst->ldisc) - luni_send(inst->ldisc, ucsoutput+start, end-start, 1); + luni_send(inst->ldisc, ucsoutput+start, end-start, true); } } else { /* @@ -2198,10 +2201,10 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) #endif generated_something = true; if (inst->ldisc) - ldisc_send(inst->ldisc, output+start, end-start, 1); + ldisc_send(inst->ldisc, output+start, end-start, true); } - show_mouseptr(inst, 0); + show_mouseptr(inst, false); term_seen_key_event(inst->term); } @@ -2231,8 +2234,8 @@ void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data) #endif if (inst->ldisc) - lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1); - show_mouseptr(inst, 0); + lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), true); + show_mouseptr(inst, false); term_seen_key_event(inst->term); key_pressed(inst); } @@ -2244,9 +2247,10 @@ void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data) gboolean scroll_internal(GtkFrontend *inst, gdouble delta, guint state, gdouble ex, gdouble ey) { - int shift, ctrl, alt, x, y, raw_mouse_mode; + int x, y; + bool shift, ctrl, alt, raw_mouse_mode; - show_mouseptr(inst, 1); + show_mouseptr(inst, true); shift = state & GDK_SHIFT_MASK; ctrl = state & GDK_CONTROL_MASK; @@ -2295,12 +2299,13 @@ gboolean scroll_internal(GtkFrontend *inst, gdouble delta, guint state, static gboolean button_internal(GtkFrontend *inst, GdkEventButton *event) { - int shift, ctrl, alt, x, y, button, act, raw_mouse_mode; + bool shift, ctrl, alt, raw_mouse_mode; + int x, y, button, act; /* Remember the timestamp. */ inst->input_event_time = event->time; - show_mouseptr(inst, 1); + show_mouseptr(inst, true); shift = event->state & GDK_SHIFT_MASK; ctrl = event->state & GDK_CONTROL_MASK; @@ -2420,12 +2425,13 @@ gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) { GtkFrontend *inst = (GtkFrontend *)data; - int shift, ctrl, alt, x, y, button; + bool shift, ctrl, alt; + int x, y, button; /* Remember the timestamp. */ inst->input_event_time = event->time; - show_mouseptr(inst, 1); + show_mouseptr(inst, true); shift = event->state & GDK_SHIFT_MASK; ctrl = event->state & GDK_CONTROL_MASK; @@ -2583,7 +2589,7 @@ gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data) GtkFrontend *inst = (GtkFrontend *)data; term_set_focus(inst->term, event->in); term_update(inst->term); - show_mouseptr(inst, 1); + show_mouseptr(inst, true); return false; } @@ -2597,7 +2603,7 @@ static void gtk_seat_set_busy_status(Seat *seat, BusyStatus status) /* * set or clear the "raw mouse message" mode */ -static void gtkwin_set_raw_mouse_mode(TermWin *tw, int activate) +static void gtkwin_set_raw_mouse_mode(TermWin *tw, bool activate) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); activate = activate && !conf_get_bool(inst->conf, CONF_no_mouse_rep); @@ -2779,7 +2785,7 @@ static void gtkwin_palette_set(TermWin *tw, int n, int r, int g, int b) } } -static int gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b) +static bool gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); if (n < 0 || n >= NALLCOLOURS) @@ -2939,7 +2945,7 @@ static void clipboard_clear(GtkClipboard *clipboard, gpointer data) static void gtkwin_clip_write( TermWin *tw, int clipboard, wchar_t *data, int *attr, - truecolour *truecolour, int len, int must_deselect) + truecolour *truecolour, int len, bool must_deselect) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); struct clipboard_state *state = &inst->clipstates[clipboard]; @@ -3087,7 +3093,7 @@ static char *retrieve_cutbuffer(GtkFrontend *inst, int *nbytes) static void gtkwin_clip_write( TermWin *tw, int clipboard, wchar_t *data, int *attr, - truecolour *truecolour, int len, int must_deselect) + truecolour *truecolour, int len, bool must_deselect) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); struct clipboard_state *state = &inst->clipstates[clipboard]; @@ -3279,8 +3285,8 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata, int length; #ifndef NOT_X_WINDOWS char **list; - int free_list_required = 0; - int free_required = 0; + bool free_list_required = false; + bool free_required = false; #endif int charset; GdkAtom seldata_target = gtk_selection_data_get_target(seldata); @@ -3338,7 +3344,7 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata, /* Xterm is rumoured to expect Latin-1, though I havn't checked the * source, so use that as a de-facto standard. */ charset = CS_ISO8859_1; - free_required = 1; + free_required = true; #else return; #endif @@ -3361,7 +3367,7 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata, text = list[0]; length = strlen(list[0]); charset = CS_UTF8; - free_list_required = 1; + free_list_required = true; } else #endif { @@ -3572,7 +3578,7 @@ static int gtkwin_char_width(TermWin *tw, int uc) return 1; } -static int gtkwin_setup_draw_ctx(TermWin *tw) +static bool gtkwin_setup_draw_ctx(TermWin *tw) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); @@ -3649,7 +3655,7 @@ static void draw_update(GtkFrontend *inst, int x, int y, int w, int h) #ifdef DRAW_TEXT_CAIRO static void cairo_set_source_rgb_dim(cairo_t *cr, double r, double g, double b, - int dim) + bool dim) { if (dim) cairo_set_source_rgb(cr, r * 2 / 3, g * 2 / 3, b * 2 / 3); @@ -3658,7 +3664,7 @@ static void cairo_set_source_rgb_dim(cairo_t *cr, double r, double g, double b, } #endif -static void draw_set_colour(GtkFrontend *inst, int col, int dim) +static void draw_set_colour(GtkFrontend *inst, int col, bool dim) { #ifdef DRAW_TEXT_GDK if (inst->uctx.type == DRAWTYPE_GDK) { @@ -3688,7 +3694,7 @@ static void draw_set_colour(GtkFrontend *inst, int col, int dim) #endif } -static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, int dim) +static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, bool dim) { #ifdef DRAW_TEXT_GDK if (inst->uctx.type == DRAWTYPE_GDK) { @@ -3717,7 +3723,7 @@ static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, int dim) #endif } -static void draw_rectangle(GtkFrontend *inst, int filled, +static void draw_rectangle(GtkFrontend *inst, bool filled, int x, int y, int w, int h) { #ifdef DRAW_TEXT_GDK @@ -3801,8 +3807,8 @@ static void draw_line(GtkFrontend *inst, int x0, int y0, int x1, int y1) } static void draw_stretch_before(GtkFrontend *inst, int x, int y, - int w, int wdouble, - int h, int hdouble, int hbothalf) + int w, bool wdouble, + int h, bool hdouble, bool hbothalf) { #ifdef DRAW_TEXT_CAIRO if (inst->uctx.type == DRAWTYPE_CAIRO) { @@ -3836,8 +3842,8 @@ static void draw_stretch_before(GtkFrontend *inst, int x, int y, } static void draw_stretch_after(GtkFrontend *inst, int x, int y, - int w, int wdouble, - int h, int hdouble, int hbothalf) + int w, bool wdouble, + int h, bool hdouble, bool hbothalf) { #ifdef DRAW_TEXT_GDK #ifndef NO_BACKING_PIXMAPS @@ -3902,7 +3908,7 @@ static void draw_backing_rect(GtkFrontend *inst) w = inst->width * inst->font_width + 2*inst->window_border; h = inst->height * inst->font_height + 2*inst->window_border; draw_set_colour(inst, 258, false); - draw_rectangle(inst, 1, 0, 0, w, h); + draw_rectangle(inst, true, 0, 0, w, h); draw_update(inst, 0, 0, w, h); win_free_draw_ctx(&inst->termwin); } @@ -3918,8 +3924,9 @@ static void do_text_internal( unsigned long attr, int lattr, truecolour truecolour) { int ncombining; - int nfg, nbg, t, fontid, shadow, rlen, widefactor, bold; - int monochrome = + int nfg, nbg, t, fontid, rlen, widefactor; + bool bold; + bool monochrome = gdk_visual_get_depth(gtk_widget_get_visual(inst->area)) == 1; if (attr & TATTR_COMBINING) { @@ -3959,7 +3966,7 @@ static void do_text_internal( attr &= ~ATTR_DIM; /* don't dim the cursor */ } - fontid = shadow = 0; + fontid = 0; if (attr & ATTR_WIDE) { widefactor = 2; @@ -3969,10 +3976,10 @@ static void do_text_internal( } if ((attr & ATTR_BOLD) && (inst->bold_style & 1)) { - bold = 1; + bold = true; fontid |= 1; } else { - bold = 0; + bold = false; } if (!inst->fonts[fontid]) { @@ -4104,18 +4111,19 @@ static void gtkwin_draw_cursor( unsigned long attr, int lattr, truecolour truecolour) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); - int active, passive, widefactor; + bool active, passive; + int widefactor; if (attr & TATTR_PASCURS) { attr &= ~TATTR_PASCURS; - passive = 1; + passive = true; } else - passive = 0; + passive = false; if ((attr & TATTR_ACTCURS) && inst->cursor_type != 0) { attr &= ~TATTR_ACTCURS; - active = 1; + active = true; } else - active = 0; + active = false; do_text_internal(inst, x, y, text, len, attr, lattr, truecolour); if (attr & TATTR_COMBINING) @@ -4257,7 +4265,7 @@ static const char *gtk_seat_get_x_display(Seat *seat) } #ifndef NOT_X_WINDOWS -static int gtk_seat_get_windowid(Seat *seat, long *id) +static bool gtk_seat_get_windowid(Seat *seat, long *id) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); GdkWindow *window = gtk_widget_get_window(inst->area); @@ -4268,7 +4276,7 @@ static int gtk_seat_get_windowid(Seat *seat, long *id) } #endif -static int gtkwin_is_utf8(TermWin *tw) +static bool gtkwin_is_utf8(TermWin *tw) { GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); return inst->ucsdata.line_codepage == CS_UTF8; @@ -4276,7 +4284,7 @@ static int gtkwin_is_utf8(TermWin *tw) char *setup_fonts_ucs(GtkFrontend *inst) { - int shadowbold = conf_get_bool(inst->conf, CONF_shadowbold); + bool shadowbold = conf_get_bool(inst->conf, CONF_shadowbold); int shadowboldoffset = conf_get_int(inst->conf, CONF_shadowboldoffset); FontSpec *fs; unifont *fonts[4]; @@ -4643,7 +4651,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) ctx->newconf = conf_copy(inst->conf); dialog = create_config_box( - title, ctx->newconf, 1, + title, ctx->newconf, true, inst->backend ? backend_cfg_info(inst->backend) : 0, after_change_settings_dialog, ctx); register_dialog(&inst->seat, DIALOG_SLOT_RECONFIGURE, dialog); @@ -4663,7 +4671,8 @@ static void after_change_settings_dialog(void *vctx, int retval) *(struct after_change_settings_dialog_ctx *)vctx; GtkFrontend *inst = ctx.inst; Conf *oldconf = inst->conf, *newconf = ctx.newconf; - int i, j, need_size; + int i, j; + bool need_size; sfree(vctx); /* we've copied this already */ @@ -5476,7 +5485,7 @@ void new_session_window(Conf *conf, const char *geometry_string) { GtkWidget *menuitem; char *s; - extern const int use_event_log, new_session, saved_sessions; + extern const bool use_event_log, new_session, saved_sessions; inst->menu = gtk_menu_new(); @@ -5552,7 +5561,7 @@ void new_session_window(Conf *conf, const char *geometry_string) inst->waitcursor = make_mouse_ptr(inst, GDK_WATCH); inst->blankcursor = make_mouse_ptr(inst, -1); inst->currcursor = inst->textcursor; - show_mouseptr(inst, 1); + show_mouseptr(inst, true); inst->eventlogstuff = eventlogstuff_new(); diff --git a/unix/unix.h b/unix/unix.h index 48e727b6..1ce587bd 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -49,7 +49,7 @@ * pure-CLI utilities, so that Unix Plink, PSFTP etc don't announce * themselves incongruously as having something to do with GTK. */ #define BUILDINFO_PLATFORM_CLI "Unix" -extern const int buildinfo_gtk_relevant; +extern const bool buildinfo_gtk_relevant; #define BUILDINFO_PLATFORM (buildinfo_gtk_relevant ? \ BUILDINFO_PLATFORM_GTK : BUILDINFO_PLATFORM_CLI) @@ -58,7 +58,7 @@ char *buildinfo_gtk_version(void); struct Filename { char *path; }; -FILE *f_open(const struct Filename *, char const *, int); +FILE *f_open(const struct Filename *, char const *, bool); struct FontSpec { char *name; /* may be "" to indicate no selected font at all */ @@ -207,7 +207,7 @@ void unregister_dialog(Seat *seat, enum DialogSlot slot); /* Things pterm.c needs from gtkdlg.c */ #ifdef MAY_REFER_TO_GTK_IN_HEADERS GtkWidget *create_config_box(const char *title, Conf *conf, - int midsession, int protcfginfo, + bool midsession, int protcfginfo, post_dialog_fn_t after, void *afterctx); #endif void nonfatal_message_box(void *window, const char *msg); @@ -243,7 +243,7 @@ struct message_box_buttons { extern const struct message_box_buttons buttons_yn, buttons_ok; GtkWidget *create_message_box( GtkWidget *parentwin, const char *title, const char *msg, int minwid, - int selectable, const struct message_box_buttons *buttons, + bool selectable, const struct message_box_buttons *buttons, post_dialog_fn_t after, void *afterctx); #endif @@ -280,10 +280,12 @@ void uxsel_input_remove(uxsel_id *id); /* uxcfg.c */ struct controlbox; -void unix_setup_config_box(struct controlbox *b, int midsession, int protocol); +void unix_setup_config_box( + struct controlbox *b, bool midsession, int protocol); /* gtkcfg.c */ -void gtk_setup_config_box(struct controlbox *b, int midsession, void *window); +void gtk_setup_config_box( + struct controlbox *b, bool midsession, void *window); /* * In the Unix Unicode layer, DEFAULT_CODEPAGE is a special value @@ -301,13 +303,13 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *window); /* BSD-semantics version of signal(), and another helpful function */ void (*putty_signal(int sig, void (*func)(int)))(int); -void block_signal(int sig, int block_it); +void block_signal(int sig, bool block_it); /* uxmisc.c */ void cloexec(int); void noncloexec(int); -int nonblock(int); -int no_nonblock(int); +bool nonblock(int); +bool no_nonblock(int); char *make_dir_and_check_ours(const char *dirname); char *make_dir_path(const char *path, mode_t mode); @@ -315,8 +317,8 @@ char *make_dir_path(const char *path, mode_t mode); * Exports from unicode.c. */ struct unicode_data; -int init_ucs(struct unicode_data *ucsdata, char *line_codepage, - int utf8_override, int font_charset, int vtmode); +bool init_ucs(struct unicode_data *ucsdata, char *line_codepage, + bool utf8_override, int font_charset, int vtmode); /* * Spare functions exported directly from uxnet.c. @@ -342,7 +344,7 @@ extern const struct BackendVtable serial_backend; /* * uxpeer.c, wrapping getsockopt(SO_PEERCRED). */ -int so_peercred(int fd, int *pid, int *uid, int *gid); +bool so_peercred(int fd, int *pid, int *uid, int *gid); /* * uxfdsock.c. diff --git a/unix/ux_x11.c b/unix/ux_x11.c index fb5c4949..16acbab4 100644 --- a/unix/ux_x11.c +++ b/unix/ux_x11.c @@ -17,7 +17,7 @@ void platform_get_x11_auth(struct X11Display *disp, Conf *conf) { char *xauthfile; - int needs_free; + bool needs_free; /* * Find the .Xauthority file. @@ -39,7 +39,7 @@ void platform_get_x11_auth(struct X11Display *disp, Conf *conf) } } -const int platform_uses_x11_unix_by_default = true; +const bool platform_uses_x11_unix_by_default = true; int platform_make_x11_server(Plug *plug, const char *progname, int mindisp, const char *screen_number_suffix, diff --git a/unix/uxagentc.c b/unix/uxagentc.c index 31829eb7..edd05d79 100644 --- a/unix/uxagentc.c +++ b/unix/uxagentc.c @@ -15,7 +15,7 @@ #include "tree234.h" #include "puttymem.h" -int agent_exists(void) +bool agent_exists(void) { const char *p = getenv("SSH_AUTH_SOCK"); if (p && *p) @@ -54,12 +54,12 @@ static int agent_connfind(void *av, void *bv) } /* - * Attempt to read from an agent socket fd. Returns 0 if the expected - * response is as yet incomplete; returns 1 if it's either complete - * (conn->retbuf non-NULL and filled with something useful) or has - * failed totally (conn->retbuf is NULL). + * Attempt to read from an agent socket fd. Returns false if the + * expected response is as yet incomplete; returns true if it's either + * complete (conn->retbuf non-NULL and filled with something useful) + * or has failed totally (conn->retbuf is NULL). */ -static int agent_try_read(agent_pending_query *conn) +static bool agent_try_read(agent_pending_query *conn) { int ret; @@ -69,7 +69,7 @@ static int agent_try_read(agent_pending_query *conn) if (conn->retbuf != conn->sizebuf) sfree(conn->retbuf); conn->retbuf = NULL; conn->retlen = 0; - return 1; + return true; } conn->retlen += ret; if (conn->retsize == 4 && conn->retlen == 4) { @@ -77,7 +77,7 @@ static int agent_try_read(agent_pending_query *conn) if (conn->retsize <= 0) { conn->retbuf = NULL; conn->retlen = 0; - return -1; /* way too large */ + return true; /* way too large */ } assert(conn->retbuf == conn->sizebuf); conn->retbuf = snewn(conn->retsize, char); @@ -85,9 +85,9 @@ static int agent_try_read(agent_pending_query *conn) } if (conn->retlen < conn->retsize) - return 0; /* more data to come */ + return false; /* more data to come */ - return 1; + return true; } void agent_cancel_query(agent_pending_query *conn) diff --git a/unix/uxcfg.c b/unix/uxcfg.c index e48a9b69..7c24603a 100644 --- a/unix/uxcfg.c +++ b/unix/uxcfg.c @@ -10,7 +10,7 @@ #include "dialog.h" #include "storage.h" -void unix_setup_config_box(struct controlbox *b, int midsession, int protocol) +void unix_setup_config_box(struct controlbox *b, bool midsession, int protocol) { struct controlset *s; union control *c; @@ -29,7 +29,7 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol) */ s = ctrl_getset(b, "Terminal", "printing", "Remote-controlled printing"); assert(s->ncontrols == 1 && s->ctrls[0]->generic.type == CTRL_EDITBOX); - s->ctrls[0]->editbox.has_list = 0; + s->ctrls[0]->editbox.has_list = false; /* * Unix supports a local-command proxy. This also means we must diff --git a/unix/uxcons.c b/unix/uxcons.c index e47a8003..1b5aabb3 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -21,10 +21,10 @@ #include "storage.h" #include "ssh.h" -int console_batch_mode = false; +bool console_batch_mode = false; static struct termios orig_termios_stderr; -static int stderr_is_a_tty; +static bool stderr_is_a_tty; void stderr_tty_init() { @@ -136,7 +136,7 @@ static int block_and_read(int fd, void *buf, size_t len) #ifdef EWOULDBLOCK (errno == EWOULDBLOCK) || #endif - 0)) { + false)) { fd_set rfds; FD_ZERO(&rfds); @@ -595,7 +595,7 @@ int console_get_userpass_input(prompts_t *p) return 1; /* success */ } -int is_interactive(void) +bool is_interactive(void) { return isatty(0); } diff --git a/unix/uxfdsock.c b/unix/uxfdsock.c index 41aaf232..2258e5bf 100644 --- a/unix/uxfdsock.c +++ b/unix/uxfdsock.c @@ -235,7 +235,7 @@ static void fdsocket_flush(Socket *s) /* do nothing */ } -static void fdsocket_set_frozen(Socket *s, int is_frozen) +static void fdsocket_set_frozen(Socket *s, bool is_frozen) { FdSocket *fds = container_of(s, FdSocket, sock); diff --git a/unix/uxmisc.c b/unix/uxmisc.c index cfdc5598..2170c3c4 100644 --- a/unix/uxmisc.c +++ b/unix/uxmisc.c @@ -58,12 +58,12 @@ const char *filename_to_str(const Filename *fn) return fn->path; } -int filename_equal(const Filename *f1, const Filename *f2) +bool filename_equal(const Filename *f1, const Filename *f2) { return !strcmp(f1->path, f2->path); } -int filename_is_null(const Filename *fn) +bool filename_is_null(const Filename *fn) { return !fn->path[0]; } @@ -202,7 +202,7 @@ void noncloexec(int fd) { exit(1); } } -int nonblock(int fd) { +bool nonblock(int fd) { int fdflags; fdflags = fcntl(fd, F_GETFL); @@ -217,7 +217,7 @@ int nonblock(int fd) { return fdflags & O_NONBLOCK; } -int no_nonblock(int fd) { +bool no_nonblock(int fd) { int fdflags; fdflags = fcntl(fd, F_GETFL); @@ -233,7 +233,7 @@ int no_nonblock(int fd) { return fdflags & O_NONBLOCK; } -FILE *f_open(const Filename *filename, char const *mode, int is_private) +FILE *f_open(const Filename *filename, char const *mode, bool is_private) { if (!is_private) { return fopen(filename->path, mode); @@ -330,7 +330,7 @@ char *make_dir_path(const char *path, mode_t mode) } } -int open_for_write_would_lose_data(const Filename *fn) +bool open_for_write_would_lose_data(const Filename *fn) { struct stat st; diff --git a/unix/uxnet.c b/unix/uxnet.c index 9ca98faf..512ad835 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -64,20 +64,21 @@ struct NetSocket { int s; Plug *plug; bufchain output_data; - int connected; /* irrelevant for listening sockets */ - int writable; - int frozen; /* this causes readability notifications to be ignored */ - int localhost_only; /* for listening sockets */ + bool connected; /* irrelevant for listening sockets */ + bool writable; + bool frozen; /* this causes readability notifications to be ignored */ + bool localhost_only; /* for listening sockets */ char oobdata[1]; int sending_oob; - int oobpending; /* is there OOB data available to read? */ - int oobinline; + bool oobpending; /* is there OOB data available to read? */ + bool oobinline; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; - int incomingeof; + bool incomingeof; int pending_error; /* in case send() returns error */ - int listener; - int nodelay, keepalive; /* for connect()-type sockets */ - int privport, port; /* and again */ + bool listener; + bool nodelay, keepalive; /* for connect()-type sockets */ + bool privport; + int port; /* and again */ SockAddr *addr; SockAddrStep step; /* @@ -292,7 +293,7 @@ SockAddr *sk_nonamelookup(const char *host) return ret; } -static int sk_nextaddr(SockAddr *addr, SockAddrStep *step) +static bool sk_nextaddr(SockAddr *addr, SockAddrStep *step) { #ifndef NO_IPV6 if (step->ai && step->ai->ai_next) { @@ -362,7 +363,7 @@ static SockAddr sk_extractaddr_tmp( return toret; } -int sk_addr_needs_port(SockAddr *addr) +bool sk_addr_needs_port(SockAddr *addr) { if (addr->superfamily == UNRESOLVED || addr->superfamily == UNIX) { return false; @@ -371,7 +372,7 @@ int sk_addr_needs_port(SockAddr *addr) } } -int sk_hostname_is_local(const char *name) +bool sk_hostname_is_local(const char *name) { return !strcmp(name, "localhost") || !strcmp(name, "::1") || @@ -381,7 +382,7 @@ int sk_hostname_is_local(const char *name) #define ipv4_is_loopback(addr) \ (((addr).s_addr & htonl(0xff000000)) == htonl(0x7f000000)) -static int sockaddr_is_loopback(struct sockaddr *sa) +static bool sockaddr_is_loopback(struct sockaddr *sa) { union sockaddr_union *u = (union sockaddr_union *)sa; switch (u->sa.sa_family) { @@ -398,12 +399,12 @@ static int sockaddr_is_loopback(struct sockaddr *sa) } } -int sk_address_is_local(SockAddr *addr) +bool sk_address_is_local(SockAddr *addr) { if (addr->superfamily == UNRESOLVED) - return 0; /* we don't know; assume not */ + return false; /* we don't know; assume not */ else if (addr->superfamily == UNIX) - return 1; + return true; else { #ifndef NO_IPV6 return sockaddr_is_loopback(addr->ais->ai_addr); @@ -418,7 +419,7 @@ int sk_address_is_local(SockAddr *addr) } } -int sk_address_is_special_local(SockAddr *addr) +bool sk_address_is_special_local(SockAddr *addr) { return addr->superfamily == UNIX; } @@ -502,7 +503,7 @@ static void sk_net_close(Socket *s); static int sk_net_write(Socket *s, const void *data, int len); static int sk_net_write_oob(Socket *s, const void *data, int len); static void sk_net_write_eof(Socket *s); -static void sk_net_set_frozen(Socket *s, int is_frozen); +static void sk_net_set_frozen(Socket *s, bool is_frozen); static SocketPeerInfo *sk_net_peer_info(Socket *s); static const char *sk_net_socket_error(Socket *s); @@ -531,18 +532,18 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->writable = 1; /* to start with */ + ret->writable = true; /* to start with */ ret->sending_oob = 0; - ret->frozen = 1; - ret->localhost_only = 0; /* unused, but best init anyway */ + ret->frozen = true; + ret->localhost_only = false; /* unused, but best init anyway */ ret->pending_error = 0; ret->oobpending = false; ret->outgoingeof = EOF_NO; ret->incomingeof = false; - ret->listener = 0; + ret->listener = false; ret->parent = ret->child = NULL; ret->addr = NULL; - ret->connected = 1; + ret->connected = true; ret->s = sockfd; @@ -551,7 +552,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) return &ret->sock; } - ret->oobinline = 0; + ret->oobinline = false; uxsel_tell(ret); add234(sktree, ret); @@ -601,7 +602,7 @@ static int try_connect(NetSocket *sock) cloexec(s); if (sock->oobinline) { - int b = true; + int b = 1; if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b)) < 0) { err = errno; @@ -611,7 +612,7 @@ static int try_connect(NetSocket *sock) } if (sock->nodelay) { - int b = true; + int b = 1; if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *) &b, sizeof(b)) < 0) { err = errno; @@ -621,7 +622,7 @@ static int try_connect(NetSocket *sock) } if (sock->keepalive) { - int b = true; + int b = 1; if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *) &b, sizeof(b)) < 0) { err = errno; @@ -737,8 +738,8 @@ static int try_connect(NetSocket *sock) * If we _don't_ get EWOULDBLOCK, the connect has completed * and we should set the socket as connected and writable. */ - sock->connected = 1; - sock->writable = 1; + sock->connected = true; + sock->writable = true; } uxsel_tell(sock); @@ -758,8 +759,8 @@ static int try_connect(NetSocket *sock) return err; } -Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug *plug) +Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline, + bool nodelay, bool keepalive, Plug *plug) { NetSocket *ret; int err; @@ -772,17 +773,17 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->connected = 0; /* to start with */ - ret->writable = 0; /* to start with */ + ret->connected = false; /* to start with */ + ret->writable = false; /* to start with */ ret->sending_oob = 0; - ret->frozen = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ + ret->frozen = false; + ret->localhost_only = false; /* unused, but best init anyway */ ret->pending_error = 0; ret->parent = ret->child = NULL; ret->oobpending = false; ret->outgoingeof = EOF_NO; ret->incomingeof = false; - ret->listener = 0; + ret->listener = false; ret->addr = addr; START_STEP(ret->addr, ret->step); ret->s = -1; @@ -804,7 +805,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, } Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, - int local_host_only, int orig_address_family) + bool local_host_only, int orig_address_family) { int s; #ifndef NO_IPV6 @@ -827,16 +828,16 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->writable = 0; /* to start with */ + ret->writable = false; /* to start with */ ret->sending_oob = 0; - ret->frozen = 0; + ret->frozen = false; ret->localhost_only = local_host_only; ret->pending_error = 0; ret->parent = ret->child = NULL; ret->oobpending = false; ret->outgoingeof = EOF_NO; ret->incomingeof = false; - ret->listener = 1; + ret->listener = true; ret->addr = NULL; ret->s = -1; @@ -879,7 +880,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, cloexec(s); - ret->oobinline = 0; + ret->oobinline = false; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)) < 0) { @@ -1267,7 +1268,7 @@ static void net_select_result(int fd, int event) int ret; char buf[20480]; /* nice big buffer for plenty of speed */ NetSocket *s; - u_long atmark; + bool atmark; /* Find the Socket structure */ s = find234(sktree, &fd, cmpforsearch); @@ -1359,11 +1360,14 @@ static void net_select_result(int fd, int event) * (data prior to urgent). */ if (s->oobinline && s->oobpending) { - atmark = 1; - if (ioctl(s->s, SIOCATMARK, &atmark) == 0 && atmark) - s->oobpending = false; /* clear this indicator */ + int atmark_from_ioctl; + if (ioctl(s->s, SIOCATMARK, &atmark_from_ioctl) == 0) { + atmark = atmark_from_ioctl; + if (atmark) + s->oobpending = false; /* clear this indicator */ + } } else - atmark = 1; + atmark = true; ret = recv(s->s, buf, s->oobpending ? 1 : sizeof(buf), 0); noise_ultralight(ret); @@ -1441,11 +1445,12 @@ static void net_select_result(int fd, int event) sk_addr_free(s->addr); s->addr = NULL; } - s->connected = s->writable = 1; + s->connected = true; + s->writable = true; uxsel_tell(s); } else { int bufsize_before, bufsize_after; - s->writable = 1; + s->writable = true; bufsize_before = s->sending_oob + bufchain_size(&s->output_data); try_send(s); bufsize_after = s->sending_oob + bufchain_size(&s->output_data); @@ -1471,7 +1476,7 @@ static const char *sk_net_socket_error(Socket *sock) return s->error; } -static void sk_net_set_frozen(Socket *sock, int is_frozen) +static void sk_net_set_frozen(Socket *sock, bool is_frozen) { NetSocket *s = container_of(sock, NetSocket, sock); if (s->frozen == is_frozen) @@ -1665,16 +1670,16 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->writable = 0; /* to start with */ + ret->writable = false; /* to start with */ ret->sending_oob = 0; - ret->frozen = 0; + ret->frozen = false; ret->localhost_only = true; ret->pending_error = 0; ret->parent = ret->child = NULL; ret->oobpending = false; ret->outgoingeof = EOF_NO; ret->incomingeof = false; - ret->listener = 1; + ret->listener = true; ret->addr = listenaddr; ret->s = -1; @@ -1691,7 +1696,7 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) cloexec(s); - ret->oobinline = 0; + ret->oobinline = false; memset(&u, '\0', sizeof(u)); u.su.sun_family = AF_UNIX; diff --git a/unix/uxnoise.c b/unix/uxnoise.c index c42466f6..bcc78273 100644 --- a/unix/uxnoise.c +++ b/unix/uxnoise.c @@ -16,28 +16,28 @@ #include "ssh.h" #include "storage.h" -static int read_dev_urandom(char *buf, int len) +static bool read_dev_urandom(char *buf, int len) { int fd; int ngot, ret; fd = open("/dev/urandom", O_RDONLY); if (fd < 0) - return 0; + return false; ngot = 0; while (ngot < len) { ret = read(fd, buf+ngot, len-ngot); if (ret < 0) { close(fd); - return 0; + return false; } ngot += ret; } close(fd); - return 1; + return true; } /* @@ -52,10 +52,10 @@ void noise_get_heavy(void (*func) (void *, int)) char buf[512]; FILE *fp; int ret; - int got_dev_urandom = 0; + bool got_dev_urandom = false; if (read_dev_urandom(buf, 32)) { - got_dev_urandom = 1; + got_dev_urandom = true; func(buf, 32); } diff --git a/unix/uxpeer.c b/unix/uxpeer.c index 8aaa3579..4ad26322 100644 --- a/unix/uxpeer.c +++ b/unix/uxpeer.c @@ -16,7 +16,7 @@ #include "putty.h" -int so_peercred(int fd, int *pid, int *uid, int *gid) +bool so_peercred(int fd, int *pid, int *uid, int *gid) { #ifdef HAVE_SO_PEERCRED struct ucred cr; diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 4cf9b0ff..42ce7ba5 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -114,7 +114,7 @@ void keylist_update(void) const char *const appname = "Pageant"; -static int time_to_die = false; +static bool time_to_die = false; /* Stub functions to permit linking against x11fwd.c. These never get * used, because in LIFE_X11 mode we connect to the X server using a @@ -122,30 +122,30 @@ static int time_to_die = false; * forwarding too. */ void chan_remotely_opened_confirmation(Channel *chan) { } void chan_remotely_opened_failure(Channel *chan, const char *err) { } -int chan_default_want_close(Channel *chan, int s, int r) { return false; } -int chan_no_exit_status(Channel *ch, int s) { return false; } -int chan_no_exit_signal(Channel *ch, ptrlen s, int c, ptrlen m) +bool chan_default_want_close(Channel *chan, bool s, bool r) { return false; } +bool chan_no_exit_status(Channel *ch, int s) { return false; } +bool chan_no_exit_signal(Channel *ch, ptrlen s, bool c, ptrlen m) { return false; } -int chan_no_exit_signal_numeric(Channel *ch, int s, int c, ptrlen m) +bool chan_no_exit_signal_numeric(Channel *ch, int s, bool c, ptrlen m) { return false; } -int chan_no_run_shell(Channel *chan) { return false; } -int chan_no_run_command(Channel *chan, ptrlen command) { return false; } -int chan_no_run_subsystem(Channel *chan, ptrlen subsys) { return false; } -int chan_no_enable_x11_forwarding( - Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata, +bool chan_no_run_shell(Channel *chan) { return false; } +bool chan_no_run_command(Channel *chan, ptrlen command) { return false; } +bool chan_no_run_subsystem(Channel *chan, ptrlen subsys) { return false; } +bool chan_no_enable_x11_forwarding( + Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata, unsigned screen_number) { return false; } -int chan_no_enable_agent_forwarding(Channel *chan) { return false; } -int chan_no_allocate_pty( +bool chan_no_enable_agent_forwarding(Channel *chan) { return false; } +bool chan_no_allocate_pty( Channel *chan, ptrlen termtype, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes) { return false; } -int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) { return false; } -int chan_no_send_break(Channel *chan, unsigned length) { return false; } -int chan_no_send_signal(Channel *chan, ptrlen signame) { return false; } -int chan_no_change_window_size( +bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) { return false; } +bool chan_no_send_break(Channel *chan, unsigned length) { return false; } +bool chan_no_send_signal(Channel *chan, ptrlen signame) { return false; } +bool chan_no_change_window_size( Channel *chan, unsigned width, unsigned height, unsigned pixwidth, unsigned pixheight) { return false; } -void chan_no_request_response(Channel *chan, int success) {} +void chan_no_request_response(Channel *chan, bool success) {} /* * These functions are part of the plug for our connection to the X @@ -158,7 +158,7 @@ static void x11_log(Plug *p, int type, SockAddr *addr, int port, static void x11_receive(Plug *plug, int urgent, char *data, int len) {} static void x11_sent(Plug *plug, int bufsize) {} static void x11_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { time_to_die = true; } @@ -206,7 +206,7 @@ void pageant_print_env(int pid) } } -void pageant_fork_and_print_env(int retain_tty) +void pageant_fork_and_print_env(bool retain_tty) { pid_t pid = fork(); if (pid == -1) { @@ -279,7 +279,7 @@ struct cmdline_key_action { const char *filename; }; -int is_agent_action(keyact action) +bool is_agent_action(keyact action) { return action == KEYACT_AGENT_LOAD; } @@ -299,7 +299,7 @@ void add_keyact(keyact action, const char *filename) keyact_tail = a; } -int have_controlling_tty(void) +bool have_controlling_tty(void) { int fd = open("/dev/tty", O_RDONLY); if (fd < 0) { @@ -347,11 +347,11 @@ static char *askpass_tty(const char *prompt) static char *askpass_gui(const char *prompt) { char *passphrase; - int success; + bool success; /* in gtkask.c */ char *gtk_askpass_main(const char *display, const char *wintitle, - const char *prompt, int *success); + const char *prompt, bool *success); passphrase = gtk_askpass_main( display, "Pageant passphrase prompt", prompt, &success); @@ -395,10 +395,11 @@ static char *askpass(const char *prompt) } } -static int unix_add_keyfile(const char *filename_str) +static bool unix_add_keyfile(const char *filename_str) { Filename *filename = filename_from_str(filename_str); - int status, ret; + int status; + bool ret; char *err; ret = true; @@ -457,12 +458,12 @@ void key_list_callback(void *ctx, const char *fingerprint, struct key_find_ctx { const char *string; - int match_fp, match_comment; + bool match_fp, match_comment; struct pageant_pubkey *found; int nfound; }; -int match_fingerprint_string(const char *string, const char *fingerprint) +bool match_fingerprint_string(const char *string, const char *fingerprint) { const char *hash; @@ -503,8 +504,8 @@ struct pageant_pubkey *find_key(const char *string, char **retstr) { struct key_find_ctx actx, *ctx = &actx; struct pageant_pubkey key_in, *key_ret; - int try_file = true, try_fp = true, try_comment = true; - int file_errors = false; + bool try_file = true, try_fp = true, try_comment = true; + bool file_errors = false; /* * Trim off disambiguating prefixes telling us how to interpret @@ -512,17 +513,21 @@ struct pageant_pubkey *find_key(const char *string, char **retstr) */ if (!strncmp(string, "file:", 5)) { string += 5; - try_fp = try_comment = false; + try_fp = false; + try_comment = false; file_errors = true; /* also report failure to load the file */ } else if (!strncmp(string, "comment:", 8)) { string += 8; - try_file = try_fp = false; + try_file = false; + try_fp = false; } else if (!strncmp(string, "fp:", 3)) { string += 3; - try_file = try_comment = false; + try_file = false; + try_comment = false; } else if (!strncmp(string, "fingerprint:", 12)) { string += 12; - try_file = try_comment = false; + try_file = false; + try_comment = false; } /* @@ -633,7 +638,7 @@ void run_client(void) { const struct cmdline_key_action *act; struct pageant_pubkey *key; - int errors = false; + bool errors = false; char *retstr; if (!agent_exists()) { @@ -735,7 +740,7 @@ void run_agent(void) int fd; int i, fdcount, fdsize, fdstate; int termination_pid = -1; - int errors = false; + bool errors = false; Conf *conf; const struct cmdline_key_action *act; @@ -799,7 +804,7 @@ void run_agent(void) conn->plug.vt = &X11Connection_plugvt; s = new_connection(sk_addr_dup(disp->addr), disp->realhost, disp->port, - 0, 1, 0, 0, &conn->plug, conf); + false, true, false, false, &conn->plug, conf); if ((err = sk_socket_error(s)) != NULL) { fprintf(stderr, "pageant: unable to connect to X server: %s", err); exit(1); @@ -999,7 +1004,7 @@ void run_agent(void) int main(int argc, char **argv) { - int doing_opts = true; + bool doing_opts = true; keyact curr_keyact = KEYACT_AGENT_LOAD; const char *standalone_askpass_prompt = NULL; @@ -1121,9 +1126,9 @@ int main(int argc, char **argv) * actions of KEYACT_AGENT_* type. */ { - int has_agent_actions = false; - int has_client_actions = false; - int has_lifetime = false; + bool has_agent_actions = false; + bool has_client_actions = false; + bool has_lifetime = false; const struct cmdline_key_action *act; for (act = keyact_head; act; act = act->next) { diff --git a/unix/uxplink.c b/unix/uxplink.c index 6794eff6..35b07f92 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -38,7 +38,7 @@ void cmdline_error(const char *fmt, ...) exit(1); } -static int local_tty = false; /* do we have a local tty? */ +static bool local_tty = false; /* do we have a local tty? */ static Backend *backend; static Conf *conf; @@ -82,11 +82,11 @@ char *x_get_default(const char *key) { return NULL; /* this is a stub */ } -int term_ldisc(Terminal *term, int mode) +bool term_ldisc(Terminal *term, int mode) { return false; } -static void plink_echoedit_update(Seat *seat, int echo, int edit) +static void plink_echoedit_update(Seat *seat, bool echo, bool edit) { /* Update stdin read mode to reflect changes in line discipline. */ struct termios mode; @@ -160,7 +160,7 @@ static char *plink_get_ttymode(Seat *seat, const char *mode) #define GET_BOOL(ourname, uxname, uxmemb, transform) \ do { \ if (strcmp(mode, ourname) == 0) { \ - int b = (orig_termios.uxmemb & uxname) != 0; \ + bool b = (orig_termios.uxmemb & uxname) != 0; \ transform; \ return dupprintf("%d", b); \ } \ @@ -325,7 +325,7 @@ void cleanup_termios(void) bufchain stdout_data, stderr_data; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; -int try_output(int is_stderr) +int try_output(bool is_stderr) { bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); @@ -333,7 +333,7 @@ int try_output(int is_stderr) int sendlen, ret; if (bufchain_size(chain) > 0) { - int prev_nonblock = nonblock(fd); + bool prev_nonblock = nonblock(fd); do { bufchain_prefix(chain, &senddata, &sendlen); ret = write(fd, senddata, sendlen); @@ -354,7 +354,7 @@ int try_output(int is_stderr) return bufchain_size(&stdout_data) + bufchain_size(&stderr_data); } -static int plink_output(Seat *seat, int is_stderr, const void *data, int len) +static int plink_output(Seat *seat, bool is_stderr, const void *data, int len) { if (is_stderr) { bufchain_add(&stderr_data, data, len); @@ -366,7 +366,7 @@ static int plink_output(Seat *seat, int is_stderr, const void *data, int len) } } -static int plink_eof(Seat *seat) +static bool plink_eof(Seat *seat) { assert(outgoingeof == EOF_NO); outgoingeof = EOF_PENDING; @@ -551,21 +551,21 @@ static void version(void) void frontend_net_error_pending(void) {} -const int share_can_be_downstream = true; -const int share_can_be_upstream = true; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = true; -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; int main(int argc, char **argv) { - int sending; + bool sending; int *fdlist; int fd; int i, fdcount, fdsize, fdstate; int exitcode; - int errors; - int use_subsystem = 0; - int just_test_share_exists = false; + bool errors; + bool use_subsystem = false; + bool just_test_share_exists = false; unsigned long now; struct winsize size; const struct BackendVtable *backvt; @@ -599,7 +599,7 @@ int main(int argc, char **argv) loaded_session = false; default_protocol = conf_get_int(conf, CONF_protocol); default_port = conf_get_int(conf, CONF_port); - errors = 0; + errors = false; { /* * Override the default protocol if PLINK_PROTOCOL is set. @@ -622,16 +622,16 @@ int main(int argc, char **argv) if (ret == -2) { fprintf(stderr, "plink: option \"%s\" requires an argument\n", p); - errors = 1; + errors = true; } else if (ret == 2) { --argc, ++argv; } else if (ret == 1) { continue; } else if (!strcmp(p, "-batch")) { - console_batch_mode = 1; + console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ - use_subsystem = 1; + use_subsystem = true; } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) { version(); } else if (!strcmp(p, "--help")) { @@ -644,7 +644,7 @@ int main(int argc, char **argv) if (argc <= 1) { fprintf(stderr, "plink: option \"-o\" requires an argument\n"); - errors = 1; + errors = true; } else { --argc; provide_xrm_string(*++argv); @@ -684,7 +684,7 @@ int main(int argc, char **argv) break; /* done with cmdline */ } else { fprintf(stderr, "plink: unknown option \"%s\"\n", p); - errors = 1; + errors = true; } } @@ -800,7 +800,7 @@ int main(int argc, char **argv) const char *error; char *realhost; /* nodelay is only useful if stdin is a terminal device */ - int nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0); + bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0); /* This is a good place for a fuzzer to fork us. */ #ifdef __AFL_HAVE_MANUAL_CONTROL diff --git a/unix/uxproxy.c b/unix/uxproxy.c index c8d40d86..c1d0c3f5 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -15,8 +15,8 @@ #include "proxy.h" Socket *platform_new_connection(SockAddr *addr, const char *hostname, - int port, int privport, - int oobinline, int nodelay, int keepalive, + int port, bool privport, + bool oobinline, bool nodelay, bool keepalive, Plug *plug, Conf *conf) { char *cmd; diff --git a/unix/uxpterm.c b/unix/uxpterm.c index b4d66924..1be68f50 100644 --- a/unix/uxpterm.c +++ b/unix/uxpterm.c @@ -8,10 +8,11 @@ #include "putty.h" const char *const appname = "pterm"; -const int use_event_log = 0; /* pterm doesn't need it */ -const int new_session = 0, saved_sessions = 0; /* or these */ -const int dup_check_launchable = 0; /* no need to check host name in conf */ -const int use_pty_argv = true; +const bool use_event_log = false; /* pterm doesn't need it */ +const bool new_session = false, saved_sessions = false; /* or these */ +const bool dup_check_launchable = false; /* no need to check host name + * in conf */ +const bool use_pty_argv = true; const struct BackendVtable *select_backend(Conf *conf) { @@ -40,7 +41,7 @@ char *make_default_wintitle(char *hostname) return dupstr("pterm"); } -void setup(int single) +void setup(bool single) { extern void pty_pre_init(void); /* declared in pty.c */ diff --git a/unix/uxpty.c b/unix/uxpty.c index e767aeb6..8dd82d42 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -87,10 +87,10 @@ struct Pty { char name[FILENAME_MAX]; pid_t child_pid; int term_width, term_height; - int child_dead, finished; + bool child_dead, finished; int exit_code; bufchain output_data; - int pending_eof; + bool pending_eof; Backend backend; }; @@ -178,7 +178,7 @@ static Pty *single_pty = NULL; #ifndef OMIT_UTMP static pid_t pty_utmp_helper_pid = -1; static int pty_utmp_helper_pipe = -1; -static int pty_stamped_utmp; +static bool pty_stamped_utmp; static struct utmpx utmp_entry; #endif @@ -246,7 +246,7 @@ static void setup_utmp(char *ttyname, char *location) } #endif - pty_stamped_utmp = 1; + pty_stamped_utmp = true; } @@ -273,7 +273,7 @@ static void cleanup_utmp(void) pututxline(&utmp_entry); endutxent(); - pty_stamped_utmp = 0; /* ensure we never double-cleanup */ + pty_stamped_utmp = false; /* ensure we never double-cleanup */ } #endif @@ -285,7 +285,7 @@ static void sigchld_handler(int signum) static void pty_setup_sigchld_handler(void) { - static int setup = false; + static bool setup = false; if (!setup) { putty_signal(SIGCHLD, sigchld_handler); setup = true; @@ -597,7 +597,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status) { char buf[4096]; int ret; - int finished = false; + bool finished = false; if (event < 0) { /* @@ -629,7 +629,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status) } } else { if (event == 1) { - int is_stdout = (fd == pty->master_o); + bool is_stdout = (fd == pty->master_o); ret = read(fd, buf, sizeof(buf)); @@ -844,12 +844,12 @@ static void copy_ttymodes_into_termios( */ Backend *pty_backend_create( Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd, - struct ssh_ttymodes ttymodes, int pipes_instead) + struct ssh_ttymodes ttymodes, bool pipes_instead) { int slavefd; pid_t pid, pgrp; #ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */ - int got_windowid; + bool got_windowid; long windowid; #endif Pty *pty; @@ -987,7 +987,7 @@ Backend *pty_backend_create( char *e = *ep; if (!strncmp(e, pty_osx_envrestore_prefix, plen)) { - int unset = (e[plen] == 'u'); + bool unset = (e[plen] == 'u'); char *pname = dupprintf("%.*s", (int)strcspn(e, "="), e); char *name = pname + plen + 1; char *value = e + strcspn(e, "="); @@ -1129,7 +1129,7 @@ Backend *pty_backend_create( putty_signal(SIGINT, SIG_DFL); putty_signal(SIGQUIT, SIG_DFL); putty_signal(SIGPIPE, SIG_DFL); - block_signal(SIGPIPE, 0); + block_signal(SIGPIPE, false); if (argv || cmd) { /* * If we were given a separated argument list, try to exec @@ -1237,7 +1237,7 @@ Backend *pty_backend_create( static const char *pty_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, - char **realhost, int nodelay, int keepalive) + char **realhost, bool nodelay, bool keepalive) { const char *cmd = NULL; struct ssh_ttymodes modes; @@ -1470,16 +1470,16 @@ static const SessionSpecial *pty_get_specials(Backend *be) return NULL; } -static int pty_connected(Backend *be) +static bool pty_connected(Backend *be) { /* Pty *pty = container_of(be, Pty, backend); */ return true; } -static int pty_sendok(Backend *be) +static bool pty_sendok(Backend *be) { /* Pty *pty = container_of(be, Pty, backend); */ - return 1; + return true; } static void pty_unthrottle(Backend *be, int backlog) @@ -1488,10 +1488,10 @@ static void pty_unthrottle(Backend *be, int backlog) /* do nothing */ } -static int pty_ldisc(Backend *be, int option) +static bool pty_ldisc(Backend *be, int option) { /* Pty *pty = container_of(be, Pty, backend); */ - return 0; /* neither editing nor echoing */ + return false; /* neither editing nor echoing */ } static void pty_provide_ldisc(Backend *be, Ldisc *ldisc) diff --git a/unix/uxputty.c b/unix/uxputty.c index a583f878..86ae8278 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -20,7 +20,7 @@ /* * Stubs to avoid uxpty.c needing to be linked in. */ -const int use_pty_argv = false; +const bool use_pty_argv = false; char **pty_argv; /* never used */ char *pty_osx_envrestore_prefix; @@ -52,8 +52,8 @@ void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx) sfree(title); } -const int use_event_log = 1, new_session = 1, saved_sessions = 1; -const int dup_check_launchable = 1; +const bool use_event_log = true, new_session = true, saved_sessions = true; +const bool dup_check_launchable = true; char *make_default_wintitle(char *hostname) { @@ -73,10 +73,10 @@ char *platform_get_x_display(void) { return dupstr(display); } -const int share_can_be_downstream = true; -const int share_can_be_upstream = true; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = true; -void setup(int single) +void setup(bool single) { sk_init(); flags = FLAG_VERBOSE | FLAG_INTERACTIVE; diff --git a/unix/uxser.c b/unix/uxser.c index 5be7cdf8..ec287be7 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -22,7 +22,7 @@ struct Serial { Seat *seat; LogContext *logctx; int fd; - int finished; + bool finished; int inbufsize; bufchain output_data; Backend backend; @@ -282,7 +282,7 @@ static const char *serial_configure(Serial *serial, Conf *conf) static const char *serial_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, char **realhost, - int nodelay, int keepalive) + bool nodelay, bool keepalive) { Serial *serial; const char *err; @@ -361,7 +361,7 @@ static void serial_select_result(int fd, int event) Serial *serial; char buf[4096]; int ret; - int finished = false; + bool finished = false; serial = find234(serial_by_fd, &fd, serial_find_by_fd); @@ -509,14 +509,14 @@ static const SessionSpecial *serial_get_specials(Backend *be) return specials; } -static int serial_connected(Backend *be) +static bool serial_connected(Backend *be) { - return 1; /* always connected */ + return true; /* always connected */ } -static int serial_sendok(Backend *be) +static bool serial_sendok(Backend *be) { - return 1; + return true; } static void serial_unthrottle(Backend *be, int backlog) @@ -526,12 +526,12 @@ static void serial_unthrottle(Backend *be, int backlog) serial_uxsel_setup(serial); } -static int serial_ldisc(Backend *be, int option) +static bool serial_ldisc(Backend *be, int option) { /* * Local editing and local echo are off by default. */ - return 0; + return false; } static void serial_provide_ldisc(Backend *be, Ldisc *ldisc) diff --git a/unix/uxserver.c b/unix/uxserver.c index 4c532212..7b9ab0f0 100644 --- a/unix/uxserver.c +++ b/unix/uxserver.c @@ -112,7 +112,7 @@ void timer_change_notify(unsigned long next) char *platform_get_x_display(void) { return NULL; } -static int verbose; +static bool verbose; static void log_to_stderr(const char *msg) { @@ -176,7 +176,7 @@ unsigned auth_methods(AuthPolicy *ap) return (AUTHMETHOD_PUBLICKEY | AUTHMETHOD_PASSWORD | AUTHMETHOD_KBDINT | AUTHMETHOD_TIS | AUTHMETHOD_CRYPTOCARD); } -int auth_none(AuthPolicy *ap, ptrlen username) +bool auth_none(AuthPolicy *ap, ptrlen username) { return false; } @@ -211,7 +211,7 @@ int auth_password(AuthPolicy *ap, ptrlen username, ptrlen password, return 2; } } -int auth_publickey(AuthPolicy *ap, ptrlen username, ptrlen public_blob) +bool auth_publickey(AuthPolicy *ap, ptrlen username, ptrlen public_blob) { struct AuthPolicy_ssh2_pubkey *iter; for (iter = ap->ssh2keys; iter; iter = iter->next) { @@ -285,11 +285,11 @@ char *auth_ssh1int_challenge(AuthPolicy *ap, unsigned method, ptrlen username) return dupprintf("This is a dummy %s challenge!\n", (method == AUTHMETHOD_TIS ? "TIS" : "CryptoCard")); } -int auth_ssh1int_response(AuthPolicy *ap, ptrlen response) +bool auth_ssh1int_response(AuthPolicy *ap, ptrlen response) { return ptrlen_eq_string(response, "otter"); } -int auth_successful(AuthPolicy *ap, ptrlen username, unsigned method) +bool auth_successful(AuthPolicy *ap, ptrlen username, unsigned method) { return true; } @@ -324,17 +324,17 @@ static void show_version_and_exit(void) exit(0); } -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; -static int finished = false; +static bool finished = false; void server_instance_terminated(void) { /* FIXME: change policy here if we're running in a listening loop */ finished = true; } -static int longoptarg(const char *arg, const char *expected, - const char **val, int *argcp, char ***argvp) +static bool longoptarg(const char *arg, const char *expected, + const char **val, int *argcp, char ***argvp) { int len = strlen(expected); if (memcmp(arg, expected, len)) diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 62c9bce6..f91d3094 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -37,7 +37,7 @@ void platform_get_x11_auth(struct X11Display *display, Conf *conf) { /* Do nothing, therefore no auth. */ } -const int platform_uses_x11_unix_by_default = true; +const bool platform_uses_x11_unix_by_default = true; /* * Default settings that are specific to PSFTP. @@ -346,7 +346,7 @@ void close_directory(DirHandle *dir) sfree(dir); } -int test_wildcard(const char *name, int cmdline) +int test_wildcard(const char *name, bool cmdline) { struct stat statbuf; @@ -403,7 +403,7 @@ void finish_wildcard_matching(WildcardMatcher *dir) { sfree(dir); } -char *stripslashes(const char *str, int local) +char *stripslashes(const char *str, bool local) { char *p; @@ -417,7 +417,7 @@ char *stripslashes(const char *str, int local) return (char *)str; } -int vet_filename(const char *name) +bool vet_filename(const char *name) { if (strchr(name, '/')) return false; @@ -428,7 +428,7 @@ int vet_filename(const char *name) return true; } -int create_directory(const char *name) +bool create_directory(const char *name) { return mkdir(name, 0777) == 0; } @@ -442,14 +442,14 @@ char *dir_file_cat(const char *dir, const char *file) * Do a select() between all currently active network fds and * optionally stdin. */ -static int ssh_sftp_do_select(int include_stdin, int no_fds_ok) +static int ssh_sftp_do_select(bool include_stdin, bool no_fds_ok) { fd_set rset, wset, xset; int i, fdcount, fdsize, *fdlist; int fd, fdstate, rwx, ret, maxfd; unsigned long now = GETTICKCOUNT(); unsigned long next; - int done_something = false; + bool done_something = false; fdlist = NULL; fdcount = fdsize = 0; @@ -566,7 +566,7 @@ int ssh_sftp_loop_iteration(void) /* * Read a PSFTP command line from stdin. */ -char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok) +char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok) { char *buf; int buflen, bufsize, ret; @@ -613,7 +613,7 @@ void frontend_net_error_pending(void) {} void platform_psftp_pre_conn_setup(void) {} -const int buildinfo_gtk_relevant = false; +const bool buildinfo_gtk_relevant = false; /* * Main program: do platform-specific initialisation and then call diff --git a/unix/uxsftpserver.c b/unix/uxsftpserver.c index 7cfee950..81214c4c 100644 --- a/unix/uxsftpserver.c +++ b/unix/uxsftpserver.c @@ -27,7 +27,7 @@ typedef struct UnixSftpServer UnixSftpServer; struct UnixSftpServer { unsigned *fdseqs; - int *fdsopen; + bool *fdsopen; int fdsize; tree234 *dirhandles; @@ -101,7 +101,7 @@ static void uss_return_handle_raw( fxp_reply_handle(reply, make_ptrlen(handlebuf, 8)); } -static int uss_decode_handle( +static bool uss_decode_handle( UnixSftpServer *uss, ptrlen handle, int *index, unsigned *seq) { unsigned char handlebuf[8]; @@ -123,7 +123,7 @@ static void uss_return_new_handle( int old_size = uss->fdsize; uss->fdsize = fd * 5 / 4 + 32; uss->fdseqs = sresize(uss->fdseqs, uss->fdsize, unsigned); - uss->fdsopen = sresize(uss->fdsopen, uss->fdsize, int); + uss->fdsopen = sresize(uss->fdsopen, uss->fdsize, bool); while (old_size < uss->fdsize) { uss->fdseqs[old_size] = 0; uss->fdsopen[old_size] = false; @@ -382,7 +382,7 @@ static void uss_reply_struct_stat(SftpReplyBuilder *reply, } static void uss_stat(SftpServer *srv, SftpReplyBuilder *reply, - ptrlen path, int follow_symlinks) + ptrlen path, bool follow_symlinks) { UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv); struct stat st; @@ -450,7 +450,7 @@ static void uss_setstat(SftpServer *srv, SftpReplyBuilder *reply, UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv); char *pathstr = mkstr(path); - int success = true; + bool success = true; SETSTAT_GUTS(PATH_PREFIX, pathstr, attrs, success); free(pathstr); @@ -470,7 +470,7 @@ static void uss_fsetstat(SftpServer *srv, SftpReplyBuilder *reply, if ((fd = uss_lookup_fd(uss, reply, handle)) < 0) return; - int success = true; + bool success = true; SETSTAT_GUTS(FD_PREFIX, fd, attrs, success); if (!success) { @@ -504,7 +504,7 @@ static void uss_read(SftpServer *srv, SftpReplyBuilder *reply, int status = lseek(fd, offset, SEEK_SET); if (status >= 0 || errno == ESPIPE) { - int seekable = (status >= 0); + bool seekable = (status >= 0); while (length > 0) { status = read(fd, p, length); if (status <= 0) @@ -573,7 +573,7 @@ static void uss_write(SftpServer *srv, SftpReplyBuilder *reply, } static void uss_readdir(SftpServer *srv, SftpReplyBuilder *reply, - ptrlen handle, int max_entries, int omit_longname) + ptrlen handle, int max_entries, bool omit_longname) { UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv); struct dirent *de; diff --git a/unix/uxshare.c b/unix/uxshare.c index 2b96f7d8..a7d7fc12 100644 --- a/unix/uxshare.c +++ b/unix/uxshare.c @@ -250,7 +250,7 @@ static char *make_dirname(const char *pi_name, char **logtext) int platform_ssh_share(const char *pi_name, Conf *conf, Plug *downplug, Plug *upplug, Socket **sock, char **logtext, char **ds_err, char **us_err, - int can_upstream, int can_downstream) + bool can_upstream, bool can_downstream) { char *dirname, *lockname, *sockname, *err; int lockfd; @@ -302,7 +302,8 @@ int platform_ssh_share(const char *pi_name, Conf *conf, if (can_downstream) { retsock = new_connection(unix_sock_addr(sockname), - "", 0, 0, 1, 0, 0, downplug, conf); + "", 0, false, true, false, false, + downplug, conf); if (sk_socket_error(retsock) == NULL) { sfree(*logtext); *logtext = sockname; diff --git a/unix/uxsignal.c b/unix/uxsignal.c index e21e0e80..8edbfacd 100644 --- a/unix/uxsignal.c +++ b/unix/uxsignal.c @@ -2,6 +2,8 @@ #include #include +#include "defs.h" + /* * Calling signal() is non-portable, as it varies in meaning * between platforms and depending on feature macros, and has @@ -25,7 +27,7 @@ void (*putty_signal(int sig, void (*func)(int)))(int) { return old.sa_handler; } -void block_signal(int sig, int block_it) +void block_signal(int sig, bool block_it) { sigset_t ss; diff --git a/unix/uxstore.c b/unix/uxstore.c index de1680f4..0d0c582e 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -678,8 +678,8 @@ int verify_host_key(const char *hostname, int port, return ret; } -int have_ssh_host_key(const char *hostname, int port, - const char *keytype) +bool have_ssh_host_key(const char *hostname, int port, + const char *keytype) { /* * If we have a host key, verify_host_key will return 0 or 2. diff --git a/unix/uxucs.c b/unix/uxucs.c index 92961eaa..3a34a969 100644 --- a/unix/uxucs.c +++ b/unix/uxucs.c @@ -16,9 +16,9 @@ * Unix Unicode-handling routines. */ -int is_dbcs_leadbyte(int codepage, char byte) +bool is_dbcs_leadbyte(int codepage, char byte) { - return 0; /* we don't do DBCS */ + return false; /* we don't do DBCS */ } int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen, @@ -98,10 +98,11 @@ int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen, /* * Return value is true if pterm is to run in direct-to-font mode. */ -int init_ucs(struct unicode_data *ucsdata, char *linecharset, - int utf8_override, int font_charset, int vtmode) +bool init_ucs(struct unicode_data *ucsdata, char *linecharset, + bool utf8_override, int font_charset, int vtmode) { - int i, ret = 0; + int i; + bool ret = false; /* * In the platform-independent parts of the code, font_codepage @@ -145,7 +146,7 @@ int init_ucs(struct unicode_data *ucsdata, char *linecharset, ucsdata->line_codepage = font_charset; if (ucsdata->line_codepage == CS_NONE) - ret = 1; + ret = true; /* * Set up unitab_line, by translating each individual character diff --git a/wcwidth.c b/wcwidth.c index 25372a79..a6596aae 100644 --- a/wcwidth.c +++ b/wcwidth.c @@ -69,12 +69,12 @@ struct interval { }; /* auxiliary function for binary search in interval table */ -static int bisearch(unsigned int ucs, const struct interval *table, int max) { +static bool bisearch(unsigned int ucs, const struct interval *table, int max) { int min = 0; int mid; if (ucs < table[0].first || ucs > table[max].last) - return 0; + return false; while (max >= min) { mid = (min + max) / 2; if (ucs > table[mid].last) @@ -82,10 +82,10 @@ static int bisearch(unsigned int ucs, const struct interval *table, int max) { else if (ucs < table[mid].first) max = mid - 1; else - return 1; + return true; } - return 0; + return false; } diff --git a/wildcard.c b/wildcard.c index f480a19a..9c560d0d 100644 --- a/wildcard.c +++ b/wildcard.c @@ -131,14 +131,14 @@ static int wc_match_fragment(const char **fragment, const char **target, */ f++; } else if (*f == '[') { - int invert = 0; - int matched = 0; + bool invert = false; + bool matched = false; /* * Open bracket introduces a character class. */ f++; if (*f == '^') { - invert = 1; + invert = true; f++; } while (*f != ']') { @@ -162,7 +162,7 @@ static int wc_match_fragment(const char **fragment, const char **target, int t = lower; lower = upper; upper = t; } if (ourchr >= lower && ourchr <= upper) - matched = 1; + matched = true; } else { matched |= (*t == *f++); } @@ -315,11 +315,11 @@ int wc_match_pl(const char *wildcard, ptrlen target) * the original wildcard. You can also pass NULL as the output * buffer if you're only interested in the return value. * - * Returns 1 on success, or 0 if a wildcard character was + * Returns true on success, or false if a wildcard character was * encountered. In the latter case the output string MAY not be * zero-terminated and you should not use it for anything! */ -int wc_unescape(char *output, const char *wildcard) +bool wc_unescape(char *output, const char *wildcard) { while (*wildcard) { if (*wildcard == '\\') { @@ -332,7 +332,7 @@ int wc_unescape(char *output, const char *wildcard) } } else if (*wildcard == '*' || *wildcard == '?' || *wildcard == '[' || *wildcard == ']') { - return 0; /* it's a wildcard! */ + return false; /* it's a wildcard! */ } else { if (output) *output++ = *wildcard; @@ -341,7 +341,7 @@ int wc_unescape(char *output, const char *wildcard) } if (output) *output = '\0'; - return 1; /* it's clean */ + return true; /* it's clean */ } #ifdef TESTMODE diff --git a/windows/sizetip.c b/windows/sizetip.c index a0fd415f..e91c5b90 100644 --- a/windows/sizetip.c +++ b/windows/sizetip.c @@ -91,7 +91,7 @@ static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg, } static HWND tip_wnd = NULL; -static int tip_enabled = 0; +static bool tip_enabled = false; void UpdateSizeTip(HWND src, int cx, int cy) { @@ -183,7 +183,7 @@ void UpdateSizeTip(HWND src, int cx, int cy) } } -void EnableSizeTip(int bEnable) +void EnableSizeTip(bool bEnable) { if (tip_wnd && !bEnable) { DestroyWindow(tip_wnd); diff --git a/windows/wincapi.c b/windows/wincapi.c index fbaf58e2..5ff7cdfa 100644 --- a/windows/wincapi.c +++ b/windows/wincapi.c @@ -9,10 +9,10 @@ #define WINCAPI_GLOBAL #include "wincapi.h" -int got_crypt(void) +bool got_crypt(void) { - static int attempted = false; - static int successful; + static bool attempted = false; + static bool successful; static HMODULE crypt; if (!attempted) { diff --git a/windows/wincapi.h b/windows/wincapi.h index 06ee2d36..f327be27 100644 --- a/windows/wincapi.h +++ b/windows/wincapi.h @@ -13,6 +13,6 @@ DECL_WINDOWS_FUNCTION(WINCAPI_GLOBAL, BOOL, CryptProtectMemory, (LPVOID,DWORD,DWORD)); -int got_crypt(void); +bool got_crypt(void); #endif diff --git a/windows/wincfg.c b/windows/wincfg.c index ec9b7e3d..493e0006 100644 --- a/windows/wincfg.c +++ b/windows/wincfg.c @@ -40,8 +40,8 @@ static void variable_pitch_handler(union control *ctrl, dlgparam *dlg, } } -void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, - int midsession, int protocol) +void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, + bool midsession, int protocol) { struct controlset *s; union control *c; diff --git a/windows/wincons.c b/windows/wincons.c index b01b1637..48dd3c2e 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -11,7 +11,7 @@ #include "storage.h" #include "ssh.h" -int console_batch_mode = false; +bool console_batch_mode = false; /* * Clean up and exit. @@ -481,14 +481,11 @@ int console_get_userpass_input(prompts_t *p) len = 0; while (1) { DWORD ret = 0; - BOOL r; prompt_ensure_result_size(pr, len * 5 / 4 + 512); - r = ReadFile(hin, pr->result + len, pr->resultsize - len - 1, - &ret, NULL); - - if (!r || ret == 0) { + if (!ReadFile(hin, pr->result + len, pr->resultsize - len - 1, + &ret, NULL) || ret == 0) { len = -1; break; } diff --git a/windows/winctrls.c b/windows/winctrls.c index 2a3a093f..99119cc9 100644 --- a/windows/winctrls.c +++ b/windows/winctrls.c @@ -165,7 +165,7 @@ void endbox(struct ctlpos *cp) /* * A static line, followed by a full-width edit box. */ -void editboxfw(struct ctlpos *cp, int password, char *text, +void editboxfw(struct ctlpos *cp, bool password, char *text, int staticid, int editid) { RECT r; @@ -534,7 +534,7 @@ void staticbtn(struct ctlpos *cp, char *stext, int sid, /* * A simple push button. */ -void button(struct ctlpos *cp, char *btext, int bid, int defbtn) +void button(struct ctlpos *cp, char *btext, int bid, bool defbtn) { RECT r; @@ -769,7 +769,7 @@ void bigeditctrl(struct ctlpos *cp, char *stext, * A list box with a static labelling it. */ void listbox(struct ctlpos *cp, char *stext, - int sid, int lid, int lines, int multi) + int sid, int lid, int lines, bool multi) { RECT r; @@ -994,7 +994,7 @@ static void pl_moveitem(HWND hwnd, int listid, int src, int dst) sfree (txt); } -int pl_itemfrompt(HWND hwnd, POINT cursor, BOOL scroll) +int pl_itemfrompt(HWND hwnd, POINT cursor, bool scroll) { int ret; POINT uppoint, downpoint; @@ -1041,7 +1041,7 @@ int pl_itemfrompt(HWND hwnd, POINT cursor, BOOL scroll) */ int handle_prefslist(struct prefslist *hdl, int *array, int maxmemb, - int is_dlmsg, HWND hwnd, + bool is_dlmsg, HWND hwnd, WPARAM wParam, LPARAM lParam) { int i; @@ -1063,7 +1063,7 @@ int handle_prefslist(struct prefslist *hdl, LB_ADDSTRING, 0, (LPARAM) ""); hdl->srcitem = p_LBItemFromPt(dlm->hWnd, dlm->ptCursor, true); - hdl->dragging = 0; + hdl->dragging = false; /* XXX hack Q183115 */ SetWindowLongPtr(hwnd, DWLP_MSGRESULT, true); ret |= 1; break; @@ -1071,10 +1071,10 @@ int handle_prefslist(struct prefslist *hdl, p_DrawInsert(hwnd, dlm->hWnd, -1); /* Clear arrow */ SendDlgItemMessage(hwnd, hdl->listid, LB_DELETESTRING, hdl->dummyitem, 0); - hdl->dragging = 0; + hdl->dragging = false; ret |= 1; break; case DL_DRAGGING: - hdl->dragging = 1; + hdl->dragging = true; dest = pl_itemfrompt(dlm->hWnd, dlm->ptCursor, true); if (dest > hdl->dummyitem) dest = hdl->dummyitem; p_DrawInsert (hwnd, dlm->hWnd, dest); @@ -1092,7 +1092,7 @@ int handle_prefslist(struct prefslist *hdl, SendDlgItemMessage(hwnd, hdl->listid, LB_DELETESTRING, hdl->dummyitem, 0); if (hdl->dragging) { - hdl->dragging = 0; + hdl->dragging = false; if (dest >= 0) { /* Correct for "missing" item. */ if (dest > hdl->srcitem) dest--; @@ -1654,7 +1654,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, shortcuts[nshortcuts++] = ctrl->fontselect.shortcut; statictext(&pos, escaped, 1, base_id); staticbtn(&pos, "", base_id+1, "Change...", base_id+2); - data = fontspec_new("", 0, 0, 0); + data = fontspec_new("", false, 0, 0); sfree(escaped); break; default: @@ -1710,7 +1710,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, } static void winctrl_set_focus(union control *ctrl, struct dlgparam *dp, - int has_focus) + bool has_focus) { if (has_focus) { if (dp->focused) @@ -1731,12 +1731,13 @@ union control *dlg_last_focused(union control *ctrl, dlgparam *dp) * The dialog-box procedure calls this function to handle Windows * messages on a control we manage. */ -int winctrl_handle_command(struct dlgparam *dp, UINT msg, - WPARAM wParam, LPARAM lParam) +bool winctrl_handle_command(struct dlgparam *dp, UINT msg, + WPARAM wParam, LPARAM lParam) { struct winctrl *c; union control *ctrl; - int i, id, ret; + int i, id; + bool ret; static UINT draglistmsg = WM_NULL; /* @@ -1747,7 +1748,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg, draglistmsg = RegisterWindowMessage (DRAGLISTMSGSTRING); if (msg != draglistmsg && msg != WM_COMMAND && msg != WM_DRAWITEM) - return 0; + return false; /* * Look up the control ID in our data. @@ -1759,7 +1760,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg, break; } if (!c) - return 0; /* we have nothing to do */ + return false; /* we have nothing to do */ if (msg == WM_DRAWITEM) { /* @@ -1787,7 +1788,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg, id = LOWORD(wParam) - c->base_id; if (!ctrl || !ctrl->generic.handler) - return 0; /* nothing we can do here */ + return false; /* nothing we can do here */ /* * From here on we do not issue `return' statements until the @@ -1796,7 +1797,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg, * to reach the end of this switch statement so that the * subsequent code can test dp->coloursel_wanted(). */ - ret = 0; + ret = false; dp->coloursel_wanted = false; /* @@ -2021,7 +2022,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg, * This function can be called to produce context help on a * control. Returns true if it has actually launched some help. */ -int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id) +bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id) { int i; struct winctrl *c; @@ -2036,17 +2037,17 @@ int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id) break; } if (!c) - return 0; /* we have nothing to do */ + return false; /* we have nothing to do */ /* * This is the Windows front end, so we're allowed to assume * `helpctx.p' is a context string. */ if (!c->ctrl || !c->ctrl->generic.helpctx.p) - return 0; /* no help available for this ctrl */ + return false; /* no help available for this ctrl */ launch_help(hwnd, c->ctrl->generic.helpctx.p); - return 1; + return true; } /* @@ -2088,14 +2089,14 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp) return 0; } -void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked) +void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked) { struct winctrl *c = dlg_findbyctrl(dp, ctrl); assert(c && c->ctrl->generic.type == CTRL_CHECKBOX); - CheckDlgButton(dp->hwnd, c->base_id, (checked != 0)); + CheckDlgButton(dp->hwnd, c->base_id, checked); } -int dlg_checkbox_get(union control *ctrl, dlgparam *dp) +bool dlg_checkbox_get(union control *ctrl, dlgparam *dp) { struct winctrl *c = dlg_findbyctrl(dp, ctrl); assert(c && c->ctrl->generic.type == CTRL_CHECKBOX); @@ -2210,7 +2211,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp) return ret; } -int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) +bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index) { struct winctrl *c = dlg_findbyctrl(dp, ctrl); assert(c && c->ctrl->generic.type == CTRL_LISTBOX && @@ -2447,16 +2448,16 @@ void dlg_coloursel_start(union control *ctrl, dlgparam *dp, int r, int g, int b) dp->coloursel_result.b = b; } -int dlg_coloursel_results(union control *ctrl, dlgparam *dp, - int *r, int *g, int *b) +bool dlg_coloursel_results(union control *ctrl, dlgparam *dp, + int *r, int *g, int *b) { if (dp->coloursel_result.ok) { *r = dp->coloursel_result.r; *g = dp->coloursel_result.g; *b = dp->coloursel_result.b; - return 1; + return true; } else - return 0; + return false; } void dlg_auto_set_fixed_pitch_flag(dlgparam *dp) @@ -2467,7 +2468,7 @@ void dlg_auto_set_fixed_pitch_flag(dlgparam *dp) HFONT hfont; HDC hdc; TEXTMETRIC tm; - int is_var; + bool is_var; /* * Attempt to load the current font, and see if it's @@ -2502,12 +2503,12 @@ void dlg_auto_set_fixed_pitch_flag(dlgparam *dp) dp->fixed_pitch_fonts = false; } -int dlg_get_fixed_pitch_flag(dlgparam *dp) +bool dlg_get_fixed_pitch_flag(dlgparam *dp) { return dp->fixed_pitch_fonts; } -void dlg_set_fixed_pitch_flag(dlgparam *dp, int flag) +void dlg_set_fixed_pitch_flag(dlgparam *dp, bool flag) { dp->fixed_pitch_fonts = flag; } diff --git a/windows/windefs.c b/windows/windefs.c index b210cde0..308c29eb 100644 --- a/windows/windefs.c +++ b/windows/windefs.c @@ -9,9 +9,9 @@ FontSpec *platform_default_fontspec(const char *name) { if (!strcmp(name, "Font")) - return fontspec_new("Courier New", 0, 10, ANSI_CHARSET); + return fontspec_new("Courier New", false, 10, ANSI_CHARSET); else - return fontspec_new("", 0, 0, 0); + return fontspec_new("", false, 0, 0); } Filename *platform_default_filename(const char *name) diff --git a/windows/windlg.c b/windows/windlg.c index d20cd805..4019b9a3 100644 --- a/windows/windlg.c +++ b/windows/windlg.c @@ -55,20 +55,20 @@ extern Conf *conf; /* defined in window.c */ void force_normal(HWND hwnd) { - static int recurse = 0; + static bool recurse = false; WINDOWPLACEMENT wp; if (recurse) return; - recurse = 1; + recurse = true; wp.length = sizeof(wp); if (GetWindowPlacement(hwnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) { wp.showCmd = SW_SHOWNORMAL; SetWindowPlacement(hwnd, &wp); } - recurse = 0; + recurse = false; } static char *getevent(int i) @@ -693,9 +693,9 @@ void defuse_showwindow(void) } } -int do_config(void) +bool do_config(void) { - int ret; + bool ret; ctrlbox = ctrl_new_box(); setup_config_box(ctrlbox, false, 0, 0); @@ -723,10 +723,11 @@ int do_config(void) return ret; } -int do_reconfig(HWND hwnd, int protcfginfo) +bool do_reconfig(HWND hwnd, int protcfginfo) { Conf *backup_conf; - int ret, protocol; + bool ret; + int protocol; backup_conf = conf_copy(conf); diff --git a/windows/window.c b/windows/window.c index e4bcbf43..31b1cbe5 100644 --- a/windows/window.c +++ b/windows/window.c @@ -102,24 +102,25 @@ static void set_input_locale(HKL); static void update_savedsess_menu(void); static void init_winfuncs(void); -static int is_full_screen(void); +static bool is_full_screen(void); static void make_full_screen(void); static void clear_full_screen(void); static void flip_full_screen(void); -static void process_clipdata(HGLOBAL clipdata, int unicode); +static void process_clipdata(HGLOBAL clipdata, bool unicode); static void setup_clipboards(Terminal *, Conf *); /* Window layout information */ static void reset_window(int); static int extra_width, extra_height; -static int font_width, font_height, font_dualwidth, font_varpitch; +static int font_width, font_height; +static bool font_dualwidth, font_varpitch; static int offset_width, offset_height; -static int was_zoomed = 0; +static bool was_zoomed = false; static int prev_rows, prev_cols; static void flash_window(int mode); static void sys_cursor_update(void); -static int get_fullscreen_rect(RECT * ss); +static bool get_fullscreen_rect(RECT * ss); static int caret_x = -1, caret_y = -1; @@ -129,8 +130,8 @@ static Ldisc *ldisc; static Backend *backend; static struct unicode_data ucsdata; -static int session_closed; -static int reconfiguring = false; +static bool session_closed; +static bool reconfiguring = false; static const SessionSpecial *specials = NULL; static HMENU specials_menu = NULL; @@ -183,11 +184,11 @@ struct agent_callback { #define FONT_SHIFT 5 static HFONT fonts[FONT_MAXNO]; static LOGFONT lfont; -static int fontflag[FONT_MAXNO]; +static bool fontflag[FONT_MAXNO]; static enum { BOLD_NONE, BOLD_SHADOW, BOLD_FONT } bold_font_mode; -static int bold_colours; +static bool bold_colours; static enum { UND_LINE, UND_FONT } und_mode; @@ -210,7 +211,7 @@ static int dbltime, lasttime, lastact; static Mouse_Button lastbtn; /* this allows xterm-style mouse handling. */ -static int send_raw_mouse = 0; +static bool send_raw_mouse = false; static int wheel_accumulator = 0; static BusyStatus busy_status = BUSY_NOT; @@ -227,7 +228,7 @@ static UINT wm_mousewheel = WM_MOUSEWHEEL; (((wch) >= 0x180B && (wch) <= 0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR */ \ ((wch) >= 0xFE00 && (wch) <= 0xFE0F)) /* VARIATION SELECTOR 1-16 */ -static int wintw_setup_draw_ctx(TermWin *); +static bool wintw_setup_draw_ctx(TermWin *); static void wintw_draw_text(TermWin *, int x, int y, wchar_t *text, int len, unsigned long attrs, int lattrs, truecolour tc); static void wintw_draw_cursor(TermWin *, int x, int y, wchar_t *text, int len, @@ -235,29 +236,29 @@ static void wintw_draw_cursor(TermWin *, int x, int y, wchar_t *text, int len, static int wintw_char_width(TermWin *, int uc); static void wintw_free_draw_ctx(TermWin *); static void wintw_set_cursor_pos(TermWin *, int x, int y); -static void wintw_set_raw_mouse_mode(TermWin *, int enable); +static void wintw_set_raw_mouse_mode(TermWin *, bool enable); static void wintw_set_scrollbar(TermWin *, int total, int start, int page); static void wintw_bell(TermWin *, int mode); static void wintw_clip_write( TermWin *, int clipboard, wchar_t *text, int *attrs, - truecolour *colours, int len, int must_deselect); + truecolour *colours, int len, bool must_deselect); static void wintw_clip_request_paste(TermWin *, int clipboard); static void wintw_refresh(TermWin *); static void wintw_request_resize(TermWin *, int w, int h); static void wintw_set_title(TermWin *, const char *title); static void wintw_set_icon_title(TermWin *, const char *icontitle); -static void wintw_set_minimised(TermWin *, int minimised); -static int wintw_is_minimised(TermWin *); -static void wintw_set_maximised(TermWin *, int maximised); +static void wintw_set_minimised(TermWin *, bool minimised); +static bool wintw_is_minimised(TermWin *); +static void wintw_set_maximised(TermWin *, bool maximised); static void wintw_move(TermWin *, int x, int y); -static void wintw_set_zorder(TermWin *, int top); -static int wintw_palette_get(TermWin *, int n, int *r, int *g, int *b); +static void wintw_set_zorder(TermWin *, bool top); +static bool wintw_palette_get(TermWin *, int n, int *r, int *g, int *b); static void wintw_palette_set(TermWin *, int n, int r, int g, int b); static void wintw_palette_reset(TermWin *); static void wintw_get_pos(TermWin *, int *x, int *y); static void wintw_get_pixels(TermWin *, int *x, int *y); -static const char *wintw_get_title(TermWin *, int icon); -static int wintw_is_utf8(TermWin *); +static const char *wintw_get_title(TermWin *, bool icon); +static bool wintw_is_utf8(TermWin *); static const TermWinVtable windows_termwin_vt = { wintw_setup_draw_ctx, @@ -292,20 +293,20 @@ static const TermWinVtable windows_termwin_vt = { static TermWin wintw[1]; static HDC wintw_hdc; -const int share_can_be_downstream = true; -const int share_can_be_upstream = true; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = true; -static int is_utf8(void) +static bool is_utf8(void) { return ucsdata.line_codepage == CP_UTF8; } -static int wintw_is_utf8(TermWin *tw) +static bool wintw_is_utf8(TermWin *tw) { return is_utf8(); } -static int win_seat_is_utf8(Seat *seat) +static bool win_seat_is_utf8(Seat *seat) { return is_utf8(); } @@ -315,14 +316,14 @@ char *win_seat_get_ttymode(Seat *seat, const char *mode) return term_get_ttymode(term, mode); } -int win_seat_get_window_pixel_size(Seat *seat, int *x, int *y) +bool win_seat_get_window_pixel_size(Seat *seat, int *x, int *y) { win_get_pixels(wintw, x, y); return true; } -static int win_seat_output(Seat *seat, int is_stderr, const void *, int); -static int win_seat_eof(Seat *seat); +static int win_seat_output(Seat *seat, bool is_stderr, const void *, int); +static bool win_seat_eof(Seat *seat); static int win_seat_get_userpass_input( Seat *seat, prompts_t *p, bufchain *input); static void win_seat_notify_remote_exit(Seat *seat); @@ -511,7 +512,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) */ { char *p; - int special_launchable_argument = false; + bool special_launchable_argument = false; default_protocol = be_default_protocol; /* Find the appropriate default port. */ @@ -1006,7 +1007,7 @@ void cleanup_exit(int code) /* * Set up, or shut down, an AsyncSelect. Called from winnet.c. */ -char *do_select(SOCKET skt, int startup) +char *do_select(SOCKET skt, bool startup) { int msg, events; if (startup) { @@ -1122,8 +1123,8 @@ static void win_seat_update_specials_menu(Seat *seat) static void update_mouse_pointer(void) { LPTSTR curstype = NULL; - int force_visible = false; - static int forced_visible = false; + bool force_visible = false; + static bool forced_visible = false; switch (busy_status) { case BUSY_NOT: if (send_raw_mouse) @@ -1166,7 +1167,7 @@ static void win_seat_set_busy_status(Seat *seat, BusyStatus status) /* * set or clear the "raw mouse message" mode */ -static void wintw_set_raw_mouse_mode(TermWin *tw, int activate) +static void wintw_set_raw_mouse_mode(TermWin *tw, bool activate) { activate = activate && !conf_get_bool(conf, CONF_no_mouse_rep); send_raw_mouse = activate; @@ -1343,7 +1344,7 @@ static void init_palette(void) */ static void exact_textout(HDC hdc, int x, int y, CONST RECT *lprc, unsigned short *lpString, UINT cbCount, - CONST INT *lpDx, int opaque) + CONST INT *lpDx, bool opaque) { #ifdef __LCC__ /* @@ -1385,15 +1386,16 @@ static void exact_textout(HDC hdc, int x, int y, CONST RECT *lprc, */ static void general_textout(HDC hdc, int x, int y, CONST RECT *lprc, unsigned short *lpString, UINT cbCount, - CONST INT *lpDx, int opaque) + CONST INT *lpDx, bool opaque) { int i, j, xp, xn; - int bkmode = 0, got_bkmode = false; + int bkmode = 0; + bool got_bkmode = false; xp = xn = x; for (i = 0; i < (int)cbCount ;) { - int rtl = is_rtl(lpString[i]); + bool rtl = is_rtl(lpString[i]); xn += lpDx[i]; @@ -1592,7 +1594,8 @@ static void init_fonts(int pick_width, int pick_height) { HDC und_dc; HBITMAP und_bm, und_oldbm; - int i, gotit; + int i; + bool gotit; COLORREF c; und_dc = CreateCompatibleDC(hdc); @@ -1653,7 +1656,9 @@ static void init_fonts(int pick_width, int pick_height) DeleteObject(fonts[FONT_BOLD]); fonts[FONT_BOLD] = 0; } - fontflag[0] = fontflag[1] = fontflag[2] = 1; + fontflag[0] = true; + fontflag[1] = true; + fontflag[2] = true; init_ucs(conf, &ucsdata); } @@ -1662,7 +1667,8 @@ static void another_font(int fontno) { int basefont; int fw_dontcare, fw_bold, quality; - int c, u, w, x; + int c, w, x; + bool u; char *s; FontSpec *font; @@ -1708,7 +1714,7 @@ static void another_font(int fontno) CLIP_DEFAULT_PRECIS, FONT_QUALITY(quality), DEFAULT_PITCH | FF_DONTCARE, s); - fontflag[fontno] = 1; + fontflag[fontno] = true; } static void deinit_fonts(void) @@ -1718,7 +1724,7 @@ static void deinit_fonts(void) if (fonts[i]) DeleteObject(fonts[i]); fonts[i] = 0; - fontflag[i] = 0; + fontflag[i] = false; } } @@ -1998,7 +2004,8 @@ static void set_input_locale(HKL kl) kbd_codepage = atoi(lbuf); } -static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt) +static void click(Mouse_Button b, int x, int y, + bool shift, bool ctrl, bool alt) { int thistime = GetMessageTime(); @@ -2041,13 +2048,13 @@ static Mouse_Button translate_button(Mouse_Button button) return 0; /* shouldn't happen */ } -static void show_mouseptr(int show) +static void show_mouseptr(bool show) { /* NB that the counter in ShowCursor() is also frobbed by * update_mouse_pointer() */ - static int cursor_visible = 1; + static bool cursor_visible = true; if (!conf_get_bool(conf, CONF_hide_mouseptr)) - show = 1; /* override if this feature disabled */ + show = true; /* override if this feature disabled */ if (cursor_visible && !show) ShowCursor(false); else if (!cursor_visible && show) @@ -2055,7 +2062,7 @@ static void show_mouseptr(int show) cursor_visible = show; } -static int is_alt_pressed(void) +static bool is_alt_pressed(void) { BYTE keystate[256]; int r = GetKeyboardState(keystate); @@ -2068,7 +2075,7 @@ static int is_alt_pressed(void) return false; } -static int resizing; +static bool resizing; static void win_seat_notify_remote_exit(Seat *seat) { @@ -2143,10 +2150,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; - static int ignore_clip = false; - static int need_backend_resize = false; - static int fullscr_on_max = false; - static int processed_resize = false; + static bool ignore_clip = false; + static bool need_backend_resize = false; + static bool fullscr_on_max = false; + static bool processed_resize = false; static UINT last_mousemove = 0; int resize_action; @@ -2167,7 +2174,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case WM_CLOSE: { char *str; - show_mouseptr(1); + show_mouseptr(true); str = dupprintf("%s Exit Confirmation", appname); if (session_closed || !conf_get_bool(conf, CONF_warn_on_close) || MessageBox(hwnd, @@ -2179,7 +2186,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } return 0; case WM_DESTROY: - show_mouseptr(1); + show_mouseptr(true); PostQuitMessage(0); return 0; case WM_INITMENUPOPUP: @@ -2205,7 +2212,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, char b[2048]; char *cl; const char *argprefix; - BOOL inherit_handles; + bool inherit_handles; STARTUPINFO si; PROCESS_INFORMATION pi; HANDLE filemap = NULL; @@ -2295,7 +2302,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, { Conf *prev_conf; int init_lvl = 1; - int reconfig_result; + bool reconfig_result; if (reconfiguring) break; @@ -2506,7 +2513,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, * We get this if the System menu has been activated * using the mouse. */ - show_mouseptr(1); + show_mouseptr(true); break; case SC_KEYMENU: /* @@ -2517,7 +2524,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, * the menu up_ rather than just sitting there in * `ready to appear' state. */ - show_mouseptr(1); /* make sure pointer is visible */ + show_mouseptr(true); /* make sure pointer is visible */ if( lParam == 0 ) PostMessage(hwnd, WM_CHAR, ' ', 0); break; @@ -2560,7 +2567,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, (conf_get_int(conf, CONF_mouse_is_xterm) == 2))) { POINT cursorpos; - show_mouseptr(1); /* make sure pointer is visible */ + show_mouseptr(true); /* make sure pointer is visible */ GetCursorPos(&cursorpos); TrackPopupMenu(popup_menus[CTXMENU].menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, @@ -2569,43 +2576,45 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, break; } { - int button, press; + int button; + bool press; switch (message) { case WM_LBUTTONDOWN: button = MBT_LEFT; wParam |= MK_LBUTTON; - press = 1; + press = true; break; case WM_MBUTTONDOWN: button = MBT_MIDDLE; wParam |= MK_MBUTTON; - press = 1; + press = true; break; case WM_RBUTTONDOWN: button = MBT_RIGHT; wParam |= MK_RBUTTON; - press = 1; + press = true; break; case WM_LBUTTONUP: button = MBT_LEFT; wParam &= ~MK_LBUTTON; - press = 0; + press = false; break; case WM_MBUTTONUP: button = MBT_MIDDLE; wParam &= ~MK_MBUTTON; - press = 0; + press = false; break; case WM_RBUTTONUP: button = MBT_RIGHT; wParam &= ~MK_RBUTTON; - press = 0; + press = false; break; - default: - button = press = 0; /* shouldn't happen */ + default: /* shouldn't happen */ + button = 0; + press = false; } - show_mouseptr(1); + show_mouseptr(true); /* * Special case: in full-screen mode, if the left * button is clicked in the very top left corner of the @@ -2613,7 +2622,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, * selection. */ { - char mouse_on_hotspot = 0; + bool mouse_on_hotspot = false; POINT pt; GetCursorPos(&pt); @@ -2630,13 +2639,13 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, if (mi.rcMonitor.left == pt.x && mi.rcMonitor.top == pt.y) { - mouse_on_hotspot = 1; + mouse_on_hotspot = true; } } } #else if (pt.x == 0 && pt.y == 0) { - mouse_on_hotspot = 1; + mouse_on_hotspot = true; } #endif if (is_full_screen() && press && @@ -2674,7 +2683,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, static LPARAM lp = 0; if (wParam != wp || lParam != lp || last_mousemove != WM_MOUSEMOVE) { - show_mouseptr(1); + show_mouseptr(true); wp = wParam; lp = lParam; last_mousemove = WM_MOUSEMOVE; } @@ -2706,7 +2715,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, static LPARAM lp = 0; if (wParam != wp || lParam != lp || last_mousemove != WM_NCMOUSEMOVE) { - show_mouseptr(1); + show_mouseptr(true); wp = wParam; lp = lParam; last_mousemove = WM_NCMOUSEMOVE; } @@ -2846,7 +2855,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, term_update(term); break; case WM_KILLFOCUS: - show_mouseptr(1); + show_mouseptr(true); term_set_focus(term, false); DestroyCaret(); caret_x = caret_y = -1; /* ensure caret is replaced next time */ @@ -2856,12 +2865,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, #ifdef RDB_DEBUG_PATCH debug((27, "WM_ENTERSIZEMOVE")); #endif - EnableSizeTip(1); + EnableSizeTip(true); resizing = true; need_backend_resize = false; break; case WM_EXITSIZEMOVE: - EnableSizeTip(0); + EnableSizeTip(false); resizing = false; #ifdef RDB_DEBUG_PATCH debug((27, "WM_EXITSIZEMOVE")); @@ -3031,7 +3040,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, height = HIWORD(lParam); if (wParam == SIZE_MAXIMIZED && !was_zoomed) { - was_zoomed = 1; + was_zoomed = true; prev_rows = term->rows; prev_cols = term->cols; if (resize_action == RESIZE_TERM) { @@ -3058,7 +3067,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } reset_window(0); } else if (wParam == SIZE_RESTORED && was_zoomed) { - was_zoomed = 0; + was_zoomed = false; if (resize_action == RESIZE_TERM) { w = (width-window_border*2) / font_width; if (w < 1) w = 1; @@ -3205,8 +3214,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, */ term_seen_key_event(term); if (ldisc) - ldisc_send(ldisc, buf, len, 1); - show_mouseptr(0); + ldisc_send(ldisc, buf, len, true); + show_mouseptr(false); } } } @@ -3258,12 +3267,13 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, if (IS_HIGH_SURROGATE(hs) && i+2 < n) { WCHAR ls = *(unsigned short *)(buff+i+2); if (IS_LOW_SURROGATE(ls)) { - luni_send(ldisc, (unsigned short *)(buff+i), 2, 1); + luni_send(ldisc, (unsigned short *)(buff+i), + 2, true); i += 2; continue; } } - luni_send(ldisc, (unsigned short *)(buff+i), 1, 1); + luni_send(ldisc, (unsigned short *)(buff+i), 1, true); } } free(buff); @@ -3280,12 +3290,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, buf[0] = wParam >> 8; term_seen_key_event(term); if (ldisc) - lpage_send(ldisc, kbd_codepage, buf, 2, 1); + lpage_send(ldisc, kbd_codepage, buf, 2, true); } else { char c = (unsigned char) wParam; term_seen_key_event(term); if (ldisc) - lpage_send(ldisc, kbd_codepage, &c, 1, 1); + lpage_send(ldisc, kbd_codepage, &c, 1, true); } return (0); case WM_CHAR: @@ -3307,10 +3317,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, pair[0] = pending_surrogate; pair[1] = c; term_seen_key_event(term); - luni_send(ldisc, pair, 2, 1); + luni_send(ldisc, pair, 2, true); } else if (!IS_SURROGATE(c)) { term_seen_key_event(term); - luni_send(ldisc, &c, 1, 1); + luni_send(ldisc, &c, 1, true); } } return 0; @@ -3336,7 +3346,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, return 0; default: if (message == wm_mousewheel || message == WM_MOUSEWHEEL) { - int shift_pressed=0, control_pressed=0; + bool shift_pressed = false, control_pressed = false; if (message == WM_MOUSEWHEEL) { wheel_accumulator += (short)HIWORD(wParam); @@ -3465,12 +3475,13 @@ static void do_text_internal( COLORREF fg, bg, t; int nfg, nbg, nfont; RECT line_box; - int force_manual_underline = 0; + bool force_manual_underline = false; int fnt_width, char_width; int text_adjust = 0; int xoffset = 0; - int maxlen, remaining, opaque; - int is_cursor = false; + int maxlen, remaining; + bool opaque; + bool is_cursor = false; static int *lpDx = NULL; static int lpDx_len = 0; int *lpDx_maybe; @@ -3540,7 +3551,7 @@ static void do_text_internal( text[0] = ucsdata.unitab_xterm['q']; if (attr & ATTR_UNDER) { attr &= ~ATTR_UNDER; - force_manual_underline = 1; + force_manual_underline = true; } } #endif @@ -3566,7 +3577,7 @@ static void do_text_internal( another_font(nfont); if (!fonts[nfont]) { if (nfont & FONT_UNDERLINE) - force_manual_underline = 1; + force_manual_underline = true; /* Don't do the same for manual bold, it could be bad news. */ nfont &= ~(FONT_BOLD | FONT_UNDERLINE); @@ -4056,7 +4067,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, unsigned char *output) { BYTE keystate[256]; - int scan, left_alt = 0, key_down, shift_state; + int scan, shift_state; + bool left_alt = false, key_down; int r, i, code; unsigned char *p = output; static int alt_sum = 0; @@ -4178,7 +4190,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, return 0; if ((HIWORD(lParam) & KF_ALTDOWN) && (keystate[VK_RMENU] & 0x80) == 0) - left_alt = 1; + left_alt = true; key_down = ((HIWORD(lParam) & KF_UP) == 0); @@ -4188,7 +4200,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, keystate[VK_MENU] = 0; else { keystate[VK_RMENU] = 0x80; - left_alt = 0; + left_alt = false; } } @@ -4373,7 +4385,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, } /* Control-Numlock for app-keypad mode switch */ if (wParam == VK_PAUSE && shift_state == 2) { - term->app_keypad_keys ^= 1; + term->app_keypad_keys = !term->app_keypad_keys; return 0; } @@ -4782,7 +4794,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, /* Okay we've done everything interesting; let windows deal with * the boring stuff */ { - BOOL capsOn=0; + bool capsOn = false; /* helg: clear CAPS LOCK state if caps lock switches to cyrillic */ if(keystate[VK_CAPITAL] != 0 && @@ -4862,7 +4874,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, keybuf = nc; term_seen_key_event(term); if (ldisc) - luni_send(ldisc, &keybuf, 1, 1); + luni_send(ldisc, &keybuf, 1, true); continue; } @@ -4874,7 +4886,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, keybuf = alt_sum; term_seen_key_event(term); if (ldisc) - luni_send(ldisc, &keybuf, 1, 1); + luni_send(ldisc, &keybuf, 1, true); } else { char ch = (char) alt_sum; /* @@ -4888,13 +4900,13 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, */ term_seen_key_event(term); if (ldisc) - ldisc_send(ldisc, &ch, 1, 1); + ldisc_send(ldisc, &ch, 1, true); } alt_sum = 0; } else { term_seen_key_event(term); if (ldisc) - luni_send(ldisc, &wch, 1, 1); + luni_send(ldisc, &wch, 1, true); } } else { if(capsOn && wch < 0x80) { @@ -4903,17 +4915,19 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, cbuf[1] = xlat_uskbd2cyrllic(wch); term_seen_key_event(term); if (ldisc) - luni_send(ldisc, cbuf+!left_alt, 1+!!left_alt, 1); + luni_send(ldisc, cbuf+!left_alt, 1+!!left_alt, + true); } else { WCHAR cbuf[2]; cbuf[0] = '\033'; cbuf[1] = wch; term_seen_key_event(term); if (ldisc) - luni_send(ldisc, cbuf +!left_alt, 1+!!left_alt, 1); + luni_send(ldisc, cbuf +!left_alt, 1+!!left_alt, + true); } } - show_mouseptr(0); + show_mouseptr(false); } /* This is so the ALT-Numpad and dead keys work correctly. */ @@ -4978,7 +4992,7 @@ static void wintw_set_scrollbar(TermWin *tw, int total, int start, int page) SetScrollInfo(hwnd, SB_VERT, &si, true); } -static int wintw_setup_draw_ctx(TermWin *tw) +static bool wintw_setup_draw_ctx(TermWin *tw) { assert(!wintw_hdc); wintw_hdc = make_hdc(); @@ -5004,7 +5018,7 @@ static void real_palette_set(int n, int r, int g, int b) } } -static int wintw_palette_get(TermWin *tw, int n, int *r, int *g, int *b) +static bool wintw_palette_get(TermWin *tw, int n, int *r, int *g, int *b) { if (n < 0 || n >= NALLCOLOURS) return false; @@ -5064,7 +5078,7 @@ static void wintw_palette_reset(TermWin *tw) } } -void write_aclip(int clipboard, char *data, int len, int must_deselect) +void write_aclip(int clipboard, char *data, int len, bool must_deselect) { HGLOBAL clipdata; void *lock; @@ -5113,7 +5127,7 @@ int cmpCOLORREF(void *va, void *vb) */ static void wintw_clip_write( TermWin *tw, int clipboard, wchar_t *data, int *attr, - truecolour *truecolour, int len, int must_deselect) + truecolour *truecolour, int len, bool must_deselect) { HGLOBAL clipdata, clipdata2, clipdata3; int len2; @@ -5536,9 +5550,11 @@ static DWORD WINAPI clipboard_read_threadfunc(void *param) if (OpenClipboard(NULL)) { if ((clipdata = GetClipboardData(CF_UNICODETEXT))) { - SendMessage(hwnd, WM_GOT_CLIPDATA, (WPARAM)1, (LPARAM)clipdata); + SendMessage(hwnd, WM_GOT_CLIPDATA, + (WPARAM)true, (LPARAM)clipdata); } else if ((clipdata = GetClipboardData(CF_TEXT))) { - SendMessage(hwnd, WM_GOT_CLIPDATA, (WPARAM)0, (LPARAM)clipdata); + SendMessage(hwnd, WM_GOT_CLIPDATA, + (WPARAM)false, (LPARAM)clipdata); } CloseClipboard(); } @@ -5546,7 +5562,7 @@ static DWORD WINAPI clipboard_read_threadfunc(void *param) return 0; } -static void process_clipdata(HGLOBAL clipdata, int unicode) +static void process_clipdata(HGLOBAL clipdata, bool unicode) { wchar_t *clipboard_contents = NULL; size_t clipboard_length = 0; @@ -5641,7 +5657,7 @@ void nonfatal(const char *fmt, ...) sfree(stuff); } -static BOOL flash_window_ex(DWORD dwFlags, UINT uCount, DWORD dwTimeout) +static bool flash_window_ex(DWORD dwFlags, UINT uCount, DWORD dwTimeout) { if (p_FlashWindowEx) { FLASHWINFO fi; @@ -5658,7 +5674,7 @@ static BOOL flash_window_ex(DWORD dwFlags, UINT uCount, DWORD dwTimeout) static void flash_window(int mode); static long next_flash; -static int flashing = 0; +static bool flashing = false; /* * Timer for platforms where we must maintain window flashing manually @@ -5681,7 +5697,7 @@ static void flash_window(int mode) if ((mode == 0) || (beep_ind == B_IND_DISABLED)) { /* stop */ if (flashing) { - flashing = 0; + flashing = false; if (p_FlashWindowEx) flash_window_ex(FLASHW_STOP, 0, 0); else @@ -5691,7 +5707,7 @@ static void flash_window(int mode) } else if (mode == 2) { /* start */ if (!flashing) { - flashing = 1; + flashing = true; if (p_FlashWindowEx) { /* For so-called "steady" mode, we use uCount=2, which * seems to be the traditional number of flashes used @@ -5783,7 +5799,7 @@ static void wintw_bell(TermWin *tw, int mode) * Minimise or restore the window in response to a server-side * request. */ -static void wintw_set_minimised(TermWin *tw, int minimised) +static void wintw_set_minimised(TermWin *tw, bool minimised) { if (IsIconic(hwnd)) { if (!minimised) @@ -5812,7 +5828,7 @@ static void wintw_move(TermWin *tw, int x, int y) * Move the window to the top or bottom of the z-order in response * to a server-side request. */ -static void wintw_set_zorder(TermWin *tw, int top) +static void wintw_set_zorder(TermWin *tw, bool top) { if (conf_get_bool(conf, CONF_alwaysontop)) return; /* ignore */ @@ -5832,7 +5848,7 @@ static void wintw_refresh(TermWin *tw) * Maximise or restore the window in response to a server-side * request. */ -static void wintw_set_maximised(TermWin *tw, int maximised) +static void wintw_set_maximised(TermWin *tw, bool maximised) { if (IsZoomed(hwnd)) { if (!maximised) @@ -5846,7 +5862,7 @@ static void wintw_set_maximised(TermWin *tw, int maximised) /* * Report whether the window is iconic, for terminal reports. */ -static int wintw_is_minimised(TermWin *tw) +static bool wintw_is_minimised(TermWin *tw) { return IsIconic(hwnd); } @@ -5876,7 +5892,7 @@ static void wintw_get_pixels(TermWin *tw, int *x, int *y) /* * Return the window or icon title. */ -static const char *wintw_get_title(TermWin *tw, int icon) +static const char *wintw_get_title(TermWin *tw, bool icon) { return icon ? icon_name : window_name; } @@ -5884,7 +5900,7 @@ static const char *wintw_get_title(TermWin *tw, int icon) /* * See if we're in full-screen mode. */ -static int is_full_screen() +static bool is_full_screen() { if (!IsZoomed(hwnd)) return false; @@ -5896,7 +5912,7 @@ static int is_full_screen() /* Get the rect/size of a full screen window using the nearest available * monitor in multimon systems; default to something sensible if only * one monitor is present. */ -static int get_fullscreen_rect(RECT * ss) +static bool get_fullscreen_rect(RECT * ss) { #if defined(MONITOR_DEFAULTTONEAREST) && !defined(NO_MULTIMON) HMONITOR mon; @@ -6009,13 +6025,13 @@ static void flip_full_screen() } } -static int win_seat_output(Seat *seat, int is_stderr, +static int win_seat_output(Seat *seat, bool is_stderr, const void *data, int len) { return term_data(term, is_stderr, data, len); } -static int win_seat_eof(Seat *seat) +static bool win_seat_eof(Seat *seat) { return true; /* do respond to incoming EOF with outgoing */ } diff --git a/windows/winhandl.c b/windows/winhandl.c index 88c375cd..2a59885b 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -58,10 +58,10 @@ struct handle_generic { HANDLE h; /* the handle itself */ HANDLE ev_to_main; /* event used to signal main thread */ HANDLE ev_from_main; /* event used to signal back to us */ - int moribund; /* are we going to kill this soon? */ - int done; /* request subthread to terminate */ - int defunct; /* has the subthread already gone? */ - int busy; /* operation currently in progress? */ + bool moribund; /* are we going to kill this soon? */ + bool done; /* request subthread to terminate */ + bool defunct; /* has the subthread already gone? */ + bool busy; /* operation currently in progress? */ void *privdata; /* for client to remember who they are */ }; @@ -81,10 +81,10 @@ struct handle_input { HANDLE h; /* the handle itself */ HANDLE ev_to_main; /* event used to signal main thread */ HANDLE ev_from_main; /* event used to signal back to us */ - int moribund; /* are we going to kill this soon? */ - int done; /* request subthread to terminate */ - int defunct; /* has the subthread already gone? */ - int busy; /* operation currently in progress? */ + bool moribund; /* are we going to kill this soon? */ + bool done; /* request subthread to terminate */ + bool defunct; /* has the subthread already gone? */ + bool busy; /* operation currently in progress? */ void *privdata; /* for client to remember who they are */ /* @@ -115,7 +115,8 @@ static DWORD WINAPI handle_input_threadfunc(void *param) struct handle_input *ctx = (struct handle_input *) param; OVERLAPPED ovl, *povl; HANDLE oev; - int readret, readlen, finished; + bool readret, finished; + int readlen; if (ctx->flags & HANDLE_FLAG_OVERLAPPED) { povl = &ovl; @@ -241,10 +242,10 @@ struct handle_output { HANDLE h; /* the handle itself */ HANDLE ev_to_main; /* event used to signal main thread */ HANDLE ev_from_main; /* event used to signal back to us */ - int moribund; /* are we going to kill this soon? */ - int done; /* request subthread to terminate */ - int defunct; /* has the subthread already gone? */ - int busy; /* operation currently in progress? */ + bool moribund; /* are we going to kill this soon? */ + bool done; /* request subthread to terminate */ + bool defunct; /* has the subthread already gone? */ + bool busy; /* operation currently in progress? */ void *privdata; /* for client to remember who they are */ /* @@ -284,7 +285,7 @@ static DWORD WINAPI handle_output_threadfunc(void *param) struct handle_output *ctx = (struct handle_output *) param; OVERLAPPED ovl, *povl; HANDLE oev; - int writeret; + bool writeret; if (ctx->flags & HANDLE_FLAG_OVERLAPPED) { povl = &ovl; @@ -377,10 +378,10 @@ struct handle_foreign { HANDLE h; /* the handle itself */ HANDLE ev_to_main; /* event used to signal main thread */ HANDLE ev_from_main; /* event used to signal back to us */ - int moribund; /* are we going to kill this soon? */ - int done; /* request subthread to terminate */ - int defunct; /* has the subthread already gone? */ - int busy; /* operation currently in progress? */ + bool moribund; /* are we going to kill this soon? */ + bool done; /* request subthread to terminate */ + bool defunct; /* has the subthread already gone? */ + bool busy; /* operation currently in progress? */ void *privdata; /* for client to remember who they are */ /* diff --git a/windows/winhelp.c b/windows/winhelp.c index 03444236..53e8dc1e 100644 --- a/windows/winhelp.c +++ b/windows/winhelp.c @@ -15,9 +15,9 @@ #include #endif /* NO_HTMLHELP */ -static int requested_help; +static bool requested_help; static char *help_path; -static int help_has_contents; +static bool help_has_contents; #ifndef NO_HTMLHELP DECL_WINDOWS_FUNCTION(static, HWND, HtmlHelpA, (HWND, LPCSTR, UINT, DWORD_PTR)); static char *chm_path; @@ -74,7 +74,7 @@ void shutdown_help(void) * call HH_UNINITIALIZE.) */ } -int has_help(void) +bool has_help(void) { /* * FIXME: it would be nice here to disregard help_path on diff --git a/windows/winhsock.c b/windows/winhsock.c index fdc225b4..71f2c188 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -36,7 +36,7 @@ typedef struct HandleSocket { /* Data received from stderr_H, if we have one. */ bufchain stderrdata; - int defer_close, deferred_close; /* in case of re-entrance */ + bool defer_close, deferred_close; /* in case of re-entrance */ char *error; @@ -209,7 +209,7 @@ static void handle_socket_unfreeze(void *hsv) } } -static void sk_handle_set_frozen(Socket *s, int is_frozen) +static void sk_handle_set_frozen(Socket *s, bool is_frozen) { HandleSocket *hs = container_of(s, HandleSocket, sock); @@ -324,7 +324,7 @@ static const SocketVtable HandleSocket_sockvt = { }; Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, - Plug *plug, int overlapped) + Plug *plug, bool overlapped) { HandleSocket *hs; int flags = (overlapped ? HANDLE_FLAG_OVERLAPPED : 0); diff --git a/windows/winjump.c b/windows/winjump.c index dccdb93d..745984ca 100644 --- a/windows/winjump.c +++ b/windows/winjump.c @@ -492,7 +492,7 @@ static void update_jumplist_from_registry(void) IObjectArray *array = NULL; IShellLink *link = NULL; IObjectArray *pRemoved = NULL; - int need_abort = false; + bool need_abort = false; /* * Create an ICustomDestinationList: the top-level object which @@ -538,7 +538,7 @@ static void update_jumplist_from_registry(void) link = make_shell_link(NULL, piterator); if (link) { UINT i; - int found; + bool found; /* * Check that the link isn't in the user-removed list. @@ -715,7 +715,7 @@ void remove_session_from_jumplist(const char * const sessionname) /* Set Explicit App User Model Id to fix removable media error with jump lists */ -BOOL set_explicit_app_user_model_id() +bool set_explicit_app_user_model_id() { DECL_WINDOWS_FUNCTION(static, HRESULT, SetCurrentProcessExplicitAppUserModelID, (PCWSTR)); diff --git a/windows/winmisc.c b/windows/winmisc.c index 6bdbedee..bf60d4a5 100644 --- a/windows/winmisc.c +++ b/windows/winmisc.c @@ -35,12 +35,12 @@ const char *filename_to_str(const Filename *fn) return fn->path; } -int filename_equal(const Filename *f1, const Filename *f2) +bool filename_equal(const Filename *f1, const Filename *f2) { return !strcmp(f1->path, f2->path); } -int filename_is_null(const Filename *fn) +bool filename_is_null(const Filename *fn) { return !*fn->path; } @@ -81,12 +81,12 @@ char *get_username(void) { DWORD namelen; char *user; - int got_username = false; + bool got_username = false; DECL_WINDOWS_FUNCTION(static, BOOLEAN, GetUserNameExA, (EXTENDED_NAME_FORMAT, LPSTR, PULONG)); { - static int tried_usernameex = false; + static bool tried_usernameex = false; if (!tried_usernameex) { /* Not available on Win9x, so load dynamically */ HMODULE secur32 = load_system32_dll("secur32.dll"); @@ -125,7 +125,7 @@ char *get_username(void) if (!got_username) { /* Fall back to local user name */ namelen = 0; - if (GetUserName(NULL, &namelen) == false) { + if (!GetUserName(NULL, &namelen)) { /* * Apparently this doesn't work at least on Windows XP SP2. * Thus assume a maximum of 256. It will fail again if it @@ -559,8 +559,7 @@ void *minefield_c_realloc(void *p, size_t size) #endif /* MINEFIELD */ -FontSpec *fontspec_new(const char *name, - int bold, int height, int charset) +FontSpec *fontspec_new(const char *name, bool bold, int height, int charset) { FontSpec *f = snew(FontSpec); f->name = dupstr(name); @@ -594,7 +593,7 @@ FontSpec *fontspec_deserialise(BinarySource *src) return fontspec_new(name, isbold, height, charset); } -int open_for_write_would_lose_data(const Filename *fn) +bool open_for_write_would_lose_data(const Filename *fn) { WIN32_FILE_ATTRIBUTE_DATA attrs; if (!GetFileAttributesEx(fn->path, GetFileExInfoStandard, &attrs)) { diff --git a/windows/winnet.c b/windows/winnet.c index 44092bbb..2e6b0f03 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -53,20 +53,20 @@ struct NetSocket { SOCKET s; Plug *plug; bufchain output_data; - int connected; - int writable; - int frozen; /* this causes readability notifications to be ignored */ - int frozen_readable; /* this means we missed at least one readability - * notification while we were frozen */ - int localhost_only; /* for listening sockets */ + bool connected; + bool writable; + bool frozen; /* this causes readability notifications to be ignored */ + bool frozen_readable; /* this means we missed at least one readability + * notification while we were frozen */ + bool localhost_only; /* for listening sockets */ char oobdata[1]; int sending_oob; - int oobinline, nodelay, keepalive, privport; + bool oobinline, nodelay, keepalive, privport; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; SockAddr *addr; SockAddrStep step; int port; - int pending_error; /* in case send() returns error */ + int pending_error; /* in case send() returns error */ /* * We sometimes need pairs of Socket structures to be linked: * if we are listening on the same IPv6 and v4 port, for @@ -81,9 +81,9 @@ struct NetSocket { struct SockAddr { int refcount; char *error; - int resolved; - int namedpipe; /* indicates that this SockAddr is phony, holding a Windows - * named pipe pathname instead of a network address */ + bool resolved; + bool namedpipe; /* indicates that this SockAddr is phony, holding a Windows + * named pipe pathname instead of a network address */ #ifndef NO_IPV6 struct addrinfo *ais; /* Addresses IPv6 style. */ #endif @@ -206,7 +206,7 @@ static HMODULE winsock2_module = NULL; static HMODULE wship6_module = NULL; #endif -int sk_startup(int hi, int lo) +bool sk_startup(int hi, int lo) { WORD winsock_ver; @@ -657,7 +657,7 @@ SockAddr *sk_namedpipe_addr(const char *pipename) return ret; } -int sk_nextaddr(SockAddr *addr, SockAddrStep *step) +bool sk_nextaddr(SockAddr *addr, SockAddrStep *step) { #ifndef NO_IPV6 if (step->ai) { @@ -739,12 +739,12 @@ static SockAddr sk_extractaddr_tmp( return toret; } -int sk_addr_needs_port(SockAddr *addr) +bool sk_addr_needs_port(SockAddr *addr) { - return addr->namedpipe ? false : true; + return !addr->namedpipe; } -int sk_hostname_is_local(const char *name) +bool sk_hostname_is_local(const char *name) { return !strcmp(name, "localhost") || !strcmp(name, "::1") || @@ -754,10 +754,10 @@ int sk_hostname_is_local(const char *name) static INTERFACE_INFO local_interfaces[16]; static int n_local_interfaces; /* 0=not yet, -1=failed, >0=number */ -static int ipv4_is_local_addr(struct in_addr addr) +static bool ipv4_is_local_addr(struct in_addr addr) { if (ipv4_is_loopback(addr)) - return 1; /* loopback addresses are local */ + return true; /* loopback addresses are local */ if (!n_local_interfaces) { SOCKET s = p_socket(AF_INET, SOCK_DGRAM, 0); DWORD retbytes; @@ -778,13 +778,13 @@ static int ipv4_is_local_addr(struct in_addr addr) SOCKADDR_IN *address = (SOCKADDR_IN *)&local_interfaces[i].iiAddress; if (address->sin_addr.s_addr == addr.s_addr) - return 1; /* this address is local */ + return true; /* this address is local */ } } - return 0; /* this address is not local */ + return false; /* this address is not local */ } -int sk_address_is_local(SockAddr *addr) +bool sk_address_is_local(SockAddr *addr) { SockAddrStep step; int family; @@ -811,13 +811,13 @@ int sk_address_is_local(SockAddr *addr) } } else { assert(family == AF_UNSPEC); - return 0; /* we don't know; assume not */ + return false; /* we don't know; assume not */ } } -int sk_address_is_special_local(SockAddr *addr) +bool sk_address_is_special_local(SockAddr *addr) { - return 0; /* no Unix-domain socket analogue here */ + return false; /* no Unix-domain socket analogue here */ } int sk_addrtype(SockAddr *addr) @@ -902,11 +902,11 @@ static void sk_net_close(Socket *s); static int sk_net_write(Socket *s, const void *data, int len); static int sk_net_write_oob(Socket *s, const void *data, int len); static void sk_net_write_eof(Socket *s); -static void sk_net_set_frozen(Socket *s, int is_frozen); +static void sk_net_set_frozen(Socket *s, bool is_frozen); static const char *sk_net_socket_error(Socket *s); static SocketPeerInfo *sk_net_peer_info(Socket *s); -extern char *do_select(SOCKET skt, int startup); +extern char *do_select(SOCKET skt, bool startup); static const SocketVtable NetSocket_sockvt = { sk_net_plug, @@ -934,12 +934,12 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->writable = 1; /* to start with */ + ret->writable = true; /* to start with */ ret->sending_oob = 0; ret->outgoingeof = EOF_NO; - ret->frozen = 1; - ret->frozen_readable = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ + ret->frozen = true; + ret->frozen_readable = false; + ret->localhost_only = false; /* unused, but best init anyway */ ret->pending_error = 0; ret->parent = ret->child = NULL; ret->addr = NULL; @@ -952,11 +952,11 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) return &ret->sock; } - ret->oobinline = 0; + ret->oobinline = false; /* Set up a select mechanism. This could be an AsyncSelect on a * window, or an EventSelect on an event object. */ - errstr = do_select(ret->s, 1); + errstr = do_select(ret->s, true); if (errstr) { ret->error = errstr; return &ret->sock; @@ -980,7 +980,7 @@ static DWORD try_connect(NetSocket *sock) int family; if (sock->s != INVALID_SOCKET) { - do_select(sock->s, 0); + do_select(sock->s, false); p_closesocket(sock->s); } @@ -1112,7 +1112,7 @@ static DWORD try_connect(NetSocket *sock) /* Set up a select mechanism. This could be an AsyncSelect on a * window, or an EventSelect on an event object. */ - errstr = do_select(s, 1); + errstr = do_select(s, true); if (errstr) { sock->error = errstr; err = 1; @@ -1145,7 +1145,7 @@ static DWORD try_connect(NetSocket *sock) * If we _don't_ get EWOULDBLOCK, the connect has completed * and we should set the socket as writable. */ - sock->writable = 1; + sock->writable = true; } err = 0; @@ -1165,8 +1165,8 @@ static DWORD try_connect(NetSocket *sock) return err; } -Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, - int nodelay, int keepalive, Plug *plug) +Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline, + bool nodelay, bool keepalive, Plug *plug) { NetSocket *ret; DWORD err; @@ -1179,13 +1179,13 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->connected = 0; /* to start with */ - ret->writable = 0; /* to start with */ + ret->connected = false; /* to start with */ + ret->writable = false; /* to start with */ ret->sending_oob = 0; ret->outgoingeof = EOF_NO; - ret->frozen = 0; - ret->frozen_readable = 0; - ret->localhost_only = 0; /* unused, but best init anyway */ + ret->frozen = false; + ret->frozen_readable = false; + ret->localhost_only = false; /* unused, but best init anyway */ ret->pending_error = 0; ret->parent = ret->child = NULL; ret->oobinline = oobinline; @@ -1206,7 +1206,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, } Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, - int local_host_only, int orig_address_family) + bool local_host_only, int orig_address_family) { SOCKET s; #ifndef NO_IPV6 @@ -1230,11 +1230,11 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); - ret->writable = 0; /* to start with */ + ret->writable = false; /* to start with */ ret->sending_oob = 0; ret->outgoingeof = EOF_NO; - ret->frozen = 0; - ret->frozen_readable = 0; + ret->frozen = false; + ret->frozen_readable = false; ret->localhost_only = local_host_only; ret->pending_error = 0; ret->parent = ret->child = NULL; @@ -1273,7 +1273,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); - ret->oobinline = 0; + ret->oobinline = false; p_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); @@ -1308,7 +1308,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, } else #endif { - int got_addr = 0; + bool got_addr = false; a.sin_family = AF_INET; /* @@ -1320,7 +1320,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (a.sin_addr.s_addr != INADDR_NONE) { /* Override localhost_only with specified listen addr. */ ret->localhost_only = ipv4_is_loopback(a.sin_addr); - got_addr = 1; + got_addr = true; } } @@ -1366,7 +1366,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, /* Set up a select mechanism. This could be an AsyncSelect on a * window, or an EventSelect on an event object. */ - errstr = do_select(s, 1); + errstr = do_select(s, true); if (errstr) { p_closesocket(s); ret->error = errstr; @@ -1401,14 +1401,13 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, static void sk_net_close(Socket *sock) { - extern char *do_select(SOCKET skt, int startup); NetSocket *s = container_of(sock, NetSocket, sock); if (s->child) sk_net_close(&s->child->sock); del234(sktree, s); - do_select(s->s, 0); + do_select(s->s, false); p_closesocket(s->s); if (s->addr) sk_addr_free(s->addr); @@ -1578,7 +1577,7 @@ void select_result(WPARAM wParam, LPARAM lParam) DWORD err; char buf[20480]; /* nice big buffer for plenty of speed */ NetSocket *s; - u_long atmark; + bool atmark; /* wParam is the socket itself */ @@ -1612,7 +1611,8 @@ void select_result(WPARAM wParam, LPARAM lParam) switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: - s->connected = s->writable = 1; + s->connected = true; + s->writable = true; /* * Once a socket is connected, we can stop falling * back through the candidate addresses to connect @@ -1626,7 +1626,7 @@ void select_result(WPARAM wParam, LPARAM lParam) case FD_READ: /* In the case the socket is still frozen, we don't even bother */ if (s->frozen) { - s->frozen_readable = 1; + s->frozen_readable = true; break; } @@ -1637,8 +1637,8 @@ void select_result(WPARAM wParam, LPARAM lParam) * (data prior to urgent). */ if (s->oobinline) { - atmark = 1; - p_ioctlsocket(s->s, SIOCATMARK, &atmark); + u_long atmark_from_ioctl = 1; + p_ioctlsocket(s->s, SIOCATMARK, &atmark_from_ioctl); /* * Avoid checking the return value from ioctlsocket(), * on the grounds that some WinSock wrappers don't @@ -1646,8 +1646,9 @@ void select_result(WPARAM wParam, LPARAM lParam) * which is equivalent to `no OOB pending', so the * effect will be to non-OOB-ify any OOB data. */ + atmark = atmark_from_ioctl; } else - atmark = 1; + atmark = true; ret = p_recv(s->s, buf, sizeof(buf), 0); noise_ultralight(ret); @@ -1684,7 +1685,7 @@ void select_result(WPARAM wParam, LPARAM lParam) case FD_WRITE: { int bufsize_before, bufsize_after; - s->writable = 1; + s->writable = true; bufsize_before = s->sending_oob + bufchain_size(&s->output_data); try_send(s); bufsize_after = s->sending_oob + bufchain_size(&s->output_data); @@ -1812,20 +1813,20 @@ static SocketPeerInfo *sk_net_peer_info(Socket *sock) return pi; } -static void sk_net_set_frozen(Socket *sock, int is_frozen) +static void sk_net_set_frozen(Socket *sock, bool is_frozen) { NetSocket *s = container_of(sock, NetSocket, sock); if (s->frozen == is_frozen) return; s->frozen = is_frozen; if (!is_frozen) { - do_select(s->s, 1); + do_select(s->s, true); if (s->frozen_readable) { char c; p_recv(s->s, &c, 1, MSG_PEEK); } } - s->frozen_readable = 0; + s->frozen_readable = false; } void socket_reselect_all(void) @@ -1835,7 +1836,7 @@ void socket_reselect_all(void) for (i = 0; (s = index234(sktree, i)) != NULL; i++) { if (!s->frozen) - do_select(s->s, 1); + do_select(s->s, true); } } @@ -1856,14 +1857,14 @@ SOCKET next_socket(int *state) return s ? s->s : INVALID_SOCKET; } -extern int socket_writable(SOCKET skt) +extern bool socket_writable(SOCKET skt) { NetSocket *s = find234(sktree, (void *)skt, cmpforsearch); if (s) return bufchain_size(&s->output_data) > 0; else - return 0; + return false; } int net_service_lookup(char *service) diff --git a/windows/winnoise.c b/windows/winnoise.c index b2305d26..39c2049a 100644 --- a/windows/winnoise.c +++ b/windows/winnoise.c @@ -19,9 +19,9 @@ DECL_WINDOWS_FUNCTION(static, BOOL, CryptReleaseContext, (HCRYPTPROV, DWORD)); static HMODULE wincrypt_module = NULL; -int win_read_random(void *buf, unsigned wanted) +bool win_read_random(void *buf, unsigned wanted) { - int toret = false; + bool toret = false; HCRYPTPROV crypt_provider; if (!wincrypt_module) { diff --git a/windows/winnpc.c b/windows/winnpc.c index f5bffbf7..31906e0d 100644 --- a/windows/winnpc.c +++ b/windows/winnpc.c @@ -16,7 +16,7 @@ #include "winsecur.h" Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, - Plug *plug, int overlapped); + Plug *plug, bool overlapped); Socket *new_named_pipe_client(const char *pipename, Plug *plug) { diff --git a/windows/winnps.c b/windows/winnps.c index 5ea141fa..d355a90a 100644 --- a/windows/winnps.c +++ b/windows/winnps.c @@ -16,7 +16,7 @@ #include "winsecur.h" Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, - Plug *plug, int overlapped); + Plug *plug, bool overlapped); typedef struct NamedPipeServerSocket { /* Parameters for (repeated) creation of named pipe objects */ @@ -73,7 +73,7 @@ static SocketPeerInfo *sk_namedpipeserver_peer_info(Socket *s) return NULL; } -static int create_named_pipe(NamedPipeServerSocket *ps, int first_instance) +static bool create_named_pipe(NamedPipeServerSocket *ps, bool first_instance) { SECURITY_ATTRIBUTES sa; @@ -127,7 +127,7 @@ static Socket *named_pipe_accept(accept_ctx_t ctx, Plug *plug) SockAddr *sk_namedpipe_addr(const char *pipename); static void named_pipe_accept_loop(NamedPipeServerSocket *ps, - int got_one_already) + bool got_one_already) { while (1) { int error; diff --git a/windows/winpgen.c b/windows/winpgen.c index 0c90838e..6d5c244b 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -71,7 +71,7 @@ void queue_idempotent_callback(IdempotentCallback *ic) { assert(0); } struct progress { int nphases; struct { - int exponential; + bool exponential; unsigned startpoint, total; unsigned param, current, n; /* if exponential */ unsigned mult; /* if linear */ @@ -93,11 +93,11 @@ static void progress_update(void *param, int action, int phase, int iprogress) p->nphases = 0; break; case PROGFN_LIN_PHASE: - p->phases[phase-1].exponential = 0; + p->phases[phase-1].exponential = false; p->phases[phase-1].mult = p->phases[phase].total / progress; break; case PROGFN_EXP_PHASE: - p->phases[phase-1].exponential = 1; + p->phases[phase-1].exponential = true; p->phases[phase-1].param = 0x10000 + progress; p->phases[phase-1].current = p->phases[phase-1].total; p->phases[phase-1].n = 0; @@ -212,8 +212,8 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg, * Prompt for a key file. Assumes the filename buffer is of size * FILENAME_MAX. */ -static int prompt_keyfile(HWND hwnd, char *dlgtitle, - char *filename, int save, int ppk) +static bool prompt_keyfile(HWND hwnd, char *dlgtitle, + char *filename, bool save, bool ppk) { OPENFILENAME of; memset(&of, 0, sizeof(of)); @@ -379,12 +379,12 @@ static DWORD WINAPI generate_key_thread(void *param) } struct MainDlgState { - int collecting_entropy; - int generation_thread_exists; - int key_exists; + bool collecting_entropy; + bool generation_thread_exists; + bool key_exists; int entropy_got, entropy_required, entropy_size; int key_bits, curve_bits; - int ssh2; + bool ssh2; keytype keytype; char **commentptr; /* points to key.comment or ssh2key.comment */ struct ssh2_userkey ssh2key; @@ -397,7 +397,7 @@ struct MainDlgState { HMENU filemenu, keymenu, cvtmenu; }; -static void hidemany(HWND hwnd, const int *ids, int hideit) +static void hidemany(HWND hwnd, const int *ids, bool hideit) { while (*ids) { ShowWindow(GetDlgItem(hwnd, *ids++), (hideit ? SW_HIDE : SW_SHOW)); @@ -642,10 +642,10 @@ void ui_set_key_type(HWND hwnd, struct MainDlgState *state, int button) } void load_key_file(HWND hwnd, struct MainDlgState *state, - Filename *filename, int was_import_cmd) + Filename *filename, bool was_import_cmd) { char *passphrase; - int needs_pass; + bool needs_pass; int type, realtype; int ret; const char *errmsg = NULL; @@ -1029,7 +1029,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, */ if (cmdline_keyfile) { Filename *fn = filename_from_str(cmdline_keyfile); - load_key_file(hwnd, state, fn, 0); + load_key_file(hwnd, state, fn, false); filename_free(fn); } @@ -1280,7 +1280,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, } } if (prompt_keyfile(hwnd, "Save private key as:", - filename, 1, (type == realtype))) { + filename, true, (type == realtype))) { int ret; FILE *fp = fopen(filename, "r"); if (fp) { @@ -1334,7 +1334,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, if (state->key_exists) { char filename[FILENAME_MAX]; if (prompt_keyfile(hwnd, "Save public key as:", - filename, 1, 0)) { + filename, true, false)) { int ret; FILE *fp = fopen(filename, "r"); if (fp) { @@ -1380,8 +1380,8 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA); if (!state->generation_thread_exists) { char filename[FILENAME_MAX]; - if (prompt_keyfile(hwnd, "Load private key:", - filename, 0, LOWORD(wParam)==IDC_LOAD)) { + if (prompt_keyfile(hwnd, "Load private key:", filename, false, + LOWORD(wParam) == IDC_LOAD)) { Filename *fn = filename_from_str(filename); load_key_file(hwnd, state, fn, LOWORD(wParam) != IDC_LOAD); filename_free(fn); diff --git a/windows/winpgnt.c b/windows/winpgnt.c index bae72174..ff105588 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -55,10 +55,10 @@ extern const char ver[]; static HWND keylist; static HWND aboutbox; static HMENU systray_menu, session_menu; -static int already_running; +static bool already_running; static char *putty_path; -static int restrict_putty_acl = false; +static bool restrict_putty_acl = false; /* CWD for "add key" file requester. */ static filereq *keypath = NULL; @@ -116,7 +116,7 @@ static void unmungestr(char *in, char *out, int outlen) /* Stubs needed to link against misc.c */ void queue_idempotent_callback(IdempotentCallback *ic) { assert(0); } -static int has_security; +static bool has_security; struct PassphraseProcStruct { char **passphrase; @@ -783,7 +783,7 @@ PSID get_default_sid(void) struct PageantReply { char *buf; size_t size, len; - int overflowed; + bool overflowed; BinarySink_IMPLEMENTATION; }; @@ -969,7 +969,7 @@ static char *answer_filemapping_message(const char *mapname) static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - static int menuinprogress; + static bool menuinprogress; static UINT msgTaskbarCreated = 0; switch (message) { @@ -1000,14 +1000,14 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, break; case WM_SYSTRAY2: if (!menuinprogress) { - menuinprogress = 1; + menuinprogress = true; update_sessions(); SetForegroundWindow(hwnd); TrackPopupMenu(systray_menu, TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, wParam, lParam, 0, hwnd, NULL); - menuinprogress = 0; + menuinprogress = false; } break; case WM_COMMAND: @@ -1169,7 +1169,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) WNDCLASS wndclass; MSG msg; const char *command = NULL; - int added_keys = 0; + bool added_keys = false; int argc, i; char **argv, **argstart; diff --git a/windows/winpgntc.c b/windows/winpgntc.c index d079c9b9..470fa847 100644 --- a/windows/winpgntc.c +++ b/windows/winpgntc.c @@ -15,7 +15,7 @@ #define AGENT_COPYDATA_ID 0x804e50ba /* random goop */ -int agent_exists(void) +bool agent_exists(void) { HWND hwnd; hwnd = FindWindow("Pageant", "Pageant"); diff --git a/windows/winplink.c b/windows/winplink.c index 14bb7498..493db000 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -40,11 +40,11 @@ WSAEVENT netevent; static Backend *backend; static Conf *conf; -int term_ldisc(Terminal *term, int mode) +bool term_ldisc(Terminal *term, int mode) { return false; } -static void plink_echoedit_update(Seat *seat, int echo, int edit) +static void plink_echoedit_update(Seat *seat, bool echo, bool edit) { /* Update stdin read mode to reflect changes in line discipline. */ DWORD mode; @@ -61,7 +61,7 @@ static void plink_echoedit_update(Seat *seat, int echo, int edit) SetConsoleMode(inhandle, mode); } -static int plink_output(Seat *seat, int is_stderr, const void *data, int len) +static int plink_output(Seat *seat, bool is_stderr, const void *data, int len) { if (is_stderr) { handle_write(stderr_handle, data, len); @@ -72,7 +72,7 @@ static int plink_output(Seat *seat, int is_stderr, const void *data, int len) return handle_backlog(stdout_handle) + handle_backlog(stderr_handle); } -static int plink_eof(Seat *seat) +static bool plink_eof(Seat *seat) { handle_write_eof(stdout_handle); return false; /* do not respond to incoming EOF with outgoing */ @@ -185,7 +185,7 @@ static void version(void) exit(0); } -char *do_select(SOCKET skt, int startup) +char *do_select(SOCKET skt, bool startup) { int events; if (startup) { @@ -254,18 +254,18 @@ void stdouterr_sent(struct handle *h, int new_backlog) } } -const int share_can_be_downstream = true; -const int share_can_be_upstream = true; +const bool share_can_be_downstream = true; +const bool share_can_be_upstream = true; int main(int argc, char **argv) { - int sending; + bool sending; SOCKET *sklist; int skcount, sksize; int exitcode; - int errors; - int use_subsystem = 0; - int just_test_share_exists = false; + bool errors; + bool use_subsystem = false; + bool just_test_share_exists = false; unsigned long now, next, then; const struct BackendVtable *vt; @@ -295,7 +295,7 @@ int main(int argc, char **argv) loaded_session = false; default_protocol = conf_get_int(conf, CONF_protocol); default_port = conf_get_int(conf, CONF_port); - errors = 0; + errors = false; { /* * Override the default protocol if PLINK_PROTOCOL is set. @@ -318,16 +318,16 @@ int main(int argc, char **argv) if (ret == -2) { fprintf(stderr, "plink: option \"%s\" requires an argument\n", p); - errors = 1; + errors = true; } else if (ret == 2) { --argc, ++argv; } else if (ret == 1) { continue; } else if (!strcmp(p, "-batch")) { - console_batch_mode = 1; + console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ - use_subsystem = 1; + use_subsystem = true; } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) { version(); } else if (!strcmp(p, "--help")) { @@ -367,7 +367,7 @@ int main(int argc, char **argv) break; /* done with cmdline */ } else { fprintf(stderr, "plink: unknown option \"%s\"\n", p); - errors = 1; + errors = true; } } @@ -451,7 +451,7 @@ int main(int argc, char **argv) const char *error; char *realhost; /* nodelay is only useful if stdin is a character device (console) */ - int nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && + bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); error = backend_init(vt, plink_seat, &backend, logctx, conf, diff --git a/windows/winprint.c b/windows/winprint.c index cb9184ba..b8b24512 100644 --- a/windows/winprint.c +++ b/windows/winprint.c @@ -32,7 +32,7 @@ DECL_WINDOWS_FUNCTION(static, BOOL, WritePrinter, static void init_winfuncs(void) { - static int initialised = false; + static bool initialised = false; if (initialised) return; { @@ -56,8 +56,8 @@ static void init_winfuncs(void) initialised = true; } -static int printer_add_enum(int param, DWORD level, char **buffer, - int offset, int *nprinters_ptr) +static bool printer_add_enum(int param, DWORD level, char **buffer, + int offset, int *nprinters_ptr) { DWORD needed = 0, nprinters = 0; @@ -169,7 +169,7 @@ printer_job *printer_start_job(char *printer) { printer_job *ret = snew(printer_job); DOC_INFO_1 docinfo; - int jobstarted = 0, pagestarted = 0; + bool jobstarted = false, pagestarted = false; init_winfuncs(); @@ -183,11 +183,11 @@ printer_job *printer_start_job(char *printer) if (!p_StartDocPrinter(ret->hprinter, 1, (LPBYTE)&docinfo)) goto error; - jobstarted = 1; + jobstarted = true; if (!p_StartPagePrinter(ret->hprinter)) goto error; - pagestarted = 1; + pagestarted = true; return ret; diff --git a/windows/winproxy.c b/windows/winproxy.c index c83e2b4f..73b77d42 100644 --- a/windows/winproxy.c +++ b/windows/winproxy.c @@ -13,11 +13,11 @@ #include "proxy.h" Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, - Plug *plug, int overlapped); + Plug *plug, bool overlapped); Socket *platform_new_connection(SockAddr *addr, const char *hostname, - int port, int privport, - int oobinline, int nodelay, int keepalive, + int port, bool privport, + bool oobinline, bool nodelay, bool keepalive, Plug *plug, Conf *conf) { char *cmd; diff --git a/windows/winsecur.c b/windows/winsecur.c index 656c327a..3096d26e 100644 --- a/windows/winsecur.c +++ b/windows/winsecur.c @@ -16,10 +16,10 @@ static PSID worldsid, networksid, usersid; -int got_advapi(void) +bool got_advapi(void) { - static int attempted = false; - static int successful; + static bool attempted = false; + static bool successful; static HMODULE advapi; if (!attempted) { @@ -92,7 +92,7 @@ PSID get_user_sid(void) return ret; } -int getsids(char **error) +bool getsids(char **error) { #ifdef __clang__ #pragma clang diagnostic push @@ -104,7 +104,7 @@ int getsids(char **error) #pragma clang diagnostic pop #endif - int ret = false; + bool ret = false; *error = NULL; @@ -142,14 +142,14 @@ int getsids(char **error) } -int make_private_security_descriptor(DWORD permissions, - PSECURITY_DESCRIPTOR *psd, - PACL *acl, - char **error) +bool make_private_security_descriptor(DWORD permissions, + PSECURITY_DESCRIPTOR *psd, + PACL *acl, + char **error) { EXPLICIT_ACCESS ea[3]; int acl_err; - int ret = false; + bool ret = false; *psd = NULL; @@ -228,11 +228,11 @@ int make_private_security_descriptor(DWORD permissions, return ret; } -static int really_restrict_process_acl(char **error) +static bool really_restrict_process_acl(char **error) { EXPLICIT_ACCESS ea[2]; int acl_err; - int ret=false; + bool ret = false; PACL acl = NULL; static const DWORD nastyace=WRITE_DAC | WRITE_OWNER | @@ -312,7 +312,7 @@ static int really_restrict_process_acl(char **error) void restrict_process_acl(void) { char *error = NULL; - int ret; + bool ret; #if !defined NO_SECURITY ret = really_restrict_process_acl(&error); diff --git a/windows/winsecur.h b/windows/winsecur.h index dd4da9ee..50c696db 100644 --- a/windows/winsecur.h +++ b/windows/winsecur.h @@ -33,7 +33,7 @@ DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetSecurityInfo, PSID, PSID, PACL, PACL)); DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetEntriesInAclA, (ULONG, PEXPLICIT_ACCESS, PACL, PACL *)); -int got_advapi(void); +bool got_advapi(void); /* * Find the SID describing the current user. The return value (if not @@ -51,9 +51,7 @@ PSID get_user_sid(void); * freed later using LocalFree). If it returns false, then instead * 'error' has been filled with a dynamically allocated error message. */ -int make_private_security_descriptor(DWORD permissions, - PSECURITY_DESCRIPTOR *psd, - PACL *acl, - char **error); +bool make_private_security_descriptor( + DWORD permissions, PSECURITY_DESCRIPTOR *psd, PACL *acl, char **error); #endif diff --git a/windows/winser.c b/windows/winser.c index d848c20c..24c8902b 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -18,7 +18,7 @@ struct Serial { LogContext *logctx; int bufsize; long clearbreak_time; - int break_in_progress; + bool break_in_progress; Backend backend; }; @@ -193,7 +193,7 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf) static const char *serial_init(Seat *seat, Backend **backend_handle, LogContext *logctx, Conf *conf, const char *host, int port, - char **realhost, int nodelay, int keepalive) + char **realhost, bool nodelay, bool keepalive) { Serial *serial; HANDLE serport; @@ -375,14 +375,14 @@ static const SessionSpecial *serial_get_specials(Backend *be) return specials; } -static int serial_connected(Backend *be) +static bool serial_connected(Backend *be) { - return 1; /* always connected */ + return true; /* always connected */ } -static int serial_sendok(Backend *be) +static bool serial_sendok(Backend *be) { - return 1; + return true; } static void serial_unthrottle(Backend *be, int backlog) @@ -392,12 +392,12 @@ static void serial_unthrottle(Backend *be, int backlog) handle_unthrottle(serial->in, backlog); } -static int serial_ldisc(Backend *be, int option) +static bool serial_ldisc(Backend *be, int option) { /* * Local editing and local echo are off by default. */ - return 0; + return false; } static void serial_provide_ldisc(Backend *be, Ldisc *ldisc) diff --git a/windows/winsftp.c b/windows/winsftp.c index c85c6c8f..7d0adde5 100644 --- a/windows/winsftp.c +++ b/windows/winsftp.c @@ -25,7 +25,7 @@ void platform_get_x11_auth(struct X11Display *display, Conf *conf) { /* Do nothing, therefore no auth. */ } -const int platform_uses_x11_unix_by_default = true; +const bool platform_uses_x11_unix_by_default = true; /* ---------------------------------------------------------------------- * File access abstraction. @@ -131,10 +131,8 @@ RFile *open_existing_file(const char *name, uint64_t *size, int read_from_file(RFile *f, void *buffer, int length) { - int ret; DWORD read; - ret = ReadFile(f->h, buffer, length, &read, NULL); - if (!ret) + if (!ReadFile(f->h, buffer, length, &read, NULL)) return -1; /* error */ else return read; @@ -190,10 +188,8 @@ WFile *open_existing_wfile(const char *name, uint64_t *size) int write_to_file(WFile *f, void *buffer, int length) { - int ret; DWORD written; - ret = WriteFile(f->h, buffer, length, &written, NULL); - if (!ret) + if (!WriteFile(f->h, buffer, length, &written, NULL)) return -1; /* error */ else return written; @@ -296,8 +292,7 @@ char *read_filename(DirHandle *dir) if (!dir->name) { WIN32_FIND_DATA fdat; - int ok = FindNextFile(dir->h, &fdat); - if (!ok) + if (!FindNextFile(dir->h, &fdat)) return NULL; else dir->name = dupstr(fdat.cFileName); @@ -329,7 +324,7 @@ void close_directory(DirHandle *dir) sfree(dir); } -int test_wildcard(const char *name, int cmdline) +int test_wildcard(const char *name, bool cmdline) { HANDLE fh; WIN32_FIND_DATA fdat; @@ -353,7 +348,7 @@ struct WildcardMatcher { char *srcpath; }; -char *stripslashes(const char *str, int local) +char *stripslashes(const char *str, bool local) { char *p; @@ -391,7 +386,7 @@ WildcardMatcher *begin_wildcard_matching(const char *name) ret = snew(WildcardMatcher); ret->h = h; ret->srcpath = dupstr(name); - last = stripslashes(ret->srcpath, 1); + last = stripslashes(ret->srcpath, true); *last = '\0'; if (fdat.cFileName[0] == '.' && (fdat.cFileName[1] == '\0' || @@ -407,9 +402,8 @@ char *wildcard_get_filename(WildcardMatcher *dir) { while (!dir->name) { WIN32_FIND_DATA fdat; - int ok = FindNextFile(dir->h, &fdat); - if (!ok) + if (!FindNextFile(dir->h, &fdat)) return NULL; if (fdat.cFileName[0] == '.' && @@ -437,7 +431,7 @@ void finish_wildcard_matching(WildcardMatcher *dir) sfree(dir); } -int vet_filename(const char *name) +bool vet_filename(const char *name) { if (strchr(name, '/') || strchr(name, '\\') || strchr(name, ':')) return false; @@ -448,7 +442,7 @@ int vet_filename(const char *name) return true; } -int create_directory(const char *name) +bool create_directory(const char *name) { return CreateDirectory(name, NULL) != 0; } @@ -467,7 +461,7 @@ char *dir_file_cat(const char *dir, const char *file) */ static SOCKET sftp_ssh_socket = INVALID_SOCKET; static HANDLE netevent = INVALID_HANDLE_VALUE; -char *do_select(SOCKET skt, int startup) +char *do_select(SOCKET skt, bool startup) { int events; if (startup) @@ -702,7 +696,7 @@ static DWORD WINAPI command_read_thread(void *param) return 0; } -char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok) +char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok) { int ret; struct command_read_ctx actx, *ctx = &actx; diff --git a/windows/winshare.c b/windows/winshare.c index 864dd9c6..5d98cc17 100644 --- a/windows/winshare.c +++ b/windows/winshare.c @@ -121,7 +121,7 @@ Socket *new_named_pipe_listener(const char *pipename, Plug *plug); int platform_ssh_share(const char *pi_name, Conf *conf, Plug *downplug, Plug *upplug, Socket **sock, char **logtext, char **ds_err, char **us_err, - int can_upstream, int can_downstream) + bool can_upstream, bool can_downstream) { char *name, *mutexname, *pipename; HANDLE mutex; diff --git a/windows/winstore.c b/windows/winstore.c index 52f9b337..5c9d1704 100644 --- a/windows/winstore.c +++ b/windows/winstore.c @@ -24,14 +24,14 @@ static const char *const puttystr = PUTTY_REG_POS "\\Sessions"; static const char hex[16] = "0123456789ABCDEF"; -static int tried_shgetfolderpath = false; +static bool tried_shgetfolderpath = false; static HMODULE shell32_module = NULL; DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA, (HWND, int, HANDLE, DWORD, LPSTR)); static void mungestr(const char *in, char *out) { - int candot = 0; + bool candot = false; while (*in) { if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' || @@ -43,7 +43,7 @@ static void mungestr(const char *in, char *out) } else *out++ = *in; in++; - candot = 1; + candot = true; } *out = '\0'; return; @@ -470,7 +470,7 @@ int verify_host_key(const char *hostname, int port, return 0; /* key matched OK in registry */ } -int have_ssh_host_key(const char *hostname, int port, +bool have_ssh_host_key(const char *hostname, int port, const char *keytype) { /* @@ -503,7 +503,7 @@ void store_host_key(const char *hostname, int port, * Open (or delete) the random seed file. */ enum { DEL, OPEN_R, OPEN_W }; -static int try_random_seed(char const *path, int action, HANDLE *ret) +static bool try_random_seed(char const *path, int action, HANDLE *ret) { if (action == DEL) { if (!DeleteFile(path) && GetLastError() != ERROR_FILE_NOT_FOUND) { diff --git a/windows/winstuff.h b/windows/winstuff.h index d71663c3..bbba4c3b 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -44,12 +44,12 @@ struct Filename { struct FontSpec { char *name; - int isbold; + bool isbold; int height; int charset; }; -struct FontSpec *fontspec_new(const char *name, - int bold, int height, int charset); +struct FontSpec *fontspec_new( + const char *name, bool bold, int height, int charset); #ifndef CLEARTYPE_QUALITY #define CLEARTYPE_QUALITY 5 @@ -228,7 +228,7 @@ GLOBAL HINSTANCE hinst; */ void init_help(void); void shutdown_help(void); -int has_help(void); +bool has_help(void); void launch_help(HWND hwnd, const char *topic); void quit_help(HWND hwnd); @@ -259,7 +259,7 @@ int win_seat_confirm_weak_cached_hostkey( * which takes the data string in the system code page instead of * Unicode. */ -void write_aclip(int clipboard, char *, int, int); +void write_aclip(int clipboard, char *, int, bool); #define WM_NETEVENT (WM_APP + 5) @@ -331,7 +331,7 @@ DECL_WINDOWS_FUNCTION(GLOBAL, int, select, fd_set FAR *, const struct timeval FAR *)); #endif -extern int socket_writable(SOCKET skt); +extern bool socket_writable(SOCKET skt); extern void socket_reselect_all(void); @@ -354,7 +354,7 @@ void init_common_controls(void); /* also does some DLL-loading */ * Exports from winutils.c. */ typedef struct filereq_tag filereq; /* cwd for file requester */ -BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save); +bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save); filereq *filereq_new(void); void filereq_free(filereq *state); int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid); @@ -369,7 +369,7 @@ struct prefslist { int listid, upbid, dnbid; int srcitem; int dummyitem; - int dragging; + bool dragging; }; /* @@ -384,13 +384,17 @@ struct dlgparam { char *errtitle; /* title of error sub-messageboxes */ void *data; /* data to pass in refresh events */ union control *focused, *lastfocused; /* which ctrl has focus now/before */ - char shortcuts[128]; /* track which shortcuts in use */ - int coloursel_wanted; /* has an event handler asked for + bool shortcuts[128]; /* track which shortcuts in use */ + bool coloursel_wanted; /* has an event handler asked for * a colour selector? */ - struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */ + struct { + unsigned char r, g, b; /* 0-255 */ + bool ok; + } coloursel_result; tree234 *privdata; /* stores per-control private data */ - int ended, endresult; /* has the dialog been ended? */ - int fixed_pitch_fonts; /* are we constrained to fixed fonts? */ + bool ended; /* has the dialog been ended? */ + int endresult; /* and if so, what was the result? */ + bool fixed_pitch_fonts; /* are we constrained to fixed fonts? */ }; /* @@ -403,7 +407,7 @@ HWND doctl(struct ctlpos *cp, RECT r, void bartitle(struct ctlpos *cp, char *name, int id); void beginbox(struct ctlpos *cp, char *name, int idbox); void endbox(struct ctlpos *cp); -void editboxfw(struct ctlpos *cp, int password, char *text, +void editboxfw(struct ctlpos *cp, bool password, char *text, int staticid, int editid); void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...); void bareradioline(struct ctlpos *cp, int nacross, ...); @@ -440,7 +444,7 @@ void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines, char *stext, int sid, int listid, int upbid, int dnbid); int handle_prefslist(struct prefslist *hdl, int *array, int maxmemb, - int is_dlmsg, HWND hwnd, + bool is_dlmsg, HWND hwnd, WPARAM wParam, LPARAM lParam); void progressbar(struct ctlpos *cp, int id); void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid, @@ -450,8 +454,8 @@ void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid, char *r1text, int r1id, char *r2text, int r2id); void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg); -int dlg_get_fixed_pitch_flag(dlgparam *dlg); -void dlg_set_fixed_pitch_flag(dlgparam *dlg, int flag); +bool dlg_get_fixed_pitch_flag(dlgparam *dlg); +void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag); #define MAX_SHORTCUTS_PER_CTRL 16 @@ -503,10 +507,10 @@ struct winctrl *winctrl_findbyid(struct winctrls *, int); struct winctrl *winctrl_findbyindex(struct winctrls *, int); void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, struct ctlpos *cp, struct controlset *s, int *id); -int winctrl_handle_command(struct dlgparam *dp, UINT msg, - WPARAM wParam, LPARAM lParam); +bool winctrl_handle_command(struct dlgparam *dp, UINT msg, + WPARAM wParam, LPARAM lParam); void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c); -int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id); +bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id); void dp_init(struct dlgparam *dp); void dp_add_tree(struct dlgparam *dp, struct winctrls *tree); @@ -515,15 +519,15 @@ void dp_cleanup(struct dlgparam *dp); /* * Exports from wincfg.c. */ -void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, - int midsession, int protocol); +void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, + bool midsession, int protocol); /* * Exports from windlg.c. */ void defuse_showwindow(void); -int do_config(void); -int do_reconfig(HWND, int); +bool do_config(void); +bool do_reconfig(HWND, int); void showeventlog(HWND); void showabout(HWND); void force_normal(HWND hwnd); @@ -539,7 +543,7 @@ void dll_hijacking_protection(void); HMODULE load_system32_dll(const char *libname); const char *win_strerror(int error); void restrict_process_acl(void); -GLOBAL int restricted_acl; +GLOBAL bool restricted_acl; /* A few pieces of up-to-date Windows API definition needed for older * compilers. */ @@ -561,7 +565,7 @@ DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory * Exports from sizetip.c. */ void UpdateSizeTip(HWND src, int cx, int cy); -void EnableSizeTip(int bEnable); +void EnableSizeTip(bool bEnable); /* * Exports from unicode.c. @@ -617,12 +621,12 @@ extern const struct BackendVtable serial_backend; void add_session_to_jumplist(const char * const sessionname); void remove_session_from_jumplist(const char * const sessionname); void clear_jumplist(void); -BOOL set_explicit_app_user_model_id(); +bool set_explicit_app_user_model_id(); /* * Exports from winnoise.c. */ -int win_read_random(void *buf, unsigned wanted); /* returns true on success */ +bool win_read_random(void *buf, unsigned wanted); /* returns true on success */ /* * Extra functions in winstore.c over and above the interface in diff --git a/windows/winucs.c b/windows/winucs.c index f40444c9..7195081a 100644 --- a/windows/winucs.c +++ b/windows/winucs.c @@ -440,7 +440,7 @@ static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr); void init_ucs(Conf *conf, struct unicode_data *ucsdata) { int i, j; - int used_dtf = 0; + bool used_dtf = false; int vtmode; /* Decide on the Line and Font codepages */ @@ -449,13 +449,13 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata) if (ucsdata->font_codepage <= 0) { ucsdata->font_codepage=0; - ucsdata->dbcs_screenfont=0; + ucsdata->dbcs_screenfont=false; } vtmode = conf_get_int(conf, CONF_vtmode); if (vtmode == VT_OEMONLY) { ucsdata->font_codepage = 437; - ucsdata->dbcs_screenfont = 0; + ucsdata->dbcs_screenfont = false; if (ucsdata->line_codepage <= 0) ucsdata->line_codepage = GetACP(); } else if (ucsdata->line_codepage <= 0) @@ -493,7 +493,7 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata) vtmode == VT_POORMAN || ucsdata->font_codepage==0)) { /* For DBCS and POOR fonts force direct to font */ - used_dtf = 1; + used_dtf = true; for (i = 0; i < 32; i++) ucsdata->unitab_line[i] = (WCHAR) i; for (i = 32; i < 256; i++) @@ -1201,7 +1201,7 @@ int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen, return MultiByteToWideChar(codepage, flags, mbstr, mblen, wcstr, wclen); } -int is_dbcs_leadbyte(int codepage, char byte) +bool is_dbcs_leadbyte(int codepage, char byte) { return IsDBCSLeadByteEx(codepage, byte); } diff --git a/windows/winutils.c b/windows/winutils.c index 58614966..5edde65b 100644 --- a/windows/winutils.c +++ b/windows/winutils.c @@ -34,17 +34,17 @@ struct filereq_tag { * save==1 -> GetSaveFileName; save==0 -> GetOpenFileName * `state' is optional. */ -BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save) +bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save) { TCHAR cwd[MAX_PATH]; /* process CWD */ - BOOL ret; + bool ret; /* Get process CWD */ if (preserve) { DWORD r = GetCurrentDirectory(lenof(cwd), cwd); if (r == 0 || r >= lenof(cwd)) /* Didn't work, oh well. Stop trying to be clever. */ - preserve = 0; + preserve = false; } /* Open the file requester, maybe setting lpstrInitialDir */ @@ -321,7 +321,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv, p = cmdline; q = outputline; outputargc = 0; while (*p) { - int quote; + bool quote; /* Skip whitespace searching for start of argument. */ while (*p && isspace(*p)) p++; @@ -331,7 +331,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv, outputargv[outputargc] = q; outputargstart[outputargc] = p; outputargc++; - quote = 0; + quote = false; /* Copy data into the argument until it's finished. */ while (*p) { diff --git a/windows/winx11.c b/windows/winx11.c index eb15b39a..e85fe4fb 100644 --- a/windows/winx11.c +++ b/windows/winx11.c @@ -16,4 +16,4 @@ void platform_get_x11_auth(struct X11Display *disp, Conf *conf) x11_get_auth_from_authfile(disp, xauthpath); } -const int platform_uses_x11_unix_by_default = false; +const bool platform_uses_x11_unix_by_default = false; diff --git a/x11fwd.c b/x11fwd.c index 4f1bb45c..b0bfa3c1 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -34,9 +34,9 @@ typedef struct X11Connection { char *auth_protocol; unsigned char *auth_data; int data_read, auth_plen, auth_psize, auth_dlen, auth_dsize; - int verified; - int input_wanted; - int no_data_sent_to_x_client; + bool verified; + bool input_wanted; + bool no_data_sent_to_x_client; char *peer_addr; int peer_port; SshChannel *c; /* channel structure held by SSH backend */ @@ -302,7 +302,8 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf, if (!err) { /* Create trial connection to see if there is a useful Unix-domain * socket */ - Socket *s = sk_new(sk_addr_dup(ux), 0, 0, 0, 0, 0, nullplug); + Socket *s = sk_new(sk_addr_dup(ux), 0, false, false, + false, false, nullplug); err = sk_socket_error(s); sk_close(s); } @@ -469,7 +470,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp, ptrlen addr, protoname, data; char *displaynum_string; int displaynum; - int ideal_match = false; + bool ideal_match = false; char *ourhostname; /* A maximally sized (wildly implausible) .Xauthority record @@ -502,7 +503,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp, * that is; so if we can't find a Unix-domain-socket entry we'll * fall back to an IP-based entry if we can find one. */ - int localhost = !disp->unixdomain && sk_address_is_local(disp->addr); + bool localhost = !disp->unixdomain && sk_address_is_local(disp->addr); authfp = fopen(authfilename, "rb"); if (!authfp) @@ -527,7 +528,7 @@ void x11_get_auth_from_authfile(struct X11Display *disp, BinarySource_BARE_INIT(src, buf, size); while (!ideal_match) { - int match = false; + bool match = false; if (src->pos >= MAX_RECORD_SIZE) { size -= src->pos; @@ -617,10 +618,12 @@ void x11_get_auth_from_authfile(struct X11Display *disp, break; case 256: /* Unix-domain / localhost */ if ((disp->unixdomain || localhost) - && ourhostname && ptrlen_eq_string(addr, ourhostname)) + && ourhostname && ptrlen_eq_string(addr, ourhostname)) { /* A matching Unix-domain socket is always the best * match. */ - match = ideal_match = true; + match = true; + ideal_match = true; + } break; } @@ -683,7 +686,7 @@ static void x11_send_init_error(struct X11Connection *conn, const char *err_message); static void x11_closing(Plug *plug, const char *error_msg, int error_code, - int calling_back) + bool calling_back) { struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); @@ -759,9 +762,9 @@ static const PlugVtable X11Connection_plugvt = { }; static void x11_chan_free(Channel *chan); -static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len); +static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len); static void x11_send_eof(Channel *chan); -static void x11_set_input_wanted(Channel *chan, int wanted); +static void x11_set_input_wanted(Channel *chan, bool wanted); static char *x11_log_close_msg(Channel *chan); static const struct ChannelVtable X11Connection_channelvt = { @@ -795,7 +798,7 @@ static const struct ChannelVtable X11Connection_channelvt = { */ Channel *x11_new_channel(tree234 *authtree, SshChannel *c, const char *peeraddr, int peerport, - int connection_sharing_possible) + bool connection_sharing_possible) { struct X11Connection *xconn; @@ -809,7 +812,7 @@ Channel *x11_new_channel(tree234 *authtree, SshChannel *c, (connection_sharing_possible ? 128 : 0); xconn->auth_protocol = NULL; xconn->authtree = authtree; - xconn->verified = 0; + xconn->verified = false; xconn->data_read = 0; xconn->input_wanted = true; xconn->no_data_sent_to_x_client = true; @@ -852,7 +855,7 @@ static void x11_chan_free(Channel *chan) sfree(xconn); } -static void x11_set_input_wanted(Channel *chan, int wanted) +static void x11_set_input_wanted(Channel *chan, bool wanted) { assert(chan->vt == &X11Connection_channelvt); X11Connection *xconn = container_of(chan, X11Connection, chan); @@ -887,7 +890,7 @@ static void x11_send_init_error(struct X11Connection *xconn, sfree(full_message); } -static int x11_parse_ip(const char *addr_string, unsigned long *ip) +static bool x11_parse_ip(const char *addr_string, unsigned long *ip) { /* @@ -907,7 +910,7 @@ static int x11_parse_ip(const char *addr_string, unsigned long *ip) /* * Called to send data down the raw connection. */ -static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) +static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len) { assert(chan->vt == &X11Connection_channelvt); X11Connection *xconn = container_of(chan, X11Connection, chan); @@ -1010,7 +1013,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) xconn->disp = auth_matched->disp; xconn->s = new_connection(sk_addr_dup(xconn->disp->addr), xconn->disp->realhost, xconn->disp->port, - 0, 1, 0, 0, &xconn->plug, + false, true, false, false, &xconn->plug, sshfwd_get_conf(xconn->c)); if ((err = sk_socket_error(xconn->s)) != NULL) { char *err_message = dupprintf("unable to connect to" @@ -1051,7 +1054,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) /* * Now we're done. */ - xconn->verified = 1; + xconn->verified = true; } /*