From 0a140d38105ad7f821f379622be6c26a0f581b90 Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Tue, 28 Jun 2005 02:32:52 +0000 Subject: [PATCH] DB dump for calls --- include/phoned.h | 3 ++- phoned/db.c | 39 ++++++++++++++++++++++++++++++++++++++- phoned/remote.c | 5 ++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/phoned.h b/include/phoned.h index 8676846..9513ac6 100644 --- a/include/phoned.h +++ b/include/phoned.h @@ -3,7 +3,7 @@ * (C)2005, Dan Ponte * BSDL w/ advert. */ -/* $Amigan: phoned/include/phoned.h,v 1.28 2005/06/25 02:43:54 dcp1990 Exp $ */ +/* $Amigan: phoned/include/phoned.h,v 1.29 2005/06/28 02:32:52 dcp1990 Exp $ */ #include /* fugly, I know... */ #define VERSION "0.1" #define LOGFILE "-" @@ -205,6 +205,7 @@ cid_t *decode_sdmf(unsigned char *s); cid_t *decode_mdmf(unsigned char *s); void voice_init(void); int dialogue_with_modem(int (*cback)(int, void*), void *arg); +short db_dump_calls(int fd, const char *fmt); /* old stuff... void modem_pickup(void); void modem_hangup(void); diff --git a/phoned/db.c b/phoned/db.c index 783c491..c05cdeb 100644 --- a/phoned/db.c +++ b/phoned/db.c @@ -27,8 +27,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/db.c,v 1.8 2005/06/28 02:02:21 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/db.c,v 1.9 2005/06/28 02:32:54 dcp1990 Exp $ */ #include +#include +#include +#include #include #include #include @@ -144,6 +147,40 @@ short db_destroy(void) /* stuff that does stuff */ +short db_dump_calls(fd, fmt) + int fd; + const char *fmt; +{ + int rc; + const char *sql = "SELECT * FROM " CALLS_TABLE; + const char *tail; + char buffer[128]; + char finalbuf[256]; + int recs = 0; + sqlite3_stmt *cst; + pthread_mutex_lock(&dbmx); + if((rc = sqlite3_prepare(db, sql, strlen(sql), &cst, &tail)) != SQLITE_OK) { + lprintf(error, "dump_calls(%d, %s): prepare: %s", fd, fmt, sqlite3_errmsg(db)); + pthread_mutex_unlock(&dbmx); + return 0; + } + /* CREATE TABLE " CALLS_TABLE " (id INTEGER PRIMARY KEY, dtime INTEGER, number TEXT, name TEXT, cidmon INTEGER, cidday INTEGER, cidhour INTEGER, cidmin INTEGER) */ + while((rc = sqlite3_step(cst)) == SQLITE_ROW) { + snprintf(buffer, sizeof(buffer), "%d:%d:%d:%d:%s:%s:%d", sqlite3_column_int(cst, 4), sqlite3_column_int(cst, 5), sqlite3_column_int(cst, 6), sqlite3_column_int(cst, 7), + sqlite3_column_text(cst, 3), sqlite3_column_text(cst, 2), sqlite3_column_int(cst, 1)); + snprintf(finalbuf, 256, fmt, buffer); + write(fd, finalbuf, strlen(finalbuf)); + recs++; + } + if(rc != SQLITE_OK && rc != SQLITE_DONE) { + lprintf(error, "dump_calls(%d, %s): error after loop: %s (rc == %d)\n", fd, fmt, sqlite3_errmsg(db), rc); + pthread_mutex_unlock(&dbmx); + return 0; + } + sqlite3_finalize(cst); + pthread_mutex_unlock(&dbmx); + return recs; +} short db_check_crend(loginna, pass) char *loginna; char *pass; /* not md5'd yet */ diff --git a/phoned/remote.c b/phoned/remote.c index 40418ed..4be7aae 100644 --- a/phoned/remote.c +++ b/phoned/remote.c @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/remote.c,v 1.18 2005/06/28 02:00:06 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/remote.c,v 1.19 2005/06/28 02:32:54 dcp1990 Exp $ */ /* system includes */ #include #include @@ -369,6 +369,9 @@ char *parse_command(cmd, cont, s) RNF("500 OK: Parser tested.\n"); } else if(CHK("bye")) { return NULL; + } else if(CHK("dumpcalls")) { + db_dump_calls(s->fd, "700 CALLREC: %s\n"); + RNF("516 DONE: Calls Done.\n"); } else if(CHK("tmop")) { if(argvect[1] != NULL) { cid_t *rc;