Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -40,11 +40,11 @@ + pluginFromFile: (OFString*)path { OFAutoreleasePool *pool; OFMutableString *file; of_plugin_handle_t handle; - OFPlugin *(*init_plugin)(); + OFPlugin *(*initPlugin)(); OFPlugin *plugin; pool = [[OFAutoreleasePool alloc] init]; file = [OFMutableString stringWithString: path]; [file appendCString: PLUGIN_SUFFIX]; @@ -52,12 +52,12 @@ if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL) @throw [OFInitializationFailedException newWithClass: self]; [pool release]; - init_plugin = (OFPlugin*(*)())dlsym(handle, "init_plugin"); - if (init_plugin == NULL || (plugin = init_plugin()) == nil) { + initPlugin = (OFPlugin*(*)())dlsym(handle, "init_plugin"); + if (initPlugin == NULL || (plugin = initPlugin()) == nil) { dlclose(handle); @throw [OFInitializationFailedException newWithClass: self]; } plugin->handle = handle; Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -79,19 +79,19 @@ OFMutableArray *readStreams; OFMutableArray *writeStreams; OFMutableArray *queue, *queueInfo; id delegate; #ifdef OF_HAVE_POLL - OFDataArray *fds; - OFMutableDictionary *fdToStream; + OFDataArray *FDs; + OFMutableDictionary *FDToStream; #else - fd_set readfds; - fd_set writefds; - fd_set exceptfds; - int nfds; + fd_set readFDs; + fd_set writeFDs; + fd_set exceptFDs; + int nFDs; #endif - int cancelFd[2]; + int cancelFD[2]; #ifdef _WIN32 struct sockaddr_in cancelAddr; #endif } Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -75,59 +75,59 @@ readStreams = [[OFMutableArray alloc] init]; writeStreams = [[OFMutableArray alloc] init]; queue = [[OFMutableArray alloc] init]; queueInfo = [[OFMutableArray alloc] init]; #ifdef OF_HAVE_POLL - fds = [[OFDataArray alloc] initWithItemSize: + FDs = [[OFDataArray alloc] initWithItemSize: sizeof(struct pollfd)]; - fdToStream = [[OFMutableDictionary alloc] init]; + FDToStream = [[OFMutableDictionary alloc] init]; #else FD_ZERO(&readfds); FD_ZERO(&writefds); #endif #ifndef _WIN32 - if (pipe(cancelFd)) + if (pipe(cancelFD)) @throw [OFInitializationFailedException newWithClass: isa]; #else /* Make sure WSAStartup has been called */ [OFTCPSocket class]; - cancelFd[0] = socket(AF_INET, SOCK_DGRAM, 0); - cancelFd[1] = socket(AF_INET, SOCK_DGRAM, 0); + cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0); + cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); - if (cancelFd[0] == INVALID_SOCKET || - cancelFd[1] == INVALID_SOCKET) + if (cancelFD[0] == INVALID_SOCKET || + cancelFD[1] == INVALID_SOCKET) @throw [OFInitializationFailedException newWithClass: isa]; cancelAddr.sin_family = AF_INET; cancelAddr.sin_port = 0; cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); cancelAddr2 = cancelAddr; - if (bind(cancelFd[0], (struct sockaddr*)&cancelAddr, - sizeof(cancelAddr)) || bind(cancelFd[1], + if (bind(cancelFD[0], (struct sockaddr*)&cancelAddr, + sizeof(cancelAddr)) || bind(cancelFD[1], (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2))) @throw [OFInitializationFailedException newWithClass: isa]; cancelAddrLen = sizeof(cancelAddr); - if (getsockname(cancelFd[0], (struct sockaddr*)&cancelAddr, + if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr, &cancelAddrLen)) @throw [OFInitializationFailedException newWithClass: isa]; #endif #ifdef OF_HAVE_POLL - p.fd = cancelFd[0]; - [fds addItem: &p]; + p.fd = cancelFD[0]; + [FDs addItem: &p]; #else - FD_SET(cancelFd[0], &readfds); - nfds = cancelFd[0] + 1; + FD_SET(cancelFD[0], &readFDs); + nFDs = cancelFD[0] + 1; #endif } @catch (id e) { [self release]; @throw e; } @@ -135,21 +135,21 @@ return self; } - (void)dealloc { - close(cancelFd[0]); - close(cancelFd[1]); + close(cancelFD[0]); + close(cancelFD[1]); [(id)delegate release]; [readStreams release]; [writeStreams release]; [queue release]; [queueInfo release]; #ifdef OF_HAVE_POLL - [fdToStream release]; - [fds release]; + [FDToStream release]; + [FDs release]; #endif [super dealloc]; } @@ -167,84 +167,85 @@ #ifdef OF_HAVE_POLL - (void)_addStream: (OFStream*)stream withEvents: (short)events { - struct pollfd *fds_c = [fds cArray]; - size_t i, count = [fds count]; - int fd = [stream fileDescriptor]; + struct pollfd *FDsCArray = [FDs cArray]; + size_t i, count = [FDs count]; + int fileDescriptor = [stream fileDescriptor]; BOOL found = NO; for (i = 0; i < count; i++) { - if (fds_c[i].fd == fd) { - fds_c[i].events |= events; + if (FDsCArray[i].fd == fileDescriptor) { + FDsCArray[i].events |= events; found = YES; } } if (!found) { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - struct pollfd p = { fd, events | POLLERR, 0 }; - [fds addItem: &p]; - [fdToStream setObject: stream - forKey: [OFNumber numberWithInt: fd]]; + struct pollfd p = { fileDescriptor, events | POLLERR, 0 }; + [FDs addItem: &p]; + [FDToStream setObject: stream + forKey: [OFNumber numberWithInt: + fileDescriptor]]; [pool release]; } } - (void)_removeStream: (OFStream*)stream withEvents: (short)events { - struct pollfd *fds_c = [fds cArray]; - size_t i, nfds = [fds count]; - int fd = [stream fileDescriptor]; + struct pollfd *FDsCArray = [FDs cArray]; + size_t i, nFDs = [FDs count]; + int fileDescriptor = [stream fileDescriptor]; - for (i = 0; i < nfds; i++) { - if (fds_c[i].fd == fd) { + for (i = 0; i < nFDs; i++) { + if (FDsCArray[i].fd == fileDescriptor) { OFAutoreleasePool *pool; - fds_c[i].events &= ~events; + FDsCArray[i].events &= ~events; - if ((fds_c[i].events & ~POLLERR) != 0) + if ((FDsCArray[i].events & ~POLLERR) != 0) return; pool = [[OFAutoreleasePool alloc] init]; - [fds removeItemAtIndex: i]; - [fdToStream removeObjectForKey: - [OFNumber numberWithInt: fd]]; + [FDs removeItemAtIndex: i]; + [FDToStream removeObjectForKey: + [OFNumber numberWithInt: fileDescriptor]]; [pool release]; } } } #else - (void)_addStream: (OFStream*)stream - withFDSet: (fd_set*)fdset + withFDSet: (fd_set*)FDSet { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - int fd = [stream fileDescriptor]; + int fileDescriptor = [stream fileDescriptor]; - FD_SET(fd, fdset); - FD_SET(fd, &exceptfds); + FD_SET(fileDescriptor, FDSet); + FD_SET(fileDescriptor, &exceptFDs); if (fd >= nfds) nfds = fd + 1; [pool release]; } - (void)_removeStream: (OFStream*)stream - withFDSet: (fd_set*)fdset - otherFDSet: (fd_set*)other_fdset -{ - int fd = [stream fileDescriptor]; - - FD_CLR(fd, fdset); - - if (!FD_ISSET(fd, other_fdset)) - FD_CLR(fd, &exceptfds); + withFDSet: (fd_set*)FDSet + otherFDSet: (fd_set*)otherFDSet +{ + int fileDescriptor = [stream fileDescriptor]; + + FD_CLR(fileDescriptor, FDSet); + + if (!FD_ISSET(fileDescriptor, otherFDSet)) + FD_CLR(fileDescriptor, &exceptfds); } #endif - (void)addStreamToObserveForReading: (OFStream*)stream { @@ -255,13 +256,13 @@ [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 - assert(write(cancelFd[1], "", 1) > 0); + assert(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } @@ -275,13 +276,13 @@ [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 - assert(write(cancelFd[1], "", 1) > 0); + assert(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } @@ -295,13 +296,13 @@ [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 - assert(write(cancelFd[1], "", 1) > 0); + assert(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } @@ -315,70 +316,70 @@ [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 - assert(write(cancelFd[1], "", 1) > 0); + assert(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFd[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } - (void)_processQueue { @synchronized (queue) { - OFStream **queue_c = [queue cArray]; - OFNumber **queueInfo_c = [queueInfo cArray]; + OFStream **queueCArray = [queue cArray]; + OFNumber **queueInfoCArray = [queueInfo cArray]; size_t i, count = [queue count]; for (i = 0; i < count; i++) { - switch ([queueInfo_c[i] intValue]) { + switch ([queueInfoCArray[i] intValue]) { case QUEUE_ADD | QUEUE_READ: - [readStreams addObject: queue_c[i]]; + [readStreams addObject: queueCArray[i]]; #ifdef OF_HAVE_POLL - [self _addStream: queue_c[i] + [self _addStream: queueCArray[i] withEvents: POLLIN]; #else - [self _addStream: queue_c[i] - withFDSet: &readfds]; + [self _addStream: queueCArray[i] + withFDSet: &readFDs]; #endif break; case QUEUE_ADD | QUEUE_WRITE: - [writeStreams addObject: queue_c[i]]; + [writeStreams addObject: queueCArray[i]]; #ifdef OF_HAVE_POLL - [self _addStream: queue_c[i] + [self _addStream: queueCArray[i] withEvents: POLLOUT]; #else - [self _addStream: queue_c[i] - withFDSet: &writefds]; + [self _addStream: queueCArray[i] + withFDSet: &writeFDs]; #endif break; case QUEUE_REMOVE | QUEUE_READ: [readStreams removeObjectIdenticalTo: - queue_c[i]]; + queueCArray[i]]; #ifdef OF_HAVE_POLL - [self _removeStream: queue_c[i] + [self _removeStream: queueCArray[i] withEvents: POLLIN]; #else - [self _removeStream: queue_c[i] - withFDSet: &readfds - otherFDSet: &writefds]; + [self _removeStream: queueCArray[i] + withFDSet: &readFDs + otherFDSet: &writeFDs]; #endif break; case QUEUE_REMOVE | QUEUE_WRITE: [writeStreams removeObjectIdenticalTo: - queue_c[i]]; + queueCArray[i]]; #ifdef OF_HAVE_POLL - [self _removeStream: queue_c[i] + [self _removeStream: queueCArray[i] withEvents: POLLOUT]; #else - [self _removeStream: queue_c[i] - withFDSet: &writefds - otherFDSet: &readfds]; + [self _removeStream: queueCArray[i] + withFDSet: &writeFDs + otherFDSet: &readFDs]; #endif break; default: assert(0); } @@ -399,17 +400,17 @@ OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; BOOL foundInCache = NO; OFStream **cArray; size_t i, count; #ifdef OF_HAVE_POLL - struct pollfd *fds_c; - size_t nfds; + struct pollfd *FDsCArray; + size_t nFDs; #else - fd_set readfds_; - fd_set writefds_; - fd_set exceptfds_; - struct timeval tv; + fd_set readFDs_; + fd_set writeFDs_; + fd_set exceptFDs_; + struct timeval time; #endif [self _processQueue]; cArray = [readStreams cArray]; @@ -429,116 +430,116 @@ */ if (foundInCache) return YES; #ifdef OF_HAVE_POLL - fds_c = [fds cArray]; - nfds = [fds count]; + FDsCArray = [FDs cArray]; + nFDs = [FDs count]; # ifdef OPEN_MAX - if (nfds > OPEN_MAX) + if (nFDs > OPEN_MAX) @throw [OFOutOfRangeException newWithClass: isa]; # endif - if (poll(fds_c, (nfds_t)nfds, timeout) < 1) + if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1) return NO; - for (i = 0; i < nfds; i++) { + for (i = 0; i < nFDs; i++) { OFNumber *num; OFStream *stream; - if (fds_c[i].revents & POLLIN) { - if (fds_c[i].fd == cancelFd[0]) { - char buf; + if (FDsCArray[i].revents & POLLIN) { + if (FDsCArray[i].fd == cancelFD[0]) { + char buffer; - assert(read(cancelFd[0], &buf, 1) > 0); - fds_c[i].revents = 0; + assert(read(cancelFD[0], &buffer, 1) > 0); + FDsCArray[i].revents = 0; continue; } - num = [OFNumber numberWithInt: fds_c[i].fd]; - stream = [fdToStream objectForKey: num]; + num = [OFNumber numberWithInt: FDsCArray[i].fd]; + stream = [FDToStream objectForKey: num]; [delegate streamDidBecomeReadyForReading: stream]; [pool releaseObjects]; } - if (fds_c[i].revents & POLLOUT) { - num = [OFNumber numberWithInt: fds_c[i].fd]; - stream = [fdToStream objectForKey: num]; + if (FDsCArray[i].revents & POLLOUT) { + num = [OFNumber numberWithInt: FDsCArray[i].fd]; + stream = [FDToStream objectForKey: num]; [delegate streamDidBecomeReadyForReading: stream]; [pool releaseObjects]; } - if (fds_c[i].revents & POLLERR) { - num = [OFNumber numberWithInt: fds_c[i].fd]; - stream = [fdToStream objectForKey: num]; + if (FDsCArray[i].revents & POLLERR) { + num = [OFNumber numberWithInt: FDsCArray[i].fd]; + stream = [FDToStream objectForKey: num]; [delegate streamDidReceiveException: stream]; [pool releaseObjects]; } - fds_c[i].revents = 0; + FDsCArray[i].revents = 0; } #else # ifdef FD_COPY - FD_COPY(&readfds, &readfds_); - FD_COPY(&writefds, &writefds_); - FD_COPY(&exceptfds, &exceptfds_); + FD_COPY(&readFDs, &readFDs_); + FD_COPY(&writeFDs, &writeFDs_); + FD_COPY(&exceptFDs, &exceptFDs_); # else - readfds_ = readfds; - writefds_ = writefds; - exceptfds_ = exceptfds; + readFDs_ = readFDs; + writeFDs_ = writeFDs; + exceptFDs_ = exceptFDs; # endif - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; + time.tv_sec = timeout / 1000; + time.tv_usec = (timeout % 1000) * 1000; - if (select(nfds, &readfds_, &writefds_, &exceptfds_, - (timeout != -1 ? &tv : NULL)) < 1) + if (select(nFDs, &readFDs_, &writeFDs_, &exceptFDs_, + (timeout != -1 ? &time : NULL)) < 1) return NO; - if (FD_ISSET(cancelFd[0], &readfds_)) { - char buf; + if (FD_ISSET(cancelFD[0], &readFDs_)) { + char buffer; #ifndef _WIN32 - assert(read(cancelFd[0], &buf, 1) > 0); + assert(read(cancelFD[0], &buffer, 1) > 0); #else - assert(recvfrom(cancelFd[0], &buf, 1, 0, NULL, NULL) > 0); + assert(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); #endif } for (i = 0; i < count; i++) { - int fd = [cArray[i] fileDescriptor]; + int fileDescriptor = [cArray[i] fileDescriptor]; - if (FD_ISSET(fd, &readfds_)) { + if (FD_ISSET(fileDescriptor, &readFDs_)) { [delegate streamDidBecomeReadyForReading: cArray[i]]; [pool releaseObjects]; } - if (FD_ISSET(fd, &exceptfds_)) { + if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: cArray[i]]; [pool releaseObjects]; /* - * Prevent calling it twice in case the fd is in both + * Prevent calling it twice in case the FD is in both * sets. */ - FD_CLR(fd, &exceptfds_); + FD_CLR(fileDescriptor, &exceptFDs_); } } cArray = [writeStreams cArray]; count = [writeStreams count]; for (i = 0; i < count; i++) { - int fd = [cArray[i] fileDescriptor]; + int fileDescriptor = [cArray[i] fileDescriptor]; - if (FD_ISSET(fd, &writefds_)) { + if (FD_ISSET(fileDescriptor, &writeFDs_)) { [delegate streamDidBecomeReadyForWriting: cArray[i]]; [pool releaseObjects]; } - if (FD_ISSET(fd, &exceptfds_)) { + if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: cArray[i]]; [pool releaseObjects]; } } #endif Index: src/OFString+URLEncoding.m ================================================================== --- src/OFString+URLEncoding.m +++ src/OFString+URLEncoding.m @@ -29,109 +29,110 @@ int _OFString_URLEncoding_reference; @implementation OFString (URLEncoding) - (OFString*)stringByURLEncoding { - const char *s; - char *ret_c; + const char *string_ = string; + char *retCString; size_t i; OFString *ret; - s = string; - /* * Worst case: 3 times longer than before. * Oh, and we can't use [self allocWithSize:] here as self might be a * @"" literal. */ - if ((ret_c = malloc((length * 3) + 1)) == NULL) + if ((retCString = malloc((length * 3) + 1)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa requestedSize: (length * 3) + 1]; - for (i = 0; *s != '\0'; s++) { - if (isalnum((int)*s) || *s == '-' || *s == '_' || *s == '.' || - *s == '~') - ret_c[i++] = *s; + for (i = 0; *string_ != '\0'; string_++) { + if (isalnum((int)*string_) || *string_ == '-' || + *string_ == '_' || *string_ == '.' || *string_ == '~') + retCString[i++] = *string_; else { uint8_t high, low; - high = *s >> 4; - low = *s & 0x0F; + high = *string_ >> 4; + low = *string_ & 0x0F; - ret_c[i++] = '%'; - ret_c[i++] = (high > 9 ? high - 10 + 'A' : high + '0'); - ret_c[i++] = (low > 9 ? low - 10 + 'A' : low + '0'); + retCString[i++] = '%'; + retCString[i++] = + (high > 9 ? high - 10 + 'A' : high + '0'); + retCString[i++] = + (low > 9 ? low - 10 + 'A' : low + '0'); } } @try { - ret = [OFString stringWithCString: ret_c + ret = [OFString stringWithCString: retCString length: i]; } @finally { - free(ret_c); + free(retCString); } return ret; } - (OFString*)stringByURLDecoding { - const char *s; - char *ret_c, c; - size_t i; - int st; - OFString *ret; - - s = string; - - if ((ret_c = malloc(length + 1)) == NULL) - @throw [OFOutOfMemoryException newWithClass: isa - requestedSize: length + 1]; - - for (st = 0, i = 0, c = 0; *s; s++) { - switch (st) { - case 0: - if (*s == '%') - st = 1; - else if (*s == '+') - ret_c[i++] = ' '; - else - ret_c[i++] = *s; - break; - case 1: - case 2: - if (*s >= '0' && *s <= '9') - c += (*s - '0') << (st == 1 ? 4 : 0); - else if (*s >= 'A' && *s <= 'F') - c += (*s - 'A' + 10) << (st == 1 ? 4 : 0); - else if (*s >= 'a' && *s <= 'f') - c += (*s - 'a' + 10) << (st == 1 ? 4 : 0); - else { - free(ret_c); - @throw [OFInvalidEncodingException - newWithClass: isa]; - } - - if (++st == 3) { - ret_c[i++] = c; - st = 0; - c = 0; - } - - break; - } - } - ret_c[i] = '\0'; - - if (st) { - free(ret_c); - @throw [OFInvalidEncodingException newWithClass: isa]; - } - - @try { - ret = [OFString stringWithCString: ret_c]; - } @finally { - free(ret_c); + OFString *ret; + const char *string_ = string; + char *retCString; + char byte = 0; + int state = 0; + size_t i; + + if ((retCString = malloc(length + 1)) == NULL) + @throw [OFOutOfMemoryException newWithClass: isa + requestedSize: length + 1]; + + for (i = 0; *string_; string_++) { + switch (state) { + case 0: + if (*string_ == '%') + state = 1; + else if (*string_ == '+') + retCString[i++] = ' '; + else + retCString[i++] = *string_; + break; + case 1: + case 2:; + uint8_t shift = (state == 1 ? 4 : 0); + + if (*string_ >= '0' && *string_ <= '9') + byte += (*string_ - '0') << shift; + else if (*string_ >= 'A' && *string_ <= 'F') + byte += (*string_ - 'A' + 10) << shift; + else if (*string_ >= 'a' && *string_ <= 'f') + byte += (*string_ - 'a' + 10) << shift; + else { + free(retCString); + @throw [OFInvalidEncodingException + newWithClass: isa]; + } + + if (++state == 3) { + retCString[i++] = byte; + state = 0; + byte = 0; + } + + break; + } + } + retCString[i] = '\0'; + + if (state != 0) { + free(retCString); + @throw [OFInvalidEncodingException newWithClass: isa]; + } + + @try { + ret = [OFString stringWithCString: retCString]; + } @finally { + free(retCString); } return ret; } @end Index: src/OFString+XMLEscaping.m ================================================================== --- src/OFString+XMLEscaping.m +++ src/OFString+XMLEscaping.m @@ -27,75 +27,78 @@ int _OFString_XMLEscaping_reference; @implementation OFString (XMLEscaping) - (OFString*)stringByXMLEscaping { - char *str_c, *tmp; + char *retCString; const char *append; - size_t len, append_len; + size_t retLength, appendLength; size_t i, j; OFString *ret; j = 0; - len = length; + retLength = length; /* * We can't use allocMemoryWithSize: here as it might be a @"" literal */ - if ((str_c = malloc(len)) == NULL) + if ((retCString = malloc(retLength)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa - requestedSize: len]; + requestedSize: retLength]; for (i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; - append_len = 4; + appendLength = 4; break; case '>': append = ">"; - append_len = 4; + appendLength = 4; break; case '"': append = """; - append_len = 6; + appendLength = 6; break; case '\'': append = "'"; - append_len = 6; + appendLength = 6; break; case '&': append = "&"; - append_len = 5; + appendLength = 5; break; default: append = NULL; - append_len = 0; + appendLength = 0; } if (append != NULL) { - if ((tmp = realloc(str_c, len + append_len)) == NULL) { - free(str_c); - @throw [OFOutOfMemoryException - newWithClass: isa - requestedSize: len + append_len]; - } - str_c = tmp; - len += append_len - 1; - - memcpy(str_c + j, append, append_len); - j += append_len; - } else - str_c[j++] = string[i]; - } - - assert(j == len); - - @try { - ret = [OFString stringWithCString: str_c - length: len]; - } @finally { - free(str_c); + char *newRetCString; + + if ((newRetCString = realloc(retCString, + retLength + appendLength)) == NULL) { + free(retCString); + @throw [OFOutOfMemoryException + newWithClass: isa + requestedSize: retLength + appendLength]; + } + retCString = newRetCString; + retLength += appendLength - 1; + + memcpy(retCString + j, append, appendLength); + j += appendLength; + } else + retCString[j++] = string[i]; + } + + assert(j == retLength); + + @try { + ret = [OFString stringWithCString: retCString + length: retLength]; + } @finally { + free(retCString); } return ret; } @end Index: src/OFString+XMLUnescaping.m ================================================================== --- src/OFString+XMLUnescaping.m +++ src/OFString+XMLUnescaping.m @@ -30,11 +30,11 @@ static OF_INLINE OFString* parse_numeric_entity(const char *entity, size_t length) { of_unichar_t c; size_t i; - char buf[5]; + char buffer[5]; if (length == 1 || *entity != '#') return nil; c = 0; @@ -65,15 +65,15 @@ else return nil; } } - if ((i = of_string_unicode_to_utf8(c, buf)) == 0) + if ((i = of_string_unicode_to_utf8(c, buffer)) == 0) return nil; - buf[i] = 0; + buffer[i] = 0; - return [OFString stringWithCString: buf + return [OFString stringWithCString: buffer length: i]; } @implementation OFString (XMLUnescaping) - (OFString*)stringByXMLUnescaping @@ -83,50 +83,53 @@ - (OFString*)stringByXMLUnescapingWithDelegate: (id )delegate { size_t i, last; - BOOL in_entity; + BOOL inEntity; OFMutableString *ret; last = 0; - in_entity = NO; + inEntity = NO; ret = [OFMutableString string]; ((OFString*)ret)->isUTF8 = [self isUTF8]; for (i = 0; i < length; i++) { - if (!in_entity && string[i] == '&') { + if (!inEntity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; last = i + 1; - in_entity = YES; - } else if (in_entity && string[i] == ';') { + inEntity = YES; + } else if (inEntity && string[i] == ';') { char *entity = string + last; - size_t len = i - last; + size_t entityLength = i - last; - if (len == 2 && !memcmp(entity, "lt", 2)) + if (entityLength == 2 && !memcmp(entity, "lt", 2)) [ret appendCStringWithoutUTF8Checking: "<" length: 1]; - else if (len == 2 && !memcmp(entity, "gt", 2)) + else if (entityLength == 2 && !memcmp(entity, "gt", 2)) [ret appendCStringWithoutUTF8Checking: ">" length: 1]; - else if (len == 4 && !memcmp(entity, "quot", 4)) + else if (entityLength == 4 && + !memcmp(entity, "quot", 4)) [ret appendCStringWithoutUTF8Checking: "\"" length: 1]; - else if (len == 4 && !memcmp(entity, "apos", 4)) + else if (entityLength == 4 && + !memcmp(entity, "apos", 4)) [ret appendCStringWithoutUTF8Checking: "'" length: 1]; - else if (len == 3 && !memcmp(entity, "amp", 3)) + else if (entityLength == 3 && !memcmp(entity, "amp", 3)) [ret appendCStringWithoutUTF8Checking: "&" length: 1]; else if (entity[0] == '#') { OFAutoreleasePool *pool; OFString *tmp; pool = [[OFAutoreleasePool alloc] init]; - tmp = parse_numeric_entity(entity, len); + tmp = parse_numeric_entity(entity, + entityLength); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; @@ -137,11 +140,11 @@ OFString *n, *tmp; pool = [[OFAutoreleasePool alloc] init]; n = [OFString stringWithCString: entity - length: len]; + length: entityLength]; tmp = [delegate string: self containsUnknownEntityNamed: n]; if (tmp == nil) @throw [OFInvalidEncodingException @@ -152,15 +155,15 @@ } else @throw [OFInvalidEncodingException newWithClass: isa]; last = i + 1; - in_entity = NO; + inEntity = NO; } } - if (in_entity) + if (inEntity) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; @@ -176,66 +179,70 @@ #ifdef OF_HAVE_BLOCKS - (OFString*)stringByXMLUnescapingWithBlock: (of_string_xml_unescaping_block_t)block { size_t i, last; - BOOL in_entity; + BOOL inEntity; OFMutableString *ret; last = 0; - in_entity = NO; + inEntity = NO; ret = [OFMutableString string]; ((OFString*)ret)->isUTF8 = [self isUTF8]; for (i = 0; i < length; i++) { - if (!in_entity && string[i] == '&') { + if (!inEntity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; last = i + 1; - in_entity = YES; - } else if (in_entity && string[i] == ';') { + inEntity = YES; + } else if (inEntity && string[i] == ';') { char *entity = string + last; - size_t len = i - last; + size_t entityLength = i - last; - if (len == 2 && !memcmp(entity, "lt", 2)) + if (entityLength == 2 && !memcmp(entity, "lt", 2)) [ret appendCStringWithoutUTF8Checking: "<" length: 1]; - else if (len == 2 && !memcmp(entity, "gt", 2)) + else if (entityLength == 2 && !memcmp(entity, "gt", 2)) [ret appendCStringWithoutUTF8Checking: ">" length: 1]; - else if (len == 4 && !memcmp(entity, "quot", 4)) + else if (entityLength == 4 && + !memcmp(entity, "quot", 4)) [ret appendCStringWithoutUTF8Checking: "\"" length: 1]; - else if (len == 4 && !memcmp(entity, "apos", 4)) + else if (entityLength == 4 && + !memcmp(entity, "apos", 4)) [ret appendCStringWithoutUTF8Checking: "'" length: 1]; - else if (len == 3 && !memcmp(entity, "amp", 3)) + else if (entityLength == 3 && !memcmp(entity, "amp", 3)) [ret appendCStringWithoutUTF8Checking: "&" length: 1]; else if (entity[0] == '#') { OFAutoreleasePool *pool; OFString *tmp; pool = [[OFAutoreleasePool alloc] init]; - tmp = parse_numeric_entity(entity, len); + tmp = parse_numeric_entity(entity, + entityLength); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; } else { OFAutoreleasePool *pool; - OFString *n, *tmp; + OFString *entityString, *tmp; pool = [[OFAutoreleasePool alloc] init]; - n = [OFString stringWithCString: entity - length: len]; - tmp = block(self, n); + entityString = [OFString + stringWithCString: entity + length: entityLength]; + tmp = block(self, entityString); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; @@ -242,15 +249,15 @@ [ret appendString: tmp]; [pool release]; } last = i + 1; - in_entity = NO; + inEntity = NO; } } - if (in_entity) + if (inEntity) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -65,11 +65,11 @@ /** * Listen on the socket. * * \param backlog Maximum length for the queue of pending connections. */ -- (void)listenWithBackLog: (int)backlog; +- (void)listenWithBackLog: (int)backLog; /** * Listen on the socket. */ - (void)listen; Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -315,20 +315,20 @@ socket: self host: host port: port]; } -- (void)listenWithBackLog: (int)backlog +- (void)listenWithBackLog: (int)backLog { if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa socket: self]; - if (listen(sock, backlog) == -1) + if (listen(sock, backLog) == -1) @throw [OFListenFailedException newWithClass: isa socket: self - backLog: backlog]; + backLog: backLog]; isListening = YES; } - (void)listen