浏览代码

pua_reginfo: use expires from contact for publish rq

Matteo Brancaleoni 1 月之前
父节点
当前提交
0e284b0632
共有 1 个文件被更改,包括 28 次插入1 次删除
  1. 28 1
      src/modules/pua_reginfo/usrloc_cb.c

+ 28 - 1
src/modules/pua_reginfo/usrloc_cb.c

@@ -257,6 +257,33 @@ error:
 	return NULL;
 }
 
+int reginfo_get_expires(urecord_t *record)
+{
+	// Loop through all record contacts and set the publish Expire value
+	// to the max expire of the contacts
+	ucontact_t *ptr;
+	time_t cur_time = time(0);
+	int expires = -1;
+	int tmp_expires;
+
+	ptr = record->contacts;
+	while(ptr) {
+		if(VALID_CONTACT(ptr, cur_time)) {
+			tmp_expires = (int)(ptr->expires - cur_time);
+			if(tmp_expires > expires) {
+				expires = tmp_expires;
+			}
+		}
+		ptr = ptr->next;
+	}
+	if(expires < 0) {
+		/* if we cannot calc expire from reg contacts, just use this default */
+		expires = 3600;
+	}
+
+	return expires;
+}
+
 void reginfo_usrloc_cb(ucontact_t *c, int type, void *param)
 {
 	str *body = NULL;
@@ -371,7 +398,7 @@ void reginfo_usrloc_cb(ucontact_t *c, int type, void *param)
 	publ.id.s = id_buf;
 	publ.id.len = id_buf_len;
 	publ.content_type = content_type;
-	publ.expires = 3600;
+	publ.expires = reginfo_get_expires(record);
 
 	/* make UPDATE_TYPE, as if this "publish dialog" is not found
 	   by pua it will fallback to INSERT_TYPE anyway */