Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added libcurl examples - http://curl.haxx.se/libcurl/c/example.html

  • Loading branch information...
commit 1a14cbb0f4f51b3f9e788e2f6d7afefc259869c9 1 parent 3e0630d
Ahmad M. Zawawi authored November 17, 2012

Showing 60 changed files with 9,040 additions and 0 deletions. Show diff stats Hide diff stats

  1. 197  examples/10-at-a-time.c
  2. 177  examples/anyauthput.c
  3. 151  examples/cacertinmem.c
  4. 81  examples/certinfo.c
  5. 176  examples/chkspeed.c
  6. 124  examples/cookie_interface.c
  7. 106  examples/curlgtk.c
  8. 513  examples/curlx.c
  9. 144  examples/debug.c
  10. 442  examples/evhiperfifo.c
  11. 149  examples/externalsocket.c
  12. 86  examples/fileupload.c
  13. 527  examples/fopen.c
  14. 148  examples/ftp-wildcard.c
  15. 94  examples/ftpget.c
  16. 87  examples/ftpgetinfo.c
  17. 76  examples/ftpgetresp.c
  18. 101  examples/ftpsget.c
  19. 140  examples/ftpupload.c
  20. 174  examples/ftpuploadresume.c
  21. 53  examples/getinfo.c
  22. 112  examples/getinmemory.c
  23. 452  examples/ghiper.c
  24. 418  examples/hiperfifo.c
  25. 86  examples/href_extractor.c
  26. 130  examples/htmltidy.c
  27. 55  examples/http-post.c
  28. 61  examples/httpcustomheader.c
  29. 125  examples/httpput.c
  30. 74  examples/https.c
  31. 44  examples/imap.c
  32. 153  examples/multi-app.c
  33. 205  examples/multi-debugcallback.c
  34. 119  examples/multi-double.c
  35. 148  examples/multi-post.c
  36. 116  examples/multi-single.c
  37. 93  examples/multithread.c
  38. 94  examples/opensslthreadlock.c
  39. 64  examples/persistant.c
  40. 73  examples/pop3s.c
  41. 73  examples/pop3slist.c
  42. 143  examples/post-callback.c
  43. 103  examples/postit2.c
  44. 84  examples/progressfunc.c
  45. 51  examples/resolve.c
  46. 271  examples/rtsp.c
  47. 107  examples/sampleconv.c
  48. 135  examples/sendrecv.c
  49. 85  examples/sepheaders.c
  50. 106  examples/sftpget.c
  51. 45  examples/simple.c
  52. 53  examples/simplepost.c
  53. 87  examples/simplesmtp.c
  54. 137  examples/simplessl.c
  55. 228  examples/smooth-gtk-thread.c
  56. 203  examples/smtp-multi.c
  57. 152  examples/smtp-tls.c
  58. 366  examples/synctime.c
  59. 162  examples/threaded-ssl.c
  60. 81  examples/url2file.c
197  examples/10-at-a-time.c
... ...
@@ -0,0 +1,197 @@
  1
+/***************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9
+ *
  10
+ * This software is licensed as described in the file COPYING, which
  11
+ * you should have received as part of this distribution. The terms
  12
+ * are also available at http://curl.haxx.se/docs/copyright.html.
  13
+ *
  14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15
+ * copies of the Software, and permit persons to whom the Software is
  16
+ * furnished to do so, under the terms of the COPYING file.
  17
+ *
  18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19
+ * KIND, either express or implied.
  20
+ *
  21
+ ***************************************************************************/
  22
+/* Example application source code using the multi interface to download many
  23
+ * files, but with a capped maximum amount of simultaneous transfers.
  24
+ *
  25
+ * Written by Michael Wallner
  26
+ */
  27
+
  28
+#include <errno.h>
  29
+#include <stdlib.h>
  30
+#include <string.h>
  31
+#ifndef WIN32
  32
+#  include <unistd.h>
  33
+#endif
  34
+#include <curl/multi.h>
  35
+
  36
+static const char *urls[] = {
  37
+  "http://www.microsoft.com",
  38
+  "http://www.opensource.org",
  39
+  "http://www.google.com",
  40
+  "http://www.yahoo.com",
  41
+  "http://www.ibm.com",
  42
+  "http://www.mysql.com",
  43
+  "http://www.oracle.com",
  44
+  "http://www.ripe.net",
  45
+  "http://www.iana.org",
  46
+  "http://www.amazon.com",
  47
+  "http://www.netcraft.com",
  48
+  "http://www.heise.de",
  49
+  "http://www.chip.de",
  50
+  "http://www.ca.com",
  51
+  "http://www.cnet.com",
  52
+  "http://www.news.com",
  53
+  "http://www.cnn.com",
  54
+  "http://www.wikipedia.org",
  55
+  "http://www.dell.com",
  56
+  "http://www.hp.com",
  57
+  "http://www.cert.org",
  58
+  "http://www.mit.edu",
  59
+  "http://www.nist.gov",
  60
+  "http://www.ebay.com",
  61
+  "http://www.playstation.com",
  62
+  "http://www.uefa.com",
  63
+  "http://www.ieee.org",
  64
+  "http://www.apple.com",
  65
+  "http://www.sony.com",
  66
+  "http://www.symantec.com",
  67
+  "http://www.zdnet.com",
  68
+  "http://www.fujitsu.com",
  69
+  "http://www.supermicro.com",
  70
+  "http://www.hotmail.com",
  71
+  "http://www.ecma.com",
  72
+  "http://www.bbc.co.uk",
  73
+  "http://news.google.com",
  74
+  "http://www.foxnews.com",
  75
+  "http://www.msn.com",
  76
+  "http://www.wired.com",
  77
+  "http://www.sky.com",
  78
+  "http://www.usatoday.com",
  79
+  "http://www.cbs.com",
  80
+  "http://www.nbc.com",
  81
+  "http://slashdot.org",
  82
+  "http://www.bloglines.com",
  83
+  "http://www.techweb.com",
  84
+  "http://www.newslink.org",
  85
+  "http://www.un.org",
  86
+};
  87
