Changeset 2027

Show
Ignore:
Timestamp:
02/23/08 22:31:16 (3 months ago)
Author:
karpet
Message:

rename ParseData? to ParserData?; add more debug env vars; implement c ptr ref counting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/analyzer.c

    r2010 r2027  
    3737    a->minwordlen = SWISH_MIN_WORD_LEN; 
    3838    a->lc         = 1; 
    39     a->ref_cnt    = 0
     39    a->ref_cnt    = 1
    4040         
    4141    if (xmlStrEqual((xmlChar*)SWISH_DEFAULT_VALUE, 
     
    8080swish_free_analyzer( swish_Analyzer * a ) 
    8181{ 
     82    a->ref_cnt--; 
     83    if (a->ref_cnt > 0) { 
     84        SWISH_WARN("analyzer ref_cnt > 0: %d\n", a->ref_cnt); 
     85    } 
    8286    swish_xfree(a);    
    8387} 
  • libswish3/trunk/src/libswish3/config.c

    r2010 r2027  
    6262free_config2(void *payload, xmlChar * key) 
    6363{ 
    64     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     64    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    6565        SWISH_DEBUG_MSG("   freeing config %s => %s", key, (xmlChar *) payload); 
    6666 
     
    7373    int             size = xmlHashSize((xmlHashTablePtr) payload); 
    7474 
    75     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     75    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    7676    { 
    7777        SWISH_DEBUG_MSG(" freeing config %s =>", confName); 
     
    8989    int             size = xmlHashSize(config->conf); 
    9090 
    91     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     91    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    9292    { 
    9393        SWISH_DEBUG_MSG("freeing config"); 
     
    120120    xmlHashTablePtr c, metas, parsers, index, prop, alias, parsewords; 
    121121 
    122     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     122    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    123123        SWISH_DEBUG_MSG("creating default config"); 
    124124 
     
    217217 
    218218    config->conf = c; 
    219     config->ref_cnt = 0
     219    config->ref_cnt = 1
    220220    config->stash = NULL; 
    221221    config->flags = flags; 
    222222 
    223223 
    224     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     224    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    225225        swish_debug_config(config); 
    226226 
     
    235235    config = swish_parse_config(conf, config); 
    236236 
    237     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     237    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    238238        swish_debug_config(config); 
    239239 
     
    453453    { 
    454454        doc = xmlParseFile((const char *) conf); 
    455         if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     455        if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    456456            SWISH_DEBUG_MSG("Parsing configuration file: %s", conf); 
    457457    } 
     
    459459    { 
    460460        doc = xmlParseMemory((const char *) conf, xmlStrlen(conf)); 
    461         if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     461        if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    462462            SWISH_DEBUG_MSG("Parsing configuration from memory"); 
    463463    } 
     
    683683                else 
    684684                { 
    685                     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     685                    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    686686                        SWISH_DEBUG_MSG(" >>> found existing name in config: %s", opt_name); 
    687687 
     
    727727                tmp_arg = arg_list->word[i]; 
    728728 
    729                 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     729                if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    730730                    SWISH_DEBUG_MSG("config %s tmp_arg = %s  opt_type = %s", opt_name, tmp_arg, opt_type); 
    731731 
     
    744744                { 
    745745                    free_tmp = 1; 
    746                     if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     746                    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    747747                        SWISH_DEBUG_MSG("tolower str: >%s<", tmp_arg); 
    748748 
     
    751751                } 
    752752 
    753                 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     753                if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    754754                    SWISH_DEBUG_MSG("config %s tmp_arg = %s  tmp_value = %s", opt_name, tmp_arg, tmp_value); 
    755755 
     
    778778            if (!name_seen && xmlStrcmp(opt_name, (xmlChar *) "IncludeConfigFile")) 
    779779            { 
    780                 if (SWISH_DEBUG == SWISH_DEBUG_CONFIG) 
     780                if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    781781                    SWISH_DEBUG_MSG(" >>> adding %s to config hash ( name_seen = %d )", opt_name, name_seen); 
    782782 
  • libswish3/trunk/src/libswish3/docinfo.c

    r2010 r2027  
    171171/* PUBLIC */ 
    172172int 
    173 swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_ParseData *parse_data ) 
     173swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_ParserData *parser_data ) 
    174174{ 
    175175    struct  stat info; 
     
    205205        swish_xfree(i->mime); 
    206206         
    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 ); 
    208208         
    209209    if (SWISH_DEBUG > 9) 
     
    213213        swish_xfree(i->parser); 
    214214         
    215     i->parser = swish_get_parser( parse_data->s3->config, i->mime ); 
     215    i->parser = swish_get_parser( parser_data->s3->config, i->mime ); 
    216216     
    217217    return 1; 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2010 r2027  
    125125 
    126126/* debugging levels */ 
    127 #define SWISH_DEBUG_MEMORY      13 
    128 #define SWISH_DEBUG_CONFIG      11 
    129127#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 
    134134 
    135135#define SWISH_DEBUG_MSG(args...)                                    \ 
     
    160160typedef struct swish_Word               swish_Word; 
    161161typedef struct swish_WordList           swish_WordList; 
    162 typedef struct swish_ParseData          swish_ParseData; 
     162typedef struct swish_ParserData          swish_ParserData; 
    163163typedef struct swish_Tag                swish_Tag; 
    164164typedef struct swish_TagStack           swish_TagStack; 
     
    311311{ 
    312312    int                    ref_cnt;             // for script bindings 
    313     void                 (*handler)(swish_ParseData*); // handler reference 
     313    void                 (*handler)(swish_ParserData*); // handler reference 
    314314    void                  *stash;               // for script bindings 
    315315}; 
    316316 
    317317// TODO maybe store swish_Parser * here instead of separate config and analyzer 
    318 struct swish_ParseData 
     318struct swish_ParserData 
    319319{ 
    320320    swish_3               *s3;                 // main object 
     
    344344=head2 Object Functions 
    345345*/ 
    346 swish_3 *   swish_init_swish3( void (*handler) (swish_ParseData *), void *stash ); 
     346swish_3 *   swish_init_swish3( void (*handler) (swish_ParserData *), void *stash ); 
    347347void        swish_free_swish3( swish_3 *s3 ); 
    348348/* 
     
    457457=head2 Parser Functions 
    458458*/ 
    459 swish_Parser *  swish_init_parser(  void (*handler) (swish_ParseData *) ); 
     459swish_Parser *  swish_init_parser(  void (*handler) (swish_ParserData *) ); 
    460460void            swish_free_parser(  swish_Parser * parser ); 
    461461int             swish_parse_file(   swish_3 * s3, 
     
    542542int                 swish_docinfo_from_filesystem(  xmlChar *filename,  
    543543                                                    swish_DocInfo * i,  
    544                                                     swish_ParseData *parse_data ); 
     544                                                    swish_ParserData *parser_data ); 
    545545void                swish_debug_docinfo( swish_DocInfo * docinfo ); 
    546546xmlChar *           swish_get_file_ext( xmlChar *url ); 
  • libswish3/trunk/src/libswish3/namedbuffer.c

    r1952 r2027  
    5858free_name_from_hash(void *buffer, xmlChar * name) 
    5959{ 
    60     if (SWISH_DEBUG == SWISH_DEBUG_NAMEDBUFFER) 
     60    if (SWISH_DEBUG >= SWISH_DEBUG_NAMEDBUFFER) 
    6161        SWISH_DEBUG_MSG(" freeing NamedBuffer %s\n", name); 
    6262 
     
    6969    swish_NamedBuffer * nb = swish_xmalloc(sizeof(swish_NamedBuffer)); 
    7070    nb->stash   = NULL; 
    71     nb->ref_cnt = 0
     71    nb->ref_cnt = 1
    7272    nb->hash    = xmlHashCreate(8);    /* will grow as needed */ 
    7373     
     
    8484{ 
    8585    xmlHashFree(nb->hash, (xmlHashDeallocator)free_name_from_hash); 
    86      
     86    
     87    nb->ref_cnt--;  
    8788    if (nb->ref_cnt > 0) 
    8889        SWISH_WARN("freeing NamedBuffer with ref_cnt > 0 (%d)", nb->ref_cnt); 
  • libswish3/trunk/src/libswish3/parser.c

    r2010 r2027  
    6464static void     get_env_vars(); 
    6565 
    66 static void     flush_buffer(   swish_ParseData * parse_data,  
     66static void     flush_buffer(   swish_ParserData * parser_data,  
    6767                                xmlChar * metaname, xmlChar * context 
    6868                                ); 
    6969 
    70 static void     tokenize(       swish_ParseData * parse_data,  
     70static void     tokenize(       swish_ParserData * parser_data,  
    7171                                xmlChar * string,  
    7272                                int len,  
     
    7676 
    7777static xmlChar *flatten_tag_stack(xmlChar * tag, swish_TagStack * stack); 
    78 static void     add_stack_to_prop_buf(xmlChar * tag, swish_ParseData * parse_data); 
     78static void     add_stack_to_prop_buf(xmlChar * tag, swish_ParserData * parser_data); 
    7979static swish_TagStack * 
    8080                push_tag_stack(swish_TagStack * stack, xmlChar * tag); 
     
    8282static xmlChar *pop_tag_stack_on_match(swish_TagStack * stack, xmlChar * tag); 
    8383 
    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); 
     84static void     mystartDocument(void *parser_data); 
     85static void     myendDocument(void *parser_data); 
     86static void     mystartElement(void *parser_data, const xmlChar * name, const xmlChar ** atts); 
     87static void     myendElement(void *parser_data, const xmlChar * name); 
    8888 
    8989/* SAX2 support */ 
    9090static void  
    9191mystartElementNs( 
    92          void *parse_data, 
     92         void *parser_data, 
    9393         const xmlChar * localname, 
    9494         const xmlChar * prefix, 
     
    107107           const xmlChar * URI); 
    108108 
    109 static void     buffer_characters(swish_ParseData * 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); 
     109static void     buffer_characters(swish_ParserData * parser_data, const xmlChar * ch, int len); 
     110static void     mycharacters(void *parser_data, const xmlChar * ch, int len); 
     111static void     mycomments(void *parser_data, const xmlChar * ch); 
    112112static void     myerr(void *user_data, xmlChar * msg,...); 
    113113 
     
    115115static void     open_tag(void *data, const xmlChar * tag, const xmlChar ** atts); 
    116116static void     close_tag(void *data, const xmlChar * tag); 
    117 static xmlChar *build_tag(swish_ParseData * parse_data, xmlChar * tag, xmlChar ** atts); 
    118  
    119 static int      docparser(swish_ParseData * parse_data, xmlChar * filename, xmlChar * buffer, int size); 
     117static xmlChar *build_tag(swish_ParserData * parser_data, xmlChar * tag, xmlChar ** atts); 
     118 
     119static int      docparser(swish_ParserData * parser_data, xmlChar * filename, xmlChar * buffer, int size); 
    120120static int      xml_parser(xmlSAXHandlerPtr sax, void *user_data, xmlChar * buffer, int size); 
    121121static int      html_parser(xmlSAXHandlerPtr sax, void *user_data, xmlChar * buffer, int size); 
    122 static int      txt_parser(swish_ParseData * parse_data, xmlChar * buffer, int size); 
    123  
    124 static swish_ParseData * 
    125                 init_parse_data(swish_3 * s3); 
    126 static void     free_parse_data(swish_ParseData * parse_data); 
     122static int      txt_parser(swish_ParserData * parser_data, xmlChar * buffer, int size); 
     123 
     124static swish_ParserData * 
     125                init_parser_data(swish_3 * s3); 
     126static void     free_parser_data(swish_ParserData * parser_data); 
    127127 
    128128/* parsing fh/buffer headers */ 
     
    140140static xmlChar *document_encoding(xmlParserCtxtPtr ctxt); 
    141141 
    142 static void     set_encoding(swish_ParseData * parse_data, xmlChar * buffer); 
     142static void     set_encoding(swish_ParserData * parser_data, xmlChar * buffer); 
    143143 
    144144 
     
    150150swish_Parser * 
    151151swish_init_parser(  
    152     void (*handler) (swish_ParseData *) 
     152    void (*handler) (swish_ParserData *) 
    153153) 
    154154{    
    155155    swish_Parser * p = (swish_Parser*) swish_xmalloc(sizeof(swish_Parser)); 
    156156    p->handler  = handler; 
    157     p->ref_cnt  = 0
     157    p->ref_cnt  = 1
    158158     
    159159    /* libxml2 stuff */ 
     
    170170swish_free_parser( swish_Parser * p ) 
    171171{         
     172    p->ref_cnt--; 
     173    if (p->ref_cnt > 0) { 
     174        SWISH_WARN("parser ref_cnt > 0: %d\n", p->ref_cnt); 
     175    } 
    172176    xmlCleanupParser(); 
    173177    xmlMemoryDump(); 
     
    178182 * properties */ 
    179183static xmlChar * 
    180 build_tag(swish_ParseData * parse_data, xmlChar * tag, xmlChar ** atts) 
     184build_tag(swish_ParserData * parser_data, xmlChar * tag, xmlChar ** atts) 
    181185{ 
    182186    int      i, is_html_tag; 
     
    190194 
    191195    /* html tags */ 
    192     if (parse_data->is_html) 
     196    if (parser_data->is_html) 
    193197    { 
    194198 
     
    198202            ) 
    199203        { 
    200             parse_data->bump_word = 1; 
     204            parser_data->bump_word = 1; 
    201205        } 
    202206        else 
     
    245249        if (metaname != NULL && metacontent != NULL) 
    246250        { 
    247             if (SWISH_DEBUG == SWISH_DEBUG_PARSER) 
     251            if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
    248252                SWISH_DEBUG_MSG("found HTML meta: %s => %s", metaname, metacontent); 
    249253                 
    250254            /* 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); 
    255259            swish_xfree(swishtag); 
    256260            return NULL; 
     
    266270        /* TODO make this configurable ala swish2 */ 
    267271 
    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); 
    276280        if (atts != 0) 
    277281        { 
     
    290294 
    291295    /* 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); 
    293297    if (alias) 
    294298    { 
     
    304308 
    305309static void 
    306 flush_buffer(swish_ParseData * parse_data, xmlChar * metaname, xmlChar * context) 
    307 { 
    308     swish_TagStack *s = parse_data->metastack; 
    309      
    310     if (SWISH_DEBUG == SWISH_DEBUG_PARSER) 
     310flush_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) 
    311315        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); 
    313317 
    314318    /* since we only flush the buffer when metaname changes, and 
     
    316320     * before parsing the string and making the tmp wordlist 
    317321     */ 
    318     if (parse_data->word_pos) 
    319         parse_data->word_pos++; 
     322    if (parser_data->word_pos) 
     323        parser_data->word_pos++; 
    320324         
    321325    /* add meta_buf as-is to metanames buffer under current tag. 
    322326       this gives us both tokens and raw text de-tagged but organized by metaname. 
    323327    */ 
    324     swish_add_buf_to_nb( parse_data->metanames, 
     328    swish_add_buf_to_nb( parser_data->metanames, 
    325329                         metaname, 
    326                          parse_data->meta_buf,  
     330                         parser_data->meta_buf,  
    327331                         (xmlChar*)SWISH_META_CONNECTOR,  
    328332                         0,  
    329333                         1); 
    330334                          
    331     if (parse_data->context_as_meta) 
     335    if (parser_data->context_as_meta) 
    332336    { 
    333337        for (s->temp = s->head; s->temp != NULL; s->temp = s->temp->next) 
     
    336340                continue; 
    337341             
    338             swish_add_buf_to_nb(parse_data->metanames, 
     342            swish_add_buf_to_nb(parser_data->metanames, 
    339343                                s->temp->name,  
    340                                 parse_data->meta_buf,  
     344                                parser_data->meta_buf,  
    341345                                (xmlChar*)SWISH_META_CONNECTOR,  
    342346                                0,  
     
    345349    }                     
    346350 
    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), 
    353357                    metaname, 
    354358                    context 
     
    356360    } 
    357361 
    358     xmlBufferEmpty(parse_data->meta_buf); 
     362    xmlBufferEmpty(parser_data->meta_buf); 
    359363 
    360364} 
     
    365369mystartDocument(void *data) 
    366370{ 
    367     /* swish_ParseData *parse_data = (swish_ParseData *) data; */ 
     371    /* swish_ParserData *parser_data = (swish_ParserData *) data; */ 
    368372 
    369373    if (SWISH_DEBUG > 2) 
     
    375379/* SAX2 callback */ 
    376380static void 
    377 myendDocument(void *parse_data) 
     381myendDocument(void *parser_data) 
    378382{ 
    379383 
     
    382386 
    383387    /* 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); 
    385389 
    386390} 
     
    431435open_tag(void *data, const xmlChar * tag, const xmlChar ** atts) 
    432436{ 
    433     swish_ParseData *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); 
    443447 
    444448 
    445449    /* 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);  */ 
    457461    } 
    458462 
    459463    /* 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); 
    464468                                
    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); 
    472476 
    473477 
     
    478482{ 
    479483    xmlChar         *context; 
    480     swish_ParseData *parse_data; 
    481     parse_data = (swish_ParseData *) data; 
     484    swish_ParserData *parser_data; 
     485    parser_data = (swish_ParserData *) data; 
    482486 
    483487    /* lowercase all names for comparison against metanames (which are also 
    484488     * 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); 
    489493 
    490494    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) 
    494498    { 
    495499        //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); 
    498502        swish_xfree(context); 
    499503    } 
    500504 
    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); 
    505509        swish_xfree(context); 
    506510    } 
    507511 
    508512    /* turn flag off so next open_tag() can evaluate */ 
    509     parse_data->bump_word = 0; 
     513    parser_data->bump_word = 0; 
    510514 
    511515} 
     
    513517/* handle all characters in doc */ 
    514518static void 
    515 buffer_characters(swish_ParseData * parse_data, const xmlChar * ch, int len) 
     519buffer_characters(swish_ParserData * parser_data, const xmlChar * ch, int len) 
    516520{ 
    517521    int             i; 
    518522    xmlChar         output[len]; 
    519     xmlBufferPtr    buf = parse_data->meta_buf; 
     523    xmlBufferPtr    buf = parser_data->meta_buf; 
    520524    /* 
    521525     * why not wchar_t ? len is number of bytes, not number of 
     
    538542    output[i] = (xmlChar) NULL; 
    539543 
    540     if (parse_data->bump_word && xmlBufferLength(buf)) 
     544    if (parser_data->bump_word && xmlBufferLength(buf)) 
    541545        swish_append_buffer(buf, (xmlChar*)" ", 1); 
    542546 
    543547    swish_append_buffer(buf, output, len); 
    544548 
    545     if (parse_data->bump_word && xmlBufferLength(parse_data->prop_buf)) 
     549    if (parser_data->bump_word && xmlBufferLength(parser_data->prop_buf)) 
    546550    { 
    547551        //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); 
    549553    } 
    550554     
    551555    //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); 
    553557 
    554558 
     
    558562/* SAX2 callback */ 
    559563static void 
    560 mycharacters(void *parse_data, const xmlChar * ch, int len) 
     564mycharacters(void *parser_data, const xmlChar * ch, int len) 
    561565{ 
    562566    if (SWISH_DEBUG > 2) 
    563567        SWISH_DEBUG_MSG(" >> mycharacters()"); 
    564568 
    565     buffer_characters(parse_data, ch, len); 
     569    buffer_characters(parser_data, ch, len); 
    566570} 
    567571 
     
    569573/* SAX2 callback */ 
    570574static void 
    571 mycomments(void *parse_data, const xmlChar * ch) 
     575mycomments(void *parser_data, const xmlChar * ch) 
    572576{ 
    573577    int             len = strlen((char *) (char *) ch); 
     
    577581    return; 
    578582 
    579     buffer_characters(parse_data, ch, len); 
     583    buffer_characters(parser_data, ch, len); 
    580584} 
    581585 
     
    595599    va_list         args; 
    596600    char            str[1000]; 
    597     swish_ParseData *parse_data = (swish_ParseData *) user_data; 
     601    swish_ParserData *parser_data = (swish_ParserData *) user_data; 
    598602 
    599603    va_start(args, msg); 
    600604    vsnprintf((char *) str, 1000, (char *) msg, args); 
    601     xmlParserError(parse_data->ctxt, (char *) str); 
     605    xmlParserError(parser_data->ctxt, (char *) str); 
    602606    va_end(args); 
    603607     
     
    617621    va_list         args; 
    618622    char            str[1000]; 
    619     swish_ParseData *parse_data = (swish_ParseData *) user_data; 
     623    swish_ParserData *parser_data = (swish_ParserData *) user_data; 
    620624 
    621625    va_start(args, msg); 
    622626    vsnprintf((char *) str, 1000, (char *) msg, args); 
    623     xmlParserWarning(parse_data->ctxt, (char *) str); 
     627    xmlParserWarning(parser_data->ctxt, (char *) str); 
    624628    va_end(args); 
    625629} 
     
    668672static int 
    669673docparser( 
    670       swish_ParseData * parse_data, 
     674      swish_ParserData * parser_data, 
    671675      xmlChar * filename, 
    672676      xmlChar * buffer, 
     
    675679 
    676680    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) 
    681685    { 
    682686        SWISH_WARN("%s appears to be empty -- can't parse it", 
    683                         parse_data->docinfo->uri); 
     687                        parser_data->docinfo->uri); 
    684688                         
    685689        return 1; 
     
    688692 
    689693    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); 
    691695 
    692696 
     
    694698    if (filename && !buffer) 
    695699    { 
    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; 
    698702    } 
    699703 
    700704    if (parser[0] == 'H') 
    701705    { 
    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); 
    704708    } 
    705709 
     
    708712        ret = xmlSAXUserParseMemory(debugSAX2Handler, NULL, (const char *) buffer, size); 
    709713#else 
    710         ret = xml_parser(my_parser_ptr, parse_data, buffer, size); 
     714        ret = xml_parser(my_parser_ptr, parser_data, buffer, size); 
    711715#endif 
    712716 
    713717    else if (parser[0] == 'T') 
    714         ret = txt_parser(parse_data, (xmlChar *) buffer, size); 
     718        ret = txt_parser(parser_data, (xmlChar *) buffer, size); 
    715719 
    716720    else 
     
    729733 
    730734 
    731 static swish_ParseData * 
    732 init_parse_data( swish_3 * s3 ) 
     735static swish_ParserData * 
     736init_parser_data( swish_3 * s3 ) 
    733737{ 
    734738 
    735739    if (SWISH_DEBUG > 9) 
    736         SWISH_DEBUG_MSG("init parse_data"); 
    737  
    738     swish_ParseData *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)); 
    739743     
    740744    ptr->s3 = s3; 
     745    ptr->s3->ref_cnt++; 
    741746     
    742747    ptr->meta_buf = xmlBufferCreateSize(SWISH_BUFFER_CHUNK_SIZE); 
     
    791796     
    792797    if (SWISH_DEBUG > 9) 
    793         SWISH_DEBUG_MSG("init done for parse_data"); 
     798        SWISH_DEBUG_MSG("init done for parser_data"); 
    794799 
    795800 
     
    800805 
    801806static void 
    802 free_parse_data(swish_ParseData * ptr) 
     807free_parser_data(swish_ParserData * ptr) 
    803808{ 
    804809 
    805810    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--; 
    807815 
    808816    /* Pop the stacks */ 
     
    815823 
    816824    if (SWISH_DEBUG > 9) 
    817         SWISH_DEBUG_MSG("freeing swish_ParseData metastack"); 
     825        SWISH_DEBUG_MSG("freeing swish_ParserData metastack"); 
    818826 
    819827    swish_xfree(ptr->metastack); 
     
    827835 
    828836    if (SWISH_DEBUG > 9) 
    829         SWISH_DEBUG_MSG("freeing swish_ParseData propstack"); 
     837        SWISH_DEBUG_MSG("freeing swish_ParserData propstack"); 
    830838 
    831839    swish_xfree(ptr->propstack); 
     
    833841 
    834842    if (SWISH_DEBUG > 9) 
    835         SWISH_DEBUG_MSG("freeing swish_ParseData properties"); 
     843        SWISH_DEBUG_MSG("freeing swish_ParserData properties"); 
    836844 
    837845    swish_free_nb(ptr->properties); 
    838846 
    839847    if (SWISH_DEBUG > 9) 
    840         SWISH_DEBUG_MSG("freeing swish_ParseData metanames"); 
     848        SWISH_DEBUG_MSG("freeing swish_ParserData metanames"); 
    841849 
    842850    swish_free_nb(ptr->metanames); 
     
    844852 
    845853    if (SWISH_DEBUG > 9) 
    846         SWISH_DEBUG_MSG("freeing swish_ParseData xmlBuffer"); 
     854        SWISH_DEBUG_MSG("freeing swish_ParserData xmlBuffer"); 
    847855 
    848856    xmlBufferFree( ptr->meta_buf ); 
     
    850858 
    851859    if (SWISH_DEBUG > 9) 
    852         SWISH_DEBUG_MSG("freeing swish_ParseData prop xmlBuffer"); 
     860        SWISH_DEBUG_MSG("freeing swish_ParserData prop xmlBuffer"); 
    853861 
    854862    xmlBufferFree( ptr->prop_buf ); 
     
    856864 
    857865    if (SWISH_DEBUG > 9) 
    858         SWISH_DEBUG_MSG("freeing swish_ParseData tag"); 
     866        SWISH_DEBUG_MSG("freeing swish_ParserData tag"); 
    859867 
    860868    if (ptr->tag != NULL) 
     
    866874 
    867875        if (SWISH_DEBUG > 9) 
    868             SWISH_DEBUG_MSG("freeing swish_ParseData libxml2 parser ctxt"); 
     876            SWISH_DEBUG_MSG("freeing swish_ParserData libxml2 parser ctxt"); 
    869877 
    870878        if (xmlStrEqual(ptr->docinfo->parser, (xmlChar *) SWISH_PARSER_XML)) 
     
    877885    { 
    878886        if (SWISH_DEBUG > 9) 
    879             SWISH_DEBUG_MSG("swish_ParseData libxml2 parser ctxt already freed"); 
     887            SWISH_DEBUG_MSG("swish_ParserData libxml2 parser ctxt already freed"); 
    880888 
    881889    } 
     
    885893 
    886894        if (SWISH_DEBUG > 9) 
    887             SWISH_DEBUG_MSG("free swish_ParseData wordList"); 
     895            SWISH_DEBUG_MSG("free swish_ParserData wordList"); 
    888896 
    889897        swish_free_wordlist(ptr->wordlist); 
     
    894902 
    895903        if (SWISH_DEBUG > 9) 
    896             SWISH_DEBUG_MSG("free swish_ParseData docinfo"); 
     904            SWISH_DEBUG_MSG("free swish_ParserData docinfo"); 
    897905 
    898906        swish_free_docinfo(ptr->docinfo); 
     
    901909     
    902910    if (SWISH_DEBUG > 9) 
    903         SWISH_DEBUG_MSG("freeing swish_ParseData ptr"); 
     911        SWISH_DEBUG_MSG("freeing swish_ParserData ptr"); 
    904912 
    905913    swish_xfree(ptr); 
     
    11931201    xmlChar             *read_buffer; 
    11941202    xmlBufferPtr        head_buf; 
    1195     swish_ParseData    *parse_data; 
     1203    swish_ParserData    *parser_data; 
    11961204    int                 xmlErr; 
    11971205    int                 min_headers, nheaders; 
     
    12441252        /* blank line indicates body */ 
    12451253            curTime      = swish_time_elapsed(); 
    1246             parse_data   = init_parse_data(s3); 
     1254            parser_data   = init_parser_data(s3); 
    12471255            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); 
    12501258 
    12511259            if (SWISH_DEBUG > 9) 
    12521260                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