[PATCH 1/3] enumerate supported VPN protocols via openconnect_get_supported_protocols()

Daniel Lenski dlenski at gmail.com
Wed Apr 19 12:35:12 PDT 2017


On Wed, Apr 19, 2017 at 3:08 AM, David Woodhouse <dwmw2 at infradead.org> wrote:
> On Sun, 2017-04-09 at 02:03 -0700, Daniel Lenski wrote:
>>
>> --- a/library.c
>> +++ b/library.c
>> @@ -109,6 +109,9 @@ err:
>>  const struct vpn_proto openconnect_protos[] = {
>>         {
>>                 .name = "anyconnect",
>> +               .pretty_name = "Cisco AnyConnect or openconnect",
>> +               .description = "Compatible with Cisco AnyConnect SSL VPN, as well as ocserv",
>> +               .flags = OC_PROTO_PROXY | OC_PROTO_CSD | OC_PROTO_AUTH_CERT | OC_PROTO_AUTH_OTP | OC_PROTO_AUTH_STOKEN,
>>                 .vpn_close_session = cstp_bye,
>>                 .tcp_connect = cstp_connect,
>>                 .tcp_mainloop = cstp_mainloop,
>
> Those strings aren't going to get translated (by humans, in the .po
> files) unless you put them in N_("…");

I tried this with _("..."), but it's not a const expression so can't
be used with static data. According to the header file, _N("...") is a
no-op.

#ifdef ENABLE_NLS
#include <libintl.h>
#define _(s) dgettext("openconnect", s)
#else
#define _(s) ((char *)(s))
#endif
#define N_(s) s

So that's why the patch adds the _("...") wrapper in the API call
instead, where the data actually becomes user-visible. Not the right
way to do it?

int openconnect_get_supported_protocols(struct oc_vpn_proto **protos)
{
       struct oc_vpn_proto *pr;
       const struct vpn_proto *p;

       *protos = pr =
calloc(sizeof(openconnect_protos)/sizeof(*openconnect_protos),
sizeof(*pr));
       if (!pr)
               return -ENOMEM;

       for (p = openconnect_protos; p->name; p++, pr++) {
               pr->name = p->name;
               pr->pretty_name = _(p->pretty_name);
               pr->description = _(p->description);
               pr->flags = p->flags;
       }
       return 0;
}

-Dan



More information about the openconnect-devel mailing list