diff --git a/checkin_notes b/checkin_notes index 6541fcc929..e214e65e8b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -3374,3 +3374,15 @@ David 10 Apr 2007 client/ cpu_sched.C sim.C,h + +Charlie 11 Apr 2007 + - Mac: Add support for Safari on Mac. + - Fix bugs in Firefx / Mozilla cookie detection: + - Don't require match for a leading "www" in URL. + - Don't return true if is_authenticator_valid(cookie) fails. + - Check for std::string.find() returning npos if it fails, not -1. + - Add extern "C" to browser.h file. + + lib/ + browser.C,h + mac_browser.m (new, Mac only) diff --git a/lib/browser.C b/lib/browser.C index 920bec8206..0cbdbdc641 100644 --- a/lib/browser.C +++ b/lib/browser.C @@ -87,7 +87,7 @@ bool parse_name_value_pair(char* buf, std::string& name, std::string& value) { s = std::string(buf); i = s.find("=", 0); - if ( i != -1 ) { + if ( i < s.npos ) { name = s.substr(0, i); value = s.substr(i + 1); strip_whitespace(name); @@ -107,6 +107,8 @@ bool parse_hostname(std::string& project_url, std::string& hostname) { end = project_url.find("/", start); hostname = project_url.substr(start, end - start); + if (starts_with(hostname.c_str(), "www")) + hostname.erase(0, 3); if (!hostname.empty()) return true; return false; @@ -295,8 +297,8 @@ bool find_project_cookie_mozilla_generic( authenticator = ""; } else { authenticator = cookie; + retval = true; } - retval = true; } } @@ -486,6 +488,11 @@ bool detect_setup_authenticator( if (detect_setup_authenticator_ie(project_url, authenticator)) { return true; } +#endif +#ifdef __APPLE__ + if (detect_setup_authenticator_safari(project_url, authenticator)) { + return true; + } #endif if (detect_setup_authenticator_firefox(project_url, authenticator)) { return true; diff --git a/lib/browser.h b/lib/browser.h index 9c43663f8c..4221613f19 100644 --- a/lib/browser.h +++ b/lib/browser.h @@ -26,13 +26,26 @@ // cookie. // +#ifdef __cplusplus +extern "C" { +#endif + bool detect_setup_authenticator(std::string& project_url, std::string& authenticator); +// is_authenticator_valid() is used by detect_setup_authenticator_safari() in mac_bowser.m +bool is_authenticator_valid(const std::string authenticator); // These functions are browser specific functions // +#ifdef __APPLE__ +bool detect_setup_authenticator_safari(std::string& project_url, std::string& authenticator); +#endif #ifdef _WIN32 bool detect_setup_authenticator_ie(std::string& project_url, std::string& authenticator); #endif bool detect_setup_authenticator_firefox(std::string& project_url, std::string& authenticator); +#ifdef __cplusplus +} // extern "C" +#endif + #endif diff --git a/lib/mac_browser.mm b/lib/mac_browser.mm new file mode 100644 index 0000000000..52b0d43a85 --- /dev/null +++ b/lib/mac_browser.mm @@ -0,0 +1,85 @@ +// Berkeley Open Infrastructure for Network Computing +// http://boinc.berkeley.edu +// Copyright (C) 2005 University of California +// +// This is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; +// either version 2.1 of the License, or (at your option) any later version. +// +// This software is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Lesser General Public License for more details. +// +// To view the GNU Lesser General Public License visit +// http://www.gnu.org/copyleft/lesser.html +// or write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "str_util.h" +#include "browser.h" + +#include + +bool detect_setup_authenticator_safari(std::string& project_url, std::string& authenticator) +{ + NSHTTPCookieStorage *cookieStorage; + NSArray *theCookies; + NSHTTPCookie *aCookie; + NSURL *theURL; + NSString *theURLString, *theValueString, *theNameString; + NSDate *expirationDate; + unsigned int i, n; + bool retval = false; + + NSAutoreleasePool* pool; + + pool = [[NSAutoreleasePool alloc] init]; + + + theURLString = [ NSString stringWithCString:project_url.c_str() ]; + + theURL = [ NSURL URLWithString:theURLString ]; + + cookieStorage = [ NSHTTPCookieStorage sharedHTTPCookieStorage ]; + + if (cookieStorage == NULL) + goto bail; + + theCookies = [ cookieStorage cookiesForURL:theURL ]; + + if (theCookies == NULL) + goto bail; + + n = [ theCookies count ]; + for (i=0; i