32 #include <sys/types.h>
39 #include "db1-ast/include/db.h"
41 static sqlite3 *sql3db;
44 static int add_row_to_bdb(
void *arg,
int columns,
char **
values,
char **column_names)
46 DBT key = { 0, }, value = { 0, };
48 if (columns != 2 || strcmp(column_names[0],
"key") || strcmp(column_names[1],
"value")) {
49 fprintf(stderr,
"Unknown row type\n");
54 key.size = strlen(values[0]) + 1;
55 value.data = values[1];
56 value.size = strlen(values[1]) + 1;
58 if (bdb->put(bdb, &key, &value, 0)) {
67 static int convert_bdb_to_sqlite3(
void)
70 if (sqlite3_exec(sql3db,
"SELECT key,value FROM astdb", add_row_to_bdb, NULL, &errmsg) != SQLITE_OK) {
71 fprintf(stderr,
"Could not add row to Berkeley DB: %s\n", errmsg);
78 static int db_open_sqlite3(
const char *dbname)
80 if (sqlite3_open(dbname, &sql3db) != SQLITE_OK) {
81 fprintf(stderr,
"Unable to open Asterisk database '%s': %s\n", dbname, sqlite3_errmsg(sql3db));
82 sqlite3_close(sql3db);
89 static int create_bdb_astdb(
void)
91 if (!bdb && !(bdb = dbopen(
"astdb", O_CREAT | O_RDWR | O_TRUNC, AST_FILE_MODE, DB_BTREE, NULL))) {
92 fprintf(stderr,
"Unable to create astdb: %s\n", strerror(errno));
98 int main(
int argc,
char *argv[])
100 struct stat dont_care;
103 fprintf(stderr,
"%s takes the path of SQLite3 astdb as its only argument\n", basename(argv[0]));
104 fprintf(stderr,
"and will produce a file 'astdb' in the current directory\n"
105 "Make a backup of any existing Berkeley DB astdb you have and copy\n"
106 "the new astdb to its location: often /var/lib/asterisk/astdb\n");
110 if (stat(argv[1], &dont_care)) {
111 fprintf(stderr,
"Unable to open %s: %s\n", argv[1], strerror(errno));
115 if (db_open_sqlite3(argv[1])) {
119 if (create_bdb_astdb()) {
123 if (convert_bdb_to_sqlite3()) {
124 fprintf(stderr,
"Database conversion failed!\n");
126 sqlite3_close(sql3db);
129 printf(
"Created ./astdb. Back up any existing astdb and copy the created\n");
130 printf(
"astdb file to the original's location. Often /var/lib/asterisk/astdb.\n");
132 sqlite3_close(sql3db);
Asterisk main include file. File version handling, generic pbx functions.
int main(int argc, char *argv[])