@@ -334,29 +334,50 @@ static char* escape_http_request(chunk_t req)
334
334
* Send a SCEP request via HTTP and wait for a response
335
335
*/
336
336
bool scep_http_request (const char * url , chunk_t msg , scep_op_t op ,
337
- scep_http_params_t * http_params , chunk_t * response )
337
+ bool http_post , chunk_t * response )
338
338
{
339
339
int len ;
340
340
status_t status ;
341
341
char * complete_url = NULL ;
342
342
const char * operation ;
343
343
host_t * srcip = NULL ;
344
344
345
- /* initialize response */
346
- * response = chunk_empty ;
345
+ uint32_t http_timeout = lib -> settings -> get_time ( lib -> settings ,
346
+ "%s.scep.http_timeout" , 30 , lib -> ns ) ;
347
347
348
- if (http_params -> bind )
348
+ char * http_bind = lib -> settings -> get_str (lib -> settings ,
349
+ "%s.scep.http_bind" , NULL , lib -> ns );
350
+
351
+ if (http_bind )
349
352
{
350
- srcip = host_create_from_string (http_params -> bind , 0 );
353
+ srcip = host_create_from_string (http_bind , 0 );
351
354
}
352
355
DBG2 (DBG_APP , "sending scep request to '%s'" , url );
353
356
357
+ /* initialize response */
358
+ * response = chunk_empty ;
359
+
354
360
operation = operations [op ];
355
361
switch (op )
356
362
{
357
363
case SCEP_PKI_OPERATION :
358
364
default :
359
- if (http_params -> get_request )
365
+ if (http_post )
366
+ {
367
+ /* form complete url */
368
+ len = strlen (url ) + 11 + strlen (operation ) + 1 ;
369
+ complete_url = malloc (len );
370
+ snprintf (complete_url , len , "%s?operation=%s" , url , operation );
371
+
372
+ status = lib -> fetcher -> fetch (lib -> fetcher , complete_url , response ,
373
+ FETCH_TIMEOUT , http_timeout ,
374
+ FETCH_REQUEST_DATA , msg ,
375
+ FETCH_REQUEST_TYPE , "" ,
376
+ FETCH_REQUEST_HEADER , "Expect:" ,
377
+ FETCH_SOURCEIP , srcip ,
378
+ FETCH_END );
379
+ }
380
+ else /* HTTP_GET */
360
381
{
361
382
char * escaped_req = escape_http_request (msg );
362
383
@@ -369,28 +390,13 @@ bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
369
390
free (escaped_req );
370
391
371
392
status = lib -> fetcher -> fetch (lib -> fetcher , complete_url , response ,
372
- FETCH_TIMEOUT , http_params -> timeout ,
393
+ FETCH_TIMEOUT , http_timeout ,
373
394
FETCH_REQUEST_HEADER , "Pragma:" ,
374
395
FETCH_REQUEST_HEADER , "Host:" ,
375
396
FETCH_REQUEST_HEADER , "Accept:" ,
376
397
FETCH_SOURCEIP , srcip ,
377
398
FETCH_END );
378
399
}
379
- else /* HTTP_POST */
380
- {
381
- /* form complete url */
382
- len = strlen (url ) + 11 + strlen (operation ) + 1 ;
383
- complete_url = malloc (len );
384
- snprintf (complete_url , len , "%s?operation=%s" , url , operation );
385
-
386
- status = lib -> fetcher -> fetch (lib -> fetcher , complete_url , response ,
387
- FETCH_TIMEOUT , http_params -> timeout ,
388
- FETCH_REQUEST_DATA , msg ,
389
- FETCH_REQUEST_TYPE , "" ,
390
- FETCH_REQUEST_HEADER , "Expect:" ,
391
- FETCH_SOURCEIP , srcip ,
392
- FETCH_END );
393
- }
394
400
break ;
395
401
case SCEP_GET_CA_CERT :
396
402
case SCEP_GET_CA_CAPS :
@@ -401,7 +407,7 @@ bool scep_http_request(const char *url, chunk_t msg, scep_op_t op,
401
407
snprintf (complete_url , len , "%s?operation=%s" , url , operation );
402
408
403
409
status = lib -> fetcher -> fetch (lib -> fetcher , complete_url , response ,
404
- FETCH_TIMEOUT , http_params -> timeout ,
410
+ FETCH_TIMEOUT , http_timeout ,
405
411
FETCH_SOURCEIP , srcip ,
406
412
FETCH_END );
407
413
}
0 commit comments