Module: sip-router
Branch: janakj/mysql
Commit: 956802dcd657e128f94c064d24f45dc918e9d2a9
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=956802d…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Feb 16 23:09:32 2009 +0100
db_con renamed to db1_con in files originating from kamailio/db_mysql.
The structure db_con has been renamed in lib/srdb1 to db1_con, thus we
need to change the name of the structure in all files originating from
kamailio/modules/db_mysql (and using lib/srdb1).
---
modules/db_mysql/km_dbase.c | 30 +++++++++++++++---------------
modules/db_mysql/km_dbase.h | 26 +++++++++++++-------------
modules/db_mysql/km_res.c | 6 +++---
modules/db_mysql/km_res.h | 4 ++--
modules/db_mysql/km_row.c | 2 +-
modules/db_mysql/km_row.h | 2 +-
modules/db_mysql/km_val.c | 2 +-
modules/db_mysql/km_val.h | 2 +-
8 files changed, 37 insertions(+), 37 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=956…
Module: sip-router
Branch: janakj/mysql
Commit: 0ba587f8e2d3d718f92ed111202657cdfa9a58ff
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0ba587f…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Feb 16 21:54:06 2009 +0100
Merge of kamaililo db_mysql module history into the sip-router tree.
This is a merge of the full history of the kamailio db_mysql module into the
git tree of the sip-router project. The purpose of the merge is to preserve
full history from kamailio svn also in the git repository.
The module db_mysql already exists in the sip-router tree, it contains the
sources merged from SER cvs (so called version 2 of the module). To avoid file
conflicts we renamed all files that have been imported from kamailio svn and
they are prefixed with km_.
Further integration with existing db_mysql module will be commited on top of
this merge.
* my_filtered: (45 commits)
- fixed auto_reconnect c&p error
- add one DBG log to each drivers error condition, that the mem is freed
- fix one DBG msg (still using module prefix), two small indention fixes
- partial revert of commit rev5359 for db_mysql module
- add group functionality to read content from specified sections
- unify common rows and row allocation functionality in the DB API core
- change behaviour of db_str2val, this now copy strings
- move db_mysql and db_unixodbc str2val implementation to the DB core,
- fix a few errors in doxygen documentation
- add a comment about the NULL value behaviour of libmysql
- docs extension: explain fetch_result functionality better to prevent errors
- remove not reached return statement at the end of val2str functions
- initial support for BIGINT database in DB core and SQL based database
- evaluate DECIMAL (and NEW_DECIMAL) type a DB_STRING, and not DB_INT
- fixed compile error - MYSQL_TYPE_NEWDECIMAL date type is supported
- fix link entity names, patch from Carsten Gross
- port from opensips r4526, credits goes to bogdan
- regenerated all READMEs (make modules-readme exclude_modules="")
- renaming: changed entities in documentation
- renaming: openser -> kamailio
...
---
Module: sip-router
Branch: janakj/mysql
Commit: d26ebfbb0c1a2c000fd57e2c9eec93e89a4a12cd
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d26ebfb…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Wed Jan 7 14:46:10 2009 +0000
- add one DBG log to each drivers error condition, that the mem is freed
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5431 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_dbase.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index ecc3106..ed79a17 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -178,6 +178,7 @@ static int db_mysql_store_result(const db_con_t* _h, db_res_t** _r)
if (db_mysql_convert_result(_h, *_r) < 0) {
LM_ERR("error while converting result\n");
+ LM_DBG("freeing result set at %p\n", _r);
pkg_free(*_r);
*_r = 0;
/* all mem on openser API side is already freed by
Module: sip-router
Branch: janakj/mysql
Commit: 89215f17a700df083e99f16e58becb3d2ab28f0b
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=89215f1…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Mon Jan 5 12:27:49 2009 +0000
- add group functionality to read content from specified sections
of the mysql config to the db_mysql module, db_url examples:
* mysql://user:pass@[group]host:port/db or
* mysql://user:pass@[group]/db or
* mysql://[group]/db
- existing functionality is not changed, this is backward compatible
- check usernames for NULL before comparing in DB API, otherwise
it would segfault when only a group name is specified
- patch from Andreas Granig, agranig at sipwise dot com, closes #1815631
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5413 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_README | 51 ++++++++++++++++++++++++++
modules/db_mysql/km_doc/db_mysql_admin.xml | 54 ++++++++++++++++++++++++++++
modules/db_mysql/km_my_con.c | 28 ++++++++++++--
3 files changed, 129 insertions(+), 4 deletions(-)
diff --git a/modules/db_mysql/km_README b/modules/db_mysql/km_README
index 54951d1..eb7693c 100644
--- a/modules/db_mysql/km_README
+++ b/modules/db_mysql/km_README
@@ -34,12 +34,16 @@ Daniel-Constantin Mierla
1.4. Exported Functions
1.5. Installation
+ 1.6. Reading configuration from my.cnf
List of Examples
1.1. Set ping_interval parameter
1.2. Set timeout_interval parameter
1.3. Set auto_reconnect parameter
+ 1.4. Set a my.cnf group in db_url parameter
+ 1.5. Adding a kamailio group to my.cnf
+ 1.6. Using [client] and specific group
Chapter 1. Admin Guide
@@ -121,3 +125,50 @@ modparam("auto_reconnect", "auto_reconnect", 0)
* - from command line use: 'make all
include_modules="db_mysql"; make install
include_modules="db_mysql"'.
+
+1.6. Reading configuration from my.cnf
+
+ In order to take into account specific mysql client options, a
+ my.cnf config group can be passed using the db_url module
+ parameter. This is done by setting [group] in front of or
+ instead of the host part. The following examples are valid
+ db_url definitions, which include a my.cnf group:
+ * mysql://user:pass@[group]host:port/db
+ * mysql://user:pass@[group]:port/db
+ * mysql://user:pass@[group]/db
+ * mysql://[group]/db
+
+ Example 1.4. Set a my.cnf group in db_url parameter
+...
+modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
+...
+
+ Example 1.5. Adding a kamailio group to my.cnf
+...
+[kamailio]
+socket = /path/to/mysql.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+
+ In addition to the given group, also the [client] section is
+ read, in the order given in my.cnf. So if you for example
+ specify a socket in both your specific group and the client
+ group, then the value is taken from the last one.
+
+ Example 1.6. Using [client] and specific group
+...
+[client]
+socket = /var/run/mysql/mysqld.sock
+
+[kamailio]
+socket = /path/to/mysqld.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+
+ In the example given above, the socket /path/to/mysqld.sock is
+ used by Kamailio because both [kamailio] and [client] define
+ this option, and the latter overwrites the first.
diff --git a/modules/db_mysql/km_doc/db_mysql_admin.xml b/modules/db_mysql/km_doc/db_mysql_admin.xml
index 31079e0..a484d02 100644
--- a/modules/db_mysql/km_doc/db_mysql_admin.xml
+++ b/modules/db_mysql/km_doc/db_mysql_admin.xml
@@ -140,5 +140,59 @@ modparam("auto_reconnect", "auto_reconnect", 0)
</listitem>
</itemizedlist>
</section>
+ <section>
+ <title>Reading configuration from my.cnf</title>
+ <para>
+ In order to take into account specific mysql client options, a my.cnf config group can be passed using the <emphasis>db_url</emphasis> module parameter. This is done by setting <emphasis>[group]</emphasis> in front of or instead of the host part. The following examples are valid <emphasis>db_url</emphasis> definitions, which include a my.cnf group:
+ </para>
+
+ <itemizedlist>
+ <listitem>mysql://user:pass@[group]host:port/db</listitem>
+ <listitem>mysql://user:pass@[group]:port/db</listitem>
+ <listitem>mysql://user:pass@[group]/db</listitem>
+ <listitem>mysql://[group]/db</listitem>
+ </itemizedlist>
+ <example>
+ <title>Set a my.cnf group in <varname>db_url</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
+...
+</programlisting>
+ </example>
+ <example>
+ <title>Adding a kamailio group to my.cnf</title>
+ <programlisting format="linespecific">
+...
+[kamailio]
+socket = /path/to/mysql.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+</programlisting>
+ </example>
+ <para>
+ In addition to the given group, also the <emphasis>[client]</emphasis> section is read, in the order given in my.cnf. So if you for example specify a <emphasis>socket</emphasis> in both your specific group and the client group, then the value is taken from the last one.
+ </para>
+ <example>
+ <title>Using [client] and specific group</title>
+ <programlisting format="linespecific">
+...
+[client]
+socket = /var/run/mysql/mysqld.sock
+
+[kamailio]
+socket = /path/to/mysqld.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+</programlisting>
+ </example>
+ <para>
+ In the example given above, the socket <emphasis>/path/to/mysqld.sock</emphasis> is used by &kamailio; because both <emphasis>[kamailio]</emphasis> and <emphasis>[client]</emphasis> define this option, and the latter overwrites the first.
+ </para>
+ </section>
</chapter>
diff --git a/modules/db_mysql/km_my_con.c b/modules/db_mysql/km_my_con.c
index 1a907b9..b5ec56a 100644
--- a/modules/db_mysql/km_my_con.c
+++ b/modules/db_mysql/km_my_con.c
@@ -43,6 +43,7 @@
struct my_con* db_mysql_new_connection(const struct db_id* id)
{
struct my_con* ptr;
+ char *host, *grp;
if (!id) {
LM_ERR("invalid parameter value\n");
@@ -66,11 +67,30 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
mysql_init(ptr->con);
+ if (id->host[0] == '[' && (host = strchr(id->host, ']')) != NULL) {
+ grp = id->host + 1;
+ *host = '\0';
+ if (host != id->host + strlen(id->host)-1) {
+ host += 1; // host found after closing bracket
+ }
+ else {
+ // let mysql read host info from my.cnf
+ // (defaults to "localhost")
+ host = NULL;
+ }
+ // read [client] and [<grp>] sections in the order
+ // given in my.cnf
+ mysql_options(ptr->con, MYSQL_READ_DEFAULT_GROUP, grp);
+ }
+ else {
+ host = id->host;
+ }
+
if (id->port) {
- LM_DBG("opening connection: mysql://xxxx:xxxx@%s:%d/%s\n", ZSW(id->host),
+ LM_DBG("opening connection: mysql://xxxx:xxxx@%s:%d/%s\n", ZSW(host),
id->port, ZSW(id->database));
} else {
- LM_DBG("opening connection: mysql://xxxx:xxxx@%s/%s\n", ZSW(id->host),
+ LM_DBG("opening connection: mysql://xxxx:xxxx@%s/%s\n", ZSW(host),
ZSW(id->database));
}
@@ -80,10 +100,10 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&db_mysql_timeout_interval);
#if (MYSQL_VERSION_ID >= 40100)
- if (!mysql_real_connect(ptr->con, id->host, id->username, id->password,
+ if (!mysql_real_connect(ptr->con, host, id->username, id->password,
id->database, id->port, 0, CLIENT_MULTI_STATEMENTS)) {
#else
- if (!mysql_real_connect(ptr->con, id->host, id->username, id->password,
+ if (!mysql_real_connect(ptr->con, host, id->username, id->password,
id->database, id->port, 0, 0)) {
#endif
LM_ERR("driver error: %s\n", mysql_error(ptr->con));