Changeset 2027
- Timestamp:
- 02/23/08 22:31:16 (3 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/analyzer.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/config.c (modified) (13 diffs)
- libswish3/trunk/src/libswish3/docinfo.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/libswish3.h (modified) (6 diffs)
- libswish3/trunk/src/libswish3/namedbuffer.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (79 diffs)
- libswish3/trunk/src/libswish3/swish.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/words.c (modified) (28 diffs)
- libswish3/trunk/src/swish_lint.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/analyzer.c
r2010 r2027 37 37 a->minwordlen = SWISH_MIN_WORD_LEN; 38 38 a->lc = 1; 39 a->ref_cnt = 0;39 a->ref_cnt = 1; 40 40 41 41 if (xmlStrEqual((xmlChar*)SWISH_DEFAULT_VALUE, … … 80 80 swish_free_analyzer( swish_Analyzer * a ) 81 81 { 82 a->ref_cnt--; 83 if (a->ref_cnt > 0) { 84 SWISH_WARN("analyzer ref_cnt > 0: %d\n", a->ref_cnt); 85 } 82 86 swish_xfree(a); 83 87 } libswish3/trunk/src/libswish3/config.c
r2010 r2027 62 62 free_config2(void *payload, xmlChar * key) 63 63 { 64 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)64 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 65 65 SWISH_DEBUG_MSG(" freeing config %s => %s", key, (xmlChar *) payload); 66 66 … … 73 73 int size = xmlHashSize((xmlHashTablePtr) payload); 74 74 75 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)75 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 76 76 { 77 77 SWISH_DEBUG_MSG(" freeing config %s =>", confName); … … 89 89 int size = xmlHashSize(config->conf); 90 90 91 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)91 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 92 92 { 93 93 SWISH_DEBUG_MSG("freeing config"); … … 120 120 xmlHashTablePtr c, metas, parsers, index, prop, alias, parsewords; 121 121 122 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)122 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 123 123 SWISH_DEBUG_MSG("creating default config"); 124 124 … … 217 217 218 218 config->conf = c; 219 config->ref_cnt = 0;219 config->ref_cnt = 1; 220 220 config->stash = NULL; 221 221 config->flags = flags; 222 222 223 223 224 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)224 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 225 225 swish_debug_config(config); 226 226 … … 235 235 config = swish_parse_config(conf, config); 236 236 237 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)237 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 238 238 swish_debug_config(config); 239 239 … … 453 453 { 454 454 doc = xmlParseFile((const char *) conf); 455 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)455 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 456 456 SWISH_DEBUG_MSG("Parsing configuration file: %s", conf); 457 457 } … … 459 459 { 460 460 doc = xmlParseMemory((const char *) conf, xmlStrlen(conf)); 461 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)461 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 462 462 SWISH_DEBUG_MSG("Parsing configuration from memory"); 463 463 } … … 683 683 else 684 684 { 685 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)685 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 686 686 SWISH_DEBUG_MSG(" >>> found existing name in config: %s", opt_name); 687 687 … … 727 727 tmp_arg = arg_list->word[i]; 728 728 729 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)729 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 730 730 SWISH_DEBUG_MSG("config %s tmp_arg = %s opt_type = %s", opt_name, tmp_arg, opt_type); 731 731 … … 744 744 { 745 745 free_tmp = 1; 746 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)746 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 747 747 SWISH_DEBUG_MSG("tolower str: >%s<", tmp_arg); 748 748 … … 751 751 } 752 752 753 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)753 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 754 754 SWISH_DEBUG_MSG("config %s tmp_arg = %s tmp_value = %s", opt_name, tmp_arg, tmp_value); 755 755 … … 778 778 if (!name_seen && xmlStrcmp(opt_name, (xmlChar *) "IncludeConfigFile")) 779 779 { 780 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG)780 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 781 781 SWISH_DEBUG_MSG(" >>> adding %s to config hash ( name_seen = %d )", opt_name, name_seen); 782 782 libswish3/trunk/src/libswish3/docinfo.c
r2010 r2027 171 171 /* PUBLIC */ 172 172 int 173 swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_Parse Data *parse_data )173 swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_ParserData *parser_data ) 174 174 { 175 175 struct stat info; … … 205 205 swish_xfree(i->mime); 206 206 207 i->mime = swish_get_mime_type( parse _data->s3->config, i->ext );207 i->mime = swish_get_mime_type( parser_data->s3->config, i->ext ); 208 208 209 209 if (SWISH_DEBUG > 9) … … 213 213 swish_xfree(i->parser); 214 214 215 i->parser = swish_get_parser( parse _data->s3->config, i->mime );215 i->parser = swish_get_parser( parser_data->s3->config, i->mime ); 216 216 217 217 return 1; libswish3/trunk/src/libswish3/libswish3.h
r2010 r2027 125 125 126 126 /* debugging levels */ 127 #define SWISH_DEBUG_MEMORY 13128 #define SWISH_DEBUG_CONFIG 11129 127 #define SWISH_DEBUG_DOCINFO 1 130 #define SWISH_DEBUG_WORDLIST 7 131 #define SWISH_DEBUG_TOKENIZER 5 132 #define SWISH_DEBUG_PARSER 9 133 #define SWISH_DEBUG_NAMEDBUFFER 15 128 #define SWISH_DEBUG_TOKENIZER 2 129 #define SWISH_DEBUG_WORDLIST 4 130 #define SWISH_DEBUG_PARSER 8 131 #define SWISH_DEBUG_CONFIG 16 132 #define SWISH_DEBUG_MEMORY 32 133 #define SWISH_DEBUG_NAMEDBUFFER 64 134 134 135 135 #define SWISH_DEBUG_MSG(args...) \ … … 160 160 typedef struct swish_Word swish_Word; 161 161 typedef struct swish_WordList swish_WordList; 162 typedef struct swish_Parse Data swish_ParseData;162 typedef struct swish_ParserData swish_ParserData; 163 163 typedef struct swish_Tag swish_Tag; 164 164 typedef struct swish_TagStack swish_TagStack; … … 311 311 { 312 312 int ref_cnt; // for script bindings 313 void (*handler)(swish_Parse Data*); // handler reference313 void (*handler)(swish_ParserData*); // handler reference 314 314 void *stash; // for script bindings 315 315 }; 316 316 317 317 // TODO maybe store swish_Parser * here instead of separate config and analyzer 318 struct swish_Parse Data318 struct swish_ParserData 319 319 { 320 320 swish_3 *s3; // main object … … 344 344 =head2 Object Functions 345 345 */ 346 swish_3 * swish_init_swish3( void (*handler) (swish_Parse Data *), void *stash );346 swish_3 * swish_init_swish3( void (*handler) (swish_ParserData *), void *stash ); 347 347 void swish_free_swish3( swish_3 *s3 ); 348 348 /* … … 457 457 =head2 Parser Functions 458 458 */ 459 swish_Parser * swish_init_parser( void (*handler) (swish_Parse Data *) );459 swish_Parser * swish_init_parser( void (*handler) (swish_ParserData *) ); 460 460 void swish_free_parser( swish_Parser * parser ); 461 461 int swish_parse_file( swish_3 * s3, … … 542 542 int swish_docinfo_from_filesystem( xmlChar *filename, 543 543 swish_DocInfo * i, 544 swish_Parse Data *parse_data );544 swish_ParserData *parser_data ); 545 545 void swish_debug_docinfo( swish_DocInfo * docinfo ); 546 546 xmlChar * swish_get_file_ext( xmlChar *url ); libswish3/trunk/src/libswish3/namedbuffer.c
r1952 r2027 58 58 free_name_from_hash(void *buffer, xmlChar * name) 59 59 { 60 if (SWISH_DEBUG == SWISH_DEBUG_NAMEDBUFFER)60 if (SWISH_DEBUG >= SWISH_DEBUG_NAMEDBUFFER) 61 61 SWISH_DEBUG_MSG(" freeing NamedBuffer %s\n", name); 62 62 … … 69 69 swish_NamedBuffer * nb = swish_xmalloc(sizeof(swish_NamedBuffer)); 70 70 nb->stash = NULL; 71 nb->ref_cnt = 0;71 nb->ref_cnt = 1; 72 72 nb->hash = xmlHashCreate(8); /* will grow as needed */ 73 73 … … 84 84 { 85 85 xmlHashFree(nb->hash, (xmlHashDeallocator)free_name_from_hash); 86 86 87 nb->ref_cnt--; 87 88 if (nb->ref_cnt > 0) 88 89 SWISH_WARN("freeing NamedBuffer with ref_cnt > 0 (%d)", nb->ref_cnt); libswish3/trunk/src/libswish3/parser.c
r2010 r2027 64 64 static void get_env_vars(); 65 65 66 static void flush_buffer( swish_Parse Data * parse_data,66 static void flush_buffer( swish_ParserData * parser_data, 67 67 xmlChar * metaname, xmlChar * context 68 68 ); 69 69 70 static void tokenize( swish_Parse Data * parse_data,70 static void tokenize( swish_ParserData * parser_data, 71 71 xmlChar * string, 72 72 int len, … … 76 76 77 77 static xmlChar *flatten_tag_stack(xmlChar * tag, swish_TagStack * stack); 78 static void add_stack_to_prop_buf(xmlChar * tag, swish_Parse Data * parse_data);78 static void add_stack_to_prop_buf(xmlChar * tag, swish_ParserData * parser_data); 79 79 static swish_TagStack * 80 80 push_tag_stack(swish_TagStack * stack, xmlChar * tag); … … 82 82 static xmlChar *pop_tag_stack_on_match(swish_TagStack * stack, xmlChar * tag); 83 83 84 static void mystartDocument(void *parse _data);85 static void myendDocument(void *parse _data);86 static void mystartElement(void *parse _data, const xmlChar * name, const xmlChar ** atts);87 static void myendElement(void *parse _data, const xmlChar * name);84 static void mystartDocument(void *parser_data); 85 static void myendDocument(void *parser_data); 86 static void mystartElement(void *parser_data, const xmlChar * name, const xmlChar ** atts); 87 static void myendElement(void *parser_data, const xmlChar * name); 88 88 89 89 /* SAX2 support */ 90 90 static void 91 91 mystartElementNs( 92 void *parse _data,92 void *parser_data, 93 93 const xmlChar * localname, 94 94 const xmlChar * prefix, … … 107 107 const xmlChar * URI); 108 108 109 static void buffer_characters(swish_Parse Data * parse_data, const xmlChar * ch, int len);110 static void mycharacters(void *parse _data, const xmlChar * ch, int len);111 static void mycomments(void *parse _data, const xmlChar * ch);109 static void buffer_characters(swish_ParserData * parser_data, const xmlChar * ch, int len); 110 static void mycharacters(void *parser_data, const xmlChar * ch, int len); 111 static void mycomments(void *parser_data, const xmlChar * ch); 112 112 static void myerr(void *user_data, xmlChar * msg,...); 113 113 … … 115 115 static void open_tag(void *data, const xmlChar * tag, const xmlChar ** atts); 116 116 static void close_tag(void *data, const xmlChar * tag); 117 static xmlChar *build_tag(swish_Parse Data * parse_data, xmlChar * tag, xmlChar ** atts);118 119 static int docparser(swish_Parse Data * parse_data, xmlChar * filename, xmlChar * buffer, int size);117 static xmlChar *build_tag(swish_ParserData * parser_data, xmlChar * tag, xmlChar ** atts); 118 119 static int docparser(swish_ParserData * parser_data, xmlChar * filename, xmlChar * buffer, int size); 120 120 static int xml_parser(xmlSAXHandlerPtr sax, void *user_data, xmlChar * buffer, int size); 121 121 static int html_parser(xmlSAXHandlerPtr sax, void *user_data, xmlChar * buffer, int size); 122 static int txt_parser(swish_Parse Data * parse_data, xmlChar * buffer, int size);123 124 static swish_Parse Data *125 init_parse _data(swish_3 * s3);126 static void free_parse _data(swish_ParseData * parse_data);122 static int txt_parser(swish_ParserData * parser_data, xmlChar * buffer, int size); 123 124 static swish_ParserData * 125 init_parser_data(swish_3 * s3); 126 static void free_parser_data(swish_ParserData * parser_data); 127 127 128 128 /* parsing fh/buffer headers */ … … 140 140 static xmlChar *document_encoding(xmlParserCtxtPtr ctxt); 141 141 142 static void set_encoding(swish_Parse Data * parse_data, xmlChar * buffer);142 static void set_encoding(swish_ParserData * parser_data, xmlChar * buffer); 143 143 144 144 … … 150 150 swish_Parser * 151 151 swish_init_parser( 152 void (*handler) (swish_Parse Data *)152 void (*handler) (swish_ParserData *) 153 153 ) 154 154 { 155 155 swish_Parser * p = (swish_Parser*) swish_xmalloc(sizeof(swish_Parser)); 156 156 p->handler = handler; 157 p->ref_cnt = 0;157 p->ref_cnt = 1; 158 158 159 159 /* libxml2 stuff */ … … 170 170 swish_free_parser( swish_Parser * p ) 171 171 { 172 p->ref_cnt--; 173 if (p->ref_cnt > 0) { 174 SWISH_WARN("parser ref_cnt > 0: %d\n", p->ref_cnt); 175 } 172 176 xmlCleanupParser(); 173 177 xmlMemoryDump(); … … 178 182 * properties */ 179 183 static xmlChar * 180 build_tag(swish_Parse Data * parse_data, xmlChar * tag, xmlChar ** atts)184 build_tag(swish_ParserData * parser_data, xmlChar * tag, xmlChar ** atts) 181 185 { 182 186 int i, is_html_tag; … … 190 194 191 195 /* html tags */ 192 if (parse _data->is_html)196 if (parser_data->is_html) 193 197 { 194 198 … … 198 202 ) 199 203 { 200 parse _data->bump_word = 1;204 parser_data->bump_word = 1; 201 205 } 202 206 else … … 245 249 if (metaname != NULL && metacontent != NULL) 246 250 { 247 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)251 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 248 252 SWISH_DEBUG_MSG("found HTML meta: %s => %s", metaname, metacontent); 249 253 250 254 /* do not match across metas */ 251 parse _data->bump_word = 1;252 open_tag(parse _data, metaname, NULL);253 buffer_characters(parse _data, metacontent, xmlStrlen(metacontent));254 close_tag(parse _data, metaname);255 parser_data->bump_word = 1; 256 open_tag(parser_data, metaname, NULL); 257 buffer_characters(parser_data, metacontent, xmlStrlen(metacontent)); 258 close_tag(parser_data, metaname); 255 259 swish_xfree(swishtag); 256 260 return NULL; … … 266 270 /* TODO make this configurable ala swish2 */ 267 271 268 parse _data->bump_word = 1;269 270 } 271 272 273 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)274 { 275 fprintf(stderr, " >>> build_tag (%s (%s) ", tag, parse _data->tag);272 parser_data->bump_word = 1; 273 274 } 275 276 277 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 278 { 279 fprintf(stderr, " >>> build_tag (%s (%s) ", tag, parser_data->tag); 276 280 if (atts != 0) 277 281 { … … 290 294 291 295 /* change our internal name for this tag if it is aliased in config */ 292 alias = swish_get_config_value(parse _data->s3->config, (xmlChar*)SWISH_ALIAS, swishtag);296 alias = swish_get_config_value(parser_data->s3->config, (xmlChar*)SWISH_ALIAS, swishtag); 293 297 if (alias) 294 298 { … … 304 308 305 309 static void 306 flush_buffer(swish_Parse Data * parse_data, xmlChar * metaname, xmlChar * context)307 { 308 swish_TagStack *s = parse _data->metastack;309 310 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)310 flush_buffer(swish_ParserData * parser_data, xmlChar * metaname, xmlChar * context) 311 { 312 swish_TagStack *s = parser_data->metastack; 313 314 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 311 315 SWISH_DEBUG_MSG("buffer is >>%s<< before flush, word_pos = %d", 312 xmlBufferContent(parse _data->meta_buf), parse_data->word_pos);316 xmlBufferContent(parser_data->meta_buf), parser_data->word_pos); 313 317 314 318 /* since we only flush the buffer when metaname changes, and … … 316 320 * before parsing the string and making the tmp wordlist 317 321 */ 318 if (parse _data->word_pos)319 parse _data->word_pos++;322 if (parser_data->word_pos) 323 parser_data->word_pos++; 320 324 321 325 /* add meta_buf as-is to metanames buffer under current tag. 322 326 this gives us both tokens and raw text de-tagged but organized by metaname. 323 327 */ 324 swish_add_buf_to_nb( parse _data->metanames,328 swish_add_buf_to_nb( parser_data->metanames, 325 329 metaname, 326 parse _data->meta_buf,330 parser_data->meta_buf, 327 331 (xmlChar*)SWISH_META_CONNECTOR, 328 332 0, 329 333 1); 330 334 331 if (parse _data->context_as_meta)335 if (parser_data->context_as_meta) 332 336 { 333 337 for (s->temp = s->head; s->temp != NULL; s->temp = s->temp->next) … … 336 340 continue; 337 341 338 swish_add_buf_to_nb(parse _data->metanames,342 swish_add_buf_to_nb(parser_data->metanames, 339 343 s->temp->name, 340 parse _data->meta_buf,344 parser_data->meta_buf, 341 345 (xmlChar*)SWISH_META_CONNECTOR, 342 346 0, … … 345 349 } 346 350 347 if (parse _data->s3->analyzer->tokenize)348 { 349 350 tokenize( parse _data,351 (xmlChar *)xmlBufferContent(parse _data->meta_buf),352 xmlBufferLength(parse _data->meta_buf),351 if (parser_data->s3->analyzer->tokenize) 352 { 353 354 tokenize( parser_data, 355 (xmlChar *)xmlBufferContent(parser_data->meta_buf), 356 xmlBufferLength(parser_data->meta_buf), 353 357 metaname, 354 358 context … … 356 360 } 357 361 358 xmlBufferEmpty(parse _data->meta_buf);362 xmlBufferEmpty(parser_data->meta_buf); 359 363 360 364 } … … 365 369 mystartDocument(void *data) 366 370 { 367 /* swish_Parse Data *parse_data = (swish_ParseData *) data; */371 /* swish_ParserData *parser_data = (swish_ParserData *) data; */ 368 372 369 373 if (SWISH_DEBUG > 2) … … 375 379 /* SAX2 callback */ 376 380 static void 377 myendDocument(void *parse _data)381 myendDocument(void *parser_data) 378 382 { 379 383 … … 382 386 383 387 /* whatever's left */ 384 flush_buffer(parse _data, (xmlChar*)SWISH_DEFAULT_METANAME, (xmlChar*)SWISH_DEFAULT_METANAME);388 flush_buffer(parser_data, (xmlChar*)SWISH_DEFAULT_METANAME, (xmlChar*)SWISH_DEFAULT_METANAME); 385 389 386 390 } … … 431 435 open_tag(void *data, const xmlChar * tag, const xmlChar ** atts) 432 436 { 433 swish_Parse Data *parse_data = (swish_ParseData *) data;434 435 if (parse _data->tag != NULL)436 swish_xfree(parse _data->tag);437 438 parse _data->tag = build_tag(parse_data, (xmlChar *) tag, (xmlChar **) atts);439 440 441 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)442 SWISH_DEBUG_MSG("checking config for '%s' in watched tags", parse _data->tag);437 swish_ParserData *parser_data = (swish_ParserData *) data; 438 439 if (parser_data->tag != NULL) 440 swish_xfree(parser_data->tag); 441 442 parser_data->tag = build_tag(parser_data, (xmlChar *) tag, (xmlChar **) atts); 443 444 445 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 446 SWISH_DEBUG_MSG("checking config for '%s' in watched tags", parser_data->tag); 443 447 444 448 445 449 /* set property if this tag is configured for it */ 446 if (swish_config_value_exists(parse _data->s3->config, (xmlChar*)SWISH_PROP, parse_data->tag))447 { 448 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)449 SWISH_DEBUG_MSG(" %s = new property", parse _data->tag);450 451 add_stack_to_prop_buf(NULL, parse _data);452 xmlBufferEmpty(parse _data->prop_buf);453 454 parse _data->propstack = push_tag_stack(parse_data->propstack, parse_data->tag);455 456 /* SWISH_DEBUG_MSG("%s pushed ok unto propstack", parse _data->tag); */450 if (swish_config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_PROP, parser_data->tag)) 451 { 452 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 453 SWISH_DEBUG_MSG(" %s = new property", parser_data->tag); 454 455 add_stack_to_prop_buf(NULL, parser_data); 456 xmlBufferEmpty(parser_data->prop_buf); 457 458 parser_data->propstack = push_tag_stack(parser_data->propstack, parser_data->tag); 459 460 /* SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag); */ 457 461 } 458 462 459 463 /* likewise for metastack */ 460 if (swish_config_value_exists(parse _data->s3->config, (xmlChar*)SWISH_META, parse_data->tag))461 { 462 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)463 SWISH_DEBUG_MSG(" %s = new metaname", parse _data->tag);464 if (swish_config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_META, parser_data->tag)) 465 { 466 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 467 SWISH_DEBUG_MSG(" %s = new metaname", parser_data->tag); 464 468 465 flush_buffer( parse _data, parse_data->metastack->head->name, parse_data->metastack->flat );466 467 parse _data->metastack = push_tag_stack(parse_data->metastack, parse_data->tag);468 } 469 470 if (SWISH_DEBUG == SWISH_DEBUG_PARSER)471 SWISH_DEBUG_MSG("config check for '%s' done", parse _data->tag);469 flush_buffer( parser_data, parser_data->metastack->head->name, parser_data->metastack->flat ); 470 471 parser_data->metastack = push_tag_stack(parser_data->metastack, parser_data->tag); 472 } 473 474 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 475 SWISH_DEBUG_MSG("config check for '%s' done", parser_data->tag); 472 476 473 477 … … 478 482 { 479 483 xmlChar *context; 480 swish_Parse Data *parse_data;481 parse _data = (swish_ParseData *) data;484 swish_ParserData *parser_data; 485 parser_data = (swish_ParserData *) data; 482 486 483 487 /* lowercase all names for comparison against metanames (which are also 484 488 * lowercased) */ 485 if (parse _data->tag != NULL)486 swish_xfree(parse _data->tag);487 488 parse _data->tag = build_tag(parse_data, (xmlChar *) tag, NULL);489 if (parser_data->tag != NULL) 490 swish_xfree(parser_data->tag); 491 492 parser_data->tag = build_tag(parser_data, (xmlChar *) tag, NULL); 489 493 490 494 if (SWISH_DEBUG > 2) 491 SWISH_DEBUG_MSG(" endElement(%s) (%s)", (xmlChar *) tag, parse _data->tag);492 493 if ((context = pop_tag_stack_on_match(parse _data->propstack, parse_data->tag)) != NULL)495 SWISH_DEBUG_MSG(" endElement(%s) (%s)", (xmlChar *) tag, parser_data->tag); 496 497 if ((context = pop_tag_stack_on_match(parser_data->propstack, parser_data->tag)) != NULL) 494 498 { 495 499 //SWISH_DEBUG_MSG("popped %s from propstack", context); 496 add_stack_to_prop_buf(parse _data->tag, parse_data);497 xmlBufferEmpty(parse _data->prop_buf);500 add_stack_to_prop_buf(parser_data->tag, parser_data); 501 xmlBufferEmpty(parser_data->prop_buf); 498 502 swish_xfree(context); 499 503 } 500 504 501 if ((context = pop_tag_stack_on_match(parse _data->metastack, parse_data->tag)) != NULL)502 { 503 /* SWISH_DEBUG_MSG("popped %s from metastack", parse _data->tag); */504 flush_buffer(parse _data, parse_data->tag, context);505 if ((context = pop_tag_stack_on_match(parser_data->metastack, parser_data->tag)) != NULL) 506 { 507 /* SWISH_DEBUG_MSG("popped %s from metastack", parser_data->tag); */ 508 flush_buffer(parser_data, parser_data->tag, context); 505 509 swish_xfree(context); 506 510 } 507 511 508 512 /* turn flag off so next open_tag() can evaluate */ 509 parse _data->bump_word = 0;513 parser_data->bump_word = 0; 510 514 511 515 } … … 513 517 /* handle all characters in doc */ 514 518 static void 515 buffer_characters(swish_Parse Data * parse_data, const xmlChar * ch, int len)519 buffer_characters(swish_ParserData * parser_data, const xmlChar * ch, int len) 516 520 { 517 521 int i; 518 522 xmlChar output[len]; 519 xmlBufferPtr buf = parse _data->meta_buf;523 xmlBufferPtr buf = parser_data->meta_buf; 520 524 /* 521 525 * why not wchar_t ? len is number of bytes, not number of … … 538 542 output[i] = (xmlChar) NULL; 539 543 540 if (parse _data->bump_word && xmlBufferLength(buf))544 if (parser_data->bump_word && xmlBufferLength(buf)) 541 545 swish_append_buffer(buf, (xmlChar*)" ", 1); 542 546 543 547 swish_append_buffer(buf, output, len); 544 548 545 if (parse _data->bump_word && xmlBufferLength(parse_data->prop_buf))549 if (parser_data->bump_word && xmlBufferLength(parser_data->prop_buf)) 546 550 { 547 551 //SWISH_DEBUG_MSG(" appending ' ' to prop_buf"); 548 swish_append_buffer(parse _data->prop_buf, (xmlChar*)" ", 1);552 swish_append_buffer(parser_data->prop_buf, (xmlChar*)" ", 1); 549 553 } 550 554 551 555 //SWISH_DEBUG_MSG(" appending '%s' to prop_buf", output); 552 swish_append_buffer(parse _data->prop_buf, output, len);556 swish_append_buffer(parser_data->prop_buf, output, len); 553 557 554 558 … … 558 562 /* SAX2 callback */ 559 563 static void 560 mycharacters(void *parse _data, const xmlChar * ch, int len)564 mycharacters(void *parser_data, const xmlChar * ch, int len) 561 565 { 562 566 if (SWISH_DEBUG > 2) 563 567 SWISH_DEBUG_MSG(" >> mycharacters()"); 564 568 565 buffer_characters(parse _data, ch, len);569 buffer_characters(parser_data, ch, len); 566 570 } 567 571 … … 569 573 /* SAX2 callback */ 570 574 static void 571 mycomments(void *parse _data, const xmlChar * ch)575 mycomments(void *parser_data, const xmlChar * ch) 572 576 { 573 577 int len = strlen((char *) (char *) ch); … … 577 581 return; 578 582 579 buffer_characters(parse _data, ch, len);583 buffer_characters(parser_data, ch, len); 580 584 } 581 585 … … 595 599 va_list args; 596 600 char str[1000]; 597 swish_Parse Data *parse_data = (swish_ParseData *) user_data;601 swish_ParserData *parser_data = (swish_ParserData *) user_data; 598 602 599 603 va_start(args, msg); 600 604 vsnprintf((char *) str, 1000, (char *) msg, args); 601 xmlParserError(parse _data->ctxt, (char *) str);605 xmlParserError(parser_data->ctxt, (char *) str); 602 606 va_end(args); 603 607 … … 617 621 va_list args; 618 622 char str[1000]; 619 swish_Parse Data *parse_data = (swish_ParseData *) user_data;623 swish_ParserData *parser_data = (swish_ParserData *) user_data; 620 624 621 625 va_start(args, msg); 622 626 vsnprintf((char *) str, 1000, (char *) msg, args); 623 xmlParserWarning(parse _data->ctxt, (char *) str);627 xmlParserWarning(parser_data->ctxt, (char *) str); 624 628 va_end(args); 625 629 } … … 668 672 static int 669 673 docparser( 670 swish_Parse Data * parse_data,674 swish_ParserData * parser_data, 671 675 xmlChar * filename, 672 676 xmlChar * buffer, … … 675 679 676 680 int ret; 677 xmlChar *mime = (xmlChar *) parse _data->docinfo->mime;678 xmlChar *parser = (xmlChar *) parse _data->docinfo->parser;679 680 if (!size && !xmlStrlen(buffer) && !parse _data->docinfo->size)681 xmlChar *mime = (xmlChar *) parser_data->docinfo->mime; 682 xmlChar *parser = (xmlChar *) parser_data->docinfo->parser; 683 684 if (!size && !xmlStrlen(buffer) && !parser_data->docinfo->size) 681 685 { 682 686 SWISH_WARN("%s appears to be empty -- can't parse it", 683 parse _data->docinfo->uri);687 parser_data->docinfo->uri); 684 688 685 689 return 1; … … 688 692 689 693 if (SWISH_DEBUG) 690 SWISH_DEBUG_MSG("%s -- using %s parser", parse _data->docinfo->uri, parser);694 SWISH_DEBUG_MSG("%s -- using %s parser", parser_data->docinfo->uri, parser); 691 695 692 696 … … 694 698 if (filename && !buffer) 695 699 { 696 buffer = swish_slurp_file_len(filename, (long) parse _data->docinfo->size);697 size = parse _data->docinfo->size;700 buffer = swish_slurp_file_len(filename, (long) parser_data->docinfo->size); 701 size = parser_data->docinfo->size; 698 702 } 699 703 700 704 if (parser[0] == 'H') 701 705 { 702 parse _data->is_html = 1;703 ret = html_parser(my_parser_ptr, parse _data, buffer, size);706 parser_data->is_html = 1; 707 ret = html_parser(my_parser_ptr, parser_data, buffer, size); 704 708 } 705 709 … … 708 712 ret = xmlSAXUserParseMemory(debugSAX2Handler, NULL, (const char *) buffer, size); 709 713 #else 710 ret = xml_parser(my_parser_ptr, parse _data, buffer, size);714 ret = xml_parser(my_parser_ptr, parser_data, buffer, size); 711 715 #endif 712 716 713 717 else if (parser[0] == 'T') 714 ret = txt_parser(parse _data, (xmlChar *) buffer, size);718 ret = txt_parser(parser_data, (xmlChar *) buffer, size); 715 719 716 720 else … … 729 733 730 734 731 static swish_Parse Data *732 init_parse _data( swish_3 * s3 )735 static swish_ParserData * 736 init_parser_data( swish_3 * s3 ) 733 737 { 734 738 735 739 if (SWISH_DEBUG > 9) 736 SWISH_DEBUG_MSG("init parse _data");737 738 swish_Parse Data *ptr = (swish_ParseData *) swish_xmalloc(sizeof(swish_ParseData));740 SWISH_DEBUG_MSG("init parser_data"); 741 742 swish_ParserData *ptr = (swish_ParserData *) swish_xmalloc(sizeof(swish_ParserData)); 739 743 740 744 ptr->s3 = s3; 745 ptr->s3->ref_cnt++; 741 746 742 747 ptr->meta_buf = xmlBufferCreateSize(SWISH_BUFFER_CHUNK_SIZE); … … 791 796 792 797 if (SWISH_DEBUG > 9) 793 SWISH_DEBUG_MSG("init done for parse _data");798 SWISH_DEBUG_MSG("init done for parser_data"); 794 799 795 800 … … 800 805 801 806 static void 802 free_parse _data(swish_ParseData * ptr)807 free_parser_data(swish_ParserData * ptr) 803 808 { 804 809 805 810 if (SWISH_DEBUG > 9) 806 SWISH_DEBUG_MSG("freeing swish_ParseData"); 811 SWISH_DEBUG_MSG("freeing swish_ParserData"); 812 813 /* dec ref count for shared ptr */ 814 ptr->s3->ref_cnt--; 807 815 808 816 /* Pop the stacks */ … … 815 823 816 824 if (SWISH_DEBUG > 9) 817 SWISH_DEBUG_MSG("freeing swish_Parse Data metastack");825 SWISH_DEBUG_MSG("freeing swish_ParserData metastack"); 818 826 819 827 swish_xfree(ptr->metastack); … … 827 835 828 836 if (SWISH_DEBUG > 9) 829 SWISH_DEBUG_MSG("freeing swish_Parse Data propstack");837 SWISH_DEBUG_MSG("freeing swish_ParserData propstack"); 830 838 831 839 swish_xfree(ptr->propstack); … … 833 841 834 842 if (SWISH_DEBUG > 9) 835 SWISH_DEBUG_MSG("freeing swish_Parse Data properties");843 SWISH_DEBUG_MSG("freeing swish_ParserData properties"); 836 844 837 845 swish_free_nb(ptr->properties); 838 846 839 847 if (SWISH_DEBUG > 9) 840 SWISH_DEBUG_MSG("freeing swish_Parse Data metanames");848 SWISH_DEBUG_MSG("freeing swish_ParserData metanames"); 841 849 842 850 swish_free_nb(ptr->metanames); … … 844 852 845 853 if (SWISH_DEBUG > 9) 846 SWISH_DEBUG_MSG("freeing swish_Parse Data xmlBuffer");854 SWISH_DEBUG_MSG("freeing swish_ParserData xmlBuffer"); 847 855 848 856 xmlBufferFree( ptr->meta_buf ); … … 850 858 851 859 if (SWISH_DEBUG > 9) 852 SWISH_DEBUG_MSG("freeing swish_Parse Data prop xmlBuffer");860 SWISH_DEBUG_MSG("freeing swish_ParserData prop xmlBuffer"); 853 861 854 862 xmlBufferFree( ptr->prop_buf ); … … 856 864 857 865 if (SWISH_DEBUG > 9) 858 SWISH_DEBUG_MSG("freeing swish_Parse Data tag");866 SWISH_DEBUG_MSG("freeing swish_ParserData tag"); 859 867 860 868 if (ptr->tag != NULL) … … 866 874 867 875 if (SWISH_DEBUG > 9) 868 SWISH_DEBUG_MSG("freeing swish_Parse Data libxml2 parser ctxt");876 SWISH_DEBUG_MSG("freeing swish_ParserData libxml2 parser ctxt"); 869 877 870 878 if (xmlStrEqual(ptr->docinfo->parser, (xmlChar *) SWISH_PARSER_XML)) … … 877 885 { 878 886 if (SWISH_DEBUG > 9) 879 SWISH_DEBUG_MSG("swish_Parse Data libxml2 parser ctxt already freed");887 SWISH_DEBUG_MSG("swish_ParserData libxml2 parser ctxt already freed"); 880 888 881 889 } … … 885 893 886 894 if (SWISH_DEBUG > 9) 887 SWISH_DEBUG_MSG("free swish_Parse Data wordList");895 SWISH_DEBUG_MSG("free swish_ParserData wordList"); 888 896 889 897 swish_free_wordlist(ptr->wordlist); … … 894 902 895 903 if (SWISH_DEBUG > 9) 896 SWISH_DEBUG_MSG("free swish_Parse Data docinfo");904 SWISH_DEBUG_MSG("free swish_ParserData docinfo"); 897 905 898 906 swish_free_docinfo(ptr->docinfo); … … 901 909 902 910 if (SWISH_DEBUG > 9) 903 SWISH_DEBUG_MSG("freeing swish_Parse Data ptr");911 SWISH_DEBUG_MSG("freeing swish_ParserData ptr"); 904 912 905 913 swish_xfree(ptr); … … 1193 1201 xmlChar *read_buffer; 1194 1202 xmlBufferPtr head_buf; 1195 swish_Parse Data *parse_data;1203 swish_ParserData *parser_data; 1196 1204 int xmlErr; 1197 1205 int min_headers, nheaders; … … 1244 1252 /* blank line indicates body */ 1245 1253 curTime = swish_time_elapsed(); 1246 parse _data = init_parse_data(s3);1254 parser_data = init_parser_data(s3); 1247 1255 head = buf_to_head( (xmlChar*)xmlBufferContent(head_buf) ); 1248 parse _data->docinfo = head_to_docinfo(head);1249 swish_check_docinfo(parse _data->docinfo, s3->config);1256 parser_data->docinfo = head_to_docinfo(head); 1257 swish_check_docinfo(parser_data->docinfo, s3->config); 1250 1258 1251 1259 if (SWISH_DEBUG > 9) 1252 1260 SWISH_DEBUG_MSG("reading %ld bytes from filehandle\n", 1253 (long int) parse _data->docinfo->size);1254 1255 read_buffer = swish_slurp_fh(fh, parse _data->docinfo->size);1261
