pcrf_json_dbi #1

Open
acouzens wants to merge 12 commits from pcrf_json_dbi into main
9 changed files with 274 additions and 10 deletions
Showing only changes of commit 9c66348213 - Show all commits

57
lib/dbi/dbi-private.h Normal file
View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <lynxis@fe80.eu>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#if !defined(OGS_DBI_INSIDE) && !defined(OGS_DBI_COMPILATION)
#error "This header cannot be included directly."
#endif
#ifndef OGS_DBI_PRIVATE_H
#define OGS_DBI_PRIVATE_H
#ifdef __cplusplus
extern "C" {
#endif
struct ogs_dbi_s {
const char *name;
/* session */
int (*session_data)(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
ogs_session_data_t *data);
/* ims */
int (*msisdn_data)(char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data);
int (*ims_data)(char *supi, ogs_ims_data_t *ims_data);
/* subscription */
int (*auth_info)(char *supi, ogs_dbi_auth_info_t *auth_info);
int (*update_sqn)(char *supi, uint64_t sqn);
int (*increment_sqn)(char *supi);
int (*update_imeisv)(char *supi, char *imeisv);
int (*subscription_data)(char *supi,
ogs_subscription_data_t *subscription_data);
};
typedef struct ogs_dbi_s ogs_dbi_t;
int ogs_dbi_deselect_interface(void);
int ogs_dbi_select_interface(const char *dbi_name);
#ifdef __cplusplus
}
#endif
#endif /* OGS_DBI_PRIVATE_H */

119
lib/dbi/dbi.c Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <lynxis@fe80.eu>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ogs-dbi.h"
#include "dbi-private.h"
#include "dbi-config-private.h"
#ifdef WITH_MONGOC
#include "mongo/mongo-private.h"
#endif
int __ogs_dbi_domain;
static ogs_dbi_t *dbi_interfaces[] = {
#ifdef WITH_MONGOC
&ogs_dbi_mongo_interface,
#endif
NULL,
};
static ogs_dbi_t *dbi_selected;
int ogs_dbi_deselect_interface()
{
dbi_selected = NULL;
return 0;
}
int ogs_dbi_select_interface(const char *dbi_name)
{
ogs_dbi_t *dbi;
int i;
ogs_assert(dbi_name);
for (i = 0; i < OGS_ARRAY_SIZE(dbi_interfaces); i++) {
dbi = dbi_interfaces[i];
if (!ogs_strcasecmp(dbi->name, dbi_name)) {
dbi_selected = dbi;
return 0;
}
}
ogs_error("Couldn't find dbi interface %s", dbi_name);
return -1;
}
/* ims */
int ogs_dbi_msisdn_data(
char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data)
{
ogs_assert(dbi_selected);
return dbi_selected->msisdn_data(imsi_or_msisdn_bcd, msisdn_data);
}
int ogs_dbi_ims_data(char *supi, ogs_ims_data_t *ims_data)
{
ogs_assert(dbi_selected);
return dbi_selected->ims_data(supi, ims_data);
}
/* session */
int ogs_dbi_session_data(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
ogs_session_data_t *session_data)
{
ogs_assert(dbi_selected);
return dbi_selected->session_data(supi, s_nssai, dnn, session_data);
}
/* subscription */
int ogs_dbi_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info)
{
ogs_assert(dbi_selected);
return dbi_selected->auth_info(supi, auth_info);
}
int ogs_dbi_update_sqn(char *supi, uint64_t sqn)
{
ogs_assert(dbi_selected);
return dbi_selected->update_sqn(supi, sqn);
}
int ogs_dbi_increment_sqn(char *supi)
{
ogs_assert(dbi_selected);
return dbi_selected->increment_sqn(supi);
}
int ogs_dbi_update_imeisv(char *supi, char *imeisv)
{
ogs_assert(dbi_selected);
return dbi_selected->update_imeisv(supi, imeisv);
}
int ogs_dbi_subscription_data(char *supi,
ogs_subscription_data_t *subscription_data)
{
ogs_assert(dbi_selected);
return dbi_selected->subscription_data(supi, subscription_data);
}

View File

