Subject: [alpine-devel] kamailio kamctl script fixed for dbtext support

From: Francesco <[email-masked]>
Date: Thu, 19 Nov 2009 14:01:55 +0100

Added patch and modified APKBUILD. Increased $pkgrel=$pkgrel+1 :)

Look and review, thanks.

:: Francesco Colista ::
From 50e48adef2bc6ebe173200f77b5e999edcd9003a Mon Sep 17 00:00:00 2001
From: Francesco Colista <[email-masked]>
Date: Thu, 19 Nov 2009 12:56:42 +0000
Subject: [PATCH] Added patch for dbtext kamctl script

---
 main/kamailio/APKBUILD |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/main/kamailio/APKBUILD b/main/kamailio/APKBUILD
index efaeaaf..d9874aa 100644
--- a/main/kamailio/APKBUILD
+++ b/main/kamailio/APKBUILD
@@ -2,7 +2,7 @@
 # Maintainer: Natanael Copa <[email-masked]>
 pkgname=kamailio
 pkgver=1.5.3
-pkgrel=0
+pkgrel=1
 pkgdesc="Open Source SIP Server"
 url="http://www.kamailio.org/"
 pkgusers="kamailio"
@@ -17,8 +17,10 @@ subpackages="$pkgname-doc $pkgname-mysql $pkgname-postgres $pkgname-pcre
 source="http://www.kamailio.org/pub/kamailio/$pkgver/src/$pkgname-$pkgver-notls_src.tar.gz
 	kamailio.cfg
 	kamailio.initd
+	kamctl_dbtext-support.patch
 	kamailio.pre-install
