Skip to content

Commit

Permalink
smpp: add db schmea
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jan 23, 2019
1 parent 336808f commit f79ae9a
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 7 deletions.
12 changes: 12 additions & 0 deletions db/schema/opensips-smpp.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
"http://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
%entities;
]>

<database xmlns:xi="http://www.w3.org/2001/XInclude">
<name>SMPP</name>
<xi:include href="smpp.xml"/>
</database>
110 changes: 110 additions & 0 deletions db/schema/smpp.xml
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
"http://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
%entities;

]>

<table id="smpp" xmlns:db="http://docbook.org/ns/docbook">
<name>smpp</name>
<version>1</version>
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
<description>
<db:para>
This table is used to provision Short Message Service Center (SMSC)
information to connect to over the SMPP (Short Message Peer-to-Peer).
More information can be found at: &OPENSIPS_MOD_DOC;proto_smpp.html.
</db:para>
</description>

<column id="id">
<name>id</name>
<type>unsigned int</type>
<size>&table_id_len;</size>
<autoincrement/>
<natural/>
<primary/>
<type db="dbtext">int,auto</type>
<description>Unique ID</description>
</column>

<column id="name">
<name>name</name>
<type>string</type>
<size>255</size>
<description>An arbitrary name of the SMSC, used to uniquely identify the binding.
</description>
</column>

<column id="ip">
<name>ip</name>
<type>string</type>
<size>&ip_add_len;</size>
<description>The IP address used to connect to the SMSC.</description>
</column>

<column id="port">
<name>port</name>
<type>unsigned int</type>
<size>5</size>
<description>The port used to connect to the SMSC.</description>
</column>

<column id="system_id">
<name>system_id</name>
<type>string</type>
<size>16</size>
<description>The System ID (also called user name) for the gateway
to use when connecting to the SMPP server.</description>
</column>

<column id="password">
<name>password</name>
<type>string</type>
<size>9</size>
<description>The password for the gateway to use when connecting to
the SMPP server.</description>
</column>

<column id="system_type">
<name>system_type</name>
<type>string</type>
<size>13</size>
<description>Configures the System Type parameter of the
the SMPP server.</description>
</column>

<column id="src_ton">
<name>src_ton</name>
<type>unsigned int</type>
<description>Specifies the Source TON (Type of Number).</description>
</column>

<column id="src_npi">
<name>src_npi</name>
<type>unsigned int</type>
<description>Specifies the Source NPI (Numbering Plan Indicator).</description>
</column>

<column id="dst_ton">
<name>dst_ton</name>
<type>unsigned int</type>
<description>Specifies the Destination TON (Type of Number).</description>
</column>

<column id="dst_npi">
<name>dst_npi</name>
<type>unsigned int</type>
<description>Specifies the Destination NPI (Numbering Plan Indicator).</description>
</column>

<column id="session_type">
<name>session_type</name>
<type>unsigned int</type>
<description>Sepecifies the type of binding: 1 - transciever,
2 - transmitter, 3 - receiver, 4 - outbind.</description>
</column>

</table>
13 changes: 11 additions & 2 deletions modules/proto_smpp/db.c
Expand Up @@ -42,7 +42,7 @@ str smpp_dst_ton_col = str_init("dst_ton");
str smpp_dst_npi_col = str_init("dst_npi");
str smpp_session_type_col = str_init("session_type");

int smpp_db_bind(const str *db_url)
int smpp_db_init(const str *db_url)
{
smpp_table.len = strlen(smpp_table.s);
smpp_name_col.len = strlen(smpp_name_col.s);
Expand All @@ -61,10 +61,19 @@ int smpp_db_bind(const str *db_url)
LM_ERR("cannot bind module database\n");
return -1;
}

if (smpp_db_connect(db_url) < 0)
return -1;

if(db_check_table_version(&smpp_dbf, smpp_db_handle,
&smpp_table, SMPP_TABLE_VERSION) < 0) {
LM_ERR("error during table version check.\n");
return -1;
}
return 0;
}

