Great. Many thanks.

I have updated and tested db_perlvdb module
(using Kamailio::VDB::Adapter::Describe) and it seems to work perfectly now.

Please find attached two patches which apply changes to both code and
documentation of this module. Kindly review and merge them to appropriate
branches as mentioned below,

The first patch "*db_perlvdb-kamailio-5x.patch*" is for Kamailio v5.0 and
v5.1 branches. Theoretically this patch will work for kamailio v4.x
branches too however, since directory structure of kamailio changed since
v5.0, so some manual work is required to fix file paths mentioned in patch
file.

The second patch "*db_perlvdb-kamailio-master.patch*" is for kamailio
master branch.


Thank you.



On Sat, May 5, 2018 at 12:23 PM, Henning Westerholt <[email protected]> wrote:

> Am Samstag, 5. Mai 2018, 09:54:53 CEST schrieb M S:
>
> > Actually I need to support Elastic Search Engine (ESE) for a large data
>
> > mining project integrated with Kamailio. The easiest way i thought to
>
> > achieve that was to use Perl VDB or else i have to write up ESE module
> for
>
> > kamailio myself.
>
> >
>
> > I am going to test the changes you did to PERL VDB module and will fix up
>
> > any minor issues to make it working again. Kindly do not remove it from
>
> > kamailio repo. I am not expert in Kamailio APIs but have good coding
>
> > experience with C / C++, so I am willing to provide maintenance and bug
>
> > fixes for the module with your help on API side if needed.
>
> >
>
> > Also, the new DB API for Kamailio, is there any documentation related to
> it
>
> > available online. I want to study it and may be add later on a separate
>
> > kamailio module exclusively for ESE for better performance and features
>
> > specific to ESE.
>
>
>
> Hello,
>
>
>
> for documentation related to the DB API have a look to the src/lib/srdb1
> directory. There is a good doxygen documentation in the files available. If
> you install doxygen you can also generate the documentation HTML files
> locally which shows additional information about dependency trees etc..
>
>
>
> Additionally have a look to the db_mysql module, here you can see how to
> interact with the generic DB API.
>
>
>
> If you have specific questions, just ask here at the development list.
>
>
>
> Best regards,
>
>
>
> Henning
>
diff --git a/src/modules/db_perlvdb/README b/src/modules/db_perlvdb/README
index 653e9d8..7e2ef11 100644
--- a/src/modules/db_perlvdb/README
+++ b/src/modules/db_perlvdb/README
@@ -69,12 +69,12 @@ Chapter 1. Admin Guide
    database access. Relaying of insert, update, query and delete
    operations is supported.
 
-   Modules can be configured to use the perlvdb module as database backend
+   Modules can be configured to use the db_perlvdb module as database backend
    using the db_url_parameter:
 modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 
    This configuration options tells acc module that it should use the
-   perlvdb module which will in turn use the Perl class
+   db_perlvdb module which will in turn use the Perl class
    Kamailio::VDB::Adapter::AccountingSIPtrace to relay the database
    requests.
 
@@ -86,13 +86,13 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 2.1. Kamailio Modules
 
    The following modules must be loaded before this module:
-     * perl -- Perl module
+     * app_perl -- Perl Application module
 
 2.2. External Libraries or Applications
 
    The following libraries or applications must be installed before
    running Kamailio with this module loaded:
-     * None (Besides the ones mentioned in the perl module documentation).
+     * None (Besides the ones mentioned in the app_perl module documentation).
 
 3. Parameters
 
@@ -136,7 +136,7 @@ Chapter 2. Developer Guide
 
 2. Base class Kamailio::VDB
 
-   A client module has to be configured to use the perlvdb module in
+   A client module has to be configured to use the db_perlvdb module in
    conjunction with a Perl class to provide the functions. The configured
    class needs to inherit from the base class Kamailio::VDB.
 
