Last change
on this file since 866b6c5 was
48de515,
checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago
|
#971 split socket core logic and main files
Extract socket core and main from ogAdmServer file.
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[48de515] | 1 | /* |
---|
| 2 | * Copyright (C) 2020 Soleta Networks <info@soleta.eu> |
---|
| 3 | * |
---|
| 4 | * This program is free software: you can redistribute it and/or modify it under |
---|
| 5 | * the terms of the GNU Affero General Public License as published by the |
---|
| 6 | * Free Software Foundation, version 3. |
---|
| 7 | */ |
---|
| 8 | |
---|
[2629906] | 9 | #include "dbi.h" |
---|
| 10 | |
---|
| 11 | struct og_dbi *og_dbi_open(struct og_dbi_config *config) |
---|
| 12 | { |
---|
| 13 | struct og_dbi *dbi; |
---|
| 14 | |
---|
| 15 | dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi)); |
---|
| 16 | if (!dbi) |
---|
| 17 | return NULL; |
---|
| 18 | |
---|
| 19 | dbi_initialize_r(NULL, &dbi->inst); |
---|
| 20 | dbi->conn = dbi_conn_new_r("mysql", dbi->inst); |
---|
| 21 | if (!dbi->conn) { |
---|
| 22 | free(dbi); |
---|
| 23 | return NULL; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | dbi_conn_set_option(dbi->conn, "host", config->host); |
---|
| 27 | dbi_conn_set_option(dbi->conn, "username", config->user); |
---|
| 28 | dbi_conn_set_option(dbi->conn, "password", config->passwd); |
---|
| 29 | dbi_conn_set_option(dbi->conn, "dbname", config->database); |
---|
| 30 | dbi_conn_set_option(dbi->conn, "encoding", "UTF-8"); |
---|
| 31 | |
---|
| 32 | if (dbi_conn_connect(dbi->conn) < 0) { |
---|
| 33 | free(dbi); |
---|
| 34 | return NULL; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | return dbi; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void og_dbi_close(struct og_dbi *dbi) |
---|
| 41 | { |
---|
| 42 | dbi_conn_close(dbi->conn); |
---|
| 43 | dbi_shutdown_r(dbi->inst); |
---|
| 44 | free(dbi); |
---|
| 45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.