Changeset 2042
- Timestamp:
- 03/02/08 22:52:11 (2 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/Makefile.am (modified) (1 diff)
- libswish3/trunk/src/libswish3/config.c (modified) (9 diffs)
- libswish3/trunk/src/libswish3/hash.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/header.c (added)
- libswish3/trunk/src/libswish3/libswish3.h (modified) (5 diffs)
- libswish3/trunk/src/libswish3/swish.c (modified) (1 diff)
- libswish3/trunk/src/swish_header.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/Makefile.am
r2041 r2042 28 28 property.c \ 29 29 metaname.c \ 30 header.c \ 30 31 $(myheaders) 31 32 libswish3/trunk/src/libswish3/config.c
r2041 r2042 82 82 swish_free_config(swish_Config * config) 83 83 { 84 int size = xmlHashSize(config->conf);85 86 84 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 87 85 { 88 86 SWISH_DEBUG_MSG("freeing config"); 89 SWISH_DEBUG_MSG("num of keys in config hash: %d", size);90 87 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config, (int) config); 91 88 } 92 89 93 xmlHashFree(config-> conf, (xmlHashDeallocator)free_string);90 xmlHashFree(config->misc, (xmlHashDeallocator)free_string); 94 91 xmlHashFree(config->properties, (xmlHashDeallocator)free_props); 95 92 xmlHashFree(config->metanames, (xmlHashDeallocator)free_metas); … … 113 110 114 111 115 /* init memory stuff, env vars, and verify locale is correct */112 /* init config object */ 116 113 117 114 swish_Config * 118 115 swish_init_config() 119 116 { 120 121 /* declare all our vars */122 117 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 136 void 137 swish_config_set_default( swish_Config *config ) 138 { 125 139 swish_Property *tmpprop; 126 140 swish_MetaName *tmpmeta; 127 141 128 142 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, 146 153 (xmlChar*)SWISH_DEFAULT_METANAME, 147 154 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) ) 148 155 ); 149 156 swish_hash_add( 150 metas,157 config->metanames, 151 158 (xmlChar*)SWISH_TITLE_METANAME, 152 159 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME) ) … … 154 161 155 162 /* 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); 157 164 tmpmeta->ref_cnt++; 158 tmpmeta = xmlHashLookup( metas, (xmlChar*)SWISH_TITLE_METANAME);165 tmpmeta = xmlHashLookup(config->metanames, (xmlChar*)SWISH_TITLE_METANAME); 159 166 tmpmeta->ref_cnt++; 160 167 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, 171 172 (xmlChar *) "text/plain", 172 173 swish_xstrdup((xmlChar *) SWISH_PARSER_TXT)); 173 swish_hash_add(parsers, 174 swish_hash_add( 175 config->parsers, 174 176 (xmlChar *) "text/xml", 175 177 swish_xstrdup((xmlChar *) SWISH_PARSER_XML)); 176 swish_hash_add(parsers, 178 swish_hash_add( 179 config->parsers, 177 180 (xmlChar *) "text/html", 178 181 swish_xstrdup((xmlChar *) SWISH_PARSER_HTML)); 179 swish_hash_add(parsers, 182 swish_hash_add( 183 config->parsers, 180 184 (xmlChar *) SWISH_DEFAULT_PARSER, 181 185 swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 182 186 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, 190 191 (xmlChar *) SWISH_INDEX_FORMAT, 191 192 swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT)); 192 swish_hash_add(index, 193 swish_hash_add( 194 config->index, 193 195 (xmlChar *) SWISH_INDEX_NAME, 194 196 swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME)); 195 swish_hash_add(index, 197 swish_hash_add( 198 config->index, 196 199 (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, 206 206 (xmlChar*)SWISH_PROP_DESCRIPTION, 207 207 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION)) 208 208 ); 209 209 swish_hash_add( 210 prop,210 config->properties, 211 211 (xmlChar*)SWISH_PROP_TITLE, 212 212 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE)) … … 214 214 215 215 /* same deal as metanames above */ 216 tmpprop = xmlHashLookup( prop, (xmlChar*)SWISH_PROP_DESCRIPTION);216 tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_DESCRIPTION); 217 217 tmpprop->ref_cnt++; 218 tmpprop = xmlHashLookup( prop, (xmlChar*)SWISH_PROP_TITLE);218 tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_TITLE); 219 219 tmpprop->ref_cnt++; 220 220 221 config->properties = prop;222 223 221 224 222 /* aliases: other names a tag might be known as, for matching properties and 225 223 * metanames */ 226 alias = xmlHashCreate(8); 227 228 swish_hash_add(alias, 224 swish_hash_add( 225 config->tag_aliases, 229 226 (xmlChar *) SWISH_TITLE_TAG, 230 227 swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)); 231 swish_hash_add(alias, 228 swish_hash_add( 229 config->tag_aliases, 232 230 (xmlChar *) SWISH_BODY_TAG, 233 231 swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 234 232 235 config->tag_aliases = alias;236 237 233 /* 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"); 247 238 swish_debug_config(config); 248 249 return config; 239 } 240 250 241 } 251 242 … … 367 358 368 359 /* append value/args to any existing names in config */ 369 if (xmlHashLookup(config-> conf, opt_name))360 if (xmlHashLookup(config->misc, opt_name)) 370 361 { 371 362 /* err(202,"Bad 'name' tag contents in config: already 372 363 * seen '%s'\n", opt_name); */ 373 vhash = xmlHashLookup(config-> conf, opt_name);364 vhash = xmlHashLookup(config->misc, opt_name); 374 365 if (vhash == NULL) 375 366 { … … 389 380 name_seen = 0; 390 381 391 vhash = xmlHashCreate(16); /* values => args */382 vhash = swish_new_hash(16); /* values => args */ 392 383 if (vhash == NULL) 393 384 SWISH_CROAK("error creating vhash"); … … 432 423 || 433 424 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 438 426 ) 439 427 { … … 476 464 SWISH_DEBUG_MSG(" >>> adding %s to config hash ( name_seen = %d )", opt_name, name_seen); 477 465 478 swish_hash_add(config-> conf, opt_name, vhash);466 swish_hash_add(config->misc, opt_name, vhash); 479 467 } 480 468 … … 514 502 515 503 /* PUBLIC */ 516 int 504 void 517 505 swish_debug_config(swish_Config * config) 518 506 { 519 int size = xmlHashSize(config->conf);520 521 507 SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); 522 508 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 520 static void 521 copy_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 554 static void 555 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2) 556 { 557 xmlHashScan(props2, (xmlHashScanner)copy_property, props1); 558 } 559 560 static void 561 copy_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 590 static void 591 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2) 592 { 593 xmlHashScan(metas2, (xmlHashScanner)copy_metaname, metas1); 594 } 595 596 void 597 swish_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 47 47 } 48 48 49 /* PUBLIC */ 50 intswish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value )49 int 50 swish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value ) 51 51 { 52 52 int ret; … … 58 58 } 59 59 60 /* PUBLIC */ 61 intswish_hash_delete( xmlHashTablePtr hash, xmlChar *key )60 int 61 swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ) 62 62 { 63 63 int ret; 64 ret = xmlHashRemoveEntry(hash, key, (xmlHashDeallocator)free_hashval );64 ret = xmlHashRemoveEntry(hash, key, (xmlHashDeallocator)free_hashval); 65 65 if (ret == -1) 66 66 SWISH_CROAK("xmlHashRemoveEntry for %s failed", key); … … 75 75 } 76 76 77 xmlHashTablePtr swish_new_hash(int size) 77 void * 78 swish_hash_fetch( xmlHashTablePtr hash, xmlChar *key ) 78 79 { 79 xmlHashTablePtr h = xmlHashCreate(size); 80 if (h == NULL) 81 { 80 return xmlHashLookup(hash, key); 81 } 82 83 xmlHashTablePtr 84 swish_new_hash(int size) 85 { 86 xmlHashTablePtr h; 87 88 h = xmlHashCreate(size); 89 if (h == NULL) { 82 90 SWISH_CROAK("error creating hash of size %d", size); 83 91 return NULL; … … 86 94 return h; 87 95 } 96 97 static void 98 merge_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 108 void 109 swish_hash_merge( xmlHashTablePtr hash1, xmlHashTablePtr hash2 ) 110 { 111 xmlHashScan(hash2, (xmlHashScanner)merge_hashes, hash1); 112 } libswish3/trunk/src/libswish3/libswish3.h
r2041 r2042 52 52 #define SWISH_INCLUDE_FILE "IncludeConfigFile" 53 53 #define SWISH_PROP "PropertyNames" 54 #define SWISH_PROP_ASIS "nostripchars"55 #define SWISH_PROP_MAX "PropertyNamesMaxLength"56 #define SWISH_PROP_SORT "PropertyNamesSortKeyLength"57 54 #define SWISH_META "MetaNames" 58 55 #define SWISH_MIME "MIME" … … 206 203 int ref_cnt; 207 204 void *stash; /* for bindings */ 208 xmlHashTablePtr conf; /* misc settings */205 xmlHashTablePtr misc; 209 206 xmlHashTablePtr properties; 210 207 xmlHashTablePtr metanames; … … 374 371 int swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ); 375 372 boolean swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ); 373 void swish_hash_merge( xmlHashTablePtr hash1, xmlHashTablePtr hash2 ); 374 void * swish_hash_fetch( xmlHashTablePtr hash, xmlChar *key ); 376 375 xmlHashTablePtr swish_new_hash(int size); 377 376 /* … … 443 442 */ 444 443 swish_Config * swish_init_config(); 444 void swish_config_set_default( swish_Config *config ); 445 void swish_config_merge(swish_Config *config1, swish_Config *config2); 445 446 swish_Config * swish_add_config( xmlChar * conf, swish_Config * config ); 446 447 swish_Config * swish_parse_config( xmlChar * conf, swish_Config * config ); 447 intswish_debug_config( swish_Config * config );448 void swish_debug_config( swish_Config * config ); 448 449 void swish_free_config(swish_Config * config); 449 450 xmlHashTablePtr swish_mime_hash(); … … 593 594 */ 594 595 596 /* 597 =head2 Header Functions 598 */ 599 boolean swish_validate_header(char *filename); 600 boolean swish_merge_config_with_header(char *filename, swish_Config *c); 601 /* 602 =cut 603 */ 604 595 605 596 606 #ifdef __cplusplus libswish3/trunk/src/libswish3/swish.c
r2028 r2042 34 34 s3->config = swish_init_config(); 35 35 s3->config->ref_cnt++; 36 swish_config_set_default( s3->config ); 36 37 s3->analyzer = swish_init_analyzer(s3->config); 37 38 s3->analyzer->ref_cnt++; libswish3/trunk/src/swish_header.c
r2041 r2042 20 20 /* check a swish3 header file for correct syntax */ 21 21 22 #include <libxml/xmlstring.h>23 22 #include <sys/param.h> 24 23 #include <stdio.h> … … 28 27 #include <locale.h> 29 28 #include <err.h> 30 #include <libxml/hash.h> 31 #include <libxml/xmlreader.h> 29 32 30 #include "libswish3.h" 33 31 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 void44 do_property_aliases(45 xmlChar *str,46 configmaker *c,47 swish_Property *prop48 )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->name57 */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 void81 do_property_attr(82 const xmlChar *attr,83 const xmlChar *attr_val,84 swish_Property *prop,85 configmaker *c86 )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 void119 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 c144 );145 146 while(xmlTextReaderMoveToNextAttribute(reader) == 1) {147 do_property_attr(148 xmlTextReaderConstName(reader),149 xmlTextReaderConstValue(reader),150 prop,151 c152 );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 void175 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_attr205 );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 else231 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 void267 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 }287 32 288 33 int … … 291 36 #ifdef LIBXML_READER_ENABLED 292 37 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;299 38 300 39 /* 301 * this initialize the library and check potential ABI mismatches40 * initialize the library and check potential API mismatches 302 41 * between the version it was compiled for and the actual shared 303 42 * library used. … … 308 47 309 48 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 } 311 55 312 56 } 313 314 swish_debug_config( c->config ); 315 swish_free_config( c->config ); 316 swish_xfree( c ); 317 57 318 58 /* 319 59 * Cleanup function for the XML library.
