Module: sip-router Branch: master Commit: 95fd2d74ce0b5527586828df7348e84170b19729 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=95fd2d74...
Author: Henning Westerholt henning.westerholt@1und1.de Committer: Henning Westerholt henning.westerholt@1und1.de Date: Mon Dec 8 18:13:57 2008 +0100
kamailio compatibility, add str_strcmp and str_casecmp functions
---
ut.c | 2 +- ut.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/ut.c b/ut.c index 90f2f1e..7c63941 100644 --- a/ut.c +++ b/ut.c @@ -28,7 +28,7 @@ * */
-#include <string.h> + #include <sys/types.h> #include <pwd.h> #include <grp.h> diff --git a/ut.h b/ut.h index 45cf559..3de7138 100644 --- a/ut.h +++ b/ut.h @@ -56,6 +56,8 @@ #include <time.h> #include <unistd.h> #include <ctype.h> +#include <string.h> +#include <strings.h>
#include "compiler_opt.h" #include "config.h" @@ -633,6 +635,49 @@ static inline int pkg_str_dup(str* dst, const str* src) return 0; }
+/** + * \brief Compare two str's case sensitive + * \param str1 first str + * \param str2 second str + * \return 0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors + */ +static inline int str_strcmp(const str *str1, const str *str2) +{ + if(str1==NULL || str2==NULL || str1->s ==NULL || str2->s==NULL || str1->len<0 || str2->len<0) + { + LM_ERR("bad parameters\n"); + return -2; + } + + if (str1->len < str2->len) + return -1; + else if (str1->len > str2->len) + return 1; + else + return strncmp(str1->s, str2->s, str1->len); +} + +/** + * \brief Compare two str's case insensitive + * \param str1 first str + * \param str2 second str + * \return 0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors + */ +static inline int str_strcasecmp(const str *str1, const str *str2) +{ + if(str1==NULL || str2==NULL || str1->s ==NULL || str2->s==NULL || str1->len<0 || str2->len<0) + { + LM_ERR("bad parameters\n"); + return -2; + } + if (str1->len < str2->len) + return -1; + else if (str1->len > str2->len) + return 1; + else + return strncasecmp(str1->s, str2->s, str1->len); +} + /* converts a username into uid:gid, * returns -1 on error & 0 on success */ int user2uid(int* uid, int* gid, char* user);