+
  88
+#define MAX 10 /* number of simultaneous transfers */
  89
+#define CNT sizeof(urls)/sizeof(char*) /* total number of transfers to do */
  90
+
  91
+static size_t cb(char *d, size_t n, size_t l, void *p)
  92
+{
  93
+  /* take care of the data here, ignored in this example */
  94
+  (void)d;
  95
+  (void)p;
  96
+  return n*l;
  97
+}
  98
+
  99
+static void init(CURLM *cm, int i)
  100
+{
  101
+  CURL *eh = curl_easy_init();
  102
+
  103
+  curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, cb);
  104
+  curl_easy_setopt(eh, CURLOPT_HEADER, 0L);
  105
+  curl_easy_setopt(eh, CURLOPT_URL, urls[i]);
  106
+  curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]);
  107
+  curl_easy_setopt(eh, CURLOPT_VERBOSE, 0L);
  108
+
  109
+  curl_multi_add_handle(cm, eh);
  110
+}
  111
+
  112
+int main(void)
  113
+{
  114
+  CURLM *cm;
  115
+  CURLMsg *msg;
  116
+  long L;
  117
+  unsigned int C=0;
  118
+  int M, Q, U = -1;
  119
+  fd_set R, W, E;
  120
+  struct timeval T;
  121
+
  122
+  curl_global_init(CURL_GLOBAL_ALL);
  123
+
  124
+  cm = curl_multi_init();
  125
+
  126
+  /* we can optionally limit the total amount of connections this multi handle
  127
+     uses */
  128
+  curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX);
  129
+
  130
+  for (C = 0; C < MAX; ++C) {
  131
+    init(cm, C);
  132
+  }
  133
+
  134
+  while (U) {
  135
+    curl_multi_perform(cm, &U);
  136
+
  137
+    if (U) {
  138
+      FD_ZERO(&R);
  139
+      FD_ZERO(&W);
  140
+      FD_ZERO(&E);
  141
+
  142
+      if (curl_multi_fdset(cm, &R, &W, &E, &M)) {
  143
+        fprintf(stderr, "E: curl_multi_fdset\n");
  144
+        return EXIT_FAILURE;
  145
+      }
  146
+
  147
+      if (curl_multi_timeout(cm, &L)) {
  148
+        fprintf(stderr, "E: curl_multi_timeout\n");
  149
+        return EXIT_FAILURE;
  150
+      }
  151
+      if (L == -1)
  152
+        L = 100;
  153
+
  154
+      if (M == -1) {
  155
+#ifdef WIN32
  156
+        Sleep(L);
  157
+#else
  158
+        sleep(L / 1000);
  159
+#endif
  160
+      } else {
  161
+        T.tv_sec = L/1000;
  162
+        T.tv_usec = (L%1000)*1000;
  163
+
  164
+        if (0 > select(M+1, &R, &W, &E, &T)) {
  165
+          fprintf(stderr, "E: select(%i,,,,%li): %i: %s\n",
  166
+              M+1, L, errno, strerror(errno));
  167
+          return EXIT_FAILURE;
  168
+        }
  169
+      }
  170
+    }
  171
+
  172
+    while ((msg = curl_multi_info_read(cm, &Q))) {
  173
+      if (msg->msg == CURLMSG_DONE) {
  174
+        char *url;
  175
+        CURL *e = msg->easy_handle;
  176
+        curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);
  177
+        fprintf(stderr, "R: %d - %s <%s>\n",
  178
+                msg->data.result, curl_easy_strerror(msg->data.result), url);
  179
+        curl_multi_remove_handle(cm, e);
  180
+        curl_easy_cleanup(e);
  181
+      }
  182
+      else {
  183
+        fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg);
  184
+      }
  185
+      if (C < CNT) {
  186
+        init(cm, C++);
  187
+        U++; /* just to prevent it from remaining at 0 if there are more
  188
+                URLs to get */
  189
+      }
  190
+    }
  191
+  }
  192
+
  193
+  curl_multi_cleanup(cm);
  194
+  curl_global_cleanup();
  195
+
  196
+  return EXIT_SUCCESS;
  197
+}
177  examples/anyauthput.c
... ...
@@ -0,0 +1,177 @@
  1
+/***************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  9
+ *
  10
+ * This software is licensed as described in the file COPYING, which
  11
+ * you should have received as part of this distribution. The terms
  12
+ * are also available at http://curl.haxx.se/docs/copyright.html.
  13
+ *
  14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15
+ * copies of the Software, and permit persons to whom the Software is
  16
+ * furnished to do so, under the terms of the COPYING file.
  17
+ *
  18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19
+ * KIND, either express or implied.
  20
+ *
  21
+ ***************************************************************************/
  22
+#include <stdio.h>
  23
+#include <fcntl.h>
  24
+#ifdef WIN32
  25
+#  include <io.h>
  26
+#else
  27
+#  ifdef __VMS
  28
+     typedef int intptr_t;
  29
+#  endif
  30
+#  include <stdint.h>
  31
+#  include <unistd.h>
  32
+#endif
  33
+#include <sys/types.h>
  34
+#include <sys/stat.h>
  35
+
  36
+#ifdef _MSC_VER
  37