diff --git a/src/modules/db_perlvdb/db_perlvdb.c b/src/modules/db_perlvdb/db_perlvdb.c
index 7a2b63e..7c158c9 100644
--- a/src/modules/db_perlvdb/db_perlvdb.c
+++ b/src/modules/db_perlvdb/db_perlvdb.c
@@ -32,18 +32,13 @@ static int mod_init(void);
 
 SV* vdbmod;
 
+static int db_perlvdb_bind_api(db_func_t *dbb);
+
 /*
  * Perl virtual database module interface
  */
 static cmd_export_t cmds[] = {
-	{"db_use_table",	(cmd_function)perlvdb_use_table, 2, 0, 0, 0},
-	{"db_init",		(cmd_function)perlvdb_db_init,   1, 0, 0, 0},
-	{"db_close",		(cmd_function)perlvdb_db_close,  2, 0, 0, 0},
-	{"db_insert",		(cmd_function)perlvdb_db_insert, 2, 0, 0, 0},
-	{"db_update",		(cmd_function)perlvdb_db_update, 2, 0, 0, 0},
-	{"db_delete",		(cmd_function)perlvdb_db_delete, 2, 0, 0, 0},
-	{"db_query",		(cmd_function)perlvdb_db_query, 2, 0, 0, 0},
-	{"db_free_result",	(cmd_function)perlvdb_db_free_result, 2, 0, 0, 0},
+	{"db_bind_api",    (cmd_function)db_perlvdb_bind_api,    0, 0, 0, 0},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -75,10 +70,32 @@ struct module_exports exports = {
 
 static int mod_init(void)
 {
-	if (!module_loaded("perl")) {
-		LM_CRIT("perl module not loaded. Exiting.\n");
+	if (!module_loaded("app_perl")) {
+		LM_CRIT("app_perl module not loaded. Exiting.\n");
 		return -1;
 	}
 
 	return 0;
 }
+
+static int db_perlvdb_bind_api(db_func_t *dbb)
+{
+	if(dbb==NULL)
+		return -1;
+
+	memset(dbb, 0, sizeof(db_func_t));
+
+	dbb->use_table        = perlvdb_use_table;
+	dbb->init             = perlvdb_db_init;
+	dbb->close            = perlvdb_db_close;
+	dbb->query            = perlvdb_db_query;
+	dbb->fetch_result     = 0;
+	dbb->raw_query        = 0;
+	dbb->free_result      = perlvdb_db_free_result;
+	dbb->insert           = perlvdb_db_insert;
+	dbb->delete           = perlvdb_db_delete; 
+	dbb->update           = perlvdb_db_update;
+	dbb->replace          = 0;
+
+	return 0;
+}
\ No newline at end of file
diff --git a/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml b/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
index 1246815..87ca9b5 100644
--- a/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
+++ b/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
@@ -31,7 +31,7 @@
 		operations is supported.
 	</para>
 	<para>
-		Modules can be configured to use the perlvdb module as
+		Modules can be configured to use the db_perlvdb module as
 		database backend using the db_url_parameter:
 	</para>
 	<programlisting>
@@ -39,7 +39,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 </programlisting>
 	<para>
 		This configuration options tells acc module that it should use the
-		perlvdb module which will in turn use the Perl class
+		db_perlvdb module which will in turn use the Perl class
 		Kamailio::VDB::Adapter::AccountingSIPtrace
 		to relay the database requests.
 	</para>
@@ -53,7 +53,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 		The following  modules must be loaded before this module:
 			<itemizedlist>
 			<listitem>
-				<para><emphasis>perl</emphasis> -- Perl module</para>
+				<para><emphasis>app_perl</emphasis> -- Perl Application module</para>
 			</listitem>
 			</itemizedlist>
 		</para>
@@ -66,7 +66,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 			<itemizedlist>
 			<listitem>
 			<para>
-				<emphasis>None</emphasis> (Besides the ones mentioned in the perl
+				<emphasis>None</emphasis> (Besides the ones mentioned in the app_perl
 				module documentation).
 			</para>
 			</listitem>
diff --git a/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml b/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
index 286cdb3..72b71e5 100644
--- a/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
+++ b/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
@@ -30,7 +30,7 @@
 	</section>
 	<section><title>Base class Kamailio::VDB</title>
 		<para>
-			A client module has to be configured to use the perlvdb module in conjunction
+			A client module has to be configured to use the db_perlvdb module in conjunction
 			with a Perl class to provide the functions. The configured class needs to
 			inherit from the base class <literal role="code">Kamailio::VDB</literal>.
 		</para>
diff --git a/src/modules/db_perlvdb/perlvdb_conv.c b/src/modules/db_perlvdb/perlvdb_conv.c
index c3f1e68..d14b48f 100644
--- a/src/modules/db_perlvdb/perlvdb_conv.c
+++ b/src/modules/db_perlvdb/perlvdb_conv.c
@@ -33,7 +33,7 @@
 /* Converts a set of pairs to perl SVs.
  * For insert, and update (second half)
  */
-AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n) {
+AV *pairs2perlarray(const db_key_t* keys, const db_val_t* vals, const int n) {
 
 	AV *array = newAV();
 	SV *element;
@@ -50,7 +50,7 @@ AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n) {
 /* Converts a set of cond's to perl SVs.
  * For delete, update (first half), query
  */
-AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n) {
+AV *conds2perlarray(const db_key_t* keys, const db_op_t* ops, const db_val_t* vals, const int n) {
 	AV *array = newAV();
 	SV *element = NULL;
 	int i = 0;
@@ -80,7 +80,7 @@ AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n) {
 /* Converts a set of key names to a perl array.
  * Needed in query.
  */
-AV *keys2perlarray(db_key_t* keys, int n) {
+AV *keys2perlarray(const db_key_t* keys, const int n) {
 	AV *array = newAV();
 	SV *element;
 	int i;
@@ -92,7 +92,7 @@ AV *keys2perlarray(db_key_t* keys, int n) {
 	return array;
 }
 
-SV *valdata(db_val_t* val) {
+SV *valdata(const db_val_t* val) {
 	SV *data = &PL_sv_undef;
 	const char* stringval;
 
@@ -148,7 +148,7 @@ SV *valdata(db_val_t* val) {
 	return data;
 }
 
-SV *val2perlval(db_val_t* val) {
+SV *val2perlval(const db_val_t* val) {
 	SV* retval;
 	SV *class;
 
@@ -167,7 +167,7 @@ SV *val2perlval(db_val_t* val) {
 
 }
 
-SV *pair2perlpair(db_key_t key, db_val_t* val) {
+SV *pair2perlpair(const db_key_t key, const db_val_t* val) {
 	SV* retval;
 	SV *class;
 
@@ -190,7 +190,7 @@ SV *pair2perlpair(db_key_t key, db_val_t* val) {
 	
 }
 
-SV *cond2perlcond(db_key_t key, db_op_t op, db_val_t* val) {
+SV *cond2perlcond(const db_key_t key, const db_op_t op, const db_val_t* val) {
 	SV* retval;
 	SV *class;
 	
@@ -290,11 +290,9 @@ int perlresult2dbres(SV *perlres, db1_res_t **r) {
 		currentstring = SvPV(d1, len);
 		charbuf = pkg_malloc(len+1);
 		strncpy(charbuf, currentstring, len+1);
-		(*r)->col.names[i]->s = charbuf;
-		(*r)->col.names[i]->len = strlen(charbuf);
+		(*r)->col.names[i] = (db_key_t)charbuf;
 
 		SvREFCNT_dec(d1);
-
 	}
 
 	rowarrayref = perlvdb_perlmethod(perlres, PERL_VDB_ROWSMETHOD,
@@ -405,8 +403,8 @@ int perlresult2dbres(SV *perlres, db1_res_t **r) {
 	}
 
 end:
-	av_undef(colarray);
-	av_undef(rowarray);
+	if (colarray) av_undef(colarray);
+	if (rowarray) av_undef(rowarray);
 	return retval;
 error:
 	LM_CRIT("broken result set. Exiting, leaving Kamailio in unknown state.\n");
diff --git a/src/modules/db_perlvdb/perlvdb_conv.h b/src/modules/db_perlvdb/perlvdb_conv.h
index 9018305..50ad626 100644
--- a/src/modules/db_perlvdb/perlvdb_conv.h
+++ b/src/modules/db_perlvdb/perlvdb_conv.h
@@ -44,21 +44,21 @@
 /* Converts a set of pairs to perl SVs.
  * For insert, and update (second half)
  */
-AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n);
+AV *pairs2perlarray(const db_key_t* keys, const db_val_t* vals, const int n);
 
 /* Converts a set of cond's to perl SVs.
  * For delete, update (first half), query
  */
-AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n);
+AV *conds2perlarray(const db_key_t* keys, const db_op_t* ops, const db_val_t* vals, const int n);
 
 /* Converts a set of key names to a perl array.
  * Needed in query.
  */
-AV *keys2perlarray(db_key_t* keys, int n);
+AV *keys2perlarray(const db_key_t* keys, const int n);
 
-SV *val2perlval(db_val_t* val);
-SV *pair2perlpair(db_key_t key, db_val_t* val);
-SV *cond2perlcond(db_key_t key, db_op_t op, db_val_t* val);
+SV *val2perlval(const db_val_t* val);
+SV *pair2perlpair(const db_key_t key, const db_val_t* val);
+SV *cond2perlcond(const db_key_t key, const db_op_t op, const db_val_t* val);
 
 int perlresult2dbres(SV *perlres, db1_res_t **r);
 
diff --git a/src/modules/db_perlvdb/perlvdbfunc.c b/src/modules/db_perlvdb/perlvdbfunc.c
index d76d7af..c6d6513 100644
--- a/src/modules/db_perlvdb/perlvdbfunc.c
+++ b/src/modules/db_perlvdb/perlvdbfunc.c
@@ -53,10 +53,10 @@ long IV2int(SV *in) {
 /*
  * Returns the class part of the URI
  */
-char *parseurl(const char* url) {
+char *parseurl(const str* url) {
 	char *cn;
 
-	cn = strchr(url, ':') + 1;
+	cn = strchr(url->s, ':') + 1;
 	if (strlen(cn) > 0)
 		return cn;
 	else
@@ -76,7 +76,7 @@ SV *newvdbobj(const char* cn) {
 	return obj;
 }
 
-SV *getobj(db1_con_t *con) {
+SV *getobj(const db1_con_t *con) {
 	return ((SV*)CON_TAIL(con));
 }
 
@@ -105,7 +105,7 @@ int checkobj(SV* obj) {
  * Initialize database module
  * No function should be called before this
  */
-db1_con_t* perlvdb_db_init(const char* url) {
+db1_con_t* perlvdb_db_init(const str* url) {
 	db1_con_t* res;
 
 	char *cn;
@@ -179,8 +179,8 @@ void perlvdb_db_close(db1_con_t* h) {
  * v: values of the keys
  * n: number of key=value pairs
  */
-int perlvdb_db_insertreplace(db1_con_t* h, db_key_t* k, db_val_t* v,
-		int n, char *insertreplace) {
+int perlvdb_db_insertreplace(const db1_con_t* h, const db_key_t* k, const db_val_t* v,
+		const int n, char *insertreplace) {
 	AV *arr;
 	SV *arrref;
 	SV *ret;
@@ -195,14 +195,14 @@ int perlvdb_db_insertreplace(db1_con_t* h, db_key_t* k, db_val_t* v,
 	return IV2int(ret);
 }
 
-int perlvdb_db_insert(db1_con_t* h, db_key_t* k, db_val_t* v, int n) {
+int perlvdb_db_insert(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n) {
 	return perlvdb_db_insertreplace(h, k, v, n, PERL_VDB_INSERTMETHOD);
 }
 
 /*
  * Just like insert, but replace the row if it exists
  */
-int perlvdb_db_replace(db1_con_t* h, db_key_t* k, db_val_t* v, int n) {
+int perlvdb_db_replace(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n) {
 	return perlvdb_db_insertreplace(h, k, v, n, PERL_VDB_REPLACEMETHOD);
 }
 
@@ -214,8 +214,8 @@ int perlvdb_db_replace(db1_con_t* h, db_key_t* k, db_val_t* v, int n) {
  * v: values of the keys that must match
  * n: number of key=value pairs
  */
-int perlvdb_db_delete(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v,
-		int n) {
+int perlvdb_db_delete(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
+		const db_val_t* v, const int n) {
 	AV *arr;
 	SV *arrref;
 	SV *ret;
@@ -242,8 +242,9 @@ int perlvdb_db_delete(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v,
  * _n: number of key=value pairs
  * _un: number of columns to update
  */
-int perlvdb_db_update(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v,
-	      db_key_t* uk, db_val_t* uv, int n, int un) {
+int perlvdb_db_update(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
+		const db_val_t* v, const db_key_t* uk, const db_val_t* uv,
+		const int n, const int un) {
 
 	AV *condarr;
 	AV *updatearr;
@@ -280,9 +281,9 @@ int perlvdb_db_update(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v,
  * nc: number of columns to return
  * o: order by the specified column
  */
-int perlvdb_db_query(db1_con_t* h, db_key_t* k, db_op_t* op, db_val_t* v,
-			db_key_t* c, int n, int nc,
-			db_key_t o, db1_res_t** r) {
+int perlvdb_db_query(const db1_con_t* h, const db_key_t* k, const db_op_t* op,
+		const db_val_t* v, const db_key_t* c, const int n, const int nc,
+		const db_key_t o, db1_res_t** r) {
 
 
 	AV *condarr;
diff --git a/src/modules/db_perlvdb/perlvdbfunc.h b/src/modules/db_perlvdb/perlvdbfunc.h
index 65c22a3..33f392b 100644
--- a/src/modules/db_perlvdb/perlvdbfunc.h
+++ b/src/modules/db_perlvdb/perlvdbfunc.h
@@ -38,7 +38,7 @@
  * Initialize/close database module
  * No function should be called before/after this
  */
-db1_con_t* perlvdb_db_init(const char* _url);
+db1_con_t* perlvdb_db_init(const str* _url);
 void perlvdb_db_close(db1_con_t* h);
 
 /*
@@ -47,16 +47,17 @@ void perlvdb_db_close(db1_con_t* h);
  */
 int perlvdb_use_table(db1_con_t* h, const str* t);
 
-int perlvdb_db_insert(db1_con_t* h, db_key_t* k, db_val_t* v, int n);
-int perlvdb_db_replace(db1_con_t* h, db_key_t* k, db_val_t* v, int n);
-int perlvdb_db_delete(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v, int n);
-int perlvdb_db_update(db1_con_t* h, db_key_t* k, db_op_t* o, db_val_t* v,
-	      db_key_t* uk, db_val_t* uv, int n, int un);
-
-int perlvdb_db_query(db1_con_t* h, db_key_t* k, db_op_t* op, db_val_t* v,
-			db_key_t* c, int n, int nc,
-			db_key_t o, db1_res_t** r);
-
+int perlvdb_db_insert(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n);
+int perlvdb_db_replace(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n);
+int perlvdb_db_delete(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
+		const db_val_t* v, const int n);
+int perlvdb_db_update(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
+		const db_val_t* v, const db_key_t* uk, const db_val_t* uv,
+		const int n, const int un);
+
+int perlvdb_db_query(const db1_con_t* h, const db_key_t* k, const db_op_t* op,
+		const db_val_t* v, const db_key_t* c, const int n, const int nc,
+		const db_key_t o, db1_res_t** r);
 int perlvdb_db_free_result(db1_con_t* _h, db1_res_t* _r);
 
 #endif /* _PERLVDBFUNC_H */
diff --git a/src/modules/db_perlvdb/README b/src/modules/db_perlvdb/README
index ba746b7..83eca6b 100644
--- a/src/modules/db_perlvdb/README
+++ b/src/modules/db_perlvdb/README
@@ -69,12 +69,12 @@ Chapter 1. Admin Guide
    database access. Relaying of insert, update, query and delete
    operations is supported.
 
-   Modules can be configured to use the perlvdb module as database backend
+   Modules can be configured to use the db_perlvdb module as database backend
    using the db_url_parameter:
 modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 
    This configuration options tells acc module that it should use the
-   perlvdb module which will in turn use the Perl class
+   db_perlvdb module which will in turn use the Perl class
    Kamailio::VDB::Adapter::AccountingSIPtrace to relay the database
    requests.
 
@@ -86,13 +86,13 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 2.1. Kamailio Modules
 
    The following modules must be loaded before this module:
-     * perl -- Perl module
+     * app_perl -- Perl Application module
 
 2.2. External Libraries or Applications
 
    The following libraries or applications must be installed before
    running Kamailio with this module loaded:
-     * None (Besides the ones mentioned in the perl module documentation).
+     * None (Besides the ones mentioned in the app_perl module documentation).
 
 3. Parameters
 
@@ -136,7 +136,7 @@ Chapter 2. Developer Guide
 
 2. Base class Kamailio::VDB
 
-   A client module has to be configured to use the perlvdb module in
+   A client module has to be configured to use the db_perlvdb module in
    conjunction with a Perl class to provide the functions. The configured
    class needs to inherit from the base class Kamailio::VDB.
 
diff --git a/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml b/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
index 1246815..87ca9b5 100644
--- a/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
+++ b/src/modules/db_perlvdb/doc/db_perlvdb_admin.xml
@@ -31,7 +31,7 @@
 		operations is supported.
 	</para>
 	<para>
-		Modules can be configured to use the perlvdb module as
+		Modules can be configured to use the db_perlvdb module as
 		database backend using the db_url_parameter:
 	</para>
 	<programlisting>
@@ -39,7 +39,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 </programlisting>
 	<para>
 		This configuration options tells acc module that it should use the
-		perlvdb module which will in turn use the Perl class
+		db_perlvdb module which will in turn use the Perl class
 		Kamailio::VDB::Adapter::AccountingSIPtrace
 		to relay the database requests.
 	</para>
@@ -53,7 +53,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 		The following  modules must be loaded before this module:
 			<itemizedlist>
 			<listitem>
-				<para><emphasis>perl</emphasis> -- Perl module</para>
+				<para><emphasis>app_perl</emphasis> -- Perl Application module</para>
 			</listitem>
 			</itemizedlist>
 		</para>
@@ -66,7 +66,7 @@ modparam("acc", "db_url", "perlvdb:Kamailio::VDB::Adapter::AccountingSIPtrace")
 			<itemizedlist>
 			<listitem>
 			<para>
-				<emphasis>None</emphasis> (Besides the ones mentioned in the perl
+				<emphasis>None</emphasis> (Besides the ones mentioned in the app_perl
 				module documentation).
 			</para>
 			</listitem>
diff --git a/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml b/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
index b6f8e7d..5ed5b07 100644
--- a/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
+++ b/src/modules/db_perlvdb/doc/db_perlvdb_devel.xml
@@ -30,7 +30,7 @@
 	</section>
 	<section><title>Base class Kamailio::VDB</title>
 		<para>
-			A client module has to be configured to use the perlvdb module in conjunction
+			A client module has to be configured to use the db_perlvdb module in conjunction
 			with a Perl class to provide the functions. The configured class needs to
 			inherit from the base class <literal role="code">Kamailio::VDB</literal>.
 		</para>
diff --git a/src/modules/db_perlvdb/perlvdb_conv.c b/src/modules/db_perlvdb/perlvdb_conv.c
index c3f1e68..d14b48f 100644
--- a/src/modules/db_perlvdb/perlvdb_conv.c
+++ b/src/modules/db_perlvdb/perlvdb_conv.c
@@ -33,7 +33,7 @@
 /* Converts a set of pairs to perl SVs.
  * For insert, and update (second half)
  */
-AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n) {
+AV *pairs2perlarray(const db_key_t* keys, const db_val_t* vals, const int n) {
 
 	AV *array = newAV();
 	SV *element;
@@ -50,7 +50,7 @@ AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n) {
 /* Converts a set of cond's to perl SVs.
  * For delete, update (first half), query
  */
-AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n) {
+AV *conds2perlarray(const db_key_t* keys, const db_op_t* ops, const db_val_t* vals, const int n) {
 	AV *array = newAV();
 	SV *element = NULL;
 	int i = 0;
@@ -80,7 +80,7 @@ AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n) {
 /* Converts a set of key names to a perl array.
  * Needed in query.
  */
-AV *keys2perlarray(db_key_t* keys, int n) {
+AV *keys2perlarray(const db_key_t* keys, const int n) {
 	AV *array = newAV();
 	SV *element;
 	int i;
@@ -92,7 +92,7 @@ AV *keys2perlarray(db_key_t* keys, int n) {
 	return array;
 }
 
-SV *valdata(db_val_t* val) {
+SV *valdata(const db_val_t* val) {
 	SV *data = &PL_sv_undef;
 	const char* stringval;
 
@@ -148,7 +148,7 @@ SV *valdata(db_val_t* val) {
 	return data;
 }
 
-SV *val2perlval(db_val_t* val) {
+SV *val2perlval(const db_val_t* val) {
 	SV* retval;
 	SV *class;
 
@@ -167,7 +167,7 @@ SV *val2perlval(db_val_t* val) {
 
 }
 
-SV *pair2perlpair(db_key_t key, db_val_t* val) {
+SV *pair2perlpair(const db_key_t key, const db_val_t* val) {
 	SV* retval;
 	SV *class;
 
@@ -190,7 +190,7 @@ SV *pair2perlpair(db_key_t key, db_val_t* val) {
 	
 }
 
-SV *cond2perlcond(db_key_t key, db_op_t op, db_val_t* val) {
+SV *cond2perlcond(const db_key_t key, const db_op_t op, const db_val_t* val) {
 	SV* retval;
 	SV *class;
 	
@@ -290,11 +290,9 @@ int perlresult2dbres(SV *perlres, db1_res_t **r) {
 		currentstring = SvPV(d1, len);
 		charbuf = pkg_malloc(len+1);
 		strncpy(charbuf, currentstring, len+1);
-		(*r)->col.names[i]->s = charbuf;
-		(*r)->col.names[i]->len = strlen(charbuf);
+		(*r)->col.names[i] = (db_key_t)charbuf;
 
 		SvREFCNT_dec(d1);
-
 	}
 
 	rowarrayref = perlvdb_perlmethod(perlres, PERL_VDB_ROWSMETHOD,
@@ -405,8 +403,8 @@ int perlresult2dbres(SV *perlres, db1_res_t **r) {
 	}
 
 end:
-	av_undef(colarray);
-	av_undef(rowarray);
+	if (colarray) av_undef(colarray);
+	if (rowarray) av_undef(rowarray);
 	return retval;
 error:
 	LM_CRIT("broken result set. Exiting, leaving Kamailio in unknown state.\n");
diff --git a/src/modules/db_perlvdb/perlvdb_conv.h b/src/modules/db_perlvdb/perlvdb_conv.h
index 9018305..50ad626 100644
--- a/src/modules/db_perlvdb/perlvdb_conv.h
+++ b/src/modules/db_perlvdb/perlvdb_conv.h
@@ -44,21 +44,21 @@
 /* Converts a set of pairs to perl SVs.
  * For insert, and update (second half)
  */
-AV *pairs2perlarray(db_key_t* keys, db_val_t* vals, int n);
+AV *pairs2perlarray(const db_key_t* keys, const db_val_t* vals, const int n);
 
 /* Converts a set of cond's to perl SVs.
  * For delete, update (first half), query
  */
-AV *conds2perlarray(db_key_t* keys, db_op_t* ops, db_val_t* vals, int n);
+AV *conds2perlarray(const db_key_t* keys, const db_op_t* ops, const db_val_t* vals, const int n);
 
 /* Converts a set of key names to a perl array.
  * Needed in query.
  */
-AV *keys2perlarray(db_key_t* keys, int n);
+AV *keys2perlarray(const db_key_t* keys, const int n);
 
-SV *val2perlval(db_val_t* val);
-SV *pair2perlpair(db_key_t key, db_val_t* val);
-SV *cond2perlcond(db_key_t key, db_op_t op, db_val_t* val);
+SV *val2perlval(const db_val_t* val);
+SV *pair2perlpair(const db_key_t key, const db_val_t* val);
+SV *cond2perlcond(const db_key_t key, const db_op_t op, const db_val_t* val);
 
 int perlresult2dbres(SV *perlres, db1_res_t **r);
 
diff --git a/src/modules/db_perlvdb/perlvdbfunc.c b/src/modules/db_perlvdb/perlvdbfunc.c
index 73a7b1c..c6d6513 100644
--- a/src/modules/db_perlvdb/perlvdbfunc.c
+++ b/src/modules/db_perlvdb/perlvdbfunc.c
@@ -76,7 +76,7 @@ SV *newvdbobj(const char* cn) {
 	return obj;
 }
 
-SV *getobj(db1_con_t *con) {
+SV *getobj(const db1_con_t *con) {
 	return ((SV*)CON_TAIL(con));
 }
 
@@ -179,8 +179,8 @@ void perlvdb_db_close(db1_con_t* h) {
  * v: values of the keys
  * n: number of key=value pairs
  */
-int perlvdb_db_insertreplace(db1_con_t* h, db_key_t* k, db_val_t* v,
-		int n, char *insertreplace) {
+int perlvdb_db_insertreplace(const db1_con_t* h, const db_key_t* k, const db_val_t* v,
+		const int n, char *insertreplace) {
 	AV *arr;
 	SV *arrref;
 	SV *ret;
@@ -202,7 +202,7 @@ int perlvdb_db_insert(const db1_con_t* h, const db_key_t* k, const db_val_t* v,
 /*
  * Just like insert, but replace the row if it exists
  */
-int perlvdb_db_replace(db1_con_t* h, db_key_t* k, db_val_t* v, int n) {
+int perlvdb_db_replace(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n) {
 	return perlvdb_db_insertreplace(h, k, v, n, PERL_VDB_REPLACEMETHOD);
 }
 
diff --git a/src/modules/db_perlvdb/perlvdbfunc.h b/src/modules/db_perlvdb/perlvdbfunc.h
index 5c09fac..33f392b 100644
--- a/src/modules/db_perlvdb/perlvdbfunc.h
+++ b/src/modules/db_perlvdb/perlvdbfunc.h
@@ -48,7 +48,7 @@ void perlvdb_db_close(db1_con_t* h);
 int perlvdb_use_table(db1_con_t* h, const str* t);
 
 int perlvdb_db_insert(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n);
-int perlvdb_db_replace(db1_con_t* h, db_key_t* k, db_val_t* v, int n);
+int perlvdb_db_replace(const db1_con_t* h, const db_key_t* k, const db_val_t* v, const int n);
 int perlvdb_db_delete(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
 		const db_val_t* v, const int n);
 int perlvdb_db_update(const db1_con_t* h, const db_key_t* k, const db_op_t* o,
_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to