From: Eric Leblond <eric@regit.org>
To: netfilter-devel@vger.kernel.org
Cc: Eric Leblond <eric@regit.org>
Subject: [PATCH 08/11] db: use offset instead of direct pointer.
Date: Fri, 10 May 2013 08:48:55 +0200 [thread overview]
Message-ID: <1368168538-29780-9-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1368168538-29780-1-git-send-email-eric@regit.org>
Use an offset approach to get the start of values printing area. It
is more generic and will be use soon.
Signed-off-by: Eric Leblond <eric@regit.org>
---
include/ulogd/db.h | 2 +-
util/db.c | 16 +++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/include/ulogd/db.h b/include/ulogd/db.h
index a02afb5..82f37b9 100644
--- a/include/ulogd/db.h
+++ b/include/ulogd/db.h
@@ -29,7 +29,7 @@ struct db_stmt {
struct db_instance {
char *stmt; /* buffer for our insert statement */
- char *stmt_val; /* pointer to the beginning of the "VALUES" part */
+ int stmt_offset; /* offset to the beginning of the "VALUES" part */
char *schema;
time_t reconnect;
int (*interp)(struct ulogd_pluginstance *upi);
diff --git a/util/db.c b/util/db.c
index ec0c045..1a11173 100644
--- a/util/db.c
+++ b/util/db.c
@@ -66,6 +66,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
unsigned int i;
char *table = table_ce(upi->config_kset).u.string;
char *procedure = procedure_ce(upi->config_kset).u.string;
+ char *stmt_val = NULL;
if (mi->stmt)
free(mi->stmt);
@@ -106,7 +107,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
else
sprintf(mi->stmt, "%s (", procedure);
- mi->stmt_val = mi->stmt + strlen(mi->stmt);
+ stmt_val = mi->stmt + strlen(mi->stmt);
for (i = 0; i < upi->input.num_keys; i++) {
if (upi->input.keys[i].flags & ULOGD_KEYF_INACTIVE)
@@ -115,19 +116,20 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
strncpy(buf, upi->input.keys[i].name, ULOGD_MAX_KEYLEN);
while ((underscore = strchr(buf, '.')))
*underscore = '_';
- sprintf(mi->stmt_val, "%s,", buf);
- mi->stmt_val = mi->stmt + strlen(mi->stmt);
+ sprintf(stmt_val, "%s,", buf);
+ stmt_val = mi->stmt + strlen(mi->stmt);
}
- *(mi->stmt_val - 1) = ')';
+ *(stmt_val - 1) = ')';
- sprintf(mi->stmt_val, " values (");
+ sprintf(stmt_val, " values (");
} else if (strncasecmp(procedure,"CALL", strlen("CALL")) == 0) {
sprintf(mi->stmt, "CALL %s(", procedure);
} else {
sprintf(mi->stmt, "SELECT %s(", procedure);
}
- mi->stmt_val = mi->stmt + strlen(mi->stmt);
+
+ mi->stmt_offset = strlen(mi->stmt);
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", mi->stmt);
@@ -266,7 +268,7 @@ static void __format_query_db(struct ulogd_pluginstance *upi)
unsigned int i;
- char * stmt_ins = di->stmt_val;
+ char * stmt_ins = di->stmt + di->stmt_offset;
for (i = 0; i < upi->input.num_keys; i++) {
struct ulogd_key *res = upi->input.keys[i].u.source;
--
1.7.10.4
next prev parent reply other threads:[~2013-05-10 6:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-10 6:48 [PATCH RFC 0/11] ulogd2 db rework Eric Leblond
2013-05-10 6:48 ` [PATCH 01/11] ulogd: display stack during configuration Eric Leblond
2013-05-10 6:48 ` [PATCH 02/11] Fix automagic support of dbi, pcap and sqlite3 Eric Leblond
2013-05-10 6:48 ` [PATCH 03/11] postgresql: add sanity checking Eric Leblond
2013-05-10 6:48 ` [PATCH 04/11] mysql: " Eric Leblond
2013-05-10 6:48 ` [PATCH 05/11] sqlite3: " Eric Leblond
2013-05-10 6:48 ` [PATCH 06/11] db: store data in memory during database downtime Eric Leblond
2013-05-10 6:48 ` [PATCH 07/11] db: suppress field in db structure Eric Leblond
2013-05-10 6:48 ` Eric Leblond [this message]
2013-05-10 6:48 ` [PATCH 09/11] db: add ring buffer for DB query Eric Leblond
2013-05-11 19:29 ` Pablo Neira Ayuso
2013-05-12 10:29 ` Eric Leblond
2013-05-21 13:38 ` Pablo Neira Ayuso
2013-05-10 6:48 ` [PATCH 10/11] db: disable SIGHUP if ring buffer is used Eric Leblond
2013-05-10 6:48 ` [PATCH 11/11] db: db ring has precedence over backlog Eric Leblond
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1368168538-29780-9-git-send-email-eric@regit.org \
--to=eric@regit.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).