MT#12987 debian: refresh conflicted patches

Change-Id: Ide0395de8faaac173f9504509b4a12ae6c484bf0
vseva/12691
Victor Seva 11 years ago
parent 8f5a085584
commit 9deb226c4b

@ -1,6 +1,22 @@
From d03bed3fae3426b19b064129d4296a707bce1de8 Mon Sep 17 00:00:00 2001
From: Sipwise Development Team <support@sipwise.com>
Date: Wed, 20 May 2015 15:10:55 +0200
Subject: [PATCH] db_postgres-timeout
Gbp-Pq-Topic: sipwise
---
modules/db_postgres/km_dbase.c | 43 +++++++++++++++++++++++++++++++++++++++++
modules/db_postgres/km_pg_con.c | 36 ++++++++++++++++++++++++++++++++--
modules/db_postgres/pg_con.c | 38 +++++++++++++++++++++++++++++++-----
modules/db_postgres/pg_mod.c | 4 ++++
modules/db_postgres/pg_mod.h | 2 ++
5 files changed, 116 insertions(+), 7 deletions(-)
diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index 21c9cea..633959d 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/modules/db_postgres/km_dbase.c
@@ -167,6 +167,10 @@
@@ -167,6 +167,10 @@ static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
int i, retries;
ExecStatusType pqresult;
PGresult *res = NULL;
@ -11,7 +27,7 @@
if(! _con || !_s || !_s->s)
{
@@ -217,6 +221,44 @@
@@ -217,6 +221,44 @@ static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
/* exec the query */
if (PQsendQuery(CON_CONNECTION(_con), s)) {
@ -56,7 +72,7 @@
/* Get the result of the query */
while ((res = PQgetResult(CON_CONNECTION(_con))) != NULL) {
db_postgres_free_query(_con);
@@ -239,6 +281,7 @@
@@ -239,6 +281,7 @@ static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
PQerrorMessage(CON_CONNECTION(_con)));
if(PQstatus(CON_CONNECTION(_con))!=CONNECTION_OK)
{
@ -64,37 +80,92 @@
LM_DBG("reseting the connection to postgress server\n");
PQreset(CON_CONNECTION(_con));
}
--- a/modules/db_postgres/pg_mod.c
+++ b/modules/db_postgres/pg_mod.c
@@ -61,6 +61,8 @@
* 0 disables reconnecting */
diff --git a/modules/db_postgres/km_pg_con.c b/modules/db_postgres/km_pg_con.c
index 92acc75..9cac456 100644
--- a/modules/db_postgres/km_pg_con.c
+++ b/modules/db_postgres/km_pg_con.c
@@ -26,12 +26,15 @@
*/
int pg_lockset = 4;
+int pg_timeout = 0; /* default = no timeout */
+int pg_keepalive = 0;
#include "km_pg_con.h"
+#include "pg_mod.h"
#include "../../mem/mem.h"
#include "../../dprint.h"
#include "../../ut.h"
#include "../../tls_hooks_init.h"
#include <string.h>
#include <time.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
/*
* Postgres module interface
@@ -92,6 +94,8 @@
static param_export_t params[] = {
{"retries", PARAM_INT, &pg_retries },
{"lockset", PARAM_INT, &pg_lockset },
+ {"timeout", PARAM_INT, &pg_timeout },
+ {"tcp_keepalive", PARAM_INT, &pg_keepalive },
{0, 0, 0}
};
--- a/modules/db_postgres/pg_mod.h
+++ b/modules/db_postgres/pg_mod.h
@@ -41,6 +41,8 @@
*/
/*!
@@ -46,6 +49,9 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
{
struct pg_con* ptr;
char *ports;
+ int i = 0;
+ const char *keywords[10], *values[10];
+ char to[16];
extern int pg_retries;
+extern int pg_timeout;
+extern int pg_keepalive;
LM_DBG("db_id = %p\n", id);
@@ -67,6 +73,8 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
/** @} */
if (id->port) {
ports = int2str(id->port, 0);
+ keywords[i] = "port";
+ values[i++] = ports;
LM_DBG("opening connection: postgres://xxxx:xxxx@%s:%d/%s\n", ZSW(id->host),
id->port, ZSW(id->database));
} else {
@@ -75,11 +83,27 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
ZSW(id->database));
}
+ keywords[i] = "host";
+ values[i++] = id->host;
+ keywords[i] = "dbname";
+ values[i++] = id->database;
+ keywords[i] = "user";
+ values[i++] = id->username;
+ keywords[i] = "password";
+ values[i++] = id->password;
+ if (pg_timeout > 0) {
+ snprintf(to, sizeof(to)-1, "%d", pg_timeout + 3);
+ keywords[i] = "connect_timeout";
+ values[i++] = to;
+ }
+
+ keywords[i] = values[i] = NULL;
+
/* don't attempt to re-init openssl if done already */
if(tls_loaded()) PQinitSSL(0);
- ptr->con = PQsetdbLogin(id->host, ports, NULL, NULL, id->database, id->username, id->password);
- LM_DBG("PQsetdbLogin(%p)\n", ptr->con);
+ ptr->con = PQconnectdbParams(keywords, values, 1);
+ LM_DBG("PQconnectdbParams(%p)\n", ptr->con);
if( (ptr->con == 0) || (PQstatus(ptr->con) != CONNECTION_OK) )
{
@@ -92,6 +116,14 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
ptr->timestamp = time(0);
ptr->id = id;
+#if defined(SO_KEEPALIVE) && defined(TCP_KEEPIDLE)
+ if (pg_keepalive) {
+ i = 1;
+ setsockopt(PQsocket(ptr->con), SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i));
+ setsockopt(PQsocket(ptr->con), IPPROTO_TCP, TCP_KEEPIDLE, &pg_keepalive, sizeof(pg_keepalive));
+ }
+#endif
+
return ptr;
err:
diff --git a/modules/db_postgres/pg_con.c b/modules/db_postgres/pg_con.c
index 32b9be7..86c68fa 100644
--- a/modules/db_postgres/pg_con.c
+++ b/modules/db_postgres/pg_con.c
@@ -39,6 +39,7 @@
@ -113,7 +184,7 @@
#include <time.h>
@@ -237,7 +239,9 @@
@@ -237,7 +239,9 @@ int pg_con_connect(db_con_t* con)
struct pg_con* pcon;
struct pg_uri* puri;
char* port_str;
@ -124,7 +195,7 @@
pcon = DB_GET_PAYLOAD(con);
puri = DB_GET_PAYLOAD(con->uri);
@@ -251,6 +255,8 @@
@@ -251,6 +255,8 @@ int pg_con_connect(db_con_t* con)
if (puri->port > 0) {
port_str = int2str(puri->port, 0);
@ -133,7 +204,7 @@
} else {
port_str = NULL;
}
@@ -260,12 +266,26 @@
@@ -260,12 +266,26 @@ int pg_con_connect(db_con_t* con)
pcon->con = NULL;
}
@ -164,7 +235,7 @@
goto error;
}
@@ -285,6 +305,14 @@
@@ -285,6 +305,14 @@ int pg_con_connect(db_con_t* con)
PQprotocolVersion(pcon->con), 0 );
#endif
@ -179,81 +250,41 @@
ret = timestamp_format(pcon->con);
if (ret == 1 || ret == -1) {
/* Assume INT8 representation if detection fails */
--- a/modules/db_postgres/km_pg_con.c
+++ b/modules/db_postgres/km_pg_con.c
@@ -26,11 +26,14 @@
*/
#include "km_pg_con.h"
+#include "pg_mod.h"
#include "../../mem/mem.h"
#include "../../dprint.h"
#include "../../ut.h"
#include <string.h>
#include <time.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
/*!
@@ -45,6 +48,9 @@
{
struct pg_con* ptr;
char *ports;
+ int i = 0;
+ const char *keywords[10], *values[10];
+ char to[16];
diff --git a/modules/db_postgres/pg_mod.c b/modules/db_postgres/pg_mod.c
index 1b2d9f7..14f50a3 100644
--- a/modules/db_postgres/pg_mod.c
+++ b/modules/db_postgres/pg_mod.c
@@ -61,6 +61,8 @@ int pg_retries = 2; /* How many times should the module try re-execute failed c
* 0 disables reconnecting */
LM_DBG("db_id = %p\n", id);
@@ -66,6 +72,8 @@
int pg_lockset = 4;
+int pg_timeout = 0; /* default = no timeout */
+int pg_keepalive = 0;
if (id->port) {
ports = int2str(id->port, 0);
+ keywords[i] = "port";
+ values[i++] = ports;
LM_DBG("opening connection: postgres://xxxx:xxxx@%s:%d/%s\n", ZSW(id->host),
id->port, ZSW(id->database));
} else {
@@ -74,8 +82,24 @@
ZSW(id->database));
}
/*
* Postgres module interface
@@ -92,6 +94,8 @@ static cmd_export_t cmds[] = {
static param_export_t params[] = {
{"retries", PARAM_INT, &pg_retries },
{"lockset", PARAM_INT, &pg_lockset },
+ {"timeout", PARAM_INT, &pg_timeout },
+ {"tcp_keepalive", PARAM_INT, &pg_keepalive },
{0, 0, 0}
};
- ptr->con = PQsetdbLogin(id->host, ports, NULL, NULL, id->database, id->username, id->password);
- LM_DBG("PQsetdbLogin(%p)\n", ptr->con);
+ keywords[i] = "host";
+ values[i++] = id->host;
+ keywords[i] = "dbname";
+ values[i++] = id->database;
+ keywords[i] = "user";
+ values[i++] = id->username;
+ keywords[i] = "password";
+ values[i++] = id->password;
+ if (pg_timeout > 0) {
+ snprintf(to, sizeof(to)-1, "%d", pg_timeout + 3);
+ keywords[i] = "connect_timeout";
+ values[i++] = to;
+ }
+
+ keywords[i] = values[i] = NULL;
+
+ ptr->con = PQconnectdbParams(keywords, values, 1);
+ LM_DBG("PQconnectdbParams(%p)\n", ptr->con);
diff --git a/modules/db_postgres/pg_mod.h b/modules/db_postgres/pg_mod.h
index 10c0535..194c7df 100644
--- a/modules/db_postgres/pg_mod.h
+++ b/modules/db_postgres/pg_mod.h
@@ -41,6 +41,8 @@
*/
if( (ptr->con == 0) || (PQstatus(ptr->con) != CONNECTION_OK) )
{
@@ -88,6 +112,14 @@
ptr->timestamp = time(0);
ptr->id = id;
extern int pg_retries;
+extern int pg_timeout;
+extern int pg_keepalive;
+#if defined(SO_KEEPALIVE) && defined(TCP_KEEPIDLE)
+ if (pg_keepalive) {
+ i = 1;
+ setsockopt(PQsocket(ptr->con), SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i));
+ setsockopt(PQsocket(ptr->con), IPPROTO_TCP, TCP_KEEPIDLE, &pg_keepalive, sizeof(pg_keepalive));
+ }
+#endif
+
return ptr;
/** @} */
err:
--
2.1.4

