Overview
Comment: | More style improvements. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
fb95acc8abcde52095b08dac37e20436 |
User & Date: | js on 2011-04-22 21:08:30 |
Other Links: | manifest | tags |
Context
2011-04-22
| ||
21:59 | OFURL: Do -[copy] in a try block to prevent leaks. check-in: 22ee389a21 user: js tags: trunk | |
21:08 | More style improvements. check-in: fb95acc8ab user: js tags: trunk | |
20:43 | OFStreamObserver: Don't ignore the timeout when using select(). check-in: 4b08544ddd user: js tags: trunk | |
Changes
Modified src/OFPlugin.m from [1a436fda73] to [ce104d5d58].
︙ | ︙ | |||
38 39 40 41 42 43 44 | @implementation OFPlugin + pluginFromFile: (OFString*)path { OFAutoreleasePool *pool; OFMutableString *file; of_plugin_handle_t handle; | | | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | @implementation OFPlugin + pluginFromFile: (OFString*)path { OFAutoreleasePool *pool; OFMutableString *file; of_plugin_handle_t handle; OFPlugin *(*initPlugin)(); OFPlugin *plugin; pool = [[OFAutoreleasePool alloc] init]; file = [OFMutableString stringWithString: path]; [file appendCString: PLUGIN_SUFFIX]; if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL) @throw [OFInitializationFailedException newWithClass: self]; [pool release]; initPlugin = (OFPlugin*(*)())dlsym(handle, "init_plugin"); if (initPlugin == NULL || (plugin = initPlugin()) == nil) { dlclose(handle); @throw [OFInitializationFailedException newWithClass: self]; } plugin->handle = handle; return plugin; } |
︙ | ︙ |
Modified src/OFStreamObserver.h from [ad26e6202d] to [923c073c02].
︙ | ︙ | |||
77 78 79 80 81 82 83 | @interface OFStreamObserver: OFObject { OFMutableArray *readStreams; OFMutableArray *writeStreams; OFMutableArray *queue, *queueInfo; id <OFStreamObserverDelegate> delegate; #ifdef OF_HAVE_POLL | | | | | | | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | @interface OFStreamObserver: OFObject { OFMutableArray *readStreams; OFMutableArray *writeStreams; OFMutableArray *queue, *queueInfo; id <OFStreamObserverDelegate> delegate; #ifdef OF_HAVE_POLL OFDataArray *FDs; OFMutableDictionary *FDToStream; #else fd_set readFDs; fd_set writeFDs; fd_set exceptFDs; int nFDs; #endif int cancelFD[2]; #ifdef _WIN32 struct sockaddr_in cancelAddr; #endif } #ifdef OF_HAVE_PROPERTIES @property (retain) id <OFStreamObserverDelegate> delegate; |
︙ | ︙ |
Modified src/OFStreamObserver.m from [4bdac00ac8] to [94e7d25075].
︙ | ︙ | |||
73 74 75 76 77 78 79 | #endif readStreams = [[OFMutableArray alloc] init]; writeStreams = [[OFMutableArray alloc] init]; queue = [[OFMutableArray alloc] init]; queueInfo = [[OFMutableArray alloc] init]; #ifdef OF_HAVE_POLL | | | | | | | | | | | | | | | | | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #endif readStreams = [[OFMutableArray alloc] init]; writeStreams = [[OFMutableArray alloc] init]; queue = [[OFMutableArray alloc] init]; queueInfo = [[OFMutableArray alloc] init]; #ifdef OF_HAVE_POLL FDs = [[OFDataArray alloc] initWithItemSize: sizeof(struct pollfd)]; FDToStream = [[OFMutableDictionary alloc] init]; #else FD_ZERO(&readfds); FD_ZERO(&writefds); #endif #ifndef _WIN32 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); 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], (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2))) @throw [OFInitializationFailedException newWithClass: isa]; cancelAddrLen = sizeof(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]; #else FD_SET(cancelFD[0], &readFDs); nFDs = cancelFD[0] + 1; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { 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]; #endif [super dealloc]; } - (id <OFStreamObserverDelegate>)delegate { |
︙ | ︙ | |||
165 166 167 168 169 170 171 | delegate = delegate_; } #ifdef OF_HAVE_POLL - (void)_addStream: (OFStream*)stream withEvents: (short)events { | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | delegate = delegate_; } #ifdef OF_HAVE_POLL - (void)_addStream: (OFStream*)stream withEvents: (short)events { 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 (FDsCArray[i].fd == fileDescriptor) { FDsCArray[i].events |= events; found = YES; } } if (!found) { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; 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 *FDsCArray = [FDs cArray]; size_t i, nFDs = [FDs count]; int fileDescriptor = [stream fileDescriptor]; for (i = 0; i < nFDs; i++) { if (FDsCArray[i].fd == fileDescriptor) { OFAutoreleasePool *pool; FDsCArray[i].events &= ~events; if ((FDsCArray[i].events & ~POLLERR) != 0) return; pool = [[OFAutoreleasePool alloc] init]; [FDs removeItemAtIndex: i]; [FDToStream removeObjectForKey: [OFNumber numberWithInt: fileDescriptor]]; [pool release]; } } } #else - (void)_addStream: (OFStream*)stream withFDSet: (fd_set*)FDSet { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; int fileDescriptor = [stream fileDescriptor]; 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*)otherFDSet { int fileDescriptor = [stream fileDescriptor]; FD_CLR(fileDescriptor, FDSet); if (!FD_ISSET(fileDescriptor, otherFDSet)) FD_CLR(fileDescriptor, &exceptfds); } #endif - (void)addStreamToObserveForReading: (OFStream*)stream { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *qi = [OFNumber numberWithInt: QUEUE_ADD | QUEUE_READ]; @synchronized (queue) { [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 assert(write(cancelFD[1], "", 1) > 0); #else assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } - (void)addStreamToObserveForWriting: (OFStream*)stream { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *qi = [OFNumber numberWithInt: QUEUE_ADD | QUEUE_WRITE]; @synchronized (queue) { [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 assert(write(cancelFD[1], "", 1) > 0); #else assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } - (void)removeStreamToObserveForReading: (OFStream*)stream { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *qi = [OFNumber numberWithInt: QUEUE_REMOVE | QUEUE_READ]; @synchronized (queue) { [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 assert(write(cancelFD[1], "", 1) > 0); #else assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } - (void)removeStreamToObserveForWriting: (OFStream*)stream { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFNumber *qi = [OFNumber numberWithInt: QUEUE_REMOVE | QUEUE_WRITE]; @synchronized (queue) { [queue addObject: stream]; [queueInfo addObject: qi]; } #ifndef _WIN32 assert(write(cancelFD[1], "", 1) > 0); #else assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif [pool release]; } - (void)_processQueue { @synchronized (queue) { OFStream **queueCArray = [queue cArray]; OFNumber **queueInfoCArray = [queueInfo cArray]; size_t i, count = [queue count]; for (i = 0; i < count; i++) { switch ([queueInfoCArray[i] intValue]) { case QUEUE_ADD | QUEUE_READ: [readStreams addObject: queueCArray[i]]; #ifdef OF_HAVE_POLL [self _addStream: queueCArray[i] withEvents: POLLIN]; #else [self _addStream: queueCArray[i] withFDSet: &readFDs]; #endif break; case QUEUE_ADD | QUEUE_WRITE: [writeStreams addObject: queueCArray[i]]; #ifdef OF_HAVE_POLL [self _addStream: queueCArray[i] withEvents: POLLOUT]; #else [self _addStream: queueCArray[i] withFDSet: &writeFDs]; #endif break; case QUEUE_REMOVE | QUEUE_READ: [readStreams removeObjectIdenticalTo: queueCArray[i]]; #ifdef OF_HAVE_POLL [self _removeStream: queueCArray[i] withEvents: POLLIN]; #else [self _removeStream: queueCArray[i] withFDSet: &readFDs otherFDSet: &writeFDs]; #endif break; case QUEUE_REMOVE | QUEUE_WRITE: [writeStreams removeObjectIdenticalTo: queueCArray[i]]; #ifdef OF_HAVE_POLL [self _removeStream: queueCArray[i] withEvents: POLLOUT]; #else [self _removeStream: queueCArray[i] withFDSet: &writeFDs otherFDSet: &readFDs]; #endif break; default: assert(0); } } |
︙ | ︙ | |||
397 398 399 400 401 402 403 | - (BOOL)observeWithTimeout: (int)timeout { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; BOOL foundInCache = NO; OFStream **cArray; size_t i, count; #ifdef OF_HAVE_POLL | | | | | | | | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | - (BOOL)observeWithTimeout: (int)timeout { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; BOOL foundInCache = NO; OFStream **cArray; size_t i, count; #ifdef OF_HAVE_POLL struct pollfd *FDsCArray; size_t nFDs; #else fd_set readFDs_; fd_set writeFDs_; fd_set exceptFDs_; struct timeval time; #endif [self _processQueue]; cArray = [readStreams cArray]; count = [readStreams count]; |
︙ | ︙ | |||
427 428 429 430 431 432 433 | * As long as we have data in the cache for any stream, we don't want * to block. */ if (foundInCache) return YES; #ifdef OF_HAVE_POLL | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | * As long as we have data in the cache for any stream, we don't want * to block. */ if (foundInCache) return YES; #ifdef OF_HAVE_POLL FDsCArray = [FDs cArray]; nFDs = [FDs count]; # ifdef OPEN_MAX if (nFDs > OPEN_MAX) @throw [OFOutOfRangeException newWithClass: isa]; # endif if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1) return NO; for (i = 0; i < nFDs; i++) { OFNumber *num; OFStream *stream; if (FDsCArray[i].revents & POLLIN) { if (FDsCArray[i].fd == cancelFD[0]) { char buffer; assert(read(cancelFD[0], &buffer, 1) > 0); FDsCArray[i].revents = 0; continue; } num = [OFNumber numberWithInt: FDsCArray[i].fd]; stream = [FDToStream objectForKey: num]; [delegate streamDidBecomeReadyForReading: stream]; [pool releaseObjects]; } if (FDsCArray[i].revents & POLLOUT) { num = [OFNumber numberWithInt: FDsCArray[i].fd]; stream = [FDToStream objectForKey: num]; [delegate streamDidBecomeReadyForReading: stream]; [pool releaseObjects]; } if (FDsCArray[i].revents & POLLERR) { num = [OFNumber numberWithInt: FDsCArray[i].fd]; stream = [FDToStream objectForKey: num]; [delegate streamDidReceiveException: stream]; [pool releaseObjects]; } FDsCArray[i].revents = 0; } #else # ifdef FD_COPY FD_COPY(&readFDs, &readFDs_); FD_COPY(&writeFDs, &writeFDs_); FD_COPY(&exceptFDs, &exceptFDs_); # else readFDs_ = readFDs; writeFDs_ = writeFDs; exceptFDs_ = exceptFDs; # endif time.tv_sec = timeout / 1000; time.tv_usec = (timeout % 1000) * 1000; if (select(nFDs, &readFDs_, &writeFDs_, &exceptFDs_, (timeout != -1 ? &time : NULL)) < 1) return NO; if (FD_ISSET(cancelFD[0], &readFDs_)) { char buffer; #ifndef _WIN32 assert(read(cancelFD[0], &buffer, 1) > 0); #else assert(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); #endif } for (i = 0; i < count; i++) { int fileDescriptor = [cArray[i] fileDescriptor]; if (FD_ISSET(fileDescriptor, &readFDs_)) { [delegate streamDidBecomeReadyForReading: cArray[i]]; [pool releaseObjects]; } if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: cArray[i]]; [pool releaseObjects]; /* * Prevent calling it twice in case the FD is in both * sets. */ FD_CLR(fileDescriptor, &exceptFDs_); } } cArray = [writeStreams cArray]; count = [writeStreams count]; for (i = 0; i < count; i++) { int fileDescriptor = [cArray[i] fileDescriptor]; if (FD_ISSET(fileDescriptor, &writeFDs_)) { [delegate streamDidBecomeReadyForWriting: cArray[i]]; [pool releaseObjects]; } if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: cArray[i]]; [pool releaseObjects]; } } #endif [pool release]; |
︙ | ︙ |
Modified src/OFString+URLEncoding.m from [5910a2a036] to [756001522a].
︙ | ︙ | |||
27 28 29 30 31 32 33 | /* Reference for static linking */ int _OFString_URLEncoding_reference; @implementation OFString (URLEncoding) - (OFString*)stringByURLEncoding { | | | < < | | | | | | | | > | > | | | > | | < > | < | < | | | | | | | | | > > | | | | | | | | | | | | | | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | /* Reference for static linking */ int _OFString_URLEncoding_reference; @implementation OFString (URLEncoding) - (OFString*)stringByURLEncoding { const char *string_ = string; char *retCString; size_t i; OFString *ret; /* * Worst case: 3 times longer than before. * Oh, and we can't use [self allocWithSize:] here as self might be a * @"" literal. */ if ((retCString = malloc((length * 3) + 1)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa requestedSize: (length * 3) + 1]; for (i = 0; *string_ != '\0'; string_++) { if (isalnum((int)*string_) || *string_ == '-' || *string_ == '_' || *string_ == '.' || *string_ == '~') retCString[i++] = *string_; else { uint8_t high, low; high = *string_ >> 4; low = *string_ & 0x0F; retCString[i++] = '%'; retCString[i++] = (high > 9 ? high - 10 + 'A' : high + '0'); retCString[i++] = (low > 9 ? low - 10 + 'A' : low + '0'); } } @try { ret = [OFString stringWithCString: retCString length: i]; } @finally { free(retCString); } return ret; } - (OFString*)stringByURLDecoding { 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 |
Modified src/OFString+XMLEscaping.m from [c2066f8693] to [bbfbe023ae].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #import "OFOutOfMemoryException.h" int _OFString_XMLEscaping_reference; @implementation OFString (XMLEscaping) - (OFString*)stringByXMLEscaping { | | | | | | | | | | | | > | > > | | | | | | | | | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #import "OFOutOfMemoryException.h" int _OFString_XMLEscaping_reference; @implementation OFString (XMLEscaping) - (OFString*)stringByXMLEscaping { char *retCString; const char *append; size_t retLength, appendLength; size_t i, j; OFString *ret; j = 0; retLength = length; /* * We can't use allocMemoryWithSize: here as it might be a @"" literal */ if ((retCString = malloc(retLength)) == NULL) @throw [OFOutOfMemoryException newWithClass: isa requestedSize: retLength]; for (i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; appendLength = 4; break; case '>': append = ">"; appendLength = 4; break; case '"': append = """; appendLength = 6; break; case '\'': append = "'"; appendLength = 6; break; case '&': append = "&"; appendLength = 5; break; default: append = NULL; appendLength = 0; } if (append != NULL) { 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 |
Modified src/OFString+XMLUnescaping.m from [ab5733ce2b] to [53b4061156].
︙ | ︙ | |||
28 29 30 31 32 33 34 | int _OFString_XMLUnescaping_reference; static OF_INLINE OFString* parse_numeric_entity(const char *entity, size_t length) { of_unichar_t c; size_t i; | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | int _OFString_XMLUnescaping_reference; static OF_INLINE OFString* parse_numeric_entity(const char *entity, size_t length) { of_unichar_t c; size_t i; char buffer[5]; if (length == 1 || *entity != '#') return nil; c = 0; entity++; length--; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | if (entity[i] >= '0' && entity[i] <= '9') c = (c * 10) + (entity[i] - '0'); else return nil; } } | | | | | | | | | | | | > | > | | | > | | | | | | | | | | | > | > | | | > | > | | | | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | if (entity[i] >= '0' && entity[i] <= '9') c = (c * 10) + (entity[i] - '0'); else return nil; } } if ((i = of_string_unicode_to_utf8(c, buffer)) == 0) return nil; buffer[i] = 0; return [OFString stringWithCString: buffer length: i]; } @implementation OFString (XMLUnescaping) - (OFString*)stringByXMLUnescaping { return [self stringByXMLUnescapingWithDelegate: nil]; } - (OFString*)stringByXMLUnescapingWithDelegate: (id <OFStringXMLUnescapingDelegate>)delegate { size_t i, last; BOOL inEntity; OFMutableString *ret; last = 0; inEntity = NO; ret = [OFMutableString string]; ((OFString*)ret)->isUTF8 = [self isUTF8]; for (i = 0; i < length; i++) { if (!inEntity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; last = i + 1; inEntity = YES; } else if (inEntity && string[i] == ';') { char *entity = string + last; size_t entityLength = i - last; if (entityLength == 2 && !memcmp(entity, "lt", 2)) [ret appendCStringWithoutUTF8Checking: "<" length: 1]; else if (entityLength == 2 && !memcmp(entity, "gt", 2)) [ret appendCStringWithoutUTF8Checking: ">" length: 1]; else if (entityLength == 4 && !memcmp(entity, "quot", 4)) [ret appendCStringWithoutUTF8Checking: "\"" length: 1]; else if (entityLength == 4 && !memcmp(entity, "apos", 4)) [ret appendCStringWithoutUTF8Checking: "'" length: 1]; 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, entityLength); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; } else if (delegate != nil) { OFAutoreleasePool *pool; OFString *n, *tmp; pool = [[OFAutoreleasePool alloc] init]; n = [OFString stringWithCString: entity length: entityLength]; tmp = [delegate string: self containsUnknownEntityNamed: n]; if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; } else @throw [OFInvalidEncodingException newWithClass: isa]; last = i + 1; inEntity = NO; } } if (inEntity) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; /* * Class swizzle the string to be immutable. We declared the return type * to be OFString*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ ret->isa = [OFString class]; return ret; } #ifdef OF_HAVE_BLOCKS - (OFString*)stringByXMLUnescapingWithBlock: (of_string_xml_unescaping_block_t)block { size_t i, last; BOOL inEntity; OFMutableString *ret; last = 0; inEntity = NO; ret = [OFMutableString string]; ((OFString*)ret)->isUTF8 = [self isUTF8]; for (i = 0; i < length; i++) { if (!inEntity && string[i] == '&') { [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; last = i + 1; inEntity = YES; } else if (inEntity && string[i] == ';') { char *entity = string + last; size_t entityLength = i - last; if (entityLength == 2 && !memcmp(entity, "lt", 2)) [ret appendCStringWithoutUTF8Checking: "<" length: 1]; else if (entityLength == 2 && !memcmp(entity, "gt", 2)) [ret appendCStringWithoutUTF8Checking: ">" length: 1]; else if (entityLength == 4 && !memcmp(entity, "quot", 4)) [ret appendCStringWithoutUTF8Checking: "\"" length: 1]; else if (entityLength == 4 && !memcmp(entity, "apos", 4)) [ret appendCStringWithoutUTF8Checking: "'" length: 1]; 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, entityLength); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; } else { OFAutoreleasePool *pool; OFString *entityString, *tmp; pool = [[OFAutoreleasePool alloc] init]; entityString = [OFString stringWithCString: entity length: entityLength]; tmp = block(self, entityString); if (tmp == nil) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendString: tmp]; [pool release]; } last = i + 1; inEntity = NO; } } if (inEntity) @throw [OFInvalidEncodingException newWithClass: isa]; [ret appendCStringWithoutUTF8Checking: string + last length: i - last]; /* * Class swizzle the string to be immutable. We declared the return type |
︙ | ︙ |
Modified src/OFTCPSocket.h from [98f00d6f79] to [5adaf7382b].
︙ | ︙ | |||
63 64 65 66 67 68 69 | onHost: (OFString*)host; /** * Listen on the socket. * * \param backlog Maximum length for the queue of pending connections. */ | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | onHost: (OFString*)host; /** * Listen on the socket. * * \param backlog Maximum length for the queue of pending connections. */ - (void)listenWithBackLog: (int)backLog; /** * Listen on the socket. */ - (void)listen; /** |
︙ | ︙ |
Modified src/OFTCPSocket.m from [ea3cfe401f] to [1ec7691203].
︙ | ︙ | |||
313 314 315 316 317 318 319 | sock = INVALID_SOCKET; @throw [OFBindFailedException newWithClass: isa socket: self host: host port: port]; } | | | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | sock = INVALID_SOCKET; @throw [OFBindFailedException newWithClass: isa socket: self host: host port: port]; } - (void)listenWithBackLog: (int)backLog { if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa socket: self]; if (listen(sock, backLog) == -1) @throw [OFListenFailedException newWithClass: isa socket: self backLog: backLog]; isListening = YES; } - (void)listen { if (sock == INVALID_SOCKET) |
︙ | ︙ |