/** * rasqal_free_row: * @row: query result row * * Destructor - Free a query result row object. */ void rasqal_free_row(rasqal_row* row) { if(!row) return; if(--row->usage) return; if(row->values) { int i; for(i = 0; i < row->size; i++) { if(row->values[i]) rasqal_free_literal(row->values[i]); } RASQAL_FREE(array, row->values); } if(row->order_values) { int i; for(i = 0; i < row->order_size; i++) { if(row->order_values[i]) rasqal_free_literal(row->order_values[i]); } RASQAL_FREE(array, row->order_values); } RASQAL_FREE(rasqal_row, row); }
void rasqal_free_row_compatible(rasqal_row_compatible* map) { if(!map) return; RASQAL_FREE(intarray, map->defined_in_map); RASQAL_FREE(rasqal_row_compatible, map); }
/** * rasqal_new_service_rowsource: * @world: world object * @query: query object * @service_uri: service URI * @query_string: query to send to service * @data_graphs: sequence of data graphs (or NULL) * @rs_flags: service rowsource flags * * INTERNAL - create a new rowsource that takes rows from a service * * All arguments are copied. * * Return value: new rowsource or NULL on failure */ rasqal_rowsource* rasqal_new_service_rowsource(rasqal_world *world, rasqal_query* query, raptor_uri* service_uri, const unsigned char* query_string, raptor_sequence* data_graphs, unsigned int rs_flags) { rasqal_service_rowsource_context* con = NULL; rasqal_service* svc = NULL; int flags = 0; int silent = (rs_flags & RASQAL_ENGINE_BITFLAG_SILENT); if(!world || !query_string) goto fail; svc = rasqal_new_service(query->world, service_uri, query_string, data_graphs); if(!svc) { if(!silent) goto fail; /* Silent errors so tidy up and return empty rowsource */ RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return rasqal_new_empty_rowsource(world, query); } con = RASQAL_CALLOC(rasqal_service_rowsource_context*, 1, sizeof(*con)); if(!con) goto fail; con->svc = svc; con->query = query; con->flags = rs_flags; return rasqal_new_rowsource_from_handler(world, query, con, &rasqal_service_rowsource_handler, query->vars_table, flags); fail: if(svc) rasqal_free_service(svc); if(con) RASQAL_FREE(rasqal_service_rowsource_context, con); if(query_string) RASQAL_FREE(cstring, query_string); if(data_graphs) raptor_free_sequence(data_graphs); return NULL; }
void rasqal_free_triples_source(rasqal_triples_source *rts) { if(!rts) return; if(rts->user_data) { rts->free_triples_source(rts->user_data); RASQAL_FREE(user_data, rts->user_data); rts->user_data = NULL; } RASQAL_FREE(rasqal_triples_source, rts); }
/** * rasqal_free_variable: * @v: #rasqal_variable object * * Destructor - Destroy a Rasqal variable object. * **/ void rasqal_free_variable(rasqal_variable* v) { if(!v) return; if(v->name) RASQAL_FREE(cstring, (void*)v->name); if(v->value) rasqal_free_literal(v->value); if(v->expression) rasqal_free_expression(v->expression); RASQAL_FREE(rasqal_variable, v); }
static int rasqal_aggregation_rowsource_finish(rasqal_rowsource* rowsource, void *user_data) { rasqal_aggregation_rowsource_context* con; con = (rasqal_aggregation_rowsource_context*)user_data; if(con->expr_data) { int i; for(i = 0; i < con->expr_count; i++) { rasqal_agg_expr_data* expr_data = &con->expr_data[i]; if(expr_data->agg_user_data) rasqal_builtin_agg_expression_execute_finish(expr_data->agg_user_data); if(expr_data->exprs_seq) raptor_free_sequence(expr_data->exprs_seq); if(expr_data->expr) rasqal_free_expression(expr_data->expr); if(expr_data->map) rasqal_free_map(expr_data->map); } RASQAL_FREE(rasqal_agg_expr_data, con->expr_data); } if(con->exprs_seq) raptor_free_sequence(con->exprs_seq); if(con->vars_seq) raptor_free_sequence(con->vars_seq); if(con->rowsource) rasqal_free_rowsource(con->rowsource); if(con->saved_row) rasqal_free_row(con->saved_row); if(con->input_values) raptor_free_sequence(con->input_values); RASQAL_FREE(rasqal_aggregation_rowsource_context, con); return 0; }
static void rasqal_service_content_type_handler(raptor_www* www, void* userdata, const char* content_type) { rasqal_service* svc = (rasqal_service*)userdata; size_t len; if(svc->content_type) RASQAL_FREE(cstring, svc->content_type); len = strlen(content_type) + 1; svc->content_type = (char*)RASQAL_MALLOC(cstring, len); if(svc->content_type) { char* p; memcpy(svc->content_type, content_type, len); for(p = svc->content_type; *p; p++) { if(*p == ';' || *p == ' ') { *p = '\0'; break; } } } }
/** * rasqal_new_variable_from_variable: * @v: #rasqal_variable to copy * * Copy Constructor - Create a new Rasqal variable from an existing one * * This does a deep copy of all variable fields * * Return value: a new #rasqal_variable or NULL on failure. **/ rasqal_variable* rasqal_new_variable_from_variable(rasqal_variable* v) { rasqal_variable* new_v; size_t name_len; unsigned char *new_name; new_v = (rasqal_variable*)RASQAL_CALLOC(rasqal_variable, 1, sizeof(rasqal_variable)); if(!new_v) return NULL; name_len = strlen((const char*)v->name); new_name = (unsigned char*)RASQAL_MALLOC(cstring, name_len+1); if(!new_name) { RASQAL_FREE(rasqal_variable, new_v); return NULL; } memcpy(new_name, v->name, name_len+1); new_v->vars_table = v->vars_table; new_v->name= new_name; new_v->value= rasqal_new_literal_from_literal(v->value); new_v->offset= v->offset; new_v->type= v->type; new_v->expression= rasqal_new_expression_from_expression(v->expression); return new_v; }
/** * rasqal_world_set_default_generate_bnodeid_parameters: * @world: #rasqal_world object * @prefix: prefix string * @base: integer base identifier * * Set default bnodeid generation parameters * * Sets the parameters for the default algorithm used to generate * blank node IDs. The default algorithm uses both @prefix and @base * to generate a new identifier. The exact identifier generated is * not guaranteed to be a strict concatenation of @prefix and @base * but will use both parts. * * For finer control of the generated identifiers, use * rasqal_world_set_generate_bnodeid_handler() * * If prefix is NULL, the default prefix is used (currently "bnodeid") * If base is less than 1, it is initialised to 1. * * Return value: non-0 on failure **/ int rasqal_world_set_default_generate_bnodeid_parameters(rasqal_world* world, char *prefix, int base) { char *prefix_copy = NULL; size_t length = 0; RASQAL_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, rasqal_world, 1); if(--base < 0) base = 0; if(prefix) { length = strlen(prefix); prefix_copy = (char*)RASQAL_MALLOC(cstring, length + 1); if(!prefix_copy) return 1; memcpy(prefix_copy, prefix, length + 1); } if(world->default_generate_bnodeid_handler_prefix) RASQAL_FREE(cstring, world->default_generate_bnodeid_handler_prefix); world->default_generate_bnodeid_handler_prefix = prefix_copy; world->default_generate_bnodeid_handler_prefix_length = length; world->default_generate_bnodeid_handler_base = base; return 0; }
static void rasqal_engine_rowsort_free_compare_data(const void* user_data) { rowsort_compare_data* rcd = (rowsort_compare_data*)user_data; RASQAL_FREE(rowsort_compare_data, rcd); }
static rasqal_literal* rasqal_builtin_agg_expression_execute_result(void* user_data) { rasqal_builtin_agg_expression_execute* b; b = (rasqal_builtin_agg_expression_execute*)user_data; if(b->expr->op == RASQAL_EXPR_COUNT) { rasqal_literal* result; result = rasqal_new_integer_literal(b->world, RASQAL_LITERAL_INTEGER, b->count); return result; } if(b->expr->op == RASQAL_EXPR_GROUP_CONCAT) { size_t len; unsigned char* str; rasqal_literal* result; len = raptor_stringbuffer_length(b->sb); str = (unsigned char*)RASQAL_MALLOC(cstring, len + 1); if(!str) return NULL; if(raptor_stringbuffer_copy_to_string(b->sb, str, len)) { RASQAL_FREE(cstring, str); return NULL; } result = rasqal_new_string_literal(b->world, str, NULL, NULL, NULL); return result; } if(b->expr->op == RASQAL_EXPR_AVG) { rasqal_literal* count_l; rasqal_literal* result; count_l = rasqal_new_integer_literal(b->world, RASQAL_LITERAL_INTEGER, b->count); result = rasqal_literal_divide(b->l, count_l, &b->error); rasqal_free_literal(count_l); if(b->error) { /* result will be NULL and error will be non-0 on division by 0 * in which case the result is literal(integer 0) */ result = rasqal_new_integer_literal(b->world, RASQAL_LITERAL_INTEGER, 0); } return result; } return rasqal_new_literal_from_literal(b->l); }
/** * rasqal_free_query_results_formatter: * @formatter: #rasqal_query_results_formatter object * * Destructor - destroy a #rasqal_query_results_formatter object. **/ void rasqal_free_query_results_formatter(rasqal_query_results_formatter* formatter) { if(!formatter) return; RASQAL_FREE(rasqal_query_results_formatter, formatter); }
void rasqal_free_query_results_format_factory(rasqal_query_results_format_factory* factory) { if(!factory) return; RASQAL_FREE(query_results_format_factory, factory); }
static void free_compare_query_results(compare_query_results* cqr) { if(!cqr) return; RASQAL_FREE(compare_query_results, cqr); }
static void raptor_free_avltree_iterator(raptor_avltree_iterator* iterator) { if(!iterator) return; RASQAL_FREE(iterator, iterator); }
static void rasqal_xsd_decimal_clear_string(rasqal_xsd_decimal* dec) { if(dec->string) { RASQAL_FREE(cstring, dec->string); dec->string=NULL; } dec->string_len=0; }
static int rasqal_empty_rowsource_finish(rasqal_rowsource* rowsource, void *user_data) { rasqal_empty_rowsource_context* con; con = (rasqal_empty_rowsource_context*)user_data; RASQAL_FREE(rasqal_empty_rowsource_context, con); return 0; }
/** * rasqal_free_xsd_decimal: * @dec: Decimal object * * Destroy XSD Decimal object. **/ void rasqal_free_xsd_decimal(rasqal_xsd_decimal* dec) { if(!dec) return; rasqal_xsd_decimal_clear(dec); RASQAL_FREE(decimal, dec); }
void rasqal_log_error_varargs(rasqal_world* world, raptor_log_level level, raptor_locator* locator, const char* message, va_list arguments) { char *buffer; size_t length; raptor_log_message logmsg; raptor_log_handler handler = world->log_handler; void* handler_data = world->log_handler_user_data; if(level == RAPTOR_LOG_LEVEL_NONE) return; buffer=raptor_vsnprintf(message, arguments); if(!buffer) { if(locator) { raptor_locator_print(locator, stderr); fputc(' ', stderr); } fputs("rasqal ", stderr); fputs(rasqal_log_level_labels[level], stderr); fputs(" - ", stderr); vfprintf(stderr, message, arguments); fputc('\n', stderr); return; } length=strlen(buffer); if(buffer[length-1]=='\n') buffer[length-1]='\0'; if(handler) { /* This is the single place in rasqal that the user error handler * functions are called. */ /* raptor2 raptor_log_handler */ logmsg.code = -1; /* no information to put as code */ logmsg.level = level; logmsg.locator = locator; logmsg.text = buffer; handler(handler_data, &logmsg); } else { if(locator) { raptor_locator_print(locator, stderr); fputc(' ', stderr); } fputs("rasqal ", stderr); fputs(rasqal_log_level_labels[level], stderr); fputs(" - ", stderr); fputs(buffer, stderr); fputc('\n', stderr); } RASQAL_FREE(cstring, buffer); }
/** * rasqal_free_service: * @svc: #rasqal_service object * * Destructor - destroy a #rasqal_service object. **/ void rasqal_free_service(rasqal_service* svc) { if(!svc) return; if(svc->service_uri) raptor_free_uri(svc->service_uri); if(svc->query_string) RASQAL_FREE(cstring, svc->query_string); if(svc->data_graphs) raptor_free_sequence(svc->data_graphs); rasqal_service_set_www(svc, NULL); RASQAL_FREE(rasqal_service, svc); }
static void raptor_free_avltree(raptor_avltree* tree) { if(!tree) return; if(tree->seq) raptor_free_sequence(tree->seq); RASQAL_FREE(avltree, tree); }
/** * rasqal_free_query_results: * @query_results: #rasqal_query_results object * * Destructor - destroy a rasqal_query_results. * **/ void rasqal_free_query_results(rasqal_query_results* query_results) { rasqal_query* query; if(!query_results) return; query = query_results->query; if(query_results->executed) { if(query_results->execution_factory->execute_finish) { rasqal_engine_error execution_error = RASQAL_ENGINE_OK; query_results->execution_factory->execute_finish(query_results->execution_data, &execution_error); /* ignoring failure of execute_finish */ } } if(query_results->execution_data) RASQAL_FREE(rasqal_engine_execution_data, query_results->execution_data); if(query_results->row) rasqal_free_row(query_results->row); if(query_results->results_sequence) raptor_free_sequence(query_results->results_sequence); /* free terms owned by static query_results->result_triple */ raptor_free_statement(&query_results->result_triple); if(query_results->triple) rasqal_free_triple(query_results->triple); if(query_results->vars_table) rasqal_free_variables_table(query_results->vars_table); if(query) rasqal_query_remove_query_result(query, query_results); RASQAL_FREE(rasqal_query_results, query_results); }
/* * rasqal_free_projection: * @projection: #rasqal_projection object * * INTERNAL - Free a projection object. * **/ void rasqal_free_projection(rasqal_projection* projection) { if(!projection) return; if(projection->variables) raptor_free_sequence(projection->variables); RASQAL_FREE(rasqal_projection, projection); }
static void rasqal_free_triples_match(rasqal_triples_match* rtm) { if(!rtm) return; if(!rtm->is_exact) rtm->finish(rtm, rtm->user_data); RASQAL_FREE(rasqal_triples_match, rtm); }
/* * rasqal_free_query_language_factory - delete a query language factory */ static void rasqal_free_query_language_factory(rasqal_query_language_factory *factory) { if(!factory) return; if(factory->finish_factory) factory->finish_factory(factory); RASQAL_FREE(rasqal_query_language_factory, factory); }
void rasqal_free_formula(rasqal_formula* formula) { if(!formula) return; if(formula->triples) raptor_free_sequence(formula->triples); if(formula->value) rasqal_free_literal(formula->value); RASQAL_FREE(rasqal_formula, formula); }
static void rasqal_read_stringbuffer_iostream_finish(void *user_data) { struct rasqal_read_stringbuffer_iostream_context* con; con = (struct rasqal_read_stringbuffer_iostream_context*)user_data; if(con->sb) raptor_free_stringbuffer(con->sb); RASQAL_FREE(rasqal_read_stringbuffer_iostream_context, con); return; }
/** * rasqal_free_variables_table: * @vt: rasqal variables table * * Destructor - destroy a new variables table */ void rasqal_free_variables_table(rasqal_variables_table* vt) { if(!vt) return; if(--vt->usage) return; if(vt->variables) RASQAL_FREE(vararray, vt->variables); if(vt->anon_variables_sequence) raptor_free_sequence(vt->anon_variables_sequence); if(vt->variables_sequence) raptor_free_sequence(vt->variables_sequence); if(vt->variable_names) RASQAL_FREE(cstrings, vt->variable_names); RASQAL_FREE(rasqal_variables_table, vt); }
static void rasqal_free_groupby_tree_node(rasqal_groupby_tree_node* node) { if(!node) return; if(node->literals) raptor_free_sequence(node->literals); if(node->rows) raptor_free_sequence(node->rows); RASQAL_FREE(rasqal_groupby_tree_node, node); }
/* * rasqal_free_solution_modifier: * @sm: #rasqal_solution_modifier object * * INTERNAL - Free a solution modifier object. * **/ void rasqal_free_solution_modifier(rasqal_solution_modifier* sm) { if(!sm) return; if(sm->order_conditions) raptor_free_sequence(sm->order_conditions); if(sm->group_conditions) raptor_free_sequence(sm->group_conditions); RASQAL_FREE(rasqal_solution_modifier, sm); }