void raptor_rss_item_add_block(raptor_rss_item* item, raptor_rss_block *block) { if(!item->blocks) { RAPTOR_DEBUG1("Adding first block\n"); item->blocks = block; } else { raptor_rss_block *cur; RAPTOR_DEBUG1("Adding subsequent block\n"); for(cur = item->blocks; cur->next; cur = cur->next) ; cur->next = block; } }
void raptor_rss_item_add_field(raptor_rss_item* item, int type, raptor_rss_field* field) { if(!item->fields[type]) { RAPTOR_DEBUG3("Adding first type %d field %s\n", type, raptor_rss_fields_info[type].name); item->fields_count++; item->fields[type] = field; } else { raptor_rss_field* cur; RAPTOR_DEBUG1("Adding subsequent field\n"); for(cur = item->fields[type]; cur->next; cur = cur->next) ; cur->next = field; } }
/** * raptor_get_serializer_factory: * @world: raptor_world object * @name: the factory name or NULL for the default factory * * Get a serializer factory by name. * * Return value: the factory object or NULL if there is no such factory **/ static raptor_serializer_factory* raptor_get_serializer_factory(raptor_world* world, const char *name) { raptor_serializer_factory *factory = NULL; RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, raptor_world, NULL); raptor_world_open(world); /* return 1st serializer if no particular one wanted - why? */ if(!name) { factory = (raptor_serializer_factory *)raptor_sequence_get_at(world->serializers, 0); if(!factory) { RAPTOR_DEBUG1("No (default) serializers registered\n"); return NULL; } } else { int i; for(i = 0; (factory = (raptor_serializer_factory*)raptor_sequence_get_at(world->serializers, i)); i++) { int namei; const char* fname; for(namei = 0; (fname = factory->desc.names[namei]); namei++) { if(!strcmp(fname, name)) break; } if(fname) break; } } return factory; }
static int raptor_ntriples_parse_chunk(raptor_parser* rdf_parser, const unsigned char *s, size_t len, int is_end) { unsigned char *buffer; unsigned char *ptr; unsigned char *start; raptor_ntriples_parser_context *ntriples_parser=(raptor_ntriples_parser_context*)rdf_parser->context; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("adding %d bytes to buffer\n", (unsigned int)len); #endif /* No data? It's the end */ if(!len) return 0; buffer=(unsigned char*)RAPTOR_MALLOC(cstring, ntriples_parser->line_length + len + 1); if(!buffer) { raptor_parser_fatal_error(rdf_parser, "Out of memory"); return 1; } if(ntriples_parser->line_length) { strncpy((char*)buffer, (const char*)ntriples_parser->line, ntriples_parser->line_length); RAPTOR_FREE(cstring, ntriples_parser->line); } ntriples_parser->line=buffer; /* move pointer to end of cdata buffer */ ptr=buffer+ntriples_parser->line_length; /* adjust stored length */ ntriples_parser->line_length += len; /* now write new stuff at end of cdata buffer */ strncpy((char*)ptr, (const char*)s, len); ptr += len; *ptr = '\0'; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("buffer now %d bytes\n", ntriples_parser->line_length); #endif ptr=buffer+ntriples_parser->offset; while(*(start=ptr)) { unsigned char *line_start=ptr; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG3("line buffer now '%s' (offset %d)\n", ptr, ptr-(buffer+ntriples_parser->offset)); #endif /* skip \n when just seen \r - i.e. \r\n or CR LF */ if(ntriples_parser->last_char == '\r' && *ptr == '\n') { #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG1("skipping a \\n\n"); #endif ptr++; rdf_parser->locator.byte++; rdf_parser->locator.column=0; start=line_start=ptr; } while(*ptr && *ptr != '\n' && *ptr != '\r') ptr++; if(!*ptr) break; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG3("found newline \\x%02x at offset %d\n", *ptr, ptr-line_start); #endif ntriples_parser->last_char=*ptr; len=ptr-line_start; rdf_parser->locator.column=0; *ptr='\0'; if(raptor_ntriples_parse_line(rdf_parser,line_start,len)) return 1; rdf_parser->locator.line++; /* go past newline */ ptr++; rdf_parser->locator.byte++; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 /* Do not peek if too far */ if(ptr-buffer < ntriples_parser->line_length) RAPTOR_DEBUG2("next char is \\x%02x\n", *ptr); else RAPTOR_DEBUG1("next char unknown - end of buffer\n"); #endif } ntriples_parser->offset=start-buffer; len=ntriples_parser->line_length - ntriples_parser->offset; if(len) { /* collapse buffer */ #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG3("collapsing buffer from %d to %d bytes\n", ntriples_parser->line_length, (unsigned int)len); #endif buffer=(unsigned char*)RAPTOR_MALLOC(cstring, len + 1); if(!buffer) { raptor_parser_fatal_error(rdf_parser, "Out of memory"); return 1; } strncpy((char*)buffer, (const char*)ntriples_parser->line+ntriples_parser->line_length-len, len); buffer[len]='\0'; RAPTOR_FREE(cstring, ntriples_parser->line); ntriples_parser->line=buffer; ntriples_parser->line_length -= ntriples_parser->offset; ntriples_parser->offset=0; #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG3("buffer now '%s' (%d bytes)\n", ntriples_parser->line, ntriples_parser->line_length); #endif } /* exit now, no more input */ if(is_end) { if(ntriples_parser->offset != ntriples_parser->line_length) { raptor_parser_error(rdf_parser, "Junk at end of input.\""); return 1; } return 0; } return 0; }