+#  ifdef _WIN64
  38
+     typedef __int64 intptr_t;
  39
+#  else
  40
+     typedef int intptr_t;
  41
+#  endif
  42
+#endif
  43
+
  44
+#include <curl/curl.h>
  45
+
  46
+#if LIBCURL_VERSION_NUM < 0x070c03
  47
+#error "upgrade your libcurl to no less than 7.12.3"
  48
+#endif
  49
+
  50
+#ifndef TRUE
  51
+#define TRUE 1
  52
+#endif
  53
+
  54
+/*
  55
+ * This example shows a HTTP PUT operation with authentiction using "any"
  56
+ * type. It PUTs a file given as a command line argument to the URL also given
  57
+ * on the command line.
  58
+ *
  59
+ * Since libcurl 7.12.3, using "any" auth and POST/PUT requires a set ioctl
  60
+ * function.
  61
+ *
  62
+ * This example also uses its own read callback.
  63
+ */
  64
+
  65
+/* ioctl callback function */
  66
+static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp)
  67
+{
  68
+  intptr_t fd = (intptr_t)userp;
  69
+
  70
+  (void)handle; /* not used in here */
  71
+
  72
+  switch(cmd) {
  73
+  case CURLIOCMD_RESTARTREAD:
  74
+    /* mr libcurl kindly asks as to rewind the read data stream to start */
  75
+    if(-1 == lseek(fd, 0, SEEK_SET))
  76
+      /* couldn't rewind */
  77
+      return CURLIOE_FAILRESTART;
  78
+
  79
+    break;
  80
+
  81
+  default: /* ignore unknown commands */
  82
+    return CURLIOE_UNKNOWNCMD;
  83
+  }
  84
+  return CURLIOE_OK; /* success! */
  85
+}
  86
+
  87
+/* read callback function, fread() look alike */
  88
+static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
  89
+{
  90
+  size_t retcode;
  91
+  curl_off_t nread;
  92
+
  93
+  intptr_t fd = (intptr_t)stream;
  94
+
  95
+  retcode = read(fd, ptr, size * nmemb);
  96
+
  97
+  nread = (curl_off_t)retcode;
  98
+
  99
+  fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
  100
+          " bytes from file\n", nread);
  101
+
  102
+  return retcode;
  103
+}
  104
+
  105
+int main(int argc, char **argv)
  106
+{
  107
+  CURL *curl;
  108
+  CURLcode res;
  109
+  intptr_t hd ;
  110
+  struct stat file_info;
  111
+
  112
+  char *file;
  113
+  char *url;
  114
+
  115
+  if(argc < 3)
  116
+    return 1;
  117
+
  118
+  file= argv[1];
  119
+  url = argv[2];
  120
+
  121
+  /* get the file size of the local file */
  122
+  hd = open(file, O_RDONLY) ;
  123
+  fstat(hd, &file_info);
  124
+
  125
+  /* In windows, this will init the winsock stuff */
  126
+  curl_global_init(CURL_GLOBAL_ALL);
  127
+
  128
+  /* get a curl handle */
  129
+  curl = curl_easy_init();
  130
+  if(curl) {
  131
+    /* we want to use our own read function */
  132
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  133
+
  134
+    /* which file to upload */
  135
+    curl_easy_setopt(curl, CURLOPT_READDATA, (void*)hd);
  136
+
  137
+    /* set the ioctl function */
  138
+    curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, my_ioctl);
  139
+
  140
+    /* pass the file descriptor to the ioctl callback as well */
  141
+    curl_easy_setopt(curl, CURLOPT_IOCTLDATA, (void*)hd);
  142
+
  143
+    /* enable "uploading" (which means PUT when doing HTTP) */
  144
+    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L) ;
  145
+
  146
+    /* specify target URL, and note that this URL should also include a file
  147
+       name, not only a directory (as you can do with GTP uploads) */
  148
+    curl_easy_setopt(curl,CURLOPT_URL, url);
  149
+
  150
+    /* and give the size of the upload, this supports large file sizes
  151
+       on systems that have general support for it */
  152
+    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
  153
+                     (curl_off_t)file_info.st_size);
  154
+
  155
+    /* tell libcurl we can use "any" auth, which lets the lib pick one, but it
  156
+       also costs one extra round-trip and possibly sending of all the PUT
  157
+       data twice!!! */
  158
+    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
  159
+
  160
+    /* set user name and password for the authentication */
  161
+    curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
  162
+
  163
+    /* Now run off and do what you've been told! */
  164
+    res = curl_easy_perform(curl);
  165
+    /* Check for errors */
  166
+    if(res != CURLE_OK)
  167
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
  168
+              curl_easy_strerror(res));
  169
+
  170
+    /* always cleanup */
  171
+    curl_easy_cleanup(curl);
  172
+  }
  173
+  close(hd); /* close the local file */
  174
+
  175
+  curl_global_cleanup();
  176
+  return 0;
  177
+}
151  examples/cacertinmem.c
... ...
@@ -0,0 +1,151 @@
  1
+/***************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9
+ *
  10
+ * This software is licensed as described in the file COPYING, which
  11
+ * you should have received as part of this distribution. The terms
  12
+ * are also available at http://curl.haxx.se/docs/copyright.html.
  13
+ *
  14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15
+ * copies of the Software, and permit persons to whom the Software is
  16
+ * furnished to do so, under the terms of the COPYING file.
  17
+ *
  18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19
+ * KIND, either express or implied.
  20
+ *
  21
+ ***************************************************************************/
  22
+/* Example using a "in core" PEM certificate to retrieve a https page.
  23
+ * Written by Theo Borm
  24
+ */
  25
