> > +static bool > +management_callback_remote_entry(void *arg, unsigned *count, char **remote) > +{ > + assert(arg); > + assert(count); > + > + struct context *c = (struct context *) arg; > + struct connection_list *l = c->options.connection_list; > + bool ret = true; > + > + if (!remote) /* query is for the count of entries */ > + { > + *count = l->len; > + } > + else if (*count < l->len) /* the query is for entry with index = count */ > + { > + struct connection_entry *ce = l->array[*count]; > + const char *proto = proto2ascii(ce->proto, ce->af, false); > + > + /* space for output including 2 commas and a nul */ > + int len = strlen(ce->remote) + strlen(ce->remote_port) + > strlen(proto) + 2 + 1; > + char *out = malloc(len); > + check_malloc_return(out); > + > + openvpn_snprintf(out, len, "%s,%s,%s", ce->remote, ce->remote_port, > proto); > + *remote = out; > + } > + else > + { > + ret = false; > + msg(M_WARN, "Invalid arguments in management query for remote entry: > count = %u", *count); > + } > + return ret; > +} > +
I am not sure mixing two related but different functions into one function has any real advantages. A function that just returns the count would simplify that function and this function. > +static void > +man_remote_entry_count(struct management *man) > +{ > + unsigned count = 0; > + if (man->persist.callback.remote_entry) > + { > + (*man->persist.callback.remote_entry)(man->persist.callback.arg, > &count, NULL); The return value is not used here, this might upset some compilers. > + msg(M_CLIENT, ">REMOTE-ENTRY-COUNT:%u", count); > + } > + else > + { > + msg(M_CLIENT, "ERROR: The remote-entry-count command is not > supported by the current daemon mode"); > + } > +} At some point we should do a helper function that does this boilerplate code that we copy&paste here over and over. Arne _______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel