/** * 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; }
/** * 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; }
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); }
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; }
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); }
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); }
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); }
/** * raptor_www_set_http_accept: * @www: #raptor_www class * @value: Accept: header value or NULL to have an empty one. * * Set HTTP Accept header. * **/ void raptor_www_set_http_accept(raptor_www* www, const char *value) { char *value_copy; size_t len = 8; /* strlen("Accept:")+1 */ size_t value_len = 0; if(value) { value_len = strlen(value); len += 1 + value_len; /* " "+value */ } value_copy = (char*)RAPTOR_MALLOC(cstring, len); if(!value_copy) return; www->http_accept = value_copy; /* copy header name */ memcpy(value_copy, "Accept:", 7); /* Do not copy NUL */ value_copy += 7; /* copy header value */ if(value) { *value_copy ++= ' '; memcpy(value_copy, value, value_len + 1); /* Copy NUL */ } else { /* Ensure value is NUL terminated */ *value_copy = '\0'; } #if RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("Using Accept header: '%s'\n", www->http_accept); #endif }
/** * 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; }
/** * raptor_vsnprintf: * @message: printf-style format string * @arguments: variable arguments list * * Format output for a variable arguments list. * * This is a wrapper around system versions of vsnprintf with * different call and return conventions. * * Return value: a newly allocated string as the format result or NULL on failure **/ char* raptor_vsnprintf(const char *message, va_list arguments) { char empty_buffer[1]; int len; char *buffer=NULL; va_list args_copy; #ifdef HAVE_C99_VSNPRINTF /* copy for re-use */ va_copy(args_copy, arguments); len=vsnprintf(empty_buffer, 1, message, args_copy)+1; va_end(args_copy); if(len<=0) return NULL; buffer=(char*)RAPTOR_MALLOC(cstring, len); if(buffer) { /* copy for re-use */ va_copy(args_copy, arguments); vsnprintf(buffer, len, message, args_copy); va_end(args_copy); } #else /* This vsnprintf doesn't return number of bytes required */ int size=2; while(1) { buffer=(char*)RAPTOR_MALLOC(cstring, size+1); if(!buffer) break; /* copy for re-use */ va_copy(args_copy, arguments); len=vsnprintf(buffer, size, message, args_copy); va_end(args_copy); if(len>=0) break; RAPTOR_FREE(cstring, buffer); size+=4; } #endif return buffer; }
static raptor_uri* raptor_default_new_uri(void *context, const unsigned char *uri_string) { unsigned char *p; size_t len; /* If uri_string is "file:path-to-file", turn it into a correct file:URI */ if(raptor_uri_uri_string_is_file_uri(uri_string)) { unsigned char *fragment=NULL; char *filename; raptor_uri* uri=NULL; filename=raptor_uri_uri_string_to_filename_fragment(uri_string, &fragment); if(filename && !access(filename, R_OK)) { uri=(raptor_uri*)raptor_uri_filename_to_uri_string(filename); /* If there was a fragment, reattach it to the new URI */ if(fragment) { unsigned char *new_fragment; raptor_uri* new_uri; new_fragment=(unsigned char*)RAPTOR_MALLOC(cstring, strlen((const char*)fragment) + 1 + sizeof(char*)); if(!new_fragment) return NULL; *new_fragment='#'; strcpy((char*)new_fragment+1, (const char*)fragment); new_uri=raptor_new_uri_relative_to_base(uri, new_fragment); RAPTOR_FREE(cstring, new_fragment); raptor_free_uri(uri); uri=new_uri; } } if(filename) RAPTOR_FREE(cstring, filename); if(fragment) RAPTOR_FREE(cstring, fragment); if(uri) return uri; } len=strlen((const char*)uri_string); p=(unsigned char*)RAPTOR_MALLOC(raptor_uri, len + sizeof(char*)); if(!p) return NULL; strcpy((char*)p, (const char*)uri_string); return (raptor_uri*)p; }
static void raptor_libxml_error_common(void* user_data, const char *msg, va_list args, const char *prefix, int is_fatal) { raptor_sax2* sax2 = NULL; int prefix_length = strlen(prefix); int length; char *nmsg; size_t msg_len; raptor_world* world = NULL; raptor_locator* locator = NULL; if(user_data) { /* Work around libxml2 bug - sometimes the sax2->error * returns a user_data, sometimes the userdata */ if(((raptor_sax2*)user_data)->magic == RAPTOR_LIBXML_MAGIC) sax2 = (raptor_sax2*)user_data; else /* user_data is not userData */ sax2 = (raptor_sax2*)((xmlParserCtxtPtr)user_data)->userData; } if(sax2) { world = sax2->world; locator = sax2->locator; if(locator) 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, 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'; } if(is_fatal) raptor_log_error_varargs(world, RAPTOR_LOG_LEVEL_FATAL, locator, nmsg ? nmsg : msg, args); else raptor_log_error_varargs(world, RAPTOR_LOG_LEVEL_ERROR, locator, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); }
static raptor_uri* raptor_default_uri_copy(void *context, raptor_uri *uri) { raptor_uri* new_uri=(raptor_uri*)RAPTOR_MALLOC(cstring, strlen((char*)uri) + sizeof(char*)); if(!new_uri) return NULL; strcpy((char*)new_uri, (char*)uri); return new_uri; }
/* Constructor */ raptor_sequence* raptor_new_sequence(raptor_free_handler *free_handler, raptor_print_handler *print_handler) { raptor_sequence* seq=(raptor_sequence*)RAPTOR_MALLOC(raptor_sequence, sizeof(raptor_sequence)); if(!seq) return NULL; seq->size=0; seq->capacity=0; seq->free_handler=free_handler; seq->print_handler=print_handler; return seq; }
static void raptor_libxml_error_common(void* user_data, const char *msg, va_list args, const char *prefix, int is_fatal) { raptor_sax2* sax2=NULL; int prefix_length=strlen(prefix); int length; char *nmsg; if(user_data) { /* Work around libxml2 bug - sometimes the sax2->error * returns a user_data, sometimes the userdata */ if(((raptor_sax2*)user_data)->magic == RAPTOR_LIBXML_MAGIC) sax2=(raptor_sax2*)user_data; else /* user_data is not userData */ sax2=(raptor_sax2*)((xmlParserCtxtPtr)user_data)->userData; } if(sax2->locator) raptor_libxml_update_document_locator(sax2, sax2->locator); 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'; } if(is_fatal) raptor_log_error_varargs(RAPTOR_LOG_LEVEL_FATAL, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_FATAL].handler, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_FATAL].user_data, sax2->locator, nmsg ? nmsg : msg, args); else raptor_log_error_varargs(RAPTOR_LOG_LEVEL_ERROR, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_ERROR].handler, sax2->error_handlers->handlers[RAPTOR_LOG_LEVEL_ERROR].user_data, sax2->locator, nmsg ? nmsg : msg, args); if(nmsg) RAPTOR_FREE(cstring,nmsg); }
/** * raptor_www_set_http_cache_control: * @www: WWW object * @cache_control: Cache-Control header value (or NULL to disable) * * Set HTTP Cache-Control:header (default none) * * The @cache_control value can be a string to set it, "" to send * a blank header or NULL to not set the header at all. * * Return value: non-0 on failure **/ int raptor_www_set_http_cache_control(raptor_www* www, const char* cache_control) { char *cache_control_copy; const char* const header="Cache-Control:"; const size_t header_len = 14; /* strlen("Cache-Control:") */ size_t len; size_t cc_len; RAPTOR_ASSERT((strlen(header) != header_len), "Cache-Control header length is wrong"); if(www->cache_control) { RAPTOR_FREE(cstring, www->cache_control); www->cache_control = NULL; } if(!cache_control) { www->cache_control = NULL; return 0; } cc_len = strlen(cache_control); len = header_len + 1 + cc_len + 1; /* header+" "+cache_control+"\0" */ cache_control_copy = (char*)RAPTOR_MALLOC(cstring, len); if(!cache_control_copy) return 1; www->cache_control = cache_control_copy; /* copy header name */ memcpy(cache_control_copy, header, header_len); /* Do not copy NUL */ cache_control_copy += header_len; /* copy header value */ if(*cache_control) { *cache_control_copy ++= ' '; memcpy(cache_control_copy, cache_control, cc_len + 1); /* Copy NUL */ } else { /* Ensure value is NUL terminated */ *cache_control_copy = '\0'; } #if RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("Using Cache-Control header: '%s'\n", www->cache_control); #endif return 0; }
static raptor_uri* raptor_default_new_uri_for_rdf_concept(void *context, const char *name) { raptor_uri *new_uri; const unsigned char *base_uri=raptor_rdf_namespace_uri; unsigned int base_uri_len=raptor_rdf_namespace_uri_len; unsigned int new_uri_len; new_uri_len=base_uri_len+strlen(name) + sizeof(char*); new_uri=(raptor_uri*)RAPTOR_MALLOC(cstring, new_uri_len); if(!new_uri) return NULL; strcpy((char*)new_uri, (const char*)base_uri); strcpy((char*)new_uri+base_uri_len, name); return new_uri; }
static raptor_uri* raptor_default_new_uri_from_uri_local_name(void *context, raptor_uri *uri, const unsigned char *local_name) { int uri_length=strlen((char*)uri); unsigned char *p=(unsigned char*)RAPTOR_MALLOC(cstring, uri_length + strlen((const char*)local_name) + sizeof(char*)); if(!p) return NULL; strcpy((char*)p, (const char*)uri); strcpy((char*)p + uri_length, (const char*)local_name); return (raptor_uri*)p; }
static raptor_uri* raptor_default_new_uri_for_rdf_concept(void *context, const char *name) { raptor_uri *new_uri; char *base_uri=RAPTOR_RDF_MS_URI; int base_uri_len=strlen(base_uri); int new_uri_len; new_uri_len=base_uri_len+strlen(name)+1; new_uri=(raptor_uri*)RAPTOR_MALLOC(cstring, new_uri_len); if(!new_uri) return NULL; strcpy((char*)new_uri, base_uri); strcpy((char*)new_uri+base_uri_len, name); return new_uri; }
/* * raptor_unique_id: * @base: base ID * * Generate a node ID for serializing * * Raptor doesn't check that blank IDs it generates are unique from * any specified by rdf:nodeID. Here, we need to emit IDs that are * different from the ones the parser generates so that there is no * collision. For now, just prefix a '_' to the parser generated * name. * * Return value: new node ID **/ unsigned char* raptor_unique_id(unsigned char *base) { const char *prefix = "_"; int prefix_len = strlen(prefix); int base_len = strlen((const char*)base); int len = prefix_len + base_len + 1; unsigned char *unique_id; unique_id= (unsigned char *)RAPTOR_MALLOC(cstring, len); strncpy((char*)unique_id, prefix, prefix_len); strncpy((char*)unique_id+prefix_len, (char *)base, base_len); unique_id[len-1]='\0'; return unique_id; }
static unsigned char* raptor_uri_construct(const unsigned char *scheme, const unsigned char *authority, const unsigned char *path, const unsigned char *query, const unsigned char *fragment) { size_t len=0; unsigned char *p; if(scheme) len+= strlen((const char*)scheme)+1; /* : */ if(authority) len+= 2 + strlen((const char*)authority); /* // */ if(path) len+= strlen((const char*)path); if(fragment) len+= 1 + strlen((const char*)fragment); /* # */ if(query) len+= 1 + strlen((const char*)query); /* ? */ p=(unsigned char*)RAPTOR_MALLOC(cstring, len+1); if(!p) return NULL; *p='\0'; if(scheme) { strcpy((char*)p, (const char*)scheme); strcat((char*)p,":"); } if(authority) { strcat((char*)p, "//"); strcat((char*)p, (const char*)authority); } if(path) strcat((char*)p, (const char*)path); if(fragment) { strcat((char*)p, "#"); strcat((char*)p, (const char*)fragment); } if(query) { strcat((char*)p, "?"); strcat((char*)p, (const char*)query); } return p; }
/** * raptor_www_set_proxy: * @www: WWW object * @proxy: proxy string. * * Set the proxy for the WWW object. * * The @proxy usually a string of the form http://server.domain:port. **/ void raptor_www_set_proxy(raptor_www* www, const char *proxy) { char *proxy_copy; size_t proxy_len; if(!proxy) return; proxy_len = strlen(proxy); proxy_copy = (char*)RAPTOR_MALLOC(cstring, proxy_len + 1); if(!proxy_copy) return; memcpy(proxy_copy, proxy, proxy_len + 1); /* copy NUL */ www->proxy = proxy_copy; }
int raptor_rss_set_date_field(raptor_rss_field* field, time_t unix_time) { size_t len = RAPTOR_ISO_DATE_LEN; if(field->value) RAPTOR_FREE(cstring, field->value); field->value = (unsigned char*)RAPTOR_MALLOC(cstring, len + 1); if(!field->value) return 1; if(raptor_rss_format_iso_date((char*)field->value, len, unix_time)) { RAPTOR_FREE(cstring, field->value); return 1; } return 0; }
static void raptor_libxml_warning(void* user_data, const char *msg, ...) { raptor_sax2* sax2 = NULL; va_list args; int prefix_length = strlen(xml_warning_prefix); int length; char *nmsg; size_t msg_len; /* Work around libxml2 bug - sometimes the sax2->error * returns a ctx, sometimes the userdata */ if(((raptor_sax2*)user_data)->magic == RAPTOR_LIBXML_MAGIC) sax2 = (raptor_sax2*)user_data; else /* user_data is not userData */ sax2 = (raptor_sax2*)((xmlParserCtxtPtr)user_data)->userData; 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_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); }
/** * raptor_www_set_user_agent: * @www: WWW object * @user_agent: User-Agent string * * Set the user agent value, for HTTP requests typically. **/ void raptor_www_set_user_agent(raptor_www* www, const char *user_agent) { char *ua_copy = NULL; size_t ua_len; if(!user_agent || !*user_agent) { www->user_agent = NULL; return; } ua_len = strlen(user_agent); ua_copy = (char*)RAPTOR_MALLOC(cstring, ua_len + 1); if(!ua_copy) return; memcpy(ua_copy, user_agent, ua_len + 1); /* copy NUL */ www->user_agent = ua_copy; }
/** * raptor_new_avltree: * @compare_handler: item comparison handler for ordering * @free_handler: item free handler (or NULL) * @flags: AVLTree flags - bitmask of #raptor_avltree_bitflags flags. * * AVL Tree Constructor * * Return value: new AVL Tree or NULL on failure */ raptor_avltree* raptor_new_avltree(raptor_data_compare_handler compare_handler, raptor_data_free_handler free_handler, unsigned int flags) { raptor_avltree* tree; tree = (raptor_avltree*)RAPTOR_MALLOC(raptor_avltree, sizeof(*tree)); if(!tree) return NULL; tree->root = NULL; tree->compare_handler = compare_handler; tree->free_handler = free_handler; tree->print_handler = NULL; tree->flags = flags; tree->size = 0; return tree; }
static void raptor_guess_parse_content_type_handler(raptor_parser* rdf_parser, const char* content_type) { raptor_guess_parser_context* guess_parser=(raptor_guess_parser_context*)rdf_parser->context; if(content_type) { const char *p; size_t len; if((p=strchr(content_type,';'))) len=p-content_type; else len=strlen(content_type); guess_parser->content_type=(char*)RAPTOR_MALLOC(cstring, len+1); strncpy(guess_parser->content_type, content_type, len); guess_parser->content_type[len]='\0'; RAPTOR_DEBUG2("Got content type '%s'\n", guess_parser->content_type); } }
/** * raptor_ntriples_string_as_utf8_string: * @rdf_parser: parser object * @src: data to read from * @len: size of data * @dest_lenp: pointer to length of destination (out) or NULL * * Turn an N-Triples string with escapes into a UTF-8 string. * * @deprecated: This requires use of parser internals and was never in the public API header. * * Return value: a new UTF-8 string **/ unsigned char* raptor_ntriples_string_as_utf8_string(raptor_parser* rdf_parser, const unsigned char *src, int len, size_t *dest_lenp) { const unsigned char *start=src; size_t length=len; unsigned char *dest; int rc; dest=(unsigned char*)RAPTOR_MALLOC(cstring, len+1); if(!dest) return NULL; rc=raptor_ntriples_term(rdf_parser, &start, dest, &length, dest_lenp, '\0', RAPTOR_TERM_CLASS_FULL, 1); if(rc) { RAPTOR_FREE(cstring, dest); dest=NULL; } return dest; }
static raptor_uri* raptor_default_new_uri_relative_to_base(void *context, raptor_uri *base_uri, const unsigned char *uri_string) { raptor_uri* new_uri; size_t new_uri_len=strlen((const char*)base_uri)+strlen((const char*)uri_string)+1; new_uri=(raptor_uri*)RAPTOR_MALLOC(cstring, new_uri_len+1); if(!new_uri) return NULL; /* If URI string is empty, just copy base URI */ if(!*uri_string) { strcpy((char*)new_uri, (char*)base_uri); return new_uri; } raptor_uri_resolve_uri_reference((const unsigned char*)base_uri, uri_string, (unsigned char*)new_uri, new_uri_len); return new_uri; }
static raptor_uri* raptor_default_new_uri_relative_to_base(void *context, raptor_uri *base_uri, const unsigned char *uri_string) { raptor_uri* new_uri; size_t new_uri_len=strlen((const char*)base_uri)+strlen((const char*)uri_string) + sizeof(char*); /* +2 is for \0 plus an extra 1 for adding any missing URI path '/' */ new_uri=(raptor_uri*)RAPTOR_MALLOC(cstring, new_uri_len+2); if(!new_uri) return NULL; /* If URI string is empty, just copy base URI */ if(!*uri_string) { strcpy((char*)new_uri, (char*)base_uri); return new_uri; } raptor_uri_resolve_uri_reference((const unsigned char*)base_uri, uri_string, (unsigned char*)new_uri, new_uri_len); return new_uri; }