+
  26
+/* on a netBSD system with OPENSSL& LIBCURL installed from
  27
+ * pkgsrc (using default paths) this program can be compiled using:
  28
+ * gcc -I/usr/pkg/include -L/usr/pkg/lib -lcurl -Wl,-R/usr/pkg/lib -lssl
  29
+ * -lcrypto -lz -o curlcacerttest curlcacerttest.c
  30
+ * on other operating systems you may want to change paths to headers
  31
+ * and libraries
  32
+*/
  33
+#include <openssl/ssl.h>
  34
+#include <curl/curl.h>
  35
+#include <stdio.h>
  36
+
  37
+size_t writefunction( void *ptr, size_t size, size_t nmemb, void *stream)
  38
+{
  39
+  fwrite(ptr,size,nmemb,stream);
  40
+  return(nmemb*size);
  41
+}
  42
+
  43
+static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm)
  44
+{
  45
+  X509_STORE * store;
  46
+  X509 * cert=NULL;
  47
+  BIO * bio;
  48
+  char * mypem = /* www.cacert.org */
  49
+    "-----BEGIN CERTIFICATE-----\n"\
  50
+    "MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\n"\
  51
+    "IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB\n"\
  52
+    "IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA\n"\
  53
+    "Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO\n"\
  54
+    "BgNVBAoTB1Jvb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEi\n"\
  55
+    "MCAGA1UEAxMZQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJ\n"\
  56
+    "ARYSc3VwcG9ydEBjYWNlcnQub3JnMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC\n"\
  57
+    "CgKCAgEAziLA4kZ97DYoB1CW8qAzQIxL8TtmPzHlawI229Z89vGIj053NgVBlfkJ\n"\
  58
+    "8BLPRoZzYLdufujAWGSuzbCtRRcMY/pnCujW0r8+55jE8Ez64AO7NV1sId6eINm6\n"\
  59
+    "zWYyN3L69wj1x81YyY7nDl7qPv4coRQKFWyGhFtkZip6qUtTefWIonvuLwphK42y\n"\
  60
+    "fk1WpRPs6tqSnqxEQR5YYGUFZvjARL3LlPdCfgv3ZWiYUQXw8wWRBB0bF4LsyFe7\n"\
  61
+    "w2t6iPGwcswlWyCR7BYCEo8y6RcYSNDHBS4CMEK4JZwFaz+qOqfrU0j36NK2B5jc\n"\
  62
+    "G8Y0f3/JHIJ6BVgrCFvzOKKrF11myZjXnhCLotLddJr3cQxyYN/Nb5gznZY0dj4k\n"\
  63
+    "epKwDpUeb+agRThHqtdB7Uq3EvbXG4OKDy7YCbZZ16oE/9KTfWgu3YtLq1i6L43q\n"\
  64
+    "laegw1SJpfvbi1EinbLDvhG+LJGGi5Z4rSDTii8aP8bQUWWHIbEZAWV/RRyH9XzQ\n"\
  65
+    "QUxPKZgh/TMfdQwEUfoZd9vUFBzugcMd9Zi3aQaRIt0AUMyBMawSB3s42mhb5ivU\n"\
  66
+    "fslfrejrckzzAeVLIL+aplfKkQABi6F1ITe1Yw1nPkZPcCBnzsXWWdsC4PDSy826\n"\
  67
+    "YreQQejdIOQpvGQpQsgi3Hia/0PsmBsJUUtaWsJx8cTLc6nloQsCAwEAAaOCAc4w\n"\
  68
+    "ggHKMB0GA1UdDgQWBBQWtTIb1Mfz4OaO873SsDrusjkY0TCBowYDVR0jBIGbMIGY\n"\
  69
+    "gBQWtTIb1Mfz4OaO873SsDrusjkY0aF9pHsweTEQMA4GA1UEChMHUm9vdCBDQTEe\n"\
  70
+    "MBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0\n"\
  71
+    "IFNpZ25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2Vy\n"\
  72
+    "dC5vcmeCAQAwDwYDVR0TAQH/BAUwAwEB/zAyBgNVHR8EKzApMCegJaAjhiFodHRw\n"\
  73
+    "czovL3d3dy5jYWNlcnQub3JnL3Jldm9rZS5jcmwwMAYJYIZIAYb4QgEEBCMWIWh0\n"\
  74
+    "dHBzOi8vd3d3LmNhY2VydC5vcmcvcmV2b2tlLmNybDA0BglghkgBhvhCAQgEJxYl\n"\
  75
+    "aHR0cDovL3d3dy5jYWNlcnQub3JnL2luZGV4LnBocD9pZD0xMDBWBglghkgBhvhC\n"\
  76
+    "AQ0ESRZHVG8gZ2V0IHlvdXIgb3duIGNlcnRpZmljYXRlIGZvciBGUkVFIGhlYWQg\n"\
  77
+    "b3ZlciB0byBodHRwOi8vd3d3LmNhY2VydC5vcmcwDQYJKoZIhvcNAQEEBQADggIB\n"\
  78
+    "ACjH7pyCArpcgBLKNQodgW+JapnM8mgPf6fhjViVPr3yBsOQWqy1YPaZQwGjiHCc\n"\
  79
+    "nWKdpIevZ1gNMDY75q1I08t0AoZxPuIrA2jxNGJARjtT6ij0rPtmlVOKTV39O9lg\n"\
  80
+    "18p5aTuxZZKmxoGCXJzN600BiqXfEVWqFcofN8CCmHBh22p8lqOOLlQ+TyGpkO/c\n"\
  81
+    "gr/c6EWtTZBzCDyUZbAEmXZ/4rzCahWqlwQ3JNgelE5tDlG+1sSPypZt90Pf6DBl\n"\
  82
+    "Jzt7u0NDY8RD97LsaMzhGY4i+5jhe1o+ATc7iwiwovOVThrLm82asduycPAtStvY\n"\
  83
+    "sONvRUgzEv/+PDIqVPfE94rwiCPCR/5kenHA0R6mY7AHfqQv0wGP3J8rtsYIqQ+T\n"\
  84
+    "SCX8Ev2fQtzzxD72V7DX3WnRBnc0CkvSyqD/HMaMyRa+xMwyN2hzXwj7UfdJUzYF\n"\
  85
+    "CpUCTPJ5GhD22Dp1nPMd8aINcGeGG7MW9S/lpOt5hvk9C8JzC6WZrG/8Z7jlLwum\n"\
  86
+    "GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk\n"\
  87
+    "zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW\n"\
  88
+    "omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD\n"\
  89
+    "-----END CERTIFICATE-----\n";
  90
+  /* get a BIO */
  91
+  bio=BIO_new_mem_buf(mypem, -1);
  92
+  /* use it to read the PEM formatted certificate from memory into an X509
  93
+   * structure that SSL can use
  94
+   */
  95
+  PEM_read_bio_X509(bio, &cert, 0, NULL);
  96
+  if (cert == NULL)
  97
+    printf("PEM_read_bio_X509 failed...\n");
  98
+
  99
+  /* get a pointer to the X509 certificate store (which may be empty!) */
  100
+  store=SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
  101
+
  102
+  /* add our certificate to this store */
  103
+  if (X509_STORE_add_cert(store, cert)==0)
  104
+    printf("error adding certificate\n");
  105
+
  106
+  /* all set to go */
  107
+  return CURLE_OK ;
  108
+}
  109
