changeset 1382:f62e18dc4800

test_ccload: allow sending to a realm instead of a particular host
author Thomas Klausner <tk@giga.or.at>
date Fri, 05 Jul 2019 18:31:50 +0200
parents f374d3f8f7d3
children 0d71c0b2eed4
files extensions/test_ccload/test_ccload.c
diffstat 1 files changed, 25 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/test_ccload/test_ccload.c	Wed Jun 26 18:11:36 2019 +0200
+++ b/extensions/test_ccload/test_ccload.c	Fri Jul 05 18:31:50 2019 +0200
@@ -31,7 +31,9 @@
 
 /* This extension waits for a signal (SIGUSR2). When it gets it, it
  * generates messages as quickly as possible to the configured target
- * host; a second SIGUSR2 signal will stop this */
+ * host; a second SIGUSR2 signal will stop this.
+ * If the target host starts with "REALM:", send to that Destination-Realm instead
+ * of a particular host. */
 
 #include <freeDiameter/extension.h>
 
@@ -196,25 +198,29 @@
 		return NULL;
 	}
 
-	/* Destination-Host */
-	fd_msg_avp_new(dh_avp_do, 0, &avp);
-	memset(&val, 0, sizeof(val));
-	val.os.data = (uint8_t *)target;
-	val.os.len = strlen(target);
-	if (fd_msg_avp_setvalue(avp, &val) != 0) {
-		fd_msg_free(msg);
-		fd_log_error("can't set value for 'Destination-Host' for 'Credit-Control-Request' message");
-		return NULL;
+	if (strncmp("REALM:", target, 6) != 0) {
+		/* Destination-Host */
+		fd_msg_avp_new(dh_avp_do, 0, &avp);
+		memset(&val, 0, sizeof(val));
+		val.os.data = (uint8_t *)target;
+		val.os.len = strlen(target);
+		if (fd_msg_avp_setvalue(avp, &val) != 0) {
+			fd_msg_free(msg);
+			fd_log_error("can't set value for 'Destination-Host' for 'Credit-Control-Request' message");
+			return NULL;
+		}
+		fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp);
+
+		if ((realm = strchr(target, '.')) == NULL) {
+			fd_msg_free(msg);
+			fd_log_error("can't extract realm from host '%s'", target);
+			return NULL;
+		}
+		/* skip dot */
+		realm++;
+	} else {
+		realm = target + 6; /* skip "REALM:" */
 	}
-	fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp);
-
-	if ((realm = strchr(target, '.')) == NULL) {
-		fd_msg_free(msg);
-		fd_log_error("can't extract realm from host '%s'", target);
-		return NULL;
-	}
-	/* skip dot */
-	realm++;
 	/* Destination-Realm */
 	fd_msg_avp_new(dr_avp_do, 0, &avp);
 	memset(&val, 0, sizeof(val));
"Welcome to our mercurial repository"