Browse code

presence: skip body operations on empty string

Daniel-Constantin Mierla authored on 09/09/2021 08:27:01
Showing 3 changed files
... ...
@@ -1700,7 +1700,8 @@ jump_over_body:
1700 1700
 	}
1701 1701
 
1702 1702
 	/* build extra headers */
1703
-	if(build_str_hdr(subs, notify_body ? 1 : 0, &str_hdr) < 0) {
1703
+	if(build_str_hdr(subs, (notify_body && notify_body->len>0) ? 1 : 0,
1704
+				&str_hdr) < 0) {
1704 1705
 		LM_ERR("while building headers\n");
1705 1706
 		goto error;
1706 1707
 	}
... ...
@@ -303,6 +303,9 @@ int pres_dmq_handle_msg(
303 303
 		} else if(strcmp(it->string, "body") == 0) {
304 304
 			p_body.s = it->valuestring;
305 305
 			p_body.len = strlen(it->valuestring);
306
+			if(p_body.len==0) {
307
+				p_body.s = NULL;
308
+			}
306 309
 		} else {
307 310
 			LM_ERR("unrecognized field in json object\n");
308 311
 			goto invalid;
... ...
@@ -737,6 +737,7 @@ static int ps_db_update_presentity(sip_msg_t *msg, presentity_t *presentity,
737 737
 	result_cols[rez_ruid_col = n_result_cols++] = &str_ruid_col;
738 738
 
739 739
 	if(new_t) {
740
+		/* new_t!=0 */
740 741
 		LM_DBG("new presentity with etag %.*s\n", presentity->etag.len,
741 742
 				presentity->etag.s);
742 743
 
... ...
@@ -888,6 +889,7 @@ static int ps_db_update_presentity(sip_msg_t *msg, presentity_t *presentity,
888 889
 			*sent_reply = 1;
889 890
 		goto send_notify;
890 891
 	} else {
892
+		/* new_t==0 */
891 893
 		LM_DBG("updating existing presentity with etag %.*s\n",
892 894
 				presentity->etag.len, presentity->etag.s);
893 895
 
... ...
@@ -1206,7 +1208,7 @@ static int ps_db_update_presentity(sip_msg_t *msg, presentity_t *presentity,
1206 1208
 		update_vals[n_update_cols].val.int_val = presentity->priority;
1207 1209
 		n_update_cols++;
1208 1210
 
1209
-		if(body && body->s) {
1211
+		if(body && body->s && body->len>0) {
1210 1212
 			update_keys[n_update_cols] = &str_body_col;
1211 1213
 			update_vals[n_update_cols].type = DB1_BLOB;
1212 1214
 			update_vals[n_update_cols].nul = 0;
... ...
@@ -1748,7 +1750,7 @@ after_etag_generation:
1748 1750
 		ptc.expires = presentity->expires + (int)time(NULL);
1749 1751
 		ptc.received_time = presentity->received_time;
1750 1752
 		ptc.priority = presentity->priority;
1751
-		if(body && body->s) {
1753
+		if(body && body->s && body->len>0) {
1752 1754
 			ptc.body = *body;
1753 1755
 		}
1754 1756
 		if(presentity->sender) {