+
  110
+int main(void)
  111
+{
  112
+  CURL * ch;
  113
+  CURLcode rv;
  114
+
  115
+  rv=curl_global_init(CURL_GLOBAL_ALL);
  116
+  ch=curl_easy_init();
  117
+  rv=curl_easy_setopt(ch,CURLOPT_VERBOSE, 0L);
  118
+  rv=curl_easy_setopt(ch,CURLOPT_HEADER, 0L);
  119
+  rv=curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1L);
  120
+  rv=curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1L);
  121
+  rv=curl_easy_setopt(ch,CURLOPT_WRITEFUNCTION, *writefunction);
  122
+  rv=curl_easy_setopt(ch,CURLOPT_WRITEDATA, stdout);
  123
+  rv=curl_easy_setopt(ch,CURLOPT_HEADERFUNCTION, *writefunction);
  124
+  rv=curl_easy_setopt(ch,CURLOPT_WRITEHEADER, stderr);
  125
+  rv=curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM");
  126
+  rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1L);
  127
+  rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/");
  128
+
  129
+  /* first try: retrieve page without cacerts' certificate -> will fail
  130
+   */
  131
+  rv=curl_easy_perform(ch);
  132
+  if (rv==CURLE_OK)
  133
+    printf("*** transfer succeeded ***\n");
  134
+  else
  135
+    printf("*** transfer failed ***\n");
  136
+
  137
+  /* second try: retrieve page using cacerts' certificate -> will succeed
  138
+   * load the certificate by installing a function doing the nescessary
  139
+   * "modifications" to the SSL CONTEXT just before link init
  140
+   */
  141
+  rv=curl_easy_setopt(ch,CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
  142
+  rv=curl_easy_perform(ch);
  143
+  if (rv==CURLE_OK)
  144
+    printf("*** transfer succeeded ***\n");
  145
+  else
  146
+    printf("*** transfer failed ***\n");
  147
+
  148
+  curl_easy_cleanup(ch);
  149
+  curl_global_cleanup();
  150
+  return rv;
  151
+}
81  examples/certinfo.c
... ...
@@ -0,0 +1,81 @@
  1
+/***************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9
+ *
  10
+ * This software is licensed as described in the file COPYING, which
  11
+ * you should have received as part of this distribution. The terms
  12
+ * are also available at http://curl.haxx.se/docs/copyright.html.
  13
+ *
  14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15
+ * copies of the Software, and permit persons to whom the Software is
  16
+ * furnished to do so, under the terms of the COPYING file.
  17
+ *
  18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19
+ * KIND, either express or implied.
  20
+ *
  21
+ ***************************************************************************/
  22
+#include <stdio.h>
  23
+
  24
+#include <curl/curl.h>
  25
+
  26
+static size_t wrfu(void *ptr,  size_t  size,  size_t  nmemb,  void *stream)
  27
+{
  28
+  (void)stream;
  29
+  (void)ptr;
  30
+  return size * nmemb;
  31
+}
  32
+
  33
+int main(void)
  34
+{
  35
+  CURL *curl;
  36
+  CURLcode res;
  37
+
  38
+  curl_global_init(CURL_GLOBAL_DEFAULT);
  39
+
  40
+  curl = curl_easy_init();
  41
+  if(curl) {
  42
+    curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
  43
+
  44
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
  45
+
  46
+    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
  47
+    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
  48
+
  49
+    curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
  50
+    curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
  51
+
  52
+    res = curl_easy_perform(curl);
  53
+
  54
+    if(!res) {
  55
+      struct curl_certinfo *ci = NULL;
  56
+
  57
+      res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
  58
+
  59
+      if(!res && ci) {
  60
+        int i;
  61
+        printf("%d certs!\n", ci->num_of_certs);
  62
+
  63
+        for(i=0; i<ci->num_of_certs; i++) {
  64
+          struct curl_slist *slist;
  65
+
  66
+          for(slist = ci->certinfo[i]; slist; slist = slist->next)
  67
+            printf("%s\n", slist->data);
  68
+
  69
+        }
  70
+      }
  71
+
  72
+    }
  73
+
  74
+
  75
+    curl_easy_cleanup(curl);
  76
+  }
  77
+
  78
+  curl_global_cleanup();
  79
+
  80
+  return 0;
  81
+}
176  examples/chkspeed.c
... ...
@@ -0,0 +1,176 @@
  1
