summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 99ba555)
raw | patch | inline | side by side (parent: 99ba555)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 12 Dec 2012 05:15:11 +0000 (06:15 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 12 Dec 2012 05:15:11 +0000 (06:15 +0100) |
This may be used to access, for example, state information throughout each
call.
call.
index 6cc68d3f44c102952a18e102aa30bf6dca697125..4397e8760ed5c6d402cec0a5e1b796c52228041e 100644 (file)
static int
sc_puppet_stcfg_get_data(sc_dbi_client_t __attribute__((unused)) *client,
- size_t n, sc_data_t *data)
+ size_t n, sc_data_t *data,
+ sc_object_t __attribute__((unused)) *user_data)
{
sc_host_t host = SC_HOST_INIT;
client = SC_OBJ_WRAPPER(user_data)->data;
if (sc_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;",
- sc_puppet_stcfg_get_data, /* #columns = */ 2,
+ sc_puppet_stcfg_get_data, NULL, /* #columns = */ 2,
/* col types = */ SC_TYPE_STRING, SC_TYPE_DATETIME)) {
fprintf(stderr, "puppet storeconfigs backend: Failed to retrieve "
"hosts from the storeconfigs DB.\n");
index 0f2a157c28dca42ab965a075e77a126bd94cb7ee..b910b977551558e97dc77105b631acc70412044d 100644 (file)
--- a/src/include/utils/dbi.h
+++ b/src/include/utils/dbi.h
#ifndef SC_UTILS_DBI_H
#define SC_UTILS_DBI_H 1
+#include "core/object.h"
#include "utils/data.h"
#include <stddef.h>
struct sc_dbi_client;
typedef struct sc_dbi_client sc_dbi_client_t;
-typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *, size_t, sc_data_t *);
+typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *,
+ size_t, sc_data_t *, sc_object_t *);
/*
* sc_dbi_options_t:
*/
int
sc_dbi_exec_query(sc_dbi_client_t *client, const char *query,
- sc_dbi_data_cb callback, int n, ...);
+ sc_dbi_data_cb callback, sc_object_t *user_data, int n, ...);
/*
* sc_dbi_client_destroy:
index f1f7691a9a0490d6c2107871f8343ac284272806..31a423efb9907597308e4c691c38998b8219da65 100644 (file)
#ifndef SC_UTILS_UNIXSOCK_H
#define SC_UTILS_UNIXSOCK_H 1
+#include "core/object.h"
#include "utils/data.h"
#include <sys/socket.h>
typedef struct sc_unixsock_client sc_unixsock_client_t;
typedef int (*sc_unixsock_client_data_cb)(sc_unixsock_client_t *,
- size_t, sc_data_t *);
+ size_t, sc_data_t *, sc_object_t *);
sc_unixsock_client_t *
sc_unixsock_client_create(const char *path);
*/
int
sc_unixsock_client_process_lines(sc_unixsock_client_t *client,
- sc_unixsock_client_data_cb callback, long int max_lines,
- const char *delim, int n_cols, ...);
+ sc_unixsock_client_data_cb callback, sc_object_t *user_data,
+ long int max_lines, const char *delim, int n_cols, ...);
/*
* sc_unixsock_client_shutdown:
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index bd58ce7b4b9d12d7a6226da3dc061e2582f0712d..d7398de15821725af5420ce5e7de8a422bf24c1f 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
static int
sc_dbi_get_data(sc_dbi_client_t *client, dbi_result res,
- unsigned int num_fields, sc_dbi_data_cb callback)
+ unsigned int num_fields, sc_dbi_data_cb callback,
+ sc_object_t *user_data)
{
sc_data_t data[num_fields];
int types[num_fields];
types[i], &data[i]))
continue;
- if (callback(client, num_fields, data))
+ if (callback(client, num_fields, data, user_data))
continue;
++success;
int
sc_dbi_exec_query(sc_dbi_client_t *client, const char *query,
- sc_dbi_data_cb callback, int n, ...)
+ sc_dbi_data_cb callback, sc_object_t *user_data, int n, ...)
{
dbi_result res;
unsigned int num_fields;
return 0;
}
- status = sc_dbi_get_data(client, res, num_fields, callback);
+ status = sc_dbi_get_data(client, res, num_fields, callback, user_data);
dbi_result_free(res);
return status;
diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c
index db025f80f9f654ffc70d528c8b870b3c62b97768..da2ca1e4a71928ab3c356d7df506d7261fab6310 100644 (file)
--- a/src/utils/unixsock.c
+++ b/src/utils/unixsock.c
static int
sc_unixsock_client_process_one_line(sc_unixsock_client_t *client,
char *line, sc_unixsock_client_data_cb callback,
- const char *delim, int column_count, int *types)
+ sc_object_t *user_data, const char *delim,
+ int column_count, int *types)
{
sc_data_t data[column_count];
char *orig_line = line;
line = next;
}
- if (callback(client, (size_t)column_count, data))
+ if (callback(client, (size_t)column_count, data, user_data))
return -1;
return 0;
} /* sc_unixsock_client_process_one_line */
@@ -310,8 +311,8 @@ sc_unixsock_client_recv(sc_unixsock_client_t *client, char *buffer, size_t bufle
int
sc_unixsock_client_process_lines(sc_unixsock_client_t *client,
- sc_unixsock_client_data_cb callback, long int max_lines,
- const char *delim, int n_cols, ...)
+ sc_unixsock_client_data_cb callback, sc_object_t *user_data,
+ long int max_lines, const char *delim, int n_cols, ...)
{
int *types = NULL;
int success = 0;
continue;
if (! sc_unixsock_client_process_one_line(client, line, callback,
- delim, column_count, types))
+ user_data, delim, column_count, types))
++success;
}