[sr-dev] git:master:46e04c65: influxdbc: initial doc files

2024-01-31 Thread Daniel-Constantin Mierla via sr-dev
Module: kamailio
Branch: master
Commit: 46e04c65dfa07ada122ad2132e9a7a841bc1e8ea
URL: 
https://github.com/kamailio/kamailio/commit/46e04c65dfa07ada122ad2132e9a7a841bc1e8ea

Author: Daniel-Constantin Mierla 
Committer: Daniel-Constantin Mierla 
Date: 2024-02-01T08:08:23+01:00

influxdbc: initial doc files

---

Added: src/modules/influxdbc/README
Added: src/modules/influxdbc/doc/Makefile
Added: src/modules/influxdbc/doc/influxdbc.xml
Added: src/modules/influxdbc/doc/influxdbc_admin.xml

---

Diff:  
https://github.com/kamailio/kamailio/commit/46e04c65dfa07ada122ad2132e9a7a841bc1e8ea.diff
Patch: 
https://github.com/kamailio/kamailio/commit/46e04c65dfa07ada122ad2132e9a7a841bc1e8ea.patch

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:dc693058: influxdbc: new module - client connector for influxdb

2024-01-31 Thread Daniel-Constantin Mierla via sr-dev
Module: kamailio
Branch: master
Commit: dc6930581ab21df13c086fdb6f69130adf0e00f2
URL: 
https://github.com/kamailio/kamailio/commit/dc6930581ab21df13c086fdb6f69130adf0e00f2

Author: Daniel-Constantin Mierla 
Committer: Daniel-Constantin Mierla 
Date: 2024-01-31T17:57:19+01:00

influxdbc: new module - client connector for influxdb

---

