From 6fd79f52068a874a8ad4d5af333b4721cf8d8743 Mon Sep 17 00:00:00 2001 From: Sewan R&D Date: Thu, 8 Jun 2023 17:28:13 +0200 Subject: [PATCH] feat: notify-purge removes a file if notify success Closes #1675 Change-Id: I5edd20efabcf94a19932a7066e80d77e6d99f0d2 --- docs/rtpengine-recording.md | 5 +++++ etc/rtpengine-recording.conf | 1 + recording-daemon/main.c | 4 +++- recording-daemon/main.h | 1 + recording-daemon/notify.c | 7 +++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/rtpengine-recording.md b/docs/rtpengine-recording.md index 2d25a7799..19a6bb984 100644 --- a/docs/rtpengine-recording.md +++ b/docs/rtpengine-recording.md @@ -328,6 +328,11 @@ sufficient for a standard installation of rtpengine. is incompatible with DB-only storage as no recording file exists on storage (see __output-storage__). +- __\-\-notify-purge__ + + Remove the local file if the HTTP request was successful. Note that this + option is only useful if __\-\-notify-record__ is also enabled. + ## EXIT STATUS - __0__ diff --git a/etc/rtpengine-recording.conf b/etc/rtpengine-recording.conf index 4d790feb1..681415de4 100644 --- a/etc/rtpengine-recording.conf +++ b/etc/rtpengine-recording.conf @@ -59,5 +59,6 @@ table = 0 # notify-uri = https://example.com/rec/finished # notify-post = false # notify-no-verify = false +# notify-purge = false # notify-concurrency = 5 # notify-retries = 10 diff --git a/recording-daemon/main.c b/recording-daemon/main.c index 2b493dcc1..3b43a884a 100644 --- a/recording-daemon/main.c +++ b/recording-daemon/main.c @@ -65,6 +65,7 @@ int notify_nverify; int notify_threads = 5; int notify_retries = 10; int notify_record; +int notify_purge; static GQueue threads = G_QUEUE_INIT; // only accessed from main thread @@ -221,7 +222,8 @@ static void options(int *argc, char ***argv) { { "notify-concurrency", 0, 0, G_OPTION_ARG_INT, ¬ify_threads,"How many simultaneous requests", "INT" }, { "notify-retries", 0, 0, G_OPTION_ARG_INT, ¬ify_retries,"How many times to retry failed requesets","INT" }, #if CURL_AT_LEAST_VERSION(7,56,0) - { "notify-record", 0, 0, G_OPTION_ARG_NONE, ¬ify_record, "Also attach recorded file to request", NULL }, + { "notify-record", 0, 0, G_OPTION_ARG_NONE, ¬ify_record, "Also attach recorded file to request", NULL }, + { "notify-purge", 0, 0, G_OPTION_ARG_NONE, ¬ify_purge, "Remove the local file if notify success", NULL }, #endif { NULL, } }; diff --git a/recording-daemon/main.h b/recording-daemon/main.h index 5d46bcb7a..d4e27e4c1 100644 --- a/recording-daemon/main.h +++ b/recording-daemon/main.h @@ -47,6 +47,7 @@ extern int notify_nverify; extern int notify_threads; extern int notify_retries; extern int notify_record; +extern int notify_purge; extern volatile int shutdown_flag; diff --git a/recording-daemon/notify.c b/recording-daemon/notify.c index 2ae169371..95f7d689d 100644 --- a/recording-daemon/notify.c +++ b/recording-daemon/notify.c @@ -125,6 +125,13 @@ static void do_notify(void *p, void *u) { /* success */ ilog(LOG_NOTICE, "HTTP notification for '%s%s%s' was successful", FMT_M(req->name)); + + if (notify_record && notify_purge) { + if (unlink(req->full_filename_path) == 0) + ilog(LOG_NOTICE, "File '%s%s%s' deleted successfully.", FMT_M(req->full_filename_path)); + else + ilog(LOG_ERR, "File '%s%s%s' could not be deleted.", FMT_M(req->full_filename_path)); + } goto cleanup; fail: