X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fregistration_table.c;h=812f54b0b6ae19591cb4c2a9ab2e51369b06dcc5;hb=fbb80c9cb3b384c4198341c7a1334f105d90015c;hp=f016a85bbc5dac0c708aae75c30c32afb6ff87d5;hpb=a2645e996327fdd35f57c7beb8e98d2a4ccb9d63;p=routeros-api.git diff --git a/src/registration_table.c b/src/registration_table.c index f016a85..812f54b 100644 --- a/src/registration_table.c +++ b/src/registration_table.c @@ -38,6 +38,7 @@ #include #include "routeros_api.h" +#include "ros_parse.h" /* Status: re @@ -86,7 +87,7 @@ Status: done */ struct rt_internal_data_s { - ros_registration_table_handler handler; + ros_registration_table_handler_t handler; void *user_data; }; typedef struct rt_internal_data_s rt_internal_data_t; @@ -94,53 +95,6 @@ typedef struct rt_internal_data_s rt_internal_data_t; /* * Private functions */ -static double sstrtod (const char *str) /* {{{ */ -{ - double ret; - char *endptr; - - if (str == NULL) - return (NAN); - - errno = 0; - endptr = NULL; - ret = strtod (str, &endptr); - if ((endptr == str) || (errno != 0)) - return (NAN); - - return (ret); -} /* }}} double sstrtod */ - -static int string_to_rx_tx_counters (const char *str, /* {{{ */ - uint64_t *rx, uint64_t *tx) -{ - const char *ptr; - char *endptr; - - if ((str == NULL) || (rx == NULL) || (tx == NULL)) - return (EINVAL); - - ptr = str; - errno = 0; - endptr = NULL; - *rx = (uint64_t) strtoull (ptr, &endptr, /* base = */ 10); - if ((endptr == str) || (errno != 0)) - return (EIO); - - assert (endptr != NULL); - if (*endptr != ',') - return (EIO); - - ptr = endptr + 1; - errno = 0; - endptr = NULL; - *tx = (uint64_t) strtoull (ptr, &endptr, /* base = */ 10); - if ((endptr == str) || (errno != 0)) - return (EIO); - - return (0); -} /* }}} int string_to_rx_tx_counters */ - static ros_registration_table_t *rt_reply_to_regtable (const ros_reply_t *r) /* {{{ */ { ros_registration_table_t *ret; @@ -157,21 +111,25 @@ static ros_registration_table_t *rt_reply_to_regtable (const ros_reply_t *r) /* memset (ret, 0, sizeof (*ret)); ret->interface = ros_reply_param_val_by_key (r, "interface"); + ret->radio_name = ros_reply_param_val_by_key (r, "radio-name"); + + ret->ap = sstrtob (ros_reply_param_val_by_key (r, "ap")); + ret->wds = sstrtob (ros_reply_param_val_by_key (r, "wds")); ret->rx_rate = sstrtod (ros_reply_param_val_by_key (r, "rx-rate")); ret->tx_rate = sstrtod (ros_reply_param_val_by_key (r, "tx-rate")); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "packets"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "packets"), &ret->rx_packets, &ret->tx_packets); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "bytes"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "bytes"), &ret->rx_bytes, &ret->tx_bytes); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "frames"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "frames"), &ret->rx_frames, &ret->tx_frames); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "frame-bytes"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "frame-bytes"), &ret->rx_frame_bytes, &ret->tx_frame_bytes); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frames"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frames"), &ret->rx_hw_frames, &ret->tx_hw_frames); - string_to_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frame-bytes"), + sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frame-bytes"), &ret->rx_hw_frame_bytes, &ret->tx_hw_frame_bytes); ret->rx_signal_strength = sstrtod (ros_reply_param_val_by_key (r, "signal-strength")); @@ -186,14 +144,14 @@ static ros_registration_table_t *rt_reply_to_regtable (const ros_reply_t *r) /* return (ret); } /* }}} ros_registration_table_t *rt_reply_to_regtable */ -static void rt_regtable_free (ros_registration_table_t *r) /* {{{ */ +static void rt_regtable_free (const ros_registration_table_t *r) /* {{{ */ { - ros_registration_table_t *next; + const ros_registration_table_t *next; while (r != NULL) { next = r->next; - free (r); + free ((void *) r); r = next; } } /* }}} void rt_regtable_free */ @@ -222,7 +180,7 @@ static int rt_internal_handler (ros_connection_t *c, /* {{{ */ * Public functions */ int ros_registration_table (ros_connection_t *c, /* {{{ */ - ros_registration_table_handler handler, void *user_data) + ros_registration_table_handler_t handler, void *user_data) { rt_internal_data_t data;