aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/simplessl.c
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/simplessl.c')
-rw-r--r--docs/examples/simplessl.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c
index 4f0d26ab5..c543d2fe1 100644
--- a/docs/examples/simplessl.c
+++ b/docs/examples/simplessl.c
@@ -55,6 +55,7 @@ int main(void)
static const char *pCertFile = "testcert.pem";
static const char *pCACertFile="cacert.pem";
+ static const char *pHeaderFile = "dumpit"
const char *pKeyName;
const char *pKeyType;
@@ -71,7 +72,7 @@ int main(void)
pEngine = NULL;
#endif
- headerfile = fopen("dumpit", "w");
+ headerfile = fopen(pHeaderFile, "wb");
curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -81,47 +82,46 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site");
curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile);
- for(i = 0; i < 1; i++) /* single-iteration loop, just to break out from */
- {
- if (pEngine) /* use crypto engine */
- {
- if (curl_easy_setopt(curl, CURLOPT_SSLENGINE,pEngine) != CURLE_OK)
- { /* load the crypto engine */
- fprintf(stderr,"can't set crypto engine\n");
+ do { /* dummy loop, just to break out from */
+ if(pEngine) {
+ /* use crypto engine */
+ if(curl_easy_setopt(curl, CURLOPT_SSLENGINE, pEngine) != CURLE_OK) {
+ /* load the crypto engine */
+ fprintf(stderr, "can't set crypto engine\n");
break;
}
- if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1L) != CURLE_OK)
- { /* set the crypto engine as default */
+ if(curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK) {
+ /* set the crypto engine as default */
/* only needed for the first time you load
a engine in a curl object... */
- fprintf(stderr,"can't set crypto engine as default\n");
+ fprintf(stderr, "can't set crypto engine as default\n");
break;
}
}
/* cert is stored PEM coded in file... */
/* since PEM is default, we needn't set it for PEM */
- curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
+ curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
/* set the cert for client authentication */
- curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile);
+ curl_easy_setopt(curl, CURLOPT_SSLCERT, pCertFile);
/* sorry, for engine we must set the passphrase
(if the key has one...) */
- if (pPassphrase)
- curl_easy_setopt(curl,CURLOPT_KEYPASSWD,pPassphrase);
+ if(pPassphrase)
+ curl_easy_setopt(curl, CURLOPT_KEYPASSWD, pPassphrase);
/* if we use a key stored in a crypto engine,
we must set the key type to "ENG" */
- curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType);
+ curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, pKeyType);
/* set the private key (file or ID in engine) */
- curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);
+ curl_easy_setopt(curl, CURLOPT_SSLKEY, pKeyName);
/* set the file with the certs vaildating the server */
- curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
+ curl_easy_setopt(curl, CURLOPT_CAINFO, pCACertFile);
/* disconnect if we can't validate server's cert */
- curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
@@ -134,7 +134,7 @@ int main(void)
}
/* always cleanup */
curl_easy_cleanup(curl);
- }
+ } while(0);
curl_global_cleanup();