Beispiel #1
0
static void my_fld_free(db_fld_t* fld, struct my_fld* payload)
{
	db_drv_free(&payload->gen);
	if (payload->buf.s) pkg_free(payload->buf.s);
	if (payload->name) pkg_free(payload->name);
	pkg_free(payload);
}
Beispiel #2
0
static void flat_uri_free(db_uri_t* uri, struct flat_uri* payload)
{
	if (payload == NULL) return;
	if (payload->path.s) free(payload->path.s);
	db_drv_free(&payload->drv);
	pkg_free(payload);
}
Beispiel #3
0
static void ld_res_free(db_res_t* res, struct ld_res* payload)
{
	db_drv_free(&payload->gen);
	if (payload->msg) ldap_msgfree(payload->msg);
	payload->msg = NULL;
	pkg_free(payload);
}
Beispiel #4
0
int flat_uri(db_uri_t* uri)
{
	struct flat_uri* furi;

	if ((furi = (struct flat_uri*)pkg_malloc(sizeof(*furi))) == NULL) {
		ERR("flatstore: No memory left\n");
		return -1;
	}
	memset(furi, '\0', sizeof(*furi));
	if (db_drv_init(&furi->drv, flat_uri_free) < 0) goto error;

	if ((furi->path.s = get_abs_pathname(NULL, &uri->body)) == NULL) {
		ERR("flatstore: Error while obtaining absolute pathname for '%.*s'\n",
			STR_FMT(&uri->body));
		goto error;
	}
	furi->path.len = strlen(furi->path.s);

	DB_SET_PAYLOAD(uri, furi);
	return 0;

 error:
	if (furi) {
		if (furi->path.s) pkg_free(furi->path.s);
		db_drv_free(&furi->drv);
		pkg_free(furi);
	}
	return -1;	
}
Beispiel #5
0
int ld_uri(db_uri_t* uri)
{
	struct ld_uri* luri;

	luri = (struct ld_uri*)pkg_malloc(sizeof(struct ld_uri));
	if (luri == NULL) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(luri, '\0', sizeof(struct ld_uri));
	if (db_drv_init(&luri->drv, ld_uri_free) < 0) goto error;
    if (parse_ldap_uri(luri,  &uri->scheme, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, luri);
	uri->cmp = ld_uri_cmp;
	return 0;

 error:
	if (luri) {
		if (luri->uri) pkg_free(luri->uri);
		if (luri->ldap_url) ldap_free_urldesc(luri->ldap_url);
		db_drv_free(&luri->drv);
		pkg_free(luri);
	}
	return -1;
}
Beispiel #6
0
static void my_cmd_free(db_cmd_t* cmd, struct my_cmd* payload)
{
	db_drv_free(&payload->gen);
	if (payload->sql_cmd.s) pkg_free(payload->sql_cmd.s);
	if (payload->st) mysql_stmt_close(payload->st);
	pkg_free(payload);
}
Beispiel #7
0
static void bdb_fld_free(db_fld_t* fld, bdb_fld_t* payload)
{
	db_drv_free(&payload->gen);
	if (payload->buf.s) pkg_free(payload->buf.s);
	if (payload->name) pkg_free(payload->name);
	pkg_free(payload);
}
Beispiel #8
0
/** Frees memory used by a ld_fld structure.
 * This function frees all memory used by a ld_fld structure
 * @param fld Generic db_fld_t* structure being freed.
 * @param payload The ldap extension structure to be freed
 */
static void ld_fld_free(db_fld_t* fld, struct ld_fld* payload)
{
	db_drv_free(&payload->gen);
	if (payload->values) ldap_value_free_len(payload->values);	
	payload->values = NULL;
	if (payload->filter) pkg_free(payload->filter);
	payload->filter = NULL;
	pkg_free(payload);
}
Beispiel #9
0
/** Destroys a bdb_cmd structure.
 * This function frees all memory used by ld_cmd structure.
 * @param cmd A pointer to generic db_cmd command being freed.
 * @param payload A pointer to ld_cmd structure to be freed.
 */
static void bdb_cmd_free(db_cmd_t *cmd, bdb_cmd_t *payload)
{
	db_drv_free(&payload->gen);
	if(payload->dbcp)
		payload->dbcp->CLOSE_CURSOR(payload->dbcp);
	if(payload->skey.s)
		pkg_free(payload->skey.s);
	pkg_free(payload);
}
Beispiel #10
0
/** Destroys a pg_cmd structure.
 * This function frees all memory used by pg_cmd structure.
 * @param cmd A pointer to generic db_cmd command being freed.
 * @param payload A pointer to pg_cmd structure to be freed.
 */
static void pg_cmd_free(db_cmd_t* cmd, struct pg_cmd* payload)
{
	db_drv_free(&payload->gen);
	if (payload->sql_cmd.s) pkg_free(payload->sql_cmd.s);
	free_pg_params(&payload->params);
	if (payload->name) pkg_free(payload->name);
	if (payload->types) PQclear(payload->types);
	pkg_free(payload);
}
Beispiel #11
0
static void pg_uri_free(db_uri_t* uri, struct pg_uri* payload)
{
	if (payload == NULL) return;
	db_drv_free(&payload->drv);
	if (payload->username) pkg_free(payload->username);
	if (payload->password) pkg_free(payload->password);
	if (payload->host) pkg_free(payload->host);
	if (payload->database) pkg_free(payload->database);
	pkg_free(payload);
}
Beispiel #12
0
static void ld_uri_free(db_uri_t* uri, struct ld_uri* payload)
{
	if (payload == NULL) return;
	if (payload->ldap_url) ldap_free_urldesc(payload->ldap_url);
	if (payload->uri) pkg_free(payload->uri);
    if (payload->username) pkg_free(payload->username);
    if (payload->password) pkg_free(payload->password);
    if (payload->ca_list) pkg_free(payload->ca_list);
    if (payload->req_cert) pkg_free(payload->req_cert);
	db_drv_free(&payload->drv);
	pkg_free(payload);
}
Beispiel #13
0
int bdb_cmd(db_cmd_t *cmd)
{
	bdb_cmd_t *bcmd;
	db_con_t *con;
	bdb_con_t *bcon;

	bcmd = (bdb_cmd_t *)pkg_malloc(sizeof(bdb_cmd_t));
	if(bcmd == NULL) {
		ERR("bdb: No memory left\n");
		goto error;
	}
	memset(bcmd, '\0', sizeof(bdb_cmd_t));
	if(db_drv_init(&bcmd->gen, bdb_cmd_free) < 0)
		goto error;

	con = cmd->ctx->con[db_payload_idx];
	bcon = DB_GET_PAYLOAD(con);
	bcmd->bcon = bcon;

	switch(cmd->type) {
		case DB_PUT:
		case DB_DEL:
		case DB_UPD:
			ERR("bdb: The driver does not support DB modifications yet.\n");
			goto error;
			break;

		case DB_GET:
			if(bdb_prepare_query(cmd, bcmd) != 0) {
				ERR("bdb: error preparing query.\n");
				goto error;
			}
			break;

		case DB_SQL:
			ERR("bdb: The driver does not support raw queries yet.\n");
			goto error;
	}

	DB_SET_PAYLOAD(cmd, bcmd);
	return 0;

error:
	if(bcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&bcmd->gen);
		pkg_free(bcmd);
	}
	return -1;
}
Beispiel #14
0
void my_res_free(db_res_t* res, struct my_res* payload)
{
	struct my_cmd* mcmd;

	mcmd = DB_GET_PAYLOAD(res->cmd);

	if (mcmd->st && mysql_stmt_free_result(mcmd->st)) {
		ERR("mysql: Error while freeing MySQL result: %d, %s\n",
			mysql_stmt_errno(mcmd->st), mysql_stmt_error(mcmd->st));
	}

	db_drv_free(&payload->gen);
	pkg_free(payload);
}
Beispiel #15
0
void bdb_res_free(db_res_t* res, bdb_res_t *payload)
{
	bdb_cmd_t *bcmd;

	bcmd = DB_GET_PAYLOAD(res->cmd);

	/* free bdb result */

	if(bcmd->dbcp!=NULL)
	{
		bcmd->dbcp->CLOSE_CURSOR(bcmd->dbcp);
		bcmd->dbcp = NULL;
	}
	db_drv_free(&payload->gen);
	pkg_free(payload);
}
Beispiel #16
0
/*
 * Attach bdb specific structure to db_res, this structure contains a pointer
 * to bdb_res_free which releases the result stored in the oracle statement
 * and if there is a cursor open in the statement then it will be closed as well
 */