@ -1,8 +1,9 @@
From f771ee9d5b0bdcefa78683c09b10b631da145f68 Mon Sep 17 00:00:00 2001
From 65bb8e9ee21b81d8b09f58f5a768f94fcc0ee92d Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Mon, 12 May 2014 15:42:48 +0200
Subject: [PATCH] dialplan: pv in match and subst
Gbp-Pq-Topic: sipwise
---
modules/dialplan/dialplan.c | 5 +
modules/dialplan/dialplan.h | 37 +++-
@ -11,9 +12,11 @@ Subject: [PATCH] dialplan: pv in match and subst
modules/dialplan/dp_repl.c | 189 +++++++++++++++++++-
5 files changed, 622 insertions(+), 36 deletions(-)
diff --git a/modules/dialplan/dialplan.c b/modules/dialplan/dialplan.c
index 07c3271..0ee0e24 100644
--- a/modules/dialplan/dialplan.c
+++ b/modules/dialplan/dialplan.c
@@ -207,6 +207,11 @@
@@ -207,6 +207,11 @@ static int mod_init(void)
static int child_init(int rank)
{
@ -25,6 +28,8 @@ Subject: [PATCH] dialplan: pv in match and subst
return 0;
}
diff --git a/modules/dialplan/dialplan.h b/modules/dialplan/dialplan.h
index fd3319e..b506853 100644
--- a/modules/dialplan/dialplan.h
+++ b/modules/dialplan/dialplan.h
@@ -44,6 +44,15 @@
@ -43,7 +48,7 @@ Subject: [PATCH] dialplan: pv in match and subst
#define MAX_REPLACE_WITH 10
typedef struct dpl_node{
@@ -55,6 +64,7 @@
@@ -55,6 +64,7 @@ typedef struct dpl_node{
pcre *match_comp, *subst_comp; /*compiled patterns*/
struct subst_expr * repl_comp;
str attrs;
@ -51,7 +56,7 @@ Subject: [PATCH] dialplan: pv in match and subst
struct dpl_node * next; /*next rule*/
}dpl_node_t, *dpl_node_p;
@@ -75,6 +85,30 @@
@@ -75,6 +85,30 @@ typedef struct dpl_id{
struct dpl_id * next;
}dpl_id_t,*dpl_id_p;
@ -82,7 +87,7 @@ Subject: [PATCH] dialplan: pv in match and subst
#define DP_VAL_INT 0
#define DP_VAL_SPEC 1
@@ -92,9 +126,10 @@
@@ -92,9 +126,10 @@ void destroy_data();
int dp_load_db();
dpl_id_p select_dpid(int id);
@ -94,9 +99,11 @@ Subject: [PATCH] dialplan: pv in match and subst
-int rule_translate(struct sip_msg *msg, str , dpl_node_t * rule, str *);
+int rule_translate(struct sip_msg *msg, str , dpl_node_t * rule, dpl_pv_node_t * rule_pv, str *);
#endif
diff --git a/modules/dialplan/dp_db.c b/modules/dialplan/dp_db.c
index 70d37a3..d129748 100644
--- a/modules/dialplan/dp_db.c
+++ b/modules/dialplan/dp_db.c
@@ -70,6 +70,9 @@
@@ -70,6 +70,9 @@ static db_func_t dp_dbf;
(_res).len = strlen(VAL_STR((_values)+ (_index)).s);\
}while(0);
@ -106,7 +113,7 @@ Subject: [PATCH] dialplan: pv in match and subst
void destroy_rule(dpl_node_t * rule);
void destroy_hash(int);
@@ -78,12 +81,16 @@
@@ -78,12 +81,16 @@ int add_rule2hash(dpl_node_t *, int);
void list_rule(dpl_node_t * );
void list_hash(int h_index);
@ -125,7 +132,7 @@ Subject: [PATCH] dialplan: pv in match and subst
int init_db_data(void)
{
@@ -163,14 +170,15 @@
@@ -163,14 +170,15 @@ int init_data(void)
}
rules_hash[0] = rules_hash[1] = 0;
@ -143,7 +150,7 @@ Subject: [PATCH] dialplan: pv in match and subst
LM_DBG("trying to initialize data from db\n");
if(init_db_data() != 0)
@@ -193,6 +201,23 @@
@@ -193,6 +201,23 @@ void destroy_data(void)
shm_free(crt_idx);
}
@ -167,7 +174,7 @@ Subject: [PATCH] dialplan: pv in match and subst
/*load rules from DB*/
int dp_load_db(void)
@@ -283,6 +308,8 @@
@@ -283,6 +308,8 @@ end:
*crt_idx = *next_idx;
list_hash(*crt_idx);
dp_dbf.free_result(dp_db_handle, res);
@ -176,7 +183,7 @@ Subject: [PATCH] dialplan: pv in match and subst
return 0;
err2:
@@ -352,6 +379,84 @@
@@ -352,6 +379,84 @@ static pcre *reg_ex_comp(const char *pattern, int *cap_cnt)
return result;
}
@ -261,7 +268,7 @@ Subject: [PATCH] dialplan: pv in match and subst
/*compile the expressions, and if ok, build the rule */
dpl_node_t * build_rule(db_val_t * values)
@@ -359,9 +464,10 @@
@@ -359,9 +464,10 @@ dpl_node_t * build_rule(db_val_t * values)
pcre *match_comp, *subst_comp;
struct subst_expr *repl_comp;
dpl_node_t * new_rule;
@ -273,7 +280,7 @@ Subject: [PATCH] dialplan: pv in match and subst
matchop = VAL_INT(values+2);
@@ -377,11 +483,21 @@
@@ -377,11 +483,21 @@ dpl_node_t * build_rule(db_val_t * values)
GET_STR_VALUE(match_exp, values, 3);
if(matchop == DP_REGEX_OP){
@ -300,7 +307,7 @@ Subject: [PATCH] dialplan: pv in match and subst
}
}
@@ -398,26 +514,38 @@
@@ -397,29 +513,41 @@ dpl_node_t * build_rule(db_val_t * values)
GET_STR_VALUE(subst_exp, values, 5);
if(subst_exp.s && subst_exp.len){
@ -336,6 +343,9 @@ Subject: [PATCH] dialplan: pv in match and subst
}
}
LM_DBG("building rule for [%d:%.*s/%.*s/%.*s]\n", matchop,
match_exp.len, ZSW(match_exp.s), subst_exp.len, ZSW(subst_exp.s),
repl_exp.len, ZSW(repl_exp.s));
- if (repl_comp && (cap_cnt < repl_comp->max_pmatch) &&
- (repl_comp->max_pmatch != 0)) {
- LM_ERR("repl_exp %.*s refers to %d sub-expressions, but "
@ -355,7 +365,7 @@ Subject: [PATCH] dialplan: pv in match and subst
}
new_rule = (dpl_node_t *)shm_malloc(sizeof(dpl_node_t));
@@ -450,6 +578,7 @@
@@ -452,6 +580,7 @@ dpl_node_t * build_rule(db_val_t * values)
new_rule->match_comp = match_comp;
new_rule->subst_comp = subst_comp;
new_rule->repl_comp = repl_comp;
@ -363,7 +373,7 @@ Subject: [PATCH] dialplan: pv in match and subst
return new_rule;
@@ -550,6 +679,85 @@
@@ -552,6 +681,85 @@ err:
return -1;
}
@ -449,7 +459,7 @@ Subject: [PATCH] dialplan: pv in match and subst
void destroy_hash(int index)
{
@@ -589,6 +797,114 @@
@@ -591,6 +799,114 @@ void destroy_hash(int index)
rules_hash[index] = 0;
}
@ -564,7 +574,7 @@ Subject: [PATCH] dialplan: pv in match and subst
void destroy_rule(dpl_node_t * rule){
@@ -619,6 +935,8 @@
@@ -621,6 +937,8 @@ void destroy_rule(dpl_node_t * rule){
if(rule->attrs.s)
shm_free(rule->attrs.s);
@ -573,7 +583,7 @@ Subject: [PATCH] dialplan: pv in match and subst
}
@@ -636,6 +954,25 @@
@@ -638,6 +956,25 @@ dpl_id_p select_dpid(int id)
return NULL;
}
@ -599,7 +609,7 @@ Subject: [PATCH] dialplan: pv in match and subst
/*FOR DEBUG PURPOSE*/
void list_hash(int h_index)
@@ -672,3 +1009,40 @@
@@ -674,3 +1011,40 @@ void list_rule(dpl_node_t * rule)
rule->attrs.len, rule->attrs.s);
}
@ -640,9 +650,11 @@ Subject: [PATCH] dialplan: pv in match and subst
+ if(flag&DP_PV_MASK) LM_DBG("DP_PV_MASK\n");
+ LM_DBG("--pv_flags:%d\n", flag);
+}
diff --git a/modules/dialplan/dp_db.h b/modules/dialplan/dp_db.h
index 0078354..9130718 100644
--- a/modules/dialplan/dp_db.h
+++ b/modules/dialplan/dp_db.h
@@ -63,6 +63,7 @@
@@ -63,6 +63,7 @@ extern str repl_exp_column;
extern str attrs_column;
int init_db_data();
@ -650,9 +662,11 @@ Subject: [PATCH] dialplan: pv in match and subst
int dp_connect_db();
void dp_disconnect_db();
diff --git a/modules/dialplan/dp_repl.c b/modules/dialplan/dp_repl.c
index ec2e5bb..2a53be4 100644
--- a/modules/dialplan/dp_repl.c
+++ b/modules/dialplan/dp_repl.c
@@ -127,13 +127,14 @@
@@ -127,13 +127,14 @@ error:
#define MAX_PHONE_NB_DIGITS 127
static char dp_output_buf[MAX_PHONE_NB_DIGITS+1];
int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
@ -668,7 +682,7 @@ Subject: [PATCH] dialplan: pv in match and subst
pv_value_t sv;
str* uri;
int ovector[3 * (MAX_REPLACE_WITH + 1)];
@@ -144,7 +145,25 @@
@@ -144,7 +145,25 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
result->s = dp_output_buf;
result->len = 0;
@ -695,7 +709,7 @@ Subject: [PATCH] dialplan: pv in match and subst
repl_comp = rule->repl_comp;
if(!repl_comp){
@@ -168,13 +187,13 @@
@@ -168,13 +187,13 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
}
/*search for the pattern from the compiled subst_exp*/
@ -712,7 +726,7 @@ Subject: [PATCH] dialplan: pv in match and subst
return -1;
}
}
@@ -308,13 +327,141 @@
@@ -308,13 +327,141 @@ error:
return -1;
}
@ -854,7 +868,7 @@ Subject: [PATCH] dialplan: pv in match and subst
int user_len, rez;
char b;
@@ -339,7 +486,27 @@
@@ -339,7 +486,27 @@ search_rule:
case DP_REGEX_OP:
LM_DBG("regex operator testing\n");
@ -883,7 +897,7 @@ Subject: [PATCH] dialplan: pv in match and subst
0, 0, NULL, 0);
break;
@@ -382,8 +549,9 @@
@@ -382,8 +549,9 @@ search_rule:
return -1;
repl:
@ -895,7 +909,7 @@ Subject: [PATCH] dialplan: pv in match and subst
if(attrs) {
attrs->len = 0;
@@ -405,7 +573,10 @@
@@ -405,7 +573,10 @@ repl:
}
}
@ -907,3 +921,6 @@ Subject: [PATCH] dialplan: pv in match and subst
LM_ERR("could not build the output\n");
return -1;
}
--
2.1.4

Loading…
Cancel
Save