Beispiel #1
0
static int
sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client,
                                     char *line, sdb_unixsock_client_data_cb callback,
                                     sdb_object_t *user_data, const char *delim,
                                     int column_count, int *types)
{
    sdb_data_t data[column_count];
    char *orig_line = line;

    int i;

    assert(column_count > 0);

    for (i = 0; i < column_count; ++i) {
        char *next;

        if (! line) { /* this must not happen */
            sdb_log(SDB_LOG_ERR, "unixsock: Unexpected EOL while "
                    "parsing line (expected %i columns delimited by '%s'; "
                    "got %i): %s", column_count, delim,
                    /* last line number */ i, orig_line);
            return -1;
        }

        if ((delim[0] == '\0') || (delim[1] == '\0'))
            next = strchr(line, (int)delim[0]);
        else
            next = strpbrk(line, delim);

        if (next) {
            *next = '\0';
            ++next;
        }

        if (types && (types[i] != SDB_TYPE_STRING)) {
            if (sdb_data_parse(line, types[i], &data[i]))
                return -1;
        }
        else {
            /* Avoid a copy in common cases */
            data[i].type = SDB_TYPE_STRING;
            data[i].data.string = line;
        }

        line = next;
    }

    if (callback(client, (size_t)column_count, data, user_data))
        return -1;

    for (i = 0; i < column_count; ++i)
        if (types && (types[i] != SDB_TYPE_STRING))
            sdb_data_free_datum(&data[i]);
    return 0;
} /* sdb_unixsock_client_process_one_line */
Beispiel #2
0
Datei: ast.c Projekt: sysdb/sysdb
static void
store_destroy(sdb_object_t *obj)
{
	sdb_ast_store_t *store = SDB_AST_STORE(obj);
	if (store->hostname)
		free(store->hostname);
	if (store->parent)
		free(store->parent);
	if (store->name)
		free(store->name);
	store->hostname = store->parent = store->name = NULL;

	if (store->store_type)
		free(store->store_type);
	if (store->store_id)
		free(store->store_id);
	store->store_type = store->store_id = NULL;

	sdb_data_free_datum(&store->value);
} /* store_destroy */
Beispiel #3
0
Datei: ast.c Projekt: sysdb/sysdb
static void
const_destroy(sdb_object_t *obj)
{
	sdb_ast_const_t *c = SDB_AST_CONST(obj);
	sdb_data_free_datum(&c->value);
} /* const_destroy */