expose struct uclient_url
[project/uclient.git] / uclient-example.c
index e0e90153d45f01cb13d337b12e726205c823c43a..083580b9a888e0b7a0b1315a9c7a91f068eff1a3 100644 (file)
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <dlfcn.h>
+#include <getopt.h>
 
 #include <libubox/blobmsg.h>
 
@@ -148,6 +149,16 @@ static int no_ssl(const char *progname)
        return 1;
 }
 
+enum {
+       L_NO_CHECK_CERTIFICATE,
+       L_CA_CERTIFICATE,
+};
+
+static const struct option longopts[] = {
+       [L_NO_CHECK_CERTIFICATE] = { "no-check-certificate", no_argument },
+       [L_CA_CERTIFICATE] = { "ca-certificate", required_argument },
+       {}
+};
 
 int main(int argc, char **argv)
 {
@@ -155,17 +166,24 @@ int main(int argc, char **argv)
        struct uclient *cl;
        bool verify = true;
        int ch;
+       int longopt_idx = 0;
 
        init_ustream_ssl();
 
-       while ((ch = getopt(argc, argv, "Cc:")) != -1) {
+       while ((ch = getopt_long(argc, argv, "", longopts, &longopt_idx)) != -1) {
                switch(ch) {
-               case 'c':
-                       if (ssl_ctx)
-                               ssl_ops->context_add_ca_crt_file(ssl_ctx, optarg);
-                       break;
-               case 'C':
-                       verify = false;
+               case 0:
+                       switch (longopt_idx) {
+                       case L_NO_CHECK_CERTIFICATE:
+                               verify = false;
+                               break;
+                       case L_CA_CERTIFICATE:
+                               if (ssl_ctx)
+                                       ssl_ops->context_add_ca_crt_file(ssl_ctx, optarg);
+                               break;
+                       default:
+                               return usage(progname);
+                       }
                        break;
                default:
                        return usage(progname);