Changeset 2042

Show
Ignore:
Timestamp:
03/02/08 22:52:11 (2 months ago)
Author:
karpet
Message:

more refactoring of config/header

Files:

Legend:

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

    r2041 r2042  
    2828                        property.c \ 
    2929                        metaname.c \ 
     30                        header.c \ 
    3031                        $(myheaders)  
    3132 
  • libswish3/trunk/src/libswish3/config.c

    r2041 r2042  
    8282swish_free_config(swish_Config * config) 
    8383{ 
    84     int size = xmlHashSize(config->conf); 
    85  
    8684    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    8785    { 
    8886        SWISH_DEBUG_MSG("freeing config"); 
    89         SWISH_DEBUG_MSG("num of keys in config hash: %d", size); 
    9087        SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config, (int) config); 
    9188    } 
    9289 
    93     xmlHashFree(config->conf,           (xmlHashDeallocator)free_string); 
     90    xmlHashFree(config->misc,           (xmlHashDeallocator)free_string); 
    9491    xmlHashFree(config->properties,     (xmlHashDeallocator)free_props); 
    9592    xmlHashFree(config->metanames,      (xmlHashDeallocator)free_metas); 
     
    113110 
    114111 
    115 /* init memory stuff, env vars, and verify locale is correct */ 
     112/* init config object */ 
    116113 
    117114swish_Config  * 
    118115swish_init_config() 
    119116{ 
    120  
    121     /* declare all our vars */ 
    122117    swish_Config  *config; 
    123     swish_ConfigFlags *flags; 
    124     xmlHashTablePtr c, metas, parsers, index, prop, alias; 
     118     
     119    /* the hashes will automatically grow as needed so we init with sane starting size */ 
     120    config              = swish_xmalloc(sizeof(swish_Config)); 
     121    config->flags       = swish_xmalloc(sizeof(swish_ConfigFlags)); 
     122    config->misc        = swish_new_hash(8); 
     123    config->metanames   = swish_new_hash(8); 
     124    config->properties  = swish_new_hash(8); 
     125    config->parsers     = swish_new_hash(8); 
     126    config->index       = swish_new_hash(8); 
     127    config->tag_aliases = swish_new_hash(8); 
     128    config->mimes       = NULL; 
     129    config->ref_cnt     = 0; 
     130    config->stash       = NULL; 
     131     
     132    return config; 
     133 
     134
     135 
     136void 
     137swish_config_set_default( swish_Config *config ) 
     138
    125139    swish_Property *tmpprop; 
    126140    swish_MetaName *tmpmeta; 
    127141 
    128142    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
    129         SWISH_DEBUG_MSG("creating default config"); 
    130  
    131     /* create our object */ 
    132  
    133     config = swish_xmalloc(sizeof(swish_Config)); 
    134     flags  = swish_xmalloc(sizeof(swish_ConfigFlags)); 
    135  
    136     /* init all config hashes */ 
    137  
    138     c = xmlHashCreate(16); 
    139  
    140     /* in order to consistently free our hashes, we strdup everything */ 
    141  
    142     /* default metanames */ 
    143     metas = xmlHashCreate(8); 
    144     swish_hash_add( 
    145             metas,  
     143        SWISH_DEBUG_MSG("setting default config"); 
     144         
     145    /* we xstrdup a lot in order to consistently free in swish_free_config() */ 
     146 
     147    /* MIME types */ 
     148    config->mimes = swish_mime_hash(); 
     149 
     150    /* metanames */ 
     151    swish_hash_add( 
     152            config->metanames,  
    146153            (xmlChar*)SWISH_DEFAULT_METANAME, 
    147154            swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) )  
    148155            ); 
    149156    swish_hash_add( 
    150             metas, 
     157            config->metanames, 
    151158            (xmlChar*)SWISH_TITLE_METANAME, 
    152159            swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME) ) 
     
    154161             
    155162    /* increm ref counts after they've been stashed. a little awkward, but saves var names... */ 
    156     tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_DEFAULT_METANAME); 
     163    tmpmeta = xmlHashLookup(config->metanames, (xmlChar*)SWISH_DEFAULT_METANAME); 
    157164    tmpmeta->ref_cnt++; 
    158     tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_TITLE_METANAME); 
     165    tmpmeta = xmlHashLookup(config->metanames, (xmlChar*)SWISH_TITLE_METANAME); 
    159166    tmpmeta->ref_cnt++; 
    160167     
    161     config->metanames = metas; 
    162  
    163  
    164     /* default MIME types */ 
    165     config->mimes = swish_mime_hash(); 
    166  
    167  
    168     /* default parser types - others added via config files */ 
    169     parsers = xmlHashCreate(5); 
    170     swish_hash_add(parsers, 
     168 
     169    /* parsers */ 
     170    swish_hash_add( 
     171            config->parsers, 
    171172            (xmlChar *) "text/plain", 
    172173            swish_xstrdup((xmlChar *) SWISH_PARSER_TXT)); 
    173     swish_hash_add(parsers, 
     174    swish_hash_add( 
     175            config->parsers, 
    174176            (xmlChar *) "text/xml", 
    175177            swish_xstrdup((xmlChar *) SWISH_PARSER_XML)); 
    176     swish_hash_add(parsers, 
     178    swish_hash_add( 
     179            config->parsers, 
    177180            (xmlChar *) "text/html", 
    178181            swish_xstrdup((xmlChar *) SWISH_PARSER_HTML)); 
    179     swish_hash_add(parsers, 
     182    swish_hash_add( 
     183            config->parsers, 
    180184            (xmlChar *) SWISH_DEFAULT_PARSER, 
    181185            swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 
    182186 
    183     config->parsers = parsers; 
    184  
    185  
    186     /* index attributes -- while testing, define all available */ 
    187     index = xmlHashCreate(4); 
    188  
    189     swish_hash_add(index, 
     187 
     188    /* index */ 
     189    swish_hash_add( 
     190            config->index, 
    190191            (xmlChar *) SWISH_INDEX_FORMAT, 
    191192            swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT)); 
    192     swish_hash_add(index, 
     193    swish_hash_add( 
     194            config->index, 
    193195            (xmlChar *) SWISH_INDEX_NAME, 
    194196            swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME)); 
    195     swish_hash_add(index, 
     197    swish_hash_add( 
     198            config->index, 
    196199            (xmlChar *) SWISH_INDEX_LOCALE, 
    197             swish_xstrdup((xmlChar *) setlocale(LC_ALL, NULL))); 
    198  
    199     config->index = index; 
    200  
    201     /* properties hash: each property is "propertyname" => type these match tag 
    202      * (meta) names and are aggregated for each doc, in propHash */ 
    203     prop = xmlHashCreate(8); 
    204     swish_hash_add( 
    205             prop, 
     200            swish_xstrdup((xmlChar *) setlocale(LC_ALL, ""))); 
     201 
     202 
     203    /* properties */ 
     204    swish_hash_add( 
     205            config->properties, 
    206206            (xmlChar*)SWISH_PROP_DESCRIPTION, 
    207207            swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION)) 
    208208            ); 
    209209    swish_hash_add( 
    210             prop
     210            config->properties
    211211            (xmlChar*)SWISH_PROP_TITLE, 
    212212            swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE)) 
     
    214214 
    215215    /* same deal as metanames above */ 
    216     tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_DESCRIPTION); 
     216    tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_DESCRIPTION); 
    217217    tmpprop->ref_cnt++; 
    218     tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_TITLE); 
     218    tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_TITLE); 
    219219    tmpprop->ref_cnt++; 
    220220     
    221     config->properties = prop; 
    222  
    223221 
    224222    /* aliases: other names a tag might be known as, for matching properties and 
    225223     * metanames */ 
    226     alias = xmlHashCreate(8); 
    227  
    228     swish_hash_add(alias, 
     224    swish_hash_add( 
     225            config->tag_aliases, 
    229226            (xmlChar *) SWISH_TITLE_TAG, 
    230227            swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)); 
    231     swish_hash_add(alias, 
     228    swish_hash_add( 
     229            config->tag_aliases, 
    232230            (xmlChar *) SWISH_BODY_TAG, 
    233231            swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 
    234232 
    235     config->tag_aliases = alias; 
    236  
    237233    /* misc default flags */ 
    238     flags->tokenize = 1; 
    239      
    240     config->conf = c; 
    241     config->ref_cnt = 0; 
    242     config->stash = NULL; 
    243     config->flags = flags; 
    244  
    245  
    246     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     234    config->flags->tokenize = 1; 
     235     
     236    if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     237        SWISH_DEBUG_MSG("config_set_default done"); 
    247238        swish_debug_config(config); 
    248  
    249     return config; 
     239    } 
     240 
    250241} 
    251242 
     
    367358 
    368359            /* append value/args to any existing names in config */ 
    369             if (xmlHashLookup(config->conf, opt_name)) 
     360            if (xmlHashLookup(config->misc, opt_name)) 
    370361            { 
    371362                /* err(202,"Bad 'name' tag contents in config: already 
    372363                 * seen '%s'\n", opt_name); */ 
    373                 vhash = xmlHashLookup(config->conf, opt_name); 
     364                vhash = xmlHashLookup(config->misc, opt_name); 
    374365                if (vhash == NULL) 
    375366                { 
     
    389380                name_seen = 0; 
    390381 
    391                 vhash = xmlHashCreate(16);    /* values => args */ 
     382                vhash = swish_new_hash(16);    /* values => args */ 
    392383                if (vhash == NULL) 
    393384                    SWISH_CROAK("error creating vhash"); 
     
    432423                    || 
    433424                    xmlStrEqual(opt_name, (xmlChar *) SWISH_PROP) 
    434                     || 
    435                     xmlStrEqual(opt_name, (xmlChar *) SWISH_PROP_MAX) 
    436                     || 
    437                     xmlStrEqual(opt_name, (xmlChar *) SWISH_PROP_SORT) 
     425 
    438426                    ) 
    439427                { 
     
    476464                    SWISH_DEBUG_MSG(" >>> adding %s to config hash ( name_seen = %d )", opt_name, name_seen); 
    477465 
    478                 swish_hash_add(config->conf, opt_name, vhash); 
     466                swish_hash_add(config->misc, opt_name, vhash); 
    479467            } 
    480468 
     
    514502 
    515503/* PUBLIC */ 
    516 int 
     504void 
    517505swish_debug_config(swish_Config * config) 
    518506{ 
    519     int size = xmlHashSize(config->conf); 
    520  
    521507    SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); 
    522508    SWISH_DEBUG_MSG("config->stash address = 0x%x  %d", (int) config->stash, (int) config->stash); 
    523     SWISH_DEBUG_MSG("num of keys in config hash: %d", size); 
    524     SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config->conf, (int) config->conf); 
    525  
    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  
     509    SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config, (int) config); 
     510 
     511    xmlHashScan(config->misc,       (xmlHashScanner)config_printer,     "misc conf"); 
     512    xmlHashScan(config->properties, (xmlHashScanner)property_printer,   "properties"); 
     513    xmlHashScan(config->metanames,  (xmlHashScanner)metaname_printer,   "metanames"); 
     514    xmlHashScan(config->parsers,    (xmlHashScanner)config_printer,     "parsers"); 
     515    xmlHashScan(config->mimes,      (xmlHashScanner)config_printer,     "mimes"); 
     516    xmlHashScan(config->index,      (xmlHashScanner)config_printer,     "index"); 
     517    xmlHashScan(config->tag_aliases,(xmlHashScanner)config_printer,     "tag_aliases"); 
     518
     519 
     520static void 
     521copy_property( xmlHashTablePtr props1, swish_Property *prop2, xmlChar *prop2name ) 
     522
     523    swish_Property *prop1; 
     524    boolean in_hash; 
     525    if (swish_hash_exists(props1, prop2name)) { 
     526        prop1 = swish_hash_fetch(props1, prop2name); 
     527        in_hash = 1; 
     528    } 
     529    else { 
     530        prop1 = swish_init_property(swish_xstrdup(prop2name)); 
     531        in_hash = 0; 
     532    } 
     533     
     534    prop1->id            = prop2->id; 
     535    if (prop1->name != NULL) { 
     536        swish_xfree( prop1->name ); 
     537    } 
     538    prop1->name          = swish_xstrdup( prop2->name ); 
     539    prop1->ignore_case   = prop2->ignore_case; 
     540    prop1->type          = prop2->type; 
     541    prop1->verbatim      = prop2->verbatim; 
     542    if (prop1->alias_for != NULL) { 
     543        swish_xfree( prop2->alias_for ); 
     544    } 
     545    prop1->alias_for     = swish_xstrdup( prop2->alias_for ); 
     546    prop1->max           = prop2->max; 
     547    prop1->sort          = prop2->sort; 
     548     
     549    if (!in_hash) { 
     550        swish_hash_add(props1, prop1->name, prop1); 
     551    } 
     552
     553 
     554static void 
     555merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2) 
     556
     557    xmlHashScan(props2, (xmlHashScanner)copy_property, props1); 
     558
     559 
     560static void 
     561copy_metaname( xmlHashTablePtr metas1, swish_MetaName *meta2, xmlChar *meta2name ) 
     562
     563    swish_MetaName *meta1; 
     564    boolean in_hash; 
     565    if (swish_hash_exists(metas1, meta2name)) { 
     566        meta1 = swish_hash_fetch(metas1, meta2name); 
     567        in_hash = 1; 
     568    } 
     569    else { 
     570        meta1 = swish_init_metaname(swish_xstrdup(meta2name)); 
     571        in_hash = 0; 
     572    } 
     573 
     574    meta1->id           = meta2->id; 
     575    if (meta1->name != NULL) { 
     576        swish_xfree(meta1->name); 
     577    } 
     578    meta1->name         = swish_xstrdup( meta2->name ); 
     579    meta1->bias         = meta2->bias; 
     580    if (meta1->alias_for != NULL) { 
     581        swish_xfree(meta1->alias_for); 
     582    } 
     583    meta1->alias_for    = swish_xstrdup( meta2->alias_for ); 
     584     
     585    if (!in_hash) { 
     586        swish_hash_add(metas1, meta1->name, meta1); 
     587    } 
     588
     589 
     590static void 
     591merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2) 
     592
     593    xmlHashScan(metas2, (xmlHashScanner)copy_metaname, metas1); 
     594
     595 
     596void 
     597swish_config_merge(swish_Config *config1, swish_Config *config2) 
     598
     599    /* values in config2 override and are set in config1 */ 
     600    merge_properties(config1->properties,   config2->properties); 
     601    merge_metanames(config1->metanames,     config2->metanames); 
     602    swish_hash_merge(config1->parsers,      config2->parsers); 
     603    swish_hash_merge(config1->mimes,        config2->mimes); 
     604    swish_hash_merge(config1->index,        config2->index); 
     605    swish_hash_merge(config1->tag_aliases,  config2->tag_aliases); 
     606    swish_hash_merge(config1->misc,         config2->misc); 
     607 
     608    /* set flags */ 
     609    config1->flags->tokenize = config2->flags->tokenize; 
     610     
     611
     612 
  • libswish3/trunk/src/libswish3/hash.c

    r2041 r2042  
    4747} 
    4848 
    49 /* PUBLIC */ 
    50 int swish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value ) 
     49int  
     50swish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value ) 
    5151{ 
    5252    int ret; 
     
    5858} 
    5959 
    60 /* PUBLIC */ 
    61 int swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ) 
     60int  
     61swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ) 
    6262{ 
    6363    int ret; 
    64     ret = xmlHashRemoveEntry(hash, key, (xmlHashDeallocator)free_hashval ); 
     64    ret = xmlHashRemoveEntry(hash, key, (xmlHashDeallocator)free_hashval); 
    6565    if (ret == -1) 
    6666        SWISH_CROAK("xmlHashRemoveEntry for %s failed", key); 
     
    7575} 
    7676 
    77 xmlHashTablePtr swish_new_hash(int size) 
     77void * 
     78swish_hash_fetch( xmlHashTablePtr hash, xmlChar *key ) 
    7879{ 
    79     xmlHashTablePtr h = xmlHashCreate(size); 
    80     if (h == NULL) 
    81     { 
     80    return xmlHashLookup(hash, key); 
     81
     82 
     83xmlHashTablePtr  
     84swish_new_hash(int size) 
     85
     86    xmlHashTablePtr h; 
     87     
     88    h = xmlHashCreate(size); 
     89    if (h == NULL) { 
    8290        SWISH_CROAK("error creating hash of size %d", size); 
    8391        return NULL; 
     
    8694    return h; 
    8795} 
     96 
     97static void 
     98merge_hashes( xmlHashTablePtr hash1, xmlChar *value, xmlChar *key ) 
     99{ 
     100    if (swish_hash_exists(hash1, key)) { 
     101        swish_hash_replace(hash1, key, value); 
     102    } 
     103    else { 
     104        swish_hash_add(hash1, key, value); 
     105    } 
     106} 
     107 
     108void 
     109swish_hash_merge( xmlHashTablePtr hash1, xmlHashTablePtr hash2 ) 
     110{ 
     111    xmlHashScan(hash2, (xmlHashScanner)merge_hashes, hash1); 
     112} 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2041 r2042  
    5252#define SWISH_INCLUDE_FILE          "IncludeConfigFile" 
    5353#define SWISH_PROP                  "PropertyNames" 
    54 #define SWISH_PROP_ASIS             "nostripchars" 
    55 #define SWISH_PROP_MAX              "PropertyNamesMaxLength" 
    56 #define SWISH_PROP_SORT             "PropertyNamesSortKeyLength" 
    5754#define SWISH_META                  "MetaNames" 
    5855#define SWISH_MIME                  "MIME" 
     
    206203    int                          ref_cnt; 
    207204    void                        *stash;      /* for bindings */ 
    208     xmlHashTablePtr              conf;       /* misc settings */ 
     205    xmlHashTablePtr              misc; 
    209206    xmlHashTablePtr              properties; 
    210207    xmlHashTablePtr              metanames; 
     
    374371int         swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ); 
    375372boolean     swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ); 
     373void        swish_hash_merge( xmlHashTablePtr hash1, xmlHashTablePtr hash2 ); 
     374void *      swish_hash_fetch( xmlHashTablePtr hash, xmlChar *key ); 
    376375xmlHashTablePtr swish_new_hash(int size); 
    377376/* 
     
    443442*/ 
    444443swish_Config *  swish_init_config(); 
     444void            swish_config_set_default( swish_Config *config ); 
     445void            swish_config_merge(swish_Config *config1, swish_Config *config2); 
    445446swish_Config *  swish_add_config( xmlChar * conf, swish_Config * config ); 
    446447swish_Config *  swish_parse_config( xmlChar * conf, swish_Config * config ); 
    447 int             swish_debug_config( swish_Config * config ); 
     448void            swish_debug_config( swish_Config * config ); 
    448449void            swish_free_config(swish_Config * config); 
    449450xmlHashTablePtr swish_mime_hash(); 
     
    593594*/ 
    594595 
     596/* 
     597=head2 Header Functions 
     598*/ 
     599boolean         swish_validate_header(char *filename); 
     600boolean         swish_merge_config_with_header(char *filename, swish_Config *c); 
     601/* 
     602=cut 
     603*/ 
     604 
    595605 
    596606#ifdef __cplusplus 
  • libswish3/trunk/src/libswish3/swish.c

    r2028 r2042  
    3434    s3->config      = swish_init_config(); 
    3535    s3->config->ref_cnt++; 
     36    swish_config_set_default( s3->config ); 
    3637    s3->analyzer    = swish_init_analyzer(s3->config); 
    3738    s3->analyzer->ref_cnt++; 
  • libswish3/trunk/src/swish_header.c

    r2041 r2042  
    2020/* check a swish3 header file for correct syntax */ 
    2121 
    22 #include <libxml/xmlstring.h> 
    2322#include <sys/param.h> 
    2423#include <stdio.h> 
     
    2827#include <locale.h> 
    2928#include <err.h> 
    30 #include <libxml/hash.h> 
    31 #include <libxml/xmlreader.h> 
     29 
    3230#include "libswish3.h" 
    3331 
    34 extern int      SWISH_DEBUG; 
    35  
    36 typedef struct { 
    37     boolean         isprops; 
    38     boolean         ismetas; 
    39     const xmlChar   *parent_name; 
    40     swish_Config    *config; 
    41 } configmaker; 
    42  
    43 static void 
    44 do_property_aliases( 
    45     xmlChar *str, 
    46     configmaker *c, 
    47     swish_Property *prop 
    48 ) 
    49 { 
    50     swish_StringList * strlist; 
    51     int i; 
    52  
    53     strlist = swish_make_stringlist(str); 
    54  
    55     /* loop over each alias and create a Property for each, 
    56        setting alias_for to prop->name 
    57     */ 
    58     for (i=0; i < strlist->n; i++) { 
    59          
    60         if (! swish_hash_exists( c->config->properties, strlist->word[i]) ) { 
    61             swish_Property *newprop = swish_init_property( swish_str_tolower(strlist->word[i]) ); 
    62             newprop->ref_cnt++; 
    63             newprop->alias_for = swish_xstrdup( prop->name ); 
    64             swish_hash_add( c->config->properties, newprop->name, newprop ); 
    65             swish_debug_property(newprop); 
    66         }  
    67         else { 
    68             SWISH_CROAK("Cannot alias Property %s to %s because %s is already a real Property", 
    69                 strlist->word[i], prop->name, strlist->word[i]); 
    70         } 
    71     
    72  
    73     } 
    74      
    75     swish_free_stringlist(strlist); 
    76  
    77 } 
    78  
    79  
    80 static void 
    81 do_property_attr( 
    82     const xmlChar *attr,  
    83     const xmlChar *attr_val,  
    84     swish_Property *prop, 
    85     configmaker *c 
    86 ) 
    87 { 
    88  
    89     if (xmlStrEqual(attr, (xmlChar*)"ignore_case")) { 
    90         prop->ignore_case = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
    91     } 
    92     else if (xmlStrEqual(attr, (xmlChar*)"max")) { 
    93         prop->max = (int)strtol((char*)attr_val, (char**)NULL, 10); 
    94     } 
    95     else if (xmlStrEqual(attr, (xmlChar*)"verbatim")) { 
    96         prop->verbatim = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
    97     } 
    98     else if (xmlStrEqual(attr, (xmlChar*)"sort")) { 
    99         prop->sort = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
    100     } 
    101     else if (xmlStrEqual(attr, (xmlChar*)"type")) { 
    102         if (xmlStrEqual(attr_val, (xmlChar*)"int")) { 
    103             prop->type = SWISH_PROP_INT; 
    104         } 
    105         else if (xmlStrEqual(attr_val, (xmlChar*)"date")) { 
    106             prop->type = SWISH_PROP_DATE; 
    107         } 
    108         else { 
    109             prop->type = SWISH_PROP_STRING; 
    110         } 
    111     } 
    112     else if (xmlStrEqual(attr, (xmlChar*)"alias")) { 
    113         do_property_aliases( (xmlChar*)attr_val, c, prop ); 
    114     } 
    115  
    116 } 
    117  
    118 static void 
    119 do_property(xmlTextReaderPtr reader, configmaker *c)  
    120 { 
    121     xmlChar *value; 
    122     swish_Property *prop; 
    123      
    124     prop  = swish_init_property( swish_str_tolower( (xmlChar*)xmlTextReaderConstName(reader) ) ); 
    125     prop->ref_cnt++; 
    126     value = NULL; 
    127          
    128     if (    xmlTextReaderHasValue(reader)  
    129         &&  xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT ) { 
    130         prop->name = swish_str_tolower( (xmlChar*)c->parent_name ); 
    131         do_property_aliases( xmlTextReaderValue(reader), c, prop ); 
    132         return; 
    133     } 
    134      
    135      
    136     if ( xmlTextReaderHasAttributes(reader) ) { 
    137      
    138         xmlTextReaderMoveToFirstAttribute(reader); 
    139         do_property_attr( 
    140                 xmlTextReaderConstName(reader), 
    141                 xmlTextReaderConstValue(reader), 
    142                 prop, 
    143                 c 
    144                 ); 
    145          
    146         while(xmlTextReaderMoveToNextAttribute(reader) == 1) { 
    147             do_property_attr( 
    148                 xmlTextReaderConstName(reader), 
    149                 xmlTextReaderConstValue(reader), 
    150                 prop, 
    151                 c 
    152                 ); 
    153         } 
    154      
    155     } 
    156          
    157     if (!swish_hash_exists( c->config->properties, prop->name )) { 
    158         swish_hash_add( c->config->properties, prop->name, prop ); 
    159     } else { 
    160         swish_debug_config( c->config ); 
    161         SWISH_CROAK("Property %s is already defined", prop->name); 
    162     } 
    163      
    164     swish_debug_property(prop); 
    165      
    166     if (value != NULL) { 
    167         xmlFree(value); 
    168     } 
    169      
    170     c->parent_name = xmlTextReaderConstName(reader); 
    171  
    172 } 
    173  
    174 static void 
    175 process_node(xmlTextReaderPtr reader, configmaker *c)  
    176 { 
    177     const xmlChar *name, *value; 
    178     xmlChar *attr, *attr_val; 
    179     int i, depth, type, is_empty, has_value, has_attr; 
    180  
    181     name = xmlTextReaderConstName(reader); 
    182     if (name == NULL) 
    183         name = BAD_CAST "--"; 
    184  
    185     value = xmlTextReaderConstValue(reader); 
    186      
    187     if (    swish_str_all_ws((xmlChar*)value)  
    188         &&  xmlStrEqual(name, (xmlChar*)"#text"))  
    189     { 
    190         return; 
    191     } 
    192  
    193     depth = xmlTextReaderDepth(reader); 
    194     type  = xmlTextReaderNodeType(reader); 
    195     is_empty    = xmlTextReaderIsEmptyElement(reader); 
    196     has_value   = xmlTextReaderHasValue(reader); 
    197     has_attr    = xmlTextReaderHasAttributes(reader); 
    198      
    199  
    200     for (i=0; i < depth; i++) { 
    201         printf(" "); 
    202     } 
    203     printf("> %s [type: %d  is_empty: %d  has_value: %d  has_attr: %d]", 
    204         name, type, is_empty, has_value, has_attr 
    205     ); 
    206      
    207     if (has_attr) { 
    208      
    209         printf("\n"); 
    210         xmlTextReaderMoveToFirstAttribute(reader); 
    211         attr = xmlTextReaderName(reader); 
    212         attr_val = xmlTextReaderValue(reader); 
    213         printf("  attr: %s = %s ", attr, attr_val); 
    214         while(xmlTextReaderMoveToNextAttribute(reader) == 1) { 
    215             attr = xmlTextReaderName(reader); 
    216             attr_val = xmlTextReaderValue(reader); 
    217             printf(" attr: %s = %s  ", attr, attr_val); 
    218         } 
    219          
    220     } 
    221      
    222     xmlTextReaderMoveToElement(reader); // move back to element for do_property() 
    223  
    224      
    225     if (value == NULL) 
    226             printf("\n"); 
    227     else { 
    228         if (xmlStrlen(value) > 40) 
    229             printf(" value: %.40s...\n", value); 
    230         else 
    231             printf(" value: %s\n", value); 
    232     } 
    233      
    234     if (type == XML_READER_TYPE_END_ELEMENT) { 
    235         if ( xmlStrEqual(name, (const xmlChar*)SWISH_PROP) ) { 
    236             c->isprops = 0; 
    237             return; 
    238         } 
    239         if ( xmlStrEqual(name, (const xmlChar*)SWISH_META) ) { 
    240             c->ismetas = 0; 
    241             return; 
    242         } 
    243     } 
    244     else { 
    245  
    246         if ( xmlStrEqual(name, (const xmlChar*)SWISH_PROP) ) { 
    247             c->isprops = 1; 
    248             return; 
    249         } 
    250         if ( xmlStrEqual(name, (const xmlChar*)SWISH_META) ) { 
    251             c->ismetas = 1; 
    252             return; 
    253         } 
    254          
    255     } 
    256      
    257     if (c->isprops && type != XML_READER_TYPE_END_ELEMENT) { 
    258         do_property(reader, c); 
    259     } 
    260      
    261      
    262      
    263 } 
    264  
    265  
    266 static void 
    267 read_header(const char *filename, configmaker *c)  
    268 { 
    269     xmlTextReaderPtr reader; 
    270     int ret; 
    271  
    272     reader = xmlReaderForFile(filename, NULL, 0); 
    273     if (reader != NULL) { 
    274         ret = xmlTextReaderRead(reader); 
    275         while (ret == 1) { 
    276             process_node(reader, c); 
    277             ret = xmlTextReaderRead(reader); 
    278         } 
    279         xmlFreeTextReader(reader); 
    280         if (ret != 0) { 
    281             SWISH_CROAK("%s : failed to parse\n", filename); 
    282         } 
    283     } else { 
    284         SWISH_CROAK("Unable to open %s\n", filename); 
    285     } 
    286 } 
    28732 
    28833int  
     
    29136#ifdef LIBXML_READER_ENABLED 
    29237    int i; 
    293     configmaker *c; 
    294      
    295     c = swish_xmalloc(sizeof(configmaker)); 
    296     c->config = swish_init_config(); 
    297     c->isprops = 0; 
    298     c->ismetas = 0; 
    29938 
    30039    /* 
    301      * this initialize the library and check potential ABI mismatches 
     40     * initialize the library and check potential API mismatches 
    30241     * between the version it was compiled for and the actual shared 
    30342     * library used. 
     
    30847 
    30948        printf("config file %s\n", argv[i]); 
    310         read_header( argv[i], c ); 
     49        if (swish_validate_header( (char*)argv[i] )) { 
     50            printf("%s ok\n", argv[i]); 
     51        } 
     52        else { 
     53            fprintf(stderr, "%s failed\n", argv[i]); 
     54        } 
    31155 
    31256    } 
    313      
    314     swish_debug_config( c->config ); 
    315     swish_free_config( c->config ); 
    316     swish_xfree( c ); 
    317      
     57         
    31858    /* 
    31959     * Cleanup function for the XML library.