sslbackend.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2017, 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 https://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. /* <DESC>
  23. * Shows HTTPS usage with client certs and optional ssl engine use.
  24. * </DESC>
  25. */
  26. #include <assert.h>
  27. #include <ctype.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <curl/curl.h>
  32. /*
  33. * An SSL-enabled libcurl is required for this sample to work (at least one
  34. * SSL backend has to be configured).
  35. *
  36. * **** This example only works with libcurl 7.56.0 and later! ****
  37. */
  38. int main(int argc, char **argv)
  39. {
  40. const char *name = argc > 1 ? argv[1] : "openssl";
  41. CURLsslset result;
  42. if(!strcmp("list", name)) {
  43. const curl_ssl_backend **list;
  44. int i;
  45. result = curl_global_sslset(-1, NULL, &list);
  46. assert(result == CURLSSLSET_UNKNOWN_BACKEND);
  47. for(i = 0; list[i]; i++)
  48. printf("SSL backend #%d: '%s' (ID: %d)\n",
  49. i, list[i]->name, list[i]->id);
  50. return 0;
  51. }
  52. else if(isdigit(*name)) {
  53. int id = atoi(name);
  54. result = curl_global_sslset((curl_sslbackend)id, NULL, NULL);
  55. }
  56. else
  57. result = curl_global_sslset(-1, name, NULL);
  58. if(result == CURLSSLSET_UNKNOWN_BACKEND) {
  59. fprintf(stderr, "Unknown SSL backend id: %s\n", name);
  60. return 1;
  61. }
  62. assert(result == CURLSSLSET_OK);
  63. printf("Version with SSL backend '%s':\n\n\t%s\n", name, curl_version());
  64. return 0;
  65. }