Changeset 1931

Show
Ignore:
Timestamp:
05/01/07 23:53:25 (1 year ago)
Author:
karpet
Message:

tweek the metanames NB to separate text chunks with ctrl char \003 and update perl bindings to access NBs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/bindings/perl/3.xs

    r1930 r1931  
    300300 
    301301 
    302 static void _store_xml2_pair_in_perl_hash(xmlChar * val, HV * perl_hash, xmlChar * key) 
     302static void sp_store_xml2_pair_in_perl_hash(xmlChar * val, HV * perl_hash, xmlChar * key) 
    303303{ 
    304304    dTHX; 
     
    306306} 
    307307 
    308 static HV * _xml2_hash_to_perl_hash( xmlHashTablePtr xml2_hash ) 
     308static HV *  
     309sp_xml2_hash_to_perl_hash( xmlHashTablePtr xml2_hash ) 
    309310{ 
    310311    dTHX; 
    311312    HV * perl_hash = newHV(); 
    312313    /* perl bug means we must increm ref count manually */ 
    313     sv_2mortal((SV*)perl_hash); 
    314     xmlHashScan(xml2_hash, (xmlHashScanner)_store_xml2_pair_in_perl_hash, perl_hash); 
     314    SvREFCNT_inc((SV*)perl_hash); 
     315    xmlHashScan(xml2_hash, (xmlHashScanner)sp_store_xml2_pair_in_perl_hash, perl_hash); 
    315316    return perl_hash; 
    316317} 
    317318 
    318 static void _add_key_to_array(xmlChar * val, AV * mykeys, xmlChar * key) 
     319static void  
     320sp_add_key_to_array(xmlChar * val, AV * mykeys, xmlChar * key) 
    319321{ 
    320322    dTHX; 
     
    322324} 
    323325 
    324 static AV * _get_xml2_hash_keys( xmlHashTablePtr xml2_hash ) 
     326static AV *  
     327sp_get_xml2_hash_keys( xmlHashTablePtr xml2_hash ) 
    325328{ 
    326329    dTHX; 
    327330    AV * mykeys = newAV(); 
    328     sv_2mortal((SV*)mykeys); /* needed?? */ 
    329     xmlHashScan(xml2_hash, (xmlHashScanner)_add_key_to_array, mykeys); 
     331    SvREFCNT_inc((SV*)mykeys); /* needed?? */ 
     332    xmlHashScan(xml2_hash, (xmlHashScanner)sp_add_key_to_array, mykeys); 
    330333    return mykeys; 
    331334} 
    332335 
    333  
    334  
    335  
    336 void sp_test_handler( swish_ParseData * parse_data ) 
     336static void 
     337sp_nb_hash_to_phash(xmlBufferPtr buf, HV *phash, xmlChar *key) 
     338
     339 
     340/* TODO: it'd be nice to split on \003 here and make each hash val an AV ref */ 
     341    dTHX; 
     342    hv_store(phash, key, strlen(key),  
     343             newSVpvn((char*)xmlBufferContent(buf), xmlBufferLength(buf)), 
     344             0); 
     345
     346 
     347static HV *  
     348sp_nb_to_hash( swish_NamedBuffer * nb ) 
     349
     350    dTHX; 
     351    HV * perl_hash = newHV(); 
     352    SvREFCNT_inc((SV*)perl_hash); 
     353    xmlHashScan(nb->hash, (xmlHashScanner)sp_nb_hash_to_phash, perl_hash); 
     354    return perl_hash; 
     355
     356 
     357 
     358void  
     359sp_test_handler( swish_ParseData * parse_data ) 
    337360{ 
    338361    dTHX; 
     
    10591082         
    10601083SV* 
    1061 property(self,p) 
     1084property(self, p) 
    10621085    swish_ParseData * self; 
    10631086    xmlChar * p; 
     
    10731096        RETVAL 
    10741097         
     1098HV* 
     1099properties(self) 
     1100    swish_ParseData * self 
     1101     
     1102    CODE: 
     1103        RETVAL = sp_nb_to_hash( self->properties ); 
     1104         
     1105    OUTPUT: 
     1106        RETVAL 
     1107         
     1108 
     1109HV* 
     1110metanames(self) 
     1111    swish_ParseData * self 
     1112     
     1113    CODE: 
     1114        RETVAL = sp_nb_to_hash( self->metanames ); 
     1115         
     1116    OUTPUT: 
     1117        RETVAL 
     1118        
     1119 
    10751120 
    10761121swish_DocInfo * 
     
    11331178     
    11341179    CODE: 
    1135         RETVAL = _get_xml2_hash_keys(self->conf); 
     1180        RETVAL = sp_get_xml2_hash_keys(self->conf); 
    11361181     
    11371182    OUTPUT: 
     
    11511196    CODE: 
    11521197        sc = swish_subconfig_hash(self, (xmlChar*)key); 
    1153         RETVAL = _xml2_hash_to_perl_hash(sc); 
     1198        RETVAL = sp_xml2_hash_to_perl_hash(sc); 
    11541199 
    11551200    OUTPUT: 
  • libswish3/trunk/bindings/perl/t/test.html

    r1914 r1931  
    11<html> 
     2 <head> 
     3  <title>This is the title of the test.html doc</title> 
     4  <meta name="foo" content="metaname bar" /> 
     5 </head> 
    26 <body> 
    37  <p>some words</p> 
  • libswish3/trunk/src/libswish3/libswish3.h

    r1930 r1931  
    102102#define SWISH_PROP_MTIME           "swishlastmodified" 
    103103#define SWISH_PROP_DESCRIPTION     "swishdescription" 
    104 #define SWISH_PROP_CONNECTOR       " | " 
     104#define SWISH_PROP_CONNECTOR       " \3" 
     105#define SWISH_META_CONNECTOR       " \3" 
    105106 
    106107/* utils */ 
  • libswish3/trunk/src/libswish3/parser.c

    r1930 r1931  
    107107           const xmlChar * URI); 
    108108 
    109 static void     chars_to_words(swish_ParseData * parse_data, const xmlChar * ch, int len); 
     109static void     buffer_characters(swish_ParseData * parse_data, const xmlChar * ch, int len); 
    110110static void     mycharacters(void *parse_data, const xmlChar * ch, int len); 
    111111static void     mycomments(void *parse_data, const xmlChar * ch); 
     
    251251        if (metaname != NULL && metacontent != NULL) 
    252252        { 
    253             if (SWISH_DEBUG > 3
     253            if (SWISH_DEBUG == SWISH_DEBUG_PARSER
    254254                swish_debug_msg("found HTML meta: %s => %s", metaname, metacontent); 
    255255                 
     
    257257            parse_data->bump_word = 1; 
    258258            open_tag(parse_data, metaname, NULL); 
    259             chars_to_words(parse_data, metacontent, xmlStrlen(metacontent)); 
     259            buffer_characters(parse_data, metacontent, xmlStrlen(metacontent)); 
    260260            close_tag(parse_data, metaname); 
    261261            swish_xfree(swishtag); 
     
    314314    swish_TagStack *s = parse_data->metastack; 
    315315     
    316     if (SWISH_DEBUG > 10
     316    if (SWISH_DEBUG == SWISH_DEBUG_PARSER
    317317        swish_debug_msg("buffer is >>%s<< before flush, word_pos = %d",  
    318318            xmlBufferContent(parse_data->buf_ptr), parse_data->word_pos); 
     
    330330    swish_add_buf_to_nb( parse_data->metanames, 
    331331                         metaname, 
    332                          parse_data->buf_ptr, '\0', 0, 1); 
     332                         parse_data->buf_ptr, (xmlChar*)SWISH_META_CONNECTOR, 0, 1); 
    333333                          
    334334    if (parse_data->context_as_meta) 
     
    341341            swish_add_buf_to_nb(parse_data->metanames, 
    342342                                s->temp->name,  
    343                                 parse_data->buf_ptr, '\0', 0, 1); 
     343                                parse_data->buf_ptr, (xmlChar*)SWISH_META_CONNECTOR, 0, 1); 
    344344        } 
    345345    }                     
     
    513513/* handle all characters in doc */ 
    514514static void 
    515 chars_to_words(swish_ParseData * parse_data, const xmlChar * ch, int len) 
     515buffer_characters(swish_ParseData * parse_data, const xmlChar * ch, int len) 
    516516{ 
    517517    int             i; 
     
    539539 
    540540    if (parse_data->bump_word && xmlBufferLength(buf)) 
    541         swish_append_buffer(buf, (xmlChar *) " ", 1); 
     541        swish_append_buffer(buf, (xmlChar*)" ", 1); 
    542542 
    543543    swish_append_buffer(buf, output, len); 
     
    546546    { 
    547547        //swish_debug_msg("   appending ' ' to prop_buf"); 
    548         swish_append_buffer(parse_data->prop_buf, (xmlChar *) " ", 1); 
     548        swish_append_buffer(parse_data->prop_buf, (xmlChar*)" ", 1); 
    549549    } 
    550550     
     
    563563        swish_debug_msg(" >> mycharacters()"); 
    564564 
    565     chars_to_words(parse_data, ch, len); 
     565    buffer_characters(parse_data, ch, len); 
    566566} 
    567567 
     
    577577    return; 
    578578 
    579     chars_to_words(parse_data, ch, len); 
     579    buffer_characters(parse_data, ch, len); 
    580580} 
    581581 
     
    16591659                                            (xmlChar*)SWISH_DEFAULT_METANAME); 
    16601660 
    1661     if (SWISH_DEBUG > 2
     1661    if (SWISH_DEBUG == SWISH_DEBUG_PARSER
    16621662        swish_debug_msg("stack pushed for %s", parse_data->metastack->flat); 
    16631663 
    1664     chars_to_words(parse_data, buffer, size); 
     1664    buffer_characters(parse_data, buffer, size); 
    16651665    flush_buffer(parse_data, (xmlChar*)SWISH_DEFAULT_METANAME, (xmlChar*)SWISH_DEFAULT_METANAME); 
    16661666     
    16671667    if (out != NULL) 
    16681668    { 
    1669         if (SWISH_DEBUG > 3
     1669        if (SWISH_DEBUG == SWISH_DEBUG_PARSER
    16701670            swish_debug_msg("tmp text buffer being freed"); 
    16711671