-	kamailio.post-install"
+	kamailio.post-install
+	"
 
 build() {
 	cd "$srcdir/$pkgname-$pkgver-notls"
@@ -32,6 +34,9 @@ build() {
 	# we actually dont need bash
 	sed -i -e '1s:/bin/bash:/bin/sh:' kamctl kamdbctl \
 		|| return 1
+	# patch for dbtext support kamctl script
+	patch kamctl < "$srcdir"/kamctl_dbtext-support.patch
+
 	cd ..
 
 	make prefix=/usr \
@@ -54,6 +59,7 @@ build() {
 		basedir="$pkgdir" install || return 1
 
 	# move default config to -doc package and use our own default config
+
 	mv "$pkgdir"/etc/kamailio/kamailio.cfg \
 		"$pkgdir"/usr/share/doc/kamailio/
 	install -m644 -D "$srcdir"/kamailio.cfg \
@@ -117,5 +123,6 @@ unixodbc() {
 md5sums="17eeea5cdc2fdd28b2f9a1bad6598de2  kamailio-1.5.3-notls_src.tar.gz
 eb665248ee39cf755a247286affc5cbb  kamailio.cfg
 81100c479890a2a8c2628db22fdd1a0c  kamailio.initd
+57fcf6ba3ab7ab7081a9c512881b2a05  kamctl_dbtext-support.patch
 c646af2dd31f5c4289a2f802c873d98f  kamailio.pre-install
 3fbaf633ff1620d0d526fc4047c7bed9  kamailio.post-install"
-- 
1.6.4.4

From 856bb3498baba4af3bbd28764de0b88a2072fcbd Mon Sep 17 00:00:00 2001
From: Francesco Colista <[email-masked]>
Date: Thu, 19 Nov 2009 12:47:08 +0000
Subject: [PATCH] Patch for kamctl for control dbtext: added email_address field with default email [email-masked] if not given.
 The email_address field cannot be null.

---
 main/kamailio/kamctl_dbtext-support.patch |   30 +++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
 create mode 100644 main/kamailio/kamctl_dbtext-support.patch

diff --git a/main/kamailio/kamctl_dbtext-support.patch b/main/kamailio/kamctl_dbtext-support.patch
new file mode 100644
index 0000000..86bd931
--- /dev/null
+++ b/main/kamailio/kamctl_dbtext-support.patch
@@ -0,0 +1,30 @@
+--- kamctl	Thu Nov 19 12:44:08 2009
++++ kamctl.patched	Thu Nov 19 12:45:52 2009
+@@ -2115,7 +2115,7 @@
+ 				exit 1
+ 			fi
+ 			shift
+-			credentials $1 $2
++			credentials $1 $2 $3
+ 			is_user $1
+ 			if [ $? -eq 0 ] ; then
+ 				minfo "user '$1' already exists"
+@@ -2133,10 +2133,16 @@
+ 			else
+ 				PASS=""
+ 			fi
++# If not specifiyed, email_address is username@domain, beacause email_address filed can't be null.
++			if [ $EMAIL_COLUMN ] ; then
++				EMAIL_ADDRESS="$1@`hostname -d`"
++			else
++				EMAIL_ADDRESS="$3"
++			fi
+ 
+ 			QUERY="insert into $SUB_TABLE ($SUBSCRIBER_COLUMN,\
+-				$REALM_COLUMN,$HA1_COLUMN,$HA1B_COLUMN,$PASSWORD_COLUMN) \
+-				values ('$OSERUSER','$OSERDOMAIN','$HA1','$HA1B','$PASS');";
++				$REALM_COLUMN,$EMAIL_COLUMN,$HA1_COLUMN,$HA1B_COLUMN,$PASSWORD_COLUMN) \
++				values ('$OSERUSER','$OSERDOMAIN','$EMAIL_ADDRESS','$HA1','$HA1B','$PASS');";
+ 			$DBCMD "$QUERY"
+ 			if [ $? -ne 0 ] ; then
+ 				merr "introducing the new user '$1' to the database failed"
-- 
1.6.4.4

---

From: Ted Trask <[email-masked]>
Date: Thu, 19 Nov 2009 11:38:25 -0800 (PST)

After looking a little deeper at the problem, I think I found a better solution.

You need to remove "email_address(string)" from the file /usr/share/kamailio/dbtext/kamailio/subscriber so the dbtext database subscriber table no longer has the email_address field.

Ted Trask

----- Original Message ----
From: Francesco <[email-masked]>
To: [email-masked]
Sent: Thu, November 19, 2009 8:01:55 AM
Subject: [alpine-devel] kamailio kamctl script fixed for dbtext support

Look and review, thanks.

:: Francesco Colista ::

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Ted Trask <[email-masked]>
Date: Thu, 19 Nov 2009 13:46:38 -0800 (PST)

Ok, I've downloaded the code for 1.5.3 and looked even deeper. The
problem is in the database definition, but not quite what I said before.

Here is the 'subscriber' definition for the various DB types:
scripts/db_berkeley/kamailio/subscriber:id(int)
username(str) domain(str) password(str) email_address(str) ha1(str)
ha1b(str) rpid(str)
scripts/postgres/auth_db-create.sql:    email_address VARCHAR(64) DEFAULT '' NOT NULL,
scripts/mysql/auth_db-create.sql:    email_address VARCHAR(64) DEFAULT '' NOT NULL,
scripts/oracle/auth_db-create.sql:    email_address VARCHAR2(64) DEFAULT '',
scripts/dbtext/kamailio/subscriber:id(int,auto)
username(string) domain(string) password(string) email_address(string)
ha1(string) ha1b(string) rpid(string,null) 

Ok, all of the
databases have the email_address column, most saying non-null and
default to "". The problem comes because kamctl doesn't take a
parameter for email_address and tries to set it to null. For postgres
it works just fine, because there's a default defined. Not true for
dbtext. It says non-null, but doesn't define a default. Further, it
appears the dbtext does not differentiate between "" and null. So, if
we remove the non-null restriction, it will allow it to be set to null,
which is actually "", which is what the default should be!

So,
to make this as clear as mud, the one line in
scripts/dbtext/kamailio/subscriber
(/usr/share/kamailio/dbtext/kamailio/subscriber on the device) should
be changed from:

id(int,auto) username(string) domain(string) password(string) email_address(string) ha1(string) ha1b(string) rpid(string,null) 

to (adding the word 'null' in the email_address column definition):

id(int,auto)
username(string) domain(string) password(string)
email_address(string,null) ha1(string) ha1b(string) rpid(string,null) 

And that should fix the problem.

Ted Trask

----- Original Message ----
From: Ted Trask <[email-masked]>
To: Francesco <[email-masked]>; [email-masked]
Sent: Thu, November 19, 2009 2:38:25 PM
Subject: Re: [alpine-devel] kamailio kamctl script fixed for dbtext support

Ted Trask

----- Original Message ----
From: Francesco <[email-masked]>
To: [email-masked]
Sent: Thu, November 19, 2009 8:01:55 AM
Subject: [alpine-devel] kamailio kamctl script fixed for dbtext support

Look and review, thanks.

:: Francesco Colista ::

---

---

---

From: Natanael Copa <[email-masked]>
Date: Fri, 20 Nov 2009 08:10:02 +0100

On Thu, 2009-11-19 at 13:46 -0800, Ted Trask wrote:
...
> And that should fix the problem.

Francesco, care to make a new patch? Or do you want me to apply your
original?

-nc

---

---

From: Francesco <[email-masked]>
Date: Fri, 20 Nov 2009 08:13:19 +0100

I'll make new patch.
Thanks.

:: Francesco Colista ::

---

---

From: Francesco <[email-masked]>
Date: Mon, 23 Nov 2009 10:43:41 +0100

New APKBUILD for kamailio, contains fix for email_address field not null.

:: Francesco Colista ::