summaryrefslogtreecommitdiff
path: root/docs/examples/simplessl.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-02-11 09:42:38 +0100
committerDaniel Stenberg <daniel@haxx.se>2016-02-11 09:44:45 +0100
commit3a6563d668406df1703edb4202afc038fcf9d30e (patch)
tree0fbb9438d99c13049f72b10c966583e582e4e238 /docs/examples/simplessl.c
parent936d8f07dfbf2ac22ffd216f5363152bcecc2651 (diff)
downloadcurl-3a6563d668406df1703edb4202afc038fcf9d30e.tar.gz
examples: adhere to curl code style
All plain C examples now (mostly) adhere to the curl code style. While they are only examples, they had diverted so much and contained all sorts of different mixed code styles by now. Having them use a unified style helps users and readability. Also, as they get copy-and-pasted widely by users, making sure they're clean and nice is a good idea. 573 checksrc warnings were addressed.
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();