/* * Check to see if there is a workgroup/domain in the URL. If yes then return an array * with the first element as the workgroup and the second element containing the * username and server name. If no workgroup just return NULL. */ static CFArrayRef CreateWrkgrpUserArray(CFURLRef url) { CFStringRef netlocation = NULL; CFArrayRef userArray = NULL; netlocation = CFURLCopyNetLocation(url); if (!netlocation) return NULL; userArray = CreateWrkgrpUserArrayFromCFStringRef(netlocation, CFSTR(";")); CFRelease(netlocation); return userArray; }
CF::String URL::GetNetLocation( void ) { CF::String str; CFStringRef cfStr; if( this->_cfObject == NULL ) { return str; } cfStr = CFURLCopyNetLocation( this->_cfObject ); if( cfStr != NULL ) { str = cfStr; CFRelease( cfStr ); } return str; }
static CFArrayRef _SecIdentityCopyPossiblePaths( CFStringRef name) { // utility function to build and return an array of possible paths for the given name. // if name is not a URL, this returns a single-element array. // if name is a URL, the array may contain 1..N elements, one for each level of the path hierarchy. CFMutableArrayRef names = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); if (!name) { return names; } CFIndex oldLength = CFStringGetLength(name); CFArrayAppendValue(names, name); CFURLRef url = CFURLCreateWithString(NULL, name, NULL); if (url) { if (CFURLCanBeDecomposed(url)) { // first, remove the query portion of this URL, if any CFStringRef qs = CFURLCopyQueryString(url, NULL); if (qs) { CFMutableStringRef newName = CFStringCreateMutableCopy(NULL, oldLength, name); if (newName) { CFIndex qsLength = CFStringGetLength(qs) + 1; // include the '?' CFStringDelete(newName, CFRangeMake(oldLength-qsLength, qsLength)); CFRelease(url); url = CFURLCreateWithString(NULL, newName, NULL); CFArraySetValueAtIndex(names, 0, newName); CFRelease(newName); } CFRelease(qs); } // now add an entry for each level of the path while (url) { CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, url); if (parent) { CFStringRef parentURLString = CFURLGetString(parent); if (parentURLString) { CFIndex newLength = CFStringGetLength(parentURLString); // check that string length has decreased as expected; for file URLs, // CFURLCreateCopyDeletingLastPathComponent can insert './' or '../' if ((newLength >= oldLength) || (!CFStringHasPrefix(name, parentURLString))) { CFRelease(parent); CFRelease(url); break; } oldLength = newLength; CFArrayAppendValue(names, parentURLString); } } CFRelease(url); url = parent; } } else { CFRelease(url); } } // finally, add wildcard entries for each subdomain url = CFURLCreateWithString(NULL, name, NULL); if (url) { if (CFURLCanBeDecomposed(url)) { CFStringRef netLocString = CFURLCopyNetLocation(url); if (netLocString) { // first strip off port number, if present CFStringRef tmpLocString = netLocString; CFArrayRef hostnameArray = CFStringCreateArrayBySeparatingStrings(NULL, netLocString, CFSTR(":")); tmpLocString = (CFStringRef)CFRetain((CFStringRef)CFArrayGetValueAtIndex(hostnameArray, 0)); CFRelease(netLocString); CFRelease(hostnameArray); netLocString = tmpLocString; // split remaining string into domain components hostnameArray = CFStringCreateArrayBySeparatingStrings(NULL, netLocString, CFSTR(".")); CFIndex subdomainCount = CFArrayGetCount(hostnameArray); CFIndex i = 0; while (++i < subdomainCount) { CFIndex j = i; CFMutableStringRef wildcardString = CFStringCreateMutable(NULL, 0); if (wildcardString) { CFStringAppendCString(wildcardString, "*", kCFStringEncodingUTF8); while (j < subdomainCount) { CFStringRef domainString = (CFStringRef)CFArrayGetValueAtIndex(hostnameArray, j++); if (CFStringGetLength(domainString) > 0) { CFStringAppendCString(wildcardString, ".", kCFStringEncodingUTF8); CFStringAppend(wildcardString, domainString); } } if (CFStringGetLength(wildcardString) > 1) { CFArrayAppendValue(names, wildcardString); } CFRelease(wildcardString); } } CFRelease(hostnameArray); CFRelease(netLocString); } } CFRelease(url); } return names; }