*/
static int
http_fetch(struct http_handler *handler, char const *uri, long *response_code,
- long *cond_met, bool log_operation, FILE *file, bool is_ta)
+ long *cond_met, bool log_operation, FILE *file)
{
CURLcode res, res2;
long unmet = 0;
setopt_str(handler->curl, CURLOPT_URL, uri);
setopt_writedata(handler->curl, file);
+ pr_val_debug("HTTP GET: %s", uri);
res = curl_easy_perform(handler->curl);
res2 = curl_easy_getinfo(handler->curl, CURLINFO_RESPONSE_CODE,
return 0;
}
- if (*response_code >= HTTP_BAD_REQUEST) {
+ if (*response_code >= HTTP_BAD_REQUEST)
return pr_val_err("Error requesting URL %s (received HTTP code %ld): %s",
uri, *response_code, curl_err_string(handler, res));
- }
pr_val_err("Error requesting URL %s: %s", uri,
curl_err_string(handler, res));
- if (log_operation) {
+ if (log_operation)
pr_op_err("Error requesting URL %s: %s", uri,
curl_err_string(handler, res));
- }
return EREQFAILED;
}
static int
__http_download_file(struct rpki_uri *uri, long *response_code, long ims_value,
- long *cond_met, bool log_operation, bool is_ta)
+ long *cond_met, bool log_operation)
{
char const *tmp_suffix = "_tmp";
struct http_handler handler;
CURL_TIMECOND_IFMODSINCE);
}
error = http_fetch(&handler, uri_get_global(uri), response_code,
- cond_met, log_operation, out, is_ta);
- if (error != EREQFAILED) {
+ cond_met, log_operation, out);
+ if (error != EREQFAILED)
break; /* Note: Usually happy path */
- }
if (retries == config_get_http_retry_count()) {
pr_val_warn("Max HTTP retries (%u) reached requesting for '%s', won't retry again.",
* request to the server failed.
*/
int
-http_download_file(struct rpki_uri *uri, bool log_operation, bool is_ta)
+http_download_file(struct rpki_uri *uri, bool log_operation)
{
long response;
long cond_met;
return __http_download_file(uri, &response, 0, &cond_met,
- log_operation, is_ta);
+ log_operation);
}
/*
int error;
error = __http_download_file(uri, &response, value, &cond_met,
- log_operation, false);
+ log_operation);
if (error)
return error;
*/
return __http_download_file(uri, &response, 0, &cond_met,
- log_operation, false);
+ log_operation);
}
response_code = 0;
cond_met = 0;
error = http_fetch(&handler, remote, &response_code, &cond_met, true,
- out, false);
+ out);
http_easy_cleanup(&handler);
file_close(out);
if (error)
int http_init(void);
void http_cleanup(void);
-int http_download_file(struct rpki_uri *, bool, bool);
+int http_download_file(struct rpki_uri *, bool);
int http_download_file_with_ims(struct rpki_uri *, long, bool);
int http_direct_download(char const *, char const *);
DBG.stream = stdout;
INF.stream = stdout;
- WRN.stream = stdout;
- ERR.stream = stdout;
- CRT.stream = stdout;
+ WRN.stream = stderr;
+ ERR.stream = stderr;
+ CRT.stream = stderr;
UNK.stream = stdout;
openlog("fort", LOG_CONS | LOG_PID, LOG_DAEMON);
int
pr_enomem(void)
{
+ static char const *ENOMEM_MSG = "Out of memory.\n";
+ ssize_t garbage;
+
/*
* I'm not using PR_SIMPLE and friends, because those allocate.
* We want to minimize allocations after a memory allocation failure.
if (LOG_ERR > op_config.level)
return -ENOMEM;
- if (op_config.syslog_enabled) {
+ if (op_config.fprintf_enabled) {
lock_mutex();
- syslog(LOG_ERR | op_config.facility, "Out of memory.");
+ /*
+ * write() is AS-Safe, which implies it doesn't allocate,
+ * unlike printf().
+ */
+ garbage = write(STDERR_FILENO, ENOMEM_MSG, strlen(ENOMEM_MSG));
unlock_mutex();
+ garbage++;
}
- if (op_config.fprintf_enabled) {
+ if (op_config.syslog_enabled) {
lock_mutex();
- fprintf(stderr, "Out of memory.\n");
+ /* This allocates, but I don't think I have more options. */
+ syslog(LOG_ERR | op_config.facility, "Out of memory.");
unlock_mutex();
}
if (error)
goto just_quit;
- /* TODO (issue49) don't forget to improve this. */
- pr_op_info("Fort 1.5.0.2");
-
error = thvar_init();
if (error)
goto revert_log;
return 0; /* Try some other TAL URI */
}
error = http_download_file(uri,
- reqs_errors_log_uri(uri_get_global(uri)), true);
+ reqs_errors_log_uri(uri_get_global(uri)));
}
/* Reminder: there's a positive error: EREQFAILED */
"TAL URI '%s' could not be downloaded.",
uri_val_get_printable(uri));
}
-
} else {
/* Look for local files */
if (!valid_file_or_dir(uri_get_local(uri), true, false,
error = http_download_file_with_ims(uri, last_update,
log_operation);
else
- error = http_download_file(uri, log_operation, false);
+ error = http_download_file(uri, log_operation);
/*
* Since distinct files can be downloaded (notification, snapshot,
#include <stdlib.h>
#include <unistd.h>
#include <signal.h> /* SIGINT, SIGQUIT, etc */
+#include <syslog.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/wait.h>
int fork_fds[2][2];
pid_t child_pid;
unsigned int retries;
+ unsigned int i;
int child_status;
int error;
if (error)
return error;
+ if (log_val_enabled(LOG_DEBUG)) {
+ pr_val_debug("Executing RSYNC:");
+ for (i = 0; i < args_len + 1; i++)
+ pr_val_debug(" %s", args[i]);
+ }
+
retries = 0;
do {
child_status = 0;
error = get_rsync_uri(requested_uri, is_ta, &rsync_uri);
} else {
error = check_ancestor_error(requested_uri);
- if (error) {
+ if (error)
return error;
- }
error = handle_strict_strategy(requested_uri, &rsync_uri);
}
check_PROGRAMS = address.test
check_PROGRAMS += clients.test
check_PROGRAMS += db_table.test
-check_PROGRAMS += http.test
check_PROGRAMS += line_file.test
check_PROGRAMS += pdu_handler.test
check_PROGRAMS += rsync.test
db_table_test_SOURCES = rtr/db/db_table_test.c
db_table_test_LDADD = ${MY_LDADD}
-http_test_SOURCES = http_test.c
-http_test_LDADD = ${MY_LDADD} ${CURL_LIBS}
-
line_file_test_SOURCES = line_file_test.c
line_file_test_LDADD = ${MY_LDADD}
+++ /dev/null
-#include <check.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include "common.c"
-#include "file.c"
-#include "impersonator.c"
-#include "log.c"
-#include "uri.c"
-#include "http/http.c"
-
-struct response {
- unsigned char *content;
- size_t size;
-};
-
-static void
-init_response(struct response *resp)
-{
- resp->size = 0;
- resp->content = malloc(sizeof(char));
-}
-
-static size_t
-write_buf_cb(unsigned char *content, size_t size, size_t nmemb, void *arg)
-{
- struct response *resp = arg;
- unsigned char *tmp;
- size_t read = size * nmemb;
-
- tmp = realloc(resp->content, resp->size + read + 1);
- if (tmp == NULL)
- return -EINVAL;
-
- resp->content = tmp;
- memcpy(&resp->content[resp->size], content, read);
- resp->size += read;
- resp->content[resp->size] = 0;
-
- return read;
-}
-
-static int
-local_download(char const *url, long *response_code, struct response *resp)
-{
- struct http_handler handler;
- long cond;
- int error;
-
- cond = 0;
- error = http_easy_init(&handler);
- if (error)
- return error;
-
- error = http_fetch(&handler, url, response_code, &cond, false,
- write_buf_cb, resp);
- http_easy_cleanup(&handler);
- return error;
-}
-
-START_TEST(http_fetch_normal)
-{
- struct response resp;
- long response_code;
- char const *url = "https://rrdp.ripe.net/notification.xml";
-
- init_response(&resp);
- response_code = 0;
-
- ck_assert_int_eq(http_init(), 0);
- ck_assert_int_eq(local_download(url, &response_code, &resp), 0);
- ck_assert_int_gt(resp.size, 0);
-
- http_cleanup();
- free(resp.content);
- if (response_code == 0)
- ck_abort_msg("NO response code received");
- else if (response_code >= HTTP_BAD_REQUEST)
- ck_abort_msg("Received response code %ld", response_code);
-}
-END_TEST
-
-Suite *http_load_suite(void)
-{
- Suite *suite;
- TCase *fetch;
-
- fetch = tcase_create("Fetch");
- tcase_add_test(fetch, http_fetch_normal);
- tcase_set_timeout(fetch, 60);
-
- suite = suite_create("http_test()");
- suite_add_tcase(suite, fetch);
-
- return suite;
-}
-
-int main(void)
-{
- Suite *suite;
- SRunner *runner;
- int tests_failed;
-
- suite = http_load_suite();
-
- runner = srunner_create(suite);
- srunner_run_all(runner, CK_NORMAL);
- tests_failed = srunner_ntests_failed(runner);
- srunner_free(runner);
-
- return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
return false;
}
-unsigned int
-config_get_max_cert_depth(void)
-{
- return 32;
-}
-
char const *
config_get_local_repository(void)
{
return rsync_priority;
}
-bool
-config_get_http_enabled(void)
-{
- return false;
-}
-
unsigned int
config_get_http_priority(void)
{
return http_priority;
}
-bool
-config_get_work_offline(void)
-{
- return false;
-}
-
-bool
-config_get_color_output(void)
-{
- return false;
-}
-
-enum filename_format
-config_get_filename_format(void)
-{
- return FNF_NAME;
-}
-
-char *
-config_get_rsync_program(void)
-{
- return "rsync";
-}
-
-struct string_array const *
-config_get_rsync_args(bool is_ta)
-{
- static const struct string_array array = { 0 };
- return &array;
-}
-
char const *
config_get_slurm(void)
{
return (3<<3); /* LOG_DAEMON */
}
-unsigned int
-config_get_asn1_decode_max_stack(void)
-{
- return 4096;
-}
-
enum incidence_action
incidence_get_action(enum incidence_id id)
{
return INAC_ERROR;
}
-/* Impersonate HTTP config */
-char const *
-config_get_http_user_agent(void)
-{
- return "fort-test/0.1";
-}
-
-unsigned int
-config_get_http_connect_timeout(void)
-{
- return 30;
-}
-
-unsigned int
-config_get_http_transfer_timeout(void)
-{
- return 0;
-}
-
-unsigned int
-config_get_http_idle_timeout(void)
-{
- return 15;
-}
-
-char const *
-config_get_http_ca_path(void)
-{
- return NULL;
-}
-
void
config_set_rsync_priority(unsigned int value)
{