void raptor_rss_common_terminate(raptor_world* world) { int i; if(--world->rss_common_initialised) return; if(world->rss_types_info_uris) { for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) { if(world->rss_types_info_uris[i]) raptor_free_uri(world->rss_types_info_uris[i]); } RAPTOR_FREE(raptor_uri* array, world->rss_types_info_uris); world->rss_types_info_uris = NULL; } if(world->rss_fields_info_uris) { for(i = 0; i< RAPTOR_RSS_FIELDS_SIZE; i++) { if(world->rss_fields_info_uris[i]) raptor_free_uri(world->rss_fields_info_uris[i]); } RAPTOR_FREE(raptor_uri* array, world->rss_fields_info_uris); world->rss_fields_info_uris = NULL; } if(world->rss_namespaces_info_uris) { for(i = 0; i < RAPTOR_RSS_NAMESPACES_SIZE;i++) { if(world->rss_namespaces_info_uris[i]) raptor_free_uri(world->rss_namespaces_info_uris[i]); } RAPTOR_FREE(raptor_uri* array, world->rss_namespaces_info_uris); world->rss_namespaces_info_uris = NULL; } }
/** * raptor_new_uri_for_retrieval - Turn a URI into one suitable for retrieval * @old_uri: URI to transform * * Takes an existing URI and ensures it has a path (default /) and has * no fragment - URI retrieval does not use the fragment part. * * Return value: new URI object or NULL on failure. **/ raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri) { unsigned char *uri_string=raptor_uri_as_string(old_uri); unsigned char *buffer; size_t buffer_len=strlen((const char*)uri_string)+1; unsigned char *scheme; unsigned char *authority; unsigned char *path; unsigned char *query; unsigned char *fragment; unsigned char *new_uri_string; raptor_uri* new_uri; buffer=(unsigned char*)RAPTOR_MALLOC(cstring, buffer_len); if(!buffer) return NULL; raptor_uri_parse (uri_string, buffer, buffer_len, &scheme, &authority, &path, &query, &fragment); if(!path) path=(unsigned char*)"/"; new_uri_string=raptor_uri_construct(scheme, authority, path, query, NULL); RAPTOR_FREE(cstring, buffer); if(!new_uri_string) return NULL; new_uri=raptor_new_uri(new_uri_string); RAPTOR_FREE(cstring, new_uri_string); return new_uri; }
static int assert_uri_to_filename (const char *uri, const char *reference_filename) { char *filename; filename=raptor_uri_uri_string_to_filename((const unsigned char*)uri); if(filename && !reference_filename) { fprintf(stderr, "%s: raptor_uri_uri_string_to_filename(%s) FAILED giving filename %s != NULL\n", program, uri, filename); if(filename) RAPTOR_FREE(cstring, filename); return 1; } else if (filename && strcmp(filename, reference_filename)) { fprintf(stderr, "%s: raptor_uri_uri_string_to_filename(%s) FAILED gaving filename %s != %s\n", program, uri, filename, reference_filename); if(filename) RAPTOR_FREE(cstring, filename); return 1; } RAPTOR_FREE(cstring, filename); return 0; }
static int assert_uri_to_relative(const char *base, const char *uri, const char *relative) { unsigned char *output; int result; raptor_uri* base_uri=NULL; raptor_uri* reference_uri=raptor_new_uri((const unsigned char*)uri); size_t length=0; if(base) base_uri=raptor_new_uri((const unsigned char*)base); output=raptor_uri_to_relative_counted_uri_string(base_uri, reference_uri, &length); result=strcmp(relative, (const char*)output); if (result) { fprintf(stderr, "%s: raptor_uri_string_to_relative_uri_string FAILED: base='%s', uri='%s', expected='%s', got='%s'\n", program, base, uri, relative, output); RAPTOR_FREE(cstring, output); return 1; } RAPTOR_FREE(cstring, output); raptor_free_uri(base_uri); raptor_free_uri(reference_uri); return 0; }
void raptor_print_subject(raptor_abbrev_subject* subject) { int i; unsigned char *subj; unsigned char *pred; unsigned char *obj; raptor_avltree_iterator* iter=NULL; /* Note: The raptor_abbrev_node field passed as the first argument for * raptor_statement_part_as_string() is somewhat arbitrary, since as * the data structure is designed, the first word in the value union * is what was passed as the subject/predicate/object of the * statement. */ subj = raptor_statement_part_as_string(subject->node->value.resource.uri, subject->node->type, NULL, NULL); if(subject->type) { obj=raptor_statement_part_as_string(subject->type->value.resource.uri, subject->type->type, subject->type->value.literal.datatype, subject->type->value.literal.language); fprintf(stderr,"[%s, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, %s]\n", subj, obj); RAPTOR_FREE(cstring, obj); } for(i=0; i < raptor_sequence_size(subject->elements); i++) { raptor_abbrev_node* o = raptor_sequence_get_at(subject->elements, i); if(o) { obj = raptor_statement_part_as_string(o->value.literal.string, o->type, o->value.literal.datatype, o->value.literal.language); fprintf(stderr,"[%s, [rdf:_%d], %s]\n", subj, i, obj); RAPTOR_FREE(cstring, obj); } } iter=raptor_new_avltree_iterator(subject->properties, NULL, NULL, 1); while(iter) { raptor_abbrev_node** nodes; nodes=(raptor_abbrev_node**)raptor_avltree_iterator_get(iter); if(!nodes) break; raptor_print_abbrev_po(stderr, nodes); if(raptor_avltree_iterator_next(iter)) break; } if(iter) raptor_free_avltree_iterator(iter); RAPTOR_FREE(cstring, subj); }
void raptor_rss_field_free(raptor_rss_field* field) { if(field->value) RAPTOR_FREE(cstring, field->value); if(field->uri) raptor_free_uri(field->uri); if(field->next) raptor_rss_field_free(field->next); RAPTOR_FREE(raptor_rss_field, field); }
/** * raptor_new_iostream_to_string: * @string_p: pointer to location to hold string * @length_p: pointer to location to hold length of string (or NULL) * @malloc_handler: pointer to malloc to use to make string (or NULL) * * Constructor - create a new iostream writing to a string. * * If @malloc_handler is null, raptor will allocate it using it's * own memory allocator. *@string_p is set to NULL on failure (and * *@length_p to 0 if @length_p is not NULL). * * Return value: new #raptor_iostream object or NULL on failure **/ RAPTOR_EXTERN_C raptor_iostream* raptor_new_iostream_to_string(void **string_p, size_t *length_p, void *(*malloc_handler)(size_t size)) { raptor_iostream* iostr; struct raptor_write_string_iostream_context* con; const raptor_iostream_handler2* handler2=&raptor_iostream_write_string_handler; const unsigned int mode=RAPTOR_IOSTREAM_MODE_WRITE; if(!raptor_iostream_check_handler(handler2, mode)) return NULL; iostr=(raptor_iostream*)RAPTOR_CALLOC(raptor_iostream, 1, sizeof(raptor_iostream)); if(!iostr) return NULL; con=(struct raptor_write_string_iostream_context*)RAPTOR_CALLOC(raptor_write_string_iostream_context, 1, sizeof(struct raptor_write_string_iostream_context)); if(!con) { RAPTOR_FREE(raptor_iostream, iostr); return NULL; } con->sb=raptor_new_stringbuffer(); if(!con->sb) { RAPTOR_FREE(raptor_iostream, iostr); RAPTOR_FREE(raptor_write_string_iostream_context, con); return NULL; } con->string_p=string_p; *string_p=NULL; con->length_p=length_p; if(length_p) *length_p=0; if(malloc_handler) con->malloc_handler=malloc_handler; else con->malloc_handler=raptor_alloc_memory; iostr->handler=handler2; iostr->user_data=(void*)con; iostr->mode = mode; if(iostr->handler->init && iostr->handler->init(iostr->user_data)) { raptor_free_iostream(iostr); return NULL; } return iostr; }
/** * raptor_free_term: * @term: #raptor_term object * * Destructor - destroy a raptor_term object. * **/ void raptor_free_term(raptor_term *term) { if(!term) return; if(--term->usage) return; switch(term->type) { case RAPTOR_TERM_TYPE_URI: if(term->value.uri) { raptor_free_uri(term->value.uri); term->value.uri = NULL; } break; case RAPTOR_TERM_TYPE_BLANK: if(term->value.blank.string) { RAPTOR_FREE(cstring, (void*)term->value.blank.string); term->value.blank.string = NULL; } break; case RAPTOR_TERM_TYPE_LITERAL: if(term->value.literal.string) { RAPTOR_FREE(cstring, (void*)term->value.literal.string); term->value.literal.string = NULL; } if(term->value.literal.datatype) { raptor_free_uri(term->value.literal.datatype); term->value.literal.datatype = NULL; } if(term->value.literal.language) { RAPTOR_FREE(cstring, (void*)term->value.literal.language); term->value.literal.language = NULL; } break; case RAPTOR_TERM_TYPE_UNKNOWN: default: break; } RAPTOR_FREE(term, (void*)term); }
/** * raptor_free_iostream: * @iostr: iostream object * * Destructor - destroy an iostream. **/ void raptor_free_iostream(raptor_iostream *iostr) { RAPTOR_ASSERT_OBJECT_POINTER_RETURN(iostr, raptor_iostream); if(iostr->flags & RAPTOR_IOSTREAM_FLAGS_EOF) raptor_iostream_write_end(iostr); if(iostr->handler->finish) iostr->handler->finish(iostr->user_data); if((iostr->flags & RAPTOR_IOSTREAM_FLAGS_FREE_HANDLER)) RAPTOR_FREE(raptor_iostream_handler2, iostr->handler); RAPTOR_FREE(raptor_iostream, iostr); }
/** * raptor_new_iostream_from_file_handle: * @handle: Input file_handle to open and read from * * Constructor - create a new iostream reading from a file_handle. * * The @handle must already be open for reading. * NOTE: This does not fclose the @handle when it is finished. * * Return value: new #raptor_iostream object or NULL on failure **/ raptor_iostream* raptor_new_iostream_from_file_handle(FILE *handle) { raptor_iostream* iostr; const raptor_iostream_handler2* handler2=&raptor_iostream_read_file_handle_handler; const unsigned int mode=RAPTOR_IOSTREAM_MODE_READ; if(!handle) return NULL; if(!raptor_iostream_check_handler(handler2, mode)) return NULL; iostr=(raptor_iostream*)RAPTOR_CALLOC(raptor_iostream, 1, sizeof(raptor_iostream)); if(!iostr) return NULL; iostr->handler=handler2; iostr->user_data=(void*)handle; iostr->mode = mode; if(iostr->handler->init && iostr->handler->init(iostr->user_data)) { RAPTOR_FREE(raptor_iostream, iostr); return NULL; } return iostr; }
/** * raptor_new_iostream_from_handler: * @context: pointer to context information to pass in to calls * @handler: pointer to handler methods * * Create a new iostream over a user-defined handler. * * @deprecated: Use raptor_new_iostream_from_handler2() instead * * Return value: new #raptor_iostream object or NULL on failure **/ raptor_iostream* raptor_new_iostream_from_handler(void *user_data, const raptor_iostream_handler *handler) { raptor_iostream* iostr=NULL; raptor_iostream_handler2 *handler2; if(!handler) return NULL; handler2=(raptor_iostream_handler2*)RAPTOR_CALLOC(raptor_iostream_handler2, 1, sizeof(raptor_iostream_handler2*)); if(!handler2) return NULL; /* Copy V1 functions to V2 structure */ handler2->init = handler->init; handler2->finish = handler->finish; handler2->write_byte = handler->write_byte; handler2->write_bytes = handler->write_bytes; handler2->write_end = handler->write_end; iostr=raptor_new_iostream_from_handler2(user_data, handler2); if(iostr) { /* Ensure newly alloced structure is freed on iostream destruction */ iostr->flags |= RAPTOR_IOSTREAM_FLAGS_FREE_HANDLER; } else /* failure: so delete it now */ RAPTOR_FREE(raptor_iostream_handler2, handler2); return iostr; }
void raptor_libxml_validation_warning(void* user_data, const char *msg, ...) { va_list args; raptor_sax2* sax2 = (raptor_sax2*)user_data; int prefix_length = strlen(xml_validation_warning_prefix); int length; char *nmsg; size_t msg_len; va_start(args, msg); raptor_libxml_update_document_locator(sax2, sax2->locator); msg_len = strlen(msg); length = prefix_length + msg_len + 1; nmsg = (char*)RAPTOR_MALLOC(cstring, length); if(nmsg) { memcpy(nmsg, xml_validation_warning_prefix, prefix_length); /* Do not copy NUL */ memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */ if(nmsg[length-2] == '\n') nmsg[length-2]='\0'; } raptor_log_error_varargs(sax2->world, RAPTOR_LOG_LEVEL_WARN, sax2->locator, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); va_end(args); }
static size_t raptor_www_curl_header_callback(void* ptr, size_t size, size_t nmemb, void *userdata) { raptor_www* www=(raptor_www*)userdata; int bytes=size*nmemb; /* If WWW has been aborted, return nothing so that * libcurl will abort the transfer */ if(www->failed) return 0; if(!strncmp((char*)ptr, "Content-Type: ", 14)) { int len=bytes-16; char *type_buffer=(char*)RAPTOR_MALLOC(cstring, len+1); strncpy(type_buffer, (char*)ptr+14, len); type_buffer[len]='\0'; if(www->type) RAPTOR_FREE(cstring, www->type); www->type=type_buffer; www->free_type=1; #if RAPTOR_DEBUG > 2 RAPTOR_DEBUG3("Got content type '%s' (%d bytes)\n", type_buffer, len); #endif if(www->content_type) www->content_type(www, www->content_type_userdata, www->type); } return bytes; }
/** * raptor_free_sax2: * @sax2: SAX2 object * * Destructor - destroy a SAX2 object */ void raptor_free_sax2(raptor_sax2 *sax2) { raptor_xml_element *xml_element; if(!sax2) return; #ifdef RAPTOR_XML_LIBXML if(sax2->xc) { raptor_libxml_free(sax2->xc); sax2->xc = NULL; } #endif while( (xml_element = raptor_xml_element_pop(sax2)) ) raptor_free_xml_element(xml_element); raptor_namespaces_clear(&sax2->namespaces); if(sax2->base_uri) raptor_free_uri(sax2->base_uri); raptor_object_options_clear(&sax2->options); RAPTOR_FREE(raptor_sax2, sax2); }
/* * raptor_ntriples_parse_terminate - Free the Raptor NTriples parser * @rdf_parser: parser object * **/ static void raptor_ntriples_parse_terminate(raptor_parser* rdf_parser) { raptor_ntriples_parser_context *ntriples_parser=(raptor_ntriples_parser_context*)rdf_parser->context; if(ntriples_parser->line_length) RAPTOR_FREE(cdata, ntriples_parser->line); }
void raptor_libxml_validation_warning(void* user_data, const char *msg, ...) { va_list args; raptor_sax2* sax2=(raptor_sax2*)user_data; int prefix_length=strlen(xml_validation_warning_prefix); int length; char *nmsg; va_start(args, msg); raptor_libxml_update_document_locator(sax2, sax2->locator); length=prefix_length+strlen(msg)+1; nmsg=(char*)RAPTOR_MALLOC(cstring, length); if(nmsg) { strcpy(nmsg, xml_validation_warning_prefix); strcpy(nmsg+prefix_length, msg); if(nmsg[length-2]=='\n') nmsg[length-2]='\0'; } raptor_log_error_varargs(RAPTOR_LOG_LEVEL_WARNING, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_WARNING].handler, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_WARNING].user_data, sax2->locator, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); va_end(args); }
void raptor_libxml_generic_error(void* user_data, const char *msg, ...) { raptor_error_handlers* error_handlers=(raptor_error_handlers*)user_data; va_list args; const char* prefix=xml_generic_error_prefix; int prefix_length=strlen(prefix); int length; char *nmsg; va_start(args, msg); /* no SAX2 and locator from error_handlers */ length=prefix_length+strlen(msg)+1; nmsg=(char*)RAPTOR_MALLOC(cstring, length); if(nmsg) { strcpy(nmsg, prefix); strcpy(nmsg+prefix_length, msg); if(nmsg[length-1]=='\n') nmsg[length-1]='\0'; } raptor_log_error_varargs(RAPTOR_LOG_LEVEL_ERROR, error_handlers->handlers[RAPTOR_LOG_LEVEL_ERROR].handler, error_handlers->handlers[RAPTOR_LOG_LEVEL_ERROR].user_data, error_handlers->locator, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); va_end(args); }
/** * raptor_term_to_counted_string: * @term: #raptor_term * @len_p: Pointer to location to store length of new string (if not NULL) * * Turns part of raptor term into a N-Triples format counted string. * * Turns the given @term into an N-Triples escaped string using all the * escapes as defined in http://www.w3.org/TR/rdf-testcases/#ntriples * * This function uses raptor_term_ntriples_write() to write to an * #raptor_iostream which is the prefered way to write formatted * output. * * Return value: the new string or NULL on failure. The length of * the new string is returned in *@len_p if len_p is not NULL. **/ unsigned char* raptor_term_to_counted_string(raptor_term *term, size_t* len_p) { raptor_iostream *iostr; void *string = NULL; int rc; RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(term, raptor_term, NULL); iostr = raptor_new_iostream_to_string(term->world, &string, len_p, NULL); if(!iostr) return NULL; rc = raptor_term_ntriples_write(term, iostr); raptor_free_iostream(iostr); if(rc) { if(string) { RAPTOR_FREE(cstring, string); string = NULL; } } return (unsigned char *)string; }
/** * raptor_iostream_format_hexadecimal: * @iostr: raptor iostream * @integer: unsigned integer to format as hexadecimal * @width: field width * * Write an integer in hexadecimal to the iostream. * * Always 0-fills the entire field and writes in uppercase A-F * * Return value: non-0 on failure **/ int raptor_iostream_format_hexadecimal(raptor_iostream* iostr, unsigned int integer, int width) { unsigned char *buf; unsigned char *p; int rc; if(width <1) return 1; buf=(unsigned char*)RAPTOR_MALLOC(cstring, width); if(!buf) return 1; p=buf+width-1; do { unsigned int digit=(integer & 15); *p-- =(digit < 10) ? '0'+digit : 'A'+(digit-10); integer >>= 4; } while(integer); while(p >= buf) *p-- = '0'; rc=raptor_iostream_write_bytes(iostr, buf, 1, width); RAPTOR_FREE(cstring, buf); return rc; }
static void raptor_write_string_iostream_finish(void *user_data) { struct raptor_write_string_iostream_context* con; size_t len; void *str = NULL; con = (struct raptor_write_string_iostream_context*)user_data; len = raptor_stringbuffer_length(con->sb); *con->string_p = NULL; if(con->length_p) *con->length_p = len; str = (void*)con->malloc_handler(len+1); if(str) { if(len) raptor_stringbuffer_copy_to_string(con->sb, (unsigned char*)str, len+1); else *(char*)str='\0'; *con->string_p = str; } if(!str && con->length_p) *con->length_p = 0; raptor_free_stringbuffer(con->sb); RAPTOR_FREE(raptor_write_string_iostream_context, con); return; }
void raptor_log_error_varargs(raptor_log_level level, raptor_message_handler handler, void* handler_data, raptor_locator* locator, const char* message, va_list arguments) { char *buffer; size_t length; if(level == RAPTOR_LOG_LEVEL_NONE) return; buffer=raptor_vsnprintf(message, arguments); if(!buffer) { if(locator) { raptor_print_locator(stderr, locator); fputc(' ', stderr); } fputs("raptor ", stderr); fputs(raptor_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'; raptor_log_error(level, handler, handler_data, locator, buffer); RAPTOR_FREE(cstring, buffer); }
static int raptor_sequence_ensure(raptor_sequence *seq, int capacity, int grow_at_front) { void **new_sequence; int offset; RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(seq, raptor_sequence, 1); if(capacity && seq->capacity >= capacity) return 0; /* POLICY - minimum size */ if(capacity < 8) capacity=8; new_sequence=(void**)RAPTOR_CALLOC(ptrarray, capacity, sizeof(void*)); if(!new_sequence) return 1; offset=(grow_at_front ? (capacity-seq->capacity) : 0)+seq->start; if(seq->size) { memcpy(&new_sequence[offset], &seq->sequence[seq->start], sizeof(void*)*seq->size); RAPTOR_FREE(ptrarray, seq->sequence); } seq->start=offset; seq->sequence=new_sequence; seq->capacity=capacity; return 0; }
/** * raptor_new_iostream_from_handler: * @world: raptor_world object * @user_data: pointer to context information to pass in to calls * @handler: pointer to handler methods * * Create a new iostream over a user-defined handler * * Return value: new #raptor_iostream object or NULL on failure **/ raptor_iostream* raptor_new_iostream_from_handler(raptor_world *world, void *user_data, const raptor_iostream_handler* const handler) { raptor_iostream* iostr; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(handler, raptor_iostream_handler, NULL); raptor_world_open(world); if(!raptor_iostream_check_handler(handler, 0)) return NULL; iostr = RAPTOR_CALLOC(raptor_iostream*, 1, sizeof(*iostr)); if(!iostr) return NULL; iostr->world = world; iostr->handler = handler; iostr->user_data = (void*)user_data; iostr->mode = raptor_iostream_calculate_modes(handler); if(iostr->handler->init && iostr->handler->init(iostr->user_data)) { RAPTOR_FREE(raptor_iostream, iostr); return NULL; } return iostr; }
/** * raptor_new_uri_from_id: * @base_uri: existing base URI * @id: RDF ID * * Constructor - create a new URI from a base URI and RDF ID. * * This creates a URI equivalent to concatenating @base_uri with * ## and @id. * * Return value: a new #raptor_uri object or NULL on failure. **/ raptor_uri* raptor_new_uri_from_id(raptor_uri *base_uri, const unsigned char *id) { raptor_uri *new_uri; unsigned char *local_name; int len; if(!base_uri || !id) return NULL; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("Using ID %s\n", id); #endif /* "#id\0" */ len=1+strlen((char*)id) + sizeof(char*); local_name=(unsigned char*)RAPTOR_MALLOC(cstring, len); if(!local_name) return NULL; *local_name='#'; strcpy((char*)local_name+1, (char*)id); new_uri=raptor_new_uri_relative_to_base(base_uri, local_name); RAPTOR_FREE(cstring, local_name); return new_uri; }
/** * raptor_new_iostream_from_file_handle: * @world: raptor world * @handle: Input file_handle to open and read from * * Constructor - create a new iostream reading from a file_handle. * * The @handle must already be open for reading. * NOTE: This does not fclose the @handle when it is finished. * * Return value: new #raptor_iostream object or NULL on failure **/ raptor_iostream* raptor_new_iostream_from_file_handle(raptor_world *world, FILE *handle) { raptor_iostream* iostr; const raptor_iostream_handler* handler; const unsigned int mode = RAPTOR_IOSTREAM_MODE_READ; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); if(!handle) return NULL; raptor_world_open(world); handler = &raptor_iostream_read_file_handle_handler; if(!raptor_iostream_check_handler(handler, mode)) return NULL; iostr = RAPTOR_CALLOC(raptor_iostream*, 1, sizeof(*iostr)); if(!iostr) return NULL; iostr->world = world; iostr->handler = handler; iostr->user_data = (void*)handle; iostr->mode = mode; if(iostr->handler->init && iostr->handler->init(iostr->user_data)) { RAPTOR_FREE(raptor_iostream, iostr); return NULL; } return iostr; }
/** * raptor_free_xml_element: * @element: XML Element * * Destructor - destroy a raptor_xml_element object. **/ void raptor_free_xml_element(raptor_xml_element *element) { unsigned int i; if(!element) return; for(i = 0; i < element->attribute_count; i++) if(element->attributes[i]) raptor_free_qname(element->attributes[i]); if(element->attributes) RAPTOR_FREE(raptor_qname_array, element->attributes); if(element->content_cdata_sb) raptor_free_stringbuffer(element->content_cdata_sb); if(element->base_uri) raptor_free_uri(element->base_uri); if(element->xml_language) RAPTOR_FREE(char*, element->xml_language); raptor_free_qname(element->name); if(element->declared_nspaces) raptor_free_sequence(element->declared_nspaces); RAPTOR_FREE(raptor_element, element); }
void raptor_libxml_generic_error(void* user_data, const char *msg, ...) { raptor_world* world = (raptor_world*)user_data; va_list args; const char* prefix = xml_generic_error_prefix; int prefix_length = strlen(prefix); int length; char *nmsg; size_t msg_len; va_start(args, msg); msg_len = strlen(msg); length = prefix_length + msg_len + 1; nmsg = (char*)RAPTOR_MALLOC(cstring, length); if(nmsg) { memcpy(nmsg, prefix, prefix_length); /* Do not copy NUL */ memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */ if(nmsg[length-1] == '\n') nmsg[length-1]='\0'; } raptor_log_error_varargs(world, RAPTOR_LOG_LEVEL_ERROR, /* locator */ NULL, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); va_end(args); }
/** * raptor_new_iostream_from_handler2: * @user_data: pointer to context information to pass in to calls * @handler2: pointer to handler methods * * Create a new iostream over a user-defined handler * * Return value: new #raptor_iostream object or NULL on failure **/ raptor_iostream* raptor_new_iostream_from_handler2(void *user_data, const raptor_iostream_handler2 * const handler2) { raptor_iostream* iostr; if(!raptor_iostream_check_handler(handler2, 0)) return NULL; iostr=(raptor_iostream*)RAPTOR_CALLOC(raptor_iostream, 1, sizeof(raptor_iostream)); if(!iostr) return NULL; iostr->handler=handler2; iostr->user_data=(void*)user_data; iostr->mode = raptor_iostream_calculate_modes(handler2); if(iostr->handler->init && iostr->handler->init(iostr->user_data)) { RAPTOR_FREE(raptor_iostream, iostr); return NULL; } return iostr; }
/** * raptor_new_uri_for_retrieval: * @old_uri: URI to transform * * Constructor - create a URI suitable for retrieval. * * Takes an existing URI and ensures it has a path (default /) and has * no fragment - URI retrieval does not use the fragment part. * * Return value: new #raptor_uri object or NULL on failure. **/ raptor_uri* raptor_new_uri_for_retrieval(raptor_uri* old_uri) { unsigned char *uri_string; unsigned char *new_uri_string; raptor_uri* new_uri; raptor_uri_detail *ud; if(!old_uri) return NULL; uri_string=raptor_uri_as_string(old_uri); ud=raptor_new_uri_detail(uri_string); if(!ud) return NULL; if(!ud->path) { ud->path=(unsigned char*)"/"; ud->path_len=1; } ud->fragment=NULL; ud->fragment_len=0; new_uri_string=raptor_uri_detail_to_string(ud, NULL); raptor_free_uri_detail(ud); if(!new_uri_string) return NULL; new_uri=raptor_new_uri(new_uri_string); RAPTOR_FREE(cstring, new_uri_string); return new_uri; }
/** * raptor_new_xml_element: * @name: The XML element name * @xml_language: the in-scope XML language (or NULL) * @xml_base: the in-scope XML base URI (or NULL) * * Constructor - create a new XML element from a QName * * Return value: a new #raptor_xml_element or NULL on failure **/ raptor_xml_element* raptor_new_xml_element(raptor_qname *name, const unsigned char *xml_language, raptor_uri *xml_base) { raptor_xml_element* xml_element; xml_element = RAPTOR_CALLOC(raptor_xml_element*, 1, sizeof(*xml_element)); if(!xml_element) return NULL; /* Element name */ xml_element->name = name; xml_element->xml_language = xml_language; xml_element->base_uri = xml_base; xml_element->declared_nspaces = NULL; xml_element->content_cdata_sb = raptor_new_stringbuffer(); if(!xml_element->content_cdata_sb) { RAPTOR_FREE(raptor_xml_element, xml_element); xml_element = NULL; } return xml_element; }