Browse code

registrar: save() - new flag to prepare the headers for reply

Daniel-Constantin Mierla authored on 13/09/2021 07:20:48
Showing 5 changed files
... ...
@@ -1236,6 +1236,11 @@ kamcmd cfg.set_now_int registrar use_expired_contacts 0
1236 1236
 					registration.
1237 1237
 					</para>
1238 1238
 				</listitem>
1239
+				<listitem>
1240
+					<para><emphasis>0x10</emphasis> - prepare the headers for
1241
+					reply, used only if flag 0x02 is set.
1242
+					</para>
1243
+				</listitem>
1239 1244
 			</itemizedlist>
1240 1245
 			<para>The flags may be given in decimal or hexadecimal format.</para>
1241 1246
 		</listitem>
... ...
@@ -49,11 +49,12 @@ extern int contact_max_size; /* configurable using module parameter "contact_max
49 49
 #define PATH_MODE_LAZY		1
50 50
 #define PATH_MODE_OFF		0
51 51
 
52
-#define REG_SAVE_MEM_FL     	(1<<0)
53
-#define REG_SAVE_NORPL_FL   	(1<<1)
54
-#define REG_SAVE_REPL_FL    	(1<<2)
55
-#define REG_SAVE_NOVARIATION_FL (1<<3)
56
-#define REG_SAVE_ALL_FL     ((1<<4)-1)
52
+#define REG_SAVE_MEM_FL     	(1<<0) /* save in memory only */
53
+#define REG_SAVE_NORPL_FL   	(1<<1) /* do not send reply internally */
54
+#define REG_SAVE_REPL_FL    	(1<<2) /* replace contacts - one contact per user */
55
+#define REG_SAVE_NOVARIATION_FL (1<<3) /* do not apply expire range */
56
+#define REG_SAVE_PREPRPL_FL   	(1<<4) /* prepare headers for reply */
57
+#define REG_SAVE_ALL_FL     ((1<<5)-1)
57 58
 
58 59
 #define REG_OUTBOUND_NONE	0
59 60
 #define REG_OUTBOUND_SUPPORTED	1
... ...
@@ -607,9 +607,9 @@ static int add_flow_timer(struct sip_msg* _m)
607 607
 }
608 608
 
609 609
 /*! \brief
610
- * Send a reply
610
+ * Prepare headers and send a reply if _mode=1
611 611
  */
612
-int reg_send_reply(struct sip_msg* _m)
612
+int reg_reply_helper(struct sip_msg* _m, int _mode)
613 613
 {
614 614
 	str unsup = str_init(OPTION_TAG_PATH_STR);
615 615
 	str outbound_str = str_init(OPTION_TAG_OUTBOUND_STR);
... ...
@@ -729,12 +729,31 @@ int reg_send_reply(struct sip_msg* _m)
729 729
 		}
730 730
 	}
731 731
 
732
-	if (slb.freply(_m, code, &msg) < 0) {
733
-		LM_ERR("failed to send %ld %.*s\n", code, msg.len,msg.s);
734
-		return -1;
735
-	} else return 0;
732
+	if(likely(_mode)) {
733
+		if (slb.freply(_m, code, &msg) < 0) {
734
+			LM_ERR("failed to send %ld %.*s\n", code, msg.len,msg.s);
735
+			return -1;
736
+		}
737
+	}
738
+
739
+	return 0;
736 740
 }
737 741
 
742
+/*! \brief
743
+ * Send a reply
744
+ */
745
+int reg_send_reply(struct sip_msg* _m)
746
+{
747
+	return reg_reply_helper(_m, 1);
748
+}
749
+
750
+/*! \brief
751
+ * Prepare a reply
752
+ */
753
+int reg_prepare_reply(struct sip_msg* _m)
754
+{
755
+	return reg_reply_helper(_m, 0);
756
+}
738 757
 
739 758
 /*! \brief
740 759
  * Release contact buffer if any
... ...
@@ -38,6 +38,11 @@
38 38
  */
39 39
 int reg_send_reply(struct sip_msg* _m);
40 40
 
41
+/*! \brief
42
+ * Prepare a reply
43
+ */
44
+int reg_prepare_reply(struct sip_msg* _m);
45
+
41 46
 
42 47
 /*! \brief
43 48
  * Build Contact HF for reply
... ...
@@ -1015,10 +1015,18 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
1015 1015
 
1016 1016
 	update_stat(accepted_registrations, 1);
1017 1017
 
1018
-	/* Only send reply upon request, not upon reply */
1019
-	if ((is_route_type(REQUEST_ROUTE) || is_route_type(FAILURE_ROUTE))
1020
-			&& !is_cflag_set(REG_SAVE_NORPL_FL) && (reg_send_reply(_m) < 0))
1021
-		return -1;
1018
+	if(!is_cflag_set(REG_SAVE_NORPL_FL)) {
1019
+		/* Only send reply upon request, not upon reply */
1020
+		if (is_route_type(REQUEST_ROUTE) || is_route_type(FAILURE_ROUTE)) {
1021
+			if (reg_send_reply(_m) < 0) {
1022
+				return -1;
1023
+			}
1024
+		}
1025
+	} else if (is_cflag_set(REG_SAVE_PREPRPL_FL)) {
1026
+		if (reg_prepare_reply(_m) < 0) {
1027
+			return -1;
1028
+		}
1029
+	}
1022 1030
 
1023 1031
 	if (path_enabled && path_mode != PATH_MODE_OFF) {
1024 1032
 		reset_path_vector(_m);