From: Florian Forster Date: Wed, 25 Nov 2009 18:53:26 +0000 (+0100) Subject: src/main.c: Let ros_connect fail if logging in returns an error. X-Git-Tag: librouteros-0.1.0~7 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=895bb0f2ce317cee72a33004286eb66ffc253304;p=routeros-api.git src/main.c: Let ros_connect fail if logging in returns an error. --- diff --git a/src/main.c b/src/main.c index 82e8c7f..a941750 100644 --- a/src/main.c +++ b/src/main.c @@ -638,7 +638,13 @@ static int login2_handler (ros_connection_t *c, const ros_reply_t *r, /* {{{ */ printf ("login2_handler has been called.\n"); reply_dump (r); - if (strcmp (r->status, "done") != 0) + if (strcmp (r->status, "trap") == 0) + { + ros_debug ("login2_handler: Logging in failed: %s.\n", + ros_reply_param_val_by_key (r, "message")); + return (EACCES); + } + else if (strcmp (r->status, "done") != 0) { ros_debug ("login2_handler: Unexpected status: %s.\n", r->status); return (EPROTO); @@ -797,6 +803,13 @@ ros_connection_t *ros_connect (const char *node, const char *service, /* {{{ */ status = ros_query (c, "/login", /* args num = */ 0, /* args = */ NULL, login_handler, &user_data); + if (status != 0) + { + ros_disconnect (c); + errno = status; + return (NULL); + } + return (c); } /* }}} ros_connection_t *ros_connect */