int smpp_db_init(const str *db_url)
int smpp_db_connect(const str *db_url)
{
if (smpp_dbf.init == 0) {
LM_ERR("unbound database module\n");
Expand Down
4 changes: 3 additions & 1 deletion modules/proto_smpp/db.h
Expand Up @@ -25,6 +25,8 @@
#include "../../db/db.h"
#include "../../str.h"

#define SMPP_TABLE_VERSION 1

extern str smpp_table;
extern str smpp_name_col;
extern str smpp_ip_col;
Expand All @@ -39,8 +41,8 @@ extern str smpp_dst_npi_col;
extern str smpp_session_type_col;
extern str smpp_outbound_uri;

int smpp_db_bind(const str *db_url);
int smpp_db_init(const str *db_url);
int smpp_db_connect(const str *db_url);
int load_smpp_sessions_from_db(struct list_head *head);
int smpp_query(const str *smpp_table, db_key_t *cols, int col_nr, db_res_t **res);
void smpp_free_results(db_res_t *res);
Expand Down
5 changes: 1 addition & 4 deletions modules/proto_smpp/proto_smpp.c
Expand Up @@ -148,9 +148,6 @@ static int mod_init(void)
db_url.len = strlen(db_url.s);
smpp_outbound_uri.len = strlen(smpp_outbound_uri.s);

if (smpp_db_bind(&db_url) < 0)
return -1;

if (smpp_db_init(&db_url) < 0)
return -1;

Expand Down Expand Up @@ -221,7 +218,7 @@ static int child_init(int rank)
{
LM_INFO("initializing child #%d\n", rank);

if (smpp_db_init(&db_url) < 0)
if (smpp_db_connect(&db_url) < 0)
return -1;

if ((rank == 1) && ipc_dispatch_rpc(rpc_bind_sessions, NULL) < 0) {
Expand Down
10 changes: 10 additions & 0 deletions scripts/db_berkeley/opensips/smpp
@@ -0,0 +1,10 @@
METADATA_COLUMNS
id(int) name(str) ip(str) port(int) system_id(str) password(str) system_type(str) src_ton(int) src_npi(int) dst_ton(int) dst_npi(int) session_type(int)
METADATA_KEY
0
METADATA_READONLY
0
METADATA_LOGFLAGS
0
METADATA_DEFAULTS
NIL|NIL|NIL|NIL|NIL|NIL|NIL|NIL|NIL|NIL|NIL|NIL
2 changes: 2 additions & 0 deletions scripts/db_berkeley/opensips/version
Expand Up @@ -112,6 +112,8 @@ silo|
silo|6
sip_trace|
sip_trace|5
smpp|
smpp|1
speed_dial|
speed_dial|3
subscriber|
Expand Down
1 change: 1 addition & 0 deletions scripts/dbtext/opensips/smpp
@@ -0,0 +1 @@
id(int,auto) name(string) ip(string) port(int) system_id(string) password(string) system_type(string) src_ton(int) src_npi(int) dst_ton(int) dst_npi(int) session_type(int)
1 change: 1 addition & 0 deletions scripts/dbtext/opensips/version
Expand Up @@ -48,6 +48,7 @@ rtpengine:1
rtpproxy_sockets:0
silo:6
sip_trace:5
smpp:1
speed_dial:3
subscriber:7
tls_mgm:3
Expand Down
16 changes: 16 additions & 0 deletions scripts/mysql/smpp-create.sql
@@ -0,0 +1,16 @@
INSERT INTO version (table_name, table_version) values ('smpp','1');
CREATE TABLE smpp (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
name CHAR(255) NOT NULL,
ip CHAR(50) NOT NULL,
port INT(5) UNSIGNED NOT NULL,
system_id CHAR(16) NOT NULL,
password CHAR(9) NOT NULL,
system_type CHAR(13) NOT NULL,
src_ton INT UNSIGNED NOT NULL,
src_npi INT UNSIGNED NOT NULL,
dst_ton INT UNSIGNED NOT NULL,
dst_npi INT UNSIGNED NOT NULL,
session_type INT UNSIGNED NOT NULL
) ENGINE=InnoDB;

24 changes: 24 additions & 0 deletions scripts/oracle/smpp-create.sql
@@ -0,0 +1,24 @@
INSERT INTO version (table_name, table_version) values ('smpp','1');
CREATE TABLE smpp (
id NUMBER(10) PRIMARY KEY,
name VARCHAR2(255),
ip VARCHAR2(50),
port NUMBER(10),
system_id VARCHAR2(16),
password VARCHAR2(9),
system_type VARCHAR2(13),
src_ton NUMBER(10),
src_npi NUMBER(10),
dst_ton NUMBER(10),
dst_npi NUMBER(10),
session_type NUMBER(10)
);

CREATE OR REPLACE TRIGGER smpp_tr
before insert on smpp FOR EACH ROW
BEGIN
auto_id(:NEW.id);
END smpp_tr;
/
BEGIN map2users('smpp'); END;
/
82 changes: 82 additions & 0 deletions scripts/pi_http/pi_framework.xml
Expand Up @@ -859,6 +859,23 @@
<column><field>fromtag</field><type>DB_STR</type></column>
<column><field>direction</field><type>DB_STR</type></column>
</db_table>
<!-- Declaration of smpp table-->
<db_table id="smpp">
<table_name>smpp</table_name>
<db_url_id>mysql</db_url_id>
<column><field>id</field><type>DB_INT</type></column>
<column><field>name</field><type>DB_STR</type></column>
<column><field>ip</field><type>DB_STR</type></column>
<column><field>port</field><type>DB_INT</type></column>
<column><field>system_id</field><type>DB_STR</type></column>
<column><field>password</field><type>DB_STR</type></column>
<column><field>system_type</field><type>DB_STR</type></column>
<column><field>src_ton</field><type>DB_INT</type></column>
<column><field>src_npi</field><type>DB_INT</type></column>
<column><field>dst_ton</field><type>DB_INT</type></column>
<column><field>dst_npi</field><type>DB_INT</type></column>
<column><field>session_type</field><type>DB_INT</type></column>
</db_table>
<!-- Declaration of speed_dial table-->
<db_table id="speed_dial">
<table_name>speed_dial</table_name>
Expand Down Expand Up @@ -4219,6 +4236,71 @@
</clause_cols>
</cmd>
</mod>
<!-- smpp provisionning -->
<mod><mod_name>smpp</mod_name>
<cmd><cmd_name>show</cmd_name>
<db_table_id>smpp</db_table_id>
<cmd_type>DB_QUERY</cmd_type>
<query_cols>
<col><field>id</field><link_cmd>update</link_cmd></col>
<col><field>name</field></col>
<col><field>ip</field></col>
<col><field>port</field></col>
<col><field>system_id</field></col>
<col><field>password</field></col>
<col><field>system_type</field></col>
<col><field>src_ton</field></col>
<col><field>src_npi</field></col>
<col><field>dst_ton</field></col>
<col><field>dst_npi</field></col>
<col><field>session_type</field></col>
</query_cols>
</cmd>
<cmd><cmd_name>add</cmd_name>
<db_table_id>smpp</db_table_id>
<cmd_type>DB_INSERT</cmd_type>
<query_cols>
<col><field>name</field></col>
<col><field>ip</field></col>
<col><field>port</field></col>
<col><field>system_id</field></col>
<col><field>password</field></col>
<col><field>system_type</field></col>
<col><field>src_ton</field></col>
<col><field>src_npi</field></col>
<col><field>dst_ton</field></col>
<col><field>dst_npi</field></col>
<col><field>session_type</field></col>
</query_cols>
</cmd>
<cmd><cmd_name>update</cmd_name>
<db_table_id>smpp</db_table_id>
<cmd_type>DB_UPDATE</cmd_type>
<clause_cols>
<col><field>id</field><operator>=</operator></col>
</clause_cols>
<query_cols>
<col><field>name</field></col>
<col><field>ip</field></col>
<col><field>port</field></col>
<col><field>system_id</field></col>
<col><field>password</field></col>
<col><field>system_type</field></col>
<col><field>src_ton</field></col>
<col><field>src_npi</field></col>
<col><field>dst_ton</field></col>
<col><field>dst_npi</field></col>
<col><field>session_type</field></col>
</query_cols>
</cmd>
<cmd><cmd_name>delete</cmd_name>
<db_table_id>smpp</db_table_id>
<cmd_type>DB_DELETE</cmd_type>
<clause_cols>
<col><field>id</field><operator>=</operator></col>
</clause_cols>
</cmd>
</mod>
<!-- speed_dial provisionning -->
<mod><mod_name>speed_dial</mod_name>
<cmd><cmd_name>show</cmd_name>
Expand Down

0 comments on commit f79ae9a

Please sign in to comment.