@ -15,9 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
libdbi_conf = configuration_data()
dbi_sources = files('''
ogs-dbi.h
dbi.c
'''.split())
libdbi_sources = [dbi_sources]
@ -31,9 +33,12 @@ mongo_sources = files('''
libmongoc_dep = dependency('libmongoc-1.0', required: true)
if libmongoc_dep.found()
libdbi_conf.set('WITH_MONGOC', 1)
libdbi_sources += [mongo_sources]
endif
configure_file(output : 'dbi-config-private.h', configuration : libdbi_conf)
libdbi_inc = include_directories('.')
libdbi = library('ogsdbi',

View File

@ -20,8 +20,9 @@
#include <mongoc.h>
#include "ogs-dbi.h"
#include "mongo-private.h"
int ogs_dbi_msisdn_data(
int ogs_dbi_mongo_msisdn_data(
char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data)
{
int rv = OGS_OK;
@ -119,7 +120,7 @@ out:
return rv;
}
int ogs_dbi_ims_data(char *supi, ogs_ims_data_t *ims_data)
int ogs_dbi_mongo_ims_data(char *supi, ogs_ims_data_t *ims_data)
{
int rv = OGS_OK;
mongoc_cursor_t *cursor = NULL;

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <lynxis@fe80.eu>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#if !defined(OGS_DBI_INSIDE) && !defined(OGS_DBI_COMPILATION)
#error "This header cannot be included directly."
#endif
#ifndef OGS_DBI_MONGO_PRIVATE_H
#define OGS_DBI_MONGO_PRIVATE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "dbi-private.h"
extern ogs_dbi_t ogs_dbi_mongo_interface;
/* ims */
int ogs_dbi_mongo_msisdn_data(
char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data);
int ogs_dbi_mongo_ims_data(char *supi, ogs_ims_data_t *ims_data);
/* session */
int ogs_dbi_mongo_session_data(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
ogs_session_data_t *session_data);
/* subscription */
int ogs_dbi_mongo_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info);
int ogs_dbi_mongo_update_sqn(char *supi, uint64_t sqn);
int ogs_dbi_mongo_update_imeisv(char *supi, char *imeisv);
int ogs_dbi_mongo_increment_sqn(char *supi);
int ogs_dbi_mongo_subscription_data(char *supi,
ogs_subscription_data_t *subscription_data);
#ifdef __cplusplus
}
#endif
#endif /* OGS_DBI_MONGO_PRIVATE_H */

View File

@ -20,8 +20,8 @@
#include <mongoc.h>
#include "ogs-dbi.h"
int __ogs_dbi_domain;
#include "dbi-private.h"
#include "mongo-private.h"
static ogs_mongoc_t self;
@ -158,11 +158,32 @@ ogs_mongoc_t *ogs_mongoc(void)
return &self;
}
ogs_dbi_t ogs_dbi_mongo_interface = {
.name = "mongo",
/* session */
.session_data = ogs_dbi_mongo_session_data,
/* ims */
.msisdn_data = ogs_dbi_mongo_msisdn_data,
.ims_data = ogs_dbi_mongo_ims_data,
/* subscription */
.auth_info = ogs_dbi_mongo_auth_info,
.update_sqn = ogs_dbi_mongo_update_sqn,
.increment_sqn = ogs_dbi_mongo_increment_sqn,
.update_imeisv = ogs_dbi_mongo_update_imeisv,
.subscription_data = ogs_dbi_mongo_subscription_data,
};
int ogs_dbi_init(const char *db_uri)
{
return ogs_dbi_mongo_init(db_uri);
}
int ogs_dbi_mongo_init(const char *db_uri)
{
int rv;
ogs_assert(db_uri);
ogs_dbi_select_interface("mongo");
rv = ogs_mongoc_init(db_uri);
if (rv != OGS_OK) return rv;
@ -173,6 +194,7 @@ int ogs_dbi_init(const char *db_uri)
ogs_assert(self.collection.subscriber);
}
return OGS_OK;
}

View File

@ -47,6 +47,7 @@ void ogs_mongoc_final(void);
ogs_mongoc_t *ogs_mongoc(void);
int ogs_dbi_init(const char *db_uri);
int ogs_dbi_mongo_init(const char *db_uri);
void ogs_dbi_final(void);
#ifdef __cplusplus

View File

@ -20,8 +20,9 @@
#include <mongoc.h>
#include "ogs-dbi.h"
#include "mongo-private.h"
int ogs_dbi_session_data(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
int ogs_dbi_mongo_session_data(char *supi, ogs_s_nssai_t *s_nssai, char *dnn,
ogs_session_data_t *session_data)
{
int rv = OGS_OK;

View File

@ -20,8 +20,9 @@
#include <mongoc.h>
#include "ogs-dbi.h"
#include "mongo-private.h"
int ogs_dbi_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info)
int ogs_dbi_mongo_auth_info(char *supi, ogs_dbi_auth_info_t *auth_info)
{
int rv = OGS_OK;
mongoc_cursor_t *cursor = NULL;
@ -111,7 +112,7 @@ out:
return rv;
}
int ogs_dbi_update_sqn(char *supi, uint64_t sqn)
int ogs_dbi_mongo_update_sqn(char *supi, uint64_t sqn)
{
int rv = OGS_OK;
bson_t *query = NULL;
@ -150,7 +151,7 @@ int ogs_dbi_update_sqn(char *supi, uint64_t sqn)
return rv;
}
int ogs_dbi_update_imeisv(char *supi, char *imeisv)
int ogs_dbi_mongo_update_imeisv(char *supi, char *imeisv)
{
int rv = OGS_OK;
bson_t *query = NULL;
@ -191,7 +192,7 @@ int ogs_dbi_update_imeisv(char *supi, char *imeisv)
return rv;
}
int ogs_dbi_increment_sqn(char *supi)
int ogs_dbi_mongo_increment_sqn(char *supi)
{
int rv = OGS_OK;
bson_t *query = NULL;
@ -245,7 +246,7 @@ out:
return rv;
}
int ogs_dbi_subscription_data(char *supi,
int ogs_dbi_mongo_subscription_data(char *supi,
ogs_subscription_data_t *subscription_data)
{
int rv = OGS_OK;