Changeset 2041

Show
Ignore:
Timestamp:
02/29/08 23:18:18 (3 months ago)
Author:
karpet
Message:

major reconstruction of config object.
basically, let go of the naive idea that the config code could be a general
purpose XML config structure and instead customized it for libswish3.
still TODO is to update the perl bindings and move code from swish_header.c
into config.c, and to write/serialize header.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/Makefile.am

    r1955 r2041  
    99# -pg is for profiling -- don't use in production 
    1010 
    11 bin_PROGRAMS = swish_lint swish_words swish_isw utf8test 
     11bin_PROGRAMS = swish_lint swish_words swish_isw utf8test swish_header 
    1212check_PROGRAMS = swish_lint 
    1313swish_lint_SOURCES = swish_lint.c $(myheaders) 
    1414swish_words_SOURCES = swish_words.c $(myheaders) 
    15 swish_isw_SOURCES = swish_isw.c  
     15swish_isw_SOURCES = swish_isw.c 
     16swish_header_SOURCES = swish_header.c $(myheaders) 
    1617utf8test_SOURCES = utf8test.c $(myheaders) 
    1718 
  • libswish3/trunk/src/libswish3/Makefile.am

    r1930 r2041  
    2626                        swish.c \ 
    2727                        analyzer.c \ 
     28                        property.c \ 
     29                        metaname.c \ 
    2830                        $(myheaders)  
    2931 
  • libswish3/trunk/src/libswish3/analyzer.c

    r2028 r2041  
    3333    a = swish_xmalloc(sizeof(swish_Analyzer)); 
    3434     
    35     /* TODO get this from config */ 
     35    /* TODO get these all from config */ 
    3636    a->maxwordlen = SWISH_MAX_WORD_LEN; 
    3737    a->minwordlen = SWISH_MIN_WORD_LEN; 
    3838    a->lc         = 1; 
    3939    a->ref_cnt    = 0; 
     40    a->tokenize   = config->flags->tokenize; 
    4041         
    41     if (xmlStrEqual((xmlChar*)SWISH_DEFAULT_VALUE, 
    42                     xmlHashLookup( 
    43                         swish_subconfig_hash(config,(xmlChar*)SWISH_WORDS), 
    44                         (xmlChar*)SWISH_PARSE_WORDS 
    45                     ) 
    46                   ) 
    47        ) 
    48     { 
    49         a->tokenize = 1; 
    50     } 
    51     else 
    52     { 
    53         if (SWISH_DEBUG) 
    54             SWISH_DEBUG_MSG("skipping WordList"); 
    55              
    56         a->tokenize = 0; 
    57     } 
    58      
     42    if (!a->tokenize && SWISH_DEBUG) 
     43        SWISH_DEBUG_MSG("skipping WordList"); 
     44 
    5945    /* tokenizer set in the parse* function */ 
    6046    a->tokenizer = NULL; 
     
    6652    a->regex     = NULL; 
    6753     
    68     a->stash      = NULL; 
     54    a->stash     = NULL; 
    6955     
    7056    return a; 
  • libswish3/trunk/src/libswish3/config.c

    r2028 r2041  
    2424 */ 
    2525 
    26  
    27 /* #include <libxml/hash.h> */ 
    2826#include <libxml/xmlstring.h> 
    2927#include <sys/param.h> 
     
    4038 
    4139 
    42 static void     config_val_printer(xmlChar * val, xmlChar * str, xmlChar * key); 
    43 static void     config_printer(xmlHashTablePtr vhash, xmlChar * str, xmlChar * key); 
    44 static void     free_config1(void *payload, xmlChar * confName); 
    45 static void     free_config2(void *payload, xmlChar * key); 
     40static void     config_printer(xmlChar * val, xmlChar * str, xmlChar * key); 
     41 
    4642static xmlDocPtr parse_xml_config(xmlChar * conf); 
    47 static int      is_multi(xmlNode * node); 
    48 static int      is_equal(xmlNode * node); 
    49 static int      is_top_level(xmlNode * node); 
    50 static xmlChar *get_node_value(xmlNode * node); 
    51 static xmlChar *get_node_key(xmlNode * node); 
    52 static xmlChar *get_node_type(xmlNode * node); 
     43static xmlChar *get_node_name(xmlNode * node); 
    5344static xmlNode *get_dom_root(xmlDocPtr doc); 
    54 static int      node_has_key(xmlNode * node); 
    55 static int      node_has_value(xmlNode * node); 
    56 static int      node_has_type(xmlNode * node); 
    57 static int      node_has_attr(xmlNode * node, const xmlChar * att); 
    58 static void     add_multi_node_to_cv(xmlNode * node, swish_ConfigValue * cv); 
    59  
     45 
     46static void     free_string(xmlChar *payload, xmlChar *key); 
     47static void     free_props(swish_Property *prop, xmlChar *propname); 
     48static void     free_metas(swish_MetaName *meta, xmlChar *metaname); 
    6049 
    6150static void 
    62 free_config2(void *payload, xmlChar * key) 
     51free_string(xmlChar *payload, xmlChar * key) 
    6352{ 
    6453    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    65         SWISH_DEBUG_MSG("   freeing config %s => %s", key, (xmlChar *) payload); 
    66  
    67     swish_xfree((xmlChar *) payload); 
     54        SWISH_DEBUG_MSG("   freeing config %s => %s", key, payload); 
     55 
     56    swish_xfree(payload); 
    6857} 
    6958 
    7059static void 
    71 free_config1(void *payload, xmlChar * confName) 
    72 
    73     int             size = xmlHashSize((xmlHashTablePtr) payload); 
    74  
    75     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    76     { 
    77         SWISH_DEBUG_MSG(" freeing config %s =>", confName); 
    78         SWISH_DEBUG_MSG(" num of keys in config hash: %d", size); 
    79         SWISH_DEBUG_MSG(" ptr addr: 0x%x  %d", (int) payload, (int) payload); 
    80     } 
    81  
    82     xmlHashFree((xmlHashTablePtr) payload, (xmlHashDeallocator) free_config2); 
    83  
     60free_props(swish_Property *prop, xmlChar *propname) 
     61
     62    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     63        SWISH_DEBUG_MSG("   freeing config->prop %s", propname); 
     64        swish_debug_property((swish_Property*)prop); 
     65    } 
     66    prop->ref_cnt--; 
     67    swish_free_property(prop); 
     68
     69 
     70static void 
     71free_metas(swish_MetaName *meta, xmlChar *metaname) 
     72
     73    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     74        SWISH_DEBUG_MSG("   freeing config->meta %s", metaname); 
     75        swish_debug_metaname((swish_MetaName*)meta); 
     76    } 
     77    meta->ref_cnt--; 
     78    swish_free_metaname(meta); 
    8479} 
    8580 
     
    8782swish_free_config(swish_Config * config) 
    8883{ 
    89     int             size = xmlHashSize(config->conf); 
     84    int size = xmlHashSize(config->conf); 
    9085 
    9186    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     
    9691    } 
    9792 
    98     xmlHashFree(config->conf, (xmlHashDeallocator) free_config1); 
     93    xmlHashFree(config->conf,           (xmlHashDeallocator)free_string); 
     94    xmlHashFree(config->properties,     (xmlHashDeallocator)free_props); 
     95    xmlHashFree(config->metanames,      (xmlHashDeallocator)free_metas); 
     96    xmlHashFree(config->tag_aliases,    (xmlHashDeallocator)free_string); 
     97    xmlHashFree(config->parsers,        (xmlHashDeallocator)free_string); 
     98    xmlHashFree(config->mimes,          (xmlHashDeallocator)free_string); 
     99    xmlHashFree(config->index,          (xmlHashDeallocator)free_string); 
    99100    swish_xfree(config->flags); 
    100101 
     
    121122    swish_Config  *config; 
    122123    swish_ConfigFlags *flags; 
    123     xmlHashTablePtr c, metas, parsers, index, prop, alias, parsewords; 
     124    xmlHashTablePtr c, metas, parsers, index, prop, alias; 
     125    swish_Property *tmpprop; 
     126    swish_MetaName *tmpmeta; 
    124127 
    125128    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     
    139142    /* default metanames */ 
    140143    metas = xmlHashCreate(8); 
    141     swish_hash_add(metas, 
    142             (xmlChar *) SWISH_DEFAULT_METANAME, 
    143             swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 
    144     swish_hash_add(metas, 
    145             (xmlChar *) SWISH_TITLE_METANAME, 
    146             swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 
    147     swish_hash_add(c, (xmlChar *) SWISH_META, metas); 
     144    swish_hash_add( 
     145            metas,  
     146            (xmlChar*)SWISH_DEFAULT_METANAME, 
     147            swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) )  
     148            ); 
     149    swish_hash_add( 
     150            metas, 
     151            (xmlChar*)SWISH_TITLE_METANAME, 
     152            swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME) ) 
     153            ); 
     154             
     155    /* increm ref counts after they've been stashed. a little awkward, but saves var names... */ 
     156    tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_DEFAULT_METANAME); 
     157    tmpmeta->ref_cnt++; 
     158    tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_TITLE_METANAME); 
     159    tmpmeta->ref_cnt++; 
     160     
     161    config->metanames = metas; 
    148162 
    149163 
    150164    /* default MIME types */ 
    151     swish_hash_add(c, (xmlChar *) SWISH_MIME, swish_mime_hash()); 
     165    config->mimes = swish_mime_hash(); 
    152166 
    153167 
     
    167181            swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 
    168182 
    169     swish_hash_add(c, (xmlChar *) SWISH_PARSERS, parsers)
     183    config->parsers = parsers
    170184 
    171185 
     
    183197            swish_xstrdup((xmlChar *) setlocale(LC_ALL, NULL))); 
    184198 
    185     swish_hash_add(c, (xmlChar *) SWISH_INDEX, index)
     199    config->index = index
    186200 
    187201    /* properties hash: each property is "propertyname" => type these match tag 
    188202     * (meta) names and are aggregated for each doc, in propHash */ 
    189203    prop = xmlHashCreate(8); 
    190     swish_hash_add(prop, 
    191             (xmlChar *) SWISH_PROP_DESCRIPTION, 
    192             swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 
    193     swish_hash_add(prop, 
    194             (xmlChar *) SWISH_PROP_TITLE, 
    195             swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 
    196  
    197     swish_hash_add(c, (xmlChar *) SWISH_PROP, prop); 
     204    swish_hash_add( 
     205            prop, 
     206            (xmlChar*)SWISH_PROP_DESCRIPTION, 
     207            swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION)) 
     208            ); 
     209    swish_hash_add( 
     210            prop, 
     211            (xmlChar*)SWISH_PROP_TITLE, 
     212            swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE)) 
     213            ); 
     214 
     215    /* same deal as metanames above */ 
     216    tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_DESCRIPTION); 
     217    tmpprop->ref_cnt++; 
     218    tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_TITLE); 
     219    tmpprop->ref_cnt++; 
     220     
     221    config->properties = prop; 
    198222 
    199223 
     
    209233            swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 
    210234 
    211     swish_hash_add(c, (xmlChar *) SWISH_ALIAS, alias); 
    212  
    213     /* word parsing settings */ 
    214     parsewords = xmlHashCreate(4); 
    215     swish_hash_add(parsewords, 
    216             (xmlChar *) SWISH_PARSE_WORDS, 
    217             swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 
    218  
    219     swish_hash_add(c, (xmlChar *) SWISH_WORDS, parsewords); 
    220  
     235    config->tag_aliases = alias; 
     236 
     237    /* misc default flags */ 
     238    flags->tokenize = 1; 
     239     
    221240    config->conf = c; 
    222241    config->ref_cnt = 0; 
     
    244263    return config; 
    245264 
    246 } 
    247  
    248 swish_ConfigValue * 
    249 swish_init_ConfigValue() 
    250 { 
    251     swish_ConfigValue *cv; 
    252     cv = swish_xmalloc(sizeof(swish_ConfigValue)); 
    253     cv->ref_cnt = 1; 
    254     cv->multi = 0; 
    255     cv->equal = 0; 
    256     cv->key = NULL; 
    257     cv->value = NULL; 
    258     return cv; 
    259 } 
    260  
    261 void 
    262 swish_free_ConfigValue(swish_ConfigValue * cv) 
    263 { 
    264     if (cv->key != NULL) 
    265         swish_xfree(cv->key); 
    266  
    267     if (cv->value != NULL) 
    268         swish_xfree(cv->value); 
    269  
    270     swish_xfree(cv); 
    271 } 
    272  
    273 swish_ConfigValue * 
    274 swish_keys(swish_Config * config,...) 
    275 { 
    276     va_list         args; 
    277     swish_ConfigValue *cv = swish_init_ConfigValue(); 
    278  
    279     va_start(args, config); 
    280  
    281  
    282     va_end(args); 
    283     return cv; 
    284 } 
    285  
    286 swish_ConfigValue * 
    287 swish_value(swish_Config * config, xmlChar * key,...) 
    288 { 
    289     va_list         args; 
    290     swish_ConfigValue *cv = swish_init_ConfigValue(); 
    291  
    292     va_start(args, key); 
    293  
    294  
    295     va_end(args); 
    296     return cv; 
    297 } 
    298  
    299  
    300 /* a xml node is multi if: - it is a predefined top-level key (MetaNames, PropertyNames, 
    301  * etc.) - it has the multi attribute present (value is ignored) - has one or more spaces 
    302  * in the value */ 
    303 static int  
    304 is_multi(xmlNode * node) 
    305 { 
    306     xmlChar        *v; 
    307  
    308     if (xmlHasProp(node, (const xmlChar *) "multi") != NULL) 
    309         return 1; 
    310  
    311     if (is_top_level(node)) 
    312         return 1; 
    313  
    314     v = get_node_value(node); 
    315     if (v != NULL && (xmlStrchr(v, ' ') || xmlStrchr(v, '\n'))) 
    316     { 
    317         xmlFree(v); 
    318         return 1; 
    319     } 
    320  
    321     return 0; 
    322 } 
    323  
    324 static int  
    325 is_top_level(xmlNode * node) 
    326 { 
    327     if (xmlStrEqual(node->name, (xmlChar *) SWISH_META)) 
    328         return 1; 
    329  
    330     if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP)) 
    331         return 1; 
    332  
    333     if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP_MAX)) 
    334         return 1; 
    335  
    336     if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP_SORT)) 
    337         return 1; 
    338  
    339     return 0; 
    340 } 
    341  
    342  
    343 /* a xml node is equal if: - no attributes are present, just content - 'key' attr is 
    344  * present and xmlStrEqual() with content - 'key' and 'value' attrs are both present and 
    345  * xmlStrEqual() */ 
    346 static int  
    347 is_equal(xmlNode * node) 
    348 { 
    349     xmlChar        *v, *k; 
    350     int             e; 
    351  
    352     if (!node_has_key(node) && !node_has_value(node)) 
    353         return 1; 
    354  
    355     v = get_node_value(node); 
    356     k = xmlGetProp(node, (const xmlChar *) "key"); 
    357     e = xmlStrEqual(k, v); 
    358     xmlFree(v); 
    359     xmlFree(k); 
    360  
    361     if (e) 
    362         return 1; 
    363  
    364  
    365     if (node_has_value(node) && !node_has_key(node)) 
    366     { 
    367         SWISH_CROAK("config node with value but no key: %s", node->name); 
    368         return 0; 
    369     } 
    370  
    371     return 0; 
    372 } 
    373  
    374 static int  
    375 node_has_key(xmlNode * node) 
    376 { 
    377     return node_has_attr(node, (const xmlChar *) "key"); 
    378 } 
    379  
    380 static int  
    381 node_has_value(xmlNode * node) 
    382 { 
    383     return node_has_attr(node, (const xmlChar *) "value"); 
    384 } 
    385  
    386 static int  
    387 node_has_type(xmlNode * node) 
    388 { 
    389     return node_has_attr(node, (const xmlChar *) "type"); 
    390 } 
    391  
    392 static int  
    393 node_has_attr(xmlNode * node, const xmlChar * att) 
    394 { 
    395     if (xmlHasProp(node, att)) 
    396         return 1; 
    397     else 
    398         return 0; 
    399 } 
    400  
    401  
    402  
    403 /* key is attr value if present, otherwise get_node_value() */ 
    404 static xmlChar * 
    405 get_node_key(xmlNode * node) 
    406 { 
    407     xmlChar        *k; 
    408     k = xmlGetProp(node, (const xmlChar *) "key"); 
    409     return k;        /* MUST be freed */ 
    410 } 
    411  
    412 static xmlChar * 
    413 get_node_type(xmlNode * node) 
    414 { 
    415     xmlChar        *k; 
    416     k = xmlGetProp(node, (const xmlChar *) "type"); 
    417     return k;        /* MUST be freed */ 
    418 } 
    419  
    420 /* get node content and remove and leading or trailing spaces */ 
    421 static xmlChar * 
    422 get_node_value(xmlNode * node) 
    423 { 
    424     xmlChar        *str; 
    425     str = xmlNodeGetContent(node); 
    426     if (str == NULL) 
    427     { 
    428         str = xmlGetProp(node, (const xmlChar *) "value"); 
    429         if (str == NULL) 
    430         { 
    431             SWISH_WARN("no value for config opt '%s'", node->name); 
    432             return NULL; 
    433         } 
    434     } 
    435  
    436  
    437     /* TODO strip spaces */ 
    438  
    439     return str;        /* MUST be freed */ 
    440265} 
    441266 
     
    473298} 
    474299 
    475 static void  
    476 add_multi_node_to_cv(xmlNode * node, swish_ConfigValue * cv) 
    477 { 
    478     xmlChar        *key, *tmp, *type; 
    479     swish_StringList *value; 
    480     int             i; 
    481  
    482     /* if node has an explicit key, use that with entire value else split up value 
    483      * into tokens on whitespace. if node has a 'type' attr, use that as hash value, 
    484      * else use str as both key/value. */ 
    485  
    486     if (node_has_key(node)) 
    487     { 
    488         key = get_node_key(node); 
    489         tmp = get_node_value(node); 
    490         if (xmlHashLookup(cv->value, key)) 
    491             swish_hash_replace(cv->value, key, tmp); 
    492         else 
    493             swish_hash_add(cv->value, key, tmp); 
    494  
    495     } 
    496     else 
    497     { 
    498         tmp = get_node_value(node); 
    499         value = swish_make_StringList(tmp); 
    500         xmlFree(tmp); 
    501  
    502         if (node_has_type(node)) 
    503             type = get_node_type(node); 
    504  
    505  
    506         for (i = 0; i < value->n; i++) 
    507         { 
    508             key = swish_xstrdup(value->word[i]); 
    509             if (type == NULL) 
    510                 tmp = swish_xstrdup(key); 
    511             else 
    512                 tmp = type; 
    513  
    514             if (xmlHashLookup(cv->value, key)) 
    515                 swish_hash_replace(cv->value, key, tmp); 
    516             else 
    517                 swish_hash_add(cv->value, key, tmp); 
    518         } 
    519     } 
    520  
    521 } 
    522300 
    523301static xmlNode * 
     
    544322} 
    545323 
    546  
    547 /* this is too complicated right now. might be easier to just plunge in and define 
    548  * different config opt types (MetaNames, etc.) rather than try and remain agnostic and 
    549  * extensible about attribute names, etc. */ 
    550 swish_Config  * 
    551 swish_parse_config_new(xmlChar * conf, swish_Config * config) 
    552 { 
    553  
    554     xmlNode        *node, *root; 
    555     xmlDocPtr       doc; 
    556     swish_ConfigValue *cv; 
    557  
    558     doc = parse_xml_config(conf); 
    559     root = get_dom_root(doc); 
    560  
    561     /* -------------------------------------------------------------------------- get 
    562      * options/values format is: 
    563      *  
    564      * <directive type="someval">some arg</directive> 
    565      *  
    566      * where type="someval" attr is optional -- defaults to whatever 'some arg' is 
    567      * -------------------------------------------------------------------------- */ 
    568  
    569     for (node = root->children; node != NULL; node = node->next) 
    570     { 
    571         if (node->type == XML_ELEMENT_NODE) 
    572         { 
    573  
    574             /* is this opt already in our config? if yes, and multi, append 
    575              * it if yes, and !multi, replace it if no, create it */ 
    576  
    577             if (xmlHashLookup(config->conf, node->name)) 
    578             { 
    579                 cv = xmlHashLookup(config->conf, node->name); 
    580  
    581                 if (cv->multi)    /* already flagged as multi */ 
    582                 { 
    583                     SWISH_DEBUG_MSG("%s is an existing multi-config", node->name); 
    584  
    585                     add_multi_node_to_cv(node, cv); 
    586  
    587                 } 
    588                 else 
    589                 { 
    590                     SWISH_DEBUG_MSG("%s exists but is not a multi-config", node->name); 
    591  
    592                     /* free the existing one and replace it with new 
    593                      * one */ 
    594                     swish_free_ConfigValue(cv); 
    595  
    596                     cv = swish_init_ConfigValue(); 
    597                     cv->key = get_node_name(node); 
    598                     cv->value = get_node_value(node); 
    599  
    600                 } 
    601             } 
    602             else 
    603             { 
    604                 /* TODO - split all these if/else into separate functions */ 
    605                 cv = swish_init_ConfigValue(); 
    606  
    607                 if (is_multi(node)) 
    608                 { 
    609                     SWISH_DEBUG_MSG("%s is a new multi-config", node->name); 
    610                     cv->value = swish_new_hash(16); 
    611                     add_multi_node_to_cv(node, cv); 
    612  
    613                 } 
    614  
    615                 if (is_equal(node)) 
    616                 { 
    617                     SWISH_DEBUG_MSG("%s is an equal node", node->name); 
    618                     cv->equal = 1; 
    619                 } 
    620  
    621  
    622             } 
    623  
    624         } 
    625  
    626     } 
    627  
    628     xmlFreeDoc(doc); 
    629     xmlCleanupParser(); 
    630     return config; 
    631 } 
    632324 
    633325swish_Config  * 
     
    722414 
    723415 
    724             arg_list = swish_make_StringList(opt_arg); 
     416            arg_list = swish_make_stringlist(opt_arg); 
    725417 
    726418            for (i = 0; i < arg_list->n; i++) 
     
    750442                        SWISH_DEBUG_MSG("tolower str: >%s<", tmp_arg); 
    751443 
    752                     tmp_arg = swish_str_tolower(tmp_arg); 
     444                    tmp_arg = swish_str_tolower(tmp_arg); // TODO mem leak !! ?? 
    753445 
    754446                } 
     
    768460            } 
    769461 
    770             swish_free_StringList(arg_list); 
     462            swish_free_stringlist(arg_list); 
    771463 
    772464            /* don't use our swish_xfree since it throws off memcount */ 
     
    802494 
    803495static void 
    804 config_val_printer(xmlChar * val, xmlChar * str, xmlChar * key) 
    805 { 
    806     SWISH_DEBUG_MSG("   %s => %s", key, val); 
     496config_printer(xmlChar *val, xmlChar *str, xmlChar *key) 
     497{ 
     498    SWISH_DEBUG_MSG(" %s:  %s => %s", str, key, val); 
    807499} 
    808500 
    809501static void 
    810 config_printer(xmlHashTablePtr vhash, xmlChar * str, xmlChar * key) 
    811 
    812     SWISH_DEBUG_MSG(" Config %s:", key); 
    813  
    814     xmlHashScan(vhash, (xmlHashScanner) config_val_printer, "vhash"); 
    815  
    816     return; 
     502property_printer(swish_Property *prop, xmlChar *str, xmlChar *propname) 
     503
     504    SWISH_DEBUG_MSG(" %s:  %s =>", str, propname); 
     505    swish_debug_property(prop); 
     506
     507 
     508static void 
     509metaname_printer(swish_MetaName *meta, xmlChar *str, xmlChar *metaname) 
     510
     511    SWISH_DEBUG_MSG(" %s:  %s =>", str, metaname); 
     512    swish_debug_metaname(meta); 
    817513} 
    818514 
     
    821517swish_debug_config(swish_Config * config) 
    822518{ 
    823     int             size = xmlHashSize(config->conf); 
     519    int size = xmlHashSize(config->conf); 
    824520 
    825521    SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); 
     
    828524    SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config->conf, (int) config->conf); 
    829525 
    830     xmlHashScan(config->conf, (xmlHashScanner) config_printer, "opt name"); 
    831  
    832     return 1; 
    833  
    834 
    835  
    836 /* PUBLIC */ 
    837 xmlHashTablePtr 
    838 swish_subconfig_hash(swish_Config * config, xmlChar * key) 
    839 
    840     xmlHashTablePtr v = xmlHashLookup(config->conf, key); 
    841  
    842     if (v == NULL) 
    843     { 
    844         /* why does this happen when value is a hashptr ? */ 
    845         SWISH_DEBUG_MSG("Config option '%s' has NULL value", key); 
    846     } 
    847  
    848     return v; 
    849 
    850  
    851 /* PUBLIC */ 
    852 /* returns true/false if 'value' is a valid key in the subconfig hash for 'key' */ 
    853 /* example might be looking up a specific metaname in the MetaNames hash */ 
    854 int 
    855 swish_config_value_exists(swish_Config * config, xmlChar * key, xmlChar * value) 
    856 
    857     xmlHashTablePtr v = swish_subconfig_hash(config, key); 
    858     return ((int) xmlHashLookup(v, value)); 
    859 
    860  
    861 xmlChar        * 
    862 swish_get_config_value(swish_Config * config, xmlChar * key, xmlChar * value) 
    863 
    864     xmlHashTablePtr v = swish_subconfig_hash(config, key); 
    865     return (xmlChar *) xmlHashLookup(v, value); 
    866 
     526    xmlHashScan(config->conf,       (xmlHashScanner)config_printer, "misc conf"); 
     527    xmlHashScan(config->properties, (xmlHashScanner)property_printer, "properties"); 
     528    xmlHashScan(config->metanames,  (xmlHashScanner)metaname_printer, "metanames"); 
     529    xmlHashScan(config->parsers,    (xmlHashScanner)config_printer, "parsers"); 
     530    xmlHashScan(config->mimes,      (xmlHashScanner)config_printer, "mimes"); 
     531    xmlHashScan(config->index,      (xmlHashScanner)config_printer, "index"); 
     532 
     533    return size; 
     534 
     535
     536 
  • libswish3/trunk/src/libswish3/hash.c

    r1952 r2041  
    6969} 
    7070 
     71boolean 
     72swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ) 
     73{ 
     74    return xmlHashLookup(hash, key) ? 1 : 0; 
     75} 
     76 
    7177xmlHashTablePtr swish_new_hash(int size) 
    7278{ 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2030 r2041  
    7070#define SWISH_INDEX_LOCALE          "Locale" 
    7171#define SWISH_DEFAULT_VALUE         "1" 
    72 #define SWISH_PARSE_WORDS           "Tokenize" 
     72#define SWISH_TOKENIZE              "Tokenize" 
    7373 
    7474/* tags */ 
     
    146146#endif 
    147147 
     148typedef char   boolean; 
    148149typedef struct swish_3                  swish_3; 
    149150typedef struct swish_Token              swish_Token; 
     
    203204struct swish_Config 
    204205{ 
    205     int                          ref_cnt;    /* for bindings */ 
     206    int                          ref_cnt; 
    206207    void                        *stash;      /* for bindings */ 
    207     xmlHashTablePtr              conf;       /* the meat */ 
     208    xmlHashTablePtr              conf;       /* misc settings */ 
     209    xmlHashTablePtr              properties; 
     210    xmlHashTablePtr              metanames; 
     211    xmlHashTablePtr              tag_aliases; 
     212    xmlHashTablePtr              parsers; 
     213    xmlHashTablePtr              mimes; 
     214    xmlHashTablePtr              index; 
    208215    struct swish_ConfigFlags    *flags;      /* shortcuts for parsing */ 
    209216}; 
     
    211218struct swish_ConfigFlags 
    212219{ 
     220    boolean         tokenize; 
    213221     
    214      
    215 }; 
    216  
    217 struct swish_ConfigValue 
    218 
    219     int             ref_cnt; 
    220     unsigned int    multi;      /* indicates whether value is a string or hashref */ 
    221     unsigned int    equal;      /* indicates whether key/value pairs are equal */ 
    222     void            *value;     /* xmlHashTablePtr or xmlChar *str */ 
    223     xmlChar         *key;       /* should be same as the key that points at this object */ 
    224 }; 
    225  
     222}; 
    226223 
    227224struct swish_NamedBuffer 
     
    248245struct swish_MetaName 
    249246{ 
     247    int                 ref_cnt; 
    250248    unsigned int        id; 
    251249    xmlChar            *name; 
    252250    int                 bias; 
     251    xmlChar            *alias_for; 
    253252}; 
    254253 
    255254struct swish_Property 
    256255{ 
     256    int                 ref_cnt; 
    257257    unsigned int        id; 
    258258    xmlChar            *name; 
     259    boolean             ignore_case; 
     260    boolean             type; 
     261    boolean             verbatim; 
     262    xmlChar            *alias_for; 
     263    unsigned int        max; 
     264    boolean             sort; 
    259265}; 
    260266 
     
    316322}; 
    317323 
    318 // TODO maybe store swish_Parser * here instead of separate config and analyzer 
    319324struct swish_ParserData 
    320325{ 
     
    368373int         swish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value ); 
    369374int         swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ); 
     375boolean     swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ); 
    370376xmlHashTablePtr swish_new_hash(int size); 
    371377/* 
     
    421427xmlChar *           swish_str_skip_ws(xmlChar *s); 
    422428void                swish_str_trim_ws(xmlChar *string); 
     429int                 swish_str_all_ws(xmlChar * s); 
    423430void                swish_debug_wchars( const wchar_t * widechars ); 
    424431int                 swish_wchar_t_comp(const void *s1, const void *s2); 
    425432int                 swish_sort_wchar(wchar_t *s); 
    426 swish_StringList *  swish_make_StringList(xmlChar * line); 
    427 swish_StringList *  swish_init_StringList(); 
    428 void                swish_free_StringList(swish_StringList * sl); 
     433swish_StringList *  swish_make_stringlist(xmlChar * line); 
     434swish_StringList *  swish_init_stringlist(); 
     435void                swish_free_stringlist(swish_StringList * sl); 
    429436/* 
    430437=cut 
     
    438445swish_Config *  swish_add_config( xmlChar * conf, swish_Config * config ); 
    439446swish_Config *  swish_parse_config( xmlChar * conf, swish_Config * config ); 
    440 swish_Config *  swish_parse_config_new( xmlChar * conf, swish_Config * config ); 
    441447int             swish_debug_config( swish_Config * config ); 
    442 xmlHashTablePtr swish_subconfig_hash( swish_Config * config, xmlChar *key); 
    443 int             swish_config_value_exists( swish_Config * config, xmlChar *key, xmlChar *value ); 
    444 xmlChar *       swish_get_config_value(swish_Config * config, xmlChar * key, xmlChar * value); 
    445448void            swish_free_config(swish_Config * config); 
    446 swish_ConfigValue * swish_keys( swish_Config * config, ... ); 
    447 swish_ConfigValue * swish_value( swish_Config * config, xmlChar * key, ... ); 
    448 swish_ConfigValue * swish_init_ConfigValue(); 
    449 void                swish_free_ConfigValue( swish_ConfigValue * cv ); 
    450449xmlHashTablePtr swish_mime_hash(); 
    451450xmlChar *       swish_get_mime_type( swish_Config * config, xmlChar * fileext ); 
     
    553552=head2 Buffer Functions 
    554553*/ 
    555 swish_NamedBuffer * swish_init_nb( swish_Config * config, xmlChar * configKey ); 
     554swish_NamedBuffer * swish_init_nb( xmlHashTablePtr confhash ); 
    556555void                swish_free_nb( swish_NamedBuffer * nb ); 
    557556void                swish_debug_nb( swish_NamedBuffer * nb, xmlChar * label ); 
     
    574573*/ 
    575574 
     575/* 
     576=head2 Property Functions 
     577*/ 
     578swish_Property *    swish_init_property( xmlChar *name ); 
     579void                swish_free_property( swish_Property *prop ); 
     580void                swish_debug_property( swish_Property *prop ); 
     581/* 
     582=cut 
     583*/ 
     584 
     585/* 
     586=head2 MetaName Functions 
     587*/ 
     588swish_MetaName *    swish_init_metaname( xmlChar *name); 
     589void                swish_free_metaname( swish_MetaName *m ); 
     590void                swish_debug_metaname( swish_MetaName *m ); 
     591/* 
     592=cut 
     593*/ 
     594 
    576595 
    577596#ifdef __cplusplus 
  • libswish3/trunk/src/libswish3/mime_types.c

    r1952 r2041  
    220220{ 
    221221    xmlChar * mime; 
    222     xmlHashTablePtr mimes = swish_subconfig_hash( config, (xmlChar *)SWISH_MIME ); 
    223     mime = xmlHashLookup( mimes, fileext ); 
     222    mime = xmlHashLookup( config->mimes, fileext ); 
    224223    if ( mime == NULL ) 
    225224    { 
     
    236235    xmlChar *parser; 
    237236    xmlChar *deftype; 
    238     xmlHashTablePtr parsers; 
    239      
    240     parsers = swish_subconfig_hash( config, (xmlChar *)SWISH_PARSERS ); 
    241     parser = xmlHashLookup( parsers, mime ); 
     237     
     238    parser = xmlHashLookup( config->parsers, mime ); 
    242239     
    243240    if (SWISH_DEBUG > 9) 
    244241        SWISH_DEBUG_MSG("using parser '%s' based on MIME '%s'", parser, mime ); 
    245242     
    246     deftype = xmlHashLookup( parsers, (xmlChar *)SWISH_DEFAULT_PARSER ); /* error check?? */ 
     243    deftype = xmlHashLookup( config->parsers, (xmlChar *)SWISH_DEFAULT_PARSER ); /* error check?? */ 
    247244         
    248245    if ( parser == NULL ) 
  • libswish3/trunk/src/libswish3/namedbuffer.c

    r2028 r2041  
    3535 
    3636static void     free_name_from_hash(void *buffer, xmlChar * name); 
    37 static void     add_name_to_hash(xmlChar * val, xmlHashTablePtr hash, xmlChar * name); 
    38 static void     print_buffer(xmlBufferPtr buffer, xmlChar * label, xmlChar * name); 
     37static void     add_name_to_hash(void *ignored, xmlHashTablePtr nbhash, xmlChar *name); 
     38static void     print_buffer(xmlBufferPtr buffer, xmlChar *label, xmlChar *name); 
    3939 
    4040static void  
    41 add_name_to_hash(xmlChar * val, xmlHashTablePtr hash, xmlChar * name) 
     41add_name_to_hash(void *ignored, xmlHashTablePtr nbhash, xmlChar * name) 
    4242{     
    4343    /* make sure we don't already have it */ 
    44     if (xmlHashLookup(hash, name)) 
     44    if (swish_hash_exists(nbhash, name)) 
    4545    { 
    4646        SWISH_WARN("%s is already in NamedBuffer hash -- ignoring", name); 
     
    5252        SWISH_DEBUG_MSG("  adding %s to NamedBuffer\n", name); 
    5353     
    54     swish_hash_add(hash, name, xmlBufferCreateSize((size_t)SWISH_BUFFER_CHUNK_SIZE)); 
     54    swish_hash_add(nbhash, name, xmlBufferCreateSize((size_t)SWISH_BUFFER_CHUNK_SIZE)); 
    5555} 
    5656 
     
    6565 
    6666swish_NamedBuffer * 
    67 swish_init_nb(swish_Config * config, xmlChar * confKey
     67swish_init_nb( xmlHashTablePtr confhash
    6868{     
    6969    swish_NamedBuffer * nb = swish_xmalloc(sizeof(swish_NamedBuffer)); 
     
    7272    nb->hash    = xmlHashCreate(8);    /* will grow as needed */ 
    7373     
    74     xmlHashTablePtr confHash    = swish_subconfig_hash( config, confKey ); 
    75                            
    76     /* add each name to our hash */ 
    77     xmlHashScan(confHash, (xmlHashScanner)add_name_to_hash, nb->hash); 
     74    /* init a buffer for each key in confhash */ 
     75    xmlHashScan(confhash, (xmlHashScanner)add_name_to_hash, nb->hash); 
    7876 
    7977    return nb; 
  • libswish3/trunk/src/libswish3/parser.c

    r2030 r2041  
    293293 
    294294    /* change our internal name for this tag if it is aliased in config */ 
    295     alias = swish_get_config_value(parser_data->s3->config, (xmlChar*)SWISH_ALIAS, swishtag); 
     295    alias = xmlHashLookup(parser_data->s3->config->tag_aliases, swishtag); 
    296296    if (alias) 
    297297    { 
     
    447447 
    448448    /* set property if this tag is configured for it */ 
    449     if (swish_config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_PROP, parser_data->tag)) 
     449    if (swish_hash_exists(parser_data->s3->config->properties, parser_data->tag)) 
    450450    { 
    451451        if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
    452452            SWISH_DEBUG_MSG(" %s = new property", parser_data->tag); 
    453453 
    454         add_stack_to_prop_buf(NULL, parser_data); 
     454        add_stack_to_prop_buf(NULL, parser_data); //TODO why NULL here ?? 
    455455        xmlBufferEmpty(parser_data->prop_buf); 
    456456 
    457457        parser_data->propstack = push_tag_stack(parser_data->propstack, parser_data->tag); 
    458458 
    459         /* SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag);  */ 
     459        if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     460            SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag); 
    460461    } 
    461462 
    462463    /* likewise for metastack */ 
    463     if (swish_config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_META, parser_data->tag)) 
     464    if (swish_hash_exists(parser_data->s3->config->metanames, parser_data->tag)) 
    464465    { 
    465466        if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     
    750751    ptr->wordlist   = swish_init_wordlist(); 
    751752    ptr->wordlist->ref_cnt++; 
    752     ptr->properties = swish_init_nb(s3->config, (xmlChar*)SWISH_PROP); 
     753    ptr->properties = swish_init_nb(s3->config->properties); 
    753754    ptr->properties->ref_cnt++; 
    754     ptr->metanames  = swish_init_nb(s3->config, (xmlChar*)SWISH_META); 
     755    ptr->metanames  = swish_init_nb(s3->config->metanames); 
    755756    ptr->metanames->ref_cnt++; 
    756757 
     
    18