When implementing Mozilla's autoconfig the other day I mentioned that a question mark (?) doesn't work in the autoadmin.global_config_url; no manner of escaping worked: neither a backslash (\?) nor URI-encoding (%3F). Firefox chops the URI at the question mark. As mentioned already, I left it at that and used PATH_INFO to get the information I needed. Simon brought the topic up again, and the issue piqued my curiosity so I downloaded the Firefox 3.0.3 source tar ball and unpacked all whopping 270 MB of it. After two or three minutes and a bit of find and grep, I landed at the file extensions/pref/autoconfig/src/nsAutoConfig.cpp which is where the magic happens. In there, the function downloadAutoConfig() clearly states that the URI is truncated at the question mark. The explanation is, that, in the original design, the user's e-mail address can be appended to the URI, if autoadmin.append_emailaddr is true. I personally consider that bad design -- the implementation ought to have parsed the URI and added either ?mail=_value_ or &mail;=_value_ to the end of the supplied string. Be that as it may and to satisfy our curiosity, we tested it. Thanks to the source code we didn't have to set up a full e-mail configuration tree because Mozilla still supports Netscape's 4.x code. In the end we set the e-mail address, tricking a GET parameter into that:

lockPref("autoadmin.append_emailaddr", true);
lockPref("mail.identity.useremail", "user=" + env_user);
lockPref("autoadmin.global_config_url", "http://example.com/auto.php");

Note how the value of useremail becomes user=jpm (for my username of jpm), and that whole string is subsequently appended to the configuration URL. So, when Firefox starts, it requests the autoconfig from

http://example.com/auto.php?user=jpm

Bingo: fifteen useless minutes (because what we implemented before worked perfectly), but it was fun. And that is the beauty of Open Source: if you can't get it to roll, you have full documentation of how it works. Who the hell needs a (badly written, incomplete, out-of-date) manual, when you've got the source? ;-) And here is the full mozilla.cfg we designed:

//BEGIN CE prefs

try {
 if(getenv("USERNAME") != "") {
    var env_user = getenv("USERNAME");
 } else {
    var env_user = "no-uid";
 }
 lockPref("autoadmin.append_emailaddr", true);
 lockPref("mail.identity.useremail", "user=" + env_user);
 lockPref("autoadmin.global_config_url", "http://example.com/auto.php");
} catch(e) {
  displayError("lockedPref", e);
}

Comments

blog comments powered by Disqus