Added the mt_reply_status function.
[routeros-api.git] / src / main.c
index 26b4423..a0d6dcc 100644 (file)
 
 #include "routeros_api.h"
 
+#if 1
+# define mt_debug(...) fprintf (stdout, __VA_ARGS__)
+#else
+# define mt_debug(...) /**/
+#endif
 
 /* FIXME */
 char *strdup (const char *);
@@ -300,6 +305,9 @@ static int send_command (mt_connection_t *c, /* {{{ */
        size_t i;
        int status;
 
+       /* FIXME: For debugging only */
+       memset (buffer, 0, sizeof (buffer));
+
        buffer_ptr = buffer;
        buffer_size = sizeof (buffer);
 
@@ -326,6 +334,7 @@ static int send_command (mt_connection_t *c, /* {{{ */
                return (status);
 
        buffer_ptr = buffer;
+       buffer_size = sizeof (buffer) - buffer_size;
        while (buffer_size > 0)
        {
                ssize_t bytes_written;
@@ -528,6 +537,9 @@ static int create_socket (const char *node, const char *service) /* {{{ */
        struct addrinfo *ai_ptr;
        int status;
 
+       mt_debug ("create_socket (node = %s, service = %s);\n",
+                       node, service);
+
        memset (&ai_hint, 0, sizeof (ai_hint));
 #ifdef AI_ADDRCONFIG
        ai_hint.ai_flags |= AI_ADDRCONFIG;
@@ -549,11 +561,15 @@ static int create_socket (const char *node, const char *service) /* {{{ */
                fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
                                ai_ptr->ai_protocol);
                if (fd < 0)
+               {
+                       mt_debug ("create_socket: socket(2) failed.\n");
                        continue;
+               }
 
                status = connect (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
                if (status != 0)
                {
+                       mt_debug ("create_socket: connect(2) failed.\n");
                        close (fd);
                        continue;
                }
@@ -614,7 +630,7 @@ int mt_disconnect (mt_connection_t *c) /* {{{ */
 int mt_query (mt_connection_t *c, /* {{{ */
                const char *command,
                size_t args_num, const char * const *args,
-               mt_reply_handler_t *handler, void *user_data)
+               mt_reply_handler_t handler, void *user_data)
 {
        int status;
        mt_reply_t *r;
@@ -657,6 +673,13 @@ int mt_reply_num (const mt_reply_t *r) /* {{{ */
        return (ret);
 } /* }}} int mt_reply_num */
 
+const char *mt_reply_status (const mt_reply_t *r) /* {{{ */
+{
+       if (r == NULL)
+               return (NULL);
+       return (r->status);
+} /* }}} char *mt_reply_status */
+
 const char *mt_reply_param_key_by_index (const mt_reply_t *r, /* {{{ */
                unsigned int index)
 {