int bdb_res(db_res_t* res)
{
	bdb_res_t *br;

	br = (bdb_res_t*)pkg_malloc(sizeof(bdb_res_t));
	if (br == NULL) {
		ERR("bdb: No memory left\n");
		return -1;
	}
	if (db_drv_init(&br->gen, bdb_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, br);
	return 0;
	
error:
	if (br) {
		db_drv_free(&br->gen);
		pkg_free(br);
	}
	return -1;
}
Beispiel #17
0
/*
 * Attach a mysql specific structure to db_res, this structure contains a pointer
 * to my_res_free which releases the mysql result stored in the mysql statement
 * and if there is a cursor open in the statement then it will be closed as well
 */
int my_res(db_res_t* res)
{
	struct my_res* mr;

	mr = (struct my_res*)pkg_malloc(sizeof(struct my_res));
	if (mr == NULL) {
		ERR("mysql: No memory left\n");
		return -1;
	}
	if (db_drv_init(&mr->gen, my_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, mr);
	return 0;

error:
	if (mr) {
		db_drv_free(&mr->gen);
		pkg_free(mr);
	}
	return -1;
}
Beispiel #18
0
int ld_res(db_res_t* res)
{
	struct ld_res* lres;

	lres = (struct ld_res*)pkg_malloc(sizeof(struct ld_res));
	if (lres == NULL) {
		ERR("ldap: No memory left\n");
		return -1;
	}
	memset(lres, '\0', sizeof(struct ld_res));
	if (db_drv_init(&lres->gen, ld_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, lres);
	return 0;
	
 error:
	if (lres) {
		db_drv_free(&lres->gen);
		pkg_free(lres);
	}
	return -1;
}
Beispiel #19
0
int flat_cmd(db_cmd_t* cmd)
{
	struct flat_cmd* fcmd;
	db_con_t* con;

	if (cmd->type != DB_PUT) {
		ERR("flatstore: The driver supports PUT operation only.\n");
		return -1;
	}

	if (DB_FLD_EMPTY(cmd->vals)) {
		ERR("flatstore: PUT command with no values encountered\n");
		return -1;
	}

	fcmd = (struct flat_cmd*)pkg_malloc(sizeof(struct flat_cmd));
	if (fcmd == NULL) {
		ERR("flatstore: No memory left\n");
		return -1;
	}
	memset(fcmd, '\0', sizeof(struct flat_cmd));
	if (db_drv_init(&fcmd->gen, flat_cmd_free) < 0) goto error;

	/* FIXME */
	con = cmd->ctx->con[db_payload_idx];
	if (flat_open_table(&fcmd->file_index, con, &cmd->table) < 0) goto error;

	DB_SET_PAYLOAD(cmd, fcmd);
	return 0;

 error:
	if (fcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&fcmd->gen);
		pkg_free(fcmd);
	}
	return -1;
}
Beispiel #20
0
int pg_uri(db_uri_t* uri)
{
	struct pg_uri* puri;

	puri = (struct pg_uri*)pkg_malloc(sizeof(struct pg_uri));
	if (puri == NULL) {
		ERR("postgres: No memory left\n");
		goto error;
	}
	memset(puri, '\0', sizeof(struct pg_uri));
	if (db_drv_init(&puri->drv, pg_uri_free) < 0) goto error;
	if (parse_postgres_uri(puri, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, puri);
	uri->cmp = pg_uri_cmp;
	return 0;

 error:
	if (puri) {
		db_drv_free(&puri->drv);
		if (puri) pkg_free(puri);
	}
	return -1;
}
Beispiel #21
0
int my_uri(db_uri_t* uri)
{
	struct my_uri* res;

	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
	if (res == NULL) {
		ERR("mysql: No memory left\n");
		goto error;
	}
	memset(res, '\0', sizeof(struct my_uri));
	if (db_drv_init(&res->drv, my_uri_free) < 0) goto error;
	if (parse_mysql_uri(res, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, res);
	uri->cmp = my_uri_cmp;
	return 0;

 error:
	if (res) {
		db_drv_free(&res->drv);
		if (res) pkg_free(res);
	}
	return -1;
}
Beispiel #22
0
/** Destroys a ld_cmd structure.
 * This function frees all memory used by ld_cmd structure.
 * @param cmd A pointer to generic db_cmd command being freed.
 * @param payload A pointer to ld_cmd structure to be freed.
 */
static void ld_cmd_free(db_cmd_t* cmd, struct ld_cmd* payload)
{
	db_drv_free(&payload->gen);
	if (payload->result) pkg_free(payload->result);
	pkg_free(payload);
}
Beispiel #23
0
int pg_cmd(db_cmd_t* cmd)
{
	struct pg_cmd* pcmd;
 
	pcmd = (struct pg_cmd*)pkg_malloc(sizeof(struct pg_cmd));
	if (pcmd == NULL) {
		ERR("postgres: No memory left\n");
		goto error;
	}
	memset(pcmd, '\0', sizeof(struct pg_cmd));
	if (db_drv_init(&pcmd->gen, pg_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
		if (build_insert_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;
		
	case DB_DEL:
		if (build_delete_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_GET:
		if (build_select_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_UPD:
		if (build_update_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;
		
	case DB_SQL:
		pcmd->sql_cmd.s = (char*)pkg_malloc(cmd->table.len + 1);
		if (pcmd->sql_cmd.s == NULL) {
			ERR("postgres: Out of private memory\n");
			goto error;
		}
		memcpy(pcmd->sql_cmd.s,cmd->table.s, cmd->table.len);
		pcmd->sql_cmd.s[cmd->table.len] = '\0';
		pcmd->sql_cmd.len = cmd->table.len;
        break;
	}

	DB_SET_PAYLOAD(cmd, pcmd);

	/* Create parameter arrays for PostgreSQL API functions */
	if (create_pg_params(cmd) < 0) goto error;	

	/* Generate a unique name for the command on the server */
	if (gen_cmd_name(cmd) != 0) goto error; 

	/* Upload the command to the server */
	if (upload_cmd(cmd) != 0) goto error;

	/* Obtain the description of the uploaded command, this includes
	 * information about result and parameter fields */
	if (get_types(cmd) != 0) goto error;

	/* Update fields based on the information retrieved from the */
	if (pg_resolve_param_oids(cmd->vals, cmd->match,
							  cmd->vals_count, cmd->match_count,
							  pcmd->types)) 
		goto error;
	if (pg_resolve_result_oids(cmd->result, cmd->result_count, pcmd->types)) 
		goto error;

	if (check_types(cmd)) goto error;

	return 0;

 error:
	if (pcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		free_pg_params(&pcmd->params);

		if (pcmd->types) PQclear(pcmd->types);
		if (pcmd->name) pkg_free(pcmd->name);
		if (pcmd->sql_cmd.s) pkg_free(pcmd->sql_cmd.s);

		db_drv_free(&pcmd->gen);
		pkg_free(pcmd);
	}
	return -1;
}
Beispiel #24
0
int my_cmd(db_cmd_t* cmd)
{
	struct my_cmd* res;
 
	res = (struct my_cmd*)pkg_malloc(sizeof(struct my_cmd));
	if (res == NULL) {
		ERR("mysql: No memory left\n");
		goto error;
	}
	memset(res, '\0', sizeof(struct my_cmd));
	/* Fetch all data to client at once by default */
	res->flags |= MY_FETCH_ALL;
	if (db_drv_init(&res->gen, my_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
		if (DB_FLD_EMPTY(cmd->vals)) {
			BUG("mysql: No parameters provided for DB_PUT in context '%.*s'\n", 
				cmd->ctx->id.len, ZSW(cmd->ctx->id.s));
			goto error;
		}
		if (build_replace_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_DEL:
		if (build_delete_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_GET:
		if (build_select_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_UPD:
		if (build_update_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_SQL:
		res->sql_cmd.s = (char*)pkg_malloc(cmd->table.len);
		if (res->sql_cmd.s == NULL) {
			ERR("mysql: Out of private memory\n");
			goto error;
		}
		memcpy(res->sql_cmd.s,cmd->table.s, cmd->table.len);
		res->sql_cmd.len = cmd->table.len;
        break;
	}

	DB_SET_PAYLOAD(cmd, res);

	/* In order to check all the parameters and results, we need to upload
	 * the command to the server. We need to do that here before we report
	 * back that the command was created successfully. Hence, this
	 * function requires the corresponding connection be established. We
	 * would not be able to check parameters if we don't do that there and
	 * that could result in repeated execution failures at runtime.
	 */
	if (upload_cmd(cmd)) goto error;
	return 0;

 error:
	if (res) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&res->gen);
		if (res->sql_cmd.s) pkg_free(res->sql_cmd.s);
		pkg_free(res);
	}
	return -1;
}
Beispiel #25
0
int ld_cmd(db_cmd_t* cmd)
{
	struct ld_cmd* lcmd;
	struct ld_cfg* cfg;
	struct ld_fld* lfld;
	int i, j;

	lcmd = (struct ld_cmd*)pkg_malloc(sizeof(struct ld_cmd));
	if (lcmd == NULL) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(lcmd, '\0', sizeof(struct ld_cmd));
	if (db_drv_init(&lcmd->gen, ld_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
	case DB_DEL:
	case DB_UPD:
		ERR("ldap: The driver does not support directory modifications yet.\n");
		goto error;
		break;

	case DB_GET:
		break;

	case DB_SQL:
		ERR("ldap: The driver does not support raw queries yet.\n");
		goto error;
	}

	cfg = ld_find_cfg(&cmd->table);
	if (cfg == NULL) {
		ERR("ldap: Cannot find configuration for '%.*s', giving up\n",
			STR_FMT(&cmd->table));
		goto error;
	}

	lcmd->base = cfg->base.s;
	lcmd->scope = cfg->scope;

	lcmd->sizelimit = cfg->sizelimit;
	if (cfg->timelimit) {
		lcmd->timelimit.tv_sec = cfg->timelimit;
		lcmd->timelimit.tv_usec = 0;
	}

	if (cfg->filter.s) {
		lcmd->filter = cfg->filter;
	}
	lcmd->chase_references = cfg->chase_references;
	lcmd->chase_referrals = cfg->chase_referrals;

	if (ld_resolve_fld(cmd->match, cfg) < 0) goto error;
	if (ld_resolve_fld(cmd->result, cfg) < 0) goto error;

	/* prepare filter for each result field */
	for(i = 0; !DB_FLD_EMPTY(cmd->result) && !DB_FLD_LAST(cmd->result[i]); i++) {
		int n;
		lfld = DB_GET_PAYLOAD(cmd->result + i);
		lfld->filter = NULL;
	
		for(j = 0, n = 0; !DB_FLD_EMPTY(cmd->match) && !DB_FLD_LAST(cmd->match[j]); j++) {
			if (strcmp(cmd->result[i].name, cmd->match[j].name) == 0)
				n++;	
		}
		
		if (n > 0) {
			lfld->filter = pkg_malloc((n+1)*sizeof(*(lfld->filter)));
			if (!lfld->filter) return -1 /* E_OUT_OF_MEM*/;
			for(j = 0, n = 0; !DB_FLD_EMPTY(cmd->match) && !DB_FLD_LAST(cmd->match[j]); j++) {
				if (strcmp(cmd->result[i].name, cmd->match[j].name) == 0) {
					lfld->filter[n] = cmd->match+j;
					n++;
				}
			}
			lfld->filter[n] = NULL;
		}
	}
	if (build_result_array(&lcmd->result, cmd) < 0) goto error;

	DB_SET_PAYLOAD(cmd, lcmd);
	return 0;

 error:
	if (lcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&lcmd->gen);
		if (lcmd->result) pkg_free(lcmd->result);
		pkg_free(lcmd);
	}
	return -1;
}
Beispiel #26
0
/** Destroys a flat_cmd structure.
 * This function frees all memory used by flat_cmd structure.
 * @param cmd A pointer to generic db_cmd command being freed.
 * @param payload A pointer to flat_cmd structure to be freed.
 */
static void flat_cmd_free(db_cmd_t* cmd, struct flat_cmd* payload)
{
	db_drv_free(&payload->gen);
	pkg_free(payload);
}