Changeset 6876
- Timestamp:
- 21/05/10 11:27:25 (11 years ago)
- Location:
- TI12-security/trunk/NDGSecurity/C/openDapPatch
- Files:
-
- 6 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/C/openDapPatch
-
Property
svn:ignore
set to
ncopen
proxy.pem
user.pem
ca
cookie.txt
-
Property
svn:ignore
set to
-
TI12-security/trunk/NDGSecurity/C/openDapPatch/README
r6834 r6876 1 1 This version of http for the netcdf/oc library allows settings 2 2 of security certificates using environment variables 3 4 NetCDF version 4.1.1 used. configure with curl to enable OPeNDAP functionality: 5 6 $ ./configure --with-curl-config=/usr/bin/curl-config 7 8 The example will work with proxy or standard X.509 certificates. -
TI12-security/trunk/NDGSecurity/C/openDapPatch/http.c
r6834 r6876 12 12 static size_t WriteFileCallback(void*, size_t, size_t, void*); 13 13 static size_t WriteMemoryCallback(void*, size_t, size_t, void*); 14 static int ocsetcurlproperties(CURL* curl, const char*); 14 15 15 16 struct Fetchdata { … … 30 31 31 32 int 32 ocfetchurl_file(CURL* curl, char* url, FILE* stream, unsigned long* sizep) 33 ocfetchurl_file(CURL* curl, char* url, FILE* stream, 34 unsigned long* sizep, long* filetime) 33 35 { 34 36 int stat = OC_NOERR; … … 37 39 38 40 39 /* These four conditionals look for value in four globals set when the 40 * .dodsrc file was read. 41 */ 42 if (dods_verify) { 43 if (set_verify(curl) != OC_NOERR) 44 goto fail; 45 } 46 if (dods_compress) { 47 if (set_compression(curl) != OC_NOERR) 48 goto fail; 49 } 50 if (pstructProxy) { 51 if (set_proxy(curl, pstructProxy) != OC_NOERR) 52 goto fail; 53 } 54 if (cook) { 55 if (set_cookies(curl, cook) != OC_NOERR) 56 goto fail; 57 } 58 59 if (credentials_in_url(url)) { 60 char *result_url = NULL; 61 if (extract_credentials(url, &userName, &password, &result_url) != OC_NOERR) 62 goto fail; 63 url = result_url; 64 } 65 66 if (userName && password) { 67 if (set_user_password(curl, userName, password) != OC_NOERR) 68 goto fail; 69 } 41 if((stat = ocsetcurlproperties(curl,url)) != OC_NOERR) goto fail; 70 42 71 43 /* Set the URL */ … … 83 55 if (cstat != CURLE_OK) 84 56 goto fail; 57 58 /* One last thing; always try to get the last modified time */ 59 cstat = curl_easy_setopt(curl, CURLOPT_FILETIME, (long)1); 85 60 86 61 fetchdata.stream = stream; … … 95 70 if (sizep != NULL) 96 71 *sizep = fetchdata.size; 72 /* Get the last modified time */ 73 if(filetime != NULL) 74 cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime); 75 if(cstat != CURLE_OK) goto fail; 97 76 } 98 77 return THROW(stat); 99 78 100 79 fail: oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat)); 101 80 return THROW(OC_ECURL); 102 81 } 103 82 104 83 int 105 ocfetchurl(CURL* curl, char* url, OCbytes* buf )84 ocfetchurl(CURL* curl, char* url, OCbytes* buf, long* filetime) 106 85 { 107 86 int stat = OC_NOERR; … … 109 88 size_t len; 110 89 111 /* These conditionals look for value in four globals set when the 112 * .dodsrc file was read. 113 */ 114 if (dods_verify) { 115 if (set_verify(curl) != OC_NOERR) 116 goto fail; 117 } 118 if (dods_compress) { 119 if (set_compression(curl) != OC_NOERR) 120 goto fail; 121 } 122 if (pstructProxy) { 123 if (set_proxy(curl, pstructProxy) != OC_NOERR) 124 goto fail; 125 } 126 if (cook) { 127 if (set_cookies(curl, cook) != OC_NOERR) 128 goto fail; 129 } 130 131 if (credentials_in_url(url)) { 132 char *result_url = NULL; 133 if (extract_credentials(url, &userName, &password, &result_url) != OC_NOERR) 134 goto fail; 135 url = result_url; 136 } 137 138 if (userName && password) { 139 if (set_user_password(curl, userName, password) != OC_NOERR) 140 goto fail; 141 } 90 if((stat = ocsetcurlproperties(curl,url)) != OC_NOERR) goto fail; 142 91 143 92 /* Set the URL */ … … 156 105 goto fail; 157 106 107 /* One last thing; always try to get the last modified time */ 108 cstat = curl_easy_setopt(curl, CURLOPT_FILETIME, (long)1); 109 158 110 cstat = curl_easy_perform(curl); 159 if (cstat != CURLE_OK) { 160 goto fail; 161 } 111 if(cstat == CURLE_PARTIAL_FILE) { 112 /* Log it but otherwise ignore */ 113 oc_log(LOGWARN, "curl error: %s; ignored", 114 curl_easy_strerror(cstat)); 115 cstat = CURLE_OK; 116 } 117 if(cstat != CURLE_OK) goto fail; 118 119 /* Get the last modified time */ 120 if(filetime != NULL) 121 cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime); 122 if(cstat != CURLE_OK) goto fail; 162 123 163 124 /* Null terminate the buffer*/ … … 168 129 return THROW(stat); 169 130 170 fail: oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat)); 131 fail: 132 oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat)); 171 133 return THROW(OC_ECURL); 172 134 } … … 182 144 fetchdata->size += (count * size); 183 145 } 146 #ifdef OCPROGRESS 147 oc_log(LOGNOTE,"callback: %lu bytes",(unsigned long)(size*nmemb)); 148 #endif 184 149 return count; 185 150 } 186 151 187 152 static size_t 188 WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, 153 WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) 189 154 { 190 155 size_t realsize = size * nmemb; 191 156 OCbytes* buf = (OCbytes*) data; 157 if(realsize == 0) 158 oc_log(LOGWARN,"WriteMemoryCallback: zero sized chunk"); 159 /* Optimize for reading potentially large dods datasets */ 160 if(!ocbytesavail(buf,realsize)) { 161 /* double the size of the packet */ 162 ocbytessetalloc(buf,2*ocbytesalloc(buf)); 163 } 192 164 ocbytesappendn(buf, ptr, realsize); 193 165 return realsize; … … 300 272 301 273 int 302 curlopen(CURL** curlp)274 occurlopen(CURL** curlp) 303 275 { 304 276 int stat = OC_NOERR; … … 321 293 if (cstat != CURLE_OK) 322 294 stat = OC_ECURL; 323 324 } 325 295 } 326 296 if (curlp) 327 297 *curlp = curl; … … 330 300 331 301 void 332 curlclose(CURL* curl)302 occurlclose(CURL* curl) 333 303 { 334 304 if (curl != NULL) 335 305 curl_easy_cleanup(curl); 336 306 } 307 308 static int 309 ocsetcurlproperties(CURL* curl, const char* url) 310 { 311 CURLcode cstat = CURLE_OK; 312 /* These conditionals look for value in four globals set when the 313 * .dodsrc file was read. 314 */ 315 if (dods_verify) { 316 if (set_verify(curl) != OC_NOERR) 317 goto fail; 318 } 319 if (dods_compress) { 320 if (set_compression(curl) != OC_NOERR) 321 goto fail; 322 } 323 if (pstructProxy) { 324 if (set_proxy(curl, pstructProxy) != OC_NOERR) 325 goto fail; 326 } 327 if (cook) { 328 if (set_cookies(curl, cook) != OC_NOERR) 329 goto fail; 330 } 331 332 if (credentials_in_url(url)) { 333 char *result_url = NULL; 334 if (extract_credentials(url, &userName, &password, &result_url) != OC_NOERR) 335 goto fail; 336 url = result_url; 337 } 338 339 if (userName && password) { 340 if (set_user_password(curl, userName, password) != OC_NOERR) 341 goto fail; 342 } 343 return OC_NOERR; 344 345 fail: 346 oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat)); 347 return THROW(OC_ECURL); 348 } 349 350 int 351 ocfetchlastmodified(CURL* curl, char* url, long* filetime) 352 { 353 int stat = OC_NOERR; 354 CURLcode cstat = CURLE_OK; 355 size_t len; 356 357 if((stat = ocsetcurlproperties(curl,url)) != OC_NOERR) goto fail; 358 359 /* Set the URL */ 360 cstat = curl_easy_setopt(curl, CURLOPT_URL, (void*)url); 361 if (cstat != CURLE_OK) 362 goto fail; 363 364 /* Ask for head */ 365 cstat = curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); /* 30sec timeout*/ 366 cstat = curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2); 367 cstat = curl_easy_setopt(curl, CURLOPT_HEADER, 1); 368 cstat = curl_easy_setopt(curl, CURLOPT_NOBODY, 1); 369 cstat = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); 370 cstat = curl_easy_setopt(curl, CURLOPT_FILETIME, (long)1); 371 372 cstat = curl_easy_perform(curl); 373 if(cstat != CURLE_OK) goto fail; 374 if(filetime != NULL) 375 cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime); 376 if(cstat != CURLE_OK) goto fail; 377 378 return THROW(stat); 379 380 fail: 381 oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat)); 382 return THROW(OC_ECURL); 383 }
Note: See TracChangeset
for help on using the changeset viewer.