Browse code

xhttp_prom: counter_dec published via KEMI interface

Sergey Safarov authored on 16/09/2021 21:02:21
Showing 1 changed files
... ...
@@ -971,9 +971,9 @@ static int fixup_counter_inc(void** param, int param_no)
971 971
 /* } */
972 972
 
973 973
 /**
974
- * @brief Add an integer to a counter (No labels).
974
+ * @brief Updates counter (No labels).
975 975
  */
976
-static int ki_xhttp_prom_counter_inc_l0(struct sip_msg* msg, str *s_name, int number)
976
+static int ki_xhttp_prom_counter_update_l0(struct sip_msg* msg, operation operation, str *s_name, int number)
977 977
 {
978 978
 	if (s_name == NULL || s_name->s == NULL || s_name->len == 0) {
979 979
 		LM_ERR("Invalid name string\n");
... ...
@@ -986,18 +986,26 @@ static int ki_xhttp_prom_counter_inc_l0(struct sip_msg* msg, str *s_name, int nu
986 986
 	}
987 987
 
988 988
 	if (prom_counter_update(s_name, INCREMENT, number, NULL, NULL, NULL)) {
989
-		LM_ERR("Cannot add number: %d to counter: %.*s\n", number, s_name->len, s_name->s);
989
+		LM_ERR("Cannot %s number: %d %s counter: %.*s\n",
990
+			   operation == INCREMENT? "add" : "decrement",
991
+			   number,
992
+			   operation == INCREMENT? "to" : "from",
993
+			   s_name->len, s_name->s);
990 994
 		return -1;
991 995
 	}
992 996
 
993
-	LM_DBG("Added %d to counter %.*s\n", number, s_name->len, s_name->s);
997
+	LM_DBG("%s %d %s counter %.*s\n",
998
+		   operation == INCREMENT? "Added" : "Decremented",
999
+		   number,
1000
+		   operation == INCREMENT? "to" : "from",
1001
+		   s_name->len, s_name->s);
994 1002
 	return 1;
995 1003
 }
996 1004
 
997 1005
 /**
998
- * @brief Add an integer to a counter (1 label).
1006
+ * @brief Updates counter (1 label).
999 1007
  */
1000
-static int ki_xhttp_prom_counter_inc_l1(struct sip_msg* msg, str *s_name, int number, str *l1)
1008
+static int ki_xhttp_prom_counter_update_l1(struct sip_msg* msg, operation operation, str *s_name, int number, str *l1)
1001 1009
 {
1002 1010
 	if (s_name == NULL || s_name->s == NULL || s_name->len == 0) {
1003 1011
 		LM_ERR("Invalid name string\n");
... ...
@@ -1015,14 +1023,20 @@ static int ki_xhttp_prom_counter_inc_l1(struct sip_msg* msg, str *s_name, int nu
1015 1023
 	}
1016 1024
 
1017 1025
 	if (prom_counter_update(s_name, INCREMENT, number, l1, NULL, NULL)) {
1018
-		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s)\n",
1019
-			   number, s_name->len, s_name->s,
1026
+		LM_ERR("Cannot %s number: %d %s counter: %.*s (%.*s)\n",
1027
+			   operation == INCREMENT? "add" : "decrement",
1028
+			   number,
1029
+			   operation == INCREMENT? "to" : "from",
1030
+			   s_name->len, s_name->s,
1020 1031
 			   l1->len, l1->s
1021 1032
 			);
1022 1033
 		return -1;
1023 1034
 	}
1024 1035
 
1025
-	LM_DBG("Added %d to counter %.*s (%.*s)\n", number,
1036
+	LM_DBG("%s %d %s counter %.*s (%.*s)\n",
1037
+		   operation == INCREMENT? "Added" : "Decremented",
1038
+		   number,
1039
+		   operation == INCREMENT? "to" : "from",
1026 1040
 		   s_name->len, s_name->s,
1027 1041
 		   l1->len, l1->s
1028 1042
 		);
... ...
@@ -1031,9 +1045,9 @@ static int ki_xhttp_prom_counter_inc_l1(struct sip_msg* msg, str *s_name, int nu
1031 1045
 }
1032 1046
 
1033 1047
 /**
1034
- * @brief Add an integer to a counter (2 labels).
1048
+ * @brief Updates counter (2 labels).
1035 1049
  */
1036
-static int ki_xhttp_prom_counter_inc_l2(struct sip_msg* msg, str *s_name, int number,
1050
+static int ki_xhttp_prom_counter_update_l2(struct sip_msg* msg, operation operation, str *s_name, int number,
1037 1051
 										str *l1, str *l2)
1038 1052
 {
1039 1053
 	if (s_name == NULL || s_name->s == NULL || s_name->len == 0) {
... ...
@@ -1057,15 +1071,21 @@ static int ki_xhttp_prom_counter_inc_l2(struct sip_msg* msg, str *s_name, int nu
1057 1071
 	}
1058 1072
 
1059 1073
 	if (prom_counter_update(s_name, INCREMENT, number, l1, l2, NULL)) {
1060
-		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s, %.*s)\n",
1061
-			   number, s_name->len, s_name->s,
1074
+		LM_ERR("Cannot %s number: %d %s counter: %.*s (%.*s, %.*s)\n",
1075
+			   operation == INCREMENT? "add" : "decrement",
1076
+			   number,
1077
+			   operation == INCREMENT? "to" : "from",
1078
+			   s_name->len, s_name->s,
1062 1079
 			   l1->len, l1->s,
1063 1080
 			   l2->len, l2->s
1064 1081
 			);
1065 1082
 		return -1;
1066 1083
 	}
1067 1084
 
1068
-	LM_DBG("Added %d to counter %.*s (%.*s, %.*s)\n", number,
1085
+	LM_DBG("%s %d %s counter %.*s (%.*s, %.*s)\n",
1086
+		   operation == INCREMENT? "Added" : "Decremented",
1087
+		   number,
1088
+		   operation == INCREMENT? "to" : "from",
1069 1089
 		   s_name->len, s_name->s,
1070 1090
 		   l1->len, l1->s,
1071 1091
 		   l2->len, l2->s
... ...
@@ -1075,9 +1095,9 @@ static int ki_xhttp_prom_counter_inc_l2(struct sip_msg* msg, str *s_name, int nu
1075 1095
 }
1076 1096
 
1077 1097
 /**
1078
- * @brief Add an integer to a counter (3 labels).
1098
+ * @brief Updates counter (3 labels).
1079 1099
  */
1080
-static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int number,
1100
+static int ki_xhttp_prom_counter_update_l3(struct sip_msg* msg, operation operation, str *s_name, int number,
1081 1101
 										str *l1, str *l2, str *l3)
1082 1102
 {
1083 1103
 	if (s_name == NULL || s_name->s == NULL || s_name->len == 0) {
... ...
@@ -1105,9 +1125,12 @@ static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int nu
1105 1125
 		return -1;
1106 1126
 	}
1107 1127
 
1108
-	if (prom_counter_update(s_name, INCREMENT, number, l1, l2, l3)) {
1109
-		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s, %.*s, %.*s)\n",
1110
-			   number, s_name->len, s_name->s,
1128
+	if (prom_counter_update(s_name, operation, number, l1, l2, l3)) {
1129
+		LM_ERR("Cannot %s number: %d %s counter: %.*s (%.*s, %.*s, %.*s)\n",
1130
+			   operation == INCREMENT? "add" : "decrement",
1131
+			   number,
1132
+			   operation == INCREMENT? "to" : "from",
1133
+			   s_name->len, s_name->s,
1111 1134
 			   l1->len, l1->s,
1112 1135
 			   l2->len, l2->s,
1113 1136
 			   l3->len, l3->s
... ...
@@ -1115,7 +1138,10 @@ static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int nu
1115 1138
 		return -1;
1116 1139
 	}
1117 1140
 
1118
-	LM_DBG("Added %d to counter %.*s (%.*s, %.*s, %.*s)\n", number,
1141
+	LM_DBG("%s %d %s counter %.*s (%.*s, %.*s, %.*s)\n",
1142
+		   operation == INCREMENT? "Added" : "Decremented",
1143
+		   number,
1144
+		   operation == INCREMENT? "to" : "from",
1119 1145
 		   s_name->len, s_name->s,
1120 1146
 		   l1->len, l1->s,
1121 1147
 		   l2->len, l2->s,
... ...
@@ -1125,6 +1151,74 @@ static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int nu
1125 1151
 	return 1;
1126 1152
 }
1127 1153
 
1154
+/**
1155
+ * @brief Add an integer to a counter (No labels).
1156
+ */
1157
+static int ki_xhttp_prom_counter_inc_l0(struct sip_msg* msg, str *s_name, int number)
1158
+{
1159
+	return ki_xhttp_prom_counter_update_l0(msg, INCREMENT, s_name, number);
1160
+}
1161
+
1162
+/**
1163
+ * @brief Add an integer to a counter (1 labels).
1164
+ */
1165
+static int ki_xhttp_prom_counter_inc_l1(struct sip_msg* msg, str *s_name, int number, str *l1)
1166
+{
1167
+	return ki_xhttp_prom_counter_update_l1(msg, INCREMENT, s_name, number, l1);
1168
+}
1169
+
1170
+/**
1171
+ * @brief Add an integer to a counter (2 labels).
1172
+ */
1173
+static int ki_xhttp_prom_counter_inc_l2(struct sip_msg* msg, str *s_name, int number,
1174
+										str *l1, str *l2)
1175
+{
1176
+	return ki_xhttp_prom_counter_update_l2(msg, INCREMENT, s_name, number, l1, l2);
1177
+}
1178
+
1179
+/**
1180
+ * @brief Add an integer to a counter (3 labels).
1181
+ */
1182
+static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int number,
1183
+										str *l1, str *l2, str *l3)
1184
+{
1185
+	return ki_xhttp_prom_counter_update_l3(msg, INCREMENT, s_name, number, l1, l2, l3);
1186
+}
1187
+
1188
+/**
1189
+ * @brief Decrement an integer from a counter (No labels).
1190
+ */
1191
+static int ki_xhttp_prom_counter_dec_l0(struct sip_msg* msg, str *s_name, int number)
1192
+{
1193
+	return ki_xhttp_prom_counter_update_l0(msg, DECREMENT, s_name, number);
1194
+}
1195
+
1196
+/**
1197
+ * @brief Decrement an integer from a counter (1 labels).
1198
+ */
1199
+static int ki_xhttp_prom_counter_dec_l1(struct sip_msg* msg, str *s_name, int number, str *l1)
1200
+{
1201
+	return ki_xhttp_prom_counter_update_l1(msg, DECREMENT, s_name, number, l1);
1202
+}
1203
+
1204
+/**
1205
+ * @brief Decrement an integer from a counter (2 labels).
1206
+ */
1207
+static int ki_xhttp_prom_counter_dec_l2(struct sip_msg* msg, str *s_name, int number,
1208
+										str *l1, str *l2)
1209
+{
1210
+	return ki_xhttp_prom_counter_update_l2(msg, DECREMENT, s_name, number, l1, l2);
1211
+}
1212
+
1213
+/**
1214
+ * @brief Decrement an integer from a counter (3 labels).
1215
+ */
1216
+static int ki_xhttp_prom_counter_dec_l3(struct sip_msg* msg, str *s_name, int number,
1217
+										str *l1, str *l2, str *l3)
1218
+{
1219
+	return ki_xhttp_prom_counter_update_l3(msg, DECREMENT, s_name, number, l1, l2, l3);
1220
+}
1221
+
1128 1222
 /**
1129 1223
  * @brief Updates a counter.
1130 1224
  */
... ...
@@ -1967,6 +2061,26 @@ static sr_kemi_t sr_kemi_xhttp_prom_exports[] = {
1967 2061
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_STR,
1968 2062
 			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE }
1969 2063
 	},
2064
+	{ str_init("xhttp_prom"), str_init("counter_dec_l0"),
2065
+	    SR_KEMIP_INT, ki_xhttp_prom_counter_dec_l0,
2066
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
2067
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2068
+	},
2069
+	{ str_init("xhttp_prom"), str_init("counter_dec_l1"),
2070
+	    SR_KEMIP_INT, ki_xhttp_prom_counter_dec_l1,
2071
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_STR,
2072
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2073
+	},
2074
+	{ str_init("xhttp_prom"), str_init("counter_dec_l2"),
2075
+	    SR_KEMIP_INT, ki_xhttp_prom_counter_dec_l2,
2076
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_STR,
2077
+			SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }
2078
+	},
2079
+	{ str_init("xhttp_prom"), str_init("counter_dec_l3"),
2080
+	    SR_KEMIP_INT, ki_xhttp_prom_counter_dec_l3,
2081
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_STR,
2082
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE }
2083
+	},
1970 2084
 	{ str_init("xhttp_prom"), str_init("gauge_set_l0"),
1971 2085
 	    SR_KEMIP_INT, ki_xhttp_prom_gauge_set_l0,
1972 2086
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,