Added: src/modules/influxdbc/Makefile
Added: src/modules/influxdbc/ic.c
Added: src/modules/influxdbc/ic.h
Added: src/modules/influxdbc/influxdbc_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/dc6930581ab21df13c086fdb6f69130adf0e00f2.diff
Patch: 
https://github.com/kamailio/kamailio/commit/dc6930581ab21df13c086fdb6f69130adf0e00f2.patch

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] 5.7 db modules: init libssl in a thread (PR #3740)

2024-01-31 Thread Henning Westerholt via sr-dev
Thanks for the PR. It adds a new core implementation, which are usually not 
introduced in stable releases. As most people are not using databases with SSL, 
I am not sure if we really need to introduce this in the stable branch. We 
already got some regressions (e.g. #3737) in the TLS module in the stable 
branch from this type of changes. Lets see what other developers think about it.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3740#issuecomment-1920638330
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] [kamailio/kamailio] 5.7 db modules: init libssl in a thread (PR #3740)

2024-01-31 Thread space88man via sr-dev
 Pre-Submission Checklist



- [X] Commit message has the format required by CONTRIBUTING guide
- [X] Commits are split per component (core, individual modules, libs, utils, 
...)
- [X] Each component has a single commit (if not, squash them into one commit)
- [X] No commits to README files for modules (changes must be done to docbook 
files
in `doc/` subfolder, the README file is autogenerated)

 Type Of Change
- [X] Small bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds new functionality)
- [ ] Breaking change (fix or feature that would change existing functionality)

 Checklist:

- [ ] PR should be backported to stable branches
- [x] Tested changes locally
- [ X] Related to issue #3738 (replace  with an open issue number)

 Description
5.7.4 has OpenSSL fixes for tls and outbound but missed out the db modules—the 
most common users of libssl

This PR updates db_mysql, db_unixodbc, db_postgres to init libssl in a thread 
to handle more configurations (tls + db module)



You can view, comment on, or merge this pull request online at:

  https://github.com/kamailio/kamailio/pull/3740

-- Commit Summary --

  * core: backport OpenSSL thread-local fixes
  * db_mysql: backport OpenSSL thread-local fixes
  * db_postgres: backport OpenSSL thread-local fixes
  * db_unixodbc: backport OpenSSL thread-local fixes

-- File Changes --

A src/core/rthreads.h (100)
M src/modules/db_mysql/km_dbase.c (9)
M src/modules/db_postgres/km_dbase.c (19)
M src/modules/db_unixodbc/dbase.c (11)

-- Patch Links --

https://github.com/kamailio/kamailio/pull/3740.patch
https://github.com/kamailio/kamailio/pull/3740.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3740
You are receiving this because you are subscribed to this thread.

Message ID: 
___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] db modules: init libssl in a thread (PR #3739)

2024-01-31 Thread space88man via sr-dev
Closed #3739.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3739#event-11663561073
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] db modules: init libssl in a thread (PR #3739)

2024-01-31 Thread space88man via sr-dev
Reopened #3739.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3739#event-11663560219
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] db modules: init libssl in a thread (PR #3739)

2024-01-31 Thread space88man via sr-dev
Closed #3739.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3739#event-11663554483
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] [kamailio/kamailio] thread-local: database module fixes need to be back-ported to 5.7 (Issue #3738)

2024-01-31 Thread space88man via sr-dev
### Description

OpenSSL integration update was back-ported to 5.7 fixing tls and outbound.

The commonly used modules db_mysql, db_unixodbc, db_postgres - fixed on master 
- did not receive thread-local fixes in time for 5.7.4.

Kamailio configurations with tls +(database module) may see shm errors

Some database modules are observed to initialise OpenSSL even if  the actual db 
connections are in clear.

### Troubleshooting

- run the main kamailio process under gdb.
- set breakpoint on CRYPTO_THREAD_set_local (an OpenSSL internal thread-local 
function)
- observe if any calls happen in Thread#1—this is the failure case


### Workaround 

When combining tls + database module switch to tls_wolfssl instead


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3738
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] TLS Module Regression (ee key too small) (Issue #3737)

2024-01-31 Thread space88man via sr-dev
Can you generate a test key pair / cert that exhibits the same behaviour and 
paste them here. 


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3737#issuecomment-1920283576
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] Dispatcher: added two new flags to mode parameter of ds_is_from_list function for more strictly matching (PR #3699)

2024-01-31 Thread Dennis via sr-dev
> Your last comment does not clarify if a destination record matching (ip, 
> socket) has to be selected over one that matches (ip, port, proto). Can you 
> present the order of selection based on matching the values for ip, port, 
> proto or socket?

The strictness are defined by the flags combination:

#define DS_MATCHED_ADDR 1
#define DS_MATCHED_PORT (1 << 1)
#define DS_MATCHED_PROTO (1 << 2)
#define DS_MATCHED_SOCK (1 << 3)

in each iteration global variable ds_strictness are "OR-ed" with corresponding 
flag by criteria of matching, the winner is that which have the greatest value, 
for example if we have:

##ip, port, protocol
70 sip:192.168.1.1:5060;transport=udp 0 1 route=route1
#ip and socket
90 sip:192.168.1.1 0 1 route=route2;sockname=udp_5060

in first case we have flags: DS_MATCHED_ADDR | DS_MATCHED_PORT | 
DS_MATCHED_PROTO (7)
in second: MATCHED_ADDR | DS_MATCHED_SOCK (9)

The winner will be second, in this case 90.


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3699#issuecomment-1919401498
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] [kamailio/kamailio] TLS Module Regression (ee key too small) (Issue #3737)

2024-01-31 Thread Tyler Moore via sr-dev
### Description

The TLS module seems to have some regression from 5.7.3 to 5.7.4 causing 
`tls.reload` to fail loading certificates.

### Troubleshooting

 System Info

- kamailio version: 5.7.4 (from official kamailio repos)
- distro version: debian 12
- OS/kernel version: Linux ip-172-31-30-183 6.1.0-17-cloud-amd64 #1 SMP 
PREEMPT_DYNAMIC Debian 6.1.69-1 (2023-12-30) x86_64 GNU/Linux
- openssl version: 3.0.11 (from official debian repos)

 Reproduction

On a fresh install of debian 12:
- install openssl from debian repos
- install kamailio 5.7.4 from kamailio repos
- install kamailio-tls-modules from kamailio repos
- create a self signed cert with 4096 bit rsa key
- create a basic tls.cfg to load those files on the client/server default domain
- reload kamailio
- try running `kamcmd tls.reload`

 Debugging Data

Example tls.cfg

```
[server:default]
method = TLSv1.2+
verify_certificate = yes
require_certificate = yes
private_key = /etc/dsiprouter/certs/dsiprouter-key.pem
certificate = /etc/dsiprouter/certs/dsiprouter-cert.pem
ca_list = /etc/dsiprouter/certs/ca-list.pem
ca_path = /etc/dsiprouter/certs/ca

[client:default]
method = TLSv1.2+
verify_certificate = yes
require_certificate = yes
private_key = /etc/dsiprouter/certs/dsiprouter-key.pem
certificate = /etc/dsiprouter/certs/dsiprouter-cert.pem
ca_list = /etc/dsiprouter/certs/ca-list.pem
ca_path = /etc/dsiprouter/certs/ca
```

Example tls cert:

```
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
7a:43:b8:fa:df:c9:ed:a7:d6:ab:bb:9a:89:c0:8e:95:fd:62:de:26
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = US, ST = MI, L = Detroit, O = dSIPRouter, CN = 
ec2-34-224-90-100.compute-1.amazonaws.com
Validity
Not Before: Jan 30 15:28:11 2024 GMT
Not After : Jan 29 15:28:11 2025 GMT
Subject: C = US, ST = MI, L = Detroit, O = dSIPRouter, CN = 
ec2-34-224-90-100.compute-1.amazonaws.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (4096 bit)
...
```

Example tls key:

```
Private-Key: (4096 bit, 2 primes)
modulus:
...
```

 Log Messages

```
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:345]: ksr_tls_fill_missing(): TLSs: tls_method=25
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:357]: ksr_tls_fill_missing(): TLSs: 
certificate='/etc/dsiprouter/certs/dsiprouter-cert.pem'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:364]: ksr_tls_fill_missing(): TLSs: 
ca_list='/etc/dsiprouter/certs/ca-list.pem'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:371]: ksr_tls_fill_missing(): TLSs: 
ca_path='/etc/dsiprouter/certs/ca'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:378]: ksr_tls_fill_missing(): TLSs: crl='(null)'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:382]: ksr_tls_fill_missing(): TLSs: require_certificate=1
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:390]: ksr_tls_fill_missing(): TLSs: cipher_list='(null)'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:397]: ksr_tls_fill_missing(): TLSs: 
private_key='/etc/dsiprouter/certs/dsiprouter-key.pem'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:401]: ksr_tls_fill_missing(): TLSs: verify_certificate=1
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:406]: ksr_tls_fill_missing(): TLSs: verify_depth=9
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: INFO: tls 
[tls_domain.c:410]: ksr_tls_fill_missing(): TLSs: verify_client=0
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: NOTICE: tls 
[tls_domain.c:1168]: ksr_tls_fix_domain(): registered server_name callback 
handler for socket [:0], server_name='' ...
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: ERROR: tls 
[tls_domain.c:590]: load_cert(): TLSs: Unable to load certificate file 
'/etc/dsiprouter/certs/dsiprouter-cert.pem'
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: ERROR: tls 
[tls_util.h:49]: tls_err_ret(): load_cert:error:0372:digital envelope 
routines::decode error (sni: unknown)
Jan 31 14:46:16 ip-172-31-30-183 /usr/sbin/kamailio[3620]: ERROR: tls 
[tls_util.h:49]: tls_err_ret(): load_cert:error:0A00018F:SSL routines::ee key 
too small (sni: unknown)
```

 SIP Traffic

N/A

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3737
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:0833a72d: db_mysql: proper macro to check mysql version id

2024-01-31 Thread Daniel-Constantin Mierla via sr-dev
Module: kamailio
Branch: master
Commit: 0833a72d4b70d224ab02c90b7b94648db7f52c73
URL: 
https://github.com/kamailio/kamailio/commit/0833a72d4b70d224ab02c90b7b94648db7f52c73

Author: Daniel-Constantin Mierla 
Committer: Daniel-Constantin Mierla 
Date: 2024-01-31T10:13:48+01:00

db_mysql: proper macro to check mysql version id

---

Modified: src/modules/db_mysql/km_my_con.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/0833a72d4b70d224ab02c90b7b94648db7f52c73.diff
Patch: 
https://github.com/kamailio/kamailio/commit/0833a72d4b70d224ab02c90b7b94648db7f52c73.patch

---

diff --git a/src/modules/db_mysql/km_my_con.c b/src/modules/db_mysql/km_my_con.c
index b415ff87655..88c950417a6 100644
--- a/src/modules/db_mysql/km_my_con.c
+++ b/src/modules/db_mysql/km_my_con.c
@@ -141,7 +141,7 @@ struct my_con *db_mysql_new_connection(const struct db_id 
*id)
break;
}
 #else
