From 543a783e2c4b6b834abee74ef832b26ceab80ea7 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 21 Nov 2007 20:36:04 +0000 Subject: [PATCH] replaced URL escaping with NGExtensions git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1550 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ldap/NGLdap/ChangeLog | 3 + sope-ldap/NGLdap/NGLdapURL.m | 156 ++++------------------------------- sope-ldap/NGLdap/Version | 2 +- 3 files changed, 18 insertions(+), 143 deletions(-) diff --git a/sope-ldap/NGLdap/ChangeLog b/sope-ldap/NGLdap/ChangeLog index 67dec7e4..fa806f48 100644 --- a/sope-ldap/NGLdap/ChangeLog +++ b/sope-ldap/NGLdap/ChangeLog @@ -1,5 +1,8 @@ 2007-11-21 Helge Hess + * NGLdapURL.m: removed local URL escaping and replaced it with + NSString+misc (v4.7.33) + * NSString+DN.m: removed cString based space-stripping function and replaced it with the method from NGExtensions (v4.7.32) diff --git a/sope-ldap/NGLdap/NGLdapURL.m b/sope-ldap/NGLdap/NGLdapURL.m index 08e0d740..6ce68208 100644 --- a/sope-ldap/NGLdap/NGLdapURL.m +++ b/sope-ldap/NGLdap/NGLdapURL.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -23,135 +24,10 @@ #include "NGLdapConnection.h" #include "NGLdapEntry.h" #include "EOQualifier+LDAP.h" +#include #include "common.h" #include -static inline BOOL isUrlAlpha(unsigned char _c) { - return - (((_c >= 'a') && (_c <= 'z')) || - ((_c >= 'A') && (_c <= 'Z'))) - ? YES : NO; -} -static inline BOOL isUrlDigit(unsigned char _c) { - return ((_c >= '0') && (_c <= '9')) ? YES : NO; -} -static inline BOOL isUrlSafeChar(unsigned char _c) { - switch (_c) { - case '$': case '-': case '_': case '@': - case '.': case '&': case '+': - return YES; - - default: - return NO; - } -} -static inline BOOL isUrlExtraChar(unsigned char _c) { - switch (_c) { - case '!': case '*': case '"': case '\'': - case '|': case ',': - return YES; - } - return NO; -} -static inline BOOL isUrlEscapeChar(unsigned char _c) { - return (_c == '%') ? YES : NO; -} -static inline BOOL isUrlReservedChar(unsigned char _c) { - switch (_c) { - case '=': case ';': case '/': - case '#': case '?': case ':': - case ' ': - return YES; - } - return NO; -} - -static inline BOOL isUrlXalpha(unsigned char _c) { - if (isUrlAlpha(_c)) return YES; - if (isUrlDigit(_c)) return YES; - if (isUrlSafeChar(_c)) return YES; - if (isUrlExtraChar(_c)) return YES; - if (isUrlEscapeChar(_c)) return YES; - return NO; -} - -static inline BOOL isUrlHexChar(unsigned char _c) { - if (isUrlDigit(_c)) - return YES; - if ((_c >= 'a') && (_c <= 'f')) - return YES; - if ((_c >= 'A') && (_c <= 'F')) - return YES; - return NO; -} - -static inline BOOL isUrlAlphaNum(unsigned char _c) { - return (isUrlAlpha(_c) || isUrlDigit(_c)) ? YES : NO; -} - -static inline BOOL isToBeEscaped(unsigned char _c) { - return (isUrlAlphaNum(_c) || (_c == '_')) ? NO : YES; -} - -static BOOL NGContainsUrlInvalidCharacters(const unsigned char *_buffer) { - while (*_buffer) { - if (isToBeEscaped(*_buffer)) - return YES; - _buffer++; - } - return NO; -} -static void NGEscapeUrlBuffer -(const unsigned char *_source, unsigned char *_dest) { - register const unsigned char *src = (void*)_source; - while (*src) { - //if (*src == ' ') { // a ' ' becomes a '+' - // *_dest = '+'; _dest++; - //} - if (!isToBeEscaped(*src)) { - *_dest = *src; - _dest++; - } - else { // any other char is escaped .. - *_dest = '%'; _dest++; - sprintf((char *)_dest, "%02X", (unsigned)*src); - _dest += 2; - } - src++; - } - *_dest = '\0'; -} -static NSString *NGEscapeUrlString(NSString *_source) { - unsigned len; - char *cstr; - NSString *s; - - if ((len = [_source cStringLength]) == 0) - return _source; - - cstr = malloc(len + 3); - [_source getCString:cstr]; - cstr[len] = '\0'; - - if (NGContainsUrlInvalidCharacters((unsigned char *)cstr)) { - // needs to be escaped ? - char *buffer = NULL; - - buffer = NGMallocAtomic([_source cStringLength] * 3 + 2); - NGEscapeUrlBuffer((unsigned char *)cstr, (unsigned char *)buffer); - - s = [[[NSString alloc] - initWithCStringNoCopy:buffer - length:strlen(buffer) - freeWhenDone:YES] autorelease]; - } - else - s = [[_source copy] autorelease]; - - free(cstr); - return s; -} - @implementation NGLdapURL + (id)ldapURLWithString:(NSString *)_url { @@ -306,8 +182,8 @@ static NSString *NGEscapeUrlString(NSString *_source) { - (NSString *)urlString { NSMutableString *s; - NSString *is; - + NSString *r; + s = [[NSMutableString alloc] initWithCapacity:200]; [s appendString:@"ldap://"]; @@ -315,15 +191,13 @@ static NSString *NGEscapeUrlString(NSString *_source) { if (self->port > 0) [s appendFormat:@":%i", self->port]; [s appendString:@"/"]; - is = self->base; - is = NGEscapeUrlString(is); - [s appendString:is]; + [s appendString:[self->base stringByEscapingURL]]; - if ((self->attributes != nil) || (self->scope != -1) || (self->filter != nil)){ + if ((self->attributes != nil) || (self->scope!=-1) || (self->filter != nil)){ + NSString *is; [s appendString:@"?"]; is = [self->attributes componentsJoinedByString:@","]; - is = NGEscapeUrlString(is); - [s appendString:is]; + [s appendString:[is stringByEscapingURL]]; } if ((self->scope != -1) || (self->filter != nil)) { [s appendString:@"?"]; @@ -340,16 +214,14 @@ static NSString *NGEscapeUrlString(NSString *_source) { break; } } - if (self->filter) { + if ([self->filter isNotEmpty]) { [s appendString:@"?"]; - is = self->filter; - is = NGEscapeUrlString(is); - [s appendString:is]; + [s appendString:[self->filter stringByEscapingURL]]; } - is = [s copy]; - [s release]; - return [is autorelease]; + r = [[s copy] autorelease]; + [s release]; s = nil; + return r; } /* NSCopying */ diff --git a/sope-ldap/NGLdap/Version b/sope-ldap/NGLdap/Version index 799512bc..5fd280f0 100644 --- a/sope-ldap/NGLdap/Version +++ b/sope-ldap/NGLdap/Version @@ -2,4 +2,4 @@ MAJOR_VERSION=4 MINOR_VERSION=7 -SUBMINOR_VERSION:=32 +SUBMINOR_VERSION:=33 -- 2.39.5