+/***************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9
+ *
  10
+ * This software is licensed as described in the file COPYING, which
  11
+ * you should have received as part of this distribution. The terms
  12
+ * are also available at http://curl.haxx.se/docs/copyright.html.
  13
+ *
  14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15
+ * copies of the Software, and permit persons to whom the Software is
  16
+ * furnished to do so, under the terms of the COPYING file.
  17
+ *
  18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19
+ * KIND, either express or implied.
  20
+ *
  21
+ ***************************************************************************/
  22
+/* Example source code to show how the callback function can be used to
  23
+ * download data into a chunk of memory instead of storing it in a file.
  24
+ * After successful download we use curl_easy_getinfo() calls to get the
  25
+ * amount of downloaded bytes, the time used for the whole download, and
  26
+ * the average download speed.
  27
+ * On Linux you can create the download test files with:
  28
+ * dd if=/dev/urandom of=file_1M.bin bs=1M count=1
  29
+ *
  30
+ */
  31
+
  32
+#include <stdio.h>
  33
+#include <stdlib.h>
  34
+#include <string.h>
  35
+#include <time.h>
  36
+
  37
+#include <curl/curl.h>
  38
+
  39
+#define URL_BASE "http://speedtest.your.domain/"
  40
+#define URL_1M   URL_BASE "file_1M.bin"
  41
+#define URL_2M   URL_BASE "file_2M.bin"
  42
+#define URL_5M   URL_BASE "file_5M.bin"
  43
+#define URL_10M  URL_BASE "file_10M.bin"
  44
+#define URL_20M  URL_BASE "file_20M.bin"
  45
+#define URL_50M  URL_BASE "file_50M.bin"
  46
+#define URL_100M URL_BASE "file_100M.bin"
  47
+
  48
+#define CHKSPEED_VERSION "1.0"
  49
+
  50
+static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data)
  51
+{
  52
+  /* we are not interested in the downloaded bytes itself,
  53
+     so we only return the size we would have saved ... */
  54
+  (void)ptr;  /* unused */
  55
+  (void)data; /* unused */
  56
+  return (size_t)(size * nmemb);
  57
+}
  58
+
  59
+int main(int argc, char *argv[])
  60
+{
  61
+  CURL *curl_handle;
  62
+  CURLcode res;
  63
+  int prtsep = 0, prttime = 0;
  64
+  const char *url = URL_1M;
  65
+  char *appname = argv[0];
  66
+
  67
+  if (argc > 1) {
  68
+    /* parse input parameters */
  69
+    for (argc--, argv++; *argv; argc--, argv++) {
  70
+      if (strncasecmp(*argv, "-", 1) == 0) {
  71
+        if (strncasecmp(*argv, "-H", 2) == 0) {
  72
+          fprintf(stderr,
  73
+                  "\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n",
  74
+                  appname);
  75
+          exit(1);
  76
+        } else if (strncasecmp(*argv, "-V", 2) == 0) {
  77
+          fprintf(stderr, "\r%s %s - %s\n",
  78
+                  appname, CHKSPEED_VERSION, curl_version());
  79
+          exit(1);
  80
+        } else if (strncasecmp(*argv, "-X", 2) == 0) {
  81
+          prtsep = 1;
  82
+        } else if (strncasecmp(*argv, "-T", 2) == 0) {
  83
+          prttime = 1;
  84
+        } else if (strncasecmp(*argv, "-M=", 3) == 0) {
  85
+          long m = strtol((*argv)+3, NULL, 10);
  86
+          switch(m) {
  87
+            case   1: url = URL_1M;
  88
+                      break;
  89
+            case   2: url = URL_2M;
  90
+                      break;
  91
+            case   5: url = URL_5M;
  92
+                      break;
  93
+            case  10: url = URL_10M;
  94
+                      break;
  95
+            case  20: url = URL_20M;
  96
+                      break;
  97
+            case  50: url = URL_50M;
  98
+                      break;
  99
+            case 100: url = URL_100M;
  100
+                      break;
  101
+            default:  fprintf(stderr, "\r%s: invalid parameter %s\n",
  102
+                              appname, *argv + 3);
  103
+                      exit(1);
  104
+          }
  105
+        } else {
  106
+          fprintf(stderr, "\r%s: invalid or unknown option %s\n",
  107
+                  appname, *argv);
  108
+          exit(1);
  109
+        }
  110
+      } else {
  111
+        url = *argv;
  112
+      }
  113
+    }
  114
+  }
  115
+
  116
+  /* print separator line */
  117
+  if (prtsep) {
  118
+    printf("-------------------------------------------------\n");
  119
+  }
  120
+  /* print localtime */
  121
+  if (prttime) {
  122
+    time_t t = time(NULL);
  123
+    printf("Localtime: %s", ctime(&t));
  124
+  }
  125
+
  126
+  /* init libcurl */
  127
+  curl_global_init(CURL_GLOBAL_ALL);
  128
+
  129
+  /* init the curl session */
  130
+  curl_handle = curl_easy_init();
  131
+
  132
+  /* specify URL to get */
  133
+  curl_easy_setopt(curl_handle, CURLOPT_URL, url);
  134
+
  135
+  /* send all data to this function  */
  136
+  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteCallback);
  137