-#ifdef MYSQL_VERSION_ID> 50710
+#if MYSQL_VERSION_ID > 50710
if(db_mysql_opt_ssl_mode != 0) {
unsigned int optuint = 0;
if(db_mysql_opt_ssl_mode == 1) {

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] Re: [kamailio/kamailio] core: infra to run functions in threads (PR #3736)

2024-01-31 Thread space88man via sr-dev
Closed #3736.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3736#event-11652747801
You are receiving this because you are subscribed to this thread.

Message ID: ___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:8a1c383f: db_postgres: use core/rthreads.h

2024-01-31 Thread S-P Chan via sr-dev
Module: kamailio
Branch: master
Commit: 8a1c383f6af5bc0547e32430a4469333160b93e6
URL: 
https://github.com/kamailio/kamailio/commit/8a1c383f6af5bc0547e32430a4469333160b93e6

Author: S-P Chan 
Committer: S-P Chan 
Date: 2024-01-31T16:47:09+08:00

db_postgres: use core/rthreads.h

---

Modified: src/modules/db_postgres/km_dbase.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/8a1c383f6af5bc0547e32430a4469333160b93e6.diff
Patch: 
https://github.com/kamailio/kamailio/commit/8a1c383f6af5bc0547e32430a4469333160b93e6.patch

---

diff --git a/src/modules/db_postgres/km_dbase.c 
b/src/modules/db_postgres/km_dbase.c
index 065b71f0709..3d58f1a53e0 100644
--- a/src/modules/db_postgres/km_dbase.c
+++ b/src/modules/db_postgres/km_dbase.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../core/dprint.h"
 #include "../../core/mem/mem.h"
 #include "../../lib/srdb1/db.h"
@@ -44,6 +43,8 @@
 #include "../../core/locking.h"
 #include "../../core/hashes.h"
 #include "../../core/clist.h"
+#define KSR_RTHREAD_NEED_PI
+#include "../../core/rthreads.h"
 #include "km_dbase.h"
 #include "km_pg_con.h"
 #include "km_val.h"
@@ -119,14 +120,7 @@ static db1_con_t *db_postgres_init0(const str *_url)
 
 db1_con_t *db_postgres_init(const str *_url)
 {
-   pthread_t tid;
-   db1_con_t *ret;
-
-   pthread_create(
-   &tid, NULL, (void *(*)(void *))db_postgres_init0, (void 
*)_url);
-   pthread_join(tid, (void **)&ret);
-
-   return ret;
+   return run_threadP((_thread_proto)db_postgres_init0, (void *)_url);
 }
 /*!
  * \brief Initialize database for future queries, specify pooling
@@ -137,28 +131,15 @@ db1_con_t *db_postgres_init(const str *_url)
  *
  * Init libssl in thread
  */
-struct _thread_args
-{
-   const str *_url;
-   db_pooling_t pooling;
-};
-
-static db1_con_t *_db_postgres_init2(struct _thread_args *args)
+static db1_con_t *db_postgres_init2_impl(const str *_url, db_pooling_t pooling)
 {
-   return db_do_init2(
-   args->_url, (void *)db_postgres_new_connection, 
args->pooling);
+   return db_do_init2(_url, (void *)db_postgres_new_connection, pooling);
 }
 
 db1_con_t *db_postgres_init2(const str *_url, db_pooling_t pooling)
 {
-   pthread_t tid;
-   db1_con_t *ret;
-
-   pthread_create(&tid, NULL, (void *(*)(void *))_db_postgres_init2,
-   (void *)&(struct _thread_args){_url, pooling});
-   pthread_join(tid, (void **)&ret);
-
-   return ret;
+   return run_threadPI(
+   (_thread_protoPI)db_postgres_init2_impl, (void *)_url, 
pooling);
 }
 /*!
  * \brief Close database when the database is no longer needed

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:733a2681: db_mysql: use core/rthreads.h

2024-01-31 Thread S-P Chan via sr-dev
Module: kamailio
Branch: master
Commit: 733a268114261d49ed11aec83fe39ea8c34a0b69
URL: 
https://github.com/kamailio/kamailio/commit/733a268114261d49ed11aec83fe39ea8c34a0b69

Author: S-P Chan 
Committer: S-P Chan 
Date: 2024-01-31T16:47:09+08:00

db_mysql: use core/rthreads.h

---

Modified: src/modules/db_mysql/km_dbase.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/733a268114261d49ed11aec83fe39ea8c34a0b69.diff
Patch: 
https://github.com/kamailio/kamailio/commit/733a268114261d49ed11aec83fe39ea8c34a0b69.patch

---

diff --git a/src/modules/db_mysql/km_dbase.c b/src/modules/db_mysql/km_dbase.c
index 721ba8aa6cf..9cd238b78ab 100644
--- a/src/modules/db_mysql/km_dbase.c
+++ b/src/modules/db_mysql/km_dbase.c
@@ -34,11 +34,11 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "../../core/mem/mem.h"
 #include "../../core/dprint.h"
 #include "../../core/async_task.h"
+#include "../../core/rthreads.h"
 #include "../../lib/srdb1/db_query.h"
 #include "../../lib/srdb1/db_ut.h"
 #include "db_mysql.h"
@@ -213,13 +213,7 @@ static db1_con_t *db_mysql_init0(const str *_url)
 
 db1_con_t *db_mysql_init(const str *_url)
 {
-   pthread_t tid;
-   db1_con_t *ret;
-
-   pthread_create(&tid, NULL, (void *(*)(void *))db_mysql_init0, (void 
*)_url);
-   pthread_join(tid, (void **)&ret);
-
-   return ret;
+   return run_threadP((_thread_proto)db_mysql_init0, (void *)_url);
 }
 /**
  * Shut down the database module.

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:94f6df50: outbound: use core/rthreads.h

2024-01-31 Thread S-P Chan via sr-dev
Module: kamailio
Branch: master
Commit: 94f6df509bf77c19c745749716a9e075ec17f3c7
URL: 
https://github.com/kamailio/kamailio/commit/94f6df509bf77c19c745749716a9e075ec17f3c7

Author: S-P Chan 
Committer: S-P Chan 
Date: 2024-01-31T16:47:09+08:00

outbound: use core/rthreads.h

---

Modified: src/modules/outbound/outbound_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/94f6df509bf77c19c745749716a9e075ec17f3c7.diff
Patch: 
https://github.com/kamailio/kamailio/commit/94f6df509bf77c19c745749716a9e075ec17f3c7.patch

---

diff --git a/src/modules/outbound/outbound_mod.c 
b/src/modules/outbound/outbound_mod.c
index e2e3a86a73b..24d7a54cd71 100644
--- a/src/modules/outbound/outbound_mod.c
+++ b/src/modules/outbound/outbound_mod.c
@@ -40,6 +40,10 @@
 #include "../../core/parser/parse_uri.h"
 #include "../../core/parser/parse_supported.h"
 
+#define KSR_RTHREAD_SKIP_P
+#define KSR_RTHREAD_NEED_V
+#include "../../core/rthreads.h"
+
 #include "api.h"
 #include "config.h"
 
@@ -75,26 +79,25 @@ struct module_exports exports = {
destroy  /* destroy 
function */
 };
 
-static void *mod_init_openssl(void *arg) {
-if(flow_token_secret.s) {
-assert(ob_key.len == SHA_DIGEST_LENGTH);
-LM_DBG("flow_token_secret mod param set. use persistent ob_key");
+static void mod_init_openssl(void)
+{
+   if(flow_token_secret.s) {
+   assert(ob_key.len == SHA_DIGEST_LENGTH);
+   LM_DBG("flow_token_secret mod param set. use persistent 
ob_key");
 #if OPENSSL_VERSION_NUMBER < 0x03000L
-SHA1((const unsigned char *)flow_token_secret.s, flow_token_secret.len,
- (unsigned char *)ob_key.s);
+   SHA1((const unsigned char *)flow_token_secret.s, 
flow_token_secret.len,
+   (unsigned char *)ob_key.s);
 #else
-EVP_Q_digest(NULL, "SHA1", NULL, flow_token_secret.s,
- flow_token_secret.len, (unsigned char *)ob_key.s, NULL);
+   EVP_Q_digest(NULL, "SHA1", NULL, flow_token_secret.s,
+   flow_token_secret.len, (unsigned char 
*)ob_key.s, NULL);
 #endif
-} else {
-if(RAND_bytes((unsigned char *)ob_key.s, ob_key.len) == 0) {
-LM_ERR("unable to get %d cryptographically strong pseudo-"
-   "random bytes\n",
-   ob_key.len);
-}
-}
-
-return NULL;
+   } else {
+   if(RAND_bytes((unsigned char *)ob_key.s, ob_key.len) == 0) {
+   LM_ERR("unable to get %d cryptographically strong 
pseudo-"
+  "random bytes\n",
+   ob_key.len);
+   }
+   }
 }
 
 static int mod_init(void)
@@ -116,12 +119,9 @@ static int mod_init(void)
ob_key.len = OB_KEY_LEN;
 
 #if OPENSSL_VERSION_NUMBER < 0x010101000L
-mod_init_openssl(NULL);
+   mod_init_openssl(NULL);
 #else
-pthread_t tid;
-void *retval;
-pthread_create(&tid, NULL, mod_init_openssl, NULL);
-pthread_join(tid, &retval);
+   run_threadV(mod_init_openssl);
 #endif
 
if(cfg_declare("outbound", outbound_cfg_def, &default_outbound_cfg,

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:f8909163: core: add infrastructure to run functions in threads

2024-01-31 Thread S-P Chan via sr-dev
Module: kamailio
Branch: master
Commit: f8909163c47c8776d23373fad688586f02d31e67
URL: 
https://github.com/kamailio/kamailio/commit/f8909163c47c8776d23373fad688586f02d31e67

Author: S-P Chan 
Committer: S-P Chan 
Date: 2024-01-31T16:47:09+08:00

core: add infrastructure to run functions in threads

---

Added: src/core/rthreads.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/f8909163c47c8776d23373fad688586f02d31e67.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f8909163c47c8776d23373fad688586f02d31e67.patch

---

diff --git a/src/core/rthreads.h b/src/core/rthreads.h
new file mode 100644
index 000..a5ad7670dae
--- /dev/null
+++ b/src/core/rthreads.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2024 Chan Shih-Ping
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * A set of helpers to run functions in threads.
+ *
+ * This is not a thread pool implementation -
+ * - it runs functions in a run-once thread to avoid
+ * creating thread-locals in the calling thread.
+ *
+ * Primary use case: to init libssl in a separate thread
+ */
+#include 
+
+/*
+ * prototype: void *fn(void *arg) { ... }
+ */
+typedef void *(*_thread_proto)(void *);
+
+#ifndef KSR_RTHREAD_SKIP_P
+static void *run_threadP(_thread_proto fn, void *arg)
+{
+   pthread_t tid;
+   void *ret;
+
+   pthread_create(&tid, NULL, fn, arg);
+   pthread_join(tid, &ret);
+
+   return ret;
+}
+#endif
+
+/*
+ * prototype: void *fn(void *arg1, int arg2) { ... }
+ */
+#ifdef KSR_RTHREAD_NEED_PI
+typedef void *(*_thread_protoPI)(void *, int);
+struct _thread_argsPI
+{
+   _thread_protoPI fn;
+   void *tptr;
+   int tint;
+};
+static void *run_thread_wrapPI(struct _thread_argsPI *args)
+{
+   return (*args->fn)(args->tptr, args->tint);
+}
+
+static void *run_threadPI(_thread_protoPI fn, void *arg1, int arg2)
+{
+   pthread_t tid;
+   void *ret;
+
+   pthread_create(&tid, NULL, (_thread_proto)&run_thread_wrapPI,
+   &(struct _thread_argsPI){fn, arg1, arg2});
+   pthread_join(tid, &ret);
+
+   return ret;
+}
+#endif
+
+/*
+ * prototype: void fn(void) { ... }
+ */
+#ifdef KSR_RTHREAD_NEED_V
+typedef void (*_thread_protoV)(void);
+struct _thread_argsV
+{
+   _thread_protoV fn;
+};
+static void *run_thread_wrapV(struct _thread_argsV *args)
+{
+   (*args->fn)();
+   return NULL;
+}
+
+static void run_threadV(_thread_protoV fn)
+{
+   pthread_t tid;
+
+   pthread_create(&tid, NULL, (_thread_proto)run_thread_wrapV,
+   &(struct _thread_argsV){fn});
+   pthread_join(tid, NULL);
+}
+#endif

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org


[sr-dev] git:master:b71ce6e5: db_unixodbc: use core/rthreads.h

2024-01-31 Thread S-P Chan via sr-dev
Module: kamailio
Branch: master
Commit: b71ce6e5733ab08b84ff09481ada91e5fca43a33
URL: 
https://github.com/kamailio/kamailio/commit/b71ce6e5733ab08b84ff09481ada91e5fca43a33

Author: S-P Chan 
Committer: S-P Chan 
Date: 2024-01-31T16:47:09+08:00

db_unixodbc: use core/rthreads.h

---

Modified: src/modules/db_unixodbc/dbase.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/b71ce6e5733ab08b84ff09481ada91e5fca43a33.diff
Patch: 
https://github.com/kamailio/kamailio/commit/b71ce6e5733ab08b84ff09481ada91e5fca43a33.patch

---

diff --git a/src/modules/db_unixodbc/dbase.c b/src/modules/db_unixodbc/dbase.c
index f3c01b81ee5..c4ba64b019c 100644
--- a/src/modules/db_unixodbc/dbase.c
+++ b/src/modules/db_unixodbc/dbase.c
@@ -22,10 +22,10 @@
  *
  */
 
-#include 
 #include "../../core/mem/mem.h"
 #include "../../core/dprint.h"
 #include "../../core/async_task.h"
+#include "../../core/rthreads.h"
 #include "../../lib/srdb1/db_query.h"
 #include "val.h"
 #include "connection.h"
@@ -241,14 +241,7 @@ static db1_con_t *db_unixodbc_init0(const str *_url)
 
 db1_con_t *db_unixodbc_init(const str *_url)
 {
-   pthread_t tid;
-   db1_con_t *ret;
-
-   pthread_create(
-   &tid, NULL, (void *(*)(void *))db_unixodbc_init0, (void 
*)_url);
-   pthread_join(tid, (void **)&ret);
-
-   return ret;
+   return run_threadP((_thread_proto)&db_unixodbc_init0, (void *)_url);
 }
 
 /*

___
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org