2009-02-21 02:42:50 +00:00
|
|
|
// This file is part of BOINC.
|
2007-04-11 10:50:09 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2009-02-21 02:42:50 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-04-11 10:50:09 +00:00
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2007-04-11 10:50:09 +00:00
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-04-11 10:50:09 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-04-11 10:50:09 +00:00
|
|
|
|
|
|
|
#include "str_util.h"
|
|
|
|
#include "browser.h"
|
|
|
|
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
2009-05-12 14:20:36 +00:00
|
|
|
bool detect_cookie_safari(std::string& project_url, std::string& name, std::string& value)
|
2007-04-11 10:50:09 +00:00
|
|
|
{
|
|
|
|
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<n; i++) {
|
|
|
|
aCookie = (NSHTTPCookie*)[ theCookies objectAtIndex:i ];
|
|
|
|
|
|
|
|
// has the cookie expired?
|
|
|
|
expirationDate = [ aCookie expiresDate ];
|
|
|
|
if ([ expirationDate compare:[ NSDate date ]] == NSOrderedAscending)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
theNameString = [ aCookie name ];
|
|
|
|
// is this the right cookie?
|
2007-04-17 09:19:32 +00:00
|
|
|
#ifdef cStringUsingEncoding // Available only is OS 10.4 and later
|
2009-05-12 14:20:36 +00:00
|
|
|
if (!starts_with([ theNameString cStringUsingEncoding:NSMacOSRomanStringEncoding ], name.c_str()))
|
2007-04-17 09:19:32 +00:00
|
|
|
continue;
|
|
|
|
theValueString = [ aCookie value ];
|
2009-05-12 14:20:36 +00:00
|
|
|
value = [ theValueString cStringUsingEncoding:NSMacOSRomanStringEncoding ];
|
2007-04-17 09:19:32 +00:00
|
|
|
#else
|
2009-05-12 14:20:36 +00:00
|
|
|
if (!starts_with([ theNameString cString ], name.c_str()))
|
2007-04-17 09:19:32 +00:00
|
|
|
continue;
|
|
|
|
theValueString = [ aCookie value ];
|
2009-05-12 14:20:36 +00:00
|
|
|
value = [ theValueString cString ];
|
2007-04-17 09:19:32 +00:00
|
|
|
#endif
|
2009-06-04 23:45:33 +00:00
|
|
|
retval = true;
|
2007-04-11 10:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bail:
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|