Переглянути джерело

db_perlvdb: updated code and documentation for latest db api

- GH #1525
Muhammad Shahzad 7 роки тому
батько
коміт
1a15e985de

+ 2 - 2
src/modules/db_perlvdb/db_perlvdb.c

@@ -95,7 +95,7 @@ static int db_perlvdb_bind_api(db_func_t *dbb)
 	dbb->insert           = perlvdb_db_insert;
 	dbb->delete           = perlvdb_db_delete; 
 	dbb->update           = perlvdb_db_update;
-	dbb->replace          = 0;
+	dbb->replace          = perlvdb_db_replace;
 
 	return 0;
-}
+}

+ 4 - 4
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>

+ 1 - 1
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>

+ 5 - 9
src/modules/db_perlvdb/perlvdb_conv.c

@@ -148,7 +148,7 @@ SV *valdata(const 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, const db_val_t* val) {
+SV *pair2perlpair(const db_key_t key, 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,13 +403,11 @@ 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");
 	return -1;
 }
 
-
-

+ 2 - 2
src/modules/db_perlvdb/perlvdb_conv.h

@@ -56,8 +56,8 @@ AV *conds2perlarray(const db_key_t* keys, const db_op_t* ops, const db_val_t* va
  */
 AV *keys2perlarray(const db_key_t* keys, const int n);
 
-SV *val2perlval(db_val_t* val);
-SV *pair2perlpair(db_key_t key, const 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);

+ 1 - 1
src/modules/db_perlvdb/perlvdbfunc.c

@@ -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);
 }
 

+ 1 - 1
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,