+
  138
+  /* some servers don't like requests that are made without a user-agent
  139
+     field, so we provide one */
  140
+  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT,
  141
+                   "libcurl-speedchecker/" CHKSPEED_VERSION);
  142
+
  143
+  /* get it! */
  144
+  res = curl_easy_perform(curl_handle);
  145
+
  146
+  if(CURLE_OK == res) {
  147
+    double val;
  148
+
  149
+    /* check for bytes downloaded */
  150
+    res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &val);
  151
+    if((CURLE_OK == res) && (val>0))
  152
+      printf("Data downloaded: %0.0f bytes.\n", val);
  153
+
  154
+    /* check for total download time */
  155
+    res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &val);
  156
+    if((CURLE_OK == res) && (val>0))
  157
+      printf("Total download time: %0.3f sec.\n", val);
  158
+
  159
+    /* check for average download speed */
  160
+    res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD, &val);
  161
+    if((CURLE_OK == res) && (val>0))
  162
+      printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024);
  163
+
  164
+  } else {
  165
+    fprintf(stderr, "Error while fetching '%s' : %s\n",
  166
+            url, curl_easy_strerror(res));
  167
+  }
  168
+
  169
+  /* cleanup curl stuff */
  170
+  curl_easy_cleanup(curl_handle);
  171
+
  172
+  /* we're done with libcurl, so clean it up */
  173
+  curl_global_cleanup();
  174
+
  175
+  return 0;
  176
+}
124  examples/cookie_interface.c
... ...
@@ -0,0 +1,124 @@
106  examples/curlgtk.c
... ...
@@ -0,0 +1,106 @@
  1
+/*****************************************************************************
  2
+ *                                  _   _ ____  _
  3
+ *  Project                     ___| | | |  _ \| |
  4
+ *                             / __| | | | |_) | |
  5
+ *                            | (__| |_| |  _ <| |___
  6
+ *                             \___|\___/|_| \_\_____|
  7
+ *
  8
+ */
  9
+/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */
  10
+/* an attempt to use the curl library in concert with a gtk-threaded application */
  11
+
  12
+#include <stdio.h>
  13
+#include <gtk/gtk.h>
  14
+
  15
+#include <curl/curl.h>
  16
+
  17
+GtkWidget *Bar;
  18
+
  19
+size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
  20
+{
  21
+  return fwrite(ptr, size, nmemb, stream);
  22
+}
  23
+
  24
+size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
  25
+{
  26
+  return fread(ptr, size, nmemb, stream);
  27
+}
  28
+
  29
+int my_progress_func(GtkWidget *bar,
  30
+                     double t, /* dltotal */
  31
+                     double d, /* dlnow */
  32
+                     double ultotal,
  33
+                     double ulnow)
  34
+{
  35
+/*  printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
  36
+  gdk_threads_enter();
  37
+  gtk_progress_set_value(GTK_PROGRESS(bar), d*100.0/t);
  38
+  gdk_threads_leave();
  39
+  return 0;
  40
+}
  41
+
  42
+void *my_thread(void *ptr)
  43
+{
  44
+  CURL *curl;
  45
+  CURLcode res;
  46
+  FILE *outfile;
  47
+  gchar *url = ptr;
  48
+
  49
+  curl = curl_easy_init();
  50
+  if(curl)
  51
+  {
  52
+    outfile = fopen("test.curl", "w");
  53
+
  54
+    curl_easy_setopt(curl, CURLOPT_URL, url);
  55
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
  56
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
  57
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
  58
+    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
  59
+    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
  60
+    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);
  61
+
  62
+    res = curl_easy_perform(curl);
  63
+
  64
+    fclose(outfile);
  65
+    /* always cleanup */
  66
+    curl_easy_cleanup(curl);
  67
+  }
  68
+
  69
+  return NULL;
  70
+}
  71
+
  72
+int main(int argc, char **argv)
  73
+{
  74
+  GtkWidget *Window, *Frame, *Frame2;
  75
+  GtkAdjustment *adj;
  76
+
  77
+  /* Must initialize libcurl before any threads are started */
  78
+  curl_global_init(CURL_GLOBAL_ALL);
  79
+
  80
+  /* Init thread */
  81
+  g_thread_init(NULL);
  82
+
  83
+  gtk_init(&argc, &argv);
  84
+  Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  85
+  Frame = gtk_frame_new(NULL);
  86
+  gtk_frame_set_shadow_type(GTK_FRAME(Frame), GTK_SHADOW_OUT);
  87
+  gtk_container_add(GTK_CONTAINER(Window), Frame);
  88
+  Frame2 = gtk_frame_new(NULL);
  89
+  gtk_frame_set_shadow_type(GTK_FRAME(Frame2), GTK_SHADOW_IN);
  90
+  gtk_container_add(GTK_CONTAINER(Frame), Frame2);
  91
+  gtk_container_set_border_width(GTK_CONTAINER(Frame2), 5);
  92
+  adj = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
  93
+  Bar = gtk_progress_bar_new_with_adjustment(adj);
  94
+  gtk_container_add(GTK_CONTAINER(Frame2), Bar);
  95
+  gtk_widget_show_all(Window);
  96
+
  97
+  if (!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0)
  98
+    g_warning("can't create the thread");
  99
+
  100
+
  101
+  gdk_threads_enter();
  102
+  gtk_main();
  103
+  gdk_threads_leave();
  104
+  return 0;
  105
+}
  106
+
513  examples/curlx.c
... ...
@@ -0,0 +1,513 @@
  1
