Changeset 2101
- Timestamp:
- 03/26/08 23:47:21 (2 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/analyzer.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/config.c (modified) (19 diffs)
- libswish3/trunk/src/libswish3/docinfo.c (modified) (9 diffs)
- libswish3/trunk/src/libswish3/error.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/getruntime.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/hash.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/header.c (modified) (36 diffs)
- libswish3/trunk/src/libswish3/io.c (modified) (11 diffs)
- libswish3/trunk/src/libswish3/mem.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/metaname.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/mime_types.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/namedbuffer.c (modified) (7 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (116 diffs)
- libswish3/trunk/src/libswish3/property.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/string.c (modified) (34 diffs)
- libswish3/trunk/src/libswish3/swish.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/times.c (modified) (7 diffs)
- libswish3/trunk/src/libswish3/words.c (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/analyzer.c
r2096 r2101 16 16 * along with libswish3; if not, write to the Free Software 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */19 18 */ 19 20 20 /* text analyzer 21 21 tokenize strings, stemming 22 22 23 23 */ 24 24 … … 28 28 29 29 swish_Analyzer * 30 swish_init_analyzer( swish_Config * config)30 swish_init_analyzer(swish_Config *config) 31 31 { 32 32 swish_Analyzer *a; 33 33 a = swish_xmalloc(sizeof(swish_Analyzer)); 34 35 /* TODO get these all from config */34 35 /* TODO get these all from config */ 36 36 a->maxwordlen = SWISH_MAX_WORD_LEN; 37 37 a->minwordlen = SWISH_MIN_WORD_LEN; 38 a->lc = 1;39 a->ref_cnt = 0;40 a->tokenize = config->flags->tokenize;41 38 a->lc = 1; 39 a->ref_cnt = 0; 40 a->tokenize = config->flags->tokenize; 41 42 42 if (!a->tokenize && SWISH_DEBUG) 43 43 SWISH_DEBUG_MSG("skipping WordList"); 44 44 45 /* tokenizer set in the parse* function */45 /* tokenizer set in the parse* function */ 46 46 a->tokenizer = NULL; 47 48 /* TODO get stemmer via config */49 a->stemmer = NULL;50 51 /* TODO standalone regex lib */52 a->regex = NULL;53 54 a->stash = NULL;55 47 48 /* TODO get stemmer via config */ 49 a->stemmer = NULL; 50 51 /* TODO standalone regex lib */ 52 a->regex = NULL; 53 54 a->stash = NULL; 55 56 56 return a; 57 57 } … … 61 61 do that prior to calling this function. 62 62 stemmer, for example, or regex 63 */64 65 void 66 swish_free_analyzer( swish_Analyzer * a)63 */ 64 65 void 66 swish_free_analyzer(swish_Analyzer *a) 67 67 { 68 68 if (a->ref_cnt != 0) { … … 72 72 SWISH_DEBUG_MSG("free analyzer"); 73 73 } 74 swish_xfree(a); 74 swish_xfree(a); 75 75 } 76 libswish3/trunk/src/libswish3/config.c
r2100 r2101 16 16 * along with libswish3; if not, write to the Free Software 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */18 */ 19 19 20 20 /* parse XML-style config files 21 * 21 * 22 22 * based on http://www.yolinux.com/TUTORIALS/GnomeLibXml2.html 23 * 24 */23 * 24 */ 25 25 26 26 #include <sys/param.h> … … 37 37 38 38 void 39 swish_free_config(swish_Config *config);40 swish_Config *41 swish_init_config();42 void 43 swish_config_set_default( swish_Config *config);44 swish_Config *45 swish_add_config(xmlChar *conf, swish_Config *config);46 swish_Config *47 swish_parse_config(xmlChar *conf, swish_Config *config);48 void 49 swish_debug_config(swish_Config *config);50 void 51 swish_config_merge(swish_Config *config1, swish_Config *config2);52 static void 53 free_string(xmlChar *payload, xmlChar *key);54 static void 55 free_props(swish_Property *prop, xmlChar *propname);56 static void 57 free_metas(swish_MetaName *meta, xmlChar *metaname);58 static void 59 config_printer(xmlChar *val, xmlChar *str, xmlChar *key);60 static void 61 property_printer(swish_Property *prop, xmlChar *str, xmlChar *propname);62 static void 63 metaname_printer(swish_MetaName *meta, xmlChar *str, xmlChar *metaname);39 swish_free_config(swish_Config *config); 40 swish_Config * 41 swish_init_config(); 42 void 43 swish_config_set_default(swish_Config *config); 44 swish_Config * 45 swish_add_config(xmlChar *conf, swish_Config *config); 46 swish_Config * 47 swish_parse_config(xmlChar *conf, swish_Config *config); 48 void 49 swish_debug_config(swish_Config *config); 50 void 51 swish_config_merge(swish_Config *config1, swish_Config *config2); 52 static void 53 free_string(xmlChar *payload, xmlChar *key); 54 static void 55 free_props(swish_Property * prop, xmlChar *propname); 56 static void 57 free_metas(swish_MetaName * meta, xmlChar *metaname); 58 static void 59 config_printer(xmlChar *val, xmlChar *str, xmlChar *key); 60 static void 61 property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname); 62 static void 63 metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname); 64 64 static void 65 65 copy_property( 66 swish_Property *prop2,67 xmlHashTablePtr props1,68 xmlChar *prop2name66 swish_Property * prop2, 67 xmlHashTablePtr props1, 68 xmlChar *prop2name 69 69 ); 70 70 static void 71 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2);71 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2); 72 72 static void 73 73 copy_metaname( 74 swish_MetaName *meta2,75 xmlHashTablePtr metas1,76 xmlChar *meta2name74 swish_MetaName * meta2, 75 xmlHashTablePtr metas1, 76 xmlChar *meta2name 77 77 ); 78 78 static void 79 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2);80 81 static void 82 free_string(xmlChar *payload, xmlChar * key)79 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2); 80 81 static void 82 free_string(xmlChar *payload, xmlChar *key) 83 83 { 84 84 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) … … 89 89 90 90 static void 91 free_props(swish_Property * prop, xmlChar *propname)91 free_props(swish_Property * prop, xmlChar *propname) 92 92 { 93 93 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 94 94 SWISH_DEBUG_MSG(" freeing config->prop %s", propname); 95 swish_debug_property((swish_Property *)prop);95 swish_debug_property((swish_Property *) prop); 96 96 } 97 97 prop->ref_cnt--; … … 102 102 103 103 static void 104 free_metas(swish_MetaName * meta, xmlChar *metaname)104 free_metas(swish_MetaName * meta, xmlChar *metaname) 105 105 { 106 106 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 107 107 SWISH_DEBUG_MSG(" freeing config->meta %s", metaname); 108 swish_debug_metaname((swish_MetaName *)meta);108 swish_debug_metaname((swish_MetaName *) meta); 109 109 } 110 110 meta->ref_cnt--; … … 115 115 116 116 void 117 swish_free_config(swish_Config * config) 118 { 119 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 120 { 117 swish_free_config(swish_Config *config) 118 { 119 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 121 120 SWISH_DEBUG_MSG("freeing config"); 122 121 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config, (int) config); 123 122 } 124 123 125 xmlHashFree(config->misc, (xmlHashDeallocator)free_string);126 xmlHashFree(config->properties, (xmlHashDeallocator)free_props);127 xmlHashFree(config->metanames, (xmlHashDeallocator)free_metas);128 xmlHashFree(config->tag_aliases, (xmlHashDeallocator)free_string);129 xmlHashFree(config->parsers, (xmlHashDeallocator)free_string);130 xmlHashFree(config->mimes, (xmlHashDeallocator)free_string);131 xmlHashFree(config->index, (xmlHashDeallocator)free_string);124 xmlHashFree(config->misc, (xmlHashDeallocator) free_string); 125 xmlHashFree(config->properties, (xmlHashDeallocator) free_props); 126 xmlHashFree(config->metanames, (xmlHashDeallocator) free_metas); 127 xmlHashFree(config->tag_aliases, (xmlHashDeallocator) free_string); 128 xmlHashFree(config->parsers, (xmlHashDeallocator) free_string); 129 xmlHashFree(config->mimes, (xmlHashDeallocator) free_string); 130 xmlHashFree(config->index, (xmlHashDeallocator) free_string); 132 131 swish_xfree(config->flags); 133 132 … … 147 146 /* init config object */ 148 147 149 swish_Config *148 swish_Config * 150 149 swish_init_config() 151 150 { 152 swish_Config *config;153 151 swish_Config *config; 152 154 153 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 155 154 SWISH_DEBUG_MSG("init config"); 156 155 } 157 158 /* the hashes will automatically grow as needed so we init with sane starting size */159 config = swish_xmalloc(sizeof(swish_Config));160 config->flags = swish_xmalloc(sizeof(swish_ConfigFlags));161 config->misc = swish_init_hash(8);162 config->metanames = swish_init_hash(8);163 config->properties = swish_init_hash(8);164 config->parsers = swish_init_hash(8);165 config->index = swish_init_hash(8);156 157 /* the hashes will automatically grow as needed so we init with sane starting size */ 158 config = swish_xmalloc(sizeof(swish_Config)); 159 config->flags = swish_xmalloc(sizeof(swish_ConfigFlags)); 160 config->misc = swish_init_hash(8); 161 config->metanames = swish_init_hash(8); 162 config->properties = swish_init_hash(8); 163 config->parsers = swish_init_hash(8); 164 config->index = swish_init_hash(8); 166 165 config->tag_aliases = swish_init_hash(8); 167 config->mimes = NULL;168 config->ref_cnt = 0;169 config->stash = NULL;170 171 /* misc default flags */166 config->mimes = NULL; 167 config->ref_cnt = 0; 168 config->stash = NULL; 169 170 /* misc default flags */ 172 171 config->flags->tokenize = 1; 173 172 174 173 return config; 175 174 … … 177 176 178 177 void 179 swish_config_set_default( swish_Config *config)178 swish_config_set_default(swish_Config *config) 180 179 { 181 180 swish_Property *tmpprop; … … 184 183 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 185 184 SWISH_DEBUG_MSG("setting default config"); 186 187 /* we xstrdup a lot in order to consistently free in swish_free_config() */188 189 /* MIME types */185 186 /* we xstrdup a lot in order to consistently free in swish_free_config() */ 187 188 /* MIME types */ 190 189 config->mimes = swish_mime_hash(); 191 190 192 /* metanames */193 swish_hash_add( 194 config->metanames,195 (xmlChar*)SWISH_DEFAULT_METANAME,196 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) )197 );198 swish_hash_add( 199 config->metanames,200 (xmlChar*)SWISH_TITLE_METANAME,201 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME))202 );203 204 /* alter swish_MetaName objects after they've been stashed. 205 a little awkward, but saves var names. 206 */207 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME);191 /* metanames */ 192 swish_hash_add( 193 config->metanames, 194 (xmlChar *) SWISH_DEFAULT_METANAME, 195 swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_DEFAULT_METANAME)) 196 ); 197 swish_hash_add( 198 config->metanames, 199 (xmlChar *) SWISH_TITLE_METANAME, 200 swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)) 201 ); 202 203 /* alter swish_MetaName objects after they've been stashed. 204 a little awkward, but saves var names. 205 */ 206 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_DEFAULT_METANAME); 208 207 tmpmeta->ref_cnt++; 209 208 tmpmeta->id = SWISH_META_DEFAULT_ID; 210 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *)SWISH_TITLE_METANAME);209 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_TITLE_METANAME); 211 210 tmpmeta->ref_cnt++; 212 211 tmpmeta->id = SWISH_META_TITLE_ID; 213 214 215 /* parsers */216 swish_hash_add( 217 config->parsers,218 (xmlChar *) "text/plain",219 swish_xstrdup((xmlChar *) SWISH_PARSER_TXT));220 swish_hash_add( 221 config->parsers,222 (xmlChar *) "text/xml",223 swish_xstrdup((xmlChar *) SWISH_PARSER_XML));224 swish_hash_add( 225 config->parsers,226 (xmlChar *) "text/html",227 swish_xstrdup((xmlChar *) SWISH_PARSER_HTML));228 swish_hash_add( 229 config->parsers,230 (xmlChar *) SWISH_DEFAULT_PARSER,231 swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE));232 233 234 /* index */235 swish_hash_add( 236 config->index,237 (xmlChar *) SWISH_INDEX_FORMAT,238 swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT));239 swish_hash_add( 240 config->index,241 (xmlChar *) SWISH_INDEX_NAME,242 swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME));243 swish_hash_add( 244 config->index,245 (xmlChar *) SWISH_INDEX_LOCALE,246 swish_xstrdup((xmlChar *) setlocale(LC_ALL, "")));247 248 249 /* properties */250 swish_hash_add( 251 config->properties,252 (xmlChar*)SWISH_PROP_DESCRIPTION,253 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION))254 );255 swish_hash_add( 256 config->properties,257 (xmlChar*)SWISH_PROP_TITLE,258 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE))259 );260 261 /* same deal as metanames above */262 tmpprop = swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION);212 213 214 /* parsers */ 215 swish_hash_add( 216 config->parsers, 217 (xmlChar *) "text/plain", 218 swish_xstrdup((xmlChar *) SWISH_PARSER_TXT)); 219 swish_hash_add( 220 config->parsers, 221 (xmlChar *) "text/xml", 222 swish_xstrdup((xmlChar *) SWISH_PARSER_XML)); 223 swish_hash_add( 224 config->parsers, 225 (xmlChar *) "text/html", 226 swish_xstrdup((xmlChar *) SWISH_PARSER_HTML)); 227 swish_hash_add( 228 config->parsers, 229 (xmlChar *) SWISH_DEFAULT_PARSER, 230 swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 231 232 233 /* index */ 234 swish_hash_add( 235 config->index, 236 (xmlChar *) SWISH_INDEX_FORMAT, 237 swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT)); 238 swish_hash_add( 239 config->index, 240 (xmlChar *) SWISH_INDEX_NAME, 241 swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME)); 242 swish_hash_add( 243 config->index, 244 (xmlChar *) SWISH_INDEX_LOCALE, 245 swish_xstrdup((xmlChar *) setlocale(LC_ALL, ""))); 246 247 248 /* properties */ 249 swish_hash_add( 250 config->properties, 251 (xmlChar *) SWISH_PROP_DESCRIPTION, 252 swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)) 253 ); 254 swish_hash_add( 255 config->properties, 256 (xmlChar *) SWISH_PROP_TITLE, 257 swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_TITLE)) 258 ); 259 260 /* same deal as metanames above */ 261 tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_DESCRIPTION); 263 262 tmpprop->ref_cnt++; 264 263 tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 265 tmpprop = swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_TITLE);264 tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_TITLE); 266 265 tmpprop->ref_cnt++; 267 266 tmpprop->id = SWISH_PROP_TITLE_ID; 268 269 270 /* aliases: other names a tag might be known as, for matching properties and267 268 269 /* aliases: other names a tag might be known as, for matching properties and 271 270 * metanames */ 272 271 swish_hash_add( 273 config->tag_aliases,274 (xmlChar *) SWISH_TITLE_TAG,275 swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME));276 swish_hash_add( 277 config->tag_aliases,278 (xmlChar *) SWISH_BODY_TAG,279 swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION));280 281 272 config->tag_aliases, 273 (xmlChar *) SWISH_TITLE_TAG, 274 swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)); 275 swish_hash_add( 276 config->tag_aliases, 277 (xmlChar *) SWISH_BODY_TAG, 278 swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 279 280 282 281 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 283 282 SWISH_DEBUG_MSG("config_set_default done"); … … 287 286 } 288 287 289 swish_Config *288 swish_Config * 290 289 swish_add_config(xmlChar *conf, swish_Config *config) 291 290 { … … 299 298 } 300 299 301 swish_Config *300 swish_Config * 302 301 swish_parse_config(xmlChar *conf, swish_Config *config) 303 302 { 304 swish_merge_config_with_header((char *)conf, config);303 swish_merge_config_with_header((char *) conf, config); 305 304 return config; 306 305 } … … 314 313 315 314 static void 316 property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname)315 property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname) 317 316 { 318 317 SWISH_DEBUG_MSG(" %s: %s =>", str, propname); … … 321 320 322 321 static void 323 metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname)322 metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname) 324 323 { 325 324 SWISH_DEBUG_MSG(" %s: %s =>", str, metaname); … … 329 328 /* PUBLIC */ 330 329 void 331 swish_debug_config(swish_Config * config)330 swish_debug_config(swish_Config *config) 332 331 { 333 332 SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); … … 335 334 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config, (int) config); 336 335 337 xmlHashScan(config->misc, (xmlHashScanner)config_printer,"misc conf");338 xmlHashScan(config->properties, (xmlHashScanner) property_printer,"properties");339 xmlHashScan(config->metanames, (xmlHashScanner)metaname_printer,"metanames");340 xmlHashScan(config->parsers, (xmlHashScanner)config_printer,"parsers");341 xmlHashScan(config->mimes, (xmlHashScanner)config_printer,"mimes");342 xmlHashScan(config->index, (xmlHashScanner)config_printer,"index");343 xmlHashScan(config->tag_aliases, (xmlHashScanner)config_printer,"tag_aliases");336 xmlHashScan(config->misc, (xmlHashScanner) config_printer, "misc conf"); 337 xmlHashScan(config->properties, (xmlHashScanner) property_printer, "properties"); 338 xmlHashScan(config->metanames, (xmlHashScanner) metaname_printer, "metanames"); 339 xmlHashScan(config->parsers, (xmlHashScanner) config_printer, "parsers"); 340 xmlHashScan(config->mimes, (xmlHashScanner) config_printer, "mimes"); 341 xmlHashScan(config->index, (xmlHashScanner) config_printer, "index"); 342 xmlHashScan(config->tag_aliases, (xmlHashScanner) config_printer, "tag_aliases"); 344 343 } 345 344 346 345 static void 347 346 copy_property( 348 swish_Property *prop2,349 xmlHashTablePtr props1,350 xmlChar *prop2name347 swish_Property * prop2, 348 xmlHashTablePtr props1, 349 xmlChar *prop2name 351 350 ) 352 351 { 353 352 swish_Property *prop1; 354 boolean in_hash;355 353 boolean in_hash; 354 356 355 if (swish_hash_exists(props1, prop2name)) { 357 356 prop1 = swish_hash_fetch(props1, prop2name); … … 363 362 in_hash = 0; 364 363 } 365 366 prop1->id = prop2->id;364 365 prop1->id = prop2->id; 367 366 if (in_hash && prop1->name != NULL) { 368 swish_xfree( prop1->name);369 prop1->name = swish_xstrdup( prop2->name);370 } 371 prop1->ignore_case = prop2->ignore_case;372 prop1->type = prop2->type;373 prop1->verbatim = prop2->verbatim;367 swish_xfree(prop1->name); 368 prop1->name = swish_xstrdup(prop2->name); 369 } 370 prop1->ignore_case = prop2->ignore_case; 371 prop1->type = prop2->type; 372 prop1->verbatim = prop2->verbatim; 374 373 if (prop1->alias_for != NULL) { 375 swish_xfree( prop2->alias_for);374 swish_xfree(prop2->alias_for); 376 375 } 377 376 if (prop2->alias_for != NULL) { 378 prop1->alias_for = swish_xstrdup( prop2->alias_for);379 } 380 prop1->max = prop2->max;381 prop1->sort = prop2->sort;382 377 prop1->alias_for = swish_xstrdup(prop2->alias_for); 378 } 379 prop1->max = prop2->max; 380 prop1->sort = prop2->sort; 381 383 382 if (!in_hash) { 384 383 swish_hash_add(props1, prop1->name, prop1); 385 384 } 386 385 387 386 } 388 387 … … 390 389 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2) 391 390 { 392 xmlHashScan(props2, (xmlHashScanner) copy_property, props1);391 xmlHashScan(props2, (xmlHashScanner) copy_property, props1); 393 392 } 394 393 395 394 static void 396 395 copy_metaname( 397 swish_MetaName *meta2,398 xmlHashTablePtr metas1,399 xmlChar *meta2name396 swish_MetaName * meta2, 397 xmlHashTablePtr metas1, 398 xmlChar *meta2name 400 399 ) 401 400 { 402 401 swish_MetaName *meta1; 403 boolean in_hash;402 boolean in_hash; 404 403 if (swish_hash_exists(metas1, meta2name)) { 405 404 meta1 = swish_hash_fetch(metas1, meta2name); … … 412 411 } 413 412 414 meta1->id = meta2->id;413 meta1->id = meta2->id; 415 414 if (in_hash && meta1->name != NULL) { 416 415 swish_xfree(meta1->name); 417 meta1->name = swish_xstrdup( meta2->name);418 } 419 meta1->bias = meta2->bias;416 meta1->name = swish_xstrdup(meta2->name); 417 } 418 meta1->bias = meta2->bias; 420 419 if (meta1->alias_for != NULL) { 421 420 swish_xfree(meta1->alias_for); 422 421 } 423 422 if (meta2->alias_for != NULL) { 424 meta1->alias_for = swish_xstrdup( meta2->alias_for);425 } 426 423 meta1->alias_for = swish_xstrdup(meta2->alias_for); 424 } 425 427 426 if (!in_hash) { 428 427 swish_hash_add(metas1, meta1->name, meta1); … … 433 432 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2) 434 433 { 435 xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1);434 xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1); 436 435 } 437 436 … … 440 439 { 441 440 442 /* values in config2 override and are set in config1 */441 /* values in config2 override and are set in config1 */ 443 442 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 444 443 SWISH_DEBUG_MSG("merge properties"); 445 444 } 446 merge_properties(config1->properties, config2->properties);447 445 merge_properties(config1->properties, config2->properties); 446 448 447 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 449 448 SWISH_DEBUG_MSG("merge metanames"); 450 449 } 451 merge_metanames(config1->metanames, config2->metanames);452 450 merge_metanames(config1->metanames, config2->metanames); 451 453 452 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 454 453 SWISH_DEBUG_MSG("merge parsers"); 455 454 } 456 swish_hash_merge(config1->parsers, config2->parsers);457 455 swish_hash_merge(config1->parsers, config2->parsers); 456 458 457 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 459 458 SWISH_DEBUG_MSG("merge mimes"); 460 459 } 461 swish_hash_merge(config1->mimes, config2->mimes);462 460 swish_hash_merge(config1->mimes, config2->mimes); 461 463 462 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 464 463 SWISH_DEBUG_MSG("merge index"); 465 464 } 466 swish_hash_merge(config1->index, config2->index);467 465 swish_hash_merge(config1->index, config2->index); 466 468 467 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 469 468 SWISH_DEBUG_MSG("merge tag_aliases"); 470 469 } 471 swish_hash_merge(config1->tag_aliases, config2->tag_aliases);472 470 swish_hash_merge(config1->tag_aliases, config2->tag_aliases); 471 473 472 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 474 473 SWISH_DEBUG_MSG("merge misc"); 475 474 } 476 swish_hash_merge(config1->misc, config2->misc);477 475 swish_hash_merge(config1->misc, config2->misc); 476 478 477 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 479 478 SWISH_DEBUG_MSG("merge complete"); 480 479 } 481 480 482 /* set flags */481 /* set flags */ 483 482 config1->flags->tokenize = config2->flags->tokenize; 484 483 485 484 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 486 485 SWISH_DEBUG_MSG("flags set"); 487 486 } 488 489 } 490 487 488 } libswish3/trunk/src/libswish3/docinfo.c
r2098 r2101 16 16 * along with libswish3; if not, write to the Free Software 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */18 */ 19 19 20 20 /* docinfo.c -- stat and time of files */ … … 28 28 #include <stdlib.h> 29 29 30 extern int errno;30 extern int errno; 31 31 32 32 #include "libswish3.h" 33 33 34 extern int SWISH_DEBUG;35 36 /* PUBLIC */ 37 swish_DocInfo *34 extern int SWISH_DEBUG; 35 36 /* PUBLIC */ 37 swish_DocInfo * 38 38 swish_init_docinfo() 39 39 { … … 41 41 if (SWISH_DEBUG > 9) 42 42 SWISH_DEBUG_MSG("init'ing docinfo"); 43 44 swish_DocInfo *docinfo = swish_xmalloc( sizeof(swish_DocInfo) ); 45 docinfo->ref_cnt = 0; 46 docinfo->nwords = 0; 47 docinfo->mtime = 0; 48 docinfo->size = 0; 49 docinfo->encoding = swish_xstrdup( (xmlChar*)SWISH_DEFAULT_ENCODING ); 50 docinfo->uri = NULL; 51 docinfo->mime = NULL; 52 docinfo->parser = NULL; 53 docinfo->ext = NULL; 54 docinfo->update = NULL; 55 56 if (SWISH_DEBUG > 9) 57 { 43 44 swish_DocInfo *docinfo = swish_xmalloc(sizeof(swish_DocInfo)); 45 docinfo->ref_cnt = 0; 46 docinfo->nwords = 0; 47 docinfo->mtime = 0; 48 docinfo->size = 0; 49 docinfo->encoding = swish_xstrdup((xmlChar *) SWISH_DEFAULT_ENCODING); 50 docinfo->uri = NULL; 51 docinfo->mime = NULL; 52 docinfo->parser = NULL; 53 docinfo->ext = NULL; 54 docinfo->update = NULL; 55 56 if (SWISH_DEBUG > 9) { 58 57 SWISH_DEBUG_MSG("docinfo all ready"); 59 swish_debug_docinfo( docinfo);58 swish_debug_docinfo(docinfo); 60 59 } 61 60 … … 65 64 /* PUBLIC */ 66 65 void 67 swish_free_docinfo( swish_DocInfo * ptr)68 { 66 swish_free_docinfo(swish_DocInfo *ptr) 67 { 69 68 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 70 69 SWISH_DEBUG_MSG("freeing swish_DocInfo"); 71 70 72 71 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 73 swish_debug_docinfo( ptr);72 swish_debug_docinfo(ptr); 74 73 75 74 … … 78 77 } 79 78 80 ptr->nwords = 0; /* why is this required? */81 ptr->mtime = 0;82 ptr->size = 0;83 84 /* encoding and mime are malloced via xmlstrdup elsewhere */79 ptr->nwords = 0; /* why is this required? */ 80 ptr->mtime = 0; 81 ptr->size = 0; 82 83 /* encoding and mime are malloced via xmlstrdup elsewhere */ 85 84 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 86 85 SWISH_DEBUG_MSG("freeing docinfo->encoding"); 87 86 swish_xfree(ptr->encoding); 88 87 89 88 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 90 89 SWISH_DEBUG_MSG("freeing docinfo->mime"); 91 90 if (ptr->mime != NULL) 92 91 swish_xfree(ptr->mime); 93 92 94 93 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 95 94 SWISH_DEBUG_MSG("freeing docinfo->uri"); 96 95 if (ptr->uri != NULL) 97 96 swish_xfree(ptr->uri); 98 97 99 98 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 100 99 SWISH_DEBUG_MSG("freeing docinfo->ext"); 101 100 if (ptr->ext != NULL) 102 101 swish_xfree(ptr->ext); 103 102 104 103 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 105 104 SWISH_DEBUG_MSG("freeing docinfo->parser"); 106 105 if (ptr->parser != NULL) 107 106 swish_xfree(ptr->parser); 108 107 109 108 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 110 109 SWISH_DEBUG_MSG("freeing docinfo ptr"); 111 110 swish_xfree(ptr); 112 111 113 112 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 114 113 SWISH_DEBUG_MSG("swish_DocInfo all freed"); … … 116 115 117 116 int 118 swish_check_docinfo(swish_DocInfo * docinfo, swish_Config *config)119 { 120 int ok;121 xmlChar *ext;122 117 swish_check_docinfo(swish_DocInfo *docinfo, swish_Config *config) 118 { 119 int ok; 120 xmlChar *ext; 121 123 122 ok = 1; 124 123 … … 131 130 if (docinfo->size == -1) 132 131 SWISH_CROAK("Failed to return required header Content-Length: for doc '%s'", 133 docinfo->uri);132 docinfo->uri); 134 133 135 134 /* might make this conditional on verbose level */ 136 if (docinfo->size == 0) 135 if (docinfo->size == 0) 137 136 SWISH_CROAK("Found zero Content-Length for doc '%s'", docinfo->uri); 138 137 139 138 ext = swish_get_file_ext(docinfo->uri); 140 /* this fails with non-filenames like db ids, etc. */ 141 142 if (docinfo->ext == NULL) 143 { 139 /* this fails with non-filenames like db ids, etc. */ 140 141 if (docinfo->ext == NULL) { 144 142 if (ext != NULL) 145 docinfo->ext = swish_xstrdup( ext);143 docinfo->ext = swish_xstrdup(ext); 146 144 else 147 docinfo->ext = swish_xstrdup((xmlChar *)"none");148 145 docinfo->ext = swish_xstrdup((xmlChar *) "none"); 146 149 147 } 150 148 … … 153 151 if (!docinfo->mime) { 154 152 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 155 SWISH_DEBUG_MSG( "no MIME known. guessing based on uri extension '%s'", docinfo->ext); 156 docinfo->mime = swish_get_mime_type( config, docinfo->ext ); 157 } 158 else 159 { 160 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 161 SWISH_DEBUG_MSG( "found MIME type in headers: '%s'", docinfo->mime); 162 163 } 164 153 SWISH_DEBUG_MSG("no MIME known. guessing based on uri extension '%s'", docinfo->ext); 154 docinfo->mime = swish_get_mime_type(config, docinfo->ext); 155 } 156 else { 157 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 158 SWISH_DEBUG_MSG("found MIME type in headers: '%s'", docinfo->mime); 159 160 } 161 165 162 if (!docinfo->parser) { 166 163 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 167 SWISH_DEBUG_MSG( "no parser defined in headers -- deducing from content type '%s'", docinfo->mime); 168 169 docinfo->parser = swish_get_parser( config, docinfo->mime ); 170 } 171 else 172 { 173 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 174 SWISH_DEBUG_MSG( "found parser in headers: '%s'", docinfo->parser); 175 176 } 177 164 SWISH_DEBUG_MSG("no parser defined in headers -- deducing from content type '%s'", docinfo->mime); 165 166 docinfo->parser = swish_get_parser(config, docinfo->mime); 167 } 168 else { 169 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 170 SWISH_DEBUG_MSG("found parser in headers: '%s'", docinfo->parser); 171 172 } 173 178 174 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 179 175 swish_debug_docinfo(docinfo); … … 185 181 /* PUBLIC */ 186 182 int 187 swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_ParserData *parser_data)188 { 189 struct statinfo;190 int stat_res;191 183 swish_docinfo_from_filesystem(xmlChar *filename, swish_DocInfo *i, swish_ParserData *parser_data) 184 { 185 struct stat info; 186 int stat_res; 187 192 188 if (i->ext != NULL) 193 swish_xfree( i->ext ); 194 195 i->ext = swish_get_file_ext( filename ); 196 197 stat_res = stat((char *)filename, &info); 198 199 if ( stat_res == -1) 200 { 189 swish_xfree(i->ext); 190 191 i->ext = swish_get_file_ext(filename); 192 193 stat_res = stat((char *) filename, &info); 194 195 if (stat_res == -1) { 201 196 SWISH_WARN("Can't stat '%s': %s", filename, strerror(errno)); 202 197 return 0; 203 198 } 204 199 205 200 if (SWISH_DEBUG > 9) 206 201 SWISH_DEBUG_MSG("handling url %s", filename); 207 208 if (i->uri != NULL)202 203 if (i->uri != NULL) 209 204 swish_xfree(i->uri); 210 211 i->uri = swish_xstrdup( filename );205 206 i->uri = swish_xstrdup(filename); 212 207 i->mtime = info.st_mtime; 213 i->size = info.st_size;214 208 i->size = info.st_size; 209 215 210 if (SWISH_DEBUG > 9) 216 211 SWISH_DEBUG_MSG("handling mime"); 217 218 if (i->mime != NULL)212 213 if (i->mime != NULL) 219 214 swish_xfree(i->mime); 220 221 i->mime = swish_get_mime_type( parser_data->s3->config, i->ext);222 215 216 i->mime = swish_get_mime_type(parser_data->s3->config, i->ext); 217 223
