[SR-Dev] git:janakj/kcore: Kamailio functions and macros missing in sip-router/ut.h

Jan Janak jan at iptel.org
Tue Mar 3 01:07:28 CET 2009


Module: sip-router
Branch: janakj/kcore
Commit: 15bb433960da81e252ed25973a27897bc96228c3
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=15bb433960da81e252ed25973a27897bc96228c3

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Tue Mar  3 00:36:29 2009 +0100

Kamailio functions and macros missing in sip-router/ut.h

This is the supplemental file to sip-router/ut.h, the contents of this
file was taken from kamailio/ut.h and it contains only functions,
variables and defines which are missing in sip-router/ut.h

Kamailio modules that included ut.h should be modified to include
"lib/kcore/km_ut.h" _in addition to_ "../../ut.h"

---

 lib/kcore/km_ut.h |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/lib/kcore/km_ut.h b/lib/kcore/km_ut.h
new file mode 100644
index 0000000..43fc11b
--- /dev/null
+++ b/lib/kcore/km_ut.h
@@ -0,0 +1,120 @@
+/*
+ *$Id$
+ *
+ * - various general purpose functions
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+/*!
+ * \file
+ * \brief Various utility functions, mostly related to string handling
+ */
+
+#ifndef _KM_UT_H
+#define _KM_UT_H
+
+#include "../../ut.h"
+
+#ifndef MIN
+#define MIN(a, b) (a<b?a:b)
+#endif
+#ifndef MAX
+#define MAX(a, b) (a>b?a:b)
+#endif
+
+
+#define append_str(_dest,_src,_len)				\
+	do{											\
+		memcpy( (_dest) , (_src) , (_len) );	\
+		(_dest) += (_len) ;						\
+	}while(0);									\
+	
+
+
+/* INTeger-TO-Buffer-STRing : convers an unsigned long to a string 
+ * IMPORTANT: the provided buffer must be at least INT2STR_MAX_LEN size !! */
+static inline char* int2bstr(unsigned long l, char *s, int* len)
+{
+	int i;
+	i=INT2STR_MAX_LEN-2;
+	s[INT2STR_MAX_LEN-1]=0;
+	/* null terminate */
+	do{
+		s[i]=l%10+'0';
+		i--;
+		l/=10;
+	}while(l && (i>=0));
+	if (l && (i<0)){
+		LM_CRIT("overflow error\n");
+	}
+	if (len) *len=(INT2STR_MAX_LEN-2)-i;
+	return &s[i+1];
+}
+
+
+inline static int hexstr2int(char *c, int len, unsigned int *val)
+{
+	char *pc;
+	int r;
+	char mychar;
+
+	r=0;
+	for (pc=c; pc<c+len; pc++) {
+		r <<= 4 ;
+		mychar=*pc;
+		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
+		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
+		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
+		else return -1;
+	}
+	*val = r;
+	return 0;
+}
+
+
+
+/*
+ * Convert a str (base 10 or 16) into integer
+ */
+static inline int strno2int( str *val, unsigned int *mask )
+{
+	/* hexa or decimal*/
+	if (val->len>2 && val->s[0]=='0' && val->s[1]=='x') {
+		return hexstr2int( val->s+2, val->len-2, mask);
+	} else {
+		return str2int( val, mask);
+	}
+}
+
+
+
+/*! right and left space trimming */
+#define trim_spaces_lr(_s_)												\
+	do{																	\
+		for(;(_s_).s[(_s_).len-1]==' ';(_s_).s[--(_s_).len]=0);			\
+		for(;(_s_).s[0]==' ';(_s_).s=(_s_).s+1,(_s_).len--);			\
+																		\
+	}																	\
+	while(0);															\
+	
+
+
+#endif /* _KM_UT_H */




More information about the sr-dev mailing list