Browse code

- support in is_method() to test many methods (e.g., is_method("INVITE|CANCEL")) - documentation updated - test if the method name is followed by comma (methods list)

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@93 689a6050-402a-0410-94f2-e92a70836424

Elena-Ramona Modroiu authored on 08/07/2005 17:50:27
Showing 3 changed files
... ...
@@ -333,6 +333,13 @@ append_time();
333 333
    the function performs method ID testing (integer comparison)
334 334
    instead of ignore case string comparison.
335 335
 
336
+   The 'name' can be a list of methods in the form of
337
+   'method1|method2|...'. In this case, the function returns true
338
+   if the SIP message's method is one from the list. IMPORTANT
339
+   NOTE: in the list must be only methods defined in OpenSER with
340
+   ID (invite, cancel, ack, bye, options, info, update, register,
341
+   message, subscribe, notify, refer, prack).
342
+
336 343
    If used for replies, the function tests the value of method
337 344
    field from CSeq header.
338 345
 
... ...
@@ -346,6 +353,10 @@ if(is_method("INVITE"))
346 353
 {
347 354
     # process INVITEs here
348 355
 }
356
+if(is_method("OPTION|UPDATE"))
357
+{
358
+    # process OPTIONs and UPDATEs here
359
+}
349 360
 ...
350 361
      _________________________________________________________
351 362
 
... ...
@@ -466,6 +466,14 @@ append_time();
466 466
 		comparison.
467 467
 		</para>
468 468
 		<para>
469
+		The 'name' can be a list of methods in the form of
470
+		'method1|method2|...'. In this case, the function returns true if the
471
+		SIP message's method is one from the list. IMPORTANT NOTE: in the list
472
+		must be only methods defined in &ser; with ID (invite, cancel, ack,
473
+		bye, options, info, update, register, message, subscribe, notify,
474
+		refer, prack).
475
+		</para>
476
+		<para>
469 477
 		If used for replies, the function tests the value of method field from
470 478
 		CSeq header.
471 479
 		</para>
... ...
@@ -484,6 +492,10 @@ if(is_method("INVITE"))
484 492
 {
485 493
     # process INVITEs here
486 494
 }
495
+if(is_method("OPTION|UPDATE"))
496
+{
497
+    # process OPTIONs and UPDATEs here
498
+}
487 499
 ...
488 500
 </programlisting>
489 501
 		</example>
... ...
@@ -641,7 +641,7 @@ static int is_method_f(struct sip_msg *msg, char *meth, char *str2 )
641 641
 	if(msg->first_line.type==SIP_REQUEST)
642 642
 	{
643 643
 		if(m->s==0)
644
-			return (msg->first_line.u.request.method_value==m->len)?1:-1;
644
+			return (msg->first_line.u.request.method_value&m->len)?1:-1;
645 645
 		else
646 646
 			return (msg->first_line.u.request.method_value==METHOD_OTHER
647 647
 					&& msg->first_line.u.request.method.len==m->len
... ...
@@ -743,6 +743,8 @@ static int hname_fixup(void** param, int param_no)
743 743
 static int fixup_method(void** param, int param_no)
744 744
 {
745 745
 	str* s;
746
+	char *p;
747
+	int m;
746 748
 	int method;
747 749
 	
748 750
 	s = (str*)pkg_malloc(sizeof(str));
... ...
@@ -759,23 +761,49 @@ static int fixup_method(void** param, int param_no)
759 761
 		pkg_free(s);
760 762
 		return E_UNSPEC;
761 763
 	}
762
-
763
-	if(parse_method(s->s, 0, &method)==NULL)
764
+	m=0;
765
+	p=s->s;
766
+	while(*p)
767
+	{
768
+		if(*p=='|')
769
+		{
770
+			*p = ',';
771
+			m=1;
772
+		}
773
+		p++;
774
+	}
775
+	if(parse_methods(s, &method)!=0)
764 776
 	{
765
-		LOG(L_ERR,"textops:fixup_method: bad method name\n");
777
+		LOG(L_ERR,"textops:fixup_method: bad method names\n");
766 778
 		pkg_free(s);
767 779
 		return E_UNSPEC;
768 780
 	}
769 781
 
770
-	if(method!=METHOD_UNDEF && method!=METHOD_OTHER)
782
+	if(m==1)
771 783
 	{
772
-		DBG("textops:fixup_method: using id for method [%.*s/%d]\n",
784
+		if(method==METHOD_UNDEF || method&METHOD_OTHER)
785
+		{
786
+			LOG(L_ERR,
787
+				"textops:fixup_method: unknown method in list [%.*s/%d]"
788
+				" - must be only defined methods\n",
789
+				s->len, s->s, method);
790
+			return E_UNSPEC;
791
+		}
792
+		DBG("textops:fixup_method: using id for methods [%.*s/%d]\n",
773 793
 				s->len, s->s, method);
774 794
 		s->s = 0;
775 795
 		s->len = method;
776
-	} else
777
-		DBG("textops:fixup_method: name for method [%.*s/%d]\n",
796
+	} else {
797
+		if(method!=METHOD_UNDEF && method!=METHOD_OTHER)
798
+		{
799
+			DBG("textops:fixup_method: using id for method [%.*s/%d]\n",
800
+				s->len, s->s, method);
801
+			s->s = 0;
802
+			s->len = method;
803
+		} else
804
+			DBG("textops:fixup_method: name for method [%.*s/%d]\n",
778 805
 				s->len, s->s, method);
806
+	}
779 807
 
780 808
 	*param = (void*)s;
781 809
 	return 0;