Changeset 1856 for trunk/gsdl/src/recpt/receptionist.cpp
- Timestamp:
- 2001-01-23T10:58:19+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/receptionist.cpp
r1838 r1856 65 65 EmailUserEvents = false; 66 66 67 languages.erase(languages.begin(), languages.end()); 68 encodings.erase(encodings.begin(), encodings.end()); 69 67 70 // these default page parameters can always be overriden 68 71 // in the configuration file … … 84 87 info_loaded = false; 85 88 info.clear(); 89 } 90 91 void languageinfo_t::clear () { 92 longname.clear(); 93 defaultencoding.clear(); 94 } 95 96 void encodinginfo_t::clear () { 97 longname.clear(); 98 label.clear(); 86 99 } 87 100 … … 112 125 ainfo.longname = "encoding"; 113 126 ainfo.multiplechar = true; 114 ainfo.defaultstatus = cgiarginfo:: weak;115 ainfo.argdefault = " w";127 ainfo.defaultstatus = cgiarginfo::none; 128 ainfo.argdefault = ""; 116 129 ainfo.savedarginfo = cgiarginfo::must; 117 130 argsinfo.addarginfo (NULL, ainfo); … … 142 155 ainfo.savedarginfo = cgiarginfo::must; 143 156 argsinfo.addarginfo (NULL, ainfo); 144 157 158 ainfo.shortname = "nl"; 159 ainfo.longname = "new language"; 160 ainfo.multiplechar = false; 161 ainfo.defaultstatus = cgiarginfo::none; 162 ainfo.argdefault = "0"; 163 ainfo.savedarginfo = cgiarginfo::mustnot; 164 argsinfo.addarginfo (NULL, ainfo); 165 145 166 // the GSDL_UID (cookie) 146 167 ainfo.shortname = "z"; … … 293 314 cfgline_here++; 294 315 } 316 } 317 318 } else if (key == "Encoding") { 319 text_t subkey, subvalue; 320 text_t shortname, longname, label; 321 text_t::const_iterator cfglinesub_here; 322 text_tarray::const_iterator cfgline_here = cfgline.begin(); 323 text_tarray::const_iterator cfgline_end = cfgline.end(); 324 while (cfgline_here != cfgline_end) { 325 cfglinesub_here = getdelimitstr((*cfgline_here).begin(), 326 (*cfgline_here).end(), '=', subkey); 327 if (subkey == "shortname") { 328 shortname = substr (cfglinesub_here, (*cfgline_here).end()); 329 } else if (subkey == "longname") { 330 longname = substr (cfglinesub_here, (*cfgline_here).end()); 331 } else if (subkey == "label") { 332 label = substr (cfglinesub_here, (*cfgline_here).end()); 333 } 334 cfgline_here++; 335 } 336 if (!shortname.empty() && !label.empty()) { 337 encodinginfo_t enc; 338 if (longname.empty()) enc.longname = shortname; 339 else enc.longname = longname; 340 enc.label = label; 341 configinfo.encodings[shortname] = enc; 342 } 343 344 } else if (key == "Language") { 345 text_t subkey, subvalue; 346 text_t shortname, longname, defaultencoding; 347 text_t::const_iterator cfglinesub_here; 348 text_tarray::const_iterator cfgline_here = cfgline.begin(); 349 text_tarray::const_iterator cfgline_end = cfgline.end(); 350 while (cfgline_here != cfgline_end) { 351 cfglinesub_here = getdelimitstr((*cfgline_here).begin(), 352 (*cfgline_here).end(), '=', subkey); 353 if (subkey == "shortname") { 354 shortname = substr (cfglinesub_here, (*cfgline_here).end()); 355 } else if (subkey == "longname") { 356 longname = substr (cfglinesub_here, (*cfgline_here).end()); 357 } else if (subkey == "default_encoding") { 358 defaultencoding = substr (cfglinesub_here, (*cfgline_here).end()); 359 } 360 cfgline_here++; 361 } 362 if (!shortname.empty()) { 363 languageinfo_t lang; 364 if (longname.empty()) lang.longname = shortname; 365 else lang.longname = longname; 366 lang.defaultencoding = defaultencoding; 367 configinfo.languages[shortname] = lang; 295 368 } 296 369 } … … 400 473 convertinfoclass::iterator converthere = converters.begin (); 401 474 convertinfoclass::iterator convertend = converters.end (); 402 text_t defaultconvertname;403 475 while (converthere != convertend) { 404 476 assert ((*converthere).second.outconverter != NULL); 405 477 if ((*converthere).second.outconverter != NULL) { 406 478 (*converthere).second.outconverter->set_rzws(1); 407 if (defaultconvertname.empty())408 defaultconvertname = (*converthere).second.name;409 479 } 410 480 converthere++; 411 }412 413 // set default converter if no good one has been defined414 if (!defaultconvertname.empty()) {415 cgiarginfo *ainfo = argsinfo.getarginfo ("w");416 if (ainfo->argdefault != "w") {417 if ((ainfo != NULL) && (converters.get_outconverter(ainfo->argdefault) == NULL)) {418 ainfo->defaultstatus = cgiarginfo::good;419 ainfo->argdefault = defaultconvertname;420 }421 }422 481 } 423 482 … … 470 529 } 471 530 531 // get the default encoding for the given language - if it fails for any 532 // reason return "" 533 text_t receptionist::get_default_encoding (const text_t &language) { 534 535 // make sure language is valid 536 if (configinfo.languages.find(language) == configinfo.languages.end()) return ""; 537 538 text_t default_encoding = configinfo.languages[language].defaultencoding; 539 540 // make sure the encoding is valid 541 if (configinfo.encodings.find(default_encoding) == configinfo.encodings.end()) return ""; 542 543 return default_encoding; 544 } 472 545 473 546 // parse_cgi_args parses cgi arguments into an argument class. … … 476 549 bool receptionist::parse_cgi_args (const text_t &argstr, cgiargsclass &args, 477 550 ostream &logout, text_tmap &fcgienv) { 478 outconvertclass text_t2ascii;479 551 480 552 // get an initial list of cgi arguments … … 491 563 if (configinfo.usecookies) get_cookie(args["z"], fcgienv); 492 564 565 // if we're changing languages, set the encoding to the default for the new language 566 if (args["nl"] == "1") { 567 args["nw"] = get_default_encoding(args["l"]); 568 } 569 493 570 // get the input encoding 571 // if encoding isn't set, set it to the default for the current language 572 if ((args.getarg("w") == NULL) || args["w"].empty()) { 573 args["w"] = get_default_encoding(args["l"]); 574 } 575 494 576 text_t &arg_w = args["w"]; 577 495 578 inconvertclass defaultinconvert; 496 579 inconvertclass *inconvert = converters.get_inconverter (arg_w); … … 520 603 } else { 521 604 // the action was not found!! 605 outconvertclass text_t2ascii; 522 606 logout << text_t2ascii << "Error: the action \"" << args["a"] 523 607 << "\" could not be found.\n"; … … 744 828 // add the encoding information 745 829 if (response == content) { 746 if (args["w"] == "u") { 747 response_data += "; charset=UTF-8"; 748 } else if (args["w"] == "g") { 749 response_data += "; charset=GBK"; 750 } else if (args["w"] == "a") { 751 response_data += "; charset=windows-1256"; 752 } else if (args["w"] == "c") { 753 response_data += "; charset=windows-1251"; 830 if (configinfo.encodings.find(args["w"]) != configinfo.encodings.end()) { 831 response_data += "; charset=" + configinfo.encodings[args["w"]].label; 754 832 } else { 755 response_data += "; charset=ISO-8859-1"; 833 // default to latin 1 834 response_data += "; charset=ISO-8859-1"; 756 835 } 757 836
Note:
See TracChangeset
for help on using the changeset viewer.