-rw-r--r-- | lib/configuration.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/configuration.cc b/lib/configuration.cc index 4ee1526..6b21690 100644 --- a/lib/configuration.cc +++ b/lib/configuration.cc | |||
@@ -1,24 +1,25 @@ | |||
1 | #ifdef USE_PCH | 1 | #ifdef USE_PCH |
2 | #include "pch.h" | 2 | #include "pch.h" |
3 | #else | 3 | #else |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fnmatch.h> | 5 | #include <fnmatch.h> |
6 | #include <cassert> | 6 | #include <cassert> |
7 | #include <stdexcept> | 7 | #include <stdexcept> |
8 | using namespace std; | 8 | using namespace std; |
9 | #include <konforka/util.h> | ||
9 | #include <dotconf.h> | 10 | #include <dotconf.h> |
10 | #include "sitecing/configuration.h" | 11 | #include "sitecing/configuration.h" |
11 | #include "sitecing/sitecing_util.h" | 12 | #include "sitecing/sitecing_util.h" |
12 | #include "sitecing/scoreboard.h" | 13 | #include "sitecing/scoreboard.h" |
13 | #endif | 14 | #endif |
14 | 15 | ||
15 | namespace sitecing { | 16 | namespace sitecing { |
16 | 17 | ||
17 | configuration::configuration() | 18 | configuration::configuration() |
18 | : flags(0), autobuild(false) { } | 19 | : flags(0), autobuild(false) { } |
19 | configuration::configuration(const string& cfile,bool ab) | 20 | configuration::configuration(const string& cfile,bool ab) |
20 | : flags(0), autobuild(ab) { | 21 | : flags(0), autobuild(ab) { |
21 | parse(cfile); | 22 | parse(cfile); |
22 | } | 23 | } |
23 | 24 | ||
24 | enum dc_ctx { | 25 | enum dc_ctx { |
@@ -291,98 +292,98 @@ namespace sitecing { | |||
291 | if(i->regex.search(target)) | 292 | if(i->regex.search(target)) |
292 | return &*i; | 293 | return &*i; |
293 | } | 294 | } |
294 | return NULL; | 295 | return NULL; |
295 | } | 296 | } |
296 | 297 | ||
297 | string config_options::lookup_http_status_handler(const string& status) { | 298 | string config_options::lookup_http_status_handler(const string& status) { |
298 | http_status_handlers_t::const_iterator i = http_status_handlers.find(status); | 299 | http_status_handlers_t::const_iterator i = http_status_handlers.find(status); |
299 | string rv; | 300 | string rv; |
300 | if(i!=http_status_handlers.end()) | 301 | if(i!=http_status_handlers.end()) |
301 | rv = i->second; | 302 | rv = i->second; |
302 | return rv; | 303 | return rv; |
303 | } | 304 | } |
304 | 305 | ||
305 | string configuration::lookup_http_status_handler(const string& target,const string& status) { | 306 | string configuration::lookup_http_status_handler(const string& target,const string& status) { |
306 | string t = "/"; | 307 | string t = "/"; |
307 | t += normalize_path(target,strip_leading_slash); | 308 | t += konforka::normalize_path(target,konforka::strip_leading_slash); |
308 | string rv; | 309 | string rv; |
309 | for(;;) { | 310 | for(;;) { |
310 | if(t[t.length()-1]=='/') { | 311 | if(t[t.length()-1]=='/') { |
311 | loaded_options* lo = lookup_loaded_options(t); | 312 | loaded_options* lo = lookup_loaded_options(t); |
312 | if( lo && (lo->flags&config_options::flag_http_status_handlers) ) { | 313 | if( lo && (lo->flags&config_options::flag_http_status_handlers) ) { |
313 | rv = lo->lookup_http_status_handler(status); | 314 | rv = lo->lookup_http_status_handler(status); |
314 | if(!rv.empty()) | 315 | if(!rv.empty()) |
315 | return rv; | 316 | return rv; |
316 | } | 317 | } |
317 | } | 318 | } |
318 | specs_t::iterator i = specs.find(t); | 319 | specs_t::iterator i = specs.find(t); |
319 | if( i!=specs.end() && (i->second.flags&&config_options::flag_http_status_handlers) ) { | 320 | if( i!=specs.end() && (i->second.flags&&config_options::flag_http_status_handlers) ) { |
320 | rv = i->second.lookup_http_status_handler(status); | 321 | rv = i->second.lookup_http_status_handler(status); |
321 | if(!rv.empty()) | 322 | if(!rv.empty()) |
322 | return rv; | 323 | return rv; |
323 | } | 324 | } |
324 | if(t.empty()) | 325 | if(t.empty()) |
325 | return rv; | 326 | return rv; |
326 | string::size_type sl=t.rfind('/'); | 327 | string::size_type sl=t.rfind('/'); |
327 | if(sl==string::npos) { | 328 | if(sl==string::npos) { |
328 | t.erase(); | 329 | t.erase(); |
329 | }else{ | 330 | }else{ |
330 | if(sl==(t.length()-1)) | 331 | if(sl==(t.length()-1)) |
331 | t.erase(sl); | 332 | t.erase(sl); |
332 | else | 333 | else |
333 | t.erase(sl+1); | 334 | t.erase(sl+1); |
334 | } | 335 | } |
335 | } | 336 | } |
336 | } | 337 | } |
337 | 338 | ||
338 | config_options::action_handler_t *configuration::lookup_action_handler(const string& target) { | 339 | config_options::action_handler_t *configuration::lookup_action_handler(const string& target) { |
339 | string t = "/"; | 340 | string t = "/"; |
340 | t += normalize_path(target,strip_leading_slash); | 341 | t += konforka::normalize_path(target,konforka::strip_leading_slash); |
341 | for(;;) { | 342 | for(;;) { |
342 | if(t[t.length()-1]=='/') { | 343 | if(t[t.length()-1]=='/') { |
343 | loaded_options* lo = lookup_loaded_options(t); | 344 | loaded_options* lo = lookup_loaded_options(t); |
344 | if( lo && (lo->flags&config_options::flag_action_handlers) ) { | 345 | if( lo && (lo->flags&config_options::flag_action_handlers) ) { |
345 | config_options::action_handler_t *rv = lo->lookup_action_handler(target); | 346 | config_options::action_handler_t *rv = lo->lookup_action_handler(target); |
346 | if(rv) | 347 | if(rv) |
347 | return rv; | 348 | return rv; |
348 | } | 349 | } |
349 | } | 350 | } |
350 | specs_t::iterator i = specs.find(t); | 351 | specs_t::iterator i = specs.find(t); |
351 | if( i!=specs.end() && (i->second.flags&&config_options::flag_action_handlers) ) { | 352 | if( i!=specs.end() && (i->second.flags&&config_options::flag_action_handlers) ) { |
352 | config_options::action_handler_t *rv = i->second.lookup_action_handler(target); | 353 | config_options::action_handler_t *rv = i->second.lookup_action_handler(target); |
353 | if(rv) | 354 | if(rv) |
354 | return rv; | 355 | return rv; |
355 | } | 356 | } |
356 | if(t.empty()) | 357 | if(t.empty()) |
357 | return NULL; | 358 | return NULL; |
358 | string::size_type sl=t.rfind('/'); | 359 | string::size_type sl=t.rfind('/'); |
359 | if(sl==string::npos) { | 360 | if(sl==string::npos) { |
360 | t.erase(); | 361 | t.erase(); |
361 | }else{ | 362 | }else{ |
362 | if(sl==(t.length()-1)) | 363 | if(sl==(t.length()-1)) |
363 | t.erase(sl); | 364 | t.erase(sl); |
364 | else | 365 | else |
365 | t.erase(sl+1); | 366 | t.erase(sl+1); |
366 | } | 367 | } |
367 | } | 368 | } |
368 | } | 369 | } |
369 | 370 | ||
370 | config_options* configuration::lookup_config(const string& target,int flag) { | 371 | config_options* configuration::lookup_config(const string& target,int flag) { |
371 | string t = "/"; // always assume leading slash | 372 | string t = "/"; // always assume leading slash |
372 | t += normalize_path(target,strip_leading_slash); | 373 | t += konforka::normalize_path(target,konforka::strip_leading_slash); |
373 | // XXX: reconsider precedence | 374 | // XXX: reconsider precedence |
374 | for(;;) { | 375 | for(;;) { |
375 | if(t[t.length()-1]=='/') { | 376 | if(t[t.length()-1]=='/') { |
376 | loaded_options* lo = lookup_loaded_options(t); | 377 | loaded_options* lo = lookup_loaded_options(t); |
377 | if( lo && (lo->flags&flag)==flag ) | 378 | if( lo && (lo->flags&flag)==flag ) |
378 | return lo; | 379 | return lo; |
379 | } | 380 | } |
380 | specs_t::iterator i = specs.find(t); | 381 | specs_t::iterator i = specs.find(t); |
381 | if( i!=specs.end() && (i->second.flags&flag)==flag ) | 382 | if( i!=specs.end() && (i->second.flags&flag)==flag ) |
382 | return &(i->second); | 383 | return &(i->second); |
383 | if(t.empty()) | 384 | if(t.empty()) |
384 | return NULL; | 385 | return NULL; |
385 | string::size_type sl=t.rfind('/'); | 386 | string::size_type sl=t.rfind('/'); |
386 | if(sl==string::npos) { | 387 | if(sl==string::npos) { |
387 | t.erase(); | 388 | t.erase(); |
388 | }else{ | 389 | }else{ |
@@ -401,33 +402,33 @@ namespace sitecing { | |||
401 | if((*pat)=='+') | 402 | if((*pat)=='+') |
402 | pat++; | 403 | pat++; |
403 | else if((*pat)=='-') { | 404 | else if((*pat)=='-') { |
404 | plus = false; | 405 | plus = false; |
405 | pat++; | 406 | pat++; |
406 | } | 407 | } |
407 | if(!fnmatch(pat,fn,FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD)) { | 408 | if(!fnmatch(pat,fn,FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD)) { |
408 | rv = plus; | 409 | rv = plus; |
409 | return true; | 410 | return true; |
410 | } | 411 | } |
411 | } | 412 | } |
412 | return false; | 413 | return false; |
413 | } | 414 | } |
414 | 415 | ||
415 | bool configuration::match_autobuild_files(const string& target,const char *fn) { | 416 | bool configuration::match_autobuild_files(const string& target,const char *fn) { |
416 | string t = "/"; | 417 | string t = "/"; |
417 | t += normalize_path(target,strip_leading_slash|strip_trailing_slash); | 418 | t += konforka::normalize_path(target,konforka::strip_leading_slash|konforka::strip_trailing_slash); |
418 | t += "/"; | 419 | t += "/"; |
419 | bool rv = false; | 420 | bool rv = false; |
420 | for(;;) { | 421 | for(;;) { |
421 | if(t[t.length()-1]=='/') { | 422 | if(t[t.length()-1]=='/') { |
422 | loaded_options* lo = lookup_loaded_options(t); | 423 | loaded_options* lo = lookup_loaded_options(t); |
423 | if(lo && (lo->flags&config_options::flag_auto_build_files) && lo->match_autobuild_files(fn,rv) ) | 424 | if(lo && (lo->flags&config_options::flag_auto_build_files) && lo->match_autobuild_files(fn,rv) ) |
424 | return rv; | 425 | return rv; |
425 | } | 426 | } |
426 | specs_t::iterator i = specs.find(t); | 427 | specs_t::iterator i = specs.find(t); |
427 | if( i!=specs.end() && (i->second.flags&config_options::flag_auto_build_files) && i->second.match_autobuild_files(fn,rv) ) | 428 | if( i!=specs.end() && (i->second.flags&config_options::flag_auto_build_files) && i->second.match_autobuild_files(fn,rv) ) |
428 | return rv; | 429 | return rv; |
429 | if(t.empty()) | 430 | if(t.empty()) |
430 | return rv; | 431 | return rv; |
431 | string::size_type sl=t.rfind('/'); | 432 | string::size_type sl=t.rfind('/'); |
432 | if(sl==string::npos) { | 433 | if(sl==string::npos) { |
433 | t.erase(); | 434 | t.erase(); |