+/*
  2
+  curlx.c  Authors: Peter Sylvester, Jean-Paul Merlin
  3
+
  4
+  This is a little program to demonstrate the usage of
  5
+
  6
+  - an ssl initialisation callback setting a user key and trustbases
  7
+  coming from a pkcs12 file
  8
+  - using an ssl application callback to find a URI in the
  9
+  certificate presented during ssl session establishment.
  10
+
  11
+*/
  12
+
  13
+
  14
+/*
  15
+ * Copyright (c) 2003 The OpenEvidence Project.  All rights reserved.
  16
+ *
  17
+ * Redistribution and use in source and binary forms, with or without
  18
+ * modification, are permitted provided that the following conditions
  19
+ * are met:
  20
+ *
  21
+ * 1. Redistributions of source code must retain the above copyright
  22
+ *    notice, this list of conditions, the following disclaimer,
  23
+ *    and the original OpenSSL and SSLeay Licences below.
  24
+ *
  25
+ * 2. Redistributions in binary form must reproduce the above copyright
  26
+ *    notice, this list of conditions, the following disclaimer
  27
+ *    and the original OpenSSL and SSLeay Licences below in
  28
+ *    the documentation and/or other materials provided with the
  29
+ *    distribution.
  30
+ *
  31
+ * 3. All advertising materials mentioning features or use of this
  32
+ *    software must display the following acknowledgments:
  33
+ *    "This product includes software developed by the Openevidence Project
  34
+ *    for use in the OpenEvidence Toolkit. (http://www.openevidence.org/)"
  35
+ *    This product includes software developed by the OpenSSL Project
  36
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  37
+ *    This product includes cryptographic software written by Eric Young
  38
+ *    (eay@cryptsoft.com).  This product includes software written by Tim
  39
+ *    Hudson (tjh@cryptsoft.com)."
  40
+ *
  41
+ * 4. The names "OpenEvidence Toolkit" and "OpenEvidence Project" must not be
  42
+ *    used to endorse or promote products derived from this software without
  43
+ *    prior written permission. For written permission, please contact
  44
+ *    openevidence-core@openevidence.org.
  45
+ *
  46
+ * 5. Products derived from this software may not be called "OpenEvidence"
  47
+ *    nor may "OpenEvidence" appear in their names without prior written
  48
+ *    permission of the OpenEvidence Project.
  49
+ *
  50
+ * 6. Redistributions of any form whatsoever must retain the following
  51
+ *    acknowledgments:
  52
+ *    "This product includes software developed by the OpenEvidence Project
  53
+ *    for use in the OpenEvidence Toolkit (http://www.openevidence.org/)
  54
+ *    This product includes software developed by the OpenSSL Project
  55
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  56
+ *    This product includes cryptographic software written by Eric Young
  57
+ *    (eay@cryptsoft.com).  This product includes software written by Tim
  58
+ *    Hudson (tjh@cryptsoft.com)."
  59
+ *
  60
+ * THIS SOFTWARE IS PROVIDED BY THE OpenEvidence PROJECT ``AS IS'' AND ANY
  61
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  63
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenEvidence PROJECT OR
  64
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  65
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  66
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  67
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  68
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  69
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  70
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  71
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  72
+ * ====================================================================
  73
+ *
  74
+ * This product includes software developed by the OpenSSL Project
  75
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)
  76
+ * This product includes cryptographic software written by Eric Young
  77
+ * (eay@cryptsoft.com).  This product includes software written by Tim
  78
+ * Hudson (tjh@cryptsoft.com).
  79
+ *
  80
+ */
  81
+
  82
+#include <stdio.h>
  83
+#include <stdlib.h>
  84
+#include <string.h>
  85
+#include <curl/curl.h>
  86
+#include <openssl/x509v3.h>
  87
+#include <openssl/x509_vfy.h>
  88
+#include <openssl/crypto.h>
  89
+#include <openssl/lhash.h>
  90
+#include <openssl/objects.h>
  91
+#include <openssl/err.h>
  92
+#include <openssl/evp.h>
  93
+#include <openssl/x509.h>
  94
+#include <openssl/pkcs12.h>
  95
+#include <openssl/bio.h>
  96
+#include <openssl/ssl.h>
  97
+
  98
+static const char *curlx_usage[]={
  99
+  "usage: curlx args\n",
  100
+  " -p12 arg         - tia  file ",
  101
+  " -envpass arg     - environement variable which content the tia private key password",
  102
+  " -out arg         - output file (response)- default stdout",
  103
+  " -in arg          - input file (request)- default stdin",
  104
+  " -connect arg     - URL of the server for the connection ex: www.openevidence.org",
  105
+  " -mimetype arg    - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query",
  106
+  " -acceptmime arg  - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none",
  107
+  " -accesstype arg  - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping",
  108
+  NULL
  109
+};
  110
+
  111
+/*
  112
+
  113
+./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS
  114
+-mimetype application/dvcs -acceptmime application/dvcs -out response
  115
+
  116
+*/
  117
+
  118
+/*
  119
+ * We use this ZERO_NULL to avoid picky compiler warnings,
  120
+ * when assigning a NULL pointer to a function pointer var.
  121
+ */
  122
+
  123
+#define ZERO_NULL 0
  124
+
  125
+/* This is a context that we pass to all callbacks */
  126
+
  127
+typedef struct sslctxparm_st {
  128
+  unsigned char * p12file ;
  129
+  const char * pst ;
  130
+  PKCS12 * p12 ;
  131
+  EVP_PKEY * pkey ;
  132
+  X509 * usercert ;
  133
+  STACK_OF(X509) * ca ;
  134
+  CURL * curl;