| 468 | } |
| 469 | |
| 470 | const char * |
| 471 | HttpBodyFactory::determine_set_by_language(std::unique_ptr<BodySetTable> &table_of_sets, StrList *acpt_language_list, |
| 472 | StrList *acpt_charset_list, float *Q_best_ptr, int *La_best_ptr, int *Lc_best_ptr, |
| 473 | int *I_best_ptr) |
| 474 | { |
| 475 | float Q, Ql, Qc, Q_best; |
| 476 | int I, Idummy, I_best; |
| 477 | int La, Lc, La_best, Lc_best; |
| 478 | int is_the_default_set; |
| 479 | const char *set_best; |
| 480 | |
| 481 | set_best = "default"; |
| 482 | Q_best = 0.00001; |
| 483 | La_best = 0; |
| 484 | Lc_best = INT_MAX; |
| 485 | I_best = INT_MAX; |
| 486 | |
| 487 | Dbg(dbg_ctl_body_factory_determine_set, " INITIAL: [ set_best='%s', Q=%g, La=%d, Lc=%d, I=%d ]", set_best, Q_best, La_best, |
| 488 | Lc_best, I_best); |
| 489 | |
| 490 | // FIX: eliminate this special case (which doesn't work anyway), by properly |
| 491 | // handling empty lists and empty pieces in match_accept_XXX |
| 492 | |
| 493 | // if no Accept-Language or Accept-Charset, just return default |
| 494 | if ((acpt_language_list->count == 0) && (acpt_charset_list->count == 0)) { |
| 495 | Q_best = 1; |
| 496 | Dbg(dbg_ctl_body_factory_determine_set, " no constraints => returning '%s'", set_best); |
| 497 | goto done; |
| 498 | } |
| 499 | |
| 500 | if (table_of_sets) { |
| 501 | /////////////////////////////////////////// |
| 502 | // loop over set->body-types hash table // |
| 503 | /////////////////////////////////////////// |
| 504 | for (const auto &it : *table_of_sets.get()) { |
| 505 | const char *set_name = it.first.c_str(); |
| 506 | HttpBodySetRawData *body_set = it.second; |
| 507 | |
| 508 | if ((it.first.empty()) || (body_set->table_of_pages == nullptr)) { |
| 509 | continue; |
| 510 | } |
| 511 | |
| 512 | ////////////////////////////////////////////////////////////////////// |
| 513 | // Take this error page language and match it against the // |
| 514 | // Accept-Language string passed in, to evaluate the match // |
| 515 | // quality. Disable wildcard processing so we use "default" // |
| 516 | // if no set explicitly matches. We also get back the index // |
| 517 | // of the match and the length of the match. // |
| 518 | // // |
| 519 | // We optimize the match in a couple of ways: // |
| 520 | // (a) if Q is better ==> wins, else if tie, // |
| 521 | // (b) if accept tag length La is bigger ==> wins, else if tie, // |
| 522 | // (c) if content tag length Lc is smaller ==> wins, else if tie, // |
| 523 | // (d) if index position I is smaller ==> wins // |
| 524 | ////////////////////////////////////////////////////////////////////// |
| 525 | |
| 526 | is_the_default_set = (strcmp(set_name, "default") == 0); |
| 527 | |