Browse code

Avoid unnecessary strlen calls and fix issue with some compilers not accepting non-constant values in case statements

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

Dan Pascu authored on 08/02/2008 16:53:38
Showing 1 changed files
... ...
@@ -408,18 +408,17 @@ error:
408 408
 	return 0;
409 409
 }
410 410
 
411
+#define STR_MATCH(s1, s2)   ((s1).len==(s2).len && strncmp((s1).s, (s2).s, (s1).len)==0)
412
+
411 413
 int get_auid_flag(str auid)
412 414
 {
415
+	static str pres_rules = str_init("pres-rules");
416
+	static str rls_services = str_init("rls-services");
413 417
 
414
-	switch (auid.len)
415
-	{
416
-		case strlen("pres-rules"): if(strncmp(auid.s, "pres-rules",
417
-											strlen("pres-rules"))== 0)
418
-										return PRES_RULES;
418
+	if (STR_MATCH(auid, pres_rules))
419
+		return PRES_RULES;
420
+	else if (STR_MATCH(auid, rls_services))
421
+		return RESOURCE_LIST;
419 422
 
420
-		case strlen("rls-services"):if(strncmp(auid.s, "rls-services",
421
-											strlen("rls-services"))== 0)
422
-										return RESOURCE_LIST;
423
-	}
424 423
 	return -1;
425 424
 }