Browse Source

rls(k): send 200ok for NOTIFY with subscription state termintated

- when rls module sends an un-SUBSCRIBE (expires=0), then the dialog
  structure is removed and the NOTIFY arriving later to confirm the
  termination of subscription does not find any record, resulting in no
  reply
- the patch detects the subscribe-state terminated in NOTIFY requests
  and sends back 200ok
- reported by Peter Dunkley
(cherry picked from commit cdee458b2ec4296cb847dd6e531285c0ac64dd80)
Daniel-Constantin Mierla 14 years ago
parent
commit
d93dc272bd
1 changed files with 23 additions and 13 deletions
  1. 23 13
      modules_k/rls/resource_notify.c

+ 23 - 13
modules_k/rls/resource_notify.c

@@ -240,16 +240,6 @@ int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
 		LM_ERR("unrecognized event package\n");
 		goto error;
 	}
-	if(pua_get_record_id(&dialog, &res_id)< 0) // verify if within a stored dialog
-	{
-		LM_ERR("occured when trying to get record id\n");
-		goto error;
-	}
-	if(res_id== 0)
-	{
-		LM_ERR("record not found\n");
-		goto error;
-	}
 
 	/* extract the subscription state */
 	hdr = msg->headers;
@@ -276,6 +266,24 @@ int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
 		LM_ERR("while parsing 'Subscription-State' header\n");
 		goto error;
 	}
+	if(pua_get_record_id(&dialog, &res_id)< 0) // verify if within a stored dialog
+	{
+		LM_ERR("occured when trying to get record id\n");
+		goto error;
+	}
+	if(res_id==0)
+	{
+		LM_DBG("presence dialog record not found\n");
+		/* if it is a NOTIFY for a terminated SUBSCRIBE dialog in RLS, then
+		 * the module might not have the dialog structure anymore
+		 * - just send 200ok, it is harmless
+		 */
+		if(auth_flag==TERMINATED_STATE)
+			goto done;
+		LM_ERR("no presence dialog record for non-TERMINATED state\n");
+		goto error;
+	}
+
 	if(msg->content_type== NULL || msg->content_type->body.s== NULL)
 	{
 		LM_DBG("cannot find content type header header\n");
@@ -408,9 +416,11 @@ done:
 		goto error;
 	}	
 
-	pkg_free(res_id->s);
-	pkg_free(res_id);
-
+	if(res_id!=NULL)
+	{
+		pkg_free(res_id->s);
+		pkg_free(res_id);
+	}
